pub struct Ui<B: Backend> {
pub layout_tree: LayoutTree,
pub layout_nodes: HashMap<WidgetId, LayoutNodeId>,
/* private fields */
}Expand description
Cross-platform UI manager over a concrete backend implementation.
Fields§
§layout_tree: LayoutTreeRepository-owned layout tree.
layout_nodes: HashMap<WidgetId, LayoutNodeId>Mapping of WidgetId to owned LayoutNodeId.
Implementations§
Source§impl<B: Backend> Ui<B>
impl<B: Backend> Ui<B>
Sourcepub fn operation_pending(&self, id: OperationId) -> bool
pub fn operation_pending(&self, id: OperationId) -> bool
Whether the operation is still pending (allocated and not completed).
Sourcepub fn cancel_operation(&mut self, id: OperationId) -> bool
pub fn cancel_operation(&mut self, id: OperationId) -> bool
Cancels a pending operation; reports false for unknown or already
finished ids (best-effort cancellation §7).
Sourcepub fn complete_operation(&mut self, id: OperationId) -> bool
pub fn complete_operation(&mut self, id: OperationId) -> bool
Marks an operation completed; reports false for stale ids, which
callers ignore instead of erroring.
Sourcepub fn host_advanced_control(
&mut self,
host: WidgetId,
family: AdvancedFamily,
) -> GuiResult<AdvancedHostCapabilities>
pub fn host_advanced_control( &mut self, host: WidgetId, family: AdvancedFamily, ) -> GuiResult<AdvancedHostCapabilities>
Calls the base hosting hook on the backend.
Source§impl<B: Backend> Ui<B>
impl<B: Backend> Ui<B>
Sourcepub fn backend_mut(&mut self) -> &mut B
pub fn backend_mut(&mut self) -> &mut B
Returns a mutable reference to the backend.
Sourcepub fn into_backend(self) -> B
pub fn into_backend(self) -> B
Consumes Ui and returns the owned backend.
Sourcepub fn create_with(
&mut self,
kind: WidgetKind,
configure: impl FnOnce(&mut WidgetSpec),
) -> GuiResult<WidgetId>
pub fn create_with( &mut self, kind: WidgetKind, configure: impl FnOnce(&mut WidgetSpec), ) -> GuiResult<WidgetId>
Creates a widget from a configured WidgetSpec.
The Ui allocates the identifier and keeps it authoritative: a closure
that writes spec.id cannot break the bookkeeping. configure may set
creation-time-only fields — toolbar_orientation (Win32 applies
CCS_VERT when the native control is created), toolbar items, colors,
size, position, selected_index, parent — that the set_* accessors
can only update after creation; the set_* path stays the live-update
route.
Sourcepub fn create(
&mut self,
kind: WidgetKind,
text: Option<&str>,
) -> GuiResult<WidgetId>
pub fn create( &mut self, kind: WidgetKind, text: Option<&str>, ) -> GuiResult<WidgetId>
Creates a widget and returns its identifier.
text is optional and interpreted by each widget/backend.
Creates a new menu and returns its identifier.
Adds an item to an existing menu.
Adds an item to an existing menu with an optional keyboard shortcut.
Attaches a menu to a window widget.
Enables or disables a menu item so state-dependent commands (Undo, Redo, Clear) grey out instead of looking actionable.
Backends without a native mapping return
GuiError::UnsupportedCapability instead of a silent no-op.
Relabels a menu item in place.
State-driven menus (a recent-files list, session lists, plugin menus)
update existing rows instead of closing and rebuilding the bar. The
item must already exist; a lane without a native mapping answers the
typed dynamic_menu_items capability error.
Inserts an item into an existing menu at index.
An index past the end appends, matching the slice-insert rule the bookkeeping uses, so a stale index can never panic a lane.
Inserts an item with an optional keyboard shortcut at index.
Removes a menu item from its menu.
Any on_menu_item_selected callback registered for the item is
dropped with it, so a stale row cannot fire into a dead handler.
Detaches a submenu from its parent and drops it.
The submenu’s own rows and their callbacks go with it, mirroring
remove_menu_item. Menus created with create_menu have no parent
and are rejected.
Attaches a menu as a right-click context menu on any widget.
Selecting an entry emits the usual UiEvent::MenuItemSelected with the
same MenuId/MenuItemId pair that the menu bar would produce.
Sourcepub fn create_tray_icon(&mut self, tooltip: &str) -> GuiResult<TrayIconId>
pub fn create_tray_icon(&mut self, tooltip: &str) -> GuiResult<TrayIconId>
Creates a system tray icon with the given tooltip.
The icon starts on the platform default image; pass pixels with
Ui::create_tray_icon_with_icon or update them later with
Ui::set_tray_icon_icon.
Sourcepub fn create_tray_icon_with_icon(
&mut self,
tooltip: &str,
icon_bytes: Vec<u8>,
) -> GuiResult<TrayIconId>
pub fn create_tray_icon_with_icon( &mut self, tooltip: &str, icon_bytes: Vec<u8>, ) -> GuiResult<TrayIconId>
Creates a system tray icon with the given tooltip and icon pixels.
icon_bytes travels to the backend through
TrayIconSpec::icon_bytes, so the payload uses the shared encoding
contract documented there: a square straight-alpha RGBA raster, or an
encoded container the lane recognises. Cocoa decodes either; Win32
consumes the RGBA raster. A lane that cannot decode the payload fails
this call rather than silently showing an image the application never
asked for.
Sourcepub fn destroy_tray_icon(&mut self, id: TrayIconId) -> GuiResult<()>
pub fn destroy_tray_icon(&mut self, id: TrayIconId) -> GuiResult<()>
Destroys a system tray icon by id.
Sourcepub fn set_tray_icon_tooltip(
&mut self,
id: TrayIconId,
tooltip: &str,
) -> GuiResult<()>
pub fn set_tray_icon_tooltip( &mut self, id: TrayIconId, tooltip: &str, ) -> GuiResult<()>
Updates the hover tooltip for a system tray icon.
Attaches or detaches a context menu for a system tray icon.
Sourcepub fn set_tray_icon_visible(
&mut self,
id: TrayIconId,
visible: bool,
) -> GuiResult<()>
pub fn set_tray_icon_visible( &mut self, id: TrayIconId, visible: bool, ) -> GuiResult<()>
Shows or hides a system tray icon.
Sourcepub fn set_tray_icon_icon(
&mut self,
id: TrayIconId,
icon_bytes: Option<Vec<u8>>,
) -> GuiResult<()>
pub fn set_tray_icon_icon( &mut self, id: TrayIconId, icon_bytes: Option<Vec<u8>>, ) -> GuiResult<()>
Replaces the icon pixels of a system tray icon.
None restores the platform default image. The stored specification is
only updated once the backend accepted the new payload, so a lane that
cannot swap icon pixels reports
GuiError::UnsupportedCapability and leaves the icon unchanged.
Sourcepub fn tray_icon(&self, id: TrayIconId) -> Option<&TrayIconSpec>
pub fn tray_icon(&self, id: TrayIconId) -> Option<&TrayIconSpec>
Returns the specification of a registered system tray icon, if present.
Sourcepub fn tray_icons(&self) -> &HashMap<TrayIconId, TrayIconSpec>
pub fn tray_icons(&self) -> &HashMap<TrayIconId, TrayIconSpec>
Returns a map of all currently registered system tray icons.
Sourcepub fn show_confirm_dialog(
&mut self,
title: &str,
message: &str,
) -> GuiResult<u64>
pub fn show_confirm_dialog( &mut self, title: &str, message: &str, ) -> GuiResult<u64>
Shows a modal Yes/No confirm dialog and returns a token identifying
it. The answer arrives as UiEvent::DialogResponse { token, confirmed }
from the event queue. When a focused widget or window is available, its
assistive technology receives an announcement before the modal backend
call begins.
Sourcepub fn show_file_dialog(&mut self, request: FileDialog) -> GuiResult<u64>
pub fn show_file_dialog(&mut self, request: FileDialog) -> GuiResult<u64>
Opens a native file dialog without creating a widget (dogfood report
#5) and returns a token. The answer arrives as
UiEvent::FileDialogResponse { token, paths }; paths is empty
when the user cancelled. Lanes without a function-style dialog report
GuiError::UnsupportedCapability("file_dialog") (Win32 and Cocoa
today); the FileChooserDialog widget keeps working everywhere.
use native_gui_core::file_dialog::FileDialog;
let token = ui.show_file_dialog(
FileDialog::save()
.title("Save jobs")
.filter("JSON", &["*.json"])
.suggested_name("jobs.json"),
)?;
// later: UiEvent::FileDialogResponse { token, paths } => ...Sourcepub fn native_window_handle(
&self,
window_id: WidgetId,
) -> GuiResult<NativeWindowHandle>
pub fn native_window_handle( &self, window_id: WidgetId, ) -> GuiResult<NativeWindowHandle>
Returns the platform handles of a top-level window, for interop with renderers and native APIs (found while dogfooding).
The window must exist and be realized (shown at least once). Backends
without support (Mock, TUI, Web, and currently Win32/Cocoa unless they
implement it) return GuiError::UnsupportedCapability. See also
Ui::window_handle behind the raw-window-handle feature.
Sourcepub fn set_close_guard(
&mut self,
widget_id: WidgetId,
guarded: bool,
) -> GuiResult<()>
pub fn set_close_guard( &mut self, widget_id: WidgetId, guarded: bool, ) -> GuiResult<()>
Enables or disables close-request interception for a window (GH-056).
A guarded window reports UiEvent::CloseRequested instead of
closing; the app answers the request (for example through
Ui::show_confirm_dialog) and approves a close by disabling the
guard and calling Ui::remove. Lanes without interception return
GuiError::UnsupportedCapability.
Sourcepub fn timer_capabilities(&self) -> TimerCapabilities
pub fn timer_capabilities(&self) -> TimerCapabilities
Reports timer operations available on this backend.
Sourcepub fn motion_capabilities(&self) -> MotionCapabilities
pub fn motion_capabilities(&self) -> MotionCapabilities
Reports timer-driven motion support on this backend.
Sourcepub fn start_motion(
&mut self,
widget_id: WidgetId,
spec: MotionSpec,
) -> GuiResult<MotionId>
pub fn start_motion( &mut self, widget_id: WidgetId, spec: MotionSpec, ) -> GuiResult<MotionId>
Starts a linear motion driven by the backend’s timer event loop.
Coalesced ticks use a bounded 16 ms cadence. The first tick is at
min(duration, 16 ms) and completion is reported at the first tick at
or after duration. Zero duration is invalid; exhausted motion/timer
IDs and a backend deadline that overflows its clock return errors
without registering a motion.
Sourcepub fn cancel_motion(&mut self, motion: MotionId) -> GuiResult<()>
pub fn cancel_motion(&mut self, motion: MotionId) -> GuiResult<()>
Cancels a live motion and purges any not-yet-delivered progress events.
Sourcepub fn start_timer(&mut self, spec: TimerSpec) -> GuiResult<TimerId>
pub fn start_timer(&mut self, spec: TimerSpec) -> GuiResult<TimerId>
Starts a one-shot or repeating timer on the UI event loop.
Sourcepub fn start_widget_timer(
&mut self,
widget_id: WidgetId,
spec: TimerSpec,
stop_policy: TimerStopPolicy,
) -> GuiResult<TimerId>
pub fn start_widget_timer( &mut self, widget_id: WidgetId, spec: TimerSpec, stop_policy: TimerStopPolicy, ) -> GuiResult<TimerId>
Starts a timer whose lifecycle follows a widget’s removal/hide policy.
Sourcepub fn cancel_timer(&mut self, timer: TimerId) -> GuiResult<()>
pub fn cancel_timer(&mut self, timer: TimerId) -> GuiResult<()>
Cancels a live timer; unknown, cancelled, or fired ids use the backend’s
Timer not found: {id} error convention.
Sourcepub fn window_capabilities(&self) -> WindowCapabilities
pub fn window_capabilities(&self) -> WindowCapabilities
Reports the extended window features available from this backend.
Sourcepub fn set_window_options(
&mut self,
widget_id: WidgetId,
options: WindowOptions,
) -> GuiResult<()>
pub fn set_window_options( &mut self, widget_id: WidgetId, options: WindowOptions, ) -> GuiResult<()>
Validates and applies portable options to a top-level window.
Sourcepub fn window_options(&self, widget_id: WidgetId) -> GuiResult<WindowOptions>
pub fn window_options(&self, widget_id: WidgetId) -> GuiResult<WindowOptions>
Returns the options last applied to a window, or the portable defaults.
Sourcepub fn dismiss_popup(&mut self, widget_id: WidgetId) -> GuiResult<()>
pub fn dismiss_popup(&mut self, widget_id: WidgetId) -> GuiResult<()>
Hides an active popup at the backend without reporting a user-dismissal event.
User- and OS-initiated dismissals arrive separately as
UiEvent::PopupDismissed.
Sourcepub fn set_text(&mut self, widget_id: WidgetId, text: &str) -> GuiResult<()>
pub fn set_text(&mut self, widget_id: WidgetId, text: &str) -> GuiResult<()>
Updates text content for a widget.
An embedded NUL is rejected before the spec or the backend changes.
Native string APIs (SetWindowTextW, GTK C strings, NSString)
truncate at the first NUL, so accepting one would store a suffix the
control never shows.
Sourcepub fn set_label_alignment(
&mut self,
widget_id: WidgetId,
alignment: LabelAlignment,
) -> GuiResult<()>
pub fn set_label_alignment( &mut self, widget_id: WidgetId, alignment: LabelAlignment, ) -> GuiResult<()>
Sets horizontal alignment for a label.
The value is stored only after the backend accepts it, so a lane without this mapping leaves the shared spec unchanged.
Sourcepub fn set_label_wrap(
&mut self,
widget_id: WidgetId,
wrap: LabelWrap,
) -> GuiResult<()>
pub fn set_label_wrap( &mut self, widget_id: WidgetId, wrap: LabelWrap, ) -> GuiResult<()>
Sets the line-wrapping mode for a label.
The value is stored only after the backend accepts it, so an unsupported wrapping mode leaves the shared spec unchanged.
Sourcepub fn text_selection(&self, widget_id: WidgetId) -> GuiResult<(usize, usize)>
pub fn text_selection(&self, widget_id: WidgetId) -> GuiResult<(usize, usize)>
Reads the live text selection, in Unicode characters (not bytes/UTF-16).
Sourcepub fn set_text_selection(
&mut self,
widget_id: WidgetId,
start: usize,
end: usize,
) -> GuiResult<()>
pub fn set_text_selection( &mut self, widget_id: WidgetId, start: usize, end: usize, ) -> GuiResult<()>
Selects a character range in a text control.
Offsets are character positions (Unicode scalar values): start
inclusive, end exclusive, so (0, 0) places a caret at the start.
The range is mirrored in the widget spec and forwarded to the
backend’s native selection mapping (TextInput, TextArea, RichText).
Sourcepub fn set_text_completion_items(
&mut self,
widget_id: WidgetId,
items: &[String],
) -> GuiResult<()>
pub fn set_text_completion_items( &mut self, widget_id: WidgetId, items: &[String], ) -> GuiResult<()>
Sets the completion/suggestion item list for a TextInput.
The shared model stores the full list and the backend applies it to
its native completion source; the lane owns filtering and its popup
(see docs/widget-expansion-roadmap.md, “TextInput completion”).
The call is transactional: the shared spec records items only after
the backend accepted them, so a lane without a completion mapping
(typed GuiError::UnsupportedCapability with the "text_completion"
identifier) leaves the model exactly as it was.
Sourcepub fn set_placeholder_text(
&mut self,
widget_id: WidgetId,
text: &str,
) -> GuiResult<()>
pub fn set_placeholder_text( &mut self, widget_id: WidgetId, text: &str, ) -> GuiResult<()>
Sets placeholder/hint text on a TextInput widget.
An embedded NUL is rejected before the spec or the backend changes:
cue-banner APIs (EM_SETCUEBANNER, GTK placeholder, AppKit
setPlaceholderString:) truncate at the first NUL.
Sourcepub fn set_monospace(
&mut self,
widget_id: WidgetId,
monospace: bool,
) -> GuiResult<()>
pub fn set_monospace( &mut self, widget_id: WidgetId, monospace: bool, ) -> GuiResult<()>
Sets monospace font rendering on a supported widget (TextArea, TextInput, Label,
RichText).
Sourcepub fn set_font(
&mut self,
widget_id: WidgetId,
font: Option<&FontDescriptor>,
) -> GuiResult<()>
pub fn set_font( &mut self, widget_id: WidgetId, font: Option<&FontDescriptor>, ) -> GuiResult<()>
Sets an explicit font family, size, weight, and slant on a supported widget (Label, Button, TextInput, TextArea).
Passing None clears the custom font back to the active theme/platform default.
Sourcepub fn set_row_icons(
&mut self,
widget_id: WidgetId,
icons: &[Option<IconRole>],
) -> GuiResult<()>
pub fn set_row_icons( &mut self, widget_id: WidgetId, icons: &[Option<IconRole>], ) -> GuiResult<()>
Sets per-row IconRole icons on a DataList or ListView widget.
Each slot aligns by row index (None omits an icon for that row); passing
an empty slice clears all row icons.
Sourcepub fn set_spell_check(
&mut self,
widget_id: WidgetId,
enabled: bool,
) -> GuiResult<()>
pub fn set_spell_check( &mut self, widget_id: WidgetId, enabled: bool, ) -> GuiResult<()>
Enables or disables the native control’s built-in spell checking on a
TextArea or RichText (NSTextView continuous checking, RichEdit
IMF_SPELLCHECKING). No dictionary engine is bundled: lanes whose
control has no built-in checker (GTK4 GtkTextView, TUI, Web) return
GuiError::UnsupportedCapability.
Sourcepub fn set_rich_text_runs(
&mut self,
widget_id: WidgetId,
runs: &[TextRun],
) -> GuiResult<()>
pub fn set_rich_text_runs( &mut self, widget_id: WidgetId, runs: &[TextRun], ) -> GuiResult<()>
Sets styled text runs on a RichText widget.
Sourcepub fn set_rich_text_images(
&mut self,
widget_id: WidgetId,
images: &[RichTextImage],
) -> GuiResult<()>
pub fn set_rich_text_images( &mut self, widget_id: WidgetId, images: &[RichTextImage], ) -> GuiResult<()>
Sets inline images on a RichText widget.
Sourcepub fn set_checked(
&mut self,
widget_id: WidgetId,
checked: bool,
) -> GuiResult<()>
pub fn set_checked( &mut self, widget_id: WidgetId, checked: bool, ) -> GuiResult<()>
Updates checked state for a widget that supports it.
Sourcepub fn set_value(&mut self, widget_id: WidgetId, value: i32) -> GuiResult<()>
pub fn set_value(&mut self, widget_id: WidgetId, value: i32) -> GuiResult<()>
Sets numeric value for widgets that support it.
Sourcepub fn set_range(
&mut self,
widget_id: WidgetId,
min: i32,
max: i32,
) -> GuiResult<()>
pub fn set_range( &mut self, widget_id: WidgetId, min: i32, max: i32, ) -> GuiResult<()>
Sets numeric range for widgets that support it.
Sourcepub fn set_step(&mut self, widget_id: WidgetId, step: i32) -> GuiResult<()>
pub fn set_step(&mut self, widget_id: WidgetId, step: i32) -> GuiResult<()>
Sets step value for widgets that support it.
Sourcepub fn set_selected_index(
&mut self,
widget_id: WidgetId,
index: usize,
) -> GuiResult<()>
pub fn set_selected_index( &mut self, widget_id: WidgetId, index: usize, ) -> GuiResult<()>
Sets selected index for widgets that support item/page selection.
On a widget with keyed rows, the index is also mapped to its
RowKey so a later Self::set_rows_keyed follows the selection
by identity instead of by position.
Sourcepub fn set_tab_items(
&mut self,
widget_id: WidgetId,
items: &[String],
) -> GuiResult<()>
pub fn set_tab_items( &mut self, widget_id: WidgetId, items: &[String], ) -> GuiResult<()>
Sets page labels for a tabs widget.
Labels follow the attached pages in attach order; pages without a
label keep the backend placeholder header. The WYSIWYG inspector and
app code can now drive WidgetSpec.tab_items at runtime.
Sourcepub fn min_tabs_height(&self, widget_id: WidgetId) -> f32
pub fn min_tabs_height(&self, widget_id: WidgetId) -> f32
Resolves the dynamic minimum height floor for a Tabs widget strip.
If the backend provides a positive natural height for the widget (e.g.
measured tab strip typography, platform theme metrics, or DPI-scaled tab buttons),
that height is used as the floor. Otherwise, falls back to MIN_TABS_HEIGHT (30.0 pt).
Sourcepub fn tabs_min_height(&self, widget_id: WidgetId) -> f32
pub fn tabs_min_height(&self, widget_id: WidgetId) -> f32
Alias for Self::min_tabs_height for ergonomic naming.
Sourcepub fn set_selected_indices(
&mut self,
widget_id: WidgetId,
indices: &[usize],
) -> GuiResult<()>
pub fn set_selected_indices( &mut self, widget_id: WidgetId, indices: &[usize], ) -> GuiResult<()>
Sets multiple selected indices for multi-select list/tree widgets.
On a widget with keyed rows, the indices are also mapped to
their RowKeys so a later Self::set_rows_keyed keeps the
surviving members selected.
Sourcepub fn set_row_drag(
&mut self,
widget_id: WidgetId,
source: bool,
target: bool,
) -> GuiResult<()>
pub fn set_row_drag( &mut self, widget_id: WidgetId, source: bool, target: bool, ) -> GuiResult<()>
Enables/disables row drag-source and drop-target behavior on a row widget (ListView/DataList/DataGrid/TreeView).
Drags started from a source widget emit UiEvent::DragStarted with the
dragged row indices; dropping onto a target emits UiEvent::Dropped
with the hit-tested target_index and the source_indices.
Sourcepub fn set_drag_source(
&mut self,
widget_id: WidgetId,
options: DragSourceOptions,
) -> GuiResult<()>
pub fn set_drag_source( &mut self, widget_id: WidgetId, options: DragSourceOptions, ) -> GuiResult<()>
Configures an additive text/custom-MIME drag source.
MIME values are normalized to lowercase and duplicate kinds are
removed while preserving preference order. Existing row drags remain
configured independently through Self::set_row_drag.
Sourcepub fn set_drag_target_options(
&mut self,
widget_id: WidgetId,
options: DragTargetOptions,
) -> GuiResult<()>
pub fn set_drag_target_options( &mut self, widget_id: WidgetId, options: DragTargetOptions, ) -> GuiResult<()>
Configures accepted text/custom-MIME kinds and the requested drop effect.
This is separate from Self::set_drop_target, which retains its
existing boolean file/URL/text API.
Sourcepub fn drag_capabilities(&self) -> DragCapabilities
pub fn drag_capabilities(&self) -> DragCapabilities
Reports support for text, custom-MIME, feedback, and preview operations.
Sourcepub fn set_file_drop_target(
&mut self,
widget_id: WidgetId,
enabled: bool,
) -> GuiResult<()>
pub fn set_file_drop_target( &mut self, widget_id: WidgetId, enabled: bool, ) -> GuiResult<()>
Enables/disables accepting external file drops from the OS shell.
When enabled, files dragged and dropped from native shell file managers
(e.g. Windows Explorer, macOS Finder, GNOME Files/Nautilus) emit
UiEvent::FilesDropped { widget_id, paths }.
Sourcepub fn set_drop_target(
&mut self,
widget_id: WidgetId,
enabled: bool,
) -> GuiResult<()>
pub fn set_drop_target( &mut self, widget_id: WidgetId, enabled: bool, ) -> GuiResult<()>
Enables or disables drop target support on a widget for files, URLs, and text.
When enabled, dropping files emits UiEvent::FilesDropped, dropping
URLs emits UiEvent::UrlsDropped, and dropping plain text emits
UiEvent::TextDropped. When dropped onto text widgets (such as
WidgetKind::RichText or WidgetKind::TextArea), the drop event
includes the character caret offset where the drop occurred.
Sourcepub fn set_size(
&mut self,
widget_id: WidgetId,
width: i32,
height: i32,
) -> GuiResult<()>
pub fn set_size( &mut self, widget_id: WidgetId, width: i32, height: i32, ) -> GuiResult<()>
Sets preferred dimensions for a widget.
The request is written into the widget’s layout style as well as the
spec and the backend, mirroring Self::set_container_direction, so
a later compute_layout pass honours it instead of rewriting it with
the computed value (imperative and declarative authoring must produce
the same result).
Sourcepub fn set_flex_grow(&mut self, widget_id: WidgetId, grow: f32) -> GuiResult<()>
pub fn set_flex_grow(&mut self, widget_id: WidgetId, grow: f32) -> GuiResult<()>
Sets how much of its parent container’s spare main-axis space a widget absorbs on each layout pass.
This is the imperative counterpart of the declarative
crate::declarative::Node::flex_grow: 0.0 (the default) keeps
the widget at its requested or natural size, while positive factors
split the remaining space between growing siblings proportionally. A
Self::set_size request becomes the widget’s basis, so a pinned
pane still grows when its window is enlarged. The main axis is the
parent’s ContainerDirection; layout roots registered with
Self::set_layout_root apply the change on their next resize, and
Self::compute_layout applies it immediately.
Sourcepub fn flex_grow(&self, widget_id: WidgetId) -> GuiResult<f32>
pub fn flex_grow(&self, widget_id: WidgetId) -> GuiResult<f32>
Returns the flex-grow factor set by Self::set_flex_grow.
Sourcepub fn set_min_size(
&mut self,
widget_id: WidgetId,
width: i32,
height: i32,
) -> GuiResult<()>
pub fn set_min_size( &mut self, widget_id: WidgetId, width: i32, height: i32, ) -> GuiResult<()>
Sets the smallest size layout passes may give a widget.
Unlike Self::set_size, which pins both axes, a minimum leaves the
widget free to stretch across its parent’s cross axis and, with
Self::set_flex_grow, along the main axis - the usual way to keep a
designed size for a pane while letting it fill a larger window. A 0
component leaves that axis unconstrained; (0, 0) clears the minimum.
Applies on the next Self::compute_layout or layout-root resize.
The floor is recorded on the shared model and forwarded to the backend so lanes that own their automatic layout (Win32) honour it too, not just the shared pass.
Sourcepub fn min_size(&self, widget_id: WidgetId) -> GuiResult<(i32, i32)>
pub fn min_size(&self, widget_id: WidgetId) -> GuiResult<(i32, i32)>
Returns the minimum recorded by Self::set_min_size, (0, 0) when
none is set.
Sourcepub fn set_preferred_width(
&mut self,
widget_id: WidgetId,
width: u32,
) -> GuiResult<()>
pub fn set_preferred_width( &mut self, widget_id: WidgetId, width: u32, ) -> GuiResult<()>
Sets a width-only constraint on a widget’s layout node, leaving its height unconstrained.
This allows panels and inspectors (such as in gui_photo_gallery)
to fix their width without having to re-pin their height to match
their container when the window resizes.
Sourcepub fn preferred_width(&self, widget_id: WidgetId) -> GuiResult<Option<u32>>
pub fn preferred_width(&self, widget_id: WidgetId) -> GuiResult<Option<u32>>
Returns the preferred width set by Self::set_preferred_width, or None if not set.
Sourcepub fn set_layout_style(
&mut self,
widget_id: WidgetId,
style: Style,
) -> GuiResult<()>
pub fn set_layout_style( &mut self, widget_id: WidgetId, style: Style, ) -> GuiResult<()>
Sets the layout style on a widget using Native GUI-owned layout types.
Validates all numeric constraints (finite numbers, non-negative factors and dimensions) before applying the style and schedules an incremental layout invalidation pass.
Sourcepub fn layout_style(&self, widget_id: WidgetId) -> GuiResult<Style>
pub fn layout_style(&self, widget_id: WidgetId) -> GuiResult<Style>
Returns the current layout style of a widget as an native-gui-owned
crate::layout::Style.
Sourcepub fn layout_rect(&self, widget_id: WidgetId) -> GuiResult<LayoutRect>
pub fn layout_rect(&self, widget_id: WidgetId) -> GuiResult<LayoutRect>
Returns the computed layout rectangle for a widget in parent-local coordinates.
Sourcepub fn debug_layout(&self, root: WidgetId) -> GuiResult<String>
pub fn debug_layout(&self, root: WidgetId) -> GuiResult<String>
Renders the computed layout of root and its descendants as an
indented text tree, one widget per line: id, kind, text, the
parent-local rect from the last Self::compute_layout, and flags
for hidden widgets, flex_grow, and app minimum sizes. A debugging
aid for “why is this row zero pixels tall?” (found while dogfooding);
the format is for humans and may change.
let window = ui.create(WidgetKind::Window, Some("Main"))?;
ui.compute_layout(window, 640.0, 480.0)?;
eprintln!("{}", ui.debug_layout(window)?);Sourcepub fn set_window_min_size(
&mut self,
widget_id: WidgetId,
width: u32,
height: u32,
) -> GuiResult<()>
pub fn set_window_min_size( &mut self, widget_id: WidgetId, width: u32, height: u32, ) -> GuiResult<()>
Sets the minimum dimensions for a top-level window.
Returns GuiError::UnsupportedWidget if widget_id is not a window.
Sourcepub fn window_min_size(
&self,
widget_id: WidgetId,
) -> GuiResult<Option<(u32, u32)>>
pub fn window_min_size( &self, widget_id: WidgetId, ) -> GuiResult<Option<(u32, u32)>>
Returns the minimum size set on a window via Self::set_window_min_size,
or derived from its layout root content minimum.
Sourcepub fn explicit_window_min_size(
&self,
widget_id: WidgetId,
) -> GuiResult<Option<(u32, u32)>>
pub fn explicit_window_min_size( &self, widget_id: WidgetId, ) -> GuiResult<Option<(u32, u32)>>
Returns only the explicit minimum size set on a window via Self::set_window_min_size.
Sourcepub fn set_resizable(
&mut self,
widget_id: WidgetId,
resizable: bool,
) -> GuiResult<()>
pub fn set_resizable( &mut self, widget_id: WidgetId, resizable: bool, ) -> GuiResult<()>
Sets whether a top-level window can be resized by the user.
Returns GuiError::UnsupportedWidget if widget_id is not a window.
Sourcepub fn is_resizable(&self, widget_id: WidgetId) -> GuiResult<bool>
pub fn is_resizable(&self, widget_id: WidgetId) -> GuiResult<bool>
Returns whether a window is resizable. Defaults to true.
Sourcepub fn native_handle(&self, widget_id: WidgetId) -> GuiResult<B::NativeHandle>
pub fn native_handle(&self, widget_id: WidgetId) -> GuiResult<B::NativeHandle>
Returns backend-native handle information for a Vulkan canvas widget.
Sourcepub fn vulkan_canvas_handle(
&self,
widget_id: WidgetId,
) -> GuiResult<B::NativeHandle>
pub fn vulkan_canvas_handle( &self, widget_id: WidgetId, ) -> GuiResult<B::NativeHandle>
Returns backend-native handle information for a Vulkan canvas widget.
Sourcepub fn metal_canvas_handle(
&self,
widget_id: WidgetId,
) -> GuiResult<MetalCanvasHandle>
pub fn metal_canvas_handle( &self, widget_id: WidgetId, ) -> GuiResult<MetalCanvasHandle>
Returns backend-native handle information for a Metal canvas widget.
Sourcepub fn create_combo_box<S: AsRef<str>>(
&mut self,
items: &[S],
) -> GuiResult<WidgetId>
pub fn create_combo_box<S: AsRef<str>>( &mut self, items: &[S], ) -> GuiResult<WidgetId>
Creates a ComboBox with typed options (found while dogfooding),
replacing the legacy create(WidgetKind::ComboBox, Some("A|B|C"))
form (still accepted, but deprecated in the docs). Works on every lane.
The first option is selected.
Sourcepub fn set_items<S: AsRef<str>>(
&mut self,
widget_id: WidgetId,
items: &[S],
) -> GuiResult<()>
pub fn set_items<S: AsRef<str>>( &mut self, widget_id: WidgetId, items: &[S], ) -> GuiResult<()>
Replaces the options of a choice widget from a slice (dogfood report
#7). ComboBox goes through Backend::set_combo_box_items (supported
across Mock, GTK, Win32, Cocoa, Web, and TUI when widgets-choice is
enabled), keeping the selected index in Ui’s model when it is still in
range and otherwise selecting the first option, silently. MultiSelect,
DataList and ListView forward to Self::set_data_list_items.
Sourcepub fn items(&self, widget_id: WidgetId) -> GuiResult<Vec<String>>
pub fn items(&self, widget_id: WidgetId) -> GuiResult<Vec<String>>
The options of a choice widget: a ComboBox/MultiSelect’s options
(parsed from the creation text, or the last Self::set_items), or a
DataList/ListView’s items.
Sourcepub fn set_data_list_items(
&mut self,
widget_id: WidgetId,
items: &[String],
) -> GuiResult<()>
pub fn set_data_list_items( &mut self, widget_id: WidgetId, items: &[String], ) -> GuiResult<()>
Sets items for a data list widget.
Sourcepub fn set_list_columns(
&mut self,
widget_id: WidgetId,
columns: &[ColumnSpec],
) -> GuiResult<()>
pub fn set_list_columns( &mut self, widget_id: WidgetId, columns: &[ColumnSpec], ) -> GuiResult<()>
Replaces the column headers of a columned list.
Validates the widget kind through the shared applicability table
(ListView only), records the columns on the spec, and forwards to
the backend. Passing an empty slice returns the widget to the
shipped single-column row contract, where rows come from
Self::set_data_list_items. A lane without a columned mapping
reports the typed UnsupportedCapability("list_view_columns")
refusal (native mappings are follow-ups).
Sourcepub fn set_list_rows(
&mut self,
widget_id: WidgetId,
rows: &[Vec<String>],
) -> GuiResult<()>
pub fn set_list_rows( &mut self, widget_id: WidgetId, rows: &[Vec<String>], ) -> GuiResult<()>
Replaces the row cells of a columned list.
Row r, cell c renders column c’s header with the text
rows[r][c]; missing trailing cells render empty and cells beyond
the column count are ignored. Shares the kind guard and the lane
capability refusal with Self::set_list_columns.
Sourcepub fn set_rows_keyed(
&mut self,
widget_id: WidgetId,
rows: &[RowSet],
) -> GuiResult<RowDelta>
pub fn set_rows_keyed( &mut self, widget_id: WidgetId, rows: &[RowSet], ) -> GuiResult<RowDelta>
Applies a keyed row update to a row widget.
Identity is the application-owned RowKey: the submitted vector
defines display order, cells replace verbatim, and the returned
RowDelta classifies what changed. Equal keys, order, and cells are
a free no-op (no backend call at all). Duplicate keys are rejected
with GuiError::Backend("duplicate row key") before anything is
touched, and a lane that cannot drop a removed selection reports the
typed UnsupportedCapability("clear_selection") refusal, also before
the rows change.
The selection follows the key the widget kept (recorded when
Self::set_selected_index/Self::set_selected_indices ran on
keyed rows): an index move writes the new index and emits one
SelectionChanged carrying it; a removed key clears the selection
and emits the clear through Self::clear_selection. The scroll
anchor follows the same rule through the lane’s scroll_anchor
capability; a lane that cannot report it is skipped rather than
guessed.
Keyed bookkeeping tracks keyed applies; calling the plain population
setters in between resets the baseline, so the next keyed apply
reports everything it writes as inserted. TreeView keeps its flat
indented-row contract for this cut.
Sourcepub fn clear_selection(&mut self, widget_id: WidgetId) -> GuiResult<()>
pub fn clear_selection(&mut self, widget_id: WidgetId) -> GuiResult<()>
Clears the selection of a row widget.
Clears the shared index and multi-selection state, drops the keyed
selection, asks the backend to clear its native selection (the
"clear_selection" capability; lanes without a mapping report the
typed refusal), and emits one
UiEvent::SelectionChanged { selected: None, index: None } when a
selection was actually cleared, so observers never miss a silent
reset. The backend is consulted before the shared model changes, so a
refused call leaves the previous selection untouched.
Sourcepub fn visible_anchor(&self, widget_id: WidgetId) -> GuiResult<Option<RowKey>>
pub fn visible_anchor(&self, widget_id: WidgetId) -> GuiResult<Option<RowKey>>
Returns the application-owned key of a keyed row widget’s topmost visible row.
The backend reports the anchor row’s index through the
"scroll_anchor" capability; a lane that cannot observe its scroll
position returns the typed GuiError::UnsupportedCapability
refusal, and a widget without keyed rows answers None.
Sourcepub fn rows_end_visible(&self, widget_id: WidgetId) -> GuiResult<bool>
pub fn rows_end_visible(&self, widget_id: WidgetId) -> GuiResult<bool>
Reports whether the last row of a keyed row widget is currently visible (follow-tail detection).
Forwarded to the backend’s Backend::rows_end_visible capability
(the same "scroll_anchor" family as
Self::visible_anchor): a lane that cannot observe its scroll
position reports the typed GuiError::UnsupportedCapability
refusal, and a widget whose rows are all above the viewport answers
false.
Sourcepub fn scroll_to_row(
&mut self,
widget_id: WidgetId,
index: usize,
) -> GuiResult<()>
pub fn scroll_to_row( &mut self, widget_id: WidgetId, index: usize, ) -> GuiResult<()>
Scrolls a row widget so index is the topmost visible row.
Forwarded to the backend’s Backend::scroll_to_row capability
(the same "scroll_anchor" family as Self::visible_anchor). A
lane that cannot move the viewport reports the typed
GuiError::UnsupportedCapability refusal.
Sourcepub fn selected_row_key(&self, widget_id: WidgetId) -> Option<RowKey>
pub fn selected_row_key(&self, widget_id: WidgetId) -> Option<RowKey>
Returns the keyed selection of a row widget, if any.
Populated when Self::set_selected_index/Self::set_selected_indices
run on a widget with keyed rows, and kept in step by
Self::set_rows_keyed and Self::clear_selection. For a
multi-selection this reports the lowest-index surviving member.
Sourcepub fn set_data_grid_rows(
&mut self,
widget_id: WidgetId,
rows: &[Vec<String>],
) -> GuiResult<()>
pub fn set_data_grid_rows( &mut self, widget_id: WidgetId, rows: &[Vec<String>], ) -> GuiResult<()>
Sets row-major cell values for a data grid widget.
Sourcepub fn set_data_grid_columns(
&mut self,
widget_id: WidgetId,
columns: &[ColumnSpec],
) -> GuiResult<()>
pub fn set_data_grid_columns( &mut self, widget_id: WidgetId, columns: &[ColumnSpec], ) -> GuiResult<()>
Declares a DataGrid’s columns separately from its data (dogfood
report #6), so the header is no longer data row 0 by convention.
The header row is rendered natively as row 0 (on every lane), data
rows set with Self::set_data_grid_data_rows follow it, and
Self::data_grid_data_row maps the raw row of a
SelectionChanged/GridCellClicked/Activated event back to a
0-based data index. Column widths are applied best-effort: lanes that
report UnsupportedCapability for set_data_grid_col_width keep
their default widths. Passing an empty slice removes the header.
Non-breaking: grids that never call this keep the raw
Self::set_data_grid_rows behaviour.
Sourcepub fn set_data_grid_data_rows(
&mut self,
widget_id: WidgetId,
rows: &[Vec<String>],
) -> GuiResult<()>
pub fn set_data_grid_data_rows( &mut self, widget_id: WidgetId, rows: &[Vec<String>], ) -> GuiResult<()>
Sets a DataGrid’s data rows (0-based), rendering the header from
Self::set_data_grid_columns above them when columns are declared.
Sourcepub fn data_grid_columns(&self, widget_id: WidgetId) -> &[ColumnSpec]
pub fn data_grid_columns(&self, widget_id: WidgetId) -> &[ColumnSpec]
The declared columns of a DataGrid (empty when none).
Sourcepub fn data_grid_data_row(
&self,
widget_id: WidgetId,
raw_row: usize,
) -> Option<usize>
pub fn data_grid_data_row( &self, widget_id: WidgetId, raw_row: usize, ) -> Option<usize>
Maps a raw grid row (as reported by SelectionChanged,
GridCellClicked, GridSelectionChanged or Activated) to a 0-based
data row: None for the header row. Without declared columns the raw
row is returned unchanged.
Sourcepub fn select_data_grid_row(
&mut self,
widget_id: WidgetId,
data_row: Option<usize>,
) -> GuiResult<()>
pub fn select_data_grid_row( &mut self, widget_id: WidgetId, data_row: Option<usize>, ) -> GuiResult<()>
Highlights one whole data row (0-based; header-aware) or clears the
highlight with None - the one-call form of building a
(row, col) list for Self::set_data_grid_selection.
Sourcepub fn set_data_grid_model(
&mut self,
widget_id: WidgetId,
model: Box<dyn DataGridModel>,
) -> GuiResult<()>
pub fn set_data_grid_model( &mut self, widget_id: WidgetId, model: Box<dyn DataGridModel>, ) -> GuiResult<()>
Sets a virtual data model for a data grid widget.
Sourcepub fn set_data_grid_row_height(
&mut self,
widget_id: WidgetId,
row: usize,
height: i32,
) -> GuiResult<()>
pub fn set_data_grid_row_height( &mut self, widget_id: WidgetId, row: usize, height: i32, ) -> GuiResult<()>
Sets the height of a specific row in a data grid widget.
Sourcepub fn set_data_grid_col_width(
&mut self,
widget_id: WidgetId,
col: usize,
width: i32,
) -> GuiResult<()>
pub fn set_data_grid_col_width( &mut self, widget_id: WidgetId, col: usize, width: i32, ) -> GuiResult<()>
Sets the width of a specific column in a data grid widget.
Sourcepub fn set_data_grid_frozen_panes(
&mut self,
widget_id: WidgetId,
rows: usize,
cols: usize,
) -> GuiResult<()>
pub fn set_data_grid_frozen_panes( &mut self, widget_id: WidgetId, rows: usize, cols: usize, ) -> GuiResult<()>
Sets the number of frozen rows and columns in a data grid widget.
pub fn set_data_grid_selection( &mut self, widget_id: WidgetId, selection: &[(usize, usize)], ) -> GuiResult<()>
Sourcepub fn set_tree_items(
&mut self,
widget_id: WidgetId,
items: &[TreeItem],
) -> GuiResult<()>
pub fn set_tree_items( &mut self, widget_id: WidgetId, items: &[TreeItem], ) -> GuiResult<()>
Sets hierarchical items for a tree view widget.
Sourcepub fn set_canvas_scene(
&mut self,
widget_id: WidgetId,
scene: &CanvasScene,
) -> GuiResult<()>
pub fn set_canvas_scene( &mut self, widget_id: WidgetId, scene: &CanvasScene, ) -> GuiResult<()>
Sets the current scene for a canvas widget.
Sourcepub fn set_canvas_surface(
&mut self,
widget_id: WidgetId,
surface: &CanvasSurface,
) -> GuiResult<()>
pub fn set_canvas_surface( &mut self, widget_id: WidgetId, surface: &CanvasSurface, ) -> GuiResult<()>
Sets the raster surface painted beneath a canvas widget’s scene.
The surface is clipped to the widget and composited over the canvas background, so transparent pixels display as the background while the stored buffer keeps its alpha. Replacing the surface repaints it immediately; full typed image resources remain the scope.
Sourcepub fn copy_to_clipboard(&mut self, widget_id: WidgetId) -> GuiResult<()>
pub fn copy_to_clipboard(&mut self, widget_id: WidgetId) -> GuiResult<()>
Copies a widget’s content into the shared clipboard.
Supported kinds: DataList/ListView (rows joined with newlines),
DataGrid (rows serialized), and text widgets (TextInput,
TextArea, Label). The text is mirrored in the Ui and forwarded
to the backend’s platform clipboard where supported (GTK today;
Win32 tracked).
Sourcepub fn paste_from_clipboard(&mut self, widget_id: WidgetId) -> GuiResult<()>
pub fn paste_from_clipboard(&mut self, widget_id: WidgetId) -> GuiResult<()>
Pastes the shared clipboard into a widget.
Supported kinds: DataList/ListView, DataGrid, and text widgets
(TextInput, TextArea, Label — a label’s text is replaced).
Prefers the backend’s platform clipboard (GTK reads the OS
clipboard); falls back to the in-memory Ui mirror.
Sourcepub fn paste_image_from_clipboard(
&mut self,
) -> GuiResult<Option<ClipboardImage>>
pub fn paste_image_from_clipboard( &mut self, ) -> GuiResult<Option<ClipboardImage>>
Pastes an image from the platform clipboard, returning raw RGBA pixels and encoded PNG bytes.
Sourcepub fn set_position(
&mut self,
widget_id: WidgetId,
x: i32,
y: i32,
) -> GuiResult<()>
pub fn set_position( &mut self, widget_id: WidgetId, x: i32, y: i32, ) -> GuiResult<()>
Sets preferred position for a widget.
Sourcepub fn set_background_color(
&mut self,
widget_id: WidgetId,
color: Color,
) -> GuiResult<()>
pub fn set_background_color( &mut self, widget_id: WidgetId, color: Color, ) -> GuiResult<()>
Sets background color for a widget.
Sourcepub fn set_alert_level(
&mut self,
widget_id: WidgetId,
level: AlertLevel,
) -> GuiResult<()>
pub fn set_alert_level( &mut self, widget_id: WidgetId, level: AlertLevel, ) -> GuiResult<()>
Sets alert severity for an alert dialog widget.
Sourcepub fn set_image_source(
&mut self,
widget_id: WidgetId,
source: &str,
) -> GuiResult<()>
pub fn set_image_source( &mut self, widget_id: WidgetId, source: &str, ) -> GuiResult<()>
Sets image source for an image widget.
Sourcepub fn image_resource_capabilities(&self) -> ImageResourceCapabilities
pub fn image_resource_capabilities(&self) -> ImageResourceCapabilities
Reports bounded in-memory RGBA image-resource support on this backend.
Sourcepub fn load_image_resource(
&mut self,
data: &ImageData,
) -> GuiResult<ImageResourceId>
pub fn load_image_resource( &mut self, data: &ImageData, ) -> GuiResult<ImageResourceId>
Loads validated RGBA8 pixels as a resource owned by this Ui.
Image dimensions must be positive, the buffer must contain exactly four bytes per pixel, each image is limited to 64 MiB, and all live images together are limited to 256 MiB. Encoded formats and filesystem paths are not accepted.
Sourcepub fn image_resource_is_live(&self, resource: ImageResourceId) -> bool
pub fn image_resource_is_live(&self, resource: ImageResourceId) -> bool
Returns whether resource is still live in this UI’s registry.
Sourcepub fn release_image_resource(
&mut self,
resource: ImageResourceId,
) -> GuiResult<()>
pub fn release_image_resource( &mut self, resource: ImageResourceId, ) -> GuiResult<()>
Releases a live image resource from its backend and this UI.
Unknown and already-released identifiers return a deterministic backend error. A refused backend release leaves the UI registry intact.
Sourcepub fn set_image_fit(
&mut self,
widget_id: WidgetId,
fit: ImageFit,
) -> GuiResult<()>
pub fn set_image_fit( &mut self, widget_id: WidgetId, fit: ImageFit, ) -> GuiResult<()>
Sets how an image scales into its bounds.
Validates the widget kind, records the mode on the shared spec, then forwards to the backend so unsupported lanes report a typed error.
Sourcepub fn set_file_chooser_mode(
&mut self,
widget_id: WidgetId,
mode: FileChooserMode,
) -> GuiResult<()>
pub fn set_file_chooser_mode( &mut self, widget_id: WidgetId, mode: FileChooserMode, ) -> GuiResult<()>
Sets what a FileChooserDialog lets the user pick.
Validates the widget kind, records the mode on the shared spec, then forwards to the backend so an unsupported picker reports a typed error instead of showing the wrong dialog.
Sourcepub fn set_icon(
&mut self,
widget_id: WidgetId,
icon: Option<IconRole>,
) -> GuiResult<()>
pub fn set_icon( &mut self, widget_id: WidgetId, icon: Option<IconRole>, ) -> GuiResult<()>
Sets the stock-art icon rendered beside a button’s label.
Validates the widget kind (Button and FileChooserDialog), records
the role on the shared spec, then forwards to the backend, which
resolves it through the portable art provider for the active theme;
None clears the icon. Lanes that cannot render button art report
the typed unsupported error instead of silently dropping the call.
Sourcepub fn set_color_dialog_data(
&mut self,
widget_id: WidgetId,
data: ColorDialogData,
) -> GuiResult<()>
pub fn set_color_dialog_data( &mut self, widget_id: WidgetId, data: ColorDialogData, ) -> GuiResult<()>
Sets the preferences of a colour-dialog widget.
Validates the widget kind, applies the shared data rules (the
crate::MAX_CUSTOM_COLORS palette cap), records the data on the
shared spec, and forwards to the backend. Native lanes without a
mapping for the chooser report the typed unsupported error from the
backend default, so a caller never believes the preferences applied.
Sourcepub fn set_font_dialog_data(
&mut self,
widget_id: WidgetId,
data: FontDialogData,
) -> GuiResult<()>
pub fn set_font_dialog_data( &mut self, widget_id: WidgetId, data: FontDialogData, ) -> GuiResult<()>
Sets the preferences of a font-dialog widget.
Validates the widget kind and the shared data rules (finite, non-inverted size range), records the data on the shared spec, and forwards to the backend. Native lanes without a mapping for the chooser report the typed unsupported error from the backend default.
Sourcepub fn set_toolbar_items(
&mut self,
widget_id: WidgetId,
items: Vec<ToolbarItem>,
) -> GuiResult<()>
pub fn set_toolbar_items( &mut self, widget_id: WidgetId, items: Vec<ToolbarItem>, ) -> GuiResult<()>
Replaces the rows of a toolbar widget.
Validates the widget kind and the shared model rules (unique tool ids, radio groups anchored on a checkable owner) before anything is recorded, so a rejected list leaves the previous rows untouched. The accepted list is stored on the shared spec and forwarded to the backend; lanes without a native toolbar report the typed unsupported error (composes them).
Sourcepub fn set_toolbar_orientation(
&mut self,
widget_id: WidgetId,
orientation: ToolbarOrientation,
) -> GuiResult<()>
pub fn set_toolbar_orientation( &mut self, widget_id: WidgetId, orientation: ToolbarOrientation, ) -> GuiResult<()>
Sets the stacking orientation of a toolbar widget.
Sourcepub fn set_tool_state(
&mut self,
widget_id: WidgetId,
tool_id: ToolId,
checked: bool,
) -> GuiResult<Vec<(ToolId, bool)>>
pub fn set_tool_state( &mut self, widget_id: WidgetId, tool_id: ToolId, checked: bool, ) -> GuiResult<Vec<(ToolId, bool)>>
Applies a programmatic checked-state change to a toolbar tool.
Radio exclusivity is enforced by the shared rules: checking a member
unchecks the other members of its group. This is the programmatic
path, so it never emits ToolToggled/ToolActivated events — the
tools whose state actually changed are returned in toolbar order
(empty for a no-op), which is what an application mirrors into its own
model. Non-checkable tools report the typed model error.
Sourcepub fn update_tool(
&mut self,
widget_id: WidgetId,
tool_id: ToolId,
update: ToolUpdate,
) -> GuiResult<()>
pub fn update_tool( &mut self, widget_id: WidgetId, tool_id: ToolId, update: ToolUpdate, ) -> GuiResult<()>
Patches one toolbar tool in place: label, tooltip, icon, display mode, enabled/visible state, and the dropdown flag.
checked is deliberately not part of ToolUpdate; use
Ui::set_tool_state so radio exclusivity and the silent-programmatic
rule apply. The patched list is forwarded to the backend like
Ui::set_toolbar_items.
Sourcepub fn set_calendar_selected_dates(
&mut self,
widget_id: WidgetId,
dates: &[CalendarDate],
) -> GuiResult<()>
pub fn set_calendar_selected_dates( &mut self, widget_id: WidgetId, dates: &[CalendarDate], ) -> GuiResult<()>
Sets the selected dates of a calendar widget.
Sourcepub fn set_calendar_bounds(
&mut self,
widget_id: WidgetId,
min_date: Option<CalendarDate>,
max_date: Option<CalendarDate>,
) -> GuiResult<()>
pub fn set_calendar_bounds( &mut self, widget_id: WidgetId, min_date: Option<CalendarDate>, max_date: Option<CalendarDate>, ) -> GuiResult<()>
Sets selectable date bounds for a calendar widget.
Sourcepub fn set_calendar_first_day_of_week(
&mut self,
widget_id: WidgetId,
first_day: CalendarFirstDayOfWeek,
) -> GuiResult<()>
pub fn set_calendar_first_day_of_week( &mut self, widget_id: WidgetId, first_day: CalendarFirstDayOfWeek, ) -> GuiResult<()>
Sets the first day of the week convention for a calendar widget.
Sourcepub fn set_calendar_selection_mode(
&mut self,
widget_id: WidgetId,
mode: CalendarSelectionMode,
) -> GuiResult<()>
pub fn set_calendar_selection_mode( &mut self, widget_id: WidgetId, mode: CalendarSelectionMode, ) -> GuiResult<()>
Sets the selection mode for a calendar widget.
Sourcepub fn set_date_value(
&mut self,
widget_id: WidgetId,
iso_date: &str,
) -> GuiResult<()>
pub fn set_date_value( &mut self, widget_id: WidgetId, iso_date: &str, ) -> GuiResult<()>
Sets date value (YYYY-MM-DD) for a date picker widget.
Sourcepub fn set_link_url(&mut self, widget_id: WidgetId, url: &str) -> GuiResult<()>
pub fn set_link_url(&mut self, widget_id: WidgetId, url: &str) -> GuiResult<()>
Sets URL for a link label widget.
Sourcepub fn set_container_direction(
&mut self,
widget_id: WidgetId,
direction: ContainerDirection,
) -> GuiResult<()>
pub fn set_container_direction( &mut self, widget_id: WidgetId, direction: ContainerDirection, ) -> GuiResult<()>
Sets stacking direction for a container widget.
Sourcepub fn set_container_wrap(
&mut self,
widget_id: WidgetId,
wrap: ContainerWrap,
) -> GuiResult<()>
pub fn set_container_wrap( &mut self, widget_id: WidgetId, wrap: ContainerWrap, ) -> GuiResult<()>
Sets wrap behavior for a container widget (Container, GroupBox, SplitPane).
Sourcepub fn create_flow_container(
&mut self,
parent: Option<WidgetId>,
gap: i32,
) -> GuiResult<WidgetId>
pub fn create_flow_container( &mut self, parent: Option<WidgetId>, gap: i32, ) -> GuiResult<WidgetId>
Creates a flow container with horizontal direction, wrapping enabled,
and the specified uniform gap between children (Container).
Sourcepub fn set_container_gap(
&mut self,
widget_id: WidgetId,
gap: i32,
) -> GuiResult<()>
pub fn set_container_gap( &mut self, widget_id: WidgetId, gap: i32, ) -> GuiResult<()>
Sets the uniform spacing between a flow container’s children, in
logical pixels (Container, GroupBox). Negative values clamp to 0.
The shared model keeps the layout tree in sync (both axes) so
compute_layout and the native auto-layout agree, mirroring
Ui::set_container_direction. Lanes that position children through
the computed layout honour this directly; lanes with native boxes map
it to their own spacing (GTK box spacing).
Sourcepub fn set_container_padding(
&mut self,
widget_id: WidgetId,
padding: i32,
) -> GuiResult<()>
pub fn set_container_padding( &mut self, widget_id: WidgetId, padding: i32, ) -> GuiResult<()>
Sets the uniform inset between a flow container’s edges and its flow
children, in logical pixels (Container, GroupBox). Negative values
clamp to 0.
Sourcepub fn set_container_scroll(
&mut self,
widget_id: WidgetId,
vertical: bool,
horizontal: bool,
) -> GuiResult<()>
pub fn set_container_scroll( &mut self, widget_id: WidgetId, vertical: bool, horizontal: bool, ) -> GuiResult<()>
Sets scroll configuration for a container widget.
Sourcepub fn draw_demo_cube(&mut self, widget_id: WidgetId) -> GuiResult<()>
pub fn draw_demo_cube(&mut self, widget_id: WidgetId) -> GuiResult<()>
Draws the built-in colored cube demo into a WidgetKind::VulkanCanvas.
Sourcepub fn compute_layout(
&mut self,
root_id: WidgetId,
width: f32,
height: f32,
) -> GuiResult<()>
pub fn compute_layout( &mut self, root_id: WidgetId, width: f32, height: f32, ) -> GuiResult<()>
Computes and applies layout for root_id.
The pass is bounded by the strict topological dirty flags maintained
by invalidate_layout: only the scheduled branches are re-seeded,
clean branches keep their layout caches and are never re-measured, and
native geometry is written only for widgets whose computed values
changed. An unchanged pass performs no measurements and no writes
while still applying any layout the tree reports as changed.
Sourcepub fn attach(&mut self, parent: WidgetId, child: WidgetId) -> GuiResult<()>
pub fn attach(&mut self, parent: WidgetId, child: WidgetId) -> GuiResult<()>
Attaches child beneath parent in the UI tree.
§Contract (Pre / Post / Inv)
- Pre: both ids are live and attaching does not close a parent cycle (self-parentage counts as a one-node cycle).
- Post:
child’s parent pointer isparentand the backend mirror was asked to attach the same pair. On any error the shared model is untouched, so a refused call never leaves a partial edge. - Inv: parent links stay acyclic.
Ui::removecascades andfocus_chain_enabledwalks rely on this to terminate. Depth is bounded by the layout engine (MAX_LAYOUT_DEPTH = 128). Attaching a leaf child short-circuits cycle validation in O(1); attaching an internal subtree walks ancestors in O(depth).
Sourcepub fn reparent(
&mut self,
child: WidgetId,
new_parent: WidgetId,
) -> GuiResult<()>
pub fn reparent( &mut self, child: WidgetId, new_parent: WidgetId, ) -> GuiResult<()>
Reparents an existing child to a new parent.
Refuses self-reparenting and any move that would close a parent cycle; a refused call leaves the previous parent edge in place.
Sourcepub fn widget_depth(&self, widget_id: WidgetId) -> usize
pub fn widget_depth(&self, widget_id: WidgetId) -> usize
Returns the tree depth of widget_id (0 for root with no parent, 1 for child of root, etc.).
Sourcepub fn widget_subtree_height(&self, widget_id: WidgetId) -> usize
pub fn widget_subtree_height(&self, widget_id: WidgetId) -> usize
Returns the height of the subtree rooted at widget_id (1 for a leaf, 1 + max(child heights)).
Sourcepub fn show(&mut self, widget_id: WidgetId) -> GuiResult<()>
pub fn show(&mut self, widget_id: WidgetId) -> GuiResult<()>
Shows a widget, typically a top-level window.
Sourcepub fn hide(&mut self, widget_id: WidgetId) -> GuiResult<()>
pub fn hide(&mut self, widget_id: WidgetId) -> GuiResult<()>
Hides a widget without removing it from the tree.
Sourcepub fn set_visible(
&mut self,
widget_id: WidgetId,
visible: bool,
) -> GuiResult<()>
pub fn set_visible( &mut self, widget_id: WidgetId, visible: bool, ) -> GuiResult<()>
Sets whether a widget is visible or hidden.
Hidden widgets are given display: Display::None in the layout tree so
they do not occupy layout space during compute_layout.
Sourcepub fn is_visible(&self, widget_id: WidgetId) -> bool
pub fn is_visible(&self, widget_id: WidgetId) -> bool
Whether the widget is currently visible (not hidden via Self::hide).
Whether the widget is effectively hidden, either directly via Self::hide
or by having an ancestor that is hidden.
Sourcepub fn capture_window_rgba(
&self,
window_id: WidgetId,
include_decorations: bool,
) -> GuiResult<(u32, u32, Vec<u8>)>
pub fn capture_window_rgba( &self, window_id: WidgetId, include_decorations: bool, ) -> GuiResult<(u32, u32, Vec<u8>)>
Captures a screenshot of the specified window as top-down RGBA pixels.
Validates that window_id exists and is a WidgetKind::Window, then forwards
to the backend implementation.
Sourcepub fn capture_widget_rgba(
&self,
widget_id: WidgetId,
) -> GuiResult<(u32, u32, Vec<u8>)>
pub fn capture_widget_rgba( &self, widget_id: WidgetId, ) -> GuiResult<(u32, u32, Vec<u8>)>
Captures a screenshot of the specified widget as top-down RGBA pixels.
Validates that widget_id exists, then forwards to the backend implementation.
Sourcepub fn native_read_text(&self, widget_id: WidgetId) -> GuiResult<Option<String>>
pub fn native_read_text(&self, widget_id: WidgetId) -> GuiResult<Option<String>>
Reads live text for a widget (E2E readback).
Validates widget_id, attempts live backend readback, and gracefully falls
back to the cached spec.text if the backend returns Ok(None).
Sourcepub fn native_read_checked(
&self,
widget_id: WidgetId,
) -> GuiResult<Option<bool>>
pub fn native_read_checked( &self, widget_id: WidgetId, ) -> GuiResult<Option<bool>>
Reads live checked state for a checkbox/radio widget (E2E readback).
Validates widget_id, attempts live backend readback, and gracefully falls
back to the cached spec.checked if the backend returns Ok(None).
Sourcepub fn native_click(&self, widget_id: WidgetId) -> GuiResult<bool>
pub fn native_click(&self, widget_id: WidgetId) -> GuiResult<bool>
Simulates a native click on an actionable widget (E2E action).
Validates widget_id and forwards to the backend implementation.
Sourcepub fn native_type_text(
&mut self,
widget_id: WidgetId,
text: &str,
) -> GuiResult<bool>
pub fn native_type_text( &mut self, widget_id: WidgetId, text: &str, ) -> GuiResult<bool>
Simulates native text input on an editable widget (E2E action).
Validates widget_id and forwards to the backend implementation.
Sourcepub fn remove(&mut self, widget_id: WidgetId) -> GuiResult<()>
pub fn remove(&mut self, widget_id: WidgetId) -> GuiResult<()>
Removes a widget (and, recursively, its descendants) from the UI tree.
The child walk follows the adjacency index (children_index), so
tearing down a subtree of size N visits each parent-child edge
exactly once: O(N) in the subtree size, independent of the total
widget count. Descendants are still removed first
so no child outlives its parent, and index edges are only released
after a removal has actually succeeded, so a backend refusal leaves
the surviving edges intact for a retry.
Sourcepub fn set_enabled(
&mut self,
widget_id: WidgetId,
enabled: bool,
) -> GuiResult<()>
pub fn set_enabled( &mut self, widget_id: WidgetId, enabled: bool, ) -> GuiResult<()>
Enables or disables a widget.
Sourcepub fn activate(&mut self, widget_id: WidgetId) -> GuiResult<()>
pub fn activate(&mut self, widget_id: WidgetId) -> GuiResult<()>
Programmatically activates a clickable widget (button, file chooser, link label) exactly as if the user clicked it.
Sourcepub fn app_data_dir(&self) -> GuiResult<PathBuf>
pub fn app_data_dir(&self) -> GuiResult<PathBuf>
Returns the platform-specific application data directory
(XDG data home on Linux, %APPDATA% on Windows, the temp directory on
the Mock backend). Apps should persist their state under a
subdirectory of this path instead of the current working directory.
Sourcepub fn set_tooltip(&mut self, widget_id: WidgetId, text: &str) -> GuiResult<()>
pub fn set_tooltip(&mut self, widget_id: WidgetId, text: &str) -> GuiResult<()>
Sets tooltip text for a widget.
Sourcepub fn set_accessible_name(
&mut self,
widget_id: WidgetId,
name: &str,
) -> GuiResult<()>
pub fn set_accessible_name( &mut self, widget_id: WidgetId, name: &str, ) -> GuiResult<()>
Sets the accessible name announced by assistive technology.
Updates the shared spec and forwards to the backend; a backend whose
native accessibility bridge has not landed returns
GuiError::UnsupportedCapability instead of silently ignoring the
request.
Sourcepub fn set_accessible_description(
&mut self,
widget_id: WidgetId,
description: &str,
) -> GuiResult<()>
pub fn set_accessible_description( &mut self, widget_id: WidgetId, description: &str, ) -> GuiResult<()>
Sets the accessible description announced after the name.
Sourcepub fn accessibility(&self, widget_id: WidgetId) -> Option<&AccessibilitySpec>
pub fn accessibility(&self, widget_id: WidgetId) -> Option<&AccessibilitySpec>
Returns the accessibility metadata of a widget, when it exists.
Sourcepub fn set_focusable(
&mut self,
widget_id: WidgetId,
focusable: bool,
) -> GuiResult<()>
pub fn set_focusable( &mut self, widget_id: WidgetId, focusable: bool, ) -> GuiResult<()>
Marks a widget as focusable (or not) for tab traversal.
Sourcepub fn is_focusable(&self, widget_id: WidgetId) -> Option<bool>
pub fn is_focusable(&self, widget_id: WidgetId) -> Option<bool>
Returns whether a widget is focusable, respecting per-kind defaults.
Sourcepub fn focus(&mut self, widget_id: WidgetId) -> GuiResult<()>
pub fn focus(&mut self, widget_id: WidgetId) -> GuiResult<()>
Moves keyboard focus to a widget.
Any existing widget can receive programmatic focus; traversal
(Self::focus_next, Self::focus_previous) visits focusable,
enabled widgets only. The previous focus is reported as
UiEvent::FocusChanged { focused: false } by backends that can report
focus (Mock and Win32 report every programmatic change; GTK and Cocoa
emit the focus-in/out transitions they observe).
Sourcepub fn focused(&self) -> Option<WidgetId>
pub fn focused(&self) -> Option<WidgetId>
Returns the widget that currently holds keyboard focus, when known.
Sourcepub fn focus_order(&self) -> Vec<WidgetId>
pub fn focus_order(&self) -> Vec<WidgetId>
Focus candidates in tab order: focusable widgets whose own and
ancestors’ enabled flags allow input, in creation order (which is
also WidgetId order).
Sourcepub fn spatial_focus_order(&self) -> Vec<WidgetId>
pub fn spatial_focus_order(&self) -> Vec<WidgetId>
Returns focus candidates in 2D spatial reading order (top-to-bottom, left-to-right).
Unlike Self::focus_order, which returns candidates in monotonic WidgetId
creation order, spatial_focus_order queries layout coordinates and partitions
widgets into visual row bands (using vertical tolerance threshold), sorting
primary by row band and secondary by horizontal offset x.
This ensures accessible Tab navigation strictly conforms to WCAG 2.1 reading order
in auto-wrapping flex containers (ContainerWrap::Wrap) and multi-row forms.
Sourcepub fn focus_next(&mut self) -> GuiResult<Option<WidgetId>>
pub fn focus_next(&mut self) -> GuiResult<Option<WidgetId>>
Moves focus to the next focus candidate, wrapping at the end.
Returns the newly focused widget, or None when nothing is
focusable.
Sourcepub fn focus_previous(&mut self) -> GuiResult<Option<WidgetId>>
pub fn focus_previous(&mut self) -> GuiResult<Option<WidgetId>>
Moves focus to the previous focus candidate, wrapping at the start.
Sourcepub fn set_theme(&mut self, theme: Theme) -> GuiResult<()>
pub fn set_theme(&mut self, theme: Theme) -> GuiResult<()>
Replaces the active theme.
Switches to the given theme.
The resolved theme is stored on the Ui record only after the backend
accepts it; on failure the previous theme is preserved.
Sourcepub fn set_theme_mode(&mut self, mode: ThemeMode) -> GuiResult<()>
pub fn set_theme_mode(&mut self, mode: ThemeMode) -> GuiResult<()>
Switches to the built-in light or dark theme.
Sourcepub fn theme_mode(&self) -> ThemeMode
pub fn theme_mode(&self) -> ThemeMode
Returns the active theme mode.
Sourcepub fn theme_capabilities(&self) -> ThemeCapabilities
pub fn theme_capabilities(&self) -> ThemeCapabilities
Returns the backend’s system theme detection capabilities.
Sourcepub fn gpu_surface_capabilities(&self) -> GpuSurfaceCapabilities
pub fn gpu_surface_capabilities(&self) -> GpuSurfaceCapabilities
Reports the active backend’s GPU host-surface capabilities.
Sourcepub fn supports_capability(&self, capability: &str) -> bool
pub fn supports_capability(&self, capability: &str) -> bool
Tests a standard GPU-surface capability identifier. Unknown identifiers
return false.
Sourcepub fn set_gpu_degradation_policy(&mut self, policy: GpuDegradationPolicy)
pub fn set_gpu_degradation_policy(&mut self, policy: GpuDegradationPolicy)
Selects the policy for future Vulkan canvas creations whose backend does not advertise a Vulkan surface.
Sourcepub fn is_gpu_degraded(&self, widget_id: WidgetId) -> bool
pub fn is_gpu_degraded(&self, widget_id: WidgetId) -> bool
Returns whether widget_id was created through a GPU degradation
path. Unknown ids and native Vulkan canvases return false.
Sourcepub fn display_capabilities(&self) -> DisplayCapabilities
pub fn display_capabilities(&self) -> DisplayCapabilities
Returns the backend’s display-metric capabilities.
Sourcepub fn displays(&self) -> GuiResult<Vec<DisplayInfo>>
pub fn displays(&self) -> GuiResult<Vec<DisplayInfo>>
Enumerates the connected displays.
On lanes that cannot enumerate this returns the typed
GuiError::UnsupportedCapability; check Ui::display_capabilities
first when the app has a fallback path. DPI/monitor transitions arrive
as UiEvent::DisplayChanged.
Sourcepub fn primary_display(&self) -> GuiResult<Option<DisplayInfo>>
pub fn primary_display(&self) -> GuiResult<Option<DisplayInfo>>
Returns the primary display, or None when enumeration
succeeds but reports no primary.
Sourcepub fn logical_pointer_projection(
&self,
widget_id: WidgetId,
x: f32,
y: f32,
) -> (f32, f32)
pub fn logical_pointer_projection( &self, widget_id: WidgetId, x: f32, y: f32, ) -> (f32, f32)
Projects a pointer coordinate from the display’s native pixel space
into logical (96-DPI) coordinates for widget_id.
Ui already applies this to every UiEvent::PointerDown,
UiEvent::PointerMove, and UiEvent::PointerUp it dispatches, so
app code never needs to call it for event coordinates: they arrive in
the logical space this returns. It stays public for the other sources
of a raw position — a drag payload, a native handle, a scripted
physical coordinate — where the scaling still has to be inverted
explicitly to line the value up with layout targets.
It resolves the widget’s display scale through
Backend::widget_scale_factor and inverts the OS scaling matrix via
crate::logical_pointer_projection. On lanes that report a scale of
1.0 (GTK4, Cocoa, Mock without a scaled display fixture) the
projection is the identity; on a 125 % Win32 display a physical
(125, 250) maps to logical (100, 200).
Sourcepub fn system_theme_mode(&self) -> Option<ThemeMode>
pub fn system_theme_mode(&self) -> Option<ThemeMode>
Returns the OS light/dark preference when the backend can detect it.
Sourcepub fn system_high_contrast(&self) -> bool
pub fn system_high_contrast(&self) -> bool
Returns whether the OS high-contrast accessibility mode is active.
Sourcepub fn stock_icon(&self, role: IconRole, size: IconSize) -> StockIcon
pub fn stock_icon(&self, role: IconRole, size: IconSize) -> StockIcon
Resolves a portable stock icon at the 96 dpi baseline.
The icon’s palette follows the active theme (light/dark), so callers
re-resolve after Ui::set_theme_mode; see
Ui::stock_icon_at_scale for DPI variants.
Sourcepub fn stock_icon_at_scale(
&self,
role: IconRole,
size: IconSize,
scale: u32,
) -> StockIcon
pub fn stock_icon_at_scale( &self, role: IconRole, size: IconSize, scale: u32, ) -> StockIcon
Resolves a portable stock icon at an explicit DPI scale factor.
scale models the display density (1 = 96 dpi, 2 = 200 %, …) and is
clamped to 1..=4; the raster edge is size.pixels() * scale.
Every call re-rasterizes the glyph (there is no cache), so resolve an icon once and reuse the returned value when drawing it repeatedly.
Sourcepub fn native_stock_icon(
&self,
role: IconRole,
size: IconSize,
) -> GuiResult<StockIcon>
pub fn native_stock_icon( &self, role: IconRole, size: IconSize, ) -> GuiResult<StockIcon>
Resolves an OS-native stock icon when the lane provides one.
Lanes without a native mapping return the typed
GuiError::UnsupportedCapability; portable art is always available
through Ui::stock_icon.
Sourcepub fn art_capabilities(&self) -> ArtCapabilities
pub fn art_capabilities(&self) -> ArtCapabilities
Returns the lane’s native stock-art capabilities.
Sourcepub fn set_theme_override(
&mut self,
widget_id: WidgetId,
theme_override: ThemeOverride,
) -> GuiResult<()>
pub fn set_theme_override( &mut self, widget_id: WidgetId, theme_override: ThemeOverride, ) -> GuiResult<()>
Adds a theme override for one widget.
The override is stored on the Ui record only after the backend accepts
it, so a refusing backend never leaves a phantom override.
Sourcepub fn theme_overrides(&self, widget_id: WidgetId) -> &[ThemeOverride]
pub fn theme_overrides(&self, widget_id: WidgetId) -> &[ThemeOverride]
Returns the theme overrides registered for a widget.
Sourcepub fn clear_theme_overrides(&mut self, widget_id: WidgetId) -> GuiResult<()>
pub fn clear_theme_overrides(&mut self, widget_id: WidgetId) -> GuiResult<()>
Clears all theme overrides for a widget.
Sourcepub fn task_proxy(&mut self) -> UiProxy
pub fn task_proxy(&mut self) -> UiProxy
Returns a cloneable handle for posting commands from worker threads.
The first call creates one bounded command channel for this Ui
(capacity DEFAULT_TASK_QUEUE_CAPACITY) wired to the backend’s wake
hook; later calls return clones of the same handle. See the
crate::async_ui module docs for the worker/UI-thread contract.
Sourcepub fn shutdown(self) -> usize
pub fn shutdown(self) -> usize
Tears the Ui down explicitly and returns how many queued
background-task commands were discarded unapplied.
Dropping a Ui (or Ui::into_backend) has the same effect — Ui
deliberately has no Drop impl so into_backend can move the backend
out; the channel receiver drops with it (see the drop contract in
crate::async_ui): the command channel closes, every
UiProxy clone then reports crate::TaskSendError::Closed, and
commands still queued are discarded without being applied. Call
shutdown after the final Ui::drain_task_commands when you need
to know whether any worker commit was lost.
Sourcepub fn drain_task_commands(&mut self) -> TaskDrainReport
pub fn drain_task_commands(&mut self) -> TaskDrainReport
Applies queued background-task commands in FIFO order.
Widget commands go through the same set_* paths as direct calls, so
shared specs and native widgets stay in sync; a command for a removed
widget is rejected instead of panicking and emits a
TaskEvent::Aborted dead-letter notification, so a teardown race
can never swallow a worker’s commit silently. Lifecycle
commands queue UiEvent::Task notifications for the next wait_event
/ poll_event call. The event functions call this automatically; call
it directly before screenshots or assertions.
Sourcepub fn drain_task_callbacks(&mut self)
pub fn drain_task_callbacks(&mut self)
Drains and invokes any pending typed task completion callbacks.
Sourcepub fn try_spawn_task_with_callback<T, W, C>(
&mut self,
worker: W,
callback: C,
) -> GuiResult<TaskHandle>
pub fn try_spawn_task_with_callback<T, W, C>( &mut self, worker: W, callback: C, ) -> GuiResult<TaskHandle>
Spawns a background worker thread and delivers its typed return value to
callback on the UI thread when complete.
This pattern mimics Tauri’s invoke(), eliminating manual TaskId
maps and custom task events. If the task is cancelled via crate::async_ui::TaskHandle::cancel,
the completion callback is skipped.
Attempts to spawn a background worker thread and deliver its typed return value
to callback on the UI thread when complete.
If thread creation fails (e.g. OS thread resource exhaustion), returns
GuiError::ResourceExhausted and cleans up task bookkeeping.
If worker panics, the panic is caught and isolated: callback is safely dropped
without executing, the TaskHandle is marked finished, and UiEvent::Task(TaskEvent::Failed)
is dispatched on the UI thread, preventing permanent callback or memory leaks.
Sourcepub fn spawn_task_with_callback<T, W, C>(
&mut self,
worker: W,
callback: C,
) -> TaskHandle
pub fn spawn_task_with_callback<T, W, C>( &mut self, worker: W, callback: C, ) -> TaskHandle
Spawns a background worker thread and delivers its typed return value to
callback on the UI thread when complete.
This pattern mimics Tauri’s invoke(), eliminating manual TaskId
maps and custom task events. If the task is cancelled via crate::async_ui::TaskHandle::cancel,
the completion callback is skipped.
If the worker panics, the panic is caught and isolated: the callback is dropped without
executing, the handle is marked finished, and a TaskEvent::Failed is dispatched.
Sourcepub fn wait_event(&mut self) -> GuiResult<UiEvent>
pub fn wait_event(&mut self) -> GuiResult<UiEvent>
Blocks until the next UI event arrives, without busy-looping.
Queued background-task commands are applied first (FIFO); their
lifecycle notifications are returned before backend events whenever
both are ready. The internal TasksPending wake marker is consumed
here and never surfaces to application code.
Sourcepub fn poll_event(&mut self) -> GuiResult<Option<UiEvent>>
pub fn poll_event(&mut self) -> GuiResult<Option<UiEvent>>
Polls one event, applying queued background-task commands first.
Returns None when neither task notifications nor backend events are
pending. The internal TasksPending wake marker is consumed here.
Sourcepub fn dispatch_events<F>(&mut self, handler: F) -> GuiResult<usize>
pub fn dispatch_events<F>(&mut self, handler: F) -> GuiResult<usize>
Drains queued events, running registered callbacks and invoking handler.
Returns the number of dispatched events.
Sourcepub fn dispatch_events_with<F>(&mut self, handler: F) -> GuiResult<usize>
pub fn dispatch_events_with<F>(&mut self, handler: F) -> GuiResult<usize>
Drains queued events, running registered callbacks and invoking
handler with &mut Ui so it can mutate widgets inline.
Returns the number of dispatched events. Each event gets the same
pre-handler treatment as Self::dispatch_events — layout-root
recompute, focus bookkeeping, then the callbacks registered through
Ui::on_* — and only then handler runs. Returning
LoopFlow::Exit stops the drain early; events produced by the
handler are queued, never dropped, and are delivered in the same
drain (see Self::run_until_closed_with for the ordering and
reentrancy rules).
Sourcepub fn run_until_closed<F>(&mut self, handler: F) -> GuiResult<()>
pub fn run_until_closed<F>(&mut self, handler: F) -> GuiResult<()>
Runs the application event loop until a WindowClosed event arrives.
Blocks efficiently (no 16 ms sleep loop): wait_event parks the
backend until an event is ready. Each event gets the same treatment
as in Self::dispatch_events — layout-root recompute, registered
callbacks, then handler.
Sourcepub fn run_until_closed_with<F>(&mut self, handler: F) -> GuiResult<()>
pub fn run_until_closed_with<F>(&mut self, handler: F) -> GuiResult<()>
Runs the application event loop until a WindowClosed event arrives,
handing handler both the UI and the event so it can mutate widgets
inline.
Blocks efficiently (no poll loop): wait_event parks the backend
until an event is ready. Each event gets the same pre-handler
treatment as Self::dispatch_events — layout-root recompute, focus
bookkeeping, then the callbacks registered through Ui::on_* — and
only then handler runs with &mut Ui. Returning
LoopFlow::Exit stops the loop early; WindowClosed always stops
it after the handler has seen the event.
§Reentrancy and ordering
- A handler may call any
UiAPI; re-entering this runner orSelf::dispatch_events_withis prevented at compile time by the&mut Uiborrow. - Registered callbacks run before the handler for the same event,
exactly like
Self::dispatch_events. - Events produced by a handler (for example
Ui::activateon the Mock backend) are queued, never dropped, and are delivered on subsequent iterations; a handler that unconditionally produces events keeps the loop busy, so guards belong in app code.
Sourcepub fn run_bounded<F>(
&mut self,
budget: Option<Duration>,
handler: F,
) -> GuiResult<RunStop>
pub fn run_bounded<F>( &mut self, budget: Option<Duration>, handler: F, ) -> GuiResult<RunStop>
Runs the application event loop until it closes, with an optional autoclose budget.
budget == None is exactly Self::run_until_closed: the loop parks
in wait_event with no polling and returns once a
UiEvent::WindowClosed arrives. With Some(budget) the loop polls
(Self::poll_event plus a crate::autoclose::BOUNDED_POLL_INTERVAL
sleep) and returns as soon as one of three things happens: the window
closed, the handler answered LoopFlow::Exit, or the budget elapsed
— see RunStop for which.
This is the library half of the NATIVE_GUI_<APP>_AUTOCLOSE_MS contract the
example-level hook established: an unattended capture run must
end by itself, because the runner’s TERM can only ever be reported as
a hang. The budget itself is resolved by
crate::autoclose::from_env, which the native-gui facade’s app::run
calls for you.
§Ordering
The same pre-handler treatment as Self::dispatch_events applies
(layout-root recompute, focus bookkeeping, then the callbacks
registered through Ui::on_*), and events produced by the handler are
queued rather than dropped — except that a stop leaves anything still
queued undelivered, exactly like Self::run_until_closed.
Sourcepub fn run_bounded_with<F>(
&mut self,
budget: Option<Duration>,
handler: F,
) -> GuiResult<RunStop>
pub fn run_bounded_with<F>( &mut self, budget: Option<Duration>, handler: F, ) -> GuiResult<RunStop>
Self::run_until_closed_with, bounded by an optional autoclose
budget.
Drop-in for the &mut Ui runner: without a budget it forwards to
Self::run_until_closed_with unchanged, so the blocking,
callback-first semantics stay the library’s. With a budget it drives
the public Self::dispatch_events_with pump and stops on the first
of a UiEvent::WindowClosed, a LoopFlow::Exit from the handler,
or the elapsed budget, reporting which through RunStop.
Sourcepub fn run_routed<M, F>(
&mut self,
routes: &Routes<M>,
handler: F,
) -> GuiResult<()>
pub fn run_routed<M, F>( &mut self, routes: &Routes<M>, handler: F, ) -> GuiResult<()>
Runs the application event loop with typed message routing.
Each event is translated through routes (ignore-by-default); when a
route matches, handler receives the typed message with &mut Ui.
Registered Ui::on_* callbacks still run first, exactly like
Self::run_until_closed_with. The loop ends after the handler sees
a WindowClosed event, or early when the handler returns
LoopFlow::Exit.
Sourcepub fn dispatch_routed<M, F>(
&mut self,
routes: &Routes<M>,
handler: F,
) -> GuiResult<usize>
pub fn dispatch_routed<M, F>( &mut self, routes: &Routes<M>, handler: F, ) -> GuiResult<usize>
Drains queued events with typed message routing.
Like Self::dispatch_events_with, but each event is translated
through routes first. Returns the number of dispatched events
(routed or ignored).
Sourcepub fn pre_dispatch(&mut self, event: &UiEvent)
pub fn pre_dispatch(&mut self, event: &UiEvent)
Work shared by every dispatch path: layout recompute for layout roots, focus bookkeeping, and registered callbacks.
Sourcepub fn observe_event(&mut self, event: &UiEvent)
pub fn observe_event(&mut self, event: &UiEvent)
Observes an event for the UI’s internal bookkeeping.
Sourcepub fn text(&self, widget_id: WidgetId) -> GuiResult<&str>
pub fn text(&self, widget_id: WidgetId) -> GuiResult<&str>
The live text of a widget: the user’s latest edit for text controls
(mirrored from TextChanged/TextSubmitted during dispatch), else
the last value written with Self::set_text or at creation.
Returns "" for a widget that never had text.
Sourcepub fn is_checked(&self, widget_id: WidgetId) -> GuiResult<bool>
pub fn is_checked(&self, widget_id: WidgetId) -> GuiResult<bool>
The live checked state of a check-capable widget (Checkbox,
RadioButton, …), kept in sync with user Toggled events.
Returns false when the state was never set or reported.
Sourcepub fn selected_index(&self, widget_id: WidgetId) -> GuiResult<Option<usize>>
pub fn selected_index(&self, widget_id: WidgetId) -> GuiResult<Option<usize>>
The live selected index of a selection widget (ComboBox,
ListView, DataList, Tabs, …), kept in sync with user
SelectionChanged events. None means nothing is selected.
Sourcepub fn selected_indices(&self, widget_id: WidgetId) -> GuiResult<&[usize]>
pub fn selected_indices(&self, widget_id: WidgetId) -> GuiResult<&[usize]>
The live selected indices of a multi-selection widget, kept in sync
with user MultiSelectionChanged events.
Sourcepub fn value(&self, widget_id: WidgetId) -> GuiResult<Option<i32>>
pub fn value(&self, widget_id: WidgetId) -> GuiResult<Option<i32>>
The live numeric value of a range widget (Slider, SpinBox,
ProgressBar), kept in sync with user ValueChanged events.
Sourcepub fn date_value(&self, widget_id: WidgetId) -> GuiResult<Option<&str>>
pub fn date_value(&self, widget_id: WidgetId) -> GuiResult<Option<&str>>
The live ISO date of a date widget, kept in sync with user
DateChanged events.
Sourcepub fn on_window_close<F>(
&mut self,
window_id: WidgetId,
callback: F,
) -> GuiResult<()>where
F: FnMut() + 'static,
pub fn on_window_close<F>(
&mut self,
window_id: WidgetId,
callback: F,
) -> GuiResult<()>where
F: FnMut() + 'static,
Registers a callback triggered when the given window closes.
Sourcepub fn on_window_resize<F>(
&mut self,
window_id: WidgetId,
callback: F,
) -> GuiResult<()>
pub fn on_window_resize<F>( &mut self, window_id: WidgetId, callback: F, ) -> GuiResult<()>
Registers a callback triggered when the given window is resized.
Sourcepub fn set_layout_root(&mut self, window_id: WidgetId) -> GuiResult<()>
pub fn set_layout_root(&mut self, window_id: WidgetId) -> GuiResult<()>
Registers a window whose declarative layout is kept in sync with the native window automatically.
Whenever dispatch_events sees a UiEvent::WindowResized for
window_id, compute_layout runs with the new dimensions before
user handlers. App code no longer needs manual resize plumbing to
keep computed layouts correct.
Multiple windows can be registered simultaneously. Calling
set_layout_root adds window_id to the registered layout roots.
Sourcepub fn add_layout_root(&mut self, window_id: WidgetId) -> GuiResult<()>
pub fn add_layout_root(&mut self, window_id: WidgetId) -> GuiResult<()>
Adds a window to the set of registered layout roots.
Secondary windows and dialogs can be added so they also automatically recompute layout on resize without clobbering other windows.
Sourcepub fn has_dirty_layout(&self) -> bool
pub fn has_dirty_layout(&self) -> bool
Returns whether any layout roots have pending layout invalidations.
Sourcepub fn is_layout_dirty(&self, widget_id: WidgetId) -> bool
pub fn is_layout_dirty(&self, widget_id: WidgetId) -> bool
Returns whether widget_id is in the pending layout invalidation schedule.
Sourcepub fn flush_layout_roots(&mut self)
pub fn flush_layout_roots(&mut self)
Re-runs layout for every layout root that has pending invalidations.
Called before each event poll/wait, so widgets shown, hidden,
re-sized or re-attached since the last pass - inside a handler or
after dispatch_events returned - are laid out at the root’s last
known size instead of waiting for the next window resize. Free when
nothing is scheduled; roots that were never laid out are skipped.
Sourcepub fn compute_layout_if_dirty(&mut self)
pub fn compute_layout_if_dirty(&mut self)
Synchronously runs a layout pass on any layout roots with pending invalidations.
Equivalent to Self::flush_layout_roots.
Sourcepub fn remove_layout_root(&mut self, window_id: WidgetId) -> bool
pub fn remove_layout_root(&mut self, window_id: WidgetId) -> bool
Removes a window from the set of registered layout roots.
Returns true if the window was registered.
Sourcepub fn is_layout_root(&self, window_id: WidgetId) -> bool
pub fn is_layout_root(&self, window_id: WidgetId) -> bool
Returns true if the given window is currently a registered layout root.
Sourcepub fn layout_roots(&self) -> &HashSet<WidgetId>
pub fn layout_roots(&self) -> &HashSet<WidgetId>
Returns the set of currently registered layout roots.
Registers a callback triggered when a menu item is selected.
Sourcepub fn widget(&self, widget_id: WidgetId) -> Option<&WidgetSpec>
pub fn widget(&self, widget_id: WidgetId) -> Option<&WidgetSpec>
Returns a widget specification by identifier.
Sourcepub fn widget_count(&self) -> usize
pub fn widget_count(&self) -> usize
Returns the number of known widgets.