wxMaxima
Loading...
Searching...
No Matches
Data Structures | Functions
WorksheetSizeMath.h File Reference

The pure arithmetic that turns a laid-out worksheet's extent into the scrollable (virtual) size and scroll granularity. More...

#include <algorithm>
#include <vector>
Include dependency graph for WorksheetSizeMath.h:
This graph shows which files directly or indirectly include this file:

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...
 
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.
 
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.
 

Detailed Description

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().

Function Documentation

◆ ApplyWorksheetVirtualSize()

void ApplyWorksheetVirtualSize ( WorksheetView view,
bool  hasTree,
int  maxWidth,
int  maxHeight,
WorksheetVirtualSizeCache cache,
int &  scrollUnit 
)
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.

Parameters
viewThe window abstraction (real worksheet or a test mock).
hasTreeWhether the worksheet has content (ignores the extent if not).
maxWidthThe document's right extent (WorksheetLayout::GetMaxPoint x).
maxHeightThe document's bottom extent (WorksheetLayout::GetMaxPoint y).
cacheThe last-applied size, updated in place to dedupe.
scrollUnitRead 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.

◆ ComputeWorksheetContentHeight()

int ComputeWorksheetContentHeight ( const std::vector< TrailingGroupGeometry > &  trailing,
int  groupSkip,
int  baseIndent 
)
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.

Parameters
trailingThe 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.
groupSkipThe vertical gap between group cells (Configuration::GetGroupSkip).
baseIndentThe 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.

◆ ComputeWorksheetContentWidth()

int ComputeWorksheetContentWidth ( const std::vector< int > &  cellWidthsWithMargins,
int  baseIndent 
)
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).

Parameters
cellWidthsWithMarginsPer-cell widths (already including margins).
baseIndentThe minimum width (Configuration::GetBaseIndent).

Kept GUI-free (no Cell/Configuration dependency) so it can be unit-tested in isolation - see test_WorksheetSizeMath.

◆ ComputeWorksheetVirtualSize()

WorksheetVirtualSize ComputeWorksheetVirtualSize ( bool  hasTree,
int  maxPointWidth,
int  maxPointHeight,
int  clientHeight,
int  currentScrollPixelY 
)
inline

Compute a worksheet's virtual size and scroll unit.

Parameters
hasTreeWhether the worksheet has any content. Without it the result is a small fixed size with a sane scroll unit.
maxPointWidthThe document's right extent (WorksheetLayout::GetMaxPoint x).
maxPointHeightThe document's bottom extent (WorksheetLayout::GetMaxPoint y).
clientHeightThe visible height of the worksheet window.
currentScrollPixelYThe current vertical scroll offset in pixels.

Invariants (that the callers rely on):

  • a vertical scrollbar always has room to move: height >= clientHeight + 10;
  • the virtual size never shrinks below what the current scroll position needs (height >= currentScrollPixelY + clientHeight + 10), so wxWidgets does not clamp the scroll position and jump the view;
  • a little over-scroll past the end is allowed (with the view scrolled fully down the document occupies the top 1/8 of the client area);
  • the scroll unit is at least 10 px, so scrolling never feels sluggish on hi-res screens nor degenerates on tiny ones.