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)),
|
.text(format!("{:?}", text_style)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if ui.button("Reset fonts").clicked {
|
crate::reset_button(ui, self);
|
||||||
*self = Default::default();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -345,9 +345,7 @@ use crate::{widgets::*, Ui};
|
||||||
|
|
||||||
impl Style {
|
impl Style {
|
||||||
pub fn ui(&mut self, ui: &mut crate::Ui) {
|
pub fn ui(&mut self, ui: &mut crate::Ui) {
|
||||||
if ui.button("Reset").clicked {
|
crate::reset_button(ui, self);
|
||||||
*self = Default::default();
|
|
||||||
}
|
|
||||||
|
|
||||||
let Self {
|
let Self {
|
||||||
body_text_style,
|
body_text_style,
|
||||||
|
@ -371,9 +369,7 @@ impl Style {
|
||||||
|
|
||||||
impl Spacing {
|
impl Spacing {
|
||||||
pub fn ui(&mut self, ui: &mut crate::Ui) {
|
pub fn ui(&mut self, ui: &mut crate::Ui) {
|
||||||
if ui.button("Reset").clicked {
|
crate::reset_button(ui, self);
|
||||||
*self = Default::default();
|
|
||||||
}
|
|
||||||
|
|
||||||
let Self {
|
let Self {
|
||||||
item_spacing,
|
item_spacing,
|
||||||
|
@ -404,15 +400,12 @@ impl Spacing {
|
||||||
|
|
||||||
impl Interaction {
|
impl Interaction {
|
||||||
pub fn ui(&mut self, ui: &mut crate::Ui) {
|
pub fn ui(&mut self, ui: &mut crate::Ui) {
|
||||||
if ui.button("Reset").clicked {
|
crate::reset_button(ui, self);
|
||||||
*self = Default::default();
|
|
||||||
}
|
|
||||||
|
|
||||||
let Self {
|
let Self {
|
||||||
resize_grab_radius_side,
|
resize_grab_radius_side,
|
||||||
resize_grab_radius_corner,
|
resize_grab_radius_corner,
|
||||||
} = self;
|
} = 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_side, 0.0..=20.0).text("resize_grab_radius_side"));
|
||||||
ui.add(
|
ui.add(
|
||||||
Slider::f32(resize_grab_radius_corner, 0.0..=20.0).text("resize_grab_radius_corner"),
|
Slider::f32(resize_grab_radius_corner, 0.0..=20.0).text("resize_grab_radius_corner"),
|
||||||
|
@ -422,9 +415,7 @@ impl Interaction {
|
||||||
|
|
||||||
impl Widgets {
|
impl Widgets {
|
||||||
pub fn ui(&mut self, ui: &mut crate::Ui) {
|
pub fn ui(&mut self, ui: &mut crate::Ui) {
|
||||||
if ui.button("Reset").clicked {
|
crate::reset_button(ui, self);
|
||||||
*self = Default::default();
|
|
||||||
}
|
|
||||||
|
|
||||||
let Self {
|
let Self {
|
||||||
active,
|
active,
|
||||||
|
@ -471,9 +462,7 @@ impl WidgetVisuals {
|
||||||
|
|
||||||
impl Visuals {
|
impl Visuals {
|
||||||
pub fn ui(&mut self, ui: &mut crate::Ui) {
|
pub fn ui(&mut self, ui: &mut crate::Ui) {
|
||||||
if ui.button("Reset").clicked {
|
crate::reset_button(ui, self);
|
||||||
*self = Default::default();
|
|
||||||
}
|
|
||||||
|
|
||||||
let Self {
|
let Self {
|
||||||
override_text_color: _,
|
override_text_color: _,
|
||||||
|
|
|
@ -739,3 +739,14 @@ impl Widget for Separator {
|
||||||
response
|
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)]
|
#[serde(default)]
|
||||||
struct ColorWidgets {
|
struct ColorWidgets {
|
||||||
srgba_unmul: [u8; 4],
|
srgba_unmul: [u8; 4],
|
||||||
|
@ -129,9 +129,7 @@ impl Default for ColorWidgets {
|
||||||
|
|
||||||
impl ColorWidgets {
|
impl ColorWidgets {
|
||||||
fn ui(&mut self, ui: &mut Ui) {
|
fn ui(&mut self, ui: &mut Ui) {
|
||||||
if ui.button("Reset").clicked {
|
egui::reset_button(ui, self);
|
||||||
*self = Default::default();
|
|
||||||
}
|
|
||||||
|
|
||||||
ui.label("Egui lets you edit colors stored as either sRGBA or linear RGBA and with or without premultiplied alpha");
|
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;
|
use std::f64::INFINITY;
|
||||||
|
|
||||||
/// Showcase sliders
|
/// Showcase sliders
|
||||||
#[derive(serde::Deserialize, serde::Serialize)]
|
#[derive(PartialEq, serde::Deserialize, serde::Serialize)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct Sliders {
|
pub struct Sliders {
|
||||||
pub min: f64,
|
pub min: f64,
|
||||||
|
@ -108,8 +108,6 @@ impl Sliders {
|
||||||
ui.checkbox(smart_aim, "Smart Aim");
|
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");
|
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 {
|
egui::reset_button(ui, self);
|
||||||
*self = Default::default();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use egui::{containers::*, widgets::*, *};
|
use egui::{containers::*, widgets::*, *};
|
||||||
use std::f32::consts::TAU;
|
use std::f32::consts::TAU;
|
||||||
|
|
||||||
#[derive(serde::Deserialize, serde::Serialize)]
|
#[derive(PartialEq, serde::Deserialize, serde::Serialize)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct FractalClock {
|
pub struct FractalClock {
|
||||||
paused: bool,
|
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.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.luminance_factor, 0.0..=1.0).text("luminance factor"));
|
||||||
ui.add(Slider::f32(&mut self.width_factor, 0.0..=1.0).text("width 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(
|
ui.add(
|
||||||
Hyperlink::new("http://www.dqd.com/~mayoff/programs/FractalClock/")
|
Hyperlink::new("http://www.dqd.com/~mayoff/programs/FractalClock/")
|
||||||
|
|
Loading…
Reference in a new issue