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

UI-owned one-line control with owning Unicode text and local paint coordinates. Mutate through the free setters between frames. The frame owner translates local commands and intersects their clips with NodeGeometry, then renders before leaving tree.frame. Focus/enabled flags are presentation snapshots only; EventRouter owns input eligibility. More...

#include <controls.hpp>

Inheritance diagram for portals::Control:
portals::Controlportals::Control portals::SizedWidget portals::Widget portals::LayoutItem portals::Button portals::CheckBox portals::Label portals::Menu portals::Slider portals::KeyHints portals::Switch portals::ThreeState portals::PopupMenu

Public Member Functions

std::expected< CellSize, TreeError > measure (CellSize available) override
 Report intrinsic text and decoration width, with height one.
std::expected< void, TreeError > arrange (CellRect local) override
 Retain a zero-origin rectangle with the allocated local extent.
std::expected< void, TreeError > paint (PaintContext &context) override
 Submit local fill/text commands from the synchronized presentation snapshot.
const GraphemeText & text () const
 Inspect the control's owning Unicode text on UI.
bool focused () const
 Inspect the last synchronized focus presentation on UI.
bool enabled () const
 Inspect the last synchronized subtree eligibility presentation on UI.
ComputedStyle styleDefaults () const override
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 void unmount ()
 Called once before destruction, children first; cleanup continues on exceptions.
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.

Protected Member Functions

 Control (GraphemeText text, std::string_view prefix, std::string_view suffix, ControlStyle style, SizePolicy policy)
 Own text/options and create fixed ASCII decorations under the text's validated width policy.
 Control (GraphemeText text, GraphemeText prefix, GraphemeText checkedPrefix, ControlStyle style, SizePolicy policy)
 Own explicitly validated equal-width boolean decorations; no additional retained fields.
bool booleanChromeMatches () const
std::expected< void, TreeError > paintCaption (PaintContext &context, bool stretchChrome)
 Paint the synchronized caption with intrinsic or allocated-width decorations.
void showChecked (bool checked)
 Select a same-width prefix between frames; used only by the checkbox binding.
bool shownChecked () const
 Inspect the single checked presentation flag on UI.
void showMixed (bool mixed)
 Select the fixed mixed decoration after caller-owned paint invalidation.

Friends

struct detail::FindAccess
struct ui::detail::ActionAccess
class ManagedScene
std::expected< void, TreeError > setControlText (WidgetTree &tree, Node< Control > node, GraphemeText text)
 Replace owning text between frames; equal bytes/policy are a no-op, changes invalidate layout.
std::expected< void, TreeError > setControlStyle (WidgetTree &tree, Node< Control > node, ControlStyle style)
 Replace owning paint values on UI between frames; equal is a no-op, changes invalidate paint.
std::expected< void, TreeError > syncControl (WidgetTree &tree, Node< Control > node, Node< Widget > focused)
 Copy focus and ancestor eligibility on UI between frames; changes invalidate paint.

Detailed Description

UI-owned one-line control with owning Unicode text and local paint coordinates. Mutate through the free setters between frames. The frame owner translates local commands and intersects their clips with NodeGeometry, then renders before leaving tree.frame. Focus/enabled flags are presentation snapshots only; EventRouter owns input eligibility.

Constructor & Destructor Documentation

◆ Control() [1/2]

portals::Control::Control ( GraphemeText text,
std::string_view prefix,
std::string_view suffix,
ControlStyle style,
SizePolicy policy )
protected

Own text/options and create fixed ASCII decorations under the text's validated width policy.

Parameters
textValidated owning text, transferred into the control with its complete WidthPolicy.
prefixBorrowed leading ASCII decoration, copied during construction; "[ ] " enables alternate same-width "[x] " and "[-] " decorations for checkbox presentation.
suffixBorrowed trailing ASCII decoration, copied during construction.
styleOwning normal/focused/disabled paint values.
policyOwning layout size policy, subsequently validated by the layout owner.
Exceptions
std::bad_allocIf text transfer or decoration storage cannot allocate.
std::bad_expected_access<TextError>If a supplied decoration cannot be validated within text limits.
Note
Construct on UI through tree.emplace, which translates allocation failure to NO_MEMORY and other constructor exceptions to CALLBACK_FAILED. Argument construction precedes that boundary.

◆ Control() [2/2]

portals::Control::Control ( GraphemeText text,
GraphemeText prefix,
GraphemeText checkedPrefix,
ControlStyle style,
SizePolicy policy )
protected

Own explicitly validated equal-width boolean decorations; no additional retained fields.

Parameters
textOwning caption.
prefixOwning off prefix.
checkedPrefixOwning on prefix.
styleManual appearances.
policyLayout size policy.

Member Function Documentation

◆ arrange()

std::expected< void, TreeError > portals::Control::arrange ( CellRect local)
overridevirtual

Retain a zero-origin rectangle with the allocated local extent.

Parameters
localParent-relative allocation; its origin is handled by the frame owner's surface adapter.
Returns
Success after storing the extent, or INVALID_GEOMETRY if the zero-origin rectangle is invalid.
Note
Called on UI through WidgetTree::arrange; no domain mutation or I/O.

Reimplemented from portals::Widget.

Reimplemented in portals::KeyHints, portals::Menu, portals::PopupMenu, and portals::Slider.

◆ booleanChromeMatches()

bool portals::Control::booleanChromeMatches ( ) const
protected
Returns
Whether owned boolean decorations use the current caption policy.

◆ enabled()

bool portals::Control::enabled ( ) const

Inspect the last synchronized subtree eligibility presentation on UI.

Returns
True when the control and its ancestors were eligible at the last sync.

◆ focused()

bool portals::Control::focused ( ) const

