Skip to main content

Ui

Struct Ui 

Source
pub struct Ui<'a> { /* private fields */ }
Expand description

The handle passed to callbacks.

It gives callbacks access to the Widgets in the window, by ID and concrete type, and lets them stop the Engine. It borrows the Engine’s widget tree only for the duration of the callback.

Implementations§

Source§

impl<'a> Ui<'a>

Source

pub fn cancel_timer(&mut self, id: TimerId) -> bool

Cancels a timer started with Engine::on_timer.

Safe to call from any callback, including the timer’s own: a timer cancelled while the timers due this frame are running does not fire afterwards. Emits EngineEvent::TimerCancelled when a waiting timer was stopped.

§Arguments
  • id - The timer to cancel.
§Returns

true if the timer was still scheduled; false if it was a one-shot that already fired, or was already cancelled.

Source

pub fn request_animation(&mut self, id: WidgetId)

Asks for an Event::Tick for a Widget on the next frame. See WidgetCache::request_animation.

§Arguments
  • id - The Widget to tick.
Source

pub fn post<T: Any>(&mut self, target: EventTarget, payload: T)

Posts a custom event, to be delivered after the callbacks currently running.

The event is queued, never delivered from inside this call. Posting from a custom-event callback is allowed; at most MAX_CUSTOM_EVENTS_PER_FRAME custom events are delivered per frame, and the rest are discarded with an EngineEvent::CustomEventDropped.

§Arguments
  • target - Which Widgets receive the event.
  • payload - The application’s data; receivers read it with Event::payload.
Source

pub fn set_event_mask(&mut self, mask: EventMask)

Changes the run loop’s event mask. See Engine::set_event_mask.

§Arguments
  • mask - The new mask; it applies from the next event.
Source

pub fn set_widget_event_mask(&mut self, id: WidgetId, mask: EventMask)

Changes a Widget’s event mask. See WidgetCache::set_event_mask.

§Arguments
  • id - The ID of the Widget.
  • mask - The new mask.
Source

pub fn get<T: Widget>(&self, id: WidgetId) -> Option<&T>

Retrieves a Widget by ID as its concrete type.

§Arguments
  • id - The ID of the Widget.
§Returns

The Widget as a T, or None if the ID does not exist or the Widget is not a T.

Source

pub fn get_mut<T: Widget>(&mut self, id: WidgetId) -> Option<&mut T>

Retrieves a Widget by ID as its concrete type, for modification.

§Arguments
  • id - The ID of the Widget.
§Returns

The Widget as a mutable T, or None if the ID does not exist or the Widget is not a T.

Source

pub fn widgets(&mut self) -> &mut WidgetCache

Returns the window’s widget tree.

Use it to add Widgets from a callback, or to reach a Widget without knowing its concrete type.

§Returns

The WidgetCache holding every Widget in the window.

Source

pub fn set_focus(&mut self, id: WidgetId) -> bool

Gives the keyboard focus to a Widget. See WidgetCache::set_focus.

§Arguments
  • id - The ID of the Widget.
§Returns

true if the Widget has focus afterward; false if it cannot take focus.

Source

pub fn focused(&self) -> Option<WidgetId>

Returns the Widget that has the keyboard focus.

§Returns

The ID of the focused Widget, or None if nothing has focus.

Source

pub fn shutdown(&mut self)

Stops the Engine.

The run loop finishes the current batch of events, then returns the application state from Engine::run; in the event-loop style, Engine::next_event returns None.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Ui<'a>

§

impl<'a> !Send for Ui<'a>

§

impl<'a> !Sync for Ui<'a>

§

impl<'a> !UnwindSafe for Ui<'a>

§

impl<'a> Freeze for Ui<'a>

§

impl<'a> Unpin for Ui<'a>

§

impl<'a> UnsafeUnpin for Ui<'a>

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