Base class for Panels and Containers in a window layout tree.
An AppCore window arranges web views and native drawing regions into a tree of rows and columns, where each node shares space along its parent container's axis. LayoutNode represents an individual element in that hierarchy, whether it's a Container grouping child nodes or a Panel hosting a single View.
You use node handles to manage panes and containers dynamically at runtime, adapting the interface without rebuilding the layout tree.
This helper toggles a sidebar panel on and off:
if (sidebar->is_hidden())
sidebar->Show();
else
sidebar->Hide();
}
A nullable smart pointer.
Definition RefPtr.h:126
Showing and Hiding
Calling Hide() takes a node off screen and redistributes its space to sibling nodes, and Show() restores the node at its remembered size.
Hiding affects different node types:
- Hiding a Container hides its entire subtree.
- Hiding a Panel suspends its hosted View. Painting and animations pause, and the page receives a visibilitychange event.
Declared Sizes
Call SetSize(), SetMinSize(), or SetMaxSize() to update a node's declared size constraints at runtime. In a resizable container, double-clicking an adjacent divider restores both neighboring panes to the declared sizes set here (discarding any divider drags made since).
Layout Geometry
Accessors report layout rectangles across different coordinate spaces:
- bounds() returns container-local logical pixels.
- device_bounds() returns window back-buffer device pixels. Native rendering passes use this coordinate space to draw beneath or above web content.
Both rectangles remain zero until the window completes its first layout pass. Calling SetSize() queues a layout pass for an upcoming frame.
This registration reads the updated dimensions once the layout pass completes:
sidebar->SetSize("320px");
on_resize_ = sidebar->OnLayoutChange([](
LayoutNode& node) {
Log(
"sidebar is now " + std::to_string(node.
bounds().
width()) +
"px wide");
});
Base class for Panels and Containers in a window layout tree.
Definition LayoutNode.h:108
virtual Rect bounds() const =0
Get the node's rect from the most recent layout in container-local logical pixels (the same space Set...
float width() const
Definition Geometry.h:428
Callback registrations report geometry changes:
- OnLayoutChange() fires when layout changes the node's bounds. It runs at most once per frame after the layout pass completes.
- OnUserResize() fires when a user resizes the node with a divider. It fires on drag release and after a double-click restores declared sizes, only when the node's size changed.
Both methods return a LayoutCallback that manages the registration (destroying it unregisters the callback).
Node Lifetimes and Handles
A handle never keeps its node or its window alive (releasing one doesn't remove the node from the layout tree). To remove a node, call Container::Remove() or Foreground::Remove().
After a node is removed or its window closes, handles remain safe to call. Mutations do nothing, and accessors return safe fallback values.
Adding a child to a removed container or a closed window logs a warning and returns a handle that isn't attached to any window.
- Note
- A View kept after its panel is removed loses its listeners– register them again after adopting it into another panel.
- See also
- Panel, Container, Container::Remove(), Foreground::Remove(), LayoutCallback
|
| virtual String | key () const =0 |
| | Get the node's key (empty if unkeyed).
|
| virtual RefPtr< Container > | parent () const =0 |
| | Get the node's parent container (null at the root or when detached).
|
| virtual int | index () const =0 |
| | Get the node's index within its parent (-1 when detached).
|
| virtual RefPtr< Panel > | AsPanel ()=0 |
| | Get this node as a Panel (null if it is not one).
|
| virtual RefPtr< Container > | AsContainer ()=0 |
| | Get this node as a Container (null if it is not one).
|
| virtual void | Hide ()=0 |
| | Hide the node and redistribute its space to its siblings.
|
| virtual void | Show ()=0 |
| | Show the node again, restoring its remembered size exactly.
|
| virtual bool | is_hidden () const =0 |
| | Whether or not the node is hidden.
|
| virtual Rect | bounds () const =0 |
| | Get the node's rect from the most recent layout in container-local logical pixels (the same space SetBounds() takes).
|
| virtual IntRect | device_bounds () const =0 |
| | Get the node's rect from the most recent layout in window back-buffer device pixels (the space your own drawing uses).
|
| virtual void | SetBounds (const Rect &bounds)=0 |
| | Place this node manually.
|
| virtual void | SetSize (Size size)=0 |
| | Set the node's declared size along its container's axis.
|
| virtual void | SetMinSize (Length min_size)=0 |
| | Set the node's minimum size constraint.
|
| virtual void | SetMaxSize (Length max_size)=0 |
| | Set the node's maximum size constraint.
|
| virtual LayoutCallback | OnUserResize (LayoutNodeCallback callback, void *user_data, LayoutDestroyUserDataCallback destroy_user_data)=0 |
| | Register a callback fired when the user resizes this node with a divider.
|
| virtual LayoutCallback | OnLayoutChange (LayoutNodeCallback callback, void *user_data, LayoutDestroyUserDataCallback destroy_user_data)=0 |
| | Register a callback that fires after layout changes this node's bounds (at most once per frame).
|
template<typename Callback>
requires std::invocable<Callback&, LayoutNode&> || std::invocable<Callback&> |
| LayoutCallback | OnUserResize (Callback callback) |
| | Register a user-resize callback (invocable form).
|
template<typename Callback>
requires std::invocable<Callback&, LayoutNode&> || std::invocable<Callback&> |
| LayoutCallback | OnLayoutChange (Callback callback) |
| | Register a layout-change callback (invocable form).
|
| RefPtr< LayoutNode > | next_sibling () const |
| | Get the sibling after this node (null at the end, at the root, or when detached).
|
| RefPtr< LayoutNode > | previous_sibling () const |
| | Get the sibling before this node (null at the start, at the root, or when detached).
|
| virtual void | AddRef () const =0 |
| | Increment the reference count (thread-safe).
|
| virtual void | Release () const =0 |
| | Decrement the reference count (thread-safe).
|
| virtual int | ref_count () const =0 |
| | Get the current reference count.
|
| virtual WeakControlBlock * | weak_control_block () const |
| | Get the control block used to track weak references to this object.
|