Shapes: the toolbar's gradient swatches open the Gradient Editor (#612)

With Fill or Stroke set to Linear or Radial Gradient, clicking its
toolbar swatch opened Fill / Stroke Options, so the gradient's colours
couldn't be edited from the toolbar as in After Effects (reported on
Discord, EffectCraft 0.8.0 on Windows 11). The swatch now opens the
Gradient Editor (prop.editGradient) on the selected shape layer's first
Gradient Fill or Gradient Stroke Colors, in contents order through nested
groups; OK sets that property. With no shape layer selected, or none
with that gradient, the swatch opens the options as before (the kind new
shapes get: the toolbar keeps no gradient stops of its own yet). The
words still open the options, a Solid Color swatch the colour picker,
and Alt-click still steps through the kinds.

Tests (ui_toolbar_gradient): a Linear Fill swatch opens the editor on the
layer's Gradient Fill Colors and OK saves an added stop; a Radial Stroke
swatch edits the Gradient Stroke, not the fill; without a selected
gradient the options open; the words, Solid swatches and Alt-click are
unchanged. The two gradient-swatch tests fail without this change.
This commit is contained in:
tylerjenningsw
2026-10-11 14:46:45 -04:00
parent 3df7e8f77c
commit 3d7f928465
2 changed files with 166 additions and 3 deletions
+31 -3
View File
@@ -12,7 +12,7 @@ use crate::widgets;
use crate::{Dialog, EffectcraftApp};
use effectcraft_color::BlendMode;
use effectcraft_engine::commands::shape_tool::{PaintKind, ToolPaint};
use effectcraft_engine::project::{LayerId, LayerSource};
use effectcraft_engine::project::{LayerId, LayerSource, PropGroup};
use effectcraft_engine::viewer as vw;
pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
@@ -301,6 +301,24 @@ fn tool_options(app: &mut EffectcraftApp, v: serde_json::Value) {
}
}
/// The Colors property of the first Gradient Fill (`gfill`) or Gradient Stroke (`gstroke`) on the
/// shape `layers`, in contents order through nested groups: (layer, property uid). The toolbar's
/// gradient swatch edits it in the Gradient Editor.
fn gradient_colors(app: &EffectcraftApp, layers: &[u64], paint: &str) -> Option<(u64, u64)> {
fn find(g: &PropGroup, paint: &str, depth: usize) -> Option<u64> {
if depth >= 16 {
return None;
}
g.groups().filter(|c| c.enabled).find_map(|c| match c.match_id.as_str() {
m if m == paint => c.get("colors").map(|p| p.uid),
"group" | "contents" => find(c, paint, depth + 1),
_ => None,
})
}
let comp = app.session.active_comp()?;
layers.iter().find_map(|&l| comp.layer(LayerId(l)).and_then(|layer| layer.props.sub("contents")).and_then(|c| find(c, paint, 0)).map(|u| (l, u)))
}
/// The colour picker of the Fill or Stroke swatch.
fn picker_id(key: &str) -> egui::Id {
egui::Id::new(("tool-pick", key))
@@ -353,8 +371,9 @@ fn fill_stroke_options(app: &mut EffectcraftApp, ui: &mut egui::Ui, p: &egui::Pa
if wresp.clicked() {
widgets::open_popup(ui, opts);
}
// The swatch picks a Solid Color's colour and opens the options for the other kinds;
// Alt-click steps through the kinds (as in After Effects).
// The swatch picks a Solid Color's colour, edits a Linear or Radial Gradient's colours in
// the Gradient Editor (the selected shape layer's Gradient Fill / Gradient Stroke), and
// opens the options otherwise; Alt-click steps through the kinds (as in After Effects).
let sr = Rect::from_min_size(pos2(wr.max.x + 6.0, cy - 8.0), vec2(20.0, 16.0));
let sresp = ui.interact(sr, egui::Id::new(("tool-paint-swatch", key)), Sense::click()).on_hover_text(format!("{title}: {}", tp.kind.label()));
paint_swatch(p, sr, &tp, sresp.hovered(), &t);
@@ -367,7 +386,16 @@ fn fill_stroke_options(app: &mut EffectcraftApp, ui: &mut egui::Ui, p: &egui::Pa
tool_options(app, json!({k: next.id()}));
} else if tp.kind == PaintKind::Solid {
widgets::open_popup(ui, picker_id(key));
} else if let Some((layer, prop)) = matches!(tp.kind, PaintKind::Linear | PaintKind::Radial)
.then(|| gradient_colors(app, shape_layers, if key == "fill" { "gfill" } else { "gstroke" }))
.flatten()
{
let ctx = ui.ctx().clone();
if let Err(e) = crate::menus::invoke(app, &ctx, "prop.editGradient", json!({"layer": layer, "prop": prop})) {
app.ui.status = e;
}
} else {
// No selected shape layer with that gradient: its options (new shapes' kind).
widgets::open_popup(ui, opts);
}
}