Skip to main content

Ui

Struct Ui 

Source
pub struct Ui { /* private fields */ }
Expand description

Handle to a UI instance: one backend, its windows and their node trees. Cheap to clone; all clones share the same state.

Implementations§

Source§

impl Ui

Source

pub fn a11y_tree(&self, window: NodeId) -> Option<A11yNode>

The computed accessibility tree of a window.

Source§

impl Ui

Source

pub fn create(&self, kind: WidgetKind, props: Vec<Prop>) -> NodeId

Source

pub fn create_window( &self, title: impl Into<String>, size: impl Into<WindowSize>, ) -> NodeId

A window fitting its height is sized at its first layout, so give it its content before the next commit.

Source

pub fn set_window_size(&self, window: NodeId, size: Size)

Asks for a window’s content size, in points, as the app would resize it. The platform may refuse it (a window in full screen keeps the screen’s), and gives it no smaller than the window’s MinSize; the content is laid out at the size it reports (WindowResized). A WindowSize::FollowHeight window takes only the width: its content sets its height. Other windows stop fitting their height.

Source

pub fn set_prop(&self, id: NodeId, prop: Prop)

Sets a prop, sending it to the backend only if it changed.

Source

pub fn set_style(&self, id: NodeId, style: Style)

Source

pub fn update_style(&self, id: NodeId, f: impl FnOnce(&mut Style))

Edits a node’s style in place (used by reactive style bindings).

Source

pub fn set_a11y(&self, id: NodeId, a11y: A11yProps)

Source

pub fn update_a11y(&self, id: NodeId, f: impl FnOnce(&mut A11yProps))

Changes part of a node’s semantics.

Source

pub fn set_test_id(&self, id: NodeId, test_id: impl Into<String>)

Source

