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

One-line button; registration is an explicit caller-owned ActionBinding. More...

#include <controls.hpp>

Inheritance diagram for portals::Button:
portals::Buttonportals::Button portals::Control portals::SizedWidget portals::Widget portals::LayoutItem portals::KeyHints

Public Member Functions

 Button (GraphemeText text, ControlStyle style={}, SizePolicy policy=DEFAULT_CONTENT_POLICY)
 Construct an owning button with ASCII brackets on UI, normally through tree.emplace.
 Button (GraphemeText text, ControlStyle style, SizePolicy policy, ButtonChrome chrome)
std::expected< CellSize, TreeError > measure (CellSize available) override
std::expected< void, TreeError > paint (PaintContext &context) override
 Paint bracket chrome at the allocated edges with a centered, independently clipped caption.
bool checked () const
Public Member Functions inherited from portals::Control
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.

Additional Inherited Members

Protected Member Functions inherited from portals::Control
 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.

Detailed Description

One-line button; registration is an explicit caller-owned ActionBinding.

Constructor & Destructor Documentation

◆ Button() [1/2]

portals::Button::Button ( GraphemeText text,
ControlStyle style = {},
SizePolicy policy = DEFAULT_CONTENT_POLICY )
explicit

Construct an owning button with ASCII brackets on UI, normally through tree.emplace.

Parameters
textValidated owning caption and WidthPolicy, transferred into the button.
styleOwning normal/focused/disabled paint values.
policyOwning size policy, checked later by layout.
Exceptions
std::bad_allocIf text transfer or decoration storage cannot allocate; tree.emplace reports internal allocation failure as NO_MEMORY, excluding construction of its arguments.

◆ Button() [2/2]

portals::Button::Button ( GraphemeText text,
ControlStyle style,
SizePolicy policy,
ButtonChrome chrome )
Parameters
textOwning caption with its complete WidthPolicy.
styleOwning normal/focused/disabled appearances.
policyOwning layout constraints.
chromeBRACKETS or NONE; invalid enum values fail with INVALID_ARGUMENT during measure/paint. Construction may allocate; existing checked tree emplacement translates exceptions.

Member Function Documentation

◆ checked()

bool portals::Button::checked ( ) const
inline
Returns
Shared action selection presentation, false for an ordinary button.

◆ measure()

std::expected< CellSize, TreeError > portals::Button::measure ( CellSize available)
overridevirtual
Parameters
availableOffered extent, not used to truncate intrinsic caption measurement.
Returns
Caption/decorations size, INVALID_ARGUMENT for invalid chrome, or Control measurement failure.

Reimplemented from portals::Widget.

Reimplemented in portals::KeyHints.

◆ paint()

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

Paint bracket chrome at the allocated edges with a centered, independently clipped caption.

Parameters
contextBorrowed synchronous sink; text borrows and sink exceptions follow Control::paint.
Returns
Success, invalid chrome/geometry, or the sink's unchanged TreeError.
Note
NONE chrome retains the intrinsic caption presentation. In widths below four cells, brackets take priority over the caption; a single cell can show only the opening bracket.

Reimplemented from portals::Widget.

Reimplemented in portals::KeyHints.


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