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

UI-owned style transaction coordinator; tree must outlive this nonmovable object. Bindings own metadata and only observe Node handles. Stale bindings are pruned on the next successful operation. Destruction leaves already computed widget values intact. One engine may own a widget's style at a time; overlapping engines are unsupported. No notifications, I/O, workers or hot reload. All mutations reject active frames and wrong-thread calls before work. More...

#include <style.hpp>

Public Member Functions

 StyleEngine (WidgetTree &tree, std::size_t maxBindings=4096, StyleRoleLimits roleLimits={})
 StyleEngine (const StyleEngine &)=delete
StyleEngine & operator= (const StyleEngine &)=delete
std::expected< Invalidation, StyleError > bind (Node< Widget > node, StyleTarget target)
 Register/update metadata and atomically recompute every bound widget.
std::expected< Invalidation, StyleError > bindBatch (std::span< const StyleRegistration > registrations)
 Update metadata in one transaction, then recompute every bound widget once. Duplicate input nodes return INVALID_ARGUMENT. Stale bindings are pruned before admission. Empty input performs the same refresh as refresh(). With index allocation available, identity lookup takes O((B + R) log(R + 2)) work and O(R) temporary space for B existing bindings and R input registrations. Metadata copies and style resolution are additional costs; existing callback order is preserved. If index allocation fails, an allocation-free O(R^2) validation preserves argument-error priority before returning NO_MEMORY for an otherwise valid batch.
std::expected< StyleRoleRegistration, StyleError > registerRoles (Node< Widget > node, std::span< const std::string_view > names)
 Register an existing bound node for a bounded semantic projection.
std::expected< StyleRoleRegistration, StyleError > registerRoles (Node< Widget > node, std::initializer_list< std::string_view > names)
std::expected< StyleRoleRegistration, StyleError > replaceRoles (const StyleRoleRegistration &registration, std::span< const std::string_view > names)
 Atomically replace the bounded names of a live semantic registration.
std::expected< StyleRoleRegistration, StyleError > replaceRoles (const StyleRoleRegistration &registration, std::initializer_list< std::string_view > names)
std::expected< Invalidation, StyleError > unregisterRoles (const StyleRoleRegistration &registration)
std::expected< Invalidation, StyleError > replace (StyleSheet sheet)
 Install a complete typed stylesheet atomically between frames.
std::expected< Invalidation, StyleError > replacePss (std::string_view source)
 Parse and install without ever exposing a partial stylesheet.
std::expected< Invalidation, StyleError > refresh ()
 Recompute against current manual widget options, between frames.
std::uint64_t revision () const noexcept
 Inspect on UI; no allocation or tree access.
std::expected< Invalidation, StyleError > enableLayers (StyleLayerOptions options={})
 Enable owning tiers atomically; equal configuration is a no-op.
std::expected< StyleLayerHandle, StyleError > addLayer (StyleTier tier, std::string_view name, const StyleSheet &sheet)
 Install an owning APPLICATION or USER layer with a unique tier name.
std::expected< Invalidation, StyleError > replaceLayer (StyleLayerHandle handle, const StyleSheet &sheet)
 Replace a non-base layer while retaining its installation order.
std::expected< Invalidation, StyleError > removeLayer (StyleLayerHandle handle)
 Remove declarations; base slots remain and revoke their owner.
std::expected< Invalidation, StyleError > updateLayers (std::span< const StyleLayerUpdate > updates)
 Atomically update existing unique handles. Empty input is a no-op.
std::expected< StyleLayerHandle, StyleError > baseLayer (StyleTier tier) const
 Observe one permanent base slot on its UI thread.
std::expected< Invalidation, StyleError > defaults (const StyleSheet &sheet)
 Replace the DEFAULTS slot beneath all other layers.
std::expected< Invalidation, StyleError > theme (const StyleSheet &sheet)
 Replace THEME and hand authority to the caller, including equal values.

Friends

class ManagedScene
struct StyleLayerTestAccess

Detailed Description

