ZenitUI
Retained-mode C++20 UI framework
Loading...
Searching...
No Matches
ZenitUI::Layout Class Reference

The base node type: tree, style, layout, input, scroll, render. More...

#include <Layout.hpp>

Inheritance diagram for ZenitUI::Layout:
[legend]

Classes

struct  ResolvedBgTexture
 Result of resolveBgTexture: a texture plus its nine-slice insets. More...

Public Member Functions

 Layout (LayoutType type=LayoutType::Stack)
 Construct a node with the given layout strategy.
virtual ~Layout ()
 Destroy the node and clean up framework-side references.
template<typename T = Layout>
std::shared_ptr< T > as ()
 static_pointer_cast helper returning shared_ptr<T>.
void addClass (const std::string &className)
 Add a class name to the node's style class list.
void removeClass (const std::string &className)
 Remove a class name; no-op if absent.
void clearStyleClasses ()
 Remove every class name.
void setStyleTag (const std::string &t)
 Set the node's style tag.
bool hasClass (const std::string &className) const
 true if the node has the given class.
bool hasId (const std::string &targetId) const
 true if the node's nodeId equals targetId.
void setId (const std::string &node_id)
 Set the node's #id (used in selectors and by UINode::find).
void setRef (const std::string &r)
 Set the node's @ref (used by UINode::ref / refAll).
const std::string & getStyleTag () const
const std::vector< std::string > & getStyleClasses () const
void setSize (Value w, Value h)
 Convenience: set explicit width and height.
std::shared_ptr< Layout > cls (const std::string &className)
 Fluent addClass; returns shared_from_this().
std::shared_ptr< Layout > id (const std::string &node_id)
 Fluent setId; returns shared_from_this().
std::shared_ptr< Layout > size (Value w, Value h)
 Fluent setSize; returns shared_from_this().
std::shared_ptr< Layout > with (std::shared_ptr< Layout > child)
 Fluent addChild; returns shared_from_this().
void addChild (std::shared_ptr< Layout > child)
 Append child to this node's child list.
void insertChildBefore (const Layout *anchor, std::shared_ptr< Layout > child)
 Insert child immediately before anchor (or append if anchor is not found).
bool moveChildBefore (const Layout *anchor, const Layout *child)
 Reposition an existing direct child immediately before anchor (or at the end if anchor is not found) without detaching its UIContext.
bool removeChild (const Layout *child)
 Synchronously detach a single direct child, clearing its parent pointer.
virtual Layout * contentTarget ()
 Return the node that receives children when built from markup.
void removeFromParent ()
 Request removal at the next culling pass.
virtual void removeAllChildren ()
 Detach every child immediately, clearing their parent pointers.
void retainObject (std::shared_ptr< void > obj)
 Retain an arbitrary type-erased object for the lifetime of this node.
std::shared_ptr< Layout > getParent () const
bool hasParent () const
bool isAncestorOf (const Layout *other) const
 true if this node is an ancestor of other.
void setInteractive (bool interactive)
void setBlocksRaycast (bool blocks)
void setEnabled (bool e)
 Enable or disable the node.
bool getEnabled () const
void setVisible (bool v)
 Show or hide the node (display: none semantics).
bool isVisible () const
void setChecked (bool c)
 Set the :checked pseudo-class state.
bool getChecked () const
bool isHoveredState () const
bool isPressedState () const
bool isFocusedState () const
bool isDisabledState () const
bool isCheckedState () const
void setUpdateWhenDisabled (bool v)
bool getUpdateWhenDisabled () const
void beginTransition ()
 Restart the current style transition from the current value.
void setFocusable (bool f)
bool isFocusable () const
bool getFocused () const
void setFocusScope (bool s)
bool isFocusScope () const
void notifyDescendantFocused (Layout *descendant)
 Notify the node that one of its descendants gained focus.
bool isStackingContext () const
 true if the node has a non-static position and a non-auto zIndex.
int getZIndex () const
 Effective zIndex; returns 0 for the "auto" case.
bool isScrollContainer () const
 true if either overflow axis is non-visible.
void scrollTo (float x, float y)
 Set the scroll offset, clamped to the valid range.
void scrollToX (float x)
void scrollToY (float y)
void scrollToTop ()
void scrollToBottom ()
void scrollToLeft ()
void scrollToRight ()
bool scrollIntoView (float margin=0.0f)
 Scroll the nearest scrolling ancestor so that this node's rect becomes visible, respecting margin.
