diff --git a/crates/ui-egui/src/panels/tests_color_wheel_box.rs b/crates/ui-egui/src/panels/tests_color_wheel_box.rs index d3866fd5d9..0b59a44d98 100644 --- a/crates/ui-egui/src/panels/tests_color_wheel_box.rs +++ b/crates/ui-egui/src/panels/tests_color_wheel_box.rs @@ -235,6 +235,27 @@ fn with_a_none_fill_the_strip_reads_zero_and_its_actions_set_the_fill() { assert!(near(hsb(&fill(h.state())), [last[0], last[1], 0.25], 0.01), "{last:?} → {:?}", hsb(&fill(h.state()))); } +/// With None, a screen reader's set-value action or an increment at the top of the strip sets the +/// fill, even when the number equals the last solid color's. +#[test] +fn with_a_none_fill_the_strip_applies_an_action_that_leaves_its_number() { + let mut app = app(json!("#ff0000"), "brightness"); + app.run("paint.setFill", json!({"none": true})).unwrap(); + let mut h = harness(app); + let last = hsb(&h.state().session.last_solid); + assert!((last[2] - 1.0).abs() < 0.01, "{last:?}"); + for (action, data) in [(Action::SetValue, Some(ActionData::NumericValue(100.0))), (Action::Increment, None)] { + h.state_mut().run("paint.setFill", json!({"none": true})).unwrap(); + h.run_steps(1); + let (target_node, target_tree) = h.get_by_label("Brightness").accesskit_node().locate(); + h.event(Event::AccessKitActionRequest(ActionRequest { target_node, target_tree, action, data })); + h.run_steps(1); + let paint = crate::panels::current_paints(h.state()).0; + let c = paint.color().unwrap_or_else(|| panic!("{action:?} left the fill as {paint:?}")); + assert!(near(hsb(&c), last, 0.01), "{action:?}: {last:?} → {:?}", hsb(&c)); + } +} + /// `ui.colorWheel` answers every junk parameter without a panic. #[test] fn ui_color_wheel_answers_junk_params_without_a_panic() { diff --git a/crates/ui-egui/src/widgets/color.rs b/crates/ui-egui/src/widgets/color.rs index f7c1d9365b..535bb70b0a 100644 --- a/crates/ui-egui/src/widgets/color.rs +++ b/crates/ui-egui/src/widgets/color.rs @@ -141,7 +141,7 @@ pub fn color_slider_stepped( ) -> (Option, Live, Option) { let id = id_with(ui.scope_id(), id); let (resp, picked, phase) = color_rail(ui, id, name, shown.clone(), value, width, track); - let stepped = slider_keys(ui, &resp, shown); + let stepped = slider_keys(ui, &resp, shown, false); (picked, phase, stepped.filter(|_| picked.is_none())) } @@ -152,12 +152,13 @@ pub fn color_slider_stepped( /// `shown`'s units that a key or an action gives. pub fn stepped_area(ui: &Ui, resp: &Response, name: &str, shown: Option) -> Option { slider_info(ui, resp, name, shown.clone()); - slider_keys(ui, resp, shown) + slider_keys(ui, resp, shown, false) } /// The focus, keys, actions and focus outline of [`color_slider_stepped`] on the control `resp`: -/// the number a key or an action gives. -fn slider_keys(ui: &Ui, resp: &Response, shown: Option) -> Option { +/// the number a key or an action gives. With `always`, a key or an action that leaves the number +/// as it was still gives it. +fn slider_keys(ui: &Ui, resp: &Response, shown: Option, always: bool) -> Option { let id = resp.id; // Focus a click or a drag gave shows no outline until a key steps the rail: the outline tells // a keyboard user where the focus is, and after a drag it only framed the rail. @@ -177,7 +178,7 @@ fn slider_keys(ui: &Ui, resp: &Response, shown: Option) -> Option(by_pointer)); @@ -190,8 +191,9 @@ fn slider_keys(ui: &Ui, resp: &Response, shown: Option) -> Option Option { +/// readers' actions on it ([`color_slider_stepped`]); `None` when they leave it as it was, unless +/// `always` and a key or an action came. +fn rail_step(ui: &Ui, id: egui::Id, focused: bool, always: bool, s: &SliderValue) -> Option { use egui::accesskit::{Action, ActionData}; use egui::{Event, Key}; let (lo, hi) = (*s.range.start(), *s.range.end()); @@ -208,6 +210,8 @@ fn rail_step(ui: &Ui, id: egui::Id, focused: bool, s: &SliderValue) -> Option Option return true, } + asked = true; false }); }); @@ -246,8 +251,9 @@ fn rail_step(ui: &Ui, id: egui::Id, focused: bool, s: &SliderValue) -> Option 0; + v = by(v, up as f64 - down as f64).clamp(lo, hi); // The last set-value request this frame. let set = i.accesskit_action_requests(id, Action::SetValue).last().and_then(|request| match request.data { Some(ActionData::NumericValue(value)) if value.is_finite() => Some(value), @@ -260,9 +266,10 @@ fn rail_step(ui: &Ui, id: egui::Id, focused: bool, s: &SliderValue) -> Option