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>
impl<'a> Ui<'a>
Sourcepub fn with_id(&mut self, key: impl Hash, add: impl FnOnce(&mut Ui<'_>))
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| ...).
Sourcepub fn horizontal(&mut self, add: impl FnOnce(&mut Ui<'_>))
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.
Sourcepub fn key_pressed(&self, key: Key) -> bool
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.
Sourcepub fn focus_next(&mut self)
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.
Sourcepub fn label_colored(&mut self, color: Color, text: impl Display)
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.
A button, as wide as its text. Clicked when the button goes down on it and up over it.
Sourcepub fn checkbox(&mut self, text: impl Display, value: &mut bool) -> Response
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.
Sourcepub fn slider_f32(
&mut self,
text: impl Display,
value: &mut f32,
range: RangeInclusive<f32>,
) -> Response
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.
Sourcepub fn slider_i32(
&mut self,
text: impl Display,
value: &mut i32,
range: RangeInclusive<i32>,
) -> Response
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.
Sourcepub fn drag_f32(
&mut self,
text: impl Display,
value: &mut f32,
per_unit: f32,
) -> Response
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.
Sourcepub fn text_input(&mut self, text: impl Display, value: &mut String) -> Response
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.
Sourcepub fn combo(
&mut self,
text: impl Display,
selected: &mut usize,
items: &[&str],
) -> Response
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.
Sourcepub fn tree_node(
&mut self,
text: impl Display,
add: impl FnOnce(&mut Ui<'_>),
) -> Response
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.
Sourcepub fn plot(
&mut self,
text: impl Display,
values: impl IntoIterator<Item = f32>,
plot: Plot,
) -> PlotResponse
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.
Sourcepub fn color_edit(&mut self, text: impl Display, color: &mut Color) -> Response
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.