bool scrollIntoView (const Rect &subRect, float margin=0.0f)
 Scroll the nearest scrolling ancestor so that subRect becomes visible, respecting margin.
float getScrollX () const
float getScrollY () const
float getMaxScrollX () const
float getMaxScrollY () const
void setPortal (bool p)
 Enable or disable portal rendering for this node.
bool isPortal () const
void setPassThrough (bool p)
bool getPassThrough () const
void setDraggable (bool d)
bool isDraggable () const
void setDroppable (bool d)
bool isDroppable () const
DragHandlers & drag ()
 Access Drag & Drop callbacks for this node, allocating storage lazily on first call.
const DragHandlers * dragHandlers () const noexcept
 Non-allocating read access to Drag & Drop callbacks, or nullptr if none were set.
void capturePointer ()
 Capture the pointer: all subsequent input events go to this node.
void releasePointer ()
 Release the pointer capture if this node owns it.
bool hasPointerCapture () const
 true if this node currently holds the pointer capture.
void setKeyboardActivates (bool v)
bool getKeyboardActivates () const
LayoutType getLayoutType () const
LayoutType getEffectiveLayoutType () const
FontHandle resolveFont (const ComputedStyle &style, FontHandle fallback={}) const
 Resolve a FontHandle from the node's style font stack.
ResolvedBgTexture resolveBgTexture (const ComputedStyle &style, TextureHandle fallbackTex={}, NineSlice fallbackSlice={0, 0, 0, 0})
 Resolve the background texture from the style, falling back to explicit parameters if the style has no background-texture.
void setInlineBase (const Style &s)
 Overlay s onto the node's inline style (highest priority).
Style & getInlineBase ()
 Direct mutable access to the inline style.
Style & getInlineDefaults ()
 Direct mutable access to the inline defaults (lowest-priority inline).
void addAnimation (const std::string &name, std::shared_ptr< UIAnimation > anim)
 Register an imperative animation under name.
void playAnimation (const std::string &name, bool playReverse=false)
 Start (or restart) the imperative animation named name.
bool hasActiveAnimations () const
 true if this node or any descendant is currently animating.
void addCssAnimation (const std::string &name)
 Manually start a CSS animation by name.
void stopCssAnimation (const std::string &name)
 Mark the named CSS animation as finished.
virtual Vec2 measure (float parent_w, float parent_h)
 Compute the intrinsic size given available space.
virtual void arrange (Rect space)
 Assign a screen rect to this node and lay out its children.
virtual void update (float dt, bool ancestorBlocked=false, bool scrolling=false)
 Per-frame update: input, style, animation, then recurse into children.
virtual void draw (float parentOpacity=1.0f)
 Draw the node and its children.
Layout * hitTest (Vec2 p, bool ancestorBlocked=false, const Rect *clipLocal=nullptr)
 Hit-test a point against this subtree.
Layout * hitTestDroppable (Vec2 p, const DragPayload &payload, const Layout *excludeSource, const Layout *excludeGhost, const Rect *clipLocal=nullptr)
 Hit-test a point against droppable nodes during an active drag (§5.22b).
void updateTree (float dt)
 Root-of-tree update: refresh pointer state and recurse.
void runFrame (float dt)
 Run one full frame: update, measure, arrange.
void renderFrame ()
 Render the current state: beginFrame, draw, endFrame.
Rect getRect () const
Vec2 getMeasuredSize () const
const ComputedStyle & getStyle () const
std::vector< const ThemeRule * > getMatchingRules () const
 Return the stylesheet theme of the active UIContext.
UIContext * contextPtr () const
 Return the UIContext this node is attached to, or nullptr if unmounted.
UIContext * context () const
 Return the UIContext this node is attached to, or nullptr if unmounted.
void attachContext (UIContext *newCtx)
 Attach this node and its subtree to newCtx.
void detachContext ()
 Detach this node and its subtree from its current UIContext.
Vec2 viewportSize () const
 Return the logical viewport size of this node's UIContext (or {0, 0} if unmounted).
const Theme & theme () const
 Return the stylesheet theme of this node's UIContext (or an empty theme if unmounted).
void setBackgroundTexture (TextureHandle tex, NineSlice np={0, 0, 0, 0})
 Override the background texture with a direct handle.
