Skip to content

Commit 4d4c75c

Browse files
committed
Fix vertical slider up/down keys and add a line in the changelog
Follow-up to #875
1 parent 491739b commit 4d4c75c

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

CHANGELOG.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ NOTE: [`epaint`](epaint/CHANGELOG.md), [`eframe`](eframe/CHANGELOG.md), [`egui_w
1313
* Most widgets containing text (`Label`, `Button` etc) now supports rich text ([#855](https://github.com/emilk/egui/pull/855)).
1414
* When using a custom font you can now specify a font index ([#873](https://github.com/emilk/egui/pull/873)).
1515
* You can now read the plot coordinates of the mouse when building a `Plot` ([#766](https://github.com/emilk/egui/pull/766)).
16+
* Add vertical sliders with `Slider::new(…).vertical()` ([#875](https://github.com/emilk/egui/pull/875)).
1617

1718
### Changed 🔧
1819
* 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
3132
* Removed `egui::paint` (use `egui::epaint` instead).
3233

3334
### Contributors 🙏
35+
* [5225225](https://github.com/5225225): ([#849](https://github.com/emilk/egui/pull/849)).
36+
* [B-Reif](https://github.com/B-Reif) ([#875](https://github.com/emilk/egui/pull/875)).
37+
* [EmbersArc](https://github.com/EmbersArc): ([#766](https://github.com/emilk/egui/pull/766)).
3438
* [mankinskin](https://github.com/mankinskin) ([#543](https://github.com/emilk/egui/pull/543))
3539
* [sumibi-yakitori](https://github.com/sumibi-yakitori) ([#830](https://github.com/emilk/egui/pull/830))
36-
* [5225225](https://github.com/5225225): ([#849](https://github.com/emilk/egui/pull/849)).
3740
* [t18b219k](https://github.com/t18b219k): ([#868](https://github.com/emilk/egui/pull/868)).
38-
* [EmbersArc](https://github.com/EmbersArc): ([#766](https://github.com/emilk/egui/pull/766)).
3941

4042

4143
## 0.15.0 - 2021-10-24 - Syntax highlighting and hscroll

egui/src/widgets/slider.rs

+9-16
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,15 @@ impl<'a> Slider<'a> {
315315
response.widget_info(|| WidgetInfo::slider(value, &self.text));
316316

317317
if response.has_focus() {
318-
let increment = ui.input().num_presses(self.key_increment());
319-
let decrement = ui.input().num_presses(self.key_decrement());
318+
let (dec_key, inc_key) = match self.orientation {
319+
SliderOrientation::Horizontal => (Key::ArrowLeft, Key::ArrowRight),
320+
// Note that this is for moving the slider position,
321+
// so up = decrement y coordinate:
322+
SliderOrientation::Vertical => (Key::ArrowUp, Key::ArrowDown),
323+
};
324+
325+
let decrement = ui.input().num_presses(dec_key);
326+
let increment = ui.input().num_presses(inc_key);
320327
let kb_step = increment as f32 - decrement as f32;
321328

322329
if kb_step != 0.0 {
@@ -394,20 +401,6 @@ impl<'a> Slider<'a> {
394401
}
395402
}
396403

397-
fn key_increment(&self) -> Key {
398-
match self.orientation {
399-
SliderOrientation::Horizontal => Key::ArrowRight,
400-
SliderOrientation::Vertical => Key::ArrowUp,
401-
}
402-
}
403-
404-
fn key_decrement(&self) -> Key {
405-
match self.orientation {
406-
SliderOrientation::Horizontal => Key::ArrowLeft,
407-
SliderOrientation::Vertical => Key::ArrowDown,
408-
}
409-
}
410-
411404
fn rail_rect(&self, rect: &Rect, radius: f32) -> Rect {
412405
match self.orientation {
413406
SliderOrientation::Horizontal => Rect::from_min_max(

egui_demo_lib/src/apps/demo/sliders.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,15 @@ impl super::View for Sliders {
132132
ui.label("Slider type:");
133133
ui.radio_value(integer, true, "i32");
134134
ui.radio_value(integer, false, "f64");
135-
});
135+
})
136+
.response
137+
.on_hover_text("All numeric types (f32, usize, …) are supported.");
138+
136139
ui.horizontal(|ui| {
137140
ui.label("Slider orientation:");
138141
ui.radio_value(vertical, false, "Horizontal");
139142
ui.radio_value(vertical, true, "Vertical");
140143
});
141-
ui.label("(f32, usize etc are also possible)");
142144
ui.add_space(8.0);
143145

144146
ui.checkbox(logarithmic, "Logarithmic");

0 commit comments

Comments
 (0)