Skip to content

Commit

Permalink
Fix vertical slider up/down keys and add a line in the changelog
Browse files Browse the repository at this point in the history
Follow-up to #875
  • Loading branch information
emilk committed Nov 13, 2021
1 parent 491739b commit 4d4c75c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)).
Expand All @@ -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
Expand Down
25 changes: 9 additions & 16 deletions egui/src/widgets/slider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(
Expand Down
6 changes: 4 additions & 2 deletions egui_demo_lib/src/apps/demo/sliders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 4d4c75c

Please sign in to comment.