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>
impl<B: Backend> Ui<B>
pub fn new(backend: B) -> Self
Sourcepub fn create_window(&self, title: &str, size: Size) -> WindowId
pub fn create_window(&self, title: &str, size: Size) -> WindowId
Opens a hidden window; fill it with Ui::set_content, then Ui::show it.
Sourcepub fn content(&self, window: WindowId, style: &StackStyle) -> Node
pub fn content(&self, window: WindowId, style: &StackStyle) -> Node
A stack to fill the window with, through Ui::set_content.
pub fn stack(&self, at: Position, style: &StackStyle) -> Node
Sourcepub fn scroll(&self, at: Position, style: &StackStyle) -> Node
pub fn scroll(&self, at: Position, style: &StackStyle) -> Node
A stack whose children scroll up and down when they are taller than it.
pub fn spacer(&self, at: Position) -> Node
pub fn label(&self, at: Position, text: &str, style: LabelStyle) -> Node
pub fn text_field( &self, at: Position, text: &str, (placeholder, lines): (&str, u32), on_change: TextHandler, on_submit: Option<ClickHandler>, ) -> Node
pub fn checkbox( &self, at: Position, title: &str, checked: bool, style: ToggleStyle, on_toggle: ToggleHandler, ) -> Node
pub fn slider( &self, at: Position, value: i64, range: (i64, i64), on_change: NumberHandler, ) -> Node
pub fn picker( &self, at: Position, options: &[String], selected: &str, on_pick: TextHandler, ) -> Node
Sourcepub fn progress(&self, at: Position, percent: Option<i64>) -> Node
pub fn progress(&self, at: Position, percent: Option<i64>) -> Node
A progress bar at percent, kept between 0 and 100, or busy without one.
Sourcepub fn image(&self, at: Position, path: &str, size: ImageSize) -> Node
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.
An area covering the stack at is in, which shows a menu of entries on a right
click.
Sourcepub fn drop_target(&self, at: Position, on_drop: DropHandler) -> Node
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.
pub fn divider(&self, at: Position) -> Node
Sourcefn add_widget(
&self,
at: Position,
place: fn(&mut Layout<B::Widget>, B::Widget, Size) -> NodeId,
create: impl FnOnce(&B, Parent<'_, B>) -> B::Widget,
) -> Node
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.
Sourcefn add<Made>(
&self,
at: Position,
create: impl FnOnce(&B, Parent<'_, B>, &B::Window) -> Made,
place: impl FnOnce(&mut Layout<B::Widget>, Made) -> NodeId,
) -> Node
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.
Sourcepub fn set_content(&self, window: WindowId, content: Node)
pub fn set_content(&self, window: WindowId, content: Node)
Makes content fill the window, removing whatever it showed before.
Sourcepub fn set_text(&self, node: Node, text: &str)
pub fn set_text(&self, node: Node, text: &str)
§Panics
When node is a stack or spacer rather than a widget.
Sourcepub fn set_badge(&self, node: Node, badge: &str)
pub fn set_badge(&self, node: Node, badge: &str)
§Panics
When node is a stack or spacer rather than a widget.
Sourcepub fn set_options(&self, node: Node, options: &[String])
pub fn set_options(&self, node: Node, options: &[String])
§Panics
When node is a stack or spacer rather than a widget.
Sourcefn change_content(&self, node: Node, change: impl FnOnce(&B, &B::Widget))
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.
Sourcepub fn set_checked(&self, node: Node, checked: bool)
pub fn set_checked(&self, node: Node, checked: bool)
§Panics
When node is a stack or spacer rather than a widget.
Sourcepub fn set_progress(&self, node: Node, percent: i64)
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.
Sourcefn change_state(&self, node: Node, change: impl FnOnce(&B, &B::Widget))
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.
Sourcepub fn show(&self, window: WindowId)
pub fn show(&self, window: WindowId)
Shows the window, first widening it if its content doesn’t fit.
pub fn set_title(&self, window: WindowId, title: &str)
pub fn set_backdrop(&self, window: WindowId, backdrop: Backdrop)
Sourcepub fn set_size(&self, window: WindowId, size: Size)
pub fn set_size(&self, window: WindowId, size: Size)
Resizes the window’s content area and lays it out at the new size.
Sourcepub fn set_close_handler(&self, on_close: WindowCloseHandler)
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.
Sourcefn close_requested(&self, window: WindowId)
fn close_requested(&self, window: WindowId)
The user asked to close window, which may have closed since the request set out.
Gives the app menus; see Backend::set_menu_bar.
Sourcepub fn waker(&self, on_wake: WakeHandler) -> B::Waker
pub fn waker(&self, on_wake: WakeHandler) -> B::Waker
Returns something any thread can use to have on_wake run on the UI thread.
Sourcepub fn dialogs(&self) -> Rc<dyn ShowDialog>
pub fn dialogs(&self) -> Rc<dyn ShowDialog>
The platform’s file dialogs, for code that isn’t generic over the backend.