docs
Docs
C++ API
C API
Search API
Ctrl K
2.0
2.0
latest
1.4
Ultralight C++ API
2.0.0
Toggle main menu visibility
Loading...
Searching...
No Matches
Panel.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
#pragma once
6
#include <
AppCore/layout/LayoutNode.h
>
7
#include <
Ultralight/View.h
>
8
9
namespace
ultralight
{
10
11
///
12
/// A layout node that hosts a single web view.
13
///
14
/// Panel%s are the leaf nodes of an AppCore layout tree and the elements of its floating layer.
15
/// Every panel hosts a single View, sizing the view to match its layout bounds and routing user
16
/// input to the page.
17
///
18
/// This example adds a panel to a window, loads a page into its view, and gives the panel keyboard
19
/// focus:
20
///
21
/// ```
22
/// RefPtr<Panel> content = window->AddPanel({ .key = "content" });
23
/// content->view()->LoadURL("file:///app.html");
24
/// content->Focus();
25
/// ```
26
///
27
/// ## Hosting a View
28
///
29
/// Call view() to access the hosted View.
30
///
31
/// You can create a panel with a new View or adopt an existing View:
32
///
33
/// - **New views come from AddPanel().** Calling Container::AddPanel(), Window::AddPanel(), or
34
/// Foreground::AddPanel() creates a panel alongside a fresh View configured for the parent
35
/// window.
36
/// - **Existing views are adopted into layout.** Calling Container::AdoptPanel() or
37
/// Foreground::AdoptPanel() creates a panel that hosts a View you created yourself, such as a
38
/// View created through a Session or one that survived removal from another panel.
39
///
40
/// @warning Never replace the editor listener on a panel's View. Replacing it disables the
41
/// window's input method support and stops Window::OnEditableStateChange() from firing
42
/// for that panel.
43
///
44
/// ## Keyboard Focus
45
///
46
/// A window directs keyboard events to one panel at a time:
47
///
48
/// - **Clicking a panel or calling Focus() grants keyboard focus.**
49
/// - **Never call View::Focus() on a panel's View.** Focusing the view directly bypasses the window
50
/// and prevents it from routing keyboard input to the active panel.
51
/// - **The window tracks the active panel.** Call Window::focused_panel() to retrieve the focused
52
/// panel, or listen for focus transitions with Window::OnFocusChange().
53
///
54
/// @note BringToFront() and OnDismiss() apply to floating panels only.
55
///
56
/// @see LayoutNode, Container::AddPanel(), Container::AdoptPanel(), Foreground,
57
/// Window::focused_panel(), Window::OnFocusChange()
58
///
59
class
AExport
Panel
:
public
LayoutNode
{
60
public
:
61
///
62
/// Get the hosted View.
63
///
64
/// @return Returns the hosted View, or null after the panel is removed or its window
65
/// closes.
66
///
67
/// @note For what happens to a View you hold after removal, see LayoutNode.
68
///
69
virtual
RefPtr<View>
view
() = 0;
70
71
///
72
/// Grant this panel exclusive keyboard focus.
73
///
74
/// You should always focus a panel through this method (or a user click) rather than
75
/// calling View::Focus() directly, otherwise the panel's window won't know where to route
76
/// keyboard input.
77
///
78
/// @note Focusing a hidden panel (or one inside a hidden container) is ignored with a
79
/// warning. So is focusing a floating panel created with FocusPolicy::None, which
80
/// never takes keyboard focus.
81
///
82
virtual
void
Focus
() = 0;
83
84
///
85
/// Bring this floating panel to the top of the foreground layer so it paints on top of other
86
/// floating panels and receives mouse input first.
87
///
88
/// @note This method only applies to floating panels. A tiled panel composites in tree order,
89
/// so calling BringToFront() on it does nothing and logs a warning.
90
///
91
virtual
void
BringToFront
() = 0;
92
93
///
94
/// Register a callback fired when the library dismisses this panel.
95
///
96
/// The library dismisses a panel when an auto-dismiss trigger fires on a floating panel
97
/// (see ForegroundPanelOptions). An application-initiated Hide() does not fire it.
98
///
99
/// @param callback The function to call. It receives `user_data` and this panel.
100
///
101
/// @param user_data Passed back to the callback on every fire (can be nullptr).
102
///
103
/// @param destroy_user_data Called once when the registration drops `user_data` (can be
104
/// nullptr).
105
///
106
/// @return Returns a LayoutCallback controlling how long the callback stays registered.
107
///
108
/// @note Callbacks must not let exceptions propagate.
109
///
110
[[nodiscard]]
virtual
LayoutCallback
OnDismiss
(
111
LayoutPanelCallback
callback,
void
* user_data,
112
LayoutDestroyUserDataCallback
destroy_user_data) = 0;
113
114
///
115
/// Register a dismiss callback (invocable form).
116
///
117
/// @param callback Any invocable. It may take the panel as `Panel&`, or nothing at all.
118
///
119
/// @return Returns a LayoutCallback controlling how long the callback stays registered.
120
///
121
template
<
typename
Callback>
122
requires
std::invocable<Callback&, Panel&> || std::invocable<Callback&>
123
[[nodiscard]]
LayoutCallback
OnDismiss
(Callback callback) {
124
auto
* holder =
new
Callback(std::move(callback));
125
LayoutPanelCallback
trampoline = [](
void
* user_data,
Panel
*
panel
) {
126
auto
& cb = *
static_cast<
Callback*
>
(user_data);
127
if
constexpr
(std::invocable<Callback&, Panel&>)
128
cb(*
panel
);
129
else
130
cb();
131
};
132
return
OnDismiss
(trampoline, holder,
133
[](
void
* user_data) {
delete
static_cast<
Callback*
>
(user_data); });
134
}
135
136
protected
:
137
virtual
~Panel
();
138
};
139
140
}
// namespace ultralight
AExport
#define AExport
Definition
Defines.h:41
LayoutNode.h
View.h
ultralight::LayoutCallback
Scoped handle that controls how long a layout callback stays registered.
Definition
Callback.h:144
ultralight::LayoutNode
Base class for Panels and Containers in a window layout tree.
Definition
LayoutNode.h:108
ultralight::Panel
A layout node that hosts a single web view.
Definition
Panel.h:59
ultralight::Panel::~Panel
virtual ~Panel()
ultralight::Panel::OnDismiss
virtual LayoutCallback OnDismiss(LayoutPanelCallback callback, void *user_data, LayoutDestroyUserDataCallback destroy_user_data)=0
Register a callback fired when the library dismisses this panel.
ultralight::Panel::view
virtual RefPtr< View > view()=0
Get the hosted View.
ultralight::Panel::Focus
virtual void Focus()=0
Grant this panel exclusive keyboard focus.
ultralight::Panel::BringToFront
virtual void BringToFront()=0
Bring this floating panel to the top of the foreground layer so it paints on top of other floating pa...
ultralight::Panel::OnDismiss
LayoutCallback OnDismiss(Callback callback)
Register a dismiss callback (invocable form).
Definition
Panel.h:123
ultralight::RefPtr
A nullable smart pointer.
Definition
RefPtr.h:126
ultralight
Root namespace for every public Ultralight type, function, and enumeration.
ultralight::LayoutPanelCallback
void(*) LayoutPanelCallback(void *user_data, Panel *panel)
Callback fired for a panel event.
Definition
Callback.h:49
ultralight::panel
PanelSpec panel(PanelOptions options={}, RefPtr< Panel > *out=nullptr)
Describe a panel in a builder expression (see Builder.h for an example).
Definition
Builder.h:90
ultralight::LayoutDestroyUserDataCallback
void(*) LayoutDestroyUserDataCallback(void *user_data)
Destroy hook for a callback registration's user data.
Definition
Callback.h:27
AppCore
layout
Panel.h
Docs
C++ API
C API
Version
2.0
2.0
latest
1.4