pub fn on_event(&self, id: NodeId, handler: impl Fn(&UiEvent) + 'static)

Adds an event handler. It runs in the reactive scope that is current now (usually the component being built), so inject, spawn_local and friends work inside it.

Source§

impl Ui

Source

pub fn set_tab_index(&self, id: NodeId, index: Option<u32>)

Moves a control ahead in the Tab order: controls with a tab index come first, lowest index first, then everything else in tree order.

Source

pub fn focused(&self, window: NodeId) -> Option<NodeId>

The control that has keyboard focus in window, if any.

Source

pub fn focus_order(&self, window: NodeId) -> Vec<NodeId>

The keyboard order of a window’s focusable controls, as sent to the backend.

Source

pub fn focus(&self, id: NodeId)

Gives the control keyboard focus, at the next commit.

Source

pub fn select_text(&self, id: NodeId, range: Range<usize>)

Focuses a text field or text area and selects these grapheme clusters of its text, at the next commit; a range past its end is cut to it. Other controls are only focused.

Source§

impl Ui

Source

pub fn process_events(&self)

Drains native events and dispatches them to handlers. Handlers run in one reactive batch per event.

Source

pub fn commit(&self)

Brings the native tree up to date: styles, structure, props, layout.

Source

pub fn tick(&self)

One run-loop turn: dispatch events and commit, repeating while the commit itself produced new events (e.g. a window resize) or new sizes views watch, until idle. Backends call this from their run loop, before it goes to sleep.

Source

pub fn perform( &self, id: NodeId, action: &A11yAction, ) -> Result<(), ActionError>

Asks the backend to perform an accessibility action, then dispatches the events it produced.

Custom widgets the backend can’t act on get the event their shared definition gives the action (e.g. Increment → a new value).

Source

pub fn synthesize( &self, id: NodeId, input: &SyntheticInput, ) -> Result<(), ActionError>

Synthesizes raw input on a native control, then dispatches the events it produced.

Source§

impl Ui

Source

pub fn windows(&self) -> Vec<NodeId>

Source

pub fn exists(&self, id: NodeId) -> bool

Source

pub fn kind(&self, id: NodeId) -> Option<WidgetKind>

Source

pub fn props(&self, id: NodeId) -> Vec<Prop>

Source

pub fn parent(&self, id: NodeId) -> Option<NodeId>

Source

pub fn children(&self, id: NodeId) -> Vec<NodeId>

Source

pub fn native_children(&self, id: NodeId) -> Vec<NodeId>

Source

pub fn frame(&self, id: NodeId) -> Option<Rect>

Frame relative to the native parent, as last sent to the backend. A list’s rows are where the platform put them, at the size sent.

Source

pub fn window_frame(&self, id: NodeId) -> Option<Rect>

Frame in the coordinates of the node’s window.

Source

pub fn viewport(&self, id: NodeId) -> Option<Rect>

Where a ScrollView shows its content, in window coordinates: its frame less the room its scroll bars take, if the platform’s do.

Source

pub fn viewport_insets(&self, id: NodeId) -> Option<Insets>

Where a ScrollView’s viewport is in its frame, as the platform last reported it.

Source

pub fn visible_rect(&self, id: NodeId) -> Option<Rect>

The part of a node that can be seen: its window frame, clipped by every enclosing scroll view’s viewport and by the window (or, in the toolbar, by its toolbar item; the sidebar, by itself). None if nothing is.

Source

pub fn window_of(&self, id: NodeId) -> Option<NodeId>

The window a node is attached to, if any.

Source

pub fn window_size(&self, window: NodeId) -> Option<Size>

Source

pub fn native_state(&self, id: NodeId) -> Option<NativeState>

Source

pub fn capture( &self, id: NodeId, ) -> impl Future<Output = Result<Image, CaptureError>> + use<>

An offscreen screenshot of a window or node.

Source

pub fn inspect(&self, id: NodeId) -> Option<NodeInfo>

The native tree under id, with window-coordinate frames.

Source§

impl Ui

Source

pub fn scroll_offset(&self, id: NodeId) -> Option<Point>

Current scroll offset of a ScrollView, List or Table.

Source

pub fn scroll_to(&self, id: NodeId, offset: Point)

Scrolls a ScrollView, List or Table. A scroll view’s offset is clamped to its content; a list’s or table’s isn’t, since its rows are the platform’s: the backend clamps it.

Source

pub fn scroll_into_view(&self, id: NodeId)

Scrolls every enclosing ScrollView, List and Table just enough to show the node.

Source§

impl Ui

Source

pub fn set_services(&self, services: Box<dyn Services>)

Replaces the platform services (tests install a scripted fake).

Source

pub fn clipboard_text(&self) -> impl Future<Output = Option<String>> + use<>

Source

pub fn set_clipboard_text( &self, text: &str, ) -> impl Future<Output = Result<(), ServiceError>> + use<>

Puts text on the clipboard. The write is issued right away; await the result to learn whether it worked.

Source

pub fn alert( &self, parent: Option<NodeId>, alert: Alert, ) -> impl Future<Output = usize> + use<>

Shows an alert; resolves to the index of the chosen button.

Source

pub fn open_file( &self, parent: Option<NodeId>, request: OpenFile, ) -> impl Future<Output = Option<Vec<PathBuf>>> + use<>

Resolves to the chosen paths, or None if cancelled.

Source

pub fn save_file( &self, parent: Option<NodeId>, request: SaveFile, ) -> impl Future<Output = Option<PathBuf>> + use<>

Source

pub fn trash( &self, parent: Option<NodeId>, paths: Vec<PathBuf>, ) -> impl Future<Output = Result<(), ServiceError>> + use<>

Moves files and folders to the trash; see Services::trash.

Source

pub fn launch( &self, parent: Option<NodeId>, target: Launch, ) -> impl Future<Output = Result<(), ServiceError>> + use<>

Opens a file, folder or URL in another app; see Services::launch.

Source

pub fn set_menu(&self, menu: MenuBar)

Installs the app’s menus, replacing the ones installed before. Their reactive parts (titles, enabled and checked states, which items there are) are sent to the platform again when they change, for as long as the current scope lives.

Source

pub fn set_window_menu(&self, window: NodeId, menu: MenuBar)

Installs a window’s own menus, shown with the app’s, until the current scope ends. A MenuBar in the window’s content does this.

Source

pub fn request_quit(&self)

Quitting as the platform asks for it from outside the app’s menus (macOS’s Dock, logging out, the session ending): the app’s Quit item, as if chosen, if it has one; otherwise every window is asked to close, as by its close button. Either way the app decides, and it ends when its last window closes. Backends call it, then see whether windows are left.

Source§

impl Ui

Source

pub fn insert_child(&self, parent: NodeId, child: NodeId, index: Option<usize>)

Inserts child under parent at index (or at the end), detaching it from its previous parent first.

Source

pub fn append_child(&self, parent: NodeId, child: NodeId)

Source

pub fn set_children(&self, parent: NodeId, children: Vec<NodeId>)

Replaces the children of parent, keeping nodes that stay.

Source

pub fn destroy(&self, id: NodeId)

Removes a node and its whole subtree, natively too.

Source§

impl Ui

Source

pub fn new(backend: impl Backend + 'static) -> Ui

Source

pub fn downgrade(&self) -> WeakUi

Source

pub fn spawn_local( &self, future: impl Future<Output = ()> + 'static, ) -> TaskHandle

Runs future on the UI thread, polled from Ui::tick. Unlike the free spawn_local, it is not tied to a reactive scope; cancel it with the returned handle.

Source

pub fn sleep(&self, duration: Duration) -> Sleep ⓘ

A future that completes after duration on this Ui’s clock.

Source

pub fn set_clock(&self, clock: Rc<dyn Clock>)

Replaces the clock timers use (tests install a ManualClock).

Source

pub fn set_waker(&self, wake: Arc<dyn Fn() + Send + Sync>)

How to make the UI thread’s run loop turn from any thread; called when a task is woken (e.g. by background work finishing).

Source

pub fn time_to_next_timer(&self) -> Option<Duration>

Time until the next timer fires (zero if overdue), for run loops to schedule a wake-up.

Source

pub fn set_app_info(&self, info: AppInfo)

The app’s id, name and icon, for the platform to show. Set it before the app’s first window; App does.

Source

pub fn pending_tasks(&self) -> usize

Tasks that have not finished yet.

Source

pub fn events(&self) -> EventSink

Source

pub fn metrics(&self) -> PlatformMetrics

Source

pub fn set_locales(&self, locales: Locales)

The app’s translations (locales!). Set them before the app’s first window; App does. The language is chosen from them again.

Source

pub fn set_languages(&self, languages: Option<Vec<String>>)

The languages to choose the app’s from, most wanted first, in place of the user’s: an app’s own language setting, or a test’s. None: the user’s, as the platform lists them.

Source

pub fn language(&self) -> LanguageIdentifier

The app’s language: the first of the user’s it has translations for, else its fallback. Tracked.

Source

pub fn take_l10n_errors(&self) -> Vec<String>

Messages missing from every language, and messages that failed to format, since the last call. Tests fail on them.

Source

pub fn set_commit_scheduler(&self, schedule: impl Fn() + 'static)

Native backends call this to learn when a commit is needed. The callback should schedule Ui::commit on the run loop (e.g. before the next frame). Without a scheduler, callers commit explicitly.

Trait Implementations§

Source§

impl Clone for Ui

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Ui

§

impl !Send for Ui

§

impl !Sync for Ui

§

impl !UnwindSafe for Ui

§

impl Freeze for Ui

§

impl Unpin for Ui

§

impl UnsafeUnpin for Ui

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.