1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-02 23:00:04 -04:00

Slider: move by at least the next increment when using fixed_decimals (#7066)

fixes https://github.com/emilk/egui/issues/7065
This commit is contained in:
Lukas Rieger
2025-06-29 13:30:39 +02:00
committed by GitHub
parent ab9f55ab01
commit c943720eed
2 changed files with 61 additions and 3 deletions

View File

@@ -1,6 +1,8 @@
use egui::accesskit::Role;
use egui::accesskit::{self, Role};
use egui::{Button, ComboBox, Image, Vec2, Widget as _};
use egui_kittest::{kittest::Queryable as _, Harness, SnapshotResults};
#[cfg(all(feature = "wgpu", feature = "snapshot"))]
use egui_kittest::SnapshotResults;
use egui_kittest::{kittest::Queryable as _, Harness};
#[test]
pub fn focus_should_skip_over_disabled_buttons() {
@@ -89,6 +91,7 @@ fn test_combobox() {
harness.run();
#[cfg(all(feature = "wgpu", feature = "snapshot"))]
let mut results = SnapshotResults::new();
#[cfg(all(feature = "wgpu", feature = "snapshot"))]
@@ -112,3 +115,45 @@ fn test_combobox() {
// Popup should be closed now
assert!(harness.query_by_label("Item 2").is_none());
}
/// `https://github.com/emilk/egui/issues/7065`
#[test]
pub fn slider_should_move_with_fixed_decimals() {
let mut value: f32 = 1.0;
let mut harness = Harness::new_ui(|ui| {
// Movement on arrow-key is relative to slider width; make the slider wide so the movement becomes small.
ui.spacing_mut().slider_width = 2000.0;
ui.add(egui::Slider::new(&mut value, 0.1..=10.0).fixed_decimals(2));
});
harness.key_press(egui::Key::Tab);
harness.run();
let actual_slider = harness.get_by_role(accesskit::Role::SpinButton);
assert_eq!(actual_slider.value(), Some("1.00".to_owned()));
harness.key_press(egui::Key::ArrowRight);
harness.run();
let actual_slider = harness.get_by_role(accesskit::Role::SpinButton);
assert_eq!(actual_slider.value(), Some("1.01".to_owned()));
harness.key_press(egui::Key::ArrowRight);
harness.run();
let actual_slider = harness.get_by_role(accesskit::Role::SpinButton);
assert_eq!(actual_slider.value(), Some("1.02".to_owned()));
harness.key_press(egui::Key::ArrowLeft);
harness.run();
let actual_slider = harness.get_by_role(accesskit::Role::SpinButton);
assert_eq!(actual_slider.value(), Some("1.01".to_owned()));
harness.key_press(egui::Key::ArrowLeft);
harness.run();
let actual_slider = harness.get_by_role(accesskit::Role::SpinButton);
assert_eq!(actual_slider.value(), Some("1.00".to_owned()));
}