From 4d4c75c6f117ab27eda4002e2e04cf944d7c0761 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sat, 13 Nov 2021 12:30:13 +0100 Subject: [PATCH] Fix vertical slider up/down keys and add a line in the changelog Follow-up to https://github.com/emilk/egui/pull/875 --- CHANGELOG.md | 6 ++++-- egui/src/widgets/slider.rs | 25 +++++++++---------------- egui_demo_lib/src/apps/demo/sliders.rs | 6 ++++-- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab36d46582c..cc58154be1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ NOTE: [`epaint`](epaint/CHANGELOG.md), [`eframe`](eframe/CHANGELOG.md), [`egui_w * Most widgets containing text (`Label`, `Button` etc) now supports rich text ([#855](https://github.com/emilk/egui/pull/855)). * When using a custom font you can now specify a font index ([#873](https://github.com/emilk/egui/pull/873)). * You can now read the plot coordinates of the mouse when building a `Plot` ([#766](https://github.com/emilk/egui/pull/766)). +* Add vertical sliders with `Slider::new(…).vertical()` ([#875](https://github.com/emilk/egui/pull/875)). ### Changed 🔧 * Unifiy the four `Memory` data buckets (`data`, `data_temp`, `id_data` and `id_data_temp`) into a single `Memory::data`, with a new interface ([#836](https://github.com/emilk/egui/pull/836)). @@ -31,11 +32,12 @@ NOTE: [`epaint`](epaint/CHANGELOG.md), [`eframe`](eframe/CHANGELOG.md), [`egui_w * Removed `egui::paint` (use `egui::epaint` instead). ### Contributors 🙏 +* [5225225](https://github.com/5225225): ([#849](https://github.com/emilk/egui/pull/849)). +* [B-Reif](https://github.com/B-Reif) ([#875](https://github.com/emilk/egui/pull/875)). +* [EmbersArc](https://github.com/EmbersArc): ([#766](https://github.com/emilk/egui/pull/766)). * [mankinskin](https://github.com/mankinskin) ([#543](https://github.com/emilk/egui/pull/543)) * [sumibi-yakitori](https://github.com/sumibi-yakitori) ([#830](https://github.com/emilk/egui/pull/830)) -* [5225225](https://github.com/5225225): ([#849](https://github.com/emilk/egui/pull/849)). * [t18b219k](https://github.com/t18b219k): ([#868](https://github.com/emilk/egui/pull/868)). -* [EmbersArc](https://github.com/EmbersArc): ([#766](https://github.com/emilk/egui/pull/766)). ## 0.15.0 - 2021-10-24 - Syntax highlighting and hscroll diff --git a/egui/src/widgets/slider.rs b/egui/src/widgets/slider.rs index 5c93bd74146..5f38a68c361 100644 --- a/egui/src/widgets/slider.rs +++ b/egui/src/widgets/slider.rs @@ -315,8 +315,15 @@ impl<'a> Slider<'a> { response.widget_info(|| WidgetInfo::slider(value, &self.text)); if response.has_focus() { - let increment = ui.input().num_presses(self.key_increment()); - let decrement = ui.input().num_presses(self.key_decrement()); + let (dec_key, inc_key) = match self.orientation { + SliderOrientation::Horizontal => (Key::ArrowLeft, Key::ArrowRight), + // Note that this is for moving the slider position, + // so up = decrement y coordinate: + SliderOrientation::Vertical => (Key::ArrowUp, Key::ArrowDown), + }; + + let decrement = ui.input().num_presses(dec_key); + let increment = ui.input().num_presses(inc_key); let kb_step = increment as f32 - decrement as f32; if kb_step != 0.0 { @@ -394,20 +401,6 @@ impl<'a> Slider<'a> { } } - fn key_increment(&self) -> Key { - match self.orientation { - SliderOrientation::Horizontal => Key::ArrowRight, - SliderOrientation::Vertical => Key::ArrowUp, - } - } - - fn key_decrement(&self) -> Key { - match self.orientation { - SliderOrientation::Horizontal => Key::ArrowLeft, - SliderOrientation::Vertical => Key::ArrowDown, - } - } - fn rail_rect(&self, rect: &Rect, radius: f32) -> Rect { match self.orientation { SliderOrientation::Horizontal => Rect::from_min_max( diff --git a/egui_demo_lib/src/apps/demo/sliders.rs b/egui_demo_lib/src/apps/demo/sliders.rs index 1cf0f33dfd5..24da825b474 100644 --- a/egui_demo_lib/src/apps/demo/sliders.rs +++ b/egui_demo_lib/src/apps/demo/sliders.rs @@ -132,13 +132,15 @@ impl super::View for Sliders { ui.label("Slider type:"); ui.radio_value(integer, true, "i32"); ui.radio_value(integer, false, "f64"); - }); + }) + .response + .on_hover_text("All numeric types (f32, usize, …) are supported."); + ui.horizontal(|ui| { ui.label("Slider orientation:"); ui.radio_value(vertical, false, "Horizontal"); ui.radio_value(vertical, true, "Vertical"); }); - ui.label("(f32, usize etc are also possible)"); ui.add_space(8.0); ui.checkbox(logarithmic, "Logarithmic");