egui::widgets

Trait Widget

source
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§

source

fn ui(self, ui: &mut Ui) -> Response

Allocate space, interact, paint, and return a Response.

Note that this consumes self. This is because most widgets (Button, TextEdit etc) are builders

Tip: you can impl Widget for &mut YourObject { }.

Implementations on Foreign Types§

source§

impl Widget for &PaintStats

source§

fn ui(self, ui: &mut Ui) -> Response

source§

impl Widget for &mut TessellationOptions

source§

fn ui(self, ui: &mut Ui) -> Response

Implementors§

source§

impl Widget for &mut Frame

source§

impl Widget for &mut FontTweak

source§

impl Widget for &mut Margin

source§

impl Widget for &mut Rounding

source§

impl Widget for &mut Shadow

source§

impl Widget for &mut Stroke

source§

impl Widget for Button<'_>

source§

impl Widget for Label

source§

impl Widget for ProgressBar

source§

impl Widget for RadioButton

source§

impl Widget for SelectableLabel

source§

impl Widget for Separator

source§

impl Widget for Spinner

source§

impl<'a> Widget for Checkbox<'a>

source§

impl<'a> Widget for DragValue<'a>

source§

impl<'a> Widget for Image<'a>

source§

impl<'a> Widget for ImageButton<'a>

source§

impl<'a> Widget for Slider<'a>

source§

impl<'t> Widget for TextEdit<'t>

source§

impl<F> Widget for F
where F: FnOnce(&mut Ui) -> Response,

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
   }
}