Inspect the last synchronized focus presentation on UI.

Returns
True when the last sync marked this eligible control focused; not routing authority.

◆ measure()

std::expected< CellSize, TreeError > portals::Control::measure ( CellSize available)
overridevirtual

Report intrinsic text and decoration width, with height one.

Parameters
availableLayout's offered extent; intentionally does not limit intrinsic measurement.
Returns
Owning cell size, or INVALID_GEOMETRY if text plus decoration width is unrepresentable.
Note
Called on UI through WidgetTree::measure; no model reads, I/O or invalidation.

Reimplemented from portals::Widget.

Reimplemented in portals::KeyHints, portals::Menu, portals::PopupMenu, portals::Slider, and portals::Switch.

◆ paint()

std::expected< void, TreeError > portals::Control::paint ( PaintContext & context)
overridevirtual

Submit local fill/text commands from the synchronized presentation snapshot.

Parameters
contextBorrowed synchronous sink; command storage is valid during submit only. Text belongs to this control and may be borrowed by a retained command until the enclosing tree.frame returns.
Returns
Success, intrinsic-measurement INVALID_GEOMETRY, or the sink's unchanged TreeError.
Note
The frame owner translates local geometry, intersects the ancestor clip and renders before leaving tree.frame. No context/text reference escapes that frame; paint performs no model reads.
Exceptions
std::bad_allocIf the sink cannot allocate. Other sink exceptions also propagate; WidgetTree::paint translates escaped exceptions to CALLBACK_FAILED.

Reimplemented from portals::Widget.

Reimplemented in portals::KeyHints, portals::Menu, portals::PopupMenu, and portals::Slider.

◆ paintCaption()

std::expected< void, TreeError > portals::Control::paintCaption ( PaintContext & context,
bool stretchChrome )
protected

Paint the synchronized caption with intrinsic or allocated-width decorations.

Parameters
contextBorrowed synchronous sink with the same lifetime and exception contract as paint.
stretchChromeKeep the decorations at the allocated edges and center the caption between them.
Returns
Success, invalid intrinsic/clip geometry, or the sink's unchanged TreeError.
Note
Borrows the existing text and decorations; no text storage is created.

◆ showChecked()

void portals::Control::showChecked ( bool checked)
protected

Select a same-width prefix between frames; used only by the checkbox binding.

Parameters
checkedTrue selects the checked decoration; false selects the original prefix.
Note
The caller owns paint invalidation; this helper only changes presentation.

◆ showMixed()

void portals::Control::showMixed ( bool mixed)
protected

Select the fixed mixed decoration after caller-owned paint invalidation.

Parameters
mixedWhether the mixed decoration overrides the checked decoration.

◆ shownChecked()

bool portals::Control::shownChecked ( ) const
protected

Inspect the single checked presentation flag on UI.

Returns
The last value supplied to showChecked, initially false.

◆ styleDefaults()

ComputedStyle portals::Control::styleDefaults ( ) const
overridevirtual
Returns
Owning manual normal/focused/disabled appearances beneath theme declarations.

Reimplemented from portals::Widget.

◆ text()

const GraphemeText & portals::Control::text ( ) const

Inspect the control's owning Unicode text on UI.

Returns
A const reference borrowed only within the enclosing tree.read callback; never retain it.

◆ setControlStyle

std::expected< void, TreeError > setControlStyle ( WidgetTree & tree,
Node< Control > node,
ControlStyle style )
friend

Replace owning paint values on UI between frames; equal is a no-op, changes invalidate paint.

Parameters
treeBorrowed UI owner containing node; used only during this call.
nodeObserving handle to the control whose appearances are replaced.
styleOwning replacement paint values; does not affect behavior or layout metrics.
Returns
Success or the tree's WRONG_THREAD, WRONG_SESSION, STALE_NODE, closed, WOULD_BLOCK (active frame), CALLBACK_FAILED or invalidation error. Rejection leaves the stored style unchanged.

◆ setControlText

std::expected< void, TreeError > setControlText ( WidgetTree & tree,
Node< Control > node,
GraphemeText text )
friend

Replace owning text between frames; equal bytes/policy are a no-op, changes invalidate layout.

Parameters
treeBorrowed UI owner containing node; used only during this call.
nodeObserving handle to the control whose text is replaced.
textValidated owning replacement, transferred only after decorations are prepared and invalidation succeeds.
Returns
Success, internal NO_MEMORY, or the tree's WRONG_THREAD, WRONG_SESSION, STALE_NODE, closed, WOULD_BLOCK (active frame), CALLBACK_FAILED or invalidation error. Failure retains the previous text.
Exceptions
std::bad_allocIf construction of the by-value argument fails before this function begins; allocation inside the mutation boundary is returned as NO_MEMORY instead. Numeric-only Slider views reject caption mutation with INVALID_ARGUMENT, including through a base node.

◆ syncControl

std::expected< void, TreeError > syncControl ( WidgetTree & tree,
Node< Control > node,
Node< Widget > focused )
friend

Copy focus and ancestor eligibility on UI between frames; changes invalidate paint.

Parameters
treeBorrowed UI owner containing node; also supplies ancestor eligibility.
nodeObserving control handle receiving the presentation snapshot.
focusedObserving snapshot obtained once from EventRouter::focused before synchronizing the controls; an empty handle means no focused control. This identity is compared, not dereferenced or made authoritative.
Returns
Success or the tree's WRONG_THREAD, WRONG_SESSION, STALE_NODE, closed, WOULD_BLOCK (active frame), CALLBACK_FAILED or invalidation error. Equal presentation flags do not invalidate.
Note
No focus recovery, registration or routing is performed; never call router.focused from paint.

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