void setShader (EffectHandle shader)
 Set a custom shader effect applied to the node's content.
void invalidateLayerCache ()
 Mark any cached off-screen filter layer on this node and its ancestors as dirty so it is re-baked on the next draw pass.
void resetInteractionState ()
 Reset transient interaction state (hovered, pressed, focused, capture, and current UIState) across this subtree, firing onHoverExit if currently hovered.
void snapStyleImmediate ()
 Immediately resolve style rules and clear pending transitions across this subtree so recycled nodes position and style on the same frame.

Public Attributes

std::function< void()> onHoverEnter
std::function< void()> onHoverExit
std::function< void()> onPress
std::function< void()> onRelease
std::function< void()> onClick
std::function< void()> onRightClick
 Right-click hook; fires on right-button press over the node.
std::function< void(MouseButton)> onButtonPress
std::function< void(MouseButton)> onButtonRelease
std::function< void(MouseButton)> onButtonClick
std::function< void()> onAnimationsFinished
 Called when the node had active local animations and now has none.
std::vector< std::shared_ptr< Layout > > children
 Children of this node.
std::string nodeId
 #id for selector matching and UINode::find.
std::string ref
 @ref for UINode::ref / refAll lookup.

Protected Member Functions

void invalidateIfRelevant (SimpleSelector::Kind kind, std::string_view name)
 Propagate a class/tag change to descendants that may match it.
void invalidateStyleCacheRecursive ()
 Mark the whole subtree as needing style re-resolution.
void invalidateFollowingSiblings (SimpleSelector::Kind kind, std::string_view name)
void invalidateFollowingSiblingsCache ()
void invalidateChildrenForSiblingRules ()
Style partStyle (const std::string &partName)
 Resolve the style for pseudo-element partName.
virtual Vec2 computeIntrinsicSize (float, float)
 Compute the intrinsic size, excluding padding and border.
virtual void onLayout ()
 Called after arrange assigns the node's rect.
virtual void onUpdate (float)
 Called every frame from update, after input dispatch.
virtual void onEnabledChanged (bool)
 Called from setEnabled after the state change.
virtual void onCheckedChanged (bool)
 Called from setChecked after the checked state changes.
virtual void onDetachContext (UIContext *)
 Called from detachContext() right before clearing ctx_.
EffectHandle resolveActiveEffect ()
 Resolve the currently active effect handle.
virtual void renderContent (float, const ComputedStyle &)
 Draw the node's content (text, images, custom geometry).
virtual void renderChrome (float op, const ComputedStyle &style)
 Draw the node's background, border, and shadow.
virtual void onDescendantFocused (Layout *)
 Called on ancestors when a descendant gains focus.
void arrangeInto (Rect space)
 Dispatch to the layout-type-specific arrange helper.
Transform2D currentTransform (const ComputedStyle &style) const
 Compute the current transform from the style's translateX/translateY/rotation/scale.
virtual void translateSubtree (float dx, float dy)
 Translate the subtree (children and their descendants) by (dx, dy).

Friends

struct StyleResolver
struct AnimationPlayer
struct InputController
struct ScrollController

Detailed Description

The base node type: tree, style, layout, input, scroll, render.

See the file-level documentation for a description of the four main passes and the composition points for subclasses.

Note
Layout is not intended to be instantiated directly in user code; use std::make_shared<Layout> for layout containers (VStack, HStack, Stack) or TLayout<Derived>::create for custom components.
Examples
00_demo/main.cpp, and 11_animations/main.cpp.

Constructor & Destructor Documentation

◆ Layout()

ZenitUI::Layout::Layout ( LayoutType type = LayoutType::Stack)
inline

Construct a node with the given layout strategy.

Defaults: interactive = 1, enabled = 1, subtreeDirty = 1, pendingTransition = 1. Style is lazily initialized on first update / measure.

◆ ~Layout()

virtual ZenitUI::Layout::~Layout ( )
inlinevirtual

Destroy the node and clean up framework-side references.

Clears the global pointers (pressTarget, releaseTarget, topmostConsumer, hoverTarget) if they pointed to this node, and releases any render targets owned by a layer draw.

Does not detach children: the parent owns children via shared_ptr, so a child's lifetime is tied to the parent unless reparented.

Member Function Documentation

◆ addAnimation()

void ZenitUI::Layout::addAnimation ( const std::string & name,
std::shared_ptr< UIAnimation > anim )
inline

