Skip to content

EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust

Merge origin/main into fix/expression-value-color (#1306)

tylerjenningswc979f5aebd20
diff --cc crates/ui-egui/src/panels/effect_controls/rows.rs
index cf50655f0,05fea44c9..249c8462b
--- a/crates/ui-egui/src/panels/effect_controls/rows.rs
+++ b/crates/ui-egui/src/panels/effect_controls/rows.rs
@@@ -71,6 -71,44 +71,49 @@@ pub(crate) fn toggle_pick(app: &mut Eff
}
}
+ /// What the value controls of one property row share.
+ #[derive(Clone, Copy)]
+ struct PropCx<'a> {
+ p: &'a egui::Painter,
+ layer: &'a Layer,
+ group: &'a PropGroup,
+ prop: &'a Property,
+ r: Rect,
+ vx: f32,
+ cy: f32,
+ swr: Rect,
+ t: Tokens,
+ uid: u64,
+ scrub: bool,
+ }
+
+ impl PropCx<'_> {
++ /// The tokens of the value fields: red while an expression drives the parameter (#1306).
++ fn value_tokens(&self) -> Tokens {
++ self.t.for_value(self.prop.has_expression())
++ }
++
+ fn set(&self, actions: &mut Actions, v: serde_json::Value) {
+ let (layer, uid, merge, scrub) = (self.layer, self.uid, format!("ec-{}", self.uid), self.scrub);
+ actions.push(("prop.set".into(), json!({"layer": layer.id.0, "prop": uid, "value": v, "merge": merge, "selected": true, "offset": scrub})))
+ }
+
+ fn twirl_open(&self, app: &mut EffectcraftApp, ui: &mut egui::Ui) {
+ let PropCx { swr, cy, uid, prop, t, .. } = self;
+ let (cy, uid) = (*cy, *uid);
+ let open = app.ui.fx_slider_open.contains(&uid);
+ let tw = Rect::from_center_size(pos2(swr.min.x - 9.0, cy), vec2(10.0, 10.0));
+ if widgets::twirl(ui, tw, open, egui::Id::unique(("ec-stw", uid)), t).clicked() {
+ if open {
+ app.ui.fx_slider_open.remove(&uid);
+ } else {
+ app.ui.fx_slider_open.insert(uid);
+ }
+ }
+ app.auto.add(&format!("effectControls.prop.{uid}.twirl"), tw, &prop.name);
+ }
+ }
+
/// One property row: stopwatch, name, value control (and the keyframe navigator). Returns the
/// value fields of a vector, one per dimension, for the pick whip.
#[allow(clippy::too_many_arguments)]
@@@ -152,258 -190,318 +195,319 @@@ fn prop_row
app.show_panel(crate::dock::PanelKind::Timeline);
}
app.auto.add(&format!("effectControls.prop.{uid}.name"), name_clip, &prop.name);
- let merge = format!("ec-{uid}");
// With several layers selected the edit applies to the same effect property of each (#491).
let scrub = ui.ctx().dragged_id().is_some() && ui.input(|i| i.pointer.is_decidedly_dragging());
- let set = |actions: &mut Actions, v: serde_json::Value| {
- actions.push(("prop.set".into(), json!({"layer": layer.id.0, "prop": uid, "value": v, "merge": merge, "selected": true, "offset": scrub})))
+ let cx = PropCx { p, layer, group, prop, r, vx, cy, swr, t, uid, scrub };
+ match &value {
+ Value::Scalar(_) if matches!(prop.ui, ParamUi::Mask) => value_mask(app, ui, &cx, &value, actions),
+ Value::Scalar(_) if matches!(prop.ui, ParamUi::Angle) => value_angle(app, ui, &cx, &value, actions),
+ Value::Scalar(_) => value_scalar(app, ui, &cx, &value, actions),
+ Value::Vec2(_) | Value::Vec3(_) => dims = value_vector(app, ui, &cx, &value, actions),
+ Value::Color(_) => value_color(app, ui, &cx, &value, actions),
+ Value::Bool(_) => value_toggle(app, ui, &cx, &value, actions),
+ Value::Enum(_) => value_popup(app, ui, &cx, &value, actions),
+ Value::Layer(_) => value_layer_ref(app, ui, &cx, &value, actions),
+ // EXtractoR's red / green / blue / alpha: a popup of the footage's OpenEXR channels (#295).
+ Value::Str(_) if crate::panels::fx_editors::is_extractor_channel(group, prop) => value_extractor(app, ui, &cx, &value, actions),
+ // A file parameter (Apply Color LUT's LUT, an OCIO config): its file name and Choose…,
+ // as in After Effects.
+ Value::Str(_) if matches!(prop.ui, ParamUi::File { .. }) => value_file(app, ui, &cx, &value, actions),
+ // A text parameter (Cryptomatte's Selection, Colorama's Output Cycle, config names):
+ // typed in a field, set when it loses the focus (Esc keeps the old text).
+ Value::Str(_) if matches!(prop.ui, ParamUi::Text) => value_text(app, ui, &cx, &value, actions),
+ Value::Gradient(_) => value_gradient(app, &cx, &value),
+ _ => {}
+ }
+ dims
+ }
+
+ fn value_mask(app: &mut EffectcraftApp, ui: &mut egui::Ui, cx: &PropCx, value: &Value, actions: &mut Actions) {
+ let Value::Scalar(v) = value else {
+ return;
};
- let twirl_open = |app: &mut EffectcraftApp, ui: &mut egui::Ui| {
- let open = app.ui.fx_slider_open.contains(&uid);
- let tw = Rect::from_center_size(pos2(swr.min.x - 9.0, cy), vec2(10.0, 10.0));
- if widgets::twirl(ui, tw, open, egui::Id::unique(("ec-stw", uid)), &t).clicked() {
- if open {
- app.ui.fx_slider_open.remove(&uid);
- } else {
- app.ui.fx_slider_open.insert(uid);
- }
- }
- app.auto.add(&format!("effectControls.prop.{uid}.twirl"), tw, &prop.name);
+ let PropCx { t, uid, cy, vx, r, layer, prop, .. } = *cx;
+ // A mask of this layer ("Path" popup).
+ let mut opts = vec!["None".to_string()];
+ if let Some(m) = layer.masks() {
+ opts.extend(m.groups().map(|g| g.name.clone()));
+ }
+ let i = v.round().max(0.0) as usize;
+ let label = opts.get(i).cloned().unwrap_or_else(|| format!("Mask {i}"));
+ let dr = Rect::from_min_size(pos2(vx, cy - 9.0), vec2((r.max.x - vx - 56.0).clamp(80.0, 200.0), 18.0));
+ let pop = egui::Id::unique(("ec-mpop", uid));
+ if widgets::dropdown(ui, dr, &label, &t, egui::Id::unique(("ec-m", uid))).clicked() {
+ widgets::open_popup(ui, pop);
+ }
+ app.auto.add(&format!("effectControls.prop.{uid}.value"), dr, &prop.name);
+ if let Some(ni) = widgets::popup_menu(ui, pop, dr.left_bottom(), &opts, Some(i)) {
+ cx.set(actions, json!(ni as f64));
+ }
+ }
+
+ fn value_angle(app: &mut EffectcraftApp, ui: &mut egui::Ui, cx: &PropCx, value: &Value, actions: &mut Actions) {
+ let Value::Scalar(v) = value else {
+ return;
};
- match &value {
- Value::Scalar(v) if matches!(prop.ui, ParamUi::Mask) => {
- // A mask of this layer ("Path" popup).
- let mut opts = vec!["None".to_string()];
- if let Some(m) = layer.masks() {
- opts.extend(m.groups().map(|g| g.name.clone()));
- }
- let i = v.round().max(0.0) as usize;
- let label = opts.get(i).cloned().unwrap_or_else(|| format!("Mask {i}"));
- let dr = Rect::from_min_size(pos2(vx, cy - 9.0), vec2((r.max.x - vx - 56.0).clamp(80.0, 200.0), 18.0));
- let pop = egui::Id::unique(("ec-mpop", uid));
- if widgets::dropdown(ui, dr, &label, &t, egui::Id::unique(("ec-m", uid))).clicked() {
- widgets::open_popup(ui, pop);
- }
- app.auto.add(&format!("effectControls.prop.{uid}.value"), dr, &prop.name);
- if let Some(ni) = widgets::popup_menu(ui, pop, dr.left_bottom(), &opts, Some(i)) {
- set(actions, json!(ni as f64));
- }
- }
- Value::Scalar(v) if matches!(prop.ui, ParamUi::Angle) => {
- let (rr, dr, nv) = fw::angle_field(ui, pos2(vx, cy - 9.0), egui::Id::unique(("ec-v", uid)), *v, 1, &vt);
- app.auto.add(&format!("effectControls.prop.{uid}.value"), rr.union(dr), &fw::format_angle(*v, 1));
- app.auto.add(&format!("effectControls.prop.{uid}.revolutions"), rr, &prop.name);
- if let Some(nv) = nv {
- set(actions, json!(nv));
- }
- twirl_open(app, ui);
- }
- Value::Scalar(v) => {
- let (min, max, dec) = match &prop.ui {
- ParamUi::Slider { min, max, decimals, .. } => (*min, *max, *decimals as usize),
- _ => (-1e9, 1e9, 1),
- };
- let suffix = match prop.ui {
- ParamUi::Percent => "%",
- _ => "",
- };
- let speed = widgets::slider_scrub_speed(&prop.ui);
- let (vr, nv, _) = widgets::hot_number_at(
- ui,
- pos2(vx, cy - 9.0),
- egui::Id::unique(("ec-v", uid)),
- *v,
- speed,
- (min, max),
- dec.max(if dec == 0 { 0 } else { 1 }),
- suffix,
- &vt,
- );
- app.auto.add(&format!("effectControls.prop.{uid}.value"), vr, &prop.name);
- if let Some(nv) = nv {
- set(actions, json!(nv));
- }
- // AE hides a slider param's slider until its twirl is opened (see `slider_row`).
- if matches!(prop.ui, ParamUi::Slider { .. }) {
- twirl_open(app, ui);
- }
- }
- Value::Vec2(_) | Value::Vec3(_) => {
- let c = value.components();
- let n = shown_dims(layer, prop, &value);
- let mut x = vx;
- if matches!(prop.ui, ParamUi::Point | ParamUi::Point3) {
- let cr = Rect::from_center_size(pos2(x + 8.0, cy), vec2(18.0, 18.0));
- let active = app.ui.fx_pick.as_ref().is_some_and(|k| k.prop == uid && k.kind == "point");
- if fw::crosshair_button(ui, cr, active, egui::Id::unique(("ec-xh", uid)), &t)
- .on_hover_text(crate::i18n::tr("Click, then click in the Composition panel"))
- .clicked()
- {
- toggle_pick(app, "point", layer, prop);
- }
- app.auto.add(&format!("effectControls.prop.{uid}.crosshair"), cr, &prop.name);
- x += 22.0;
- }
- for d in 0..n.min(c.len()) {
- let (vr, nv, _) = widgets::hot_number_at(ui, pos2(x, cy - 9.0), egui::Id::unique(("ec-v", uid, d)), c[d], 1.0, (-1e9, 1e9), 1, "", &vt);
- app.auto.add(&format!("effectControls.prop.{uid}.value.{d}"), vr, &prop.name);
- dims.push(vr);
- if let Some(nv) = nv {
- let mut nc = c.clone();
- nc[d] = nv;
- set(actions, json!(nc));
- // Typed into this component only: other selected layers keep the rest of
- // their own value (#1434).
- if let Some((_, a)) = actions.last_mut() {
- a["dims"] = json!([d]);
- }
- }
- x = vr.max.x + 8.0;
- }
- let PropCx { t, uid, cy, vx, prop, .. } = *cx;
- let (rr, dr, nv) = fw::angle_field(ui, pos2(vx, cy - 9.0), egui::Id::unique(("ec-v", uid)), *v, 1, &t);
++ let PropCx { uid, cy, vx, prop, .. } = *cx;
++ let (rr, dr, nv) = fw::angle_field(ui, pos2(vx, cy - 9.0), egui::Id::unique(("ec-v", uid)), *v, 1, &cx.value_tokens());
+ app.auto.add(&format!("effectControls.prop.{uid}.value"), rr.union(dr), &fw::format_angle(*v, 1));
+ app.auto.add(&format!("effectControls.prop.{uid}.revolutions"), rr, &prop.name);
+ if let Some(nv) = nv {
+ cx.set(actions, json!(nv));
+ }
+ cx.twirl_open(app, ui);
+ }
+
+ fn value_scalar(app: &mut EffectcraftApp, ui: &mut egui::Ui, cx: &PropCx, value: &Value, actions: &mut Actions) {
+ let Value::Scalar(v) = value else {
+ return;
+ };
- let PropCx { t, uid, cy, vx, prop, .. } = *cx;
++ let PropCx { uid, cy, vx, prop, .. } = *cx;
+ let (min, max, dec) = match &prop.ui {
+ ParamUi::Slider { min, max, decimals, .. } => (*min, *max, *decimals as usize),
+ _ => (-1e9, 1e9, 1),
+ };
+ let suffix = match prop.ui {
+ ParamUi::Percent => "%",
+ _ => "",
+ };
+ let speed = widgets::slider_scrub_speed(&prop.ui);
+ let (vr, nv, _) = widgets::hot_number_at(
+ ui,
+ pos2(vx, cy - 9.0),
+ egui::Id::unique(("ec-v", uid)),
+ *v,
+ &widgets::HotSpec { speed, range: (min, max), decimals: dec.max(if dec == 0 { 0 } else { 1 }), suffix },
- &t,
++ &cx.value_tokens(),
+ );
+ app.auto.add(&format!("effectControls.prop.{uid}.value"), vr, &prop.name);
+ if let Some(nv) = nv {
+ cx.set(actions, json!(nv));
+ }
+ // AE hides a slider param's slider until its twirl is opened (see `slider_row`).
+ if matches!(prop.ui, ParamUi::Slider { .. }) {
+ cx.twirl_open(app, ui);
+ }
+ }
+
+ fn value_vector(app: &mut EffectcraftApp, ui: &mut egui::Ui, cx: &PropCx, value: &Value, actions: &mut Actions) -> Vec<Rect> {
+ let mut dims = vec![];
+ let PropCx { t, uid, cy, vx, layer, prop, .. } = *cx;
+ let c = value.components();
+ let n = shown_dims(layer, prop, value);
++ let vt = cx.value_tokens();
+ let mut x = vx;
+ if matches!(prop.ui, ParamUi::Point | ParamUi::Point3) {
+ let cr = Rect::from_center_size(pos2(x + 8.0, cy), vec2(18.0, 18.0));
+ let active = app.ui.fx_pick.as_ref().is_some_and(|k| k.prop == uid && k.kind == "point");
+ if fw::crosshair_button(ui, cr, active, egui::Id::unique(("ec-xh", uid)), &t)
+ .on_hover_text(crate::i18n::tr("Click, then click in the Composition panel"))
+ .clicked()
+ {
+ toggle_pick(app, "point", layer, prop);
}
- Value::Color(c) => {
- let sr = Rect::from_min_size(pos2(vx, cy - 8.0), vec2(30.0, 16.0));
- let pop = egui::Id::unique(("ec-cpop", uid));
- if widgets::swatch(ui, sr, [c[0] as f32, c[1] as f32, c[2] as f32, 1.0], egui::Id::unique(("ec-c", uid)), &t).clicked() {
- widgets::open_popup(ui, pop);
- }
- app.auto.add(&format!("effectControls.prop.{uid}.value"), sr, &prop.name);
- let er = Rect::from_center_size(pos2(sr.max.x + 14.0, cy), vec2(18.0, 18.0));
- let active = app.ui.fx_pick.as_ref().is_some_and(|k| k.prop == uid && k.kind == "color");
- if fw::eyedropper_button(ui, er, active, egui::Id::unique(("ec-eye", uid)), &t)
- .on_hover_text(crate::i18n::tr("Eyedropper: click, then click in the Composition panel"))
- .clicked()
- {
- toggle_pick(app, "color", layer, prop);
- }
- app.auto.add(&format!("effectControls.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, sr.left_bottom(), &mut rgb) {
- set(actions, json!([rgb[0], rgb[1], rgb[2], 1.0]));
+ app.auto.add(&format!("effectControls.prop.{uid}.crosshair"), cr, &prop.name);
+ x += 22.0;
+ }
+ for d in 0..n.min(c.len()) {
+ let (vr, nv, _) = widgets::hot_number_at(
+ ui,
+ pos2(x, cy - 9.0),
+ egui::Id::unique(("ec-v", uid, d)),
+ c[d],
+ &widgets::HotSpec { speed: 1.0, range: (-1e9, 1e9), decimals: 1, suffix: "" },
- &t,
++ &vt,
+ );
+ app.auto.add(&format!("effectControls.prop.{uid}.value.{d}"), vr, &prop.name);
+ dims.push(vr);
+ if let Some(nv) = nv {
+ let mut nc = c.clone();
+ nc[d] = nv;
+ cx.set(actions, json!(nc));
+ // Typed into this component only: other selected layers keep the rest of
+ // their own value (#1434).
+ if let Some((_, a)) = actions.last_mut() {
+ a["dims"] = json!([d]);
}
}
- Value::Bool(b) => {
- let cr = Rect::from_min_size(pos2(vx, cy - 8.0), vec2(16.0, 16.0));
- if widgets::checkbox(ui, cr, *b, &t, egui::Id::unique(("ec-b", uid))).clicked() {
- set(actions, json!(!b));
- }
- p.text(pos2(cr.max.x + 6.0, cy), Align2::LEFT_CENTER, &prop.name, Tokens::ui(12.0), t.text_dim);
- app.auto.add(&format!("effectControls.prop.{uid}.value"), cr, &prop.name);
+ x = vr.max.x + 8.0;
+ }
+ dims
+ }
+
+ fn value_color(app: &mut EffectcraftApp, ui: &mut egui::Ui, cx: &PropCx, value: &Value, actions: &mut Actions) {
+ let Value::Color(c) = value else {
+ return;
+ };
+ let PropCx { t, uid, cy, vx, layer, prop, .. } = *cx;
+ let sr = Rect::from_min_size(pos2(vx, cy - 8.0), vec2(30.0, 16.0));
+ let pop = egui::Id::unique(("ec-cpop", uid));
+ if widgets::swatch(ui, sr, [c[0] as f32, c[1] as f32, c[2] as f32, 1.0], egui::Id::unique(("ec-c", uid)), &t).clicked() {
+ widgets::open_popup(ui, pop);
+ }
+ app.auto.add(&format!("effectControls.prop.{uid}.value"), sr, &prop.name);
+ let er = Rect::from_center_size(pos2(sr.max.x + 14.0, cy), vec2(18.0, 18.0));
+ let active = app.ui.fx_pick.as_ref().is_some_and(|k| k.prop == uid && k.kind == "color");
+ if fw::eyedropper_button(ui, er, active, egui::Id::unique(("ec-eye", uid)), &t)
+ .on_hover_text(crate::i18n::tr("Eyedropper: click, then click in the Composition panel"))
+ .clicked()
+ {
+ toggle_pick(app, "color", layer, prop);
+ }
+ app.auto.add(&format!("effectControls.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, sr.left_bottom(), &mut rgb) {
+ cx.set(actions, json!([rgb[0], rgb[1], rgb[2], 1.0]));
+ }
+ }
+
+ fn value_toggle(app: &mut EffectcraftApp, ui: &mut egui::Ui, cx: &PropCx, value: &Value, actions: &mut Actions) {
+ let Value::Bool(b) = value else {
+ return;
+ };
+ let PropCx { t, uid, cy, vx, p, prop, .. } = *cx;
+ let cr = Rect::from_min_size(pos2(vx, cy - 8.0), vec2(16.0, 16.0));
+ if widgets::checkbox(ui, cr, *b, &t, egui::Id::unique(("ec-b", uid))).clicked() {
+ cx.set(actions, json!(!b));
+ }
+ p.text(pos2(cr.max.x + 6.0, cy), Align2::LEFT_CENTER, &prop.name, Tokens::ui(12.0), t.text_dim);
+ app.auto.add(&format!("effectControls.prop.{uid}.value"), cr, &prop.name);
+ }
+
+ fn value_popup(app: &mut EffectcraftApp, ui: &mut egui::Ui, cx: &PropCx, value: &Value, actions: &mut Actions) {
+ let Value::Enum(i) = value else {
+ return;
+ };
+ let PropCx { t, uid, cy, vx, r, p, prop, .. } = *cx;
+ if let ParamUi::Popup { options } = &prop.ui {
+ let widest = options.iter().map(|o| p.layout_no_wrap(o.clone(), Tokens::ui(11.5), t.text).size().x).fold(0.0, f32::max);
+ let dr = Rect::from_min_size(pos2(vx, cy - 9.0), vec2((widest + 30.0).clamp(80.0, (r.max.x - vx - 56.0).max(80.0)), 18.0));
+ let pop = egui::Id::unique(("ec-epop", uid));
+ if widgets::dropdown(ui, dr, options.get(*i as usize).map(String::as_str).unwrap_or(""), &t, egui::Id::unique(("ec-e", uid))).clicked() {
+ widgets::open_popup(ui, pop);
}
- Value::Enum(i) => {
- if let ParamUi::Popup { options } = &prop.ui {
- let widest = options.iter().map(|o| p.layout_no_wrap(o.clone(), Tokens::ui(11.5), t.text).size().x).fold(0.0, f32::max);
- let dr = Rect::from_min_size(pos2(vx, cy - 9.0), vec2((widest + 30.0).clamp(80.0, (r.max.x - vx - 56.0).max(80.0)), 18.0));
- let pop = egui::Id::unique(("ec-epop", uid));
- if widgets::dropdown(ui, dr, options.get(*i as usize).map(String::as_str).unwrap_or(""), &t, egui::Id::unique(("ec-e", uid))).clicked() {
- widgets::open_popup(ui, pop);
- }
- app.auto.add(&format!("effectControls.prop.{uid}.value"), dr, &prop.name);
- if let Some(ni) = widgets::popup_menu(ui, pop, dr.left_bottom(), options, Some(*i as usize)) {
- set(actions, json!(ni));
- }
- }
+ app.auto.add(&format!("effectControls.prop.{uid}.value"), dr, &prop.name);
+ if let Some(ni) = widgets::popup_menu(ui, pop, dr.left_bottom(), options, Some(*i as usize)) {
+ cx.set(actions, json!(ni));
}
- Value::Layer(l) => {
- let comp = app.session.active_comp_arc();
- if let Some(comp) = comp {
- let dr = Rect::from_min_size(pos2(vx, cy - 9.0), vec2(((r.max.x - vx) * 0.55).clamp(90.0, 170.0), 18.0));
- if let Some(chosen) = widgets::layer_picker(ui, dr, &comp.layers, *l, &t, egui::Id::unique(("ec-l", uid))) {
- set(actions, chosen.map(|id| json!(id)).unwrap_or(serde_json::Value::Null));
- }
- app.auto.add(&format!("effectControls.prop.{uid}.value"), dr, &prop.name);
- // Source / Masks / Effects & Masks (the hidden companion parameter).
- if let Some(src) = group.get(&effectcraft_engine::effects::layer_source_id(&prop.match_id)) {
- let si = src.value.as_enum() as usize;
- let opts: Vec<String> = effectcraft_engine::effects::LAYER_SOURCE_OPTIONS.iter().map(|s| s.to_string()).collect();
- let sr = Rect::from_min_size(pos2(dr.max.x + 6.0, cy - 9.0), vec2(((r.max.x - dr.max.x) - 64.0).clamp(70.0, 120.0), 18.0));
- let spop = egui::Id::unique(("ec-lspop", uid));
- if widgets::dropdown(ui, sr, opts.get(si).map(String::as_str).unwrap_or(""), &t, egui::Id::unique(("ec-ls", uid))).clicked() {
- widgets::open_popup(ui, spop);
- }
- app.auto.add(&format!("effectControls.prop.{uid}.source"), sr, &src.name);
- if let Some(ni) = widgets::popup_menu(ui, spop, sr.left_bottom(), &opts, Some(si)) {
- actions.push(("prop.set".into(), json!({"layer": layer.id.0, "prop": src.uid, "value": ni})));
- }
- }
- }
- }
- // EXtractoR's red / green / blue / alpha: a popup of the footage's OpenEXR channels (#295).
- Value::Str(s) if crate::panels::fx_editors::is_extractor_channel(group, prop) => {
- let dr = Rect::from_min_size(pos2(vx, cy - 9.0), vec2((r.max.x - vx - 56.0).clamp(80.0, 200.0), 18.0));
- crate::panels::fx_editors::channel_popup(app, ui, layer, prop, s, dr, actions);
+ }
+ }
+
+ fn value_layer_ref(app: &mut EffectcraftApp, ui: &mut egui::Ui, cx: &PropCx, value: &Value, actions: &mut Actions) {
+ let Value::Layer(l) = value else {
+ return;
+ };
+ let PropCx { t, uid, cy, vx, r, layer, prop, group, .. } = *cx;
+ let comp = app.session.active_comp_arc();
+ if let Some(comp) = comp {
+ let dr = Rect::from_min_size(pos2(vx, cy - 9.0), vec2(((r.max.x - vx) * 0.55).clamp(90.0, 170.0), 18.0));
+ if let Some(chosen) = widgets::layer_picker(ui, dr, &comp.layers, *l, &t, egui::Id::unique(("ec-l", uid))) {
+ cx.set(actions, chosen.map(|id| json!(id)).unwrap_or(serde_json::Value::Null));
}
- // A file parameter (Apply Color LUT's LUT, an OCIO config): its file name and Choose…,
- // as in After Effects.
- Value::Str(s) if matches!(prop.ui, ParamUi::File { .. }) => {
- let bw = 70.0;
- let br = Rect::from_min_size(pos2(vx, cy - 9.0), vec2(bw, 18.0));
- if widgets::text_button(ui, br, crate::i18n::tr("Choose..."), false, &t, egui::Id::unique(("ec-file", uid))).clicked() {
- let filters: Vec<&str> = match &prop.ui {
- ParamUi::File { filters } => filters.iter().map(String::as_str).collect(),
- _ => vec![],
- };
- match app.hooks.pick_files.as_ref() {
- Some(pick) => {
- if let Some(path) = pick(&filters).into_iter().next() {
- actions.push(("prop.set".into(), json!({"layer": layer.id.0, "prop": uid, "value": path})));
- }
- }
- None => app.ui.status = "no file dialog available: set the path with prop.set".into(),
- }
+ app.auto.add(&format!("effectControls.prop.{uid}.value"), dr, &prop.name);
+ // Source / Masks / Effects & Masks (the hidden companion parameter).
+ if let Some(src) = group.get(&effectcraft_engine::effects::layer_source_id(&prop.match_id)) {
+ let si = src.value.as_enum() as usize;
+ let opts: Vec<String> = effectcraft_engine::effects::LAYER_SOURCE_OPTIONS.iter().map(|s| s.to_string()).collect();
+ let sr = Rect::from_min_size(pos2(dr.max.x + 6.0, cy - 9.0), vec2(((r.max.x - dr.max.x) - 64.0).clamp(70.0, 120.0), 18.0));
+ let spop = egui::Id::unique(("ec-lspop", uid));
+ if widgets::dropdown(ui, sr, opts.get(si).map(String::as_str).unwrap_or(""), &t, egui::Id::unique(("ec-ls", uid))).clicked() {
+ widgets::open_popup(ui, spop);
}
- app.auto.add(&format!("effectControls.prop.{uid}.choose"), br, &prop.name);
- let shown = if s.trim().is_empty() {
- crate::i18n::tr("None").to_string()
- } else if s.contains('\n') {
- prop.name.clone()
- } else {
- effectcraft_engine::sequence::file_name(s)
- };
- let nr = Rect::from_min_max(pos2(br.max.x + 8.0, r.min.y), pos2(r.max.x - 8.0, r.max.y));
- let np = p.with_clip_rect(nr.intersect(p.clip_rect()));
- np.text(pos2(nr.min.x, cy), Align2::LEFT_CENTER, &shown, Tokens::ui(12.0), if s.trim().is_empty() { t.text_dim } else { t.text });
- let hover = ui.interact(nr, egui::Id::unique(("ec-file-name", uid)), Sense::hover());
- if !s.trim().is_empty() && !s.contains('\n') {
- hover.on_hover_text(s.as_str());
+ app.auto.add(&format!("effectControls.prop.{uid}.source"), sr, &src.name);
+ if let Some(ni) = widgets::popup_menu(ui, spop, sr.left_bottom(), &opts, Some(si)) {
+ actions.push(("prop.set".into(), json!({"layer": layer.id.0, "prop": src.uid, "value": ni})));
}
- app.auto.add(&format!("effectControls.prop.{uid}.value"), nr, &shown);
}
- // A text parameter (Cryptomatte's Selection, Colorama's Output Cycle, config names):
- // typed in a field, set when it loses the focus (Esc keeps the old text).
- Value::Str(s) if matches!(prop.ui, ParamUi::Text) => {
- let fr = Rect::from_min_size(pos2(vx, cy - 9.0), vec2((r.max.x - vx - 12.0).clamp(80.0, 320.0), 18.0));
- let bid = egui::Id::unique(("ec-text", uid));
- let mut buf: String = ui.data(|d| d.get_temp(bid)).unwrap_or_else(|| s.clone());
- let resp = widgets::text_field(ui, fr, &mut buf, "", &t);
- // The field has no visible hint: give the screen reader the parameter's name.
- resp.widget_info(|| egui::WidgetInfo::labeled(egui::Role::TextInput, ui.is_enabled(), &prop.name));
- app.auto.add(&format!("effectControls.prop.{uid}.value"), fr, &prop.name);
- if resp.lost_focus() {
- if buf != *s && !ui.input(|i| i.key_pressed(egui::Key::Escape)) {
- actions.push(("prop.set".into(), json!({"layer": layer.id.0, "prop": uid, "value": buf})));
+ }
+ }
+
+ fn value_extractor(app: &mut EffectcraftApp, ui: &mut egui::Ui, cx: &PropCx, value: &Value, actions: &mut Actions) {
+ let Value::Str(s) = value else {
+ return;
+ };
+ let PropCx { cy, vx, r, layer, prop, .. } = *cx;
+ let dr = Rect::from_min_size(pos2(vx, cy - 9.0), vec2((r.max.x - vx - 56.0).clamp(80.0, 200.0), 18.0));
+ crate::panels::fx_editors::channel_popup(app, ui, layer, prop, s, dr, actions);
+ }
+
+ fn value_file(app: &mut EffectcraftApp, ui: &mut egui::Ui, cx: &PropCx, value: &Value, actions: &mut Actions) {
+ let Value::Str(s) = value else {
+ return;
+ };
+ let PropCx { t, uid, cy, vx, r, p, layer, prop, .. } = *cx;
+ let bw = 70.0;
+ let br = Rect::from_min_size(pos2(vx, cy - 9.0), vec2(bw, 18.0));
+ if widgets::text_button(ui, br, crate::i18n::tr("Choose..."), false, &t, egui::Id::unique(("ec-file", uid))).clicked() {
+ let filters: Vec<&str> = match &prop.ui {
+ ParamUi::File { filters } => filters.iter().map(String::as_str).collect(),
+ _ => vec![],
+ };
+ match app.hooks.pick_files.as_ref() {
+ Some(pick) => {
+ if let Some(path) = pick(&filters).into_iter().next() {
+ actions.push(("prop.set".into(), json!({"layer": layer.id.0, "prop": uid, "value": path})));
}
- ui.data_mut(|d| d.remove::<String>(bid));
- } else if resp.has_focus() {
- ui.data_mut(|d| d.insert_temp(bid, buf));
}
+ None => app.ui.status = "no file dialog available: set the path with prop.set".into(),
}
- Value::Gradient(g) => {
- let gr = Rect::from_min_size(pos2(vx, cy - 7.0), vec2((r.max.x - vx - 56.0).clamp(60.0, 180.0), 14.0));
- let n = 48;
- for k in 0..n {
- let f = k as f64 / (n - 1) as f64;
- let c = gradient_at(g, f);
- let x0 = gr.min.x + gr.width() * k as f32 / n as f32;
- let x1 = gr.min.x + gr.width() * (k + 1) as f32 / n as f32;
- p.rect_filled(Rect::from_min_max(pos2(x0, gr.min.y), pos2(x1, gr.max.y)), 0.0, c);
- }
- p.rect_stroke(gr, 2.0, Stroke::new(1.0, t.field_border), egui::StrokeKind::Inside);
- app.auto.add(&format!("effectControls.prop.{uid}.value"), gr, &prop.name);
+ }
+ app.auto.add(&format!("effectControls.prop.{uid}.choose"), br, &prop.name);
+ let shown = if s.trim().is_empty() {
+ crate::i18n::tr("None").to_string()
+ } else if s.contains('\n') {
+ prop.name.clone()
+ } else {
+ effectcraft_engine::sequence::file_name(s)
+ };
+ let nr = Rect::from_min_max(pos2(br.max.x + 8.0, r.min.y), pos2(r.max.x - 8.0, r.max.y));
+ let np = p.with_clip_rect(nr.intersect(p.clip_rect()));
+ np.text(pos2(nr.min.x, cy), Align2::LEFT_CENTER, &shown, Tokens::ui(12.0), if s.trim().is_empty() { t.text_dim } else { t.text });
+ let hover = ui.interact(nr, egui::Id::unique(("ec-file-name", uid)), Sense::hover());
+ if !s.trim().is_empty() && !s.contains('\n') {
+ hover.on_hover_text(s);
+ }
+ app.auto.add(&format!("effectControls.prop.{uid}.value"), nr, &shown);
+ }
+
+ fn value_text(app: &mut EffectcraftApp, ui: &mut egui::Ui, cx: &PropCx, value: &Value, actions: &mut Actions) {
+ let Value::Str(s) = value else {
+ return;
+ };
+ let PropCx { t, uid, cy, vx, r, layer, prop, .. } = *cx;
+ let fr = Rect::from_min_size(pos2(vx, cy - 9.0), vec2((r.max.x - vx - 12.0).clamp(80.0, 320.0), 18.0));
+ let bid = egui::Id::unique(("ec-text", uid));
+ let mut buf: String = ui.data(|d| d.get_temp(bid)).unwrap_or_else(|| s.to_owned());
+ let resp = widgets::text_field(ui, fr, &mut buf, "", &t);
+ // The field has no visible hint: give the screen reader the parameter's name.
+ resp.widget_info(|| egui::WidgetInfo::labeled(egui::Role::TextInput, ui.is_enabled(), &prop.name));
+ app.auto.add(&format!("effectControls.prop.{uid}.value"), fr, &prop.name);
+ if resp.lost_focus() {
+ if buf != *s && !ui.input(|i| i.key_pressed(egui::Key::Escape)) {
+ actions.push(("prop.set".into(), json!({"layer": layer.id.0, "prop": uid, "value": buf})));
}
- _ => {}
+ ui.data_mut(|d| d.remove::<String>(bid));
+ } else if resp.has_focus() {
+ ui.data_mut(|d| d.insert_temp(bid, buf));
}
- dims
+ }
+
+ fn value_gradient(app: &mut EffectcraftApp, cx: &PropCx, value: &Value) {
+ let Value::Gradient(g) = value else {
+ return;
+ };
+ let PropCx { t, uid, cy, vx, r, p, prop, .. } = *cx;
+ let gr = Rect::from_min_size(pos2(vx, cy - 7.0), vec2((r.max.x - vx - 56.0).clamp(60.0, 180.0), 14.0));
+ let n = 48;
+ for k in 0..n {
+ let f = k as f64 / (n - 1) as f64;
+ let c = gradient_at(g, f);
+ let x0 = gr.min.x + gr.width() * k as f32 / n as f32;
+ let x1 = gr.min.x + gr.width() * (k + 1) as f32 / n as f32;
+ p.rect_filled(Rect::from_min_max(pos2(x0, gr.min.y), pos2(x1, gr.max.y)), 0.0, c);
+ }
+ p.rect_stroke(gr, 2.0, Stroke::new(1.0, t.field_border), egui::StrokeKind::Inside);
+ app.auto.add(&format!("effectControls.prop.{uid}.value"), gr, &prop.name);
}
/// How many of a vector parameter's values show (a 3D point's Z only on a 3D layer).
diff --cc crates/ui-egui/src/panels/properties.rs
index d055ea407,c35108937..b10604122
--- a/crates/ui-egui/src/panels/properties.rs
+++ b/crates/ui-egui/src/panels/properties.rs
@@@ -288,7 -285,14 +287,14 @@@ fn transform_row(app: &mut EffectcraftA
}
Value::Scalar(v) => {
let range = if pr.name == "Opacity" { (0.0, 100.0) } else { (-1e9, 1e9) };
- let (vr, nv, _) = widgets::hot_number_at(ui, pos2(vx, cy - 9.0), egui::Id::unique(("props-v", uid)), *v, 0.5, range, decimals(*v), suffix, &vt);
+ let (vr, nv, _) = widgets::hot_number_at(
+ ui,
+ pos2(vx, cy - 9.0),
+ egui::Id::unique(("props-v", uid)),
+ *v,
+ &widgets::HotSpec { speed: 0.5, range, decimals: decimals(*v), suffix },
- &t,
++ &vt,
+ );
app.auto.add(&format!("{base}.value"), vr, &pr.name);
if let Some(nv) = nv {
set(actions, json!(nv));
@@@ -313,8 -317,14 +319,14 @@@
}
}
for d in 0..n.min(c.len()) {
- let (vr, nv, _) =
- widgets::hot_number_at(ui, pos2(x, cy - 9.0), egui::Id::unique(("props-v", uid, d)), c[d], 1.0, (-1e9, 1e9), decimals(c[d]), suffix, &vt);
+ let (vr, nv, _) = widgets::hot_number_at(
+ ui,
+ pos2(x, cy - 9.0),
+ egui::Id::unique(("props-v", uid, d)),
+ c[d],
+ &widgets::HotSpec { speed: 1.0, range: (-1e9, 1e9), decimals: decimals(c[d]), suffix },
- &t,
++ &vt,
+ );
app.auto.add(&format!("{base}.value.{d}"), vr, &pr.name);
if let Some(nv) = nv {
let mut nc = c.clone();
diff --cc crates/ui-egui/src/panels/timeline.rs
index 68151b388,30b93e62e..34083f015
--- a/crates/ui-egui/src/panels/timeline.rs
+++ b/crates/ui-egui/src/panels/timeline.rs
@@@ -4337,202 -5387,272 +5387,274 @@@ fn fmt_num(v: f64, d: usize) -> String
format!("{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;
- // The values themselves: red while an expression drives the property (#1306).
- let vt = t.for_value(prop.has_expression());
- 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, &vt);
- 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, &vt);
- 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).
- let linkable = feather || (pct && prop.match_id == "scale");
- let linked = linkable && !app.ui.timeline.unlinked.contains(&uid);
- 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);
- }
- 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, &vt);
- 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), vt.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;
++ // The values themselves: red while an expression drives the property (#1306).
++ let vt = app.tokens.for_value(prop.has_expression());
+ 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);
++ let (rr, dr, nv) = super::fx_widgets::angle_field(ui, pos2(x, y), egui::Id::unique(("v", uid, 0)), *v, 1, &vt);
+ 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), vt.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,
++ &vt,
+ );
+ 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 vt = t.for_value(prop.has_expression());
+ 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).
+ // 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);
}
- 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,
++ &vt,
+ );
+ 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);
++ p.text(pos2(x, at.y), Align2::LEFT_CENTER, ",", Tokens::ui(12.0), vt.hot_text);
+ x += 6.0;
}
}
dims
}
+ /// A colour: swatch, eyedropper and picker.
+ fn color_editor(app: &mut EffectcraftApp, ui: &mut egui::Ui, ve: &ValueEdit<'_>, actions: &mut Vec<(String, serde_json::Value)>, value: &Value) {
+ let Value::Color(c) = value else { return };
+ let (layer, prop, at, uid) = (ve.layer, ve.prop, ve.at, ve.uid);
+ let t = app.tokens;
+ let x = at.x;
+ 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) {
+ ve.set(actions, json!([rgb[0], rgb[1], rgb[2], 1.0]));
+ }
+ }
+
+ /// A checkbox.
+ fn bool_editor(app: &mut EffectcraftApp, ui: &mut egui::Ui, ve: &ValueEdit<'_>, actions: &mut Vec<(String, serde_json::Value)>, value: &Value) {
+ let Value::Bool(b) = value else { return };
+ let (prop, at, uid) = (ve.prop, ve.at, ve.uid);
+ let t = app.tokens;
+ let x = at.x;
+ 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() {
+ ve.set(actions, json!(!b));
+ }
+ app.auto.add(&format!("timeline.prop.{uid}.value"), r, &prop.name);
+ }
+
+ /// A popup (or the number when the property has no options).
+ fn enum_editor(app: &mut EffectcraftApp, ui: &mut egui::Ui, ve: &ValueEdit<'_>, actions: &mut Vec<(String, serde_json::Value)>, value: &Value) {
+ let Value::Enum(i) = value else { return };
+ let (p, layer, prop, at, uid) = (ve.p, ve.layer, ve.prop, ve.at, ve.uid);
+ let t = app.tokens;
+ let x = at.x;
+ // 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)) {
+ ve.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);
++ p.text(pos2(x, at.y), Align2::LEFT_CENTER, fmt_num(*i as f64, 0), Tokens::ui(12.0), t.for_value(prop.has_expression()).hot_text);
+ }
+ }
+
+ /// A layer reference picker.
+ fn layer_editor(app: &mut EffectcraftApp, ui: &mut egui::Ui, ve: &ValueEdit<'_>, actions: &mut Vec<(String, serde_json::Value)>, value: &Value) {
+ let Value::Layer(l) = value else { return };
+ let (prop, at, uid) = (ve.prop, ve.at, ve.uid);
+ let t = app.tokens;
+ let x = at.x;
+ // 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)))
+ {
+ ve.set(actions, chosen.map(|id| json!(id)).unwrap_or(serde_json::Value::Null));
+ }
+ app.auto.add(&format!("timeline.prop.{uid}.value"), r, &prop.name);
+ }
+
+ /// Opens the Gradient Editor at the current time (#612).
+ fn gradient_editor(app: &mut EffectcraftApp, ui: &mut egui::Ui, ve: &ValueEdit<'_>, actions: &mut Vec<(String, serde_json::Value)>) {
+ let (p, layer, prop, at, uid) = (ve.p, ve.layer, ve.prop, ve.at, ve.uid);
+ let t = app.tokens;
+ let x = at.x;
+ // 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);
+ }
+ 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})));
+ }
+ }
+
#[cfg(test)]
mod tests;