UI-owned style transaction coordinator; tree must outlive this nonmovable object. Bindings own metadata and only observe Node handles. Stale bindings are pruned on the next successful operation. Destruction leaves already computed widget values intact. One engine may own a widget's style at a time; overlapping engines are unsupported. No notifications, I/O, workers or hot reload. All mutations reject active frames and wrong-thread calls before work.

Constructor & Destructor Documentation

◆ StyleEngine()

portals::StyleEngine::StyleEngine ( WidgetTree & tree,
std::size_t maxBindings = 4096,
StyleRoleLimits roleLimits = {} )
explicit
Parameters
treeBorrowed UI owner, required to outlive the engine.
maxBindingsPositive registry budget; default matches the tree's default capacity.
roleLimitsExplicit opt-in counts; coherence is checked before role registration.

Member Function Documentation

◆ addLayer()

std::expected< StyleLayerHandle, StyleError > portals::StyleEngine::addLayer ( StyleTier tier,
std::string_view name,
const StyleSheet & sheet )

Install an owning APPLICATION or USER layer with a unique tier name.

Parameters
tierAPPLICATION or USER priority.
nameNonempty tier-unique name, normalized into ownership after budget admission.
sheetBorrowed declarations, copied after admission; input remains caller-owned.
Returns
Weak observer or atomic failure; destroying the observer leaves declarations installed.

◆ baseLayer()

std::expected< StyleLayerHandle, StyleError > portals::StyleEngine::baseLayer ( StyleTier tier) const

Observe one permanent base slot on its UI thread.

Parameters
tierDEFAULTS or THEME priority.
Returns
Weak observer or boundary/argument error; allocation-free.

◆ bind()

std::expected< Invalidation, StyleError > portals::StyleEngine::bind ( Node< Widget > node,
StyleTarget target )

Register/update metadata and atomically recompute every bound widget.

Parameters
nodeChecked target; no ownership transfer.
targetOwned matching metadata, copied during staging.
Returns
Coalesced invalidation, or error retaining every previous value and binding.

◆ bindBatch()

std::expected< Invalidation, StyleError > portals::StyleEngine::bindBatch ( std::span< const StyleRegistration > registrations)

Update metadata in one transaction, then recompute every bound widget once. Duplicate input nodes return INVALID_ARGUMENT. Stale bindings are pruned before admission. Empty input performs the same refresh as refresh(). With index allocation available, identity lookup takes O((B + R) log(R + 2)) work and O(R) temporary space for B existing bindings and R input registrations. Metadata copies and style resolution are additional costs; existing callback order is preserved. If index allocation fails, an allocation-free O(R^2) validation preserves argument-error priority before returning NO_MEMORY for an otherwise valid batch.

Parameters
registrationsBorrowed live targets and metadata, copied during staging.
Returns
Coalesced invalidation, or an error preserving all values, bindings and revisions.

◆ defaults()

std::expected< Invalidation, StyleError > portals::StyleEngine::defaults ( const StyleSheet & sheet)

Replace the DEFAULTS slot beneath all other layers.

Parameters
sheetBorrowed replacement declarations, copied only after budget admission.
Returns
Actual invalidation or atomic failure; layers must already be enabled.

◆ enableLayers()

std::expected< Invalidation, StyleError > portals::StyleEngine::enableLayers ( StyleLayerOptions options = {})

Enable owning tiers atomically; equal configuration is a no-op.

Parameters
optionsNonzero aggregate limits, including at least two layer slots.
Returns
Effective invalidation or atomic boundary/budget/identity/allocation failure.

◆ refresh()

std::expected< Invalidation, StyleError > portals::StyleEngine::refresh ( )

Recompute against current manual widget options, between frames.

Returns
Actual invalidation or error with no partial update.

◆ registerRoles() [1/2]

std::expected< StyleRoleRegistration, StyleError > portals::StyleEngine::registerRoles ( Node< Widget > node,
std::initializer_list< std::string_view > names )
inline
Parameters
nodeChecked live binding.
namesBorrowed names copied during this call.
Returns
Scoped registration or the exact checked registration failure.

◆ registerRoles() [2/2]

std::expected< StyleRoleRegistration, StyleError > portals::StyleEngine::registerRoles ( Node< Widget > node,
std::span< const std::string_view > names )

