Skip to main content

Ui

Struct Ui 

Source
pub struct Ui<B: Backend> {
    state: Rc<RefCell<UiState<B>>>,
}
Expand description

A shared handle to the app’s windows; clones refer to the same UI.

Fields§

§state: Rc<RefCell<UiState<B>>>

Implementations§

Source§

impl<B: Backend> Ui<B>

Source

pub fn new(backend: B) -> Self

Source

pub fn create_window(&self, title: &str, size: Size) -> WindowId

Opens a hidden window; fill it with Ui::set_content, then Ui::show it.

Source

pub fn content(&self, window: WindowId, style: &StackStyle) -> Node

A stack to fill the window with, through Ui::set_content.

Source

pub fn stack(&self, at: Position, style: &StackStyle) -> Node

Source

pub fn scroll(&self, at: Position, style: &StackStyle) -> Node

A stack whose children scroll up and down when they are taller than it.

Source

pub fn spacer(&self, at: Position) -> Node

Source

pub fn label(&self, at: Position, text: &str, style: LabelStyle) -> Node

Source

pub fn button( &self, at: Position, title: &str, look: (ButtonStyle, Icon), selected: Option<bool>, on_click: ClickHandler, ) -> Node

Source

pub fn nav_item( &self, at: Position, title: &str, icon: Icon, badge: &str, selected: bool, on_click: ClickHandler, ) -> Node

Source

pub fn text_field( &self, at: Position, text: &str, (placeholder, lines): (&str, u32), on_change: TextHandler, on_submit: Option<ClickHandler>, ) -> Node

Source

pub fn checkbox( &self, at: Position, title: &str, checked: bool, style: ToggleStyle, on_toggle: ToggleHandler, ) -> Node

Source

pub fn slider( &self, at: Position, value: i64, range: (i64, i64), on_change: NumberHandler, ) -> Node

Source

pub fn picker( &self, at: Position, options: &[String], selected: &str, on_pick: TextHandler, ) -> Node

Source

pub fn progress(&self, at: Position, percent: Option<i64>) -> Node

A progress bar at percent, kept between 0 and 100, or busy without one.

Source

pub fn image(&self, at: Position, path: &str, size: ImageSize) -> Node

The image in the file at path, where ~ stands for the home folder, shown at size. An empty path, or one whose home folder can’t be found, shows nothing, as a file that can’t be read as an image does.

Source

pub fn context_menu( &self, at: Position, entries: &[MenuEntry<usize>], on_select: MenuHandler, ) -> Node

An area covering the stack at is in, which shows a menu of entries on a right click.

Source

pub fn drop_target(&self, at: Position, on_drop: DropHandler) -> Node

An area covering the stack at is in, which takes files and links dropped on it.

Source

pub fn divider(&self, at: Position) -> Node

Source

fn add_widget( &self, at: Position, place: fn(&mut Layout<B::Widget>, B::Widget, Size) -> NodeId, create: impl FnOnce(&B, Parent<'_, B>) -> B::Widget, ) -> Node

Creates a widget in the parent at names, and places it there.

Source

fn add<Made>( &self, at: Position, create: impl FnOnce(&B, Parent<'_, B>, &B::Window) -> Made, place: impl FnOnce(&mut Layout<B::Widget>, Made) -> NodeId, ) -> Node

Makes a node in two steps, create making its native parts in the parent at names, and place adding them to the layout, then places it there.

Source

pub fn set_content(&self, window: WindowId, content: Node)

Makes content fill the window, removing whatever it showed before.

Source

pub fn remove(&self, node: Node)

Removes node and everything inside it from the window.

Source

pub fn set_text(&self, node: Node, text: &str)

§Panics

When node is a stack or spacer rather than a widget.

Source

pub fn set_badge(&self, node: Node, badge: &str)

§Panics

When node is a stack or spacer rather than a widget.

Source

pub fn set_image(&self, node: Node, path: &str)

Shows the image at path instead, as Ui::image does.

§Panics

When node is a stack or spacer rather than a widget.

Source

pub fn set_options(&self, node: Node, options: &[String])

§Panics

When node is a stack or spacer rather than a widget.

Source

fn change_content(&self, node: Node, change: impl FnOnce(&B, &B::Widget))

Changes what a widget shows, then lays its window out again if that changed its size.

Source

pub fn set_checked(&self, node: Node, checked: bool)

§Panics

When node is a stack or spacer rather than a widget.

Source

pub fn set_progress(&self, node: Node, percent: i64)

Fills a progress bar to percent, kept between 0 and 100.

§Panics

When node is a stack or spacer rather than a widget.

Source

pub fn set_value(&self, node: Node, value: i64)

Moves a slider to value.

§Panics

When node is a stack or spacer rather than a widget.

Source

fn change_state(&self, node: Node, change: impl FnOnce(&B, &B::Widget))

Changes a widget’s state, such as whether it’s checked, which leaves its size alone.

Source

pub fn flush(&self)

Lays out every window changed since the last flush.

Source

pub fn show(&self, window: WindowId)

Shows the window, first widening it if its content doesn’t fit.

Source

pub fn set_title(&self, window: WindowId, title: &str)

Source

pub fn set_backdrop(&self, window: WindowId, backdrop: Backdrop)

Source

pub fn set_size(&self, window: WindowId, size: Size)

Resizes the window’s content area and lays it out at the new size.

Source

pub fn set_close_handler(&self, on_close: WindowCloseHandler)

Removes the window’s widgets and closes it. Its id must not be used again.

§Panics

When the window is already closed. Has on_close decide what happens when the user asks to close a window, in place of closing it.

Source

fn close_requested(&self, window: WindowId)

The user asked to close window, which may have closed since the request set out.

Source

pub fn focus(&self, window: WindowId)

Brings a window already shown to the front.

Source

pub fn close(&self, window: WindowId)

Closes the window and removes everything in it.

§Panics

When the window is closed already.

Source

pub fn set_menu_bar(&self, menus: &[Menu<usize>], on_select: MenuHandler)

Gives the app menus; see Backend::set_menu_bar.

Source

pub fn waker(&self, on_wake: WakeHandler) -> B::Waker

Returns something any thread can use to have on_wake run on the UI thread.

Source

pub fn dialogs(&self) -> Rc<dyn ShowDialog>

The platform’s file dialogs, for code that isn’t generic over the backend.

Source

pub fn run(&self)

Runs the event loop until the app quits.

Trait Implementations§

Source§

impl<B: Backend> Clone for Ui<B>

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

impl<B: Backend> Debug for Ui<B>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<B> !RefUnwindSafe for Ui<B>

§

impl<B> !Send for Ui<B>

§

impl<B> !Sync for Ui<B>

§

impl<B> !UnwindSafe for Ui<B>

§

impl<B> Freeze for Ui<B>

§

impl<B> Unpin for Ui<B>

§

impl<B> UnsafeUnpin for Ui<B>

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