Register an imperative animation under name.

Does not start it; call playAnimation after registering. The animation object is shared, so it can be played simultaneously on multiple nodes.

◆ addChild()

void ZenitUI::Layout::addChild ( std::shared_ptr< Layout > child)
inline

Append child to this node's child list.

Sets child->parent to a weak reference of this node and marks the style as pending. Logs a warning and returns early if the node is not owned by a shared_ptr (i.e. weak_from_this() is expired).

◆ addClass()

void ZenitUI::Layout::addClass ( const std::string & className)

Add a class name to the node's style class list.

No-op if the class is already present. Invalidates the style cache and propagates the change to descendants that might match rules with this class in their selector chain (via invalidateIfRelevant).

◆ addCssAnimation()

void ZenitUI::Layout::addCssAnimation ( const std::string & name)
inline

Manually start a CSS animation by name.

Usually unnecessary: CSS animations are driven by the animations field of the resolved style and synced automatically. Provided for debug and for imperative overrides.

◆ arrange()

virtual void ZenitUI::Layout::arrange ( Rect space)
virtual

Assign a screen rect to this node and lay out its children.

For scroll containers, this triggers a full re-arrange when needed, then applies the scroll offset delta. Otherwise, it delegates to arrangeInto (the flex/stack flow dispatch).

Reimplemented in ZenitUI::UI::Dropdown, and ZenitUI::UI::SplitPane.

◆ arrangeInto()

void ZenitUI::Layout::arrangeInto ( Rect space)
protected

Dispatch to the layout-type-specific arrange helper.

Computes padding / border, then calls arrangeAbsoluteAndPortals for out-of-flow children and then one of:

  • arrangeVerticalFlow for Vertical
  • arrangeHorizontalFlow (or arrangeWrapFlow if wrap) for Horizontal
  • arrangeStackFlow for Stack

◆ as()

template<typename T = Layout>
std::shared_ptr< T > ZenitUI::Layout::as ( )
inline

static_pointer_cast helper returning shared_ptr<T>.

Convenience for std::static_pointer_cast<T>(shared_from_this()). No runtime type check; use with care if the dynamic type is not known.

◆ beginTransition()

void ZenitUI::Layout::beginTransition ( )
inline

Restart the current style transition from the current value.

Resets transitionTimer to 0 and re-snapshots the start style. Equivalent to StyleResolver::beginStateTransition for the current state, but without changing the state.

◆ capturePointer()

void ZenitUI::Layout::capturePointer ( )
inline

Capture the pointer: all subsequent input events go to this node.

Capture is released automatically on button-up (Layout::updateTree) or when the node is disabled / destroyed. Only one node can hold capture at a time; capturing overrides any previous owner.

◆ clearStyleClasses()

void ZenitUI::Layout::clearStyleClasses ( )

Remove every class name.

Equivalent to calling removeClass for each.

◆ computeIntrinsicSize()

virtual Vec2 ZenitUI::Layout::computeIntrinsicSize ( float ,
float  )
inlineprotectedvirtual

Compute the intrinsic size, excluding padding and border.

Called from measure with the available inner size. Subclasses override to report content-dependent sizing (text extents, image dimensions, etc.). Default: {0, 0} (size to zero content).

Reimplemented in ZenitUI::UI::Checkbox, ZenitUI::UI::ProgressBar, ZenitUI::UI::Slider, ZenitUI::UI::SplitPane, ZenitUI::UI::Text, ZenitUI::UI::TextArea, and ZenitUI::UI::TextInput.

◆ contentTarget()

virtual Layout * ZenitUI::Layout::contentTarget ( )
inlinevirtual

Return the node that receives children when built from markup.

Components that wrap their content in a sub-layout (e.g. Modal keeps its children inside content) override this to point at the wrapper. Default: this.

Reimplemented in ZenitUI::UI::MenuItem, ZenitUI::UI::Modal, ZenitUI::UI::Table, ZenitUI::UI::TabView, and ZenitUI::UI::TreeItem.

◆ draw()

virtual void ZenitUI::Layout::draw ( float parentOpacity = 1.0f)
virtual

Draw the node and its children.

Applies style overlays (CSS animations, if any), then dispatches to drawInline or drawLayer depending on whether the node has filters that need a layer pass. After drawing, calls scroll_.drawScrollbar.

