Skip to main content

kui_core/
ui.rs

1//! [`Ui`]: the frame builder a Rust view declares its tree through.
2//!
3//! A `Ui` borrows a [`Core`] for the length of one frame. It is a thin,
4//! safe facade over the core's flat builder methods (which are also the FFI
5//! surface): every call opens, fills or closes a node, or reads a fact the
6//! last frame established. It never captures app state, so `view(&state)`
7//! and `update(&mut state)` cannot conflict.
8//!
9//! The shape of a view: containers open with [`Ui::with`] (scoped) or
10//! [`Ui::open`]/[`Ui::close`], leaves with [`Ui::leaf`] and [`Ui::text`],
11//! and each node's look and behaviour is a [`NodeSpec`]. Nodes are keyed by
12//! position unless a `_keyed` or `_indexed` form gives them a stable
13//! identity, which anything retained across frames (focus, scrolling, an
14//! edit buffer, a transition) needs.
15//!
16//! ```rust
17//! use kui_core::{Color, Core, NodeSpec, Size, Sizing, TextStyle, widgets};
18//!
19//! let mut core = Core::new();
20//! let mut ui = core.frame(Size::new(400.0, 300.0), 1.0);
21//! let theme = ui.theme();
22//! ui.configure_root(NodeSpec::column().fill().pad(12.0).gap(8.0));
23//!
24//! // A toolbar: a row of buttons, keyed by their labels.
25//! ui.with(NodeSpec::row().gap(6.0), |ui| {
26//!     widgets::button(ui, "Open", "open");
27//!     widgets::button(ui, "Save", "save");
28//! });
29//!
30//! // A panel that grows to fill the rest, with a label in it.
31//! let panel = ui.with_keyed(
32//!     "panel",
33//!     NodeSpec::column().fill().pad(8.0).bg(theme.surface).radius(6.0),
34//!     |ui| {
35//!         ui.text("Ready.", TextStyle::new(14.0).color(theme.muted));
36//!         ui.leaf(NodeSpec::row().size(Sizing::GROW, 1.0).bg(Color::hex(0x80808080)));
37//!     },
38//! );
39//! assert!(!ui.is_hovered(panel)); // nothing has moved the pointer yet
40//! ui.finish();
41//! ```
42//!
43//! [`Ui::finish`] is the one way out of a frame: it runs layout and
44//! emission and leaves the results in [`Core::output`].
45
46use crate::edit::EditOptions;
47use crate::env::Env;
48use crate::geom::{Rect, Size, Vec2};
49use crate::key::Key;
50use crate::line::Stroke;
51use crate::runtime::Core;
52use crate::slot::{Fill, Slot};
53use crate::spec::{NodeSpec, TextStyle};
54use crate::text::Span;
55use crate::tree::OriginId;
56use crate::value::Value;
57use crate::window::{WindowCommand, WindowConfig, WindowId};
58
59pub struct Ui<'a> {
60    core: &'a mut Core,
61    /// What fills the slots this frame declares (`Core::frame_with`);
62    /// `None` for a frame begun without one, and inside a fill — an
63    /// extension's `slot` declares and fills nothing.
64    filler: Option<&'a mut dyn Fill>,
65}
66
67impl<'a> Ui<'a> {
68    pub(crate) fn new(core: &'a mut Core) -> Self {
69        Self { core, filler: None }
70    }
71
72    /// [`Self::wrap`] with something to fill the slots the frame declares
73    /// — for a frontend that drives `Core` directly and keeps an
74    /// extension list of its own (the C context, a headless Node one), so
75    /// its `slot` and `finish` are this type's rather than a copy of them.
76    pub fn with_filler(core: &'a mut Core, filler: &'a mut dyn Fill) -> Self {
77        Self {
78            core,
79            filler: Some(filler),
80        }
81    }
82
83    /// Escape hatch to the underlying core (e.g. for FFI view callbacks).
84    pub fn core(&mut self) -> &mut Core {
85        self.core
86    }
87
88    /// The inverse escape hatch: wraps a borrowed core mid-frame so foreign
89    /// frontends that drive `Core` directly (FFI, Node) can call `widgets::*`.
90    pub fn wrap(core: &'a mut Core) -> Self {
91        Self { core, filler: None }
92    }
93
94    /// Declares a slot here, with no parameters: whatever fills it draws
95    /// now, as children of the node this view is inside, at this
96    /// position among its siblings. `name` is the full name,
97    /// `namespace/slot` — the namespace the host gave the extension when
98    /// it loaded it, and the slot in the extension's own vocabulary
99    /// (`"fs/panel"`). `"ns/root"` is the fill that follows the host's
100    /// view for an extension listing no slots, and declaring it moves
101    /// that fill here.
102    pub fn slot(&mut self, name: &str) {
103        self.slot_with(name, &crate::slot::NULL_PARAMS);
104    }
105
106    /// `slot` with parameters the extension reads this frame
107    /// (`Slot::params`); a `Value` because it is the type that already
108    /// crosses to an extension. Nothing is retained — pass what is true
109    /// this frame, every frame.
110    ///
111    /// Whether the slot was declared: false for a name this frame already
112    /// declared (which warns, `duplicate-slot`) or outside a frame. True
113    /// whether or not anything filled it — a host with nothing loaded
114    /// still gets a placed, empty node to lay out around.
115    pub fn slot_with(&mut self, name: &str, params: &Value) -> bool {
116        let Some(key) = self.core.begin_slot(name) else {
117            return false;
118        };
119        if let Some(filler) = self.filler.as_deref_mut() {
120            filler.fill(name, key, params, &mut Ui::new(self.core));
121        }
122        true
123    }
124
125    /// Whether the full name `name` was declared this frame so far.
126    pub fn slot_declared(&self, name: &str) -> bool {
127        self.core.slot_declared(name)
128    }
129
130    /// Declares a devtools tab an extension fills: `name` is the tab's
131    /// identity, `label` what the strip shows,
132    /// `slot` the full slot name (`"ts/panel"`) the extension names.
133    /// While the tab is the one on show, the panel declares the slot in
134    /// the tab's body and the fill is drawn there; otherwise the slot is
135    /// not declared and the extension is not asked, though its naming
136    /// the slot raises no `unknown-slot`. Made every frame, panel on or
137    /// off. A name declared twice in a frame warns `duplicate-tab`.
138    pub fn devtools_tab(&mut self, name: &str, label: &str, slot: &str) {
139        self.core.devtools_tab_declare(name, label, Some(slot));
140    }
141
142    /// Declares a devtools tab the host draws itself, and draws it
143    /// **only when it is shown**: `f` runs
144    /// when the panel is on, docked in this window, and `name` is the
145    /// tab on show — otherwise this declares and returns, and the tab
146    /// costs nothing. What `f` builds is the host's: its keys, labels
147    /// and origin, its events reaching the host untouched — laid out
148    /// and painted as a layer over the panel's tab body, clipped to it,
149    /// in the dock's focus region. The panel's facts are read through
150    /// `devtools_selected` and its siblings.
151    pub fn devtools_tab_with(&mut self, name: &str, label: &str, f: impl FnOnce(&mut Ui<'_>)) {
152        if !self.core.devtools_tab_declare(name, label, None) {
153            return;
154        }
155        if !self.core.devtools_tab_shown(name) {
156            return;
157        }
158        self.core.devtools_tab_open(name);
159        f(self);
160        self.core.close();
161    }
162
163    /// Whether the host form of tab `name` is shown this frame — what
164    /// `devtools_tab_with` asks before running its closure, for a caller
165    /// that builds the content some other way.
166    pub fn devtools_tab_shown(&self, name: &str) -> bool {
167        self.core.devtools_tab_shown(name)
168    }
169
170    /// The bare declaration either form makes: `slot` for the extension
171    /// form, `None` for a host form whose
172    /// content is built some other way or not at all this frame. Whether
173    /// the declaration stood — false for a name already declared this
174    /// frame (`duplicate-tab`) or outside a frame.
175    pub fn devtools_tab_declare(&mut self, name: &str, label: &str, slot: Option<&str>) -> bool {
176        self.core.devtools_tab_declare(name, label, slot)
177    }
178
179    /// The host form for a binding that decided the laziness on its own
180    /// side (a Node encoder or a Lua converter that already read which
181    /// tab is on show): declares the tab and builds
182    /// `f` as its content **whether or not** the tab is shown here — a
183    /// content whose body the panel did not build anchors to nothing
184    /// and paints nothing, and a name already declared this frame
185    /// (`duplicate-tab`) builds into a node of no size, so the caller's
186    /// stream stays in step either way. `devtools_tab_with` is the door
187    /// for a caller that can skip the work.
188    pub fn devtools_tab_declared(&mut self, name: &str, label: &str, f: impl FnOnce(&mut Ui<'_>)) {
189        if self.core.devtools_tab_declare(name, label, None) {
190            self.core.devtools_tab_open(name);
191        } else {
192            self.core.open(
193                NodeSpec::column()
194                    .width(crate::spec::Sizing::Fixed(0.0))
195                    .height(crate::spec::Sizing::Fixed(0.0))
196                    .clip(),
197            );
198        }
199        f(self);
200        self.core.close();
201    }
202
203    /// The panel's selected node (`Core::devtools_selected`).
204    pub fn devtools_selected(&self) -> Option<Key> {
205        self.core.devtools_selected()
206    }
207
208    /// The panel's hovered tree row (`Core::devtools_hovered`).
209    pub fn devtools_hovered(&self) -> Option<Key> {
210        self.core.devtools_hovered()
211    }
212
213    /// The node the picker is over (`Core::devtools_picked`).
214    pub fn devtools_picked(&self) -> Option<Key> {
215        self.core.devtools_picked()
216    }
217
218    /// Whether the panel's picker is up (`Core::devtools_picking`).
219    pub fn devtools_picking(&self) -> bool {
220        self.core.devtools_picking()
221    }
222
223    /// The tab the panel is on, by name (`Core::devtools_current_tab`).
224    pub fn devtools_current_tab(&self) -> String {
225        self.core.devtools_current_tab()
226    }
227
228    /// Loads `ext` under `namespace` into the list filling this frame's
229    /// slots, and answers with the origin it got. This is how an
230    /// extension hosts an extension of its own: the guest asks mid-frame,
231    /// when it knows what it wants, and the plugin lands in the same list
232    /// as the host's own — one namespace map, one origin per extension,
233    /// however deep the loading went (`crate::slot`).
234    ///
235    /// Fails when the namespace is taken, or empty with an extension that
236    /// names itself nothing, exactly as
237    /// `Extensions::push_as` does, and when this frame was begun without
238    /// a filler (`Core::frame`) or with one that is not a list.
239    pub fn add_extension(
240        &mut self,
241        namespace: &str,
242        ext: Box<dyn crate::runtime::Extension>,
243    ) -> Result<OriginId, String> {
244        match self.filler.as_deref_mut() {
245            Some(filler) => filler.add(namespace, ext),
246            None => Err(format!(
247                "cannot load `{namespace}`: this frame declares no slots to fill"
248            )),
249        }
250    }
251
252    /// Runs `f` as the fill of `slot` under `origin`: nodes it opens are
253    /// tagged with the origin, keyed under the slot's key, and closed
254    /// for it if it leaves any open. What a `Fill` implementation calls
255    /// per extension; see `Core::fill`.
256    pub fn fill(&mut self, origin: OriginId, slot: &Slot<'_>, f: impl FnOnce(&mut Ui<'_>)) {
257        self.core.fill(slot, origin, f);
258    }
259
260    /// `fill`, with `filler` answering the slots the fill declares — an
261    /// extension hosting extensions of its own. `Extensions::fill_one`
262    /// passes itself, which is what makes one namespace map do for every
263    /// level; see `crate::slot`.
264    pub fn fill_within(
265        &mut self,
266        origin: OriginId,
267        slot: &Slot<'_>,
268        filler: &mut dyn Fill,
269        f: impl FnOnce(&mut Ui<'_>),
270    ) {
271        self.core.fill_within(slot, origin, Some(filler), f);
272    }
273
274    /// The origin the nodes opened right now are tagged with:
275    /// `OriginId::HOST` in the host's own view, the filling extension's
276    /// inside a fill. What records who declared a slot, and so where the
277    /// replies of whatever fills it go.
278    pub fn origin(&self) -> OriginId {
279        self.core.origin()
280    }
281
282    /// The viewport this frame lays out into: the window, less the
283    /// devtools' dock while the panel is docked (`Core::viewport`).
284    pub fn viewport(&self) -> Size {
285        self.core.viewport()
286    }
287
288    /// The env reading's inputs, the frame's facts included
289    /// (`Core::env_facts`): what a binding's `env` table is filled from.
290    pub fn env_facts(&self) -> crate::schema::EnvFacts {
291        self.core.env_facts()
292    }
293
294    /// Host facts pushed by the frame driver (refresh rate, focus).
295    pub fn env(&self) -> Env {
296        self.core.env
297    }
298
299    /// This frame's palette: the named colours the stock widgets paint
300    /// with, derived from `env.system` unless the app pinned something
301    /// else (see [`crate::theme`]).
302    ///
303    /// By value, because it is [`Copy`] and a view that took a reference
304    /// could not then touch `ui`. `let t = ui.theme();` at the top of a
305    /// widget is the idiom.
306    pub fn theme(&self) -> crate::theme::Theme {
307        *self.core.theme()
308    }
309
310    /// Whether anyone chose the theme's accent, or it is kui's fallback
311    /// blue — see [`Core::has_accent`](crate::runtime::Core::has_accent).
312    pub fn has_accent(&self) -> bool {
313        self.core.has_accent()
314    }
315
316    /// The sizes the stock widgets are built from
317    /// ([`Metrics`](crate::metrics::Metrics)), by value like the theme and
318    /// for the same reason. What a view reads to make its own controls
319    /// agree with the stock ones on a radius and a padding.
320    pub fn metrics(&self) -> crate::metrics::Metrics {
321        *self.core.metrics()
322    }
323
324    /// Declares the tokens this origin references by name (see
325    /// [`crate::tokens`] and
326    /// [`Core::set_tokens`](crate::runtime::Core::set_tokens)). Inside a
327    /// fill the table is the extension's own.
328    pub fn set_tokens(&mut self, tokens: crate::tokens::Tokens) {
329        self.core.set_tokens(tokens);
330    }
331
332    /// What a `$name` resolves to this frame — the running origin's
333    /// table over the host's, the roles in front of both — for a view
334    /// that reads a token by name rather than holding its id.
335    pub fn tokens(&self) -> crate::tokens::TokenLookup<'_> {
336        self.core.token_lookup()
337    }
338
339    /// A colour token by name, this frame's half. A name that resolves
340    /// to nothing, or to a length, raises `unknown-token` and answers
341    /// `None`, so the view leaves the slot at its default
342    /// (`.bg(ui.token_color("peach").unwrap_or(t.surface))`) rather than
343    /// painting a transparent that would hide the node a typo was on.
344    pub fn token_color(&mut self, name: &str) -> Option<crate::color::Color> {
345        match self.core.token_lookup().color(name) {
346            Ok(c) => Some(c),
347            Err(e) => {
348                self.core.warn_unknown_token(&e);
349                None
350            }
351        }
352    }
353
354    /// A length token by name; unknown warns and answers `None`, as above.
355    pub fn token_length(&mut self, name: &str) -> Option<f32> {
356        match self.core.token_lookup().length(name) {
357            Ok(v) => Some(v),
358            Err(e) => {
359                self.core.warn_unknown_token(&e);
360                None
361            }
362        }
363    }
364
365    /// Declares this frame's window title (declare every frame you care;
366    /// the driver diffs and applies changes).
367    pub fn window_title(&mut self, title: &str) {
368        self.core.set_window_title(title);
369    }
370
371    /// Declares that this frame wants the window kept above every other
372    /// app's; see [`crate::Core::set_always_on_top`]. Declare it every
373    /// frame you want it — a frame that does not lowers the window again,
374    /// which is what makes a pin button a toggle — and read whether the
375    /// platform agreed from `env().window.always_on_top`.
376    pub fn always_on_top(&mut self, on_top: bool) {
377        self.core.set_always_on_top(on_top);
378    }
379
380    /// Declares that this frame wants secure keyboard entry while the
381    /// window has the keyboard (a password prompt); see
382    /// [`crate::Core::set_secure_input`]. Declare it every frame the
383    /// prompt is up: a frame that does not turns it off.
384    pub fn secure_input(&mut self, on: bool) {
385        self.core.set_secure_input(on);
386    }
387
388    /// Declares which Option keys act as Alt in this window on macOS, so
389    /// Option-u arrives as the chord `A-u` rather than composing an
390    /// accent; see [`crate::Core::set_option_as_alt`]. Declare it every
391    /// frame: a frame that does not gives the Option keys back to the
392    /// layout.
393    pub fn option_as_alt(&mut self, option_as_alt: crate::OptionAsAlt) {
394        self.core.set_option_as_alt(option_as_alt);
395    }
396
397    /// Declares that this window takes the keyboard as keys, with the
398    /// platform's input method off — no composition, and on a Mac no dead
399    /// keys and no press-and-hold, so a held letter repeats; see
400    /// [`crate::Core::set_ime_off`]. A modal editor's normal mode. Declare
401    /// it every frame: a frame that does not gives the IME back.
402    pub fn ime_off(&mut self, off: bool) {
403        self.core.set_ime_off(off);
404    }
405
406    /// Declares that a window named `name` exists this frame; see
407    /// `Core::declare_window`. It opens on the first frame that declares
408    /// it (`config` is read then and never again), stays open while any
409    /// window's frame keeps declaring it, and closes when none does.
410    /// `view` is then called for it too, with [`Ui::window_name`] saying
411    /// which window is being drawn.
412    pub fn window(&mut self, name: &str, config: WindowConfig) {
413        self.core.declare_window(name, config);
414    }
415
416    /// The name of the window this frame is drawing: `"main"` for the one
417    /// the launcher opened, else the name the declaration that opened it
418    /// used. `env().window.id` is the same window as a number.
419    pub fn window_name(&self) -> std::rc::Rc<str> {
420        self.core.window_name()
421    }
422
423    /// Sets the origin the nodes opened from here on are tagged with; see
424    /// [`Ui::origin`].
425    pub fn set_origin(&mut self, origin: OriginId) {
426        self.core.set_origin(origin);
427    }
428
429    /// The root node's spec for this frame: its direction, padding, gap
430    /// and background. Call it first; the default root is a fit column.
431    pub fn configure_root(&mut self, spec: NodeSpec) {
432        self.core.configure_root(spec);
433    }
434
435    /// The key a child opened under `label` would get here, without
436    /// opening it: read it before the node exists to ask `is_hovered` or
437    /// `is_focused` while building it.
438    pub fn child_key(&self, label: &str) -> Key {
439        self.core.child_key(label)
440    }
441
442    /// The key the `i`th child gets from auto-keying; see `open_indexed`.
443    pub fn child_key_indexed(&self, i: u64) -> Key {
444        self.core.child_key_indexed(i)
445    }
446
447    /// Whether the pointer is over `key`, as of the last input. Only a
448    /// node that tracks hover answers true (one with a click, a drag, a
449    /// hover background or `hoverable`).
450    pub fn is_hovered(&self, key: Key) -> bool {
451        self.core.is_hovered(key)
452    }
453
454    /// Whether the primary button is held on `key`.
455    pub fn is_pressed(&self, key: Key) -> bool {
456        self.core.is_pressed(key)
457    }
458
459    /// Whether files dragged in from the OS are over `key`, for
460    /// drop-dependent *layout*; a colour swap is `drop_bg`.
461    pub fn is_drop_target(&self, key: Key) -> bool {
462        self.core.is_drop_target(key)
463    }
464
465    /// The zone the dragged files are over, if any.
466    pub fn drop_target(&self) -> Option<Key> {
467        self.core.drop_target()
468    }
469
470    /// Whether any member of a hover group (`NodeSpec::hover_group`) is
471    /// hovered; the id comes from `NodeSpec::hover_group_id`.
472    pub fn is_group_hovered(&self, group: u64) -> bool {
473        self.core.is_group_hovered(group)
474    }
475
476    /// Whether any member of a hover group is pressed.
477    pub fn is_group_pressed(&self, group: u64) -> bool {
478        self.core.is_group_pressed(group)
479    }
480
481    /// Physical modifier state (the host also receives it as a
482    /// `{kind="modifiers"}` event whenever it changes).
483    pub fn modifiers(&self) -> crate::input::KeyMods {
484        self.core.modifiers()
485    }
486
487    /// The caret's blink phase — `true` draws it; see
488    /// `Core::caret_visible`. A custom editor draws its caret node on the
489    /// on phase and skips it on the off, keeping the `caret` row on its
490    /// `line` either way (that row is what the clock is armed on).
491    pub fn caret_visible(&self) -> bool {
492        self.core.caret_visible()
493    }
494
495    /// Asks for one more frame after this one; see `Core::request_frame`.
496    #[track_caller]
497    pub fn request_frame(&mut self) {
498        self.core.request_frame();
499    }
500
501    /// Asks for one more frame on kui's own behalf (a stock widget's, not
502    /// the app's), named `why` in a trace.
503    #[track_caller]
504    pub(crate) fn owe_frame(&mut self, why: &'static str) {
505        self.core.owe_frame(why);
506    }
507
508    /// Measures text the way layout would, without adding a node; see
509    /// `Core::measure_text`. Sizing a column to its widest label, or
510    /// choosing a tier that fits, is arithmetic on these numbers instead
511    /// of hand-tuned constants. The metrics do not scale linearly:
512    /// `measured × zoom` is not `measure(size × zoom)`, because shaping
513    /// rounds per size, so anything that zooms measures at the size it
514    /// draws.
515    pub fn measure_text(
516        &mut self,
517        content: &str,
518        style: &TextStyle,
519        max_w: Option<f32>,
520    ) -> crate::text::TextMetrics {
521        self.core.measure_text(content, style, max_w)
522    }
523
524    /// Where a point lands in the text node `key` drew, as a byte offset
525    /// and a visual line; see `Core::text_hit`. During a build it answers
526    /// from the last frame, which is the layout a click was made against.
527    pub fn text_hit(&self, key: Key, point: Vec2) -> Option<crate::text::TextHit> {
528        self.core.text_hit(key, point)
529    }
530
531    /// The window's selected text — a `selectable` scope's, or the
532    /// focused editor's; see `Core::copy_selection`.
533    pub fn selection_text(&self) -> Option<String> {
534        self.core.copy_selection()
535    }
536
537    /// The text selection's two ends as the drag made them — anchor, then
538    /// focus — each a virtualised row's data index (or none) and a byte;
539    /// see `Core::selection_ends`.
540    pub fn selection_ends(&self) -> Option<(crate::select::RangeEnd, crate::select::RangeEnd)> {
541        self.core.selection_ends()
542    }
543
544    /// The window's selection when it lives in a `cells` grid — its ends
545    /// as absolute lines and columns; see `Core::cell_selection`.
546    ///
547    /// Offered where the text selection offers only [`Self::selection_text`]
548    /// because a grid's ends mean something to the app: they are the
549    /// session's own line numbers, not byte offsets into runs the app never
550    /// laid out.
551    pub fn cell_selection(&self) -> Option<crate::select::CellSelection> {
552        self.core.cell_selection()
553    }
554
555    /// Opens a context menu; see `Core::open_menu`.
556    pub fn open_menu(&mut self, menu: crate::menu::Menu) {
557        self.core.open_menu(menu);
558    }
559
560    /// Closes whatever menu is open; see `Core::close_menu`.
561    pub fn close_menu(&mut self) -> bool {
562        self.core.close_menu()
563    }
564
565    /// Asks for the selection as text; see `Core::request_copy`.
566    pub fn request_copy(&mut self) -> crate::select::CopyRequest {
567        self.core.request_copy()
568    }
569
570    /// Answers a `selectionrange` ask; see `Core::answer_selection_range`.
571    pub fn answer_selection_range(&mut self, text: &str) -> bool {
572        self.core.answer_selection_range(text)
573    }
574
575    /// The selection as HTML; see `Core::selection_html`.
576    pub fn selection_html(&self) -> Option<String> {
577        self.core.selection_html()
578    }
579
580    /// Puts text on the system clipboard; see `Core::set_clipboard`.
581    pub fn set_clipboard(&mut self, text: impl Into<String>, html: Option<String>) {
582        self.core.set_clipboard(text, html);
583    }
584
585    /// Puts a secret on the system clipboard marked concealed and
586    /// transient, the way a password manager does; see
587    /// `Core::set_clipboard_secret`.
588    pub fn set_clipboard_secret(&mut self, text: impl Into<String>) {
589        self.core.set_clipboard_secret(text);
590    }
591
592    /// Asks for the clipboard's text, delivered as a `text` event on the
593    /// focused sink or as typing into the focused editor; see
594    /// `Core::request_paste`.
595    pub fn request_paste(&mut self) {
596        self.core.request_paste();
597    }
598
599    /// Whether a paste asked for is still unanswered; see
600    /// `Core::awaiting_paste`.
601    pub fn awaiting_paste(&self) -> bool {
602        self.core.awaiting_paste()
603    }
604
605    /// Asks the host for a file dialog; the answer is a `files` event to
606    /// whoever's view asked. False when one is already outstanding. See
607    /// `Core::request_files`.
608    #[track_caller]
609    pub fn request_files(&mut self, dialog: crate::dialog::FileDialog) -> bool {
610        self.core.request_files(dialog)
611    }
612
613    /// `Core::awaiting_files`.
614    pub fn awaiting_files(&self) -> bool {
615        self.core.awaiting_files()
616    }
617
618    /// Selects everything in the scope `key` declared; see
619    /// `Core::select_all_in`.
620    pub fn select_all_in(&mut self, key: Key) -> bool {
621        self.core.select_all_in(key)
622    }
623
624    /// Drops the window's selection; see `Core::clear_selection`.
625    pub fn clear_selection(&mut self) -> bool {
626        self.core.clear_selection()
627    }
628
629    /// The caret rect for a byte offset in the text node `key` drew; see
630    /// `Core::caret_rect`.
631    pub fn caret_rect(&self, key: Key, byte: usize) -> Option<Rect> {
632        self.core.caret_rect(key, byte)
633    }
634
635    /// `measure_text` for a rich-text paragraph.
636    pub fn measure_rich_text(
637        &mut self,
638        spans: &[Span<'_>],
639        base: &TextStyle,
640        max_w: Option<f32>,
641    ) -> crate::text::TextMetrics {
642        self.core.measure_rich_text(spans, base, max_w)
643    }
644
645    /// Opens a node under the next auto key; its children follow until
646    /// [`Self::close`]. [`Self::with`] is the scoped form, and the one to
647    /// prefer: an `open` without its `close` is a `node-left-open`
648    /// warning.
649    #[inline]
650    pub fn open(&mut self, spec: NodeSpec) -> Key {
651        self.core.open(spec)
652    }
653
654    /// [`Self::open`] under a label key: stable across frames whatever
655    /// the siblings before it, and what `key_of(label)` finds.
656    #[inline]
657    pub fn open_keyed(&mut self, label: &str, spec: NodeSpec) -> Key {
658        self.core.open_keyed(label, spec)
659    }
660
661    /// Opens a node under a key the caller built rather than a label:
662    /// `ui.child_key("gap").index(id)` is a label and an index with no
663    /// string formatted and no clash with the sibling-index keys
664    /// `open_indexed` gives, and a key kept from an earlier `child_key` —
665    /// read for `is_hovered` first — is opened as it is instead of spelled
666    /// twice. Build it from this parent's `child_key`: two nodes under one
667    /// key in a frame are a `duplicate-key` warning, as two labels are.
668    /// It has no label, so `key_of` does not find it.
669    #[inline]
670    pub fn open_key(&mut self, key: Key, spec: NodeSpec) -> Key {
671        self.core.open_key(key, spec)
672    }
673
674    /// Scoped [`Self::open_key`].
675    pub fn with_key(&mut self, key: Key, spec: NodeSpec, f: impl FnOnce(&mut Ui<'_>)) -> Key {
676        self.open_key(key, spec);
677        f(self);
678        self.close();
679        key
680    }
681
682    /// [`Self::leaf`] under a key the caller built; see [`Self::open_key`].
683    #[inline]
684    pub fn leaf_key(&mut self, key: Key, spec: NodeSpec) -> Key {
685        self.open_key(key, spec);
686        self.close();
687        key
688    }
689
690    /// `open` under a key the caller chose — the panel's own nodes, whose
691    /// keys another node anchors to by name before they exist.
692    #[inline]
693    pub(crate) fn open_with_key(&mut self, key: Key, label: &str, spec: NodeSpec) {
694        self.core.open_with_key_named(key, label, spec)
695    }
696
697    /// `open_keyed` by sibling index: the key auto-keying would have given
698    /// the `i`th child. A virtualizing list opens each row with its data
699    /// index, so a row keeps its identity when the built range slides past
700    /// it. See `Core::open_indexed`.
701    #[inline]
702    pub fn open_indexed(&mut self, i: u64, spec: NodeSpec) -> Key {
703        self.core.open_indexed(i, spec)
704    }
705
706    /// Closes the node the last `open*` opened.
707    #[inline]
708    pub fn close(&mut self) {
709        self.core.close();
710    }
711
712    /// Opens a node, runs `f` for its children and closes it. The usual
713    /// way to declare a container:
714    ///
715    /// ```rust
716    /// # use kui_core::{Core, NodeSpec, Size, TextStyle};
717    /// # let mut core = Core::new();
718    /// # let mut ui = core.frame(Size::new(200.0, 100.0), 1.0);
719    /// ui.with(NodeSpec::row().gap(8.0).pad(4.0), |ui| {
720    ///     ui.text("Name", TextStyle::new(14.0));
721    ///     ui.text("Ada", TextStyle::new(14.0));
722    /// });
723    /// # ui.finish();
724    /// ```
725    pub fn with(&mut self, spec: NodeSpec, f: impl FnOnce(&mut Ui<'_>)) -> Key {
726        let key = self.open(spec);
727        f(self);
728        self.close();
729        key
730    }
731
732    /// Scoped [`Self::open_keyed`].
733    pub fn with_keyed(&mut self, label: &str, spec: NodeSpec, f: impl FnOnce(&mut Ui<'_>)) -> Key {
734        let key = self.open_keyed(label, spec);
735        f(self);
736        self.close();
737        key
738    }
739
740    /// A node with no children: a spacer, a rule, a swatch, a hit area —
741    /// `with(spec, |_| {})` without the empty closure.
742    #[inline]
743    pub fn leaf(&mut self, spec: NodeSpec) -> Key {
744        let key = self.open(spec);
745        self.close();
746        key
747    }
748
749    /// [`Self::leaf`] under a label key.
750    #[inline]
751    pub fn leaf_keyed(&mut self, label: &str, spec: NodeSpec) -> Key {
752        let key = self.open_keyed(label, spec);
753        self.close();
754        key
755    }
756
757    /// [`Self::leaf`] under a data index; see [`Self::open_indexed`].
758    #[inline]
759    pub fn leaf_indexed(&mut self, i: u64, spec: NodeSpec) -> Key {
760        let key = self.open_indexed(i, spec);
761        self.close();
762        key
763    }
764
765    /// Declares how many indexed rows the open node's virtual list has,
766    /// built or not; see [`crate::Core::row_count`].
767    pub fn row_count(&mut self, n: u64) {
768        self.core.row_count(n);
769    }
770
771    /// Scoped `open_indexed`: the `i`th child's auto-key, given to a node
772    /// that is not in the `i`th slot.
773    pub fn with_indexed(&mut self, i: u64, spec: NodeSpec, f: impl FnOnce(&mut Ui<'_>)) -> Key {
774        let key = self.open_indexed(i, spec);
775        f(self);
776        self.close();
777        key
778    }
779
780    /// A paragraph of plain text in one style, wrapped at the width its
781    /// parent gives it. A text has no box of its own (no padding,
782    /// background, key or click); [`Self::text_in`] puts it in one.
783    ///
784    /// ```rust
785    /// # use kui_core::{Color, Core, NodeSpec, Size, TextStyle};
786    /// # let mut core = Core::new();
787    /// # let mut ui = core.frame(Size::new(200.0, 100.0), 1.0);
788    /// ui.text("Plain, in the theme's foreground", TextStyle::new(14.0));
789    /// ui.text("Bold-ish, mono, red", TextStyle::new(13.0).mono().color(Color::hex(0xd43b3bff)));
790    /// let badge = ui.text_in(NodeSpec::row().pad_xy(6.0, 2.0).radius(4.0), "3", TextStyle::new(12.0));
791    /// # let _ = badge;
792    /// # ui.finish();
793    /// ```
794    pub fn text(&mut self, content: &str, style: TextStyle) {
795        self.core.text_node(content, style);
796    }
797
798    /// A box of `spec` holding one text: `with(spec, |ui| ui.text(…))` for
799    /// the label, the cell, the badge that needs a width, a background, a
800    /// click or a role. Returns the box's key.
801    #[inline]
802    pub fn text_in(&mut self, spec: NodeSpec, content: &str, style: TextStyle) -> Key {
803        let key = self.open(spec);
804        self.text(content, style);
805        self.close();
806        key
807    }
808
809    /// [`Self::text_in`] under a label key.
810    #[inline]
811    pub fn text_in_keyed(
812        &mut self,
813        label: &str,
814        spec: NodeSpec,
815        content: &str,
816        style: TextStyle,
817    ) -> Key {
818        let key = self.open_keyed(label, spec);
819        self.text(content, style);
820        self.close();
821        key
822    }
823
824    /// [`Self::text_in`] under a data index; see [`Self::open_indexed`].
825    #[inline]
826    pub fn text_in_indexed(
827        &mut self,
828        i: u64,
829        spec: NodeSpec,
830        content: &str,
831        style: TextStyle,
832    ) -> Key {
833        let key = self.open_indexed(i, spec);
834        self.text(content, style);
835        self.close();
836        key
837    }
838
839    /// A cell grid (a terminal's screen) as one node; see
840    /// [`crate::cells`]. The spec is the node's own.
841    pub fn cells(&mut self, grid: &crate::cells::CellGrid<'_>, spec: NodeSpec) {
842        self.core.cells(grid, spec);
843    }
844
845    /// [`Self::cells`] under a data index; see [`Self::open_indexed`].
846    pub fn cells_indexed(&mut self, i: u64, grid: &crate::cells::CellGrid<'_>, spec: NodeSpec) {
847        self.core.cells_indexed(i, grid, spec);
848    }
849
850    /// [`Self::cells`] under a declared key.
851    pub fn cells_keyed(&mut self, label: &str, grid: &crate::cells::CellGrid<'_>, spec: NodeSpec) {
852        self.core.cells_keyed(label, grid, spec);
853    }
854
855    /// A paragraph of styled spans, shaped and wrapped as one flow.
856    pub fn rich_text(&mut self, spans: &[Span<'_>], base: TextStyle) {
857        self.core.rich_text_node(spans, base);
858    }
859
860    /// A registered image; see `Core::image_node` for sizing semantics.
861    pub fn image(&mut self, id: crate::resources::ImageId, spec: NodeSpec) {
862        self.core.image_node(id, spec);
863    }
864
865    /// [`Self::image`] with its `sampling` and `fit` rows; see
866    /// `Core::image_node_with`.
867    pub fn image_with(
868        &mut self,
869        id: crate::resources::ImageId,
870        opts: crate::resources::ImageOpts,
871        spec: NodeSpec,
872    ) {
873        self.core.image_node_with(id, opts, spec);
874    }
875
876    /// A box a registered WGSL function paints; see `Core::fragment_node`
877    /// for what it is, and `Core::add_fragment` for where the handle comes
878    /// from. It has no intrinsic size, so give it one.
879    ///
880    /// `frag` is the handle, or `handle.with_image(img)` for a function
881    /// that reads a registered image through `kui_sample(uv)`: a
882    /// waveform, a heatmap, an image effect.
883    pub fn fragment(
884        &mut self,
885        frag: impl Into<crate::fragment::FragmentRef>,
886        params: &[f32],
887        spec: NodeSpec,
888    ) -> Key {
889        self.core.fragment_node(frag, params, spec)
890    }
891
892    /// A fragment holding children, which paint over it: a gradient card
893    /// with a title and buttons on top of it.
894    pub fn fragment_with(
895        &mut self,
896        frag: impl Into<crate::fragment::FragmentRef>,
897        params: &[f32],
898        spec: NodeSpec,
899        f: impl FnOnce(&mut Ui<'_>),
900    ) -> Key {
901        let key = self.core.open_fragment(frag, params, spec);
902        f(self);
903        self.core.close();
904        key
905    }
906
907    /// [`Self::fragment`] under a label key, for one that transitions or
908    /// exits and needs a stable identity across frames.
909    pub fn fragment_keyed(
910        &mut self,
911        label: &str,
912        frag: impl Into<crate::fragment::FragmentRef>,
913        params: &[f32],
914        spec: NodeSpec,
915    ) -> Key {
916        self.core.fragment_node_keyed(label, frag, params, spec)
917    }
918
919    /// [`Self::fragment_with`] under a label key.
920    pub fn fragment_with_keyed(
921        &mut self,
922        label: &str,
923        frag: impl Into<crate::fragment::FragmentRef>,
924        params: &[f32],
925        spec: NodeSpec,
926        f: impl FnOnce(&mut Ui<'_>),
927    ) -> Key {
928        let key = self.core.open_fragment_keyed(label, frag, params, spec);
929        f(self);
930        self.core.close();
931        key
932    }
933
934    /// [`Self::fragment`] under a data index; see [`Self::open_indexed`].
935    pub fn fragment_indexed(
936        &mut self,
937        i: u64,
938        frag: impl Into<crate::fragment::FragmentRef>,
939        params: &[f32],
940        spec: NodeSpec,
941    ) -> Key {
942        let key = self.core.open_fragment_indexed(i, frag, params, spec);
943        self.core.close();
944        key
945    }
946
947    /// [`Self::fragment_with`] under a data index.
948    pub fn fragment_with_indexed(
949        &mut self,
950        i: u64,
951        frag: impl Into<crate::fragment::FragmentRef>,
952        params: &[f32],
953        spec: NodeSpec,
954        f: impl FnOnce(&mut Ui<'_>),
955    ) -> Key {
956        let key = self.core.open_fragment_indexed(i, frag, params, spec);
957        f(self);
958        self.core.close();
959        key
960    }
961
962    /// A round-capped segment from `from` to `to`, in the parent's box
963    /// space; see `Core::line_node` for what it is and is not.
964    #[inline]
965    pub fn line(&mut self, from: Vec2, to: Vec2, stroke: Stroke, spec: NodeSpec) {
966        self.core.line_node(&[from, to], stroke, spec);
967    }
968
969    /// [`Self::line`] under a label key.
970    pub fn line_keyed(
971        &mut self,
972        label: &str,
973        from: Vec2,
974        to: Vec2,
975        stroke: Stroke,
976        spec: NodeSpec,
977    ) {
978        self.core.line_node_keyed(label, &[from, to], stroke, spec);
979    }
980
981    /// [`Self::line`] under a data index; see [`Self::open_indexed`].
982    pub fn line_indexed(&mut self, i: u64, from: Vec2, to: Vec2, stroke: Stroke, spec: NodeSpec) {
983        self.core.line_node_indexed(i, &[from, to], stroke, spec);
984    }
985
986    /// A stroke through `points`: a polyline, or a smooth curve through
987    /// them with [`Stroke::curve`]; see `Core::line_node`.
988    #[inline]
989    pub fn polyline(&mut self, points: &[Vec2], stroke: Stroke, spec: NodeSpec) {
990        self.core.line_node(points, stroke, spec);
991    }
992
993    /// [`Self::polyline`] under a data index; see [`Self::open_indexed`].
994    pub fn polyline_indexed(&mut self, i: u64, points: &[Vec2], stroke: Stroke, spec: NodeSpec) {
995        self.core.line_node_indexed(i, points, stroke, spec);
996    }
997
998    /// [`Self::polyline`] under a label key.
999    pub fn polyline_keyed(&mut self, label: &str, points: &[Vec2], stroke: Stroke, spec: NodeSpec) {
1000        self.core.line_node_keyed(label, points, stroke, spec);
1001    }
1002
1003    /// A filled polygon through `points` in the parent's box space, the
1004    /// fill in `spec`'s `bg`; see `Core::polygon_node` for what it is and
1005    /// is not.
1006    pub fn polygon(&mut self, points: &[Vec2], spec: NodeSpec) {
1007        self.core.polygon_node(points, spec);
1008    }
1009
1010    /// [`Self::polygon`] under a label key.
1011    pub fn polygon_keyed(&mut self, label: &str, points: &[Vec2], spec: NodeSpec) {
1012        self.core.polygon_node_keyed(label, points, spec);
1013    }
1014
1015    /// [`Self::polygon`] under a data index; see [`Self::open_indexed`].
1016    pub fn polygon_indexed(&mut self, i: u64, points: &[Vec2], spec: NodeSpec) {
1017        self.core.polygon_node_indexed(i, points, spec);
1018    }
1019
1020    /// A path — any outline — filled with `spec`'s `bg` and stroked by
1021    /// the path's own stroke; see `Core::path_node` for what it is and
1022    /// is not.
1023    pub fn path(&mut self, path: &crate::path::Path, spec: NodeSpec) {
1024        self.core.path_node(path, spec);
1025    }
1026
1027    /// [`Self::path`] under a label key.
1028    pub fn path_keyed(&mut self, label: &str, path: &crate::path::Path, spec: NodeSpec) {
1029        self.core.path_node_keyed(label, path, spec);
1030    }
1031
1032    /// [`Self::path`] under a data index; see [`Self::open_indexed`].
1033    pub fn path_indexed(&mut self, i: u64, path: &crate::path::Path, spec: NodeSpec) {
1034        self.core.path_node_indexed(i, path, spec);
1035    }
1036
1037    /// [`Self::path`] from SVG path data; data that does not parse raises
1038    /// `path-malformed` and draws nothing. See `Core::path_d_node`.
1039    pub fn path_d(
1040        &mut self,
1041        d: &str,
1042        rule: crate::path::FillRule,
1043        stroke: Option<Stroke>,
1044        turn: Option<crate::path::Turn>,
1045        spec: NodeSpec,
1046    ) {
1047        self.core.path_d_node(d, rule, stroke, turn, spec);
1048    }
1049
1050    /// [`Self::path_d`] under a label key.
1051    pub fn path_d_keyed(
1052        &mut self,
1053        label: &str,
1054        d: &str,
1055        rule: crate::path::FillRule,
1056        stroke: Option<Stroke>,
1057        turn: Option<crate::path::Turn>,
1058        spec: NodeSpec,
1059    ) {
1060        self.core
1061            .path_d_node_keyed(label, d, rule, stroke, turn, spec);
1062    }
1063
1064    /// An `audio` node: a playback retained for as long as the view keeps
1065    /// declaring it; see `Core::audio_node`.
1066    pub fn audio(&mut self, spec: crate::audio::AudioSpec) -> Key {
1067        self.core.audio_node(spec)
1068    }
1069
1070    /// `audio` with a label-derived key; see `Core::audio_node_keyed`.
1071    pub fn audio_keyed(&mut self, label: &str, spec: crate::audio::AudioSpec) -> Key {
1072        self.core.audio_node_keyed(label, spec)
1073    }
1074
1075    /// Starts a playback from a view; see `Core::play`. Views run every
1076    /// frame, so gate it on state that changes once (or use `audio`).
1077    pub fn play(
1078        &mut self,
1079        sound: crate::resources::SoundId,
1080        opts: crate::audio::PlayOptions,
1081    ) -> crate::audio::PlaybackId {
1082        self.core.play(sound, opts)
1083    }
1084
1085    /// An editable text node; state retained by key. See `Core::text_edit`.
1086    pub fn text_edit(
1087        &mut self,
1088        label: &str,
1089        initial: &str,
1090        opts: &EditOptions,
1091        spec: NodeSpec,
1092    ) -> Key {
1093        self.core.text_edit(label, initial, opts, spec)
1094    }
1095
1096    /// Whether `key` holds keyboard focus — any node: an editor, a key
1097    /// sink, a button Tab landed on (see `Core::focus`).
1098    pub fn is_focused(&self, key: Key) -> bool {
1099        self.core.is_focused(key)
1100    }
1101
1102    /// The node holding keyboard focus, if any.
1103    pub fn focused(&self) -> Option<Key> {
1104        self.core.focus()
1105    }
1106
1107    /// Whether focus got where it is by keyboard or assistive technology
1108    /// (a Tab press, a reader's request) rather than a click — when a
1109    /// view that styles its own focus should show it.
1110    pub fn focus_visible(&self) -> bool {
1111        self.core.focus_visible()
1112    }
1113
1114    /// The key of the node opened under `label` — in this frame so far,
1115    /// then in the last finished one. For a caller that holds only the
1116    /// label and cannot spell the path (`child_key` is the same question
1117    /// asked from the parent); see `Core::key_of`.
1118    pub fn key_of(&mut self, label: &str) -> Option<Key> {
1119        self.core.key_of(label)
1120    }
1121
1122    /// Moves keyboard focus to `key` now (an editor, an `on_key` sink, a
1123    /// control, a `focusable` node); see `Core::set_focus`.
1124    pub fn focus(&mut self, key: Key) {
1125        self.core.set_focus(Some(key));
1126    }
1127
1128    /// Drops keyboard focus.
1129    pub fn blur(&mut self) {
1130        self.core.set_focus(None);
1131    }
1132
1133    /// Moves focus to the next focusable node in tree order, wrapping —
1134    /// what Tab does. A key sink that binds Tab itself calls this to hand
1135    /// the keyboard on.
1136    ///
1137    /// Deferred, unlike the rest of this handle: a `Ui` only exists while a
1138    /// frame is being built, and `begin_frame` cleared the tree the Tab
1139    /// ring is made of, so stepping now would walk an empty ring. The step
1140    /// is applied at `finish`, against the frame this call is part of — so
1141    /// a view that declares three rows and asks to step lands on one of
1142    /// them, without waiting a frame for them to exist. Outside a frame
1143    /// (a driver handling a key press) `Core::focus_next` steps at once.
1144    #[track_caller]
1145    pub fn focus_next(&mut self) {
1146        self.core.request_focus_step(true);
1147    }
1148
1149    /// Shift-Tab: the previous focusable node. Deferred to `finish` for the
1150    /// reason [`Ui::focus_next`] gives.
1151    #[track_caller]
1152    pub fn focus_prev(&mut self) {
1153        self.core.request_focus_step(false);
1154    }
1155
1156    /// Enters a focus region (the node `key` names, declared
1157    /// `focus_region`), or the main ring for `None`: focus lands on what
1158    /// that ring
1159    /// last held if the node is still there, else its `initial_focus`,
1160    /// else its first stop, and shows. Deferred to `finish` like
1161    /// [`Ui::focus_next`], so a view may name the region it is declaring
1162    /// right now — the dock this frame toggles on. A key the frame does
1163    /// not declare as a region raises `focus-region-without-node`.
1164    #[track_caller]
1165    pub fn focus_region(&mut self, key: Option<Key>) {
1166        self.core.focus_region(key);
1167    }
1168
1169    /// The focus region in effect — the node whose ring Tab walks — or
1170    /// `None` for the main ring. What a chord that toggles between a dock
1171    /// and the app reads to know which way it is going.
1172    pub fn region(&self) -> Option<Key> {
1173        self.core.region()
1174    }
1175
1176    /// An editor's current text, by its key; `None` for a key no editor
1177    /// holds.
1178    pub fn edit_text(&self, key: Key) -> Option<String> {
1179        self.core.edit_text(key)
1180    }
1181
1182    /// Replaces an editor's text, caret at the end (`Core::set_edit_text`).
1183    /// Returns whether it reached an editor now, or was held for the
1184    /// frame that declares the key.
1185    pub fn set_edit_text(&mut self, key: Key, text: &str) -> bool {
1186        self.core.set_edit_text(key, text)
1187    }
1188
1189    /// The same by the label the view declares, for a caller with no key
1190    /// yet: an `update` opening a field the editor has not fired an
1191    /// event from (`Core::set_edit_text_by_label`).
1192    pub fn set_edit_text_by_label(&mut self, label: &str, text: &str) -> bool {
1193        self.core.set_edit_text_by_label(label, text)
1194    }
1195
1196    /// Says something once, with no node behind it (`Core::announce`).
1197    /// Takes effect at once, unlike `focus_next`: the queue is not made of
1198    /// a finished tree.
1199    ///
1200    /// A view runs every frame, so a call made from here needs a guard the
1201    /// app clears; the core reports the unguarded case as
1202    /// `announcement-repeated`. A region whose message is on screen is the
1203    /// `live` prop instead.
1204    pub fn announce(&mut self, text: &str, live: crate::access::Live) {
1205        self.core.announce(text, live);
1206    }
1207
1208    /// Scrolls whatever contains `key` so the node shows — "scroll to the
1209    /// selected row", without the container geometry the app cannot see.
1210    /// Resolved when this frame finishes laying out, so a row the view is
1211    /// declaring right now reveals fine; a key the frame does not declare,
1212    /// or one nothing scrollable contains, is a no-op. See `Core::reveal`.
1213    #[track_caller]
1214    pub fn reveal(&mut self, key: Key) {
1215        self.core.reveal(key);
1216    }
1217
1218    /// The handle for an installed or loaded font family by name (what
1219    /// `family = "Name"` resolves to in the declarative bindings), so a
1220    /// Rust view names a face without reaching for the core. `None` when
1221    /// no face matches. Idempotent.
1222    pub fn system_font(&mut self, name: &str) -> Option<crate::resources::FontId> {
1223        self.core.add_system_font(name)
1224    }
1225
1226    /// [`Self::reveal`] by label, resolved when this frame finishes; see
1227    /// `Core::reveal_label`.
1228    #[track_caller]
1229    pub fn reveal_label(&mut self, label: &str) {
1230        self.core.reveal_label(label);
1231    }
1232
1233    /// `set_scroll` by label, resolved before this frame lays out; see
1234    /// `Core::set_scroll_label`.
1235    #[track_caller]
1236    pub fn set_scroll_label(&mut self, label: &str, offset: Vec2) {
1237        self.core.set_scroll_label(label, offset);
1238    }
1239
1240    /// A scroll container's retained offset, clamped as of the last
1241    /// layout — the number to stash in a model and hand back to
1242    /// `set_scroll` later. Zero for a node that never scrolled.
1243    pub fn scroll_offset(&self, key: Key) -> Vec2 {
1244        self.core.scroll_offset(key)
1245    }
1246
1247    /// Sets that offset, the way the wheel would: `Vec2::ZERO` jumps to
1248    /// the top, a large value to the end (the next layout clamps it).
1249    #[track_caller]
1250    pub fn set_scroll(&mut self, key: Key, offset: Vec2) {
1251        self.core.set_scroll(key, offset);
1252    }
1253
1254    /// Moves a container's scroll state by the content that moved under
1255    /// it (`drawn` for the drawn place and an eased leg's start, `target`
1256    /// for the offset) with no ease asked or ended: a variable-height
1257    /// list's height correction. See `Core::shift_scroll`.
1258    pub fn shift_scroll(&mut self, key: Key, drawn: Vec2, target: Vec2) {
1259        self.core.shift_scroll(key, drawn, target);
1260    }
1261
1262    /// What the last layout resolved for a scroll container — its box, its
1263    /// content size and the clamped offset — so a view can build only the
1264    /// rows that fit and two spacers instead of ten thousand rows. `None`
1265    /// until a layout has resolved `key` as a container. It describes the
1266    /// previous frame; see `Core::scroll_geometry`, or
1267    /// `widgets::uniform_list` for the uniform-row case.
1268    pub fn scroll_geometry(&self, key: Key) -> Option<crate::scroll::ScrollGeometry> {
1269        self.core.scroll_geometry(key)
1270    }
1271
1272    /// The rect the last frame laid an `on_layout` node out at; see
1273    /// `Core::layout_of`.
1274    pub fn layout_of(&self, key: Key) -> Option<Rect> {
1275        self.core.layout_of(key)
1276    }
1277
1278    /// Declares this node focused: it takes keyboard focus when the
1279    /// declaration *starts* (the first frame it is made), and a Tab press
1280    /// afterwards is not clobbered by the view repeating it. An `on_key`
1281    /// sink then gets presses in `on_event` as `{kind="key", code, ctrl,
1282    /// alt, shift, super, text, repeat, tag}`. To move focus at any time,
1283    /// `focus(key)`.
1284    pub fn take_key_focus(&mut self, key: Key) {
1285        self.core.set_key_focus(Some(key));
1286    }
1287
1288    /// The node holding keyboard focus (the same as `focused`).
1289    pub fn key_focus(&self) -> Option<Key> {
1290        self.core.key_focus()
1291    }
1292
1293    /// Asks the frame driver to apply a window command (close from a
1294    /// keymap, minimize from a command line).
1295    pub fn window_command(&mut self, cmd: WindowCommand) {
1296        self.core.push_window_command(cmd);
1297    }
1298
1299    /// Asks the driver to resize a window (logical px) — a request applied
1300    /// on the driver's next pump and ignored headlessly, not a declaration:
1301    /// the user owns a window's size once it exists. `ui.env().window.id`
1302    /// is the window this view is drawing. See `Core::set_window_size`.
1303    pub fn set_window_size(&mut self, window: WindowId, size: Size) {
1304        self.core.set_window_size(window, size);
1305    }
1306
1307    /// Asks the driver to give a window keyboard focus; queued the same
1308    /// way. See `Core::focus_window`.
1309    pub fn focus_window(&mut self, window: WindowId) {
1310        self.core.focus_window(window);
1311    }
1312
1313    /// Runs layout and emission; results land in `Core::output()`. A frame
1314    /// begun with a filler lets it finish first: the `"root"` fill, unless
1315    /// the view declared it, and the `unknown-slot` check. An open context
1316    /// menu is drawn after both, which is what makes it the frame's modal
1317    /// scope and its topmost float.
1318    pub fn finish(self) {
1319        let Ui { core, filler } = self;
1320        // Not in the devtools' own window: nothing the host or an
1321        // extension declares there is built.
1322        if let Some(filler) = filler {
1323            if !core.devtools_window() {
1324                // A declared tab's extension fill first — a layer
1325                // anchored to a body the panel builds below, so the
1326                // filler's own `unknown-slot` check sees the slot
1327                // declared — then the root fills.
1328                core.devtools_fill_mount(filler);
1329                filler.finish(&mut Ui::new(core));
1330            }
1331            // The panel, after the fills and before the menu: the menu is
1332            // the last thing declared and so the topmost float.
1333            core.devtools_finish();
1334            if core.devtools_window() {
1335                // The panel's own window: the extension form's fill lands
1336                // here too, when the pane gave the frame a filler.
1337                core.devtools_fill_mount(filler);
1338            }
1339        } else {
1340            core.devtools_finish();
1341        }
1342        Core::build_menu(&mut Ui::new(core));
1343        core.finish_frame();
1344    }
1345}