Add widget egui::reset_button
This commit is contained in:
parent
fffa5e7795
commit
a905c884e8
6 changed files with 24 additions and 31 deletions
|
@ -65,8 +65,6 @@ impl paint::FontDefinitions {
|
|||
.text(format!("{:?}", text_style)),
|
||||
);
|
||||
}
|
||||
if ui.button("Reset fonts").clicked {
|
||||
*self = Default::default();
|
||||
}
|
||||
crate::reset_button(ui, self);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -345,9 +345,7 @@ use crate::{widgets::*, Ui};
|
|||
|
||||
impl Style {
|
||||
pub fn ui(&mut self, ui: &mut crate::Ui) {
|
||||
if ui.button("Reset").clicked {
|
||||
*self = Default::default();
|
||||
}
|
||||
crate::reset_button(ui, self);
|
||||
|
||||
let Self {
|
||||
body_text_style,
|
||||
|
@ -371,9 +369,7 @@ impl Style {
|
|||
|
||||
impl Spacing {
|
||||
pub fn ui(&mut self, ui: &mut crate::Ui) {
|
||||
if ui.button("Reset").clicked {
|
||||
*self = Default::default();
|
||||
}
|
||||
crate::reset_button(ui, self);
|
||||
|
||||
let Self {
|
||||
item_spacing,
|
||||
|
@ -404,15 +400,12 @@ impl Spacing {
|
|||
|
||||
impl Interaction {
|
||||
pub fn ui(&mut self, ui: &mut crate::Ui) {
|
||||
if ui.button("Reset").clicked {
|
||||
*self = Default::default();
|
||||
}
|
||||
crate::reset_button(ui, self);
|
||||
|
||||
let Self {
|
||||
resize_grab_radius_side,
|
||||
resize_grab_radius_corner,
|
||||
} = self;
|
||||
|
||||
ui.add(Slider::f32(resize_grab_radius_side, 0.0..=20.0).text("resize_grab_radius_side"));
|
||||
ui.add(
|
||||
Slider::f32(resize_grab_radius_corner, 0.0..=20.0).text("resize_grab_radius_corner"),
|
||||
|
@ -422,9 +415,7 @@ impl Interaction {
|
|||
|
||||
impl Widgets {
|
||||
pub fn ui(&mut self, ui: &mut crate::Ui) {
|
||||
if ui.button("Reset").clicked {
|
||||
*self = Default::default();
|
||||
}
|
||||
crate::reset_button(ui, self);
|
||||
|
||||
let Self {
|
||||
active,
|
||||
|
@ -471,9 +462,7 @@ impl WidgetVisuals {
|
|||
|
||||
impl Visuals {
|
||||
pub fn ui(&mut self, ui: &mut crate::Ui) {
|
||||
if ui.button("Reset").clicked {
|
||||
*self = Default::default();
|
||||
}
|
||||
crate::reset_button(ui, self);
|
||||
|
||||
let Self {
|
||||
override_text_color: _,
|
||||
|
|
|
@ -739,3 +739,14 @@ impl Widget for Separator {
|
|||
response
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
/// Show a button to reset a value to its default.
|
||||
/// The button is only enabled if the value does not already have its original value.
|
||||
pub fn reset_button<T: Default + PartialEq>(ui: &mut Ui, value: &mut T) {
|
||||
let def = T::default();
|
||||
if ui.add(Button::new("Reset").enabled(*value != def)).clicked {
|
||||
*value = def;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,7 +106,7 @@ impl DemoWindow {
|
|||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#[derive(serde::Deserialize, serde::Serialize)]
|
||||
#[derive(PartialEq, serde::Deserialize, serde::Serialize)]
|
||||
#[serde(default)]
|
||||
struct ColorWidgets {
|
||||
srgba_unmul: [u8; 4],
|
||||
|
@ -129,9 +129,7 @@ impl Default for ColorWidgets {
|
|||
|
||||
impl ColorWidgets {
|
||||
fn ui(&mut self, ui: &mut Ui) {
|
||||
if ui.button("Reset").clicked {
|
||||
*self = Default::default();
|
||||
}
|
||||
egui::reset_button(ui, self);
|
||||
|
||||
ui.label("Egui lets you edit colors stored as either sRGBA or linear RGBA and with or without premultiplied alpha");
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ use egui::*;
|
|||
use std::f64::INFINITY;
|
||||
|
||||
/// Showcase sliders
|
||||
#[derive(serde::Deserialize, serde::Serialize)]
|
||||
#[derive(PartialEq, serde::Deserialize, serde::Serialize)]
|
||||
#[serde(default)]
|
||||
pub struct Sliders {
|
||||
pub min: f64,
|
||||
|
@ -108,8 +108,6 @@ impl Sliders {
|
|||
ui.checkbox(smart_aim, "Smart Aim");
|
||||
ui.label("Smart Aim will guide you towards round values when you drag the slider so you you are more likely to hit 250 than 247.23");
|
||||
|
||||
if ui.button("Reset slider demo").clicked {
|
||||
*self = Default::default();
|
||||
}
|
||||
egui::reset_button(ui, self);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use egui::{containers::*, widgets::*, *};
|
||||
use std::f32::consts::TAU;
|
||||
|
||||
#[derive(serde::Deserialize, serde::Serialize)]
|
||||
#[derive(PartialEq, serde::Deserialize, serde::Serialize)]
|
||||
#[serde(default)]
|
||||
pub struct FractalClock {
|
||||
paused: bool,
|
||||
|
@ -87,9 +87,8 @@ impl FractalClock {
|
|||
ui.add(Slider::f32(&mut self.length_factor, 0.0..=1.0).text("length factor"));
|
||||
ui.add(Slider::f32(&mut self.luminance_factor, 0.0..=1.0).text("luminance factor"));
|
||||
ui.add(Slider::f32(&mut self.width_factor, 0.0..=1.0).text("width factor"));
|
||||
if ui.button("Reset").clicked {
|
||||
*self = Default::default();
|
||||
}
|
||||
|
||||
egui::reset_button(ui, self);
|
||||
|
||||
ui.add(
|
||||
Hyperlink::new("http://www.dqd.com/~mayoff/programs/FractalClock/")
|
||||
|
|
Loading…
Reference in a new issue