Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
Loading...
Searching...
No Matches
portals::Grid Class Reference

UI-owned Grid implementing the existing pure Layout contract. Every visible child needs a placement. All spans are checked, including hidden/stale entries. Later siblings paint/hit above earlier siblings; placement order does not change stacking. Intrinsic tracks absorb child demand, then Row's allocation rules apply independently on each axis. Constructors own settings; invalid settings are reported by Layout methods. Layout errors are INVALID_ARGUMENT, NODE_LIMIT, INVALID_GEOMETRY or NO_MEMORY. No I/O, retained spans or tree traversal. More...

#include <grid.hpp>

Inheritance diagram for portals::Grid:
portals::Gridportals::Grid portals::SizedWidget portals::Layout portals::Widget portals::LayoutItem

Public Member Functions

 Grid (const GridOptions &options={}, SizePolicy policy={})
 Own settings and size policies.
 Grid (const GridOptions &options, GridPlacementMode mode, SizePolicy policy={}, std::optional< GridScrollOptions > scroll={}, WidthPolicy width={})
 Own resolved settings in a fixed construction-time placement mode.
 ~Grid () override
 Release owning caches without callbacks or terminal operations.
void unmount () override
 Retire an optional scroll lease, pointer capture and intent before destruction.
std::expected< void, TreeError > arrange (CellRect local) override
std::expected< CellRect, TreeError > childClip (CellSize available) const override
std::expected< LayoutChildPolicy, TreeError > childLayoutFor (NodeId child, CellSize available) const override
std::expected< void, TreeError > paint (PaintContext &context) override
ComputedStyle styleDefaults () const override
GridOptions options () const
 Owning UI-thread copy; allocation may throw bad_alloc.
bool usesRegions () const noexcept
std::expected< CellSize, TreeError > childAvailable (CellSize available) const override
 Checked inset bounds.
std::expected< CellSize, TreeError > measureChildren (std::span< const MeasuredChild > children) const override
 Aggregate tracks.
std::expected< std::vector< CellRect >, TreeError > arrangeChildren (std::span< const MeasuredChild > children, CellSize available) const override
 Child-order local rectangles.
Public Member Functions inherited from portals::SizedWidget
 SizedWidget (SizePolicy policy={})
 Own the supplied policies; checked by layout.
SizePolicy sizePolicy () const override
 Copy current policy without borrowing storage.
Public Member Functions inherited from portals::Widget
virtual ~Widget ()=default
 Destroy on UI after the last active tree borrow.
virtual void mount ()
 Called exactly once after attachment; exceptions are reported.
virtual std::expected< CellSize, TreeError > measure (CellSize available)
 Default desired size is empty.
virtual bool styleReadOnly () const noexcept
 Read actual view-only state during style staging; false by default.
const std::shared_ptr< const StyleSnapshot > & computedStyle () const noexcept
 Inspect the last atomically installed theme inside tree.read/frame.
std::uint64_t styleRevision () const noexcept
Public Member Functions inherited from portals::LayoutItem
virtual ~LayoutItem ()=default
 Destroy with the implementing widget.
Public Member Functions inherited from portals::Layout
virtual ~Layout ()=default
 Destroy with the implementing widget.

Friends

struct detail::ScrollWidgetAccess
std::expected< void, TreeError > setGridOptions (WidgetTree &tree, Node< Grid > node, const GridOptions &options)
 Validate and atomically copy settings on the UI owner between frames, then invalidate layout. Tree errors propagate; invalid configuration leaves the previous settings unchanged. Input is borrowed only for this call. Allocation failure returns NO_MEMORY.
std::expected< void, TreeError > setDeclarativeGridOptions (WidgetTree &tree, Node< Grid > node, const GridOptions &options)
 Atomically replace resolved declarative settings between frames on the UI owner.
std::expected< void, TreeError > setGridPresentation (WidgetTree &tree, Node< Grid > node, const GridPresentation &presentation)
 Replace owning backgrounds between frames on the UI owner.

Detailed Description

UI-owned Grid implementing the existing pure Layout contract. Every visible child needs a placement. All spans are checked, including hidden/stale entries. Later siblings paint/hit above earlier siblings; placement order does not change stacking. Intrinsic tracks absorb child demand, then Row's allocation rules apply independently on each axis. Constructors own settings; invalid settings are reported by Layout methods. Layout errors are INVALID_ARGUMENT, NODE_LIMIT, INVALID_GEOMETRY or NO_MEMORY. No I/O, retained spans or tree traversal.

Constructor & Destructor Documentation

◆ Grid() [1/2]

portals::Grid::Grid ( const GridOptions & options = {},
SizePolicy policy = {} )
explicit

Own settings and size policies.

Parameters
optionsTracks, sparse placements and limits copied into independent storage.
policySize policy of this grid in its parent.
Exceptions
std::bad_allocIf copying the configuration cannot allocate storage.

◆ Grid() [2/2]

portals::Grid::Grid ( const GridOptions & options,
GridPlacementMode mode,
SizePolicy policy = {},
std::optional< GridScrollOptions > scroll = {},
WidthPolicy width = {} )

Own resolved settings in a fixed construction-time placement mode.

Parameters
optionsComplete resolved tracks and identities, copied into independent storage.
modeEXPLICIT permits overlap; DECLARATIVE rejects overlapping cell rectangles.
policySize policy of this grid in its parent.
scrollOptional existing scroll owner, fixed before mounting; no additional widget is created.
widthExisting terminal width policy used to validate scroll chrome glyphs.
Exceptions
std::bad_allocIf the configuration cannot be copied.

