[demo] Move slider demo to own window

This commit is contained in:
Emil Ernerfeldt 2021-01-25 20:14:39 +01:00
parent 6d57a24f35
commit 5e3a89bf00
4 changed files with 34 additions and 34 deletions

View file

@ -14,6 +14,7 @@ impl Default for Demos {
fn default() -> Self { fn default() -> Self {
let demos: Vec<Box<dyn super::Demo>> = vec![ let demos: Vec<Box<dyn super::Demo>> = vec![
Box::new(super::WidgetGallery::default()), Box::new(super::WidgetGallery::default()),
Box::new(super::sliders::Sliders::default()),
Box::new(super::input_test::InputTest::default()), Box::new(super::input_test::InputTest::default()),
Box::new(super::FontBook::default()), Box::new(super::FontBook::default()),
Box::new(super::Painting::default()), Box::new(super::Painting::default()),

View file

@ -15,7 +15,7 @@ pub mod font_contents_ubuntu;
pub mod input_test; pub mod input_test;
mod painting; mod painting;
mod scrolls; mod scrolls;
mod sliders; pub mod sliders;
mod tests; mod tests;
pub mod toggle_switch; pub mod toggle_switch;
mod widget_gallery; mod widget_gallery;

View file

@ -29,8 +29,24 @@ impl Default for Sliders {
} }
} }
impl Sliders { impl super::Demo for Sliders {
pub fn ui(&mut self, ui: &mut Ui) { fn name(&self) -> &str {
"⬌ Sliders"
}
fn show(&mut self, ctx: &egui::CtxRef, open: &mut bool) {
egui::Window::new(self.name())
.open(open)
.resizable(false)
.show(ctx, |ui| {
use super::View;
self.ui(ui);
});
}
}
impl super::View for Sliders {
fn ui(&mut self, ui: &mut Ui) {
let Self { let Self {
min, min,
max, max,
@ -84,7 +100,7 @@ impl Sliders {
} }
ui.separator(); ui.separator();
ui.label("Demo slider range:"); ui.label("Slider range:");
ui.add( ui.add(
Slider::f64(min, full_range.clone()) Slider::f64(min, full_range.clone())
.logarithmic(true) .logarithmic(true)

View file

@ -20,7 +20,6 @@ pub struct Widgets {
button_enabled: bool, button_enabled: bool,
count: usize, count: usize,
radio: Enum, radio: Enum,
sliders: super::Sliders,
angle: f32, angle: f32,
color: Color32, color: Color32,
single_line_text_input: String, single_line_text_input: String,
@ -34,7 +33,6 @@ impl Default for Widgets {
button_enabled: true, button_enabled: true,
radio: Enum::First, radio: Enum::First,
count: 0, count: 0,
sliders: Default::default(),
angle: std::f32::consts::TAU / 3.0, angle: std::f32::consts::TAU / 3.0,
color: (Rgba::from_rgb(0.0, 1.0, 0.5) * 0.75).into(), color: (Rgba::from_rgb(0.0, 1.0, 0.5) * 0.75).into(),
single_line_text_input: "Hello World!".to_owned(), single_line_text_input: "Hello World!".to_owned(),
@ -79,6 +77,9 @@ impl Widgets {
ui.label("Tooltips can be more than just simple text.") ui.label("Tooltips can be more than just simple text.")
.on_hover_ui(tooltip_ui); .on_hover_ui(tooltip_ui);
egui::Frame::group(ui.style()).show(ui, |ui| {
ui.label("This is a group of widgets");
ui.horizontal(|ui| { ui.horizontal(|ui| {
ui.radio_value(&mut self.radio, Enum::First, "First"); ui.radio_value(&mut self.radio, Enum::First, "First");
ui.radio_value(&mut self.radio, Enum::Second, "Second"); ui.radio_value(&mut self.radio, Enum::Second, "Second");
@ -90,6 +91,7 @@ impl Widgets {
ui.selectable_value(&mut self.radio, Enum::Second, "Second"); ui.selectable_value(&mut self.radio, Enum::Second, "Second");
ui.selectable_value(&mut self.radio, Enum::Third, "Third"); ui.selectable_value(&mut self.radio, Enum::Third, "Third");
}); });
});
ui.checkbox(&mut self.button_enabled, "Button enabled"); ui.checkbox(&mut self.button_enabled, "Button enabled");
@ -104,25 +106,6 @@ impl Widgets {
ui.label(format!("The button has been clicked {} times.", self.count)); ui.label(format!("The button has been clicked {} times.", self.count));
}); });
egui::Frame::group(ui.style()).show(ui, |ui| {
ui.horizontal(|ui| {
ui.label("Drag this value to change it:");
ui.add(DragValue::f64(&mut self.sliders.value).speed(0.01));
});
ui.add(
egui::Slider::f64(&mut self.sliders.value, 1.0..=100.0)
.logarithmic(true)
.text("A slider"),
);
egui::CollapsingHeader::new("More sliders")
.default_open(false)
.show(ui, |ui| {
self.sliders.ui(ui);
});
});
ui.separator(); ui.separator();
ui.horizontal_for_text(TextStyle::Body, |ui| { ui.horizontal_for_text(TextStyle::Body, |ui| {