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§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Implementors§
impl Widget for &mut Frame
impl Widget for &mut CornerRadius
impl Widget for &mut FontTweak
impl Widget for &mut Margin
impl Widget for &mut Shadow
impl Widget for &mut Stroke
impl Widget for AtomLayout<'_>
impl Widget for Button<'_>
impl Widget for Checkbox<'_>
impl Widget for DragValue<'_>
impl Widget for Hyperlink
impl Widget for Image<'_>
impl Widget for ImageButton<'_>
impl Widget for Label
impl Widget for Link
impl Widget for ProgressBar
impl Widget for RadioButton<'_>
impl Widget for Separator
impl Widget for Slider<'_>
impl Widget for Spinner
impl Widget for TextEdit<'_>
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
}
}