pub trait Widget {
// Required method
fn ui(self, ui: &mut Ui) -> Response;
}
Expand description
Anything implementing Widget can be added to a Ui
with Ui::add
.
Button
, Label
, Slider
, etc all implement the Widget
trait.
You only need to implement Widget
if you care about being able to do ui.add(your_widget);
.
Note that the widgets (Button
, TextEdit
etc) are
builders,
and not objects that hold state.
Tip: you can impl Widget for &mut YourThing { }
.
|ui: &mut Ui| -> Response { … }
also implements Widget
.
Required Methods§
Implementations on Foreign Types§
Implementors§
impl Widget for Button<'_>
impl Widget for Hyperlink
impl Widget for Label
impl Widget for Link
impl Widget for ProgressBar
impl Widget for RadioButton
impl Widget for SelectableLabel
impl Widget for Separator
impl Widget for Spinner
impl<'a> Widget for Checkbox<'a>
impl<'a> Widget for DragValue<'a>
impl<'a> Widget for Image<'a>
impl<'a> Widget for ImageButton<'a>
impl<'a> Widget for Slider<'a>
impl<'t> Widget for TextEdit<'t>
impl<F> Widget for F
This enables functions that return impl Widget
, so that you can
create a widget by just returning a lambda from a function.
For instance: ui.add(slider_vec2(&mut vec2));
with:
pub fn slider_vec2(value: &mut egui::Vec2) -> impl egui::Widget + '_ {
move |ui: &mut egui::Ui| {
ui.horizontal(|ui| {
ui.add(egui::Slider::new(&mut value.x, 0.0..=1.0).text("x"));
ui.add(egui::Slider::new(&mut value.y, 0.0..=1.0).text("y"));
})
.response
}
}