Root nodes also flush framePortals: portals that were registered during the tree walk are drawn at the root, above everything else.

Reimplemented in ZenitUI::UI::CanvasLayout.

◆ getInlineBase()

Style & ZenitUI::Layout::getInlineBase ( )
inline

Direct mutable access to the inline style.

Marks the style as pending on every call, so mutating the returned reference and then dropping it is safe (the next frame will re-resolve).

◆ getInlineDefaults()

Style & ZenitUI::Layout::getInlineDefaults ( )
inline

Direct mutable access to the inline defaults (lowest-priority inline).

Applied before theme rules; useful for overriding a component's hardcoded defaults without overriding user-supplied CSS.

◆ hitTest()

Layout * ZenitUI::Layout::hitTest ( Vec2 p,
bool ancestorBlocked = false,
const Rect * clipLocal = nullptr )

Hit-test a point against this subtree.

Traversal order matches paint order reversed: front-most first. Within a node, stacking-context children are checked before normal-flow children; negative-Z children last. The self-rect is checked after all children, so a child always wins over its parent.

Parameters
pPoint in screen space.
ancestorBlockedtrue if an ancestor already rejected the point.
clipLocalOptional clip rect in this node's local space.
Returns
The frontmost interactive (or blocksRaycast) node under p, or nullptr.

◆ hitTestDroppable()

Layout * ZenitUI::Layout::hitTestDroppable ( Vec2 p,
const DragPayload & payload,
const Layout * excludeSource,
const Layout * excludeGhost,
const Rect * clipLocal = nullptr )

Hit-test a point against droppable nodes during an active drag (§5.22b).

Traverses in reverse paint order (portals, positive Z, normal flow, negative Z), skipping excludeSource, excludeGhost, and their subtrees. Non-droppable nodes and droppables whose canAcceptDrop returns false do not block matching siblings behind them or droppable ancestors.

◆ invalidateIfRelevant()

void ZenitUI::Layout::invalidateIfRelevant ( SimpleSelector::Kind kind,
std::string_view name )
protected

Propagate a class/tag change to descendants that may match it.

Only descendants whose relevantSymbols_ list mentions the changed symbol are marked. If the theme version changed since the last refresh, every descendant is invalidated conservatively.

◆ invalidateLayerCache()

void ZenitUI::Layout::invalidateLayerCache ( )
inline

Mark any cached off-screen filter layer on this node and its ancestors as dirty so it is re-baked on the next draw pass.

Subclasses whose visual output can change without modifying style or layout (e.g. custom Canvas draws or blinking carets) should call this whenever their rendered pixels change.

◆ isAncestorOf()

bool ZenitUI::Layout::isAncestorOf ( const Layout * other) const
inline

true if this node is an ancestor of other.

Walks up from other->getParent(); this is an ancestor only if found strictly above other. Self is not an ancestor of self.

◆ measure()

virtual Vec2 ZenitUI::Layout::measure ( float parent_w,
float parent_h )
virtual

Compute the intrinsic size given available space.

Called bottom-up during measure. Subclasses override computeIntrinsicSize (which receives the available space after padding / border) rather than this method directly.

Parameters
parent_wAvailable width from the parent, in pixels.
parent_hAvailable height from the parent, in pixels.
Returns
The node's own measured size, including padding and border.

Reimplemented in ZenitUI::UI::MenuBar, ZenitUI::UI::Table, and ZenitUI::UI::TabView.

◆ moveChildBefore()

bool ZenitUI::Layout::moveChildBefore ( const Layout * anchor,
const Layout * child )

Reposition an existing direct child immediately before anchor (or at the end if anchor is not found) without detaching its UIContext.

Returns
true if child was found among direct children.

◆ onCheckedChanged()

virtual void ZenitUI::Layout::onCheckedChanged ( bool )
inlineprotectedvirtual

Called from setChecked after the checked state changes.

Reimplemented in ZenitUI::UI::Checkbox, and ZenitUI::UI::Toggle.

◆ onDetachContext()

virtual void ZenitUI::Layout::onDetachContext ( UIContext * )
inlineprotectedvirtual

Called from detachContext() right before clearing ctx_.

Reimplemented in ZenitUI::UI::CanvasLayout.

◆ onEnabledChanged()

virtual void ZenitUI::Layout::onEnabledChanged ( bool )
inlineprotectedvirtual

Called from setEnabled after the state change.

