fill: a double-clicked gradient stop's colour menu stays open

The menu hung from a point under the marker, so the press of the double click that
opened it counted as a press outside and closed it in the same pass. It now hangs
from the marker's rect, which the outside rule leaves out.

Restores panels::fillui::tests::double_clicking_a_stop_opens_its_color_menu.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Dylan M. Taylor
2026-11-28 20:38:56 +00:00
co-authored by Claude Opus 5.5
parent f4761dc706
commit dbeef34c33
+57 -5
View File
@@ -7,6 +7,7 @@ use craft::color_ui::ui::gradient::GradientEditor;
use craft::i18n::Word;
use craft::theme::Srgba;
use craft::ui::choice::Segmented;
use craft::ui::contract::overlay::Anchor;
use craft::ui::contract::{Bind, Entry, Props as _, Show as _, ShowContainer as _};
use craft::ui::form::Field;
use craft::ui::list::ThumbAspect;
@@ -280,7 +281,7 @@ pub(crate) fn gradient_editor(app: &mut crate::SlideApp, ui: &mut Ui, label: &st
if let Some(request) = editor.color_requested
&& let Some(rect) = request.rect
{
app.fill_editor.stop = Some((request.index, rect.left_bottom()));
app.fill_editor.stop = Some((request.index, rect));
}
stop_menu(app, ui, label, g, &mut out);
out.filter(|edited| edited != g)
@@ -458,10 +459,11 @@ pub(crate) fn pattern_editor(app: &mut crate::SlideApp, ui: &mut Ui, p: &Pattern
out.filter(|pattern| pattern != pt)
}
/// The open stop-colour popover; delayed samples carry their target in their answer key.
/// The open stop-colour popover: the stop and its marker's rect, which the popover hangs from. Delayed samples carry
/// their target in their answer key.
#[derive(Default)]
pub struct FillEditorState {
stop: Option<(usize, egui::Pos2)>,
stop: Option<(usize, Rect)>,
}
/// Converts a gradient to framework stops.
@@ -522,14 +524,15 @@ fn stop_menu(app: &mut crate::SlideApp, ui: &mut Ui, label: &str, g: &Gradient,
}
}
let open = app.fill_editor.stop;
if let Some((i, point)) = open {
if let Some((i, marker)) = open {
let Some(key) = keys.get(i) else {
app.fill_editor.stop = None;
return;
};
// Hung from the marker, so the press of the double click that opened it is not a press outside.
let mut menu = Popover::new(Word::plain("Stop color"), Bind::given(open.is_some()))
.id_salt(label)
.at_point(point)
.overlay(|overlay| overlay.anchor(Anchor::Rect(marker)))
.show(ui, |ui, cx| color_menu(app, ui, cx, key, None));
let picked = menu.settle(|_, value| value.take()).flatten();
if let Some(Some(color)) = picked {
@@ -551,6 +554,55 @@ fn recolor_stop(out: &mut Option<Gradient>, g: &Gradient, i: usize, color: Color
#[cfg(test)]
mod tests {
use super::*;
use egui::accesskit::Role;
use egui_kittest::Harness;
use egui_kittest::kittest::Queryable;
fn selected_gradient(h: &Harness<'_, crate::SlideApp>) -> Gradient {
let shapes = h.state().session.active().unwrap().selected_shapes();
let Some(deckcraft_model::Fill::Gradient(g)) = shapes[0].fill.clone() else { panic!("the shape keeps a gradient fill") };
g
}
/// #2175: double-clicking a gradient stop selects it and opens its colour menu; a colour picked there colours that
/// stop.
#[test]
fn double_clicking_a_stop_opens_its_color_menu() {
let mut session = deckcraft_engine::Session::with_new();
session.execute("slide.new", &json!({"layout": "blank"})).unwrap();
let id = session.execute("shape.insert", &json!({"preset": "rect", "rect": [40.0, 40.0, 120.0, 80.0]})).unwrap()["id"].clone();
session.execute("edit.select", &json!({"ids": [id]})).unwrap();
session.execute("shape.fill", &json!({"gradient": {"stops": [[0, "accent1"], [1, "accent2"]], "angle": 90}})).unwrap();
let mut h = crate::test_harness::harness_with(
session,
crate::Services::default(),
Harness::builder().with_size(vec2(1800.0, 1500.0)).with_step_dt(1.0 / 60.0),
|_| {},
);
h.state_mut().ui.pane = Some("format".into());
h.state_mut().ui.format_tab = "fill".into();
h.run_steps(3);
let before = selected_gradient(&h);
assert!(h.query_by_label("Theme Colors").is_none(), "the menu starts closed");
let stop = h.get_by_role_and_label(Role::GraphicsObject, "Color stop 2 of 2").rect().center();
h.hover_at(stop);
h.run_steps(1);
for _ in 0..2 {
for pressed in [true, false] {
h.event(egui::Event::PointerButton { pos: stop, button: egui::PointerButton::Primary, pressed, modifiers: egui::Modifiers::NONE });
h.run_steps(1);
}
}
h.run_steps(2);
assert!(h.query_by_label("Theme Colors").is_some(), "the colour menu opened");
h.get_by_label(SchemeSlot::Accent6.label()).click();
h.run_steps(2);
let after = selected_gradient(&h);
assert_eq!(after.stops.len(), before.stops.len(), "no stop was added");
assert_ne!(after.stops[1].color, before.stops[1].color, "the double-clicked stop took the colour");
assert_eq!(after.stops[1].color, ColorRef::scheme(SchemeSlot::Accent6));
assert_eq!(after.stops[0].color, before.stops[0].color, "the other stop keeps its colour");
}
#[test]
fn gradient_json_retains_flip_mode() {