|
wxMaxima
|
The pure arithmetic that turns a laid-out worksheet's extent into the scrollable (virtual) size and scroll granularity. More...
#include <algorithm>#include <vector>Go to the source code of this file.
Data Structures | |
| struct | TrailingGroupGeometry |
| One trailing group cell's geometry, as GetMaxPoint's height walk needs it. More... | |
| struct | WorksheetVirtualSize |
| The scrollable size + scroll granularity computed for a worksheet. More... | |
| struct | ScrollCompensation |
| Where to scroll to, and how far to shift the document, to keep a point still. More... | |
| class | WorksheetView |
| The narrow view surface the worksheet's layout pipeline needs. More... | |
| struct | WorksheetVirtualSizeCache |
| Remembers the last virtual size applied, so an unchanged size is a no-op. More... | |
Functions | |
| int | ComputeWorksheetContentWidth (const std::vector< int > &cellWidthsWithMargins, int baseIndent) |
| Compute the worksheet's content width. | |
| int | ComputeWorksheetContentHeight (const std::vector< TrailingGroupGeometry > &trailing, int groupSkip, int baseIndent) |
| Compute the worksheet's content height from its trailing cells' geometry. | |
| WorksheetVirtualSize | ComputeWorksheetVirtualSize (bool hasTree, int maxPointWidth, int maxPointHeight, int clientHeight, int currentScrollPixelY) |
| Compute a worksheet's virtual size and scroll unit. | |
| ScrollCompensation | ComputeScrollCompensation (int scrollUnitsY, int scrollUnit, int topOffset, int shift) |
| Compute the scroll position that keeps a point of the worksheet still on screen. | |
| void | ApplyWorksheetVirtualSize (WorksheetView &view, bool hasTree, int maxWidth, int maxHeight, WorksheetVirtualSizeCache &cache, int &scrollUnit) |
| Measure the view, compute the virtual size and apply it, skipping no-ops. | |
The pure arithmetic that turns a laid-out worksheet's extent into the scrollable (virtual) size and scroll granularity.
Kept deliberately free of any GUI/wxWidgets dependency so the scroll-range math - historically a source of "the pane won't scroll" bugs - can be unit-tested in isolation. WorksheetLayout::AdjustSize() measures the document (GetMaxPoint) and the window (GetClientSize) and feeds the numbers here, then applies the result with SetVirtualSize()/SetScrollRate().
|
inline |
Measure the view, compute the virtual size and apply it, skipping no-ops.
This is the view-facing half of WorksheetLayout::AdjustSize(): it reads the client size and scroll position from view, feeds them (with the already-measured document extent maxWidth / maxHeight) to ComputeWorksheetVirtualSize(), and - only if the result actually changed and is positive - pushes it back to the view and updates the scroll rate.
| view | The window abstraction (real worksheet or a test mock). |
| hasTree | Whether the worksheet has content (ignores the extent if not). |
| maxWidth | The document's right extent (WorksheetLayout::GetMaxPoint x). |
| maxHeight | The document's bottom extent (WorksheetLayout::GetMaxPoint y). |
| cache | The last-applied size, updated in place to dedupe. |
| scrollUnit | Read to turn the scroll position into pixels, and updated to the new granularity. WorksheetLayout keeps it as a member because Worksheet's scroll handlers read it too. |
|
inline |
Compute the scroll position that keeps a point of the worksheet still on screen.
When Maxima appends output to a cell above the cursor, everything below that cell moves down, the cursor with it. Scrolling down by the same amount would put it back - but the view can only scroll in whole scroll units (10 px or more), so on its own that would still leave the cursor jittering by up to one unit on every append. The remainder is absorbed by the worksheet's top offset: an extra top margin of less than one scroll unit that shifts the whole document down. Scrolling one unit further than needed and moving the document down by the excess makes the compensation pixel-exact.
With the scroll position S, the top offset t and the point having moved down by shift pixels, the point stays where it was on screen exactly if the new values S', t' satisfy S' - t' = S + shift - t. This picks the smallest S' that is a multiple of the scroll unit and allows a t' in [0, scrollUnit). Near the top of the document, where S' cannot go below 0, t' is clamped to that range and the compensation is only as good as it can be.
| scrollUnitsY | The current vertical scroll position, in scroll units. |
| scrollUnit | The scroll granularity in px (> 0). |
| topOffset | The current top offset in px. |
| shift | How far (px) the point to keep still has moved down in the document; negative if it moved up. |
Kept GUI-free so it can be unit-tested in isolation - see test_WorksheetSizeMath.
|
inline |
Compute the worksheet's content height from its trailing cells' geometry.
This is the backward walk WorksheetLayout::GetMaxPoint() runs from the last cell: it accumulates the heights of the cells at the bottom whose position is not yet trustworthy (stale-and-unpositioned, or still-being-laid-out) until it reaches an "anchor" - a cell whose size is stale but whose top position (y) is already valid - and pins the total to that anchor's top plus everything accumulated below it. If the walk runs off the top of the document (no such anchor), the height falls back to the document's base indent plus the accumulated heights.
| trailing | The cells starting at the LAST cell and running backward. The walk stops at (and includes) the first entry that is the anchor, i.e. sizeIsStale && currentY >= 0. |
| groupSkip | The vertical gap between group cells (Configuration::GetGroupSkip). |
| baseIndent | The document's top margin (Configuration::GetBaseIndent), used only when there is no anchor. |
Kept GUI-free (no Cell/Configuration dependency) so this fiddly stale-cell accounting can be unit-tested in isolation - see test_WorksheetSizeMath.
|
inline |
Compute the worksheet's content width.
That is the document's base indent, widened to fit the widest group cell. Each entry in cellWidthsWithMargins is a cell's width including its left and right margins (WorksheetLayout::GroupCellWidthWithMargins).
| cellWidthsWithMargins | Per-cell widths (already including margins). |
| baseIndent | The minimum width (Configuration::GetBaseIndent). |
Kept GUI-free (no Cell/Configuration dependency) so it can be unit-tested in isolation - see test_WorksheetSizeMath.
|
inline |
Compute a worksheet's virtual size and scroll unit.
| hasTree | Whether the worksheet has any content. Without it the result is a small fixed size with a sane scroll unit. |
| maxPointWidth | The document's right extent (WorksheetLayout::GetMaxPoint x). |
| maxPointHeight | The document's bottom extent (WorksheetLayout::GetMaxPoint y). |
| clientHeight | The visible height of the worksheet window. |
| currentScrollPixelY | The current vertical scroll offset in pixels. |
Invariants (that the callers rely on):