EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust
Merge remote-tracking branch 'origin/main' into feat/shape-size-chain-2489
ashokram-si17e88507f924
diff --cc crates/ui-egui/src/panels/timeline.rsindex f4cd4b991,a45d8e708..30b93e62e--- a/crates/ui-egui/src/panels/timeline.rs+++ b/crates/ui-egui/src/panels/timeline.rs@@@ -4337,198 -5387,159 +5387,161 @@@ fn fmt_num(v: f64, d: usize) -> Stringformat!("{v:.d$}")}- /// Inline value editor for a property row; pushes `prop.set` actions. Returns the rects of a- /// multi-dimension value's fields, one per dimension (none for other values).- fn value_editor(- app: &mut EffectcraftApp,- ui: &mut egui::Ui,- p: &egui::Painter,- layer: &Layer,- prop: &Property,- value: &Value,+ /// What the property value editors share: where to draw, what they edit, and how a change is+ /// worded as a `prop.set` command.+ struct ValueEdit<'a> {+ p: &'a egui::Painter,+ layer: &'a Layer,+ prop: &'a Property,at: Pos2,- actions: &mut Vec<(String, serde_json::Value)>,- ) -> Vec<Rect> {- let t = app.tokens;- let uid = prop.uid;- let mut dims = vec![];- let merge = format!("scrub-{uid}");- // With several layers selected the edit applies to all of them (#491): a scrub by the same- // change, a typed value as it is.- let scrub = ui.ctx().dragged_id().is_some() && ui.input(|i| i.pointer.is_decidedly_dragging());- // Proportional Scrubbing (After Effects 26.2): Ctrl+Alt (Cmd+Opt) spreads the change over the- // selected layers by selection order, the first unchanged and the last by all of it.- let proportional = scrub && ui.input(|i| widgets::proportional_scrub(i.modifiers));- let set = |actions: &mut Vec<(String, serde_json::Value)>, v: serde_json::Value| {+ uid: u64,+ merge: String,+ scrub: bool,+ proportional: bool,+ }++ impl<'a> ValueEdit<'a> {+ /// The editor of `prop` on `layer` at `at`; `ui` says whether a scrub is under way.+ fn new(ui: &egui::Ui, p: &'a egui::Painter, layer: &'a Layer, prop: &'a Property, at: Pos2) -> Self {+ let uid = prop.uid;+ // With several layers selected the edit applies to all of them (#491): a scrub by the same+ // change, a typed value as it is.+ let scrub = ui.ctx().dragged_id().is_some() && ui.input(|i| i.pointer.is_decidedly_dragging());+ // Proportional Scrubbing (After Effects 26.2): Ctrl+Alt (Cmd+Opt) spreads the change over the+ // selected layers by selection order, the first unchanged and the last by all of it.+ let proportional = scrub && ui.input(|i| widgets::proportional_scrub(i.modifiers));+ Self { p, layer, prop, at, uid, merge: format!("scrub-{uid}"), scrub, proportional }+ }++ /// Queues the `prop.set` of one edit.+ fn set(&self, actions: &mut Vec<(String, serde_json::Value)>, v: serde_json::Value) {actions.push(("prop.set".into(),- json!({"layer": layer.id.0, "prop": uid, "value": v, "merge": merge, "selected": true, "offset": scrub, "proportional": proportional}),+ json!({"layer": self.layer.id.0, "prop": self.uid, "value": v, "merge": self.merge, "selected": true, "offset": self.scrub, "proportional": self.proportional}),))- };- let is_3d = layer.is_3d();- let mut x = at.x;- let y = at.y - 9.0;+ }+ }++ /// Inline value editor for a property row; pushes `prop.set` actions. Returns the rects of a+ /// multi-dimension value's fields, one per dimension (none for other values).+ fn value_editor(app: &mut EffectcraftApp, ui: &mut egui::Ui, ve: &ValueEdit<'_>, value: &Value, actions: &mut Vec<(String, serde_json::Value)>) -> Vec<Rect> {match value {- Value::Scalar(v) => {- let (min, max, dec, speed) = match &prop.ui {- ParamUi::Slider { min, max, decimals, .. } => (*min, *max, *decimals as usize, widgets::slider_scrub_speed(&prop.ui)),- ParamUi::Percent => (-1e6, 1e6, 1, 0.5),- _ => (-1e9, 1e9, 1, 1.0),- };- if matches!(prop.ui, ParamUi::Angle) {- let (rr, dr, nv) = super::fx_widgets::angle_field(ui, pos2(x, y), egui::Id::unique(("v", uid, 0)), *v, 1, &t);- app.auto.add(&format!("timeline.prop.{uid}.value"), dr, &prop.name);- app.auto.add(&format!("timeline.prop.{uid}.revolutions"), rr, &prop.name);- if let Some(nv) = nv {- set(actions, json!(nv));- }- } else {- // A Range Selector's Start, End and Offset count characters with Units = Index (#1814).- let pct = (matches!(prop.ui, ParamUi::Percent) || prop.match_id == "opacity") && !effectcraft_engine::render::text::in_index_units(layer, uid);- let suffix = if pct { "%" } else { "" };- let (r, nv, _) = widgets::hot_number_at(ui, pos2(x, y), egui::Id::unique(("v", uid, 0)), *v, speed, (min, max), dec.max(1), suffix, &t);- app.auto.add(&format!("timeline.prop.{uid}.value"), r, &prop.name);- if let Some(nv) = nv {- set(actions, json!(nv));- }- }+ Value::Scalar(_) => scalar_editor(app, ui, ve, actions, value),+ Value::Vec2(_) | Value::Vec3(_) => return vector_editor(app, ui, ve, actions, value),+ Value::Color(_) => color_editor(app, ui, ve, actions, value),+ Value::Bool(_) => bool_editor(app, ui, ve, actions, value),+ Value::Enum(_) => enum_editor(app, ui, ve, actions, value),+ Value::Layer(_) => layer_editor(app, ui, ve, actions, value),+ Value::Gradient(_) => gradient_editor(app, ui, ve, actions),+ Value::Path(_) => {+ ve.p.text(pos2(ve.at.x, ve.at.y), Align2::LEFT_CENTER, crate::i18n::tr("Shape…"), Tokens::ui(12.0), app.tokens.hot_text);}- Value::Vec2(_) | Value::Vec3(_) => {- let c = value.components();- let n = if prop.shown_dims > 0 && !(is_3d && c.len() == 3) { prop.shown_dims as usize } else { c.len() };- let pct = matches!(prop.ui, ParamUi::Percent);- // Mask Feather: two linked values, never negative (as in After Effects, #203).- let feather = prop.match_id == "feather" && layer.props.parent_of(uid).is_some_and(|g| matches!(g.kind, GroupKind::Mask { .. }));- let range = if feather { (0.0, 1e9) } else { (-1e9, 1e9) };- // Scale and Mask Feather: the chain link (Constrain Proportions, on by default).- // Rectangle and Ellipse Path Size have it too, off by default (#2489).- let size = prop.match_id == "size" && layer.props.parent_of(uid).is_some_and(|g| matches!(g.match_id.as_str(), "rect" | "ellipse"));- let linkable = feather || size || (pct && prop.match_id == "scale");- let linked = linkable && app.ui.timeline.is_linked(uid, !size);- if linkable {- let lr = Rect::from_center_size(pos2(x + 7.0, at.y), vec2(14.0, 14.0));- let resp = ui.interact(lr, egui::Id::unique(("tl-link", uid)), Sense::click()).on_hover_text(crate::i18n::tr("Constrain Proportions"));- icons::paint(p, lr, Icon::Link, if linked { t.accent } else { t.text_faint });- app.auto.add(&format!("timeline.prop.{uid}.link"), lr, "Constrain Proportions");- if resp.clicked() {- app.ui.timeline.toggle_link(uid, !size);- }- x += 18.0;- }- for d in 0..n.min(c.len()) {- let suffix = if pct && d + 1 == n { "%" } else { "" };- let (r, nv, _) =- widgets::hot_number_at(ui, pos2(x, y), egui::Id::unique(("v", uid, d)), c[d], if pct { 0.5 } else { 1.0 }, range, 1, suffix, &t);- app.auto.add(&format!("timeline.prop.{uid}.value.{d}"), r, &prop.name);- dims.push(r);- if let Some(nv) = nv {- let mut nc = c.clone();- // Alt edits one value of a linked pair (Ctrl+Alt is a proportional scrub).- let shown = if linked && !ui.input(|i| i.modifiers.alt && !widgets::proportional_scrub(i.modifiers)) { n.min(c.len()) } else { 1 };- let from = if shown == 1 { d } else { 0 };- for (e, v) in widgets::constrained(c.get(from..from + shown).unwrap_or_default(), d - from, nv).into_iter().enumerate() {- if let Some(slot) = nc.get_mut(from + e) {- *slot = v;- }- }- set(actions, json!(nc));- // Typed into these components only: other selected layers keep the rest of- // their own value (#1434).- if let Some((_, a)) = actions.last_mut() {- a["dims"] = json!((from..from + shown).collect::<Vec<_>>());- }- }- x = r.max.x + if d + 1 < n { 2.0 } else { 0.0 };- if d + 1 < n {- p.text(pos2(x, at.y), Align2::LEFT_CENTER, ",", Tokens::ui(12.0), t.hot_text);- x += 6.0;- }- }+ Value::Text(_) => {}+ Value::Str(s) => {+ ve.p.text(pos2(ve.at.x, ve.at.y), Align2::LEFT_CENTER, s.chars().take(30).collect::<String>(), Tokens::ui(12.0), app.tokens.text_dim);}- Value::Color(c) => {- let r = Rect::from_min_size(pos2(x, at.y - 7.0), vec2(26.0, 14.0));- let resp = widgets::swatch(ui, r, [c[0] as f32, c[1] as f32, c[2] as f32, 1.0], egui::Id::unique(("sw", uid)), &t);- app.auto.add(&format!("timeline.prop.{uid}.value"), r, &prop.name);- let pop = egui::Id::unique(("cpop", uid));- if resp.clicked() {- widgets::open_popup(ui, pop);- }- // The eyedropper after the swatch samples the Composition panel (shape Fill and- // Stroke colours, text and effect colours), as in After Effects' Timeline (#633).- let er = Rect::from_center_size(pos2(r.max.x + 12.0, at.y), vec2(16.0, 16.0));- let active = app.ui.fx_pick.as_ref().is_some_and(|k| k.prop == uid && k.kind == "color");- if super::fx_widgets::eyedropper_button(ui, er, active, egui::Id::unique(("tl-eye", uid)), &t)- .on_hover_text(crate::i18n::tr("Eyedropper: click, then click in the Composition panel"))- .clicked()- {- super::effect_controls::toggle_pick(app, "color", layer, prop);- }- app.auto.add(&format!("timeline.prop.{uid}.eyedropper"), er, &prop.name);- let mut rgb = [c[0] as f32, c[1] as f32, c[2] as f32];- if crate::widgets::color_popup(ui, pop, r.left_bottom(), &mut rgb) {- set(actions, json!([rgb[0], rgb[1], rgb[2], 1.0]));- }+ }+ Vec::new()+ }++ /// A number: scrubbable hot text, or the angle field.+ fn scalar_editor(app: &mut EffectcraftApp, ui: &mut egui::Ui, ve: &ValueEdit<'_>, actions: &mut Vec<(String, serde_json::Value)>, value: &Value) {+ let Value::Scalar(v) = value else { return };+ let (layer, prop, at, uid) = (ve.layer, ve.prop, ve.at, ve.uid);+ let t = app.tokens;+ let (x, y) = (at.x, at.y - 9.0);+ let (min, max, dec, speed) = match &prop.ui {+ ParamUi::Slider { min, max, decimals, .. } => (*min, *max, *decimals as usize, widgets::slider_scrub_speed(&prop.ui)),+ ParamUi::Percent => (-1e6, 1e6, 1, 0.5),+ _ => (-1e9, 1e9, 1, 1.0),+ };+ if matches!(prop.ui, ParamUi::Angle) {+ let (rr, dr, nv) = super::fx_widgets::angle_field(ui, pos2(x, y), egui::Id::unique(("v", uid, 0)), *v, 1, &t);+ app.auto.add(&format!("timeline.prop.{uid}.value"), dr, &prop.name);+ app.auto.add(&format!("timeline.prop.{uid}.revolutions"), rr, &prop.name);+ if let Some(nv) = nv {+ ve.set(actions, json!(nv));}- Value::Bool(b) => {- let r = Rect::from_min_size(pos2(x, at.y - 8.0), vec2(16.0, 16.0));- if widgets::checkbox(ui, r, *b, &t, egui::Id::unique(("cb", uid))).clicked() {- set(actions, json!(!b));- }- app.auto.add(&format!("timeline.prop.{uid}.value"), r, &prop.name);- }- Value::Enum(i) => {- // Text Path Options ▸ Path lists the layer's masks.- let mask_opts: Option<Vec<String>> = layer- .props- .prop("text/pathOptions/path")- .filter(|q| q.uid == uid)- .map(|_| std::iter::once("None".to_string()).chain(layer.masks().into_iter().flat_map(|m| m.groups().map(|g| g.name.clone()))).collect());- let ui_opts = mask_opts.map(|options| ParamUi::Popup { options });- if let ParamUi::Popup { options } = ui_opts.as_ref().unwrap_or(&prop.ui) {- let r = Rect::from_min_size(pos2(x, at.y - 9.0), vec2(150.0, 18.0));- let label = options.get(*i as usize).cloned().unwrap_or_default();- let pop = egui::Id::unique(("epop", uid));- if widgets::dropdown(ui, r, &label, &t, egui::Id::unique(("en", uid))).clicked() {- widgets::open_popup(ui, pop);- }- app.auto.add(&format!("timeline.prop.{uid}.value"), r, &prop.name);- if let Some(ni) = widgets::popup_menu(ui, pop, r.left_bottom(), options, Some(*i as usize)) {- set(actions, json!(ni));- }- } else {- p.text(pos2(x, at.y), Align2::LEFT_CENTER, fmt_num(*i as f64, 0), Tokens::ui(12.0), t.hot_text);- }+ } else {+ // A Range Selector's Start, End and Offset count characters with Units = Index (#1814).+ let pct = (matches!(prop.ui, ParamUi::Percent) || prop.match_id == "opacity") && !effectcraft_engine::render::text::in_index_units(layer, uid);+ let suffix = if pct { "%" } else { "" };+ let (r, nv, _) = widgets::hot_number_at(+ ui,+ pos2(x, y),+ egui::Id::unique(("v", uid, 0)),+ *v,+ &widgets::HotSpec { speed, range: (min, max), decimals: dec.max(1), suffix },+ &t,+ );+ app.auto.add(&format!("timeline.prop.{uid}.value"), r, &prop.name);+ if let Some(nv) = nv {+ ve.set(actions, json!(nv));}- Value::Path(_) => {- p.text(pos2(x, at.y), Align2::LEFT_CENTER, crate::i18n::tr("Shape…"), Tokens::ui(12.0), t.hot_text);+ }+ }++ /// A multi-dimension value: one hot-text field per dimension, with the link chain. Returns their rects.+ fn vector_editor(app: &mut EffectcraftApp, ui: &mut egui::Ui, ve: &ValueEdit<'_>, actions: &mut Vec<(String, serde_json::Value)>, value: &Value) -> Vec<Rect> {+ let (p, layer, prop, at, uid) = (ve.p, ve.layer, ve.prop, ve.at, ve.uid);+ let t = app.tokens;+ let (mut x, y) = (at.x, at.y - 9.0);+ let is_3d = layer.is_3d();+ let mut dims = vec![];+ let c = value.components();+ let n = if prop.shown_dims > 0 && !(is_3d && c.len() == 3) { prop.shown_dims as usize } else { c.len() };+ let pct = matches!(prop.ui, ParamUi::Percent);+ // Mask Feather: two linked values, never negative (as in After Effects, #203).+ let feather = prop.match_id == "feather" && layer.props.parent_of(uid).is_some_and(|g| matches!(g.kind, GroupKind::Mask { .. }));+ let range = if feather { (0.0, 1e9) } else { (-1e9, 1e9) };+ // Scale and Mask Feather: the chain link (Constrain Proportions, on by default).- let linkable = feather || (pct && prop.match_id == "scale");- let linked = linkable && !app.ui.timeline.unlinked.contains(&uid);++ // Rectangle and Ellipse Path Size have it too, off by default (#2489).++ let size = prop.match_id == "size" && layer.props.parent_of(uid).is_some_and(|g| matches!(g.match_id.as_str(), "rect" | "ellipse"));++ let linkable = feather || size || (pct && prop.match_id == "scale");++ let linked = linkable && app.ui.timeline.is_linked(uid, !size);+ if linkable {+ let lr = Rect::from_center_size(pos2(x + 7.0, at.y), vec2(14.0, 14.0));+ let resp = ui.interact(lr, egui::Id::unique(("tl-link", uid)), Sense::click()).on_hover_text(crate::i18n::tr("Constrain Proportions"));+ icons::paint(p, lr, Icon::Link, if linked { t.accent } else { t.text_faint });+ app.auto.add(&format!("timeline.prop.{uid}.link"), lr, "Constrain Proportions");- if resp.clicked() && !app.ui.timeline.unlinked.remove(&uid) {- app.ui.timeline.unlinked.insert(uid);++ if resp.clicked() {++ app.ui.timeline.toggle_link(uid, !size);}- Value::Text(_) => {}- Value::Layer(l) => {- // Layer references (a light's Source, a Displacement Map's layer…) pick from the- // comp's layers, as in Effect Controls; the choice is written through the same- // undoable prop.set as the other value arms.- let r = Rect::from_min_size(pos2(x, at.y - 9.0), vec2(150.0, 18.0));- if let Some(comp) = app.session.active_comp_arc()- && let Some(chosen) = widgets::layer_picker(ui, r, &comp.layers, *l, &t, egui::Id::unique(("tl-lay", uid)))- {- set(actions, chosen.map(|id| json!(id)).unwrap_or(serde_json::Value::Null));- }- app.auto.add(&format!("timeline.prop.{uid}.value"), r, &prop.name);- }- Value::Gradient(_) => {- // Opens the Gradient Editor at the current time (#612).- let r = p.text(pos2(x, at.y), Align2::LEFT_CENTER, crate::i18n::tr("Edit Gradient…"), Tokens::ui(12.0), t.hot_text);- let resp = ui.interact(r.expand(2.0), egui::Id::unique(("gradient-edit", uid)), Sense::click());- if resp.hovered() {- ui.ctx().set_cursor_icon(egui::CursorIcon::PointingHand);+ x += 18.0;+ }+ for d in 0..n.min(c.len()) {+ let suffix = if pct && d + 1 == n { "%" } else { "" };+ let (r, nv, _) = widgets::hot_number_at(+ ui,+ pos2(x, y),+ egui::Id::unique(("v", uid, d)),+ c[d],+ &widgets::HotSpec { speed: if pct { 0.5 } else { 1.0 }, range, decimals: 1, suffix },+ &t,+ );+ app.auto.add(&format!("timeline.prop.{uid}.value.{d}"), r, &prop.name);+ dims.push(r);+ if let Some(nv) = nv {+ let mut nc = c.clone();+ // Alt edits one value of a linked pair (Ctrl+Alt is a proportional scrub).+ let shown = if linked && !ui.input(|i| i.modifiers.alt && !widgets::proportional_scrub(i.modifiers)) { n.min(c.len()) } else { 1 };+ let from = if shown == 1 { d } else { 0 };+ for (e, v) in widgets::constrained(c.get(from..from + shown).unwrap_or_default(), d - from, nv).into_iter().enumerate() {+ if let Some(slot) = nc.get_mut(from + e) {+ *slot = v;+ }}- app.auto.add(&format!("timeline.prop.{uid}.value"), r, &prop.name);- if resp.clicked() {- actions.push(("prop.editGradient".into(), json!({"layer": layer.id.0, "prop": uid})));+ ve.set(actions, json!(nc));+ // Typed into these components only: other selected layers keep the rest of+ // their own value (#1434).+ if let Some((_, a)) = actions.last_mut() {+ a["dims"] = json!((from..from + shown).collect::<Vec<_>>());}}- Value::Str(s) => {- p.text(pos2(x, at.y), Align2::LEFT_CENTER, s.chars().take(30).collect::<String>(), Tokens::ui(12.0), t.text_dim);+ x = r.max.x + if d + 1 < n { 2.0 } else { 0.0 };+ if d + 1 < n {+ p.text(pos2(x, at.y), Align2::LEFT_CENTER, ",", Tokens::ui(12.0), t.hot_text);+ x += 6.0;}}dims