Reimplemented in ZenitUI::UI::Dropdown, ZenitUI::UI::SplitPane, ZenitUI::UI::TextArea, and ZenitUI::UI::TextInput.

◆ onLayout()

virtual void ZenitUI::Layout::onLayout ( )
inlineprotectedvirtual

Called after arrange assigns the node's rect.

Reimplemented in ZenitUI::UI::Text.

◆ onUpdate()

virtual void ZenitUI::Layout::onUpdate ( float )
inlineprotectedvirtual

◆ partStyle()

Style ZenitUI::Layout::partStyle ( const std::string & partName)
inlineprotected

Resolve the style for pseudo-element partName.

Delegates to StyleResolver::partFor. Parts are independent of the main style and have their own transition state.

◆ playAnimation()

void ZenitUI::Layout::playAnimation ( const std::string & name,
bool playReverse = false )
inline

Start (or restart) the imperative animation named name.

Parameters
nameName previously registered via addAnimation().
playReverseWhen true, plays from end to start.

◆ removeAllChildren()

virtual void ZenitUI::Layout::removeAllChildren ( )
virtual

Detach every child immediately, clearing their parent pointers.

Unlike removeFromParent, this is synchronous and does not defer. Overridden by components that cache child pointers (e.g. VirtualView clears its materialized list first).

◆ removeChild()

bool ZenitUI::Layout::removeChild ( const Layout * child)

Synchronously detach a single direct child, clearing its parent pointer.

Returns
true if child was found and removed.

◆ removeClass()

void ZenitUI::Layout::removeClass ( const std::string & className)

Remove a class name; no-op if absent.

Invalidates the style cache and propagates the change to relevant descendants, same as addClass.

◆ removeFromParent()

void ZenitUI::Layout::removeFromParent ( )
inline

Request removal at the next culling pass.

Does not detach immediately: Layout::cullRemovedChildren on the parent removes the node and its subtree on the next frame. This defers destruction to a safe point in the frame cycle.

◆ renderChrome()

virtual void ZenitUI::Layout::renderChrome ( float op,
const ComputedStyle & style )
protectedvirtual

Draw the node's background, border, and shadow.

The default implementation reads background, backgroundTexture, borderColor / borderWidth, boxShadow, and radius from the style and emits the corresponding draw calls. Subclasses with custom chrome can override, but should usually keep the default and add their rendering to renderContent.

◆ renderContent()

virtual void ZenitUI::Layout::renderContent ( float ,
const ComputedStyle &  )
inlineprotectedvirtual

Draw the node's content (text, images, custom geometry).

Called after renderChrome (background, border, shadow) and before children are drawn. The clip rect is already pushed if overflow requires it.

Reimplemented in ZenitUI::UI::Checkbox, ZenitUI::UI::ImageContainer, ZenitUI::UI::ProgressBar, ZenitUI::UI::Slider, ZenitUI::UI::SplitPane, ZenitUI::UI::Text, ZenitUI::UI::TextArea, and ZenitUI::UI::TextInput.

◆ resetInteractionState()

void ZenitUI::Layout::resetInteractionState ( )

Reset transient interaction state (hovered, pressed, focused, capture, and current UIState) across this subtree, firing onHoverExit if currently hovered.

Used when recycling rows in VirtualList.

◆ resolveActiveEffect()

EffectHandle ZenitUI::Layout::resolveActiveEffect ( )
inlineprotected

Resolve the currently active effect handle.

Prefers the style's effect over the setShader override. Returns an invalid handle if neither is set.

◆ resolveFont()

FontHandle ZenitUI::Layout::resolveFont ( const ComputedStyle & style,
FontHandle fallback = {} ) const
inline

Resolve a FontHandle from the node's style font stack.

Parameters
styleComputed style carrying the font field.
fallbackReturned if the stack is empty or resolution fails.

◆ retainObject()

void ZenitUI::Layout::retainObject ( std::shared_ptr< void > obj)
inline

Retain an arbitrary type-erased object for the lifetime of this node.

Lazily allocates storage on first call (zero heap overhead for nodes that do not retain objects). Used by ZMarkup to tie a BuildContext (and its Bindable subscriptions) to the root node without cycles.

◆ scrollIntoView() [1/2]

bool ZenitUI::Layout::scrollIntoView ( const Rect & subRect,
float margin = 0.0f )

