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 a17bbc5be2..d05b1885db 100644 --- a/crates/ui-egui/src/panels/tests_color_wheel_box.rs +++ b/crates/ui-egui/src/panels/tests_color_wheel_box.rs @@ -242,20 +242,25 @@ 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 equal to the last solid color's own number still sets -/// the fill. +/// 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_a_set_value_equal_to_the_hidden_number_sets_the_fill() { +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:?}"); - let (target_node, target_tree) = h.get_by_label("Brightness").accesskit_node().locate(); - let data = Some(ActionData::NumericValue(100.0)); - h.event(Event::AccessKitActionRequest(ActionRequest { target_node, target_tree, action: Action::SetValue, data })); - h.run_steps(1); - assert!(near(hsb(&fill(h.state())), last, 0.01), "{last:?} → {:?}", crate::panels::current_paints(h.state()).0); + 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. diff --git a/crates/ui-egui/src/widgets/color.rs b/crates/ui-egui/src/widgets/color.rs index d997ccd428..a89bff04ee 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())) } @@ -173,7 +173,7 @@ pub fn opacity_slider( ramp.add_triangle(0, 2, 3); shapes.push(egui::Shape::mesh(ramp)); ui.painter().set(under, egui::Shape::Vec(shapes)); - let stepped = slider_keys(ui, &resp, shown); + let stepped = slider_keys(ui, &resp, shown, false); (picked, phase, stepped.filter(|_| picked.is_none())) } @@ -184,12 +184,13 @@ pub fn opacity_slider( /// `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. @@ -209,7 +210,7 @@ fn slider_keys(ui: &Ui, resp: &Response, shown: Option) -> Option(by_pointer)); @@ -222,8 +223,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()); @@ -240,6 +242,8 @@ fn rail_step(ui: &Ui, id: egui::Id, focused: bool, s: &SliderValue) -> Option Option return true, } + asked = true; false }); }); @@ -278,8 +283,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), @@ -292,9 +298,10 @@ fn rail_step(ui: &Ui, id: egui::Id, focused: bool, s: &SliderValue) -> Option Color32, ) -> (Option, Live, Option) { - use egui::accesskit::{Action, ActionData}; let id = id_with(ui.scope_id(), id); let read = if marked { shown.clone() } else { shown.as_ref().map(|s| SliderValue { value: 0.0, text: None, ..s.clone() }) }; let (resp, picked, phase) = channel_rail(ui, id, name, read, value, marked, size, track); - let unmarked = shown.as_ref().filter(|_| !marked && ui.is_enabled()).map(|s| s.value); - let mut stepped = slider_keys(ui, &resp, shown); - // Without a marker there is no color yet, so a set value applies even when it leaves the number - // as it was. - if stepped.is_none() - && let Some(v) = unmarked - && ui.input(|i| { - i.accesskit_action_requests(resp.id, Action::SetValue).any(|r| matches!(r.data, Some(ActionData::NumericValue(n)) if n.is_finite())) - }) - { - stepped = Some(v); - } + let stepped = slider_keys(ui, &resp, shown, !marked); (picked, phase, stepped.filter(|_| picked.is_none())) }