pub struct Ui { /* private fields */ }Expand description
The platform-independent UI runtime: owns the root view, reacts to input and
state changes, and produces a Scene for the renderer.
Platform layers drive it with Ui::set_viewport, Ui::handle_event and
Ui::update, and register a waker with Ui::set_waker to schedule a
frame when state changes outside of event handling (timers, async tasks).
Implementations§
Source§impl Ui
impl Ui
Sourcepub fn access_tree(&mut self) -> AccessTree
pub fn access_tree(&mut self) -> AccessTree
The accessibility tree of the latest frame: roles, names, states and
frames of everything on screen, for screen readers. Call it after
Ui::update; platform layers send it to the operating system when it
changes. While a modal layer is open, only that layer is exposed.
Sourcepub fn shortcuts(&self) -> Vec<Hotkey>
pub fn shortcuts(&self) -> Vec<Hotkey>
The keyboard shortcuts the latest frame answers to, in the order they were registered, for tools that look for two commands on the same keys.
Sourcepub fn perform_action(&mut self, id: u64, action: AccessAction) -> bool
pub fn perform_action(&mut self, id: u64, action: AccessAction) -> bool
Performs an action assistive technology asked for on the node with
this id (from the latest Ui::access_tree). Returns true if the UI
needs a redraw.
Source§impl Ui
impl Ui
Sourcepub fn new(root: impl View + 'static, theme: Theme) -> Ui
pub fn new(root: impl View + 'static, theme: Theme) -> Ui
A runtime for root under theme, with an 800×600 viewport at scale 1.
Sourcepub fn take_frame_work(&mut self) -> FrameWork
pub fn take_frame_work(&mut self) -> FrameWork
What was done since the last call: a platform asks once per frame.
Sourcepub fn set_view_profiling(&mut self, on: bool)
pub fn set_view_profiling(&mut self, on: bool)
Measures every type of view too, on top of the clock of Ui::set_phase_clock.
It costs a little per view, so it stays off unless someone is looking.
Sourcepub fn view_costs(&self) -> Vec<ViewCost>
pub fn view_costs(&self) -> Vec<ViewCost>
What each type of view cost in the latest build, the most expensive first. Empty
without Ui::set_view_profiling.
Sourcepub fn set_phase_clock(&mut self, clock: Option<Rc<dyn Fn() -> f64>>)
pub fn set_phase_clock(&mut self, clock: Option<Rc<dyn Fn() -> f64>>)
Measures the phases with clock, which tells the seconds. Without a clock,
which is the default, measuring costs nothing. WebAssembly has no clock of its
own, so it is the platform that passes one in.
Sourcepub fn phase_times(&self) -> PhaseTimes
pub fn phase_times(&self) -> PhaseTimes
Time spent in each phase since the clock was set; see Ui::set_phase_clock.
Sourcepub fn set_clipboard(&mut self, provider: impl ClipboardProvider + 'static)
pub fn set_clipboard(&mut self, provider: impl ClipboardProvider + 'static)
Installs the system clipboard (platform layers do this); the default is an in-memory clipboard.
Sourcepub fn set_links(&mut self, provider: impl LinkOpener + 'static)
pub fn set_links(&mut self, provider: impl LinkOpener + 'static)
Installs how addresses open (the platform layers do). Until then they are only
recorded, which tests read through crate::Links::opened.
Sourcepub fn set_full_screen(&mut self, provider: impl FullScreenProvider + 'static)
pub fn set_full_screen(&mut self, provider: impl FullScreenProvider + 'static)
Installs how the app enters and leaves full screen (the platform layers do). Until then the request is only remembered.
Sourcepub fn full_screen(&self) -> FullScreen
pub fn full_screen(&self) -> FullScreen
The full screen service views ask through.
Sourcepub fn set_sound(&mut self, provider: impl SoundProvider + 'static)
pub fn set_sound(&mut self, provider: impl SoundProvider + 'static)
Installs the system’s sound (platform layers do this); the default is silence.
Sourcepub fn set_file_picker(&mut self, provider: impl FilePickerProvider + 'static)
pub fn set_file_picker(&mut self, provider: impl FilePickerProvider + 'static)
Installs the system’s chooser of files (platform layers do this); the default chooses nothing.
Sourcepub fn set_files_over(&mut self, over: bool)
pub fn set_files_over(&mut self, over: bool)
Says whether files are being dragged over the window (platform layers do this).
Sourcepub fn drop_files(
&mut self,
position: Option<Point>,
files: Vec<PickedFile>,
) -> bool
pub fn drop_files( &mut self, position: Option<Point>, files: Vec<PickedFile>, ) -> bool
Hands dropped files to the place under position. When no place is there, and the
screen has only one, it goes there: not every system says where a drop landed.
Whether anything took them.
Sourcepub fn set_waker(&mut self, waker: impl Fn() + 'static)
pub fn set_waker(&mut self, waker: impl Fn() + 'static)
Called whenever reactive state the UI depends on changes.
Sourcepub fn ui_waker(&self) -> UiWaker
pub fn ui_waker(&self) -> UiWaker
A handle that asks for a rebuild from another thread; see UiWaker.
Sourcepub fn set_remote_waker(&mut self, notify: impl Fn() + Send + Sync + 'static)
pub fn set_remote_waker(&mut self, notify: impl Fn() + Send + Sync + 'static)
Tells a platform when a UiWaker fires, from whichever thread that is,
so it can leave its sleep. Only the first call counts.
Sourcepub fn set_viewport(&mut self, size: Size, scale: f32)
pub fn set_viewport(&mut self, size: Size, scale: f32)
Sets the viewport in logical pixels and the device scale factor.
Sourcepub fn set_theme(&mut self, theme: Theme)
pub fn set_theme(&mut self, theme: Theme)
Switches the theme; components can do the same through BuildCx::theme_state.
Sourcepub fn theme_state(&self) -> State<Theme>
pub fn theme_state(&self) -> State<Theme>
The theme as reactive state.
Sourcepub fn text_system(&mut self) -> &mut TextSystem
pub fn text_system(&mut self) -> &mut TextSystem
Fonts registered here become available to every Text.
Sourcepub fn needs_redraw(&self) -> bool
pub fn needs_redraw(&self) -> bool
True when the next Ui::update would produce a different scene.
Sourcepub fn is_animating(&self) -> bool
pub fn is_animating(&self) -> bool
True while an animation is running, which means the next frame will differ from this one even if nothing else happens.
Sourcepub fn set_time(&mut self, seconds: f64)
pub fn set_time(&mut self, seconds: f64)
Sets the clock (seconds since the app started). Platforms call it before handling events and before each frame. Animations start only once a platform drives this clock.
Animations follow their own clock, which skips stalls: after a long pause (a hidden window, a slow frame) they continue about where they were instead of jumping to the end.
Sourcepub fn set_reduced_motion(&mut self, reduced: bool)
pub fn set_reduced_motion(&mut self, reduced: bool)
Tells the runtime that the system asks for reduced motion. Things stop
traveling and springing; colors and opacity may still fade. A theme can
ask for the same through its reduced_motion token.
Sourcepub fn next_wake(&self) -> Option<f64>
pub fn next_wake(&self) -> Option<f64>
When the UI wants its next frame even without input (seconds, same clock
as Ui::set_time). Platforms schedule a timer for it.
Sourcepub fn is_dragging(&self) -> bool
pub fn is_dragging(&self) -> bool
True while a pointer drag that started on a draggable element (a slider, a splitter) is in progress. Touch platforms use it to tell drags from scrolls.
Sourcepub fn cursor(&self) -> CursorIcon
pub fn cursor(&self) -> CursorIcon
The cursor the platform should show.
Sourcepub fn update(&mut self) -> &Scene
pub fn update(&mut self) -> &Scene
Rebuilds, lays out and paints as needed, then returns the current scene.
Sourcepub fn element_count(&self) -> usize
pub fn element_count(&self) -> usize
Number of elements produced by the last build.
Sourcepub fn handle_event(&mut self, event: &Event) -> bool
pub fn handle_event(&mut self, event: &Event) -> bool
Feeds one input event; returns true when a redraw is needed.