mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
The Layers panel blend-mode list previews the hovered mode, but egui's item spacing leaves a gap between rows that hovers no row, so moving the pointer down the list flashed the layer's current mode back at every gap. While the pointer is over the open list and between rows, report the nearest row as hovered, so the preview moves straight from one mode to the next. Co-authored-by: Fabio Lussi <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2 files changed
+34
No files matched your search
@@ -104,3 +104,23 @@ fn hovering_the_layers_panel_blend_list_previews_and_a_click_commits() {
|
||||
assert_eq!(steps(h.state()), undo + 1, "choosing records one step");
|
||||
assert_eq!(previewed(&mut h), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn moving_between_modes_keeps_a_preview_across_the_gaps_between_them() {
|
||||
// #2553: the pointer between two rows used to hover neither, flashing the document back.
|
||||
let (s, _) = session();
|
||||
let mut h = harness(s);
|
||||
let dropdown = h.query_all_by_role(Role::ComboBox).map(|n| n.rect()).max_by(|a, b| a.top().total_cmp(&b.top())).unwrap();
|
||||
click(&mut h, dropdown.center());
|
||||
let (dissolve, darken) = (h.get_by_label("Dissolve").rect(), h.get_by_label("Darken").rect());
|
||||
assert!(darken.top() > dissolve.bottom(), "the rows have a gap between them");
|
||||
let multiply = h.get_by_label("Multiply").rect().center();
|
||||
let mut y = dissolve.center().y;
|
||||
while y <= multiply.y {
|
||||
h.hover_at(Pos2::new(multiply.x, y));
|
||||
h.run_steps(1);
|
||||
assert!(previewed(&mut h).is_some(), "a mode previews at y = {y}");
|
||||
y += 0.5;
|
||||
}
|
||||
assert_eq!(previewed(&mut h), Some(BlendMode::Multiply));
|
||||
}
|
||||
@@ -939,6 +939,9 @@ fn dropdown_with<T: PartialEq + Clone>(ui: &mut Ui, id: &str, current: &mut T, o
|
||||
reveal |= wheeled;
|
||||
chosen.extend(stepped);
|
||||
}
|
||||
// The row nearest the pointer, by its distance to each row.
|
||||
let pointer = ui.ctx().pointer_hover_pos().filter(|_| ui.rect_contains_pointer(ui.clip_rect()));
|
||||
let mut nearest: Option<(f32, &T)> = None;
|
||||
for (v, l) in options {
|
||||
let item = ui.selectable_label(v == current, tl!(l));
|
||||
if reveal && v == current {
|
||||
@@ -947,11 +950,22 @@ fn dropdown_with<T: PartialEq + Clone>(ui: &mut Ui, id: &str, current: &mut T, o
|
||||
if item.hovered() {
|
||||
hovered = Some(v.clone());
|
||||
}
|
||||
if let Some(p) = pointer {
|
||||
let d = (item.rect.top() - p.y).max(p.y - item.rect.bottom()).max(0.0);
|
||||
if nearest.is_none_or(|(n, _)| d < n) {
|
||||
nearest = Some((d, v));
|
||||
}
|
||||
}
|
||||
if item.clicked() {
|
||||
*current = v.clone();
|
||||
chosen.push(v.clone());
|
||||
}
|
||||
}
|
||||
// Between two rows (item spacing) the pointer hovers neither; it is still over the list,
|
||||
// so keep previewing the nearest row instead of flashing the current value back (#2553).
|
||||
if hovered.is_none() {
|
||||
hovered = nearest.map(|(_, v)| v.clone());
|
||||
}
|
||||
});
|
||||
if combo_box_arrow_keys(ui, &response.response, current, options) {
|
||||
chosen.push(current.clone());
|
||||
|
||||
Reference in new issue
Block a user