docs
Loading...
Searching...
No Matches
Layout.h
Go to the documentation of this file.
1///
2/// Copyright (C) 2026 Ultralight, Inc. All rights reserved.
3/// A license is required for commercial use. https://ultralig.ht
4///
5/// @file Layout.h
6///
7/// Panels and containers for arranging web views across a window.
8///
9/// `#include <AppCore/Layout.h>`
10///
11/// The layout API arranges web content across an AppCore window using panels and containers. You
12/// declare sizes once, and the window recalculates the layout whenever it resizes or its display
13/// scale changes.
14///
15/// This example splits a window into a sidebar and a content pane:
16///
17/// ```
18/// RefPtr<Container> body = window->layout()->AddRow();
19/// RefPtr<Panel> sidebar = body->AddPanel({ .size = "240px" });
20/// RefPtr<Panel> content = body->AddPanel(); // takes the rest of the row
21///
22/// sidebar->view()->LoadURL("file:///sidebar.html");
23/// content->view()->LoadURL("file:///content.html");
24/// ```
25///
26/// ## The Layout Tree
27///
28/// A window's tiled layout forms a tree rooted at Window::layout(). The root container is a column
29/// that spans the window's content area, holding child Panel%s and nested row or column
30/// Container%s. Each Panel hosts one View, while containers manage the placement and sizing of
31/// their children.
32///
33/// Floating panels sit outside this tree in the window's Foreground layer, reached through
34/// Window::foreground(). They float above tiled panels without shifting the layout underneath,
35/// which suits overlays such as toasts, menus, and heads-up displays.
36///
37/// This diagram shows the relationship between a window, its tiled layout tree, and its floating
38/// layer:
39///
40/// ```text
41/// Window
42/// +- layout() Container (a column)
43/// | +- Panel View
44/// | +- Container (a row)
45/// | +- Panel View
46/// | +- Panel View
47/// +- foreground() Foreground
48/// +- Panel View
49/// ```
50///
51/// ## Where to Start
52///
53/// Choose the type that fits your layout task:
54///
55/// | Task | Type |
56/// |------------------------------------------|-----------------------|
57/// | Arrange views in rows or columns | Container |
58/// | Host an individual web view | Panel |
59/// | Float overlays above the layout | Foreground |
60/// | Track bounds or listen for resizes | LayoutNode |
61/// | Declare a whole layout in one expression | Window::BuildLayout() |
62///
63/// ## Rules for Layout Handles
64///
65/// Every container and panel handle follows these conventions:
66///
67/// - **Call layout methods only on the main thread.** Layout handles and tree mutations aren't
68/// thread-safe, so background threads must dispatch layout work through App::PostTask().
69/// - **A handle doesn't keep its node or window alive.** Releasing a handle leaves its node in the
70/// tree, while calls on a handle after its node is removed or its window closes do nothing (see
71/// LayoutNode).
72/// - **Changes apply together in one layout pass on an upcoming frame.** Geometry accessors like
73/// LayoutNode::bounds() report the updated layout once that pass completes.
74/// - **Mistakes log a warning rather than throwing.** Disallowed actions do nothing and write a
75/// warning to the log.
76///
77/// @note `<AppCore/Window.h>` already includes this header, so applications that create windows
78/// don't need to include `<AppCore/Layout.h>` directly.
79///
80/// @see Window::layout(), Window::foreground(), Window::BuildLayout()
81///
82#pragma once
Declarative functions for constructing layout trees.