Scroll the nearest scrolling ancestor so that subRect becomes visible, respecting margin.

Only one ancestor is adjusted (the first scrolling ancestor). For nested scroll views, callers must iterate manually or call this on each level.

Returns
true if the offset changed.

◆ scrollIntoView() [2/2]

bool ZenitUI::Layout::scrollIntoView ( float margin = 0.0f)

Scroll the nearest scrolling ancestor so that this node's rect becomes visible, respecting margin.

Returns
true if the offset changed.
See also
scrollIntoView(const Rect&, float)

◆ scrollTo()

void ZenitUI::Layout::scrollTo ( float x,
float y )
inline

Set the scroll offset, clamped to the valid range.

No-op if the node is not a scroll container. The change is applied to the subtree via ScrollController::applyOffsetDelta on the next arrange pass.

◆ setBackgroundTexture()

void ZenitUI::Layout::setBackgroundTexture ( TextureHandle tex,
NineSlice np = {0, 0, 0, 0} )
inline

Override the background texture with a direct handle.

Takes precedence over the style's background-texture field. Used by ImageContainer and components that set the texture at runtime.

◆ setChecked()

void ZenitUI::Layout::setChecked ( bool c)
inline

Set the :checked pseudo-class state.

Used by Checkbox, Toggle, and any component that wants a :checked style rule to fire. Marks the style pending.

◆ setEnabled()

void ZenitUI::Layout::setEnabled ( bool e)

Enable or disable the node.

Disabling a node releases focus and pointer capture, fires onEnabledChanged(false), and forces UIState::Disabled. Input to the subtree is suppressed by Layout::update via the ancestorBlocked chain.

◆ setPortal()

void ZenitUI::Layout::setPortal ( bool p)
inline

Enable or disable portal rendering for this node.

Portals draw at the root and hit-test above everything else. Used by Dropdown, Popup, Tooltip and any component that must escape its ancestors' clip rect.

◆ setShader()

void ZenitUI::Layout::setShader ( EffectHandle shader)
inline

Set a custom shader effect applied to the node's content.

Composed on top of any effect from the style. Both are pushed during drawInline / drawLayer when the renderer supports Feature::Effects.

◆ setStyleTag()

void ZenitUI::Layout::setStyleTag ( const std::string & t)

Set the node's style tag.

The tag is matched against SimpleSelector::Kind::Tag in the stylesheet. Changing the tag invalidates both the old and new tag rules for every descendant.

◆ setVisible()

void ZenitUI::Layout::setVisible ( bool v)

Show or hide the node (display: none semantics).

Hidden nodes take zero space, do not contribute to parent gap or flex distribution, are skipped by draw, hitTest, and Tab focus traversal, and release focus/capture if held by this subtree.

◆ translateSubtree()

virtual void ZenitUI::Layout::translateSubtree ( float dx,
float dy )
protectedvirtual

Translate the subtree (children and their descendants) by (dx, dy).

Used by the scroll fast path. Portals are skipped: their position is independent of the scroll container.

Reimplemented in ZenitUI::UI::Dropdown.

◆ update()

virtual void ZenitUI::Layout::update ( float dt,
bool ancestorBlocked = false,
bool scrolling = false )
virtual

Per-frame update: input, style, animation, then recurse into children.

This is where the frame begins for a subtree. The recursion passes down two propagated flags:

  • ancestorBlocked: any ancestor disabled, animating a blocking animation, or non-interactive with blocksRaycast on.
  • ancestorScrolling: any ancestor is scrolling; children freeze their hover/press state so a drag does not flicker buttons.

After the recursion, the node fires its own input callbacks, its own onUpdate, and culling of any child that set wantsRemoval.

◆ updateTree()

void ZenitUI::Layout::updateTree ( float dt)

Root-of-tree update: refresh pointer state and recurse.

Entry point for the per-frame update. Handles hit-testing, focus acquisition/release, Tab-cycle focus navigation, and the pressTarget/releaseTarget bookkeeping that click dispatch depends on.

Member Data Documentation

◆ children

std::vector<std::shared_ptr<Layout> > ZenitUI::Layout::children

Children of this node.

Managed by addChild / cullRemovedChildren.

◆ onAnimationsFinished

std::function<void()> ZenitUI::Layout::onAnimationsFinished

Called when the node had active local animations and now has none.

Local means "on this node", not descendants. A parent can report finished while a child is still animating.


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