1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-02 14:50:03 -04:00

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(toggle(bool))` (instead of `toggle(ui, bool)`)
This commit is contained in:
Emil Ernerfeldt
2021-02-20 11:58:08 +01:00
parent 6fe70e685b
commit 040553da78
4 changed files with 62 additions and 48 deletions

View File

@@ -156,7 +156,10 @@ impl super::View for WidgetGallery {
ui.end_row();
ui.label("Custom widget:");
super::toggle_switch::demo(ui, boolean);
ui.add(super::toggle_switch::toggle(boolean)).on_hover_text(
"It's easy to create your own widgets!\n\
This toggle switch is just 15 lines of code.",
);
ui.end_row();
ui.label("Plot:");