Skip to main content

Ui

Struct Ui 

Source
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

Source

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.

Source

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.

Source

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

Source

pub fn new(root: impl View + 'static, theme: Theme) -> Ui

A runtime for root under theme, with an 800×600 viewport at scale 1.

Source

pub fn take_frame_work(&mut self) -> FrameWork

What was done since the last call: a platform asks once per frame.

Source

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.

Source

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.

Source

pub fn stats(&self) -> UiStats

What this runtime has done so far.

Source

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.

Source

pub fn phase_times(&self) -> PhaseTimes

Time spent in each phase since the clock was set; see Ui::set_phase_clock.

Source

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.

Source

pub fn clipboard(&self) -> Clipboard

The clipboard widgets copy to and paste from.

Installs how addresses open (the platform layers do). Until then they are only recorded, which tests read through crate::Links::opened.

The links service views open addresses through.

Source

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.

Source

pub fn full_screen(&self) -> FullScreen

The full screen service views ask through.

Source

pub fn set_sound(&mut self, provider: impl SoundProvider + 'static)

Installs the system’s sound (platform layers do this); the default is silence.

Source

pub fn sound(&self) -> Sound

The sound system views play through.

Source

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.

Source

pub fn set_files_over(&mut self, over: bool)

Says whether files are being dragged over the window (platform layers do this).

Source

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.

Source

pub fn set_waker(&mut self, waker: impl Fn() + 'static)

Called whenever reactive state the UI depends on changes.

Source

pub fn ui_waker(&self) -> UiWaker

A handle that asks for a rebuild from another thread; see UiWaker.

Source

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.

Source

pub fn set_viewport(&mut self, size: Size, scale: f32)

Sets the viewport in logical pixels and the device scale factor.

Source

pub fn viewport(&self) -> Size

The viewport size in logical pixels.

Source

pub fn scale(&self) -> f32

The device scale factor (physical pixels per logical pixel).

Source

pub fn theme(&self) -> Theme

The current theme.

Source

pub fn set_theme(&mut self, theme: Theme)

Switches the theme; components can do the same through BuildCx::theme_state.

Source

pub fn theme_state(&self) -> State<Theme>

The theme as reactive state.

Source

pub fn text_system(&mut self) -> &mut TextSystem

Fonts registered here become available to every Text.

Source

pub fn needs_redraw(&self) -> bool

True when the next Ui::update would produce a different scene.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn cursor(&self) -> CursorIcon

The cursor the platform should show.

Source

pub fn update(&mut self) -> &Scene

Rebuilds, lays out and paints as needed, then returns the current scene.

Source

pub fn scene(&self) -> &Scene

The last painted scene.

Source

pub fn element_count(&self) -> usize

Number of elements produced by the last build.

Source

pub fn handle_event(&mut self, event: &Event) -> bool

Feeds one input event; returns true when a redraw is needed.

Trait Implementations§

Source§

impl Debug for Ui

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !Freeze for Ui

§

impl !RefUnwindSafe for Ui

§

impl !Send for Ui

§

impl !Sync for Ui

§

impl !UnwindSafe 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> AutoreleaseSafe for T
where T: ?Sized,

Source§

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

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

§

fn to_sample_(self) -> U

Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more