Member Function Documentation

◆ arrange()

std::expected< void, TreeError > portals::Grid::arrange ( CellRect local)
overridevirtual
Parameters
localParent-local allocation, used only to derive owning regional geometry.
Returns
Success or checked geometry/controller/settings error; never publishes controller values.

Reimplemented from portals::Widget.

◆ arrangeChildren()

std::expected< std::vector< CellRect >, TreeError > portals::Grid::arrangeChildren ( std::span< const MeasuredChild > children,
CellSize available ) const
overridevirtual

Child-order local rectangles.

Parameters
childrenVisible child measurements, policies and identities in sibling order.
availableContainer-local extent in terminal cells.
Returns
Owning rectangles in child order, or INVALID_ARGUMENT, NODE_LIMIT, INVALID_GEOMETRY or NO_MEMORY as applicable.

Implements portals::Layout.

◆ childAvailable()

std::expected< CellSize, TreeError > portals::Grid::childAvailable ( CellSize available) const
overridevirtual

Checked inset bounds.

Parameters
availableContainer extent offered by its parent, in cells.
Returns
Normalized inner extent after padding, or invalid settings/coordinate overflow.

Implements portals::Layout.

◆ childClip()

std::expected< CellRect, TreeError > portals::Grid::childClip ( CellSize available) const
overridevirtual
Parameters
availableNormalized complete allocation.
Returns
Cached full content envelope inside frame, padding and owned scrollbar strips.

Reimplemented from portals::Layout.

◆ childLayoutFor()

std::expected< LayoutChildPolicy, TreeError > portals::Grid::childLayoutFor ( NodeId child,
CellSize available ) const
overridevirtual
Parameters
childFull identity of one measured direct child.
availableComplete allocation.
Returns
Cached owning regional clip/reveal/input policy, or an unchanged layout error.

Reimplemented from portals::Layout.

◆ measureChildren()

std::expected< CellSize, TreeError > portals::Grid::measureChildren ( std::span< const MeasuredChild > children) const
overridevirtual

Aggregate tracks.

Parameters
childrenVisible child measurements and policies, borrowed only for this calculation.
Returns
Aggregate intrinsic extent including gaps/padding, or a validation, geometry or allocation error.

Implements portals::Layout.

◆ options()

GridOptions portals::Grid::options ( ) const

Owning UI-thread copy; allocation may throw bad_alloc.

Returns
An independent copy of the complete sparse configuration.
Exceptions
std::bad_allocIf the owning copy cannot be allocated.

◆ paint()

std::expected< void, TreeError > portals::Grid::paint ( PaintContext & context)
overridevirtual
Parameters
contextSynchronous sink borrowing grid-owned chrome text only through the enclosing frame.
Returns
Success, WOULD_BLOCK before submission above the whole paint budget, or sink/geometry error.

Reimplemented from portals::Widget.

◆ styleDefaults()

ComputedStyle portals::Grid::styleDefaults ( ) const
overridevirtual
Returns
Existing scroll defaults when enabled; backgrounds never alter child state styles.

Reimplemented from portals::Widget.

◆ unmount()

void portals::Grid::unmount ( )
overridevirtual

Retire an optional scroll lease, pointer capture and intent before destruction.

Reimplemented from portals::Widget.

◆ usesRegions()

bool portals::Grid::usesRegions ( ) const
noexcept
Returns
Whether this grid declared header/body regions before mount; no allocation or mutation.

◆ setDeclarativeGridOptions

std::expected< void, TreeError > setDeclarativeGridOptions ( WidgetTree & tree,
Node< Grid > node,
const GridOptions & options )
friend

Atomically replace resolved declarative settings between frames on the UI owner.

Parameters
treeOwning tree, borrowed for checked access and layout invalidation.
nodeDeclarative grid; an explicit grid returns INVALID_ARGUMENT without changing mode.
optionsComplete owning replacement; overlap is rejected and full identities remain authoritative.
Returns
Success, or validation/access/allocation error with old settings retained before publication. Input is borrowed only during this call. Layout callbacks cannot call this setter.

◆ setGridOptions

std::expected< void, TreeError > setGridOptions ( WidgetTree & tree,
Node< Grid > node,
const GridOptions & options )
friend

Validate and atomically copy settings on the UI owner between frames, then invalidate layout. Tree errors propagate; invalid configuration leaves the previous settings unchanged. Input is borrowed only for this call. Allocation failure returns NO_MEMORY.

Parameters
treeOwning tree, borrowed for the UI-only update.
nodeChecked observer of the grid being updated.
optionsComplete replacement configuration; borrowed only while making an independent copy.
Returns
Success after replacement and layout invalidation, or a validation/access/allocation error.

◆ setGridPresentation

std::expected< void, TreeError > setGridPresentation ( WidgetTree & tree,
Node< Grid > node,
const GridPresentation & presentation )
friend

Replace owning backgrounds between frames on the UI owner.

Parameters
treeOwning tree borrowed for this checked update.
nodeGrid receiving backgrounds.
presentationComplete replacement with positive paint budget; borrowed only during this call.
Returns
Success or access/validation error; equal values request no extra paint.

The documentation for this class was generated from the following file: