Skip to main content

Ui

Struct Ui 

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

A window’s content, being filled: each widget takes a row, from the top, or a place in a row of Ui::horizontal.

A widget’s text is formatted with Display, into a buffer the frames reuse. Its identity is the hash of its scope’s (its window’s, a tree node’s, a Ui::with_id’s) and its text, or its explicit ID: "Pause (3)##pause" shows Pause (3) and is the widget pause, which stays the one held, or the field with the keyboard, as its count changes. Two widgets of one text in one scope are one widget: give them IDs, or scopes.

Implementations§

Source§

impl<'a> Ui<'a>

Source

pub fn with_id(&mut self, key: impl Hash, add: impl FnOnce(&mut Ui<'_>))

Fills add with the widgets of key’s scope: for the same texts in a loop, say, ui.with_id(index, |ui| ...).

Source

pub fn horizontal(&mut self, add: impl FnOnce(&mut Ui<'_>))

Lays the widgets of add side by side in one row, as high as the highest. A control with a label takes the style’s control_width there, its label after it; a button, a checkbox or a label, its text’s width.

Source

pub fn key_pressed(&self, key: Key) -> bool

Whether key was pressed this frame, or repeated: for keys a text field does not use, Up, Down, Tab, PageUp and PageDown, while it has the keyboard, as a console’s history and completion want.

Source

pub fn focus_next(&mut self)

Gives the keyboard to the next text field called, its caret at its end: a console’s command line when it opens, say. The field takes none of this frame’s edits, which were typed before it had the keyboard: the key that opened the console is not typed into it.

Source

pub fn label(&mut self, text: impl Display)

A line of text.

Source

pub fn label_colored(&mut self, color: Color, text: impl Display)

A line of text in color. One out of the window’s view is not formatted, in a column of rows, which keeps a long log cheap.

Source

pub fn button(&mut self, text: impl Display) -> Response

A button, as wide as its text. Clicked when the button goes down on it and up over it.

Source

pub fn checkbox(&mut self, text: impl Display, value: &mut bool) -> Response

A box ticked when value is true, and its text: a click on either flips it.

Source

pub fn slider_f32( &mut self, text: impl Display, value: &mut f32, range: RangeInclusive<f32>, ) -> Response

A slider of value in range: pressing or dragging on it sets the value under the pointer, held in the range. A value outside the range is left as it is until the slider is moved; a reversed range is swapped; with a NaN bound, it changes nothing.

Source

pub fn slider_i32( &mut self, text: impl Display, value: &mut i32, range: RangeInclusive<i32>, ) -> Response

A slider of whole numbers, as Ui::slider_f32: the value under the pointer is rounded to the nearest, over any range of i32.

Source

pub fn drag_f32( &mut self, text: impl Display, value: &mut f32, per_unit: f32, ) -> Response

A number changed by dragging across it: per_unit for each UI unit the pointer moves right, less moving left. A step or a result that is not finite changes nothing.

Source

pub fn text_input(&mut self, text: impl Display, value: &mut String) -> Response

A one-line text field editing value.

A press on it gives it the keyboard, the caret where it was pressed; a press elsewhere, Escape, or another field taking the keyboard, takes it back (lost_focus, when the field is next called). With the keyboard, typed text goes in at the caret, replacing a selection; Backspace and Delete remove; Left, Right, Home and End move the caret, selecting with Shift; Control or Super with A selects all; Enter is submitted, and the field keeps the keyboard. Other keys are the caller’s (Ui::key_pressed). A value the caller changed puts the caret at its end. Copy and paste are not built.

Source

pub fn combo( &mut self, text: impl Display, selected: &mut usize, items: &[&str], ) -> Response

A choice of items, selected the one shown: a click opens their list over everything, and a click on one picks it; a press elsewhere closes the list. With no items, or selected past them, it shows nothing and changes nothing until one is picked.

Source

pub fn tree_node( &mut self, text: impl Display, add: impl FnOnce(&mut Ui<'_>), ) -> Response

A node of a tree, open or closed by a click, add filling its children, moved in, while it is open. It keeps its state by its identity, and is the scope of its children’s.

Source

pub fn separator(&mut self)

A line across the window.

Source

pub fn plot( &mut self, text: impl Display, values: impl IntoIterator<Item = f32>, plot: Plot, ) -> PlotResponse

A line graph of values, from the left edge to the right, each value i of n at i / (n − 1) of the width, as plot says; values that are not finite break the line, and a value with no finite one beside it is a dot. It says which value is under the pointer, and which was clicked.

Source

pub fn color_edit(&mut self, text: impl Display, color: &mut Color) -> Response

A color: a swatch and its text, then a slider of 0 to 255 for each of red, green, blue and alpha, in its own scope.

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> Forget for Ui<'a>

§

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

§

impl<'a> Move 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.