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 a window named `name` exists this frame; see
398    /// `Core::declare_window`. It opens on the first frame that declares
399    /// it (`config` is read then and never again), stays open while any
400    /// window's frame keeps declaring it, and closes when none does.
401    /// `view` is then called for it too, with [`Ui::window_name`] saying
402    /// which window is being drawn.
403    pub fn window(&mut self, name: &str, config: WindowConfig) {
404        self.core.declare_window(name, config);
405    }
406
407    /// The name of the window this frame is drawing: `"main"` for the one
408    /// the launcher opened, else the name the declaration that opened it
409    /// used. `env().window.id` is the same window as a number.
410    pub fn window_name(&self) -> std::rc::Rc<str> {
411        self.core.window_name()
412    }
413
414    /// Sets the origin the nodes opened from here on are tagged with; see
415    /// [`Ui::origin`].
416    pub fn set_origin(&mut self, origin: OriginId) {
417        self.core.set_origin(origin);
418    }
419
420    /// The root node's spec for this frame: its direction, padding, gap
421    /// and background. Call it first; the default root is a fit column.
422    pub fn configure_root(&mut self, spec: NodeSpec) {
423        self.core.configure_root(spec);
424    }
425
426    /// The key a child opened under `label` would get here, without
427    /// opening it: read it before the node exists to ask `is_hovered` or
428    /// `is_focused` while building it.
429    pub fn child_key(&self, label: &str) -> Key {
430        self.core.child_key(label)
431    }
432
433    /// The key the `i`th child gets from auto-keying; see `open_indexed`.
434    pub fn child_key_indexed(&self, i: u64) -> Key {
435        self.core.child_key_indexed(i)
436    }
437
438    /// Whether the pointer is over `key`, as of the last input. Only a
439    /// node that tracks hover answers true (one with a click, a drag, a
440    /// hover background or `hoverable`).
441    pub fn is_hovered(&self, key: Key) -> bool {
442        self.core.is_hovered(key)
443    }
444
445    /// Whether the primary button is held on `key`.
446    pub fn is_pressed(&self, key: Key) -> bool {
447        self.core.is_pressed(key)
448    }
449
450    /// Whether files dragged in from the OS are over `key`, for
451    /// drop-dependent *layout*; a colour swap is `drop_bg`.
452    pub fn is_drop_target(&self, key: Key) -> bool {
453        self.core.is_drop_target(key)
454    }
455
456    /// The zone the dragged files are over, if any.
457    pub fn drop_target(&self) -> Option<Key> {
458        self.core.drop_target()
459    }
460
461    /// Whether any member of a hover group (`NodeSpec::hover_group`) is
462    /// hovered; the id comes from `NodeSpec::hover_group_id`.
463    pub fn is_group_hovered(&self, group: u64) -> bool {
464        self.core.is_group_hovered(group)
465    }
466
467    /// Whether any member of a hover group is pressed.
468    pub fn is_group_pressed(&self, group: u64) -> bool {
469        self.core.is_group_pressed(group)
470    }
471
472    /// Physical modifier state (the host also receives it as a
473    /// `{kind="modifiers"}` event whenever it changes).
474    pub fn modifiers(&self) -> crate::input::KeyMods {
475        self.core.modifiers()
476    }
477
478    /// The caret's blink phase — `true` draws it; see
479    /// `Core::caret_visible`. A custom editor draws its caret node on the
480    /// on phase and skips it on the off, keeping the `caret` row on its
481    /// `line` either way (that row is what the clock is armed on).
482    pub fn caret_visible(&self) -> bool {
483        self.core.caret_visible()
484    }
485
486    /// Asks for one more frame after this one; see `Core::request_frame`.
487    #[track_caller]
488    pub fn request_frame(&mut self) {
489        self.core.request_frame();
490    }
491
492    /// Asks for one more frame on kui's own behalf (a stock widget's, not
493    /// the app's), named `why` in a trace.
494    #[track_caller]
495    pub(crate) fn owe_frame(&mut self, why: &'static str) {
496        self.core.owe_frame(why);
497    }
498
499    /// Measures text the way layout would, without adding a node; see
500    /// `Core::measure_text`. Sizing a column to its widest label, or
501    /// choosing a tier that fits, is arithmetic on these numbers instead
502    /// of hand-tuned constants. The metrics do not scale linearly:
503    /// `measured × zoom` is not `measure(size × zoom)`, because shaping
504    /// rounds per size, so anything that zooms measures at the size it
505    /// draws.
506    pub fn measure_text(
507        &mut self,
508        content: &str,
509        style: &TextStyle,
510        max_w: Option<f32>,
511    ) -> crate::text::TextMetrics {
512        self.core.measure_text(content, style, max_w)
513    }
514
515    /// Where a point lands in the text node `key` drew, as a byte offset
516    /// and a visual line; see `Core::text_hit`. During a build it answers
517    /// from the last frame, which is the layout a click was made against.
518    pub fn text_hit(&self, key: Key, point: Vec2) -> Option<crate::text::TextHit> {
519        self.core.text_hit(key, point)
520    }
521
522    /// The window's selected text — a `selectable` scope's, or the
523    /// focused editor's; see `Core::copy_selection`.
524    pub fn selection_text(&self) -> Option<String> {
525        self.core.copy_selection()
526    }
527
528    /// The text selection's two ends as the drag made them — anchor, then
529    /// focus — each a virtualised row's data index (or none) and a byte;
530    /// see `Core::selection_ends`.
531    pub fn selection_ends(&self) -> Option<(crate::select::RangeEnd, crate::select::RangeEnd)> {
532        self.core.selection_ends()
533    }
534
535    /// The window's selection when it lives in a `cells` grid — its ends
536    /// as absolute lines and columns; see `Core::cell_selection`.
537    ///
538    /// Offered where the text selection offers only [`Self::selection_text`]
539    /// because a grid's ends mean something to the app: they are the
540    /// session's own line numbers, not byte offsets into runs the app never
541    /// laid out.
542    pub fn cell_selection(&self) -> Option<crate::select::CellSelection> {
543        self.core.cell_selection()
544    }
545
546    /// Opens a context menu; see `Core::open_menu`.
547    pub fn open_menu(&mut self, menu: crate::menu::Menu) {
548        self.core.open_menu(menu);
549    }
550
551    /// Closes whatever menu is open; see `Core::close_menu`.
552    pub fn close_menu(&mut self) -> bool {
553        self.core.close_menu()
554    }
555
556    /// Asks for the selection as text; see `Core::request_copy`.
557    pub fn request_copy(&mut self) -> crate::select::CopyRequest {
558        self.core.request_copy()
559    }
560
561    /// Answers a `selectionrange` ask; see `Core::answer_selection_range`.
562    pub fn answer_selection_range(&mut self, text: &str) -> bool {
563        self.core.answer_selection_range(text)
564    }
565
566    /// The selection as HTML; see `Core::selection_html`.
567    pub fn selection_html(&self) -> Option<String> {
568        self.core.selection_html()
569    }
570
571    /// Puts text on the system clipboard; see `Core::set_clipboard`.
572    pub fn set_clipboard(&mut self, text: impl Into<String>, html: Option<String>) {
573        self.core.set_clipboard(text, html);
574    }
575
576    /// Puts a secret on the system clipboard marked concealed and
577    /// transient, the way a password manager does; see
578    /// `Core::set_clipboard_secret`.
579    pub fn set_clipboard_secret(&mut self, text: impl Into<String>) {
580        self.core.set_clipboard_secret(text);
581    }
582
583    /// Asks for the clipboard's text, delivered as a `text` event on the
584    /// focused sink or as typing into the focused editor; see
585    /// `Core::request_paste`.
586    pub fn request_paste(&mut self) {
587        self.core.request_paste();
588    }
589
590    /// Whether a paste asked for is still unanswered; see
591    /// `Core::awaiting_paste`.
592    pub fn awaiting_paste(&self) -> bool {
593        self.core.awaiting_paste()
594    }
595
596    /// Asks the host for a file dialog; the answer is a `files` event to
597    /// whoever's view asked. False when one is already outstanding. See
598    /// `Core::request_files`.
599    #[track_caller]
600    pub fn request_files(&mut self, dialog: crate::dialog::FileDialog) -> bool {
601        self.core.request_files(dialog)
602    }
603
604    /// `Core::awaiting_files`.
605    pub fn awaiting_files(&self) -> bool {
606        self.core.awaiting_files()
607    }
608
609    /// Selects everything in the scope `key` declared; see
610    /// `Core::select_all_in`.
611    pub fn select_all_in(&mut self, key: Key) -> bool {
612        self.core.select_all_in(key)
613    }
614
615    /// Drops the window's selection; see `Core::clear_selection`.
616    pub fn clear_selection(&mut self) -> bool {
617        self.core.clear_selection()
618    }
619
620    /// The caret rect for a byte offset in the text node `key` drew; see
621    /// `Core::caret_rect`.
622    pub fn caret_rect(&self, key: Key, byte: usize) -> Option<Rect> {
623        self.core.caret_rect(key, byte)
624    }
625
626    /// `measure_text` for a rich-text paragraph.
627    pub fn measure_rich_text(
628        &mut self,
629        spans: &[Span<'_>],
630        base: &TextStyle,
631        max_w: Option<f32>,
632    ) -> crate::text::TextMetrics {
633        self.core.measure_rich_text(spans, base, max_w)
634    }
635
636    /// Opens a node under the next auto key; its children follow until
637    /// [`Self::close`]. [`Self::with`] is the scoped form, and the one to
638    /// prefer: an `open` without its `close` is a `node-left-open`
639    /// warning.
640    #[inline]
641    pub fn open(&mut self, spec: NodeSpec) -> Key {
642        self.core.open(spec)
643    }
644
645    /// [`Self::open`] under a label key: stable across frames whatever
646    /// the siblings before it, and what `key_of(label)` finds.
647    #[inline]
648    pub fn open_keyed(&mut self, label: &str, spec: NodeSpec) -> Key {
649        self.core.open_keyed(label, spec)
650    }
651
652    /// Opens a node under a key the caller built rather than a label:
653    /// `ui.child_key("gap").index(id)` is a label and an index with no
654    /// string formatted and no clash with the sibling-index keys
655    /// `open_indexed` gives, and a key kept from an earlier `child_key` —
656    /// read for `is_hovered` first — is opened as it is instead of spelled
657    /// twice. Build it from this parent's `child_key`: two nodes under one
658    /// key in a frame are a `duplicate-key` warning, as two labels are.
659    /// It has no label, so `key_of` does not find it.
660    #[inline]
661    pub fn open_key(&mut self, key: Key, spec: NodeSpec) -> Key {
662        self.core.open_key(key, spec)
663    }
664
665    /// Scoped [`Self::open_key`].
666    pub fn with_key(&mut self, key: Key, spec: NodeSpec, f: impl FnOnce(&mut Ui<'_>)) -> Key {
667        self.open_key(key, spec);
668        f(self);
669        self.close();
670        key
671    }
672
673    /// [`Self::leaf`] under a key the caller built; see [`Self::open_key`].
674    #[inline]
675    pub fn leaf_key(&mut self, key: Key, spec: NodeSpec) -> Key {
676        self.open_key(key, spec);
677        self.close();
678        key
679    }
680
681    /// `open` under a key the caller chose — the panel's own nodes, whose
682    /// keys another node anchors to by name before they exist.
683    #[inline]
684    pub(crate) fn open_with_key(&mut self, key: Key, label: &str, spec: NodeSpec) {
685        self.core.open_with_key_named(key, label, spec)
686    }
687
688    /// `open_keyed` by sibling index: the key auto-keying would have given
689    /// the `i`th child. A virtualizing list opens each row with its data
690    /// index, so a row keeps its identity when the built range slides past
691    /// it. See `Core::open_indexed`.
692    #[inline]
693    pub fn open_indexed(&mut self, i: u64, spec: NodeSpec) -> Key {
694        self.core.open_indexed(i, spec)
695    }
696
697    /// Closes the node the last `open*` opened.
698    #[inline]
699    pub fn close(&mut self) {
700        self.core.close();
701    }
702
703    /// Opens a node, runs `f` for its children and closes it. The usual
704    /// way to declare a container:
705    ///
706    /// ```rust
707    /// # use kui_core::{Core, NodeSpec, Size, TextStyle};
708    /// # let mut core = Core::new();
709    /// # let mut ui = core.frame(Size::new(200.0, 100.0), 1.0);
710    /// ui.with(NodeSpec::row().gap(8.0).pad(4.0), |ui| {
711    ///     ui.text("Name", TextStyle::new(14.0));
712    ///     ui.text("Ada", TextStyle::new(14.0));
713    /// });
714    /// # ui.finish();
715    /// ```
716    pub fn with(&mut self, spec: NodeSpec, f: impl FnOnce(&mut Ui<'_>)) -> Key {
717        let key = self.open(spec);
718        f(self);
719        self.close();
720        key
721    }
722
723    /// Scoped [`Self::open_keyed`].
724    pub fn with_keyed(&mut self, label: &str, spec: NodeSpec, f: impl FnOnce(&mut Ui<'_>)) -> Key {
725        let key = self.open_keyed(label, spec);
726        f(self);
727        self.close();
728        key
729    }
730
731    /// A node with no children: a spacer, a rule, a swatch, a hit area —
732    /// `with(spec, |_| {})` without the empty closure.
733    #[inline]
734    pub fn leaf(&mut self, spec: NodeSpec) -> Key {
735        let key = self.open(spec);
736        self.close();
737        key
738    }
739
740    /// [`Self::leaf`] under a label key.
741    #[inline]
742    pub fn leaf_keyed(&mut self, label: &str, spec: NodeSpec) -> Key {
743        let key = self.open_keyed(label, spec);
744        self.close();
745        key
746    }
747
748    /// [`Self::leaf`] under a data index; see [`Self::open_indexed`].
749    #[inline]
750    pub fn leaf_indexed(&mut self, i: u64, spec: NodeSpec) -> Key {
751        let key = self.open_indexed(i, spec);
752        self.close();
753        key
754    }
755
756    /// Declares how many indexed rows the open node's virtual list has,
757    /// built or not; see [`crate::Core::row_count`].
758    pub fn row_count(&mut self, n: u64) {
759        self.core.row_count(n);
760    }
761
762    /// Scoped `open_indexed`: the `i`th child's auto-key, given to a node
763    /// that is not in the `i`th slot.
764    pub fn with_indexed(&mut self, i: u64, spec: NodeSpec, f: impl FnOnce(&mut Ui<'_>)) -> Key {
765        let key = self.open_indexed(i, spec);
766        f(self);
767        self.close();
768        key
769    }
770
771    /// A paragraph of plain text in one style, wrapped at the width its
772    /// parent gives it. A text has no box of its own (no padding,
773    /// background, key or click); [`Self::text_in`] puts it in one.
774    ///
775    /// ```rust
776    /// # use kui_core::{Color, Core, NodeSpec, Size, TextStyle};
777    /// # let mut core = Core::new();
778    /// # let mut ui = core.frame(Size::new(200.0, 100.0), 1.0);
779    /// ui.text("Plain, in the theme's foreground", TextStyle::new(14.0));
780    /// ui.text("Bold-ish, mono, red", TextStyle::new(13.0).mono().color(Color::hex(0xd43b3bff)));
781    /// let badge = ui.text_in(NodeSpec::row().pad_xy(6.0, 2.0).radius(4.0), "3", TextStyle::new(12.0));
782    /// # let _ = badge;
783    /// # ui.finish();
784    /// ```
785    pub fn text(&mut self, content: &str, style: TextStyle) {
786        self.core.text_node(content, style);
787    }
788
789    /// A box of `spec` holding one text: `with(spec, |ui| ui.text(…))` for
790    /// the label, the cell, the badge that needs a width, a background, a
791    /// click or a role. Returns the box's key.
792    #[inline]
793    pub fn text_in(&mut self, spec: NodeSpec, content: &str, style: TextStyle) -> Key {
794        let key = self.open(spec);
795        self.text(content, style);
796        self.close();
797        key
798    }
799
800    /// [`Self::text_in`] under a label key.
801    #[inline]
802    pub fn text_in_keyed(
803        &mut self,
804        label: &str,
805        spec: NodeSpec,
806        content: &str,
807        style: TextStyle,
808    ) -> Key {
809        let key = self.open_keyed(label, spec);
810        self.text(content, style);
811        self.close();
812        key
813    }
814
815    /// [`Self::text_in`] under a data index; see [`Self::open_indexed`].
816    #[inline]
817    pub fn text_in_indexed(
818        &mut self,
819        i: u64,
820        spec: NodeSpec,
821        content: &str,
822        style: TextStyle,
823    ) -> Key {
824        let key = self.open_indexed(i, spec);
825        self.text(content, style);
826        self.close();
827        key
828    }
829
830    /// A cell grid (a terminal's screen) as one node; see
831    /// [`crate::cells`]. The spec is the node's own.
832    pub fn cells(&mut self, grid: &crate::cells::CellGrid<'_>, spec: NodeSpec) {
833        self.core.cells(grid, spec);
834    }
835
836    /// [`Self::cells`] under a data index; see [`Self::open_indexed`].
837    pub fn cells_indexed(&mut self, i: u64, grid: &crate::cells::CellGrid<'_>, spec: NodeSpec) {
838        self.core.cells_indexed(i, grid, spec);
839    }
840
841    /// [`Self::cells`] under a declared key.
842    pub fn cells_keyed(&mut self, label: &str, grid: &crate::cells::CellGrid<'_>, spec: NodeSpec) {
843        self.core.cells_keyed(label, grid, spec);
844    }
845
846    /// A paragraph of styled spans, shaped and wrapped as one flow.
847    pub fn rich_text(&mut self, spans: &[Span<'_>], base: TextStyle) {
848        self.core.rich_text_node(spans, base);
849    }
850
851    /// A registered image; see `Core::image_node` for sizing semantics.
852    pub fn image(&mut self, id: crate::resources::ImageId, spec: NodeSpec) {
853        self.core.image_node(id, spec);
854    }
855
856    /// [`Self::image`] with its `sampling` and `fit` rows; see
857    /// `Core::image_node_with`.
858    pub fn image_with(
859        &mut self,
860        id: crate::resources::ImageId,
861        opts: crate::resources::ImageOpts,
862        spec: NodeSpec,
863    ) {
864        self.core.image_node_with(id, opts, spec);
865    }
866
867    /// A box a registered WGSL function paints; see `Core::fragment_node`
868    /// for what it is, and `Core::add_fragment` for where the handle comes
869    /// from. It has no intrinsic size, so give it one.
870    ///
871    /// `frag` is the handle, or `handle.with_image(img)` for a function
872    /// that reads a registered image through `kui_sample(uv)`: a
873    /// waveform, a heatmap, an image effect.
874    pub fn fragment(
875        &mut self,
876        frag: impl Into<crate::fragment::FragmentRef>,
877        params: &[f32],
878        spec: NodeSpec,
879    ) -> Key {
880        self.core.fragment_node(frag, params, spec)
881    }
882
883    /// A fragment holding children, which paint over it: a gradient card
884    /// with a title and buttons on top of it.
885    pub fn fragment_with(
886        &mut self,
887        frag: impl Into<crate::fragment::FragmentRef>,
888        params: &[f32],
889        spec: NodeSpec,
890        f: impl FnOnce(&mut Ui<'_>),
891    ) -> Key {
892        let key = self.core.open_fragment(frag, params, spec);
893        f(self);
894        self.core.close();
895        key
896    }
897
898    /// [`Self::fragment`] under a label key, for one that transitions or
899    /// exits and needs a stable identity across frames.
900    pub fn fragment_keyed(
901        &mut self,
902        label: &str,
903        frag: impl Into<crate::fragment::FragmentRef>,
904        params: &[f32],
905        spec: NodeSpec,
906    ) -> Key {
907        self.core.fragment_node_keyed(label, frag, params, spec)
908    }
909
910    /// [`Self::fragment_with`] under a label key.
911    pub fn fragment_with_keyed(
912        &mut self,
913        label: &str,
914        frag: impl Into<crate::fragment::FragmentRef>,
915        params: &[f32],
916        spec: NodeSpec,
917        f: impl FnOnce(&mut Ui<'_>),
918    ) -> Key {
919        let key = self.core.open_fragment_keyed(label, frag, params, spec);
920        f(self);
921        self.core.close();
922        key
923    }
924
925    /// [`Self::fragment`] under a data index; see [`Self::open_indexed`].
926    pub fn fragment_indexed(
927        &mut self,
928        i: u64,
929        frag: impl Into<crate::fragment::FragmentRef>,
930        params: &[f32],
931        spec: NodeSpec,
932    ) -> Key {
933        let key = self.core.open_fragment_indexed(i, frag, params, spec);
934        self.core.close();
935        key
936    }
937
938    /// [`Self::fragment_with`] under a data index.
939    pub fn fragment_with_indexed(
940        &mut self,
941        i: u64,
942        frag: impl Into<crate::fragment::FragmentRef>,
943        params: &[f32],
944        spec: NodeSpec,
945        f: impl FnOnce(&mut Ui<'_>),
946    ) -> Key {
947        let key = self.core.open_fragment_indexed(i, frag, params, spec);
948        f(self);
949        self.core.close();
950        key
951    }
952
953    /// A round-capped segment from `from` to `to`, in the parent's box
954    /// space; see `Core::line_node` for what it is and is not.
955    #[inline]
956    pub fn line(&mut self, from: Vec2, to: Vec2, stroke: Stroke, spec: NodeSpec) {
957        self.core.line_node(&[from, to], stroke, spec);
958    }
959
960    /// [`Self::line`] under a label key.
961    pub fn line_keyed(
962        &mut self,
963        label: &str,
964        from: Vec2,
965        to: Vec2,
966        stroke: Stroke,
967        spec: NodeSpec,
968    ) {
969        self.core.line_node_keyed(label, &[from, to], stroke, spec);
970    }
971
972    /// [`Self::line`] under a data index; see [`Self::open_indexed`].
973    pub fn line_indexed(&mut self, i: u64, from: Vec2, to: Vec2, stroke: Stroke, spec: NodeSpec) {
974        self.core.line_node_indexed(i, &[from, to], stroke, spec);
975    }
976
977    /// A stroke through `points`: a polyline, or a smooth curve through
978    /// them with [`Stroke::curve`]; see `Core::line_node`.
979    #[inline]
980    pub fn polyline(&mut self, points: &[Vec2], stroke: Stroke, spec: NodeSpec) {
981        self.core.line_node(points, stroke, spec);
982    }
983
984    /// [`Self::polyline`] under a data index; see [`Self::open_indexed`].
985    pub fn polyline_indexed(&mut self, i: u64, points: &[Vec2], stroke: Stroke, spec: NodeSpec) {
986        self.core.line_node_indexed(i, points, stroke, spec);
987    }
988
989    /// [`Self::polyline`] under a label key.
990    pub fn polyline_keyed(&mut self, label: &str, points: &[Vec2], stroke: Stroke, spec: NodeSpec) {
991        self.core.line_node_keyed(label, points, stroke, spec);
992    }
993
994    /// A filled polygon through `points` in the parent's box space, the
995    /// fill in `spec`'s `bg`; see `Core::polygon_node` for what it is and
996    /// is not.
997    pub fn polygon(&mut self, points: &[Vec2], spec: NodeSpec) {
998        self.core.polygon_node(points, spec);
999    }
1000
1001    /// [`Self::polygon`] under a label key.
1002    pub fn polygon_keyed(&mut self, label: &str, points: &[Vec2], spec: NodeSpec) {
1003        self.core.polygon_node_keyed(label, points, spec);
1004    }
1005
1006    /// [`Self::polygon`] under a data index; see [`Self::open_indexed`].
1007    pub fn polygon_indexed(&mut self, i: u64, points: &[Vec2], spec: NodeSpec) {
1008        self.core.polygon_node_indexed(i, points, spec);
1009    }
1010
1011    /// A path — any outline — filled with `spec`'s `bg` and stroked by
1012    /// the path's own stroke; see `Core::path_node` for what it is and
1013    /// is not.
1014    pub fn path(&mut self, path: &crate::path::Path, spec: NodeSpec) {
1015        self.core.path_node(path, spec);
1016    }
1017
1018    /// [`Self::path`] under a label key.
1019    pub fn path_keyed(&mut self, label: &str, path: &crate::path::Path, spec: NodeSpec) {
1020        self.core.path_node_keyed(label, path, spec);
1021    }
1022
1023    /// [`Self::path`] under a data index; see [`Self::open_indexed`].
1024    pub fn path_indexed(&mut self, i: u64, path: &crate::path::Path, spec: NodeSpec) {
1025        self.core.path_node_indexed(i, path, spec);
1026    }
1027
1028    /// [`Self::path`] from SVG path data; data that does not parse raises
1029    /// `path-malformed` and draws nothing. See `Core::path_d_node`.
1030    pub fn path_d(
1031        &mut self,
1032        d: &str,
1033        rule: crate::path::FillRule,
1034        stroke: Option<Stroke>,
1035        turn: Option<crate::path::Turn>,
1036        spec: NodeSpec,
1037    ) {
1038        self.core.path_d_node(d, rule, stroke, turn, spec);
1039    }
1040
1041    /// [`Self::path_d`] under a label key.
1042    pub fn path_d_keyed(
1043        &mut self,
1044        label: &str,
1045        d: &str,
1046        rule: crate::path::FillRule,
1047        stroke: Option<Stroke>,
1048        turn: Option<crate::path::Turn>,
1049        spec: NodeSpec,
1050    ) {
1051        self.core
1052            .path_d_node_keyed(label, d, rule, stroke, turn, spec);
1053    }
1054
1055    /// An `audio` node: a playback retained for as long as the view keeps
1056    /// declaring it; see `Core::audio_node`.
1057    pub fn audio(&mut self, spec: crate::audio::AudioSpec) -> Key {
1058        self.core.audio_node(spec)
1059    }
1060
1061    /// `audio` with a label-derived key; see `Core::audio_node_keyed`.
1062    pub fn audio_keyed(&mut self, label: &str, spec: crate::audio::AudioSpec) -> Key {
1063        self.core.audio_node_keyed(label, spec)
1064    }
1065
1066    /// Starts a playback from a view; see `Core::play`. Views run every
1067    /// frame, so gate it on state that changes once (or use `audio`).
1068    pub fn play(
1069        &mut self,
1070        sound: crate::resources::SoundId,
1071        opts: crate::audio::PlayOptions,
1072    ) -> crate::audio::PlaybackId {
1073        self.core.play(sound, opts)
1074    }
1075
1076    /// An editable text node; state retained by key. See `Core::text_edit`.
1077    pub fn text_edit(
1078        &mut self,
1079        label: &str,
1080        initial: &str,
1081        opts: &EditOptions,
1082        spec: NodeSpec,
1083    ) -> Key {
1084        self.core.text_edit(label, initial, opts, spec)
1085    }
1086
1087    /// Whether `key` holds keyboard focus — any node: an editor, a key
1088    /// sink, a button Tab landed on (see `Core::focus`).
1089    pub fn is_focused(&self, key: Key) -> bool {
1090        self.core.is_focused(key)
1091    }
1092
1093    /// The node holding keyboard focus, if any.
1094    pub fn focused(&self) -> Option<Key> {
1095        self.core.focus()
1096    }
1097
1098    /// Whether focus got where it is by keyboard or assistive technology
1099    /// (a Tab press, a reader's request) rather than a click — when a
1100    /// view that styles its own focus should show it.
1101    pub fn focus_visible(&self) -> bool {
1102        self.core.focus_visible()
1103    }
1104
1105    /// The key of the node opened under `label` — in this frame so far,
1106    /// then in the last finished one. For a caller that holds only the
1107    /// label and cannot spell the path (`child_key` is the same question
1108    /// asked from the parent); see `Core::key_of`.
1109    pub fn key_of(&mut self, label: &str) -> Option<Key> {
1110        self.core.key_of(label)
1111    }
1112
1113    /// Moves keyboard focus to `key` now (an editor, an `on_key` sink, a
1114    /// control, a `focusable` node); see `Core::set_focus`.
1115    pub fn focus(&mut self, key: Key) {
1116        self.core.set_focus(Some(key));
1117    }
1118
1119    /// Drops keyboard focus.
1120    pub fn blur(&mut self) {
1121        self.core.set_focus(None);
1122    }
1123
1124    /// Moves focus to the next focusable node in tree order, wrapping —
1125    /// what Tab does. A key sink that binds Tab itself calls this to hand
1126    /// the keyboard on.
1127    ///
1128    /// Deferred, unlike the rest of this handle: a `Ui` only exists while a
1129    /// frame is being built, and `begin_frame` cleared the tree the Tab
1130    /// ring is made of, so stepping now would walk an empty ring. The step
1131    /// is applied at `finish`, against the frame this call is part of — so
1132    /// a view that declares three rows and asks to step lands on one of
1133    /// them, without waiting a frame for them to exist. Outside a frame
1134    /// (a driver handling a key press) `Core::focus_next` steps at once.
1135    #[track_caller]
1136    pub fn focus_next(&mut self) {
1137        self.core.request_focus_step(true);
1138    }
1139
1140    /// Shift-Tab: the previous focusable node. Deferred to `finish` for the
1141    /// reason [`Ui::focus_next`] gives.
1142    #[track_caller]
1143    pub fn focus_prev(&mut self) {
1144        self.core.request_focus_step(false);
1145    }
1146
1147    /// Enters a focus region (the node `key` names, declared
1148    /// `focus_region`), or the main ring for `None`: focus lands on what
1149    /// that ring
1150    /// last held if the node is still there, else its `initial_focus`,
1151    /// else its first stop, and shows. Deferred to `finish` like
1152    /// [`Ui::focus_next`], so a view may name the region it is declaring
1153    /// right now — the dock this frame toggles on. A key the frame does
1154    /// not declare as a region raises `focus-region-without-node`.
1155    #[track_caller]
1156    pub fn focus_region(&mut self, key: Option<Key>) {
1157        self.core.focus_region(key);
1158    }
1159
1160    /// The focus region in effect — the node whose ring Tab walks — or
1161    /// `None` for the main ring. What a chord that toggles between a dock
1162    /// and the app reads to know which way it is going.
1163    pub fn region(&self) -> Option<Key> {
1164        self.core.region()
1165    }
1166
1167    /// An editor's current text, by its key; `None` for a key no editor
1168    /// holds.
1169    pub fn edit_text(&self, key: Key) -> Option<String> {
1170        self.core.edit_text(key)
1171    }
1172
1173    /// Replaces an editor's text, caret at the end (`Core::set_edit_text`).
1174    /// Returns whether it reached an editor now, or was held for the
1175    /// frame that declares the key.
1176    pub fn set_edit_text(&mut self, key: Key, text: &str) -> bool {
1177        self.core.set_edit_text(key, text)
1178    }
1179
1180    /// The same by the label the view declares, for a caller with no key
1181    /// yet: an `update` opening a field the editor has not fired an
1182    /// event from (`Core::set_edit_text_by_label`).
1183    pub fn set_edit_text_by_label(&mut self, label: &str, text: &str) -> bool {
1184        self.core.set_edit_text_by_label(label, text)
1185    }
1186
1187    /// Says something once, with no node behind it (`Core::announce`).
1188    /// Takes effect at once, unlike `focus_next`: the queue is not made of
1189    /// a finished tree.
1190    ///
1191    /// A view runs every frame, so a call made from here needs a guard the
1192    /// app clears; the core reports the unguarded case as
1193    /// `announcement-repeated`. A region whose message is on screen is the
1194    /// `live` prop instead.
1195    pub fn announce(&mut self, text: &str, live: crate::access::Live) {
1196        self.core.announce(text, live);
1197    }
1198
1199    /// Scrolls whatever contains `key` so the node shows — "scroll to the
1200    /// selected row", without the container geometry the app cannot see.
1201    /// Resolved when this frame finishes laying out, so a row the view is
1202    /// declaring right now reveals fine; a key the frame does not declare,
1203    /// or one nothing scrollable contains, is a no-op. See `Core::reveal`.
1204    #[track_caller]
1205    pub fn reveal(&mut self, key: Key) {
1206        self.core.reveal(key);
1207    }
1208
1209    /// The handle for an installed or loaded font family by name (what
1210    /// `family = "Name"` resolves to in the declarative bindings), so a
1211    /// Rust view names a face without reaching for the core. `None` when
1212    /// no face matches. Idempotent.
1213    pub fn system_font(&mut self, name: &str) -> Option<crate::resources::FontId> {
1214        self.core.add_system_font(name)
1215    }
1216
1217    /// [`Self::reveal`] by label, resolved when this frame finishes; see
1218    /// `Core::reveal_label`.
1219    #[track_caller]
1220    pub fn reveal_label(&mut self, label: &str) {
1221        self.core.reveal_label(label);
1222    }
1223
1224    /// `set_scroll` by label, resolved before this frame lays out; see
1225    /// `Core::set_scroll_label`.
1226    #[track_caller]
1227    pub fn set_scroll_label(&mut self, label: &str, offset: Vec2) {
1228        self.core.set_scroll_label(label, offset);
1229    }
1230
1231    /// A scroll container's retained offset, clamped as of the last
1232    /// layout — the number to stash in a model and hand back to
1233    /// `set_scroll` later. Zero for a node that never scrolled.
1234    pub fn scroll_offset(&self, key: Key) -> Vec2 {
1235        self.core.scroll_offset(key)
1236    }
1237
1238    /// Sets that offset, the way the wheel would: `Vec2::ZERO` jumps to
1239    /// the top, a large value to the end (the next layout clamps it).
1240    #[track_caller]
1241    pub fn set_scroll(&mut self, key: Key, offset: Vec2) {
1242        self.core.set_scroll(key, offset);
1243    }
1244
1245    /// Moves a container's scroll state by the content that moved under
1246    /// it (`drawn` for the drawn place and an eased leg's start, `target`
1247    /// for the offset) with no ease asked or ended: a variable-height
1248    /// list's height correction. See `Core::shift_scroll`.
1249    pub fn shift_scroll(&mut self, key: Key, drawn: Vec2, target: Vec2) {
1250        self.core.shift_scroll(key, drawn, target);
1251    }
1252
1253    /// What the last layout resolved for a scroll container — its box, its
1254    /// content size and the clamped offset — so a view can build only the
1255    /// rows that fit and two spacers instead of ten thousand rows. `None`
1256    /// until a layout has resolved `key` as a container. It describes the
1257    /// previous frame; see `Core::scroll_geometry`, or
1258    /// `widgets::uniform_list` for the uniform-row case.
1259    pub fn scroll_geometry(&self, key: Key) -> Option<crate::scroll::ScrollGeometry> {
1260        self.core.scroll_geometry(key)
1261    }
1262
1263    /// The rect the last frame laid an `on_layout` node out at; see
1264    /// `Core::layout_of`.
1265    pub fn layout_of(&self, key: Key) -> Option<Rect> {
1266        self.core.layout_of(key)
1267    }
1268
1269    /// Declares this node focused: it takes keyboard focus when the
1270    /// declaration *starts* (the first frame it is made), and a Tab press
1271    /// afterwards is not clobbered by the view repeating it. An `on_key`
1272    /// sink then gets presses in `on_event` as `{kind="key", code, ctrl,
1273    /// alt, shift, super, text, repeat, tag}`. To move focus at any time,
1274    /// `focus(key)`.
1275    pub fn take_key_focus(&mut self, key: Key) {
1276        self.core.set_key_focus(Some(key));
1277    }
1278
1279    /// The node holding keyboard focus (the same as `focused`).
1280    pub fn key_focus(&self) -> Option<Key> {
1281        self.core.key_focus()
1282    }
1283
1284    /// Asks the frame driver to apply a window command (close from a
1285    /// keymap, minimize from a command line).
1286    pub fn window_command(&mut self, cmd: WindowCommand) {
1287        self.core.push_window_command(cmd);
1288    }
1289
1290    /// Asks the driver to resize a window (logical px) — a request applied
1291    /// on the driver's next pump and ignored headlessly, not a declaration:
1292    /// the user owns a window's size once it exists. `ui.env().window.id`
1293    /// is the window this view is drawing. See `Core::set_window_size`.
1294    pub fn set_window_size(&mut self, window: WindowId, size: Size) {
1295        self.core.set_window_size(window, size);
1296    }
1297
1298    /// Asks the driver to give a window keyboard focus; queued the same
1299    /// way. See `Core::focus_window`.
1300    pub fn focus_window(&mut self, window: WindowId) {
1301        self.core.focus_window(window);
1302    }
1303
1304    /// Runs layout and emission; results land in `Core::output()`. A frame
1305    /// begun with a filler lets it finish first: the `"root"` fill, unless
1306    /// the view declared it, and the `unknown-slot` check. An open context
1307    /// menu is drawn after both, which is what makes it the frame's modal
1308    /// scope and its topmost float.
1309    pub fn finish(self) {
1310        let Ui { core, filler } = self;
1311        // Not in the devtools' own window: nothing the host or an
1312        // extension declares there is built.
1313        if let Some(filler) = filler {
1314            if !core.devtools_window() {
1315                // A declared tab's extension fill first — a layer
1316                // anchored to a body the panel builds below, so the
1317                // filler's own `unknown-slot` check sees the slot
1318                // declared — then the root fills.
1319                core.devtools_fill_mount(filler);
1320                filler.finish(&mut Ui::new(core));
1321            }
1322            // The panel, after the fills and before the menu: the menu is
1323            // the last thing declared and so the topmost float.
1324            core.devtools_finish();
1325            if core.devtools_window() {
1326                // The panel's own window: the extension form's fill lands
1327                // here too, when the pane gave the frame a filler.
1328                core.devtools_fill_mount(filler);
1329            }
1330        } else {
1331            core.devtools_finish();
1332        }
1333        Core::build_menu(&mut Ui::new(core));
1334        core.finish_frame();
1335    }
1336}