emilk / egui

egui: an easy-to-use immediate mode GUI in Rust that runs on both web and native
https://www.egui.rs/
Apache License 2.0
21.33k stars 1.54k forks source link

Support double clicking widgets to reset to default value out of the box #1421

Open virtualritz opened 2 years ago

virtualritz commented 2 years ago

A lot of desktop apps in the 2D/3D DCC space now support double-clicking a widget to reset it to its default value. It would be great if egui had support for this out of the box.

Probably for grid layout widgets the label could be part of this. I.e. the entire rectangle, colored in alternating shades of gray, that is the widget's backdrop, would be the active area for double click reset to default.

emilk commented 2 years ago

You should already be able to implement this rather easily with:

if ui.add(DragValue::new(&mut value)).double_clicked() {
    *value = 0.0; // or whatever the default is
}

and the same for sliders, checkboxes etc. Is that good enough already?