Gradient panel: a picked midpoint stays with the gradient it was picked on

The Gradient panel kept a selected midpoint diamond for the first selected
object only. With that object still selected, choosing the Live Paint
Bucket or toggling to the Stroke proxy left the diamond selected on the
gradient the panel showed then, and the Location field edited that
gradient's midpoint although nobody picked it.

The diamond is now kept for the same owner a selected stop is kept for
(document, object, proxy, Appearance row, symbol part and the bucket),
through the new `Session::gradient_owner`.
This commit is contained in:
dotCooCoo committed 2026-11-20 21:20:58 -08:00
1 parent 9fff48d88f
commit 17554f2a91
4 files changed
+44 -13

No files matched your search

+8 -2
View File
@@ -87,9 +87,10 @@ fn select_stop(s: &mut Session, p: &Value) -> Result<Value> {
/// front, the Appearance panel's active item and whether the Live Paint Bucket is the active tool
/// (its proxies show the default paint). Selecting other art, picking a part of the instance,
/// toggling the proxy, picking another item or choosing the bucket or leaving it leaves no stop
/// selected.
/// selected. The Gradient panel keys its selected midpoint diamond by it as well
/// ([`Session::gradient_owner`]).
#[derive(Clone, Copy, Debug, PartialEq)]
pub(crate) struct StopOwner {
pub struct StopOwner {
doc: Option<usize>,
object: Option<NodeId>,
/// The object whose paint the active proxy shows: a Live Paint group without faces (or edges)
@@ -134,6 +135,11 @@ impl Session {
pub fn selected_stop(&self) -> Option<usize> {
self.gradient_stop.filter(|(_, owner)| *owner == StopOwner::of(self)).map(|(i, _)| i)
}
/// Whose gradient the active proxy shows now, as a selected stop keeps it ([`StopOwner`]).
pub fn gradient_owner(&self) -> StopOwner {
StopOwner::of(self)
}
}
type Parsed<T> = std::result::Result<T, String>;
+1
View File
@@ -30,6 +30,7 @@ pub use cmd::clipboard::{Clipboard, SourceLayer};
pub use cmd::create::constrain_click;
pub use cmd::distortcmds::{perspective_click, width_point_pair};
pub use cmd::flare::flare_settings;
pub use cmd::gradient::StopOwner;
pub use cmd::graph::{GraphTypeSubject, calculated_axes as graph_calculated_axes, graph_type_subject};
pub use cmd::params::{check_keys, check_params};
pub use cmd::pathops::auto_simplify_level;
+8 -11
View File
@@ -31,7 +31,8 @@ use vectorcraft_color::gradient::{
MAX_REPEATS, MIN_STOPS, duplicate_stop, insert_stop, midpoint_from_pos, midpoint_pos, move_stop, remove_stop, set_midpoint, swap_stop_colors,
};
use vectorcraft_color::{Color, Freeform, FreeformMode, Gradient, GradientKind, GradientMethod, GradientPaint, GradientSpread, GradientStop, Paint};
use vectorcraft_doc::{NodeId, StrokeGradientMode};
use vectorcraft_doc::StrokeGradientMode;
use vectorcraft_engine::StopOwner;
use super::{active_paint, live_run, pstate, set_pstate};
use crate::state::Dialog;
@@ -231,15 +232,11 @@ fn gradient_swatches(app: &VectorcraftApp) -> Vec<(String, GradientPaint)> {
.collect()
}
/// The selected midpoint diamond: kept for the object it was picked on, and given up when a stop
/// is selected.
/// The selected midpoint diamond: kept for the gradient it was picked on, as a selected stop is
/// ([`vectorcraft_engine::Session::gradient_owner`]), and given up when a stop is selected.
fn selected_mid(app: &VectorcraftApp, ctx: &egui::Context, stops: usize) -> Option<usize> {
let (i, owner) = pstate::<Option<(usize, Option<NodeId>)>>(ctx, MID_SELECTED)?;
(app.session.selected_stop().is_none() && i + 1 < stops && owner == first_id(app)).then_some(i)
}
fn first_id(app: &VectorcraftApp) -> Option<NodeId> {
app.session.active().and_then(|d| d.selection.objects.first().copied())
let (i, owner) = pstate::<Option<(usize, StopOwner)>>(ctx, MID_SELECTED)?;
(app.session.selected_stop().is_none() && i + 1 < stops && owner == app.session.gradient_owner()).then_some(i)
}
// ---------- UI ----------
@@ -935,12 +932,12 @@ fn apply_ramp_edit(
popover: Option<(usize, Pos2)>,
) {
if let Some(i) = pick_mid {
set_pstate(ui.ctx(), MID_SELECTED, Some((i, first_id(app))));
set_pstate(ui.ctx(), MID_SELECTED, Some((i, app.session.gradient_owner())));
if sel.is_some() {
select_stop(app, None);
}
} else if select.is_some() {
set_pstate(ui.ctx(), MID_SELECTED, None::<(usize, Option<NodeId>)>);
set_pstate(ui.ctx(), MID_SELECTED, None::<(usize, StopOwner)>);
}
match changed {
// Stops added, moved or dropped on the ramp carry colors the gradient or a swatch has, or
@@ -1,4 +1,5 @@
use egui::{Event, Modifiers, PointerButton};
use vectorcraft_doc::NodeId;
use vectorcraft_engine::Session;
use super::super::tests_long_popups::{PopupWindow, assert_last_row_scrolls_into_view, assert_short_list_does_not_scroll};
@@ -417,6 +418,32 @@ fn a_selected_diamond_shows_and_sets_its_midpoint_in_location() {
assert!(texts.iter().any(|(t, _)| t == "0%"));
}
/// A diamond picked on the selected object's gradient is not selected on another gradient the
/// panel shows with that object still selected: the Live Paint Bucket's, or the stroke's after the
/// proxy toggles. Going back to the object's fill selects it again.
#[test]
fn a_picked_diamond_stays_with_the_gradient_it_was_picked_on() {
let stops = json!([{"offset": 0, "color": "#ffffff", "midpoint": 0.3}, {"offset": 1, "color": "#000000"}]);
let mut app = app(json!({"gradient": {"stops": stops}}));
app.run("paint.setStroke", json!({"gradient": {"kind": "radial"}})).unwrap();
app.session.fill_active = true;
let mut p = Panel::new();
p.frame(&mut app, vec![], Modifiers::NONE);
let diamond = p.widget(("grad-mid", 0_usize));
p.click(&mut app, diamond.center());
assert_eq!(selected_mid(&app, &p.ctx, 2), Some(0), "the diamond is picked");
app.select_tool("livePaintBucket");
app.run("paint.setFill", json!({"gradient": {"kind": "radial"}})).unwrap();
p.frame(&mut app, vec![], Modifiers::NONE);
assert_eq!(selected_mid(&app, &p.ctx, 2), None, "the bucket's gradient");
app.select_tool("selection");
p.frame(&mut app, vec![], Modifiers::NONE);
assert_eq!(selected_mid(&app, &p.ctx, 2), Some(0), "the object's fill again");
app.session.fill_active = false;
p.frame(&mut app, vec![], Modifiers::NONE);
assert_eq!(selected_mid(&app, &p.ctx, 2), None, "the object's stroke");
}
/// A mirrored conic's Aspect Ratio field shows the extent's size, and a typed value keeps the
/// sweep mirrored.
#[test]