Register an existing bound node for a bounded semantic projection.

Parameters
nodeChecked live binding.
namesUnique lower-kebab names copied before publication.
Returns
Scoped owning registration, or atomic argument/budget/lifetime/allocation failure.

◆ removeLayer()

std::expected< Invalidation, StyleError > portals::StyleEngine::removeLayer ( StyleLayerHandle handle)

Remove declarations; base slots remain and revoke their owner.

Parameters
handleLive observer; removed non-base identities cannot be reused.
Returns
Actual invalidation or an error retaining all committed state.

◆ replace()

std::expected< Invalidation, StyleError > portals::StyleEngine::replace ( StyleSheet sheet)

Install a complete typed stylesheet atomically between frames.

Parameters
sheetOwned replacement rules; validation and staging precede commit.
Returns
Actual paint/layout invalidation, or error retaining sheet/revision/widget values.

◆ replaceLayer()

std::expected< Invalidation, StyleError > portals::StyleEngine::replaceLayer ( StyleLayerHandle handle,
const StyleSheet & sheet )

Replace a non-base layer while retaining its installation order.

Parameters
handleExisting non-base observer, admitted on the engine UI thread.
sheetBorrowed candidate; equal values allocate nothing and retain revision.
Returns
Actual invalidation or an error retaining all committed state.

◆ replacePss()

std::expected< Invalidation, StyleError > portals::StyleEngine::replacePss ( std::string_view source)

Parse and install without ever exposing a partial stylesheet.

Parameters
sourceBorrowed PSS; copied by parsing before the atomic commit.
Returns
Actual invalidation or source/tree error retaining the prior revision.

◆ replaceRoles() [1/2]

std::expected< StyleRoleRegistration, StyleError > portals::StyleEngine::replaceRoles ( const StyleRoleRegistration & registration,
std::initializer_list< std::string_view > names )
inline
Parameters
registrationLive registration owned by this engine.
namesBorrowed names copied during this call.
Returns
New scoped registration or the exact checked replacement failure.

◆ replaceRoles() [2/2]

std::expected< StyleRoleRegistration, StyleError > portals::StyleEngine::replaceRoles ( const StyleRoleRegistration & registration,
std::span< const std::string_view > names )

Atomically replace the bounded names of a live semantic registration.

Parameters
registrationLive registration owned by this engine; its participation must survive staging.
namesUnique nonempty lower-kebab names, copied before publication within the configured limits.
Returns
New scoped registration, retiring every copy of the old handle on success. Identical ordered names return shared participation without invalidation or a revision change. All checked failures preserve the previous registry, palettes, widget styles and revision. Retained old palette snapshots remain valid. Wrong-thread, active-frame, reentry, retired/foreign registration, stale node, argument, budget and allocation failures use the existing StyleError causes. No consumer callbacks run during publication.

◆ revision()

std::uint64_t portals::StyleEngine::revision ( ) const
noexcept

Inspect on UI; no allocation or tree access.

Returns
Last committed revision, initially zero; equal styles can still advance it.

◆ theme()

std::expected< Invalidation, StyleError > portals::StyleEngine::theme ( const StyleSheet & sheet)

Replace THEME and hand authority to the caller, including equal values.

Parameters
sheetBorrowed replacement, installed as the whole sheet in legacy mode.
Returns
Actual invalidation or atomic failure; failed changes never revoke prior authority.

◆ unregisterRoles()

std::expected< Invalidation, StyleError > portals::StyleEngine::unregisterRoles ( const StyleRoleRegistration & registration)
Parameters
registrationLive registration of this engine, retained by the caller.
Returns
One paint invalidation on success, or typed failure preserving the projection.

◆ updateLayers()

std::expected< Invalidation, StyleError > portals::StyleEngine::updateLayers ( std::span< const StyleLayerUpdate > updates)

Atomically update existing unique handles. Empty input is a no-op.

Parameters
updatesBorrowed complete batch; duplicate handles and base replacements are rejected.
Returns
Actual invalidation or an error retaining all declarations, bindings and identities.

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