Trait egui::widgets::Widget [−][src]
#[must_use = "You should put this widget in an ui with `ui.add(widget);`"] pub trait Widget { fn ui(self, ui: &mut Ui) -> Response; }
Anything implementing Widget can be added to a Ui
with Ui::add
.
Examples include [Button]
, [Label]
and Slider
.
|ui: &mut Ui| -> Response { … }
also implemented Widget
.
Required methods
Loading content...Implementations on Foreign Types
Loading content...Implementors
impl<F> Widget for F where
F: FnOnce(&mut Ui) -> Response,
[src]
impl<F> Widget for F where
F: FnOnce(&mut Ui) -> Response,
[src]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 } }