Hue/Saturation range bar: narrow zones stay selectable

CodeRabbit (discussion_r4369183389): at the narrowest Properties panel
the bar is about 230 points, a 30° zone is ~19 points, and every press
in it fell within the fixed 10-point handle reach, so no zone could be
dragged. A handle's reach toward a neighbour is now a third of the gap
(3 to 10 points), leaving the middle third of a narrow zone to the zone;
an open side keeps the full 10 points.

Test: hue_range_zones_stay_selectable_on_a_narrow_bar.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Hector VillarrealandClaude Opus 5.5 committed 2026-11-05 22:53:19 -06:00
1 parent aec8579000
commit f2dcbee218
2 files changed
+34 -2

No files matched your search

+18 -1
View File
@@ -45,7 +45,7 @@ use gradient_map::gradient_map;
pub use gradient_map::{gradient_presets, is_gray, swatches};
use hue_saturation::hue_saturation;
#[cfg(test)]
use hue_saturation::{hue_range_zone, lightness_track, move_hue_range_handle, move_hue_range_zone, saturation_track};
use hue_saturation::{hue_range_handle_at, hue_range_zone, lightness_track, move_hue_range_handle, move_hue_range_zone, saturation_track};
use levels::levels;
pub use levels::{auto_levels, gamma_from_pos, gamma_pos};
pub use session::{layer_editor, layer_mem, properties_coalesce, properties_reset, session_start};
@@ -264,6 +264,23 @@ mod tests {
/// #9252: Photoshop 2025's zone drags on a colour range (measured on Reds): the fully-on span
/// moves all four handles, each fade its own two; a side stops at the other and the range
/// never passes a turn.
/// #9272 review: at the narrowest Properties panel (a 230-point bar) a 30° zone is ~19 points
/// wide; a press in its middle grabs the zone, not a handle, while each handle stays grabbable.
#[test]
fn hue_range_zones_stay_selectable_on_a_narrow_bar() {
let w = 230.0;
let xs = [75.0f32, 105.0, 135.0, 165.0].map(|d| d / 360.0 * w);
for (a, z) in [(0, 1), (1, 2), (2, 3)] {
assert_eq!(hue_range_handle_at(xs, (xs[a] + xs[z]) / 2.0), None, "the middle of zone {a}..{z} is the zone's");
}
for (k, x) in xs.iter().enumerate() {
assert_eq!(hue_range_handle_at(xs, *x + 1.0), Some(k as u8), "handle {k}");
}
assert_eq!(hue_range_handle_at(xs, xs[0] - 9.0), Some(0), "the full reach outside the range");
let stacked = [50.0, 50.0, 80.0, 120.0];
assert!(hue_range_handle_at(stacked, 51.0).is_some(), "coinciding handles stay grabbable");
}
#[test]
fn hue_range_zones_move_their_handles() {
let reds = [-45.0, -15.0, 15.0, 45.0];
@@ -38,6 +38,21 @@ pub(super) fn move_hue_range_handle(bounds: [f32; 4], k: usize, deg: f32) -> [f3
b
}
/// The range handle a press at `x` grabs, given the four handles' x positions: the nearest
/// within 10 points, or within a third of the gap to the next handle on that side, so the middle
/// third of a narrow zone still drags the zone (at least 3 points, for handles that coincide).
pub(super) fn hue_range_handle_at(xs: [f32; 4], x: f32) -> Option<u8> {
let k = nearest(&xs, x)?;
let d = x - xs[k as usize];
let gap = xs
.iter()
.enumerate()
.filter(|&(j, &o)| j != k as usize && (o - xs[k as usize]) * d.signum() >= 0.0)
.map(|(_, &o)| (o - xs[k as usize]).abs())
.fold(f32::INFINITY, f32::min);
(d.abs() < (gap / 3.0).clamp(3.0, 10.0)).then_some(k)
}
/// Which zone of a colour range a hue `deg` falls in, between its handles: 0 = the left fade
/// (between the first two), 1 = the fully-on span, 2 = the right fade; `None` outside the range.
pub(super) fn hue_range_zone(bounds: [f32; 4], deg: f32) -> Option<u8> {
@@ -227,7 +242,7 @@ pub(super) fn hue_saturation(ui: &mut egui::Ui, v: &mut Value, cx: &EditorCx) ->
&& ui.input(|i| i.pointer.primary_pressed())
&& let Some(pos) = ui.input(|i| i.pointer.press_origin())
{
which = nearest(&b.map(xof), pos.x).filter(|k| (xof(b[*k as usize]) - pos.x).abs() < 10.0);
which = hue_range_handle_at(b.map(xof), pos.x);
zone = if which.is_none() { hue_range_zone(b, deg_of(pos.x)).map(|z| (z, b, pos.x)) } else { None };
}
if bresp.is_pointer_button_down_on()