Skip to content

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

Merge main into fix/1190-checkbox-drag

Claudeb2ab66ec47c3
diff --cc crates/ui-egui/src/header.rs
index 571229007,3eee89453..11af34d59
--- a/crates/ui-egui/src/header.rs
+++ b/crates/ui-egui/src/header.rs
@@@ -174,7 -218,7 +218,7 @@@ fn snapping_toggle(app: &mut Effectcraf
let snap = Rect::from_min_size(pos2(x, cy - 10.0), vec2(20.0, 20.0));
// The engine owns snapping (View ▸ Snapping); the checkbox mirrors it.
app.ui.snapping = app.session.state.snapping;
- if widgets::checkbox(ui, snap, app.ui.snapping, &t, egui::Id::new("snapping")).changed() {
- if widgets::checkbox(ui, snap, app.ui.snapping, &t, egui::Id::unique("snapping")).clicked() {
++ if widgets::checkbox(ui, snap, app.ui.snapping, &t, egui::Id::unique("snapping")).changed() {
let _ = app.session.execute("view.snapping", serde_json::json!({}));
app.ui.snapping = app.session.state.snapping;
}
@@@ -591,7 -685,7 +685,7 @@@ fn puppet_options(app: &mut Effectcraft
p.text(pos2(x, cy), Align2::LEFT_CENTER, tr("Mesh:"), Tokens::ui(12.0), t.text_dim);
x += 40.0;
let show = Rect::from_min_size(pos2(x, cy - 10.0), vec2(20.0, 20.0));
- if widgets::checkbox(ui, show, o.show_mesh, &t, egui::Id::new("puppet-show-mesh")).changed() {
- if widgets::checkbox(ui, show, o.show_mesh, &t, egui::Id::unique("puppet-show-mesh")).clicked() {
++ if widgets::checkbox(ui, show, o.show_mesh, &t, egui::Id::unique("puppet-show-mesh")).changed() {
let _ = app.session.execute("puppet.mesh", json!({"showMesh": !o.show_mesh}));
}
app.auto.add("header.puppet.showMesh", show, "Show mesh");
diff --cc crates/ui-egui/src/panels/anim_tools.rs
index 8d4066a7f,b07da8567..800261f36
--- a/crates/ui-egui/src/panels/anim_tools.rs
+++ b/crates/ui-egui/src/panels/anim_tools.rs
@@@ -41,7 -45,7 +45,7 @@@ fn number(app: &mut EffectcraftApp, ui
fn checkbox(app: &mut EffectcraftApp, ui: &mut egui::Ui, at: egui::Pos2, auto: &str, text: &str, on: bool) -> bool {
let t = app.tokens;
let r = Rect::from_min_size(at, vec2(16.0, 16.0));
- let clicked = widgets::checkbox(ui, r, on, &t, egui::Id::new(("animtool-cb", auto))).changed();
- let clicked = widgets::checkbox(ui, r, on, &t, egui::Id::unique(("animtool-cb", auto))).clicked();
++ let clicked = widgets::checkbox(ui, r, on, &t, egui::Id::unique(("animtool-cb", auto))).changed();
ui.painter().text(pos2(r.max.x + 6.0, r.center().y), Align2::LEFT_CENTER, text, Tokens::ui(12.0), t.text);
app.auto.add(auto, r, text);
if clicked { !on } else { on }
diff --cc crates/ui-egui/src/panels/effect_controls/rows.rs
index 000000000,05fea44c9..991d63f62
mode 000000,100644..100644
--- a/crates/ui-egui/src/panels/effect_controls/rows.rs
+++ b/crates/ui-egui/src/panels/effect_controls/rows.rs
@@@ -1,0 -1,726 +1,726 @@@
+ use super::common::{Actions, DIAL_ROW, PARAM_NAME_X, ROW, TREE_INDENT, gesture_key};
+ use super::{
+ Align2, Color32, EffectcraftApp, EvalCtx, FxPick, Icon, Layer, Node, ParamUi, PropGroup, Property, Rect, Sense, Stroke, Tokens, Value, fw, icons, json,
+ pos2, vec2, widgets,
+ };
+
+ fn triangle(p: &egui::Painter, c: egui::Pos2, left: bool, col: Color32) {
+ let (dx, h) = (if left { -3.5 } else { 3.5 }, 4.0);
+ p.add(egui::Shape::convex_polygon(vec![pos2(c.x + dx, c.y), pos2(c.x - dx, c.y - h), pos2(c.x - dx, c.y + h)], col, Stroke::NONE));
+ }
+
+ /// The layer and whether the time is on a key, for the key navigator.
+ #[derive(Clone, Copy)]
+ struct KeyNav {
+ layer_id: u64,
+ on_key: bool,
+ }
+
+ /// ◀ ◆ ▶ at the right end of an animated parameter's row.
+ fn key_navigator(app: &mut EffectcraftApp, ui: &mut egui::Ui, p: &egui::Painter, nav: KeyNav, prop: &Property, r: Rect, actions: &mut Actions) {
+ let KeyNav { layer_id, on_key } = nav;
+ let t = app.tokens;
+ let cy = r.center().y;
+ let uid = prop.uid;
+ for (what, dx) in [("prev", -44.0), ("key", -32.0), ("next", -20.0)] {
+ let cr = Rect::from_center_size(pos2(r.max.x + dx, cy), vec2(12.0, 16.0));
+ let resp = ui.interact(cr, egui::Id::unique(("ec-nav", uid, what)), Sense::click());
+ let col = if resp.hovered() { t.text } else { t.text_dim };
+ match what {
+ "prev" => triangle(p, cr.center(), true, col),
+ "next" => triangle(p, cr.center(), false, col),
+ _ => {
+ let kr = Rect::from_center_size(cr.center(), vec2(10.0, 10.0));
+ if on_key {
+ icons::paint(p, kr, Icon::Keyframe, t.keyframe);
+ } else {
+ let c = kr.center();
+ let d = 4.5;
+ p.add(egui::Shape::closed_line(
+ vec![pos2(c.x, c.y - d), pos2(c.x + d, c.y), pos2(c.x, c.y + d), pos2(c.x - d, c.y)],
+ Stroke::new(1.0, col),
+ ));
+ }
+ }
+ }
+ app.auto.add(&format!("effectControls.prop.{uid}.{what}Key"), cr, &prop.name);
+ if resp.clicked() {
+ match what {
+ "prev" => actions.push(("time.go".into(), json!({"to": "prevKey", "prop": uid}))),
+ "next" => actions.push(("time.go".into(), json!({"to": "nextKey", "prop": uid}))),
+ _ => actions.push(("prop.toggleKey".into(), json!({"layer": layer_id, "prop": uid, "selected": true}))),
+ }
+ }
+ }
+ }
+
+ /// Toggle a viewer pick (crosshair / eyedropper) for a parameter (also the Timeline's colour
+ /// eyedroppers).
+ pub(crate) fn toggle_pick(app: &mut EffectcraftApp, kind: &str, layer: &Layer, prop: &Property) {
+ let pick = FxPick { kind: kind.into(), layer: layer.id.0, prop: prop.uid, name: prop.name.clone() };
+ if app.ui.fx_pick.as_ref() == Some(&pick) {
+ app.ui.fx_pick = None;
+ } else {
+ app.ui.fx_pick = Some(pick);
+ app.ui.text_color_pick = None;
+ app.ui.status = if kind == "point" {
+ format!("Click in the Composition panel to set {}", prop.name)
+ } else {
+ format!("Click in the Composition panel to sample {}", prop.name)
+ };
+ }
+ }
+
+ /// 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<'_> {
+ 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)]
+ fn prop_row(
+ app: &mut EffectcraftApp,
+ ui: &mut egui::Ui,
+ p: &egui::Painter,
+ layer: &Layer,
+ group: &PropGroup,
+ prop: &Property,
+ ectx: &EvalCtx,
+ r: Rect,
+ indent: f32,
+ actions: &mut Actions,
+ ) -> Vec<Rect> {
+ let t = app.tokens;
+ let mut dims = vec![];
+ let cy = r.center().y;
+ let uid = prop.uid;
+ if ui.input(|i| i.pointer.primary_pressed()) && ui.rect_contains_pointer(r) {
+ let add = ui.input(|i| i.modifiers.shift || i.modifiers.command);
+ actions.push(("prop.select".into(), json!({"layer": layer.id.0, "prop": uid, "add": add})));
+ }
+ let swr = Rect::from_center_size(pos2(r.min.x + indent, cy), vec2(14.0, 14.0));
+ if !prop.static_only && !matches!(prop.ui, ParamUi::Hidden) {
+ let resp = ui.interact(swr, egui::Id::unique(("ec-sw", uid)), Sense::click());
+ icons::paint(
+ p,
+ swr,
+ Icon::Stopwatch,
+ if prop.is_animated() {
+ t.hot_text
+ } else if resp.hovered() {
+ t.text
+ } else {
+ t.text_dim
+ },
+ );
+ app.auto.add(&format!("effectControls.prop.{uid}.stopwatch"), swr, &prop.name);
+ if resp.clicked() {
+ actions.push(("prop.toggleAnimation".into(), json!({"layer": layer.id.0, "prop": uid, "selected": true})));
+ }
+ }
+ if prop.is_animated() {
+ let half = ectx.comp.frame_duration().0 / 2;
+ let on_key = prop.keys.iter().any(|k| (layer.comp_time(k.time).0 - ectx.time.0).abs() <= half);
+ key_navigator(app, ui, p, KeyNav { layer_id: layer.id.0, on_key }, prop, r, actions);
+ }
+ let value = ectx.value(layer, prop);
+ // Keep a shared value column while names and their icons follow the group hierarchy.
+ // Extremely deep groups still leave a little name space before their value.
+ let vx = (r.min.x + r.width() * 0.48).max(r.min.x + PARAM_NAME_X + 124.0).max(swr.max.x + 40.0);
+ // A vector's values end before the keyframe navigator: in a narrow panel they move left over
+ // the name (cut short) instead of running under the navigator (#271).
+ let vx = match &value {
+ Value::Vec2(_) | Value::Vec3(_) => {
+ let point = if matches!(prop.ui, ParamUi::Point | ParamUi::Point3) { 22.0 } else { 0.0 };
+ let fields: f32 = value
+ .components()
+ .iter()
+ .take(shown_dims(layer, prop, &value))
+ .map(|v| p.layout_no_wrap(format!("{v:.1}"), Tokens::ui(12.0), t.hot_text).size().x + 12.0)
+ .sum();
+ let right = r.max.x - if prop.is_animated() { 52.0 } else { 8.0 };
+ vx.min(right - point - fields + 8.0).max(swr.max.x + 60.0)
+ }
+ _ => vx,
+ };
+ let name_clip = Rect::from_min_max(pos2(swr.max.x + 6.0, r.min.y), pos2(vx - 6.0, r.max.y));
+ app.auto.add(&format!("effectControls.prop.{uid}.name"), name_clip, &prop.name);
+ p.with_clip_rect(name_clip.intersect(p.clip_rect())).text(pos2(swr.max.x + 6.0, cy), Align2::LEFT_CENTER, &prop.name, Tokens::ui(12.0), t.text);
+ let name_response = ui.interact(name_clip, egui::Id::unique(("ec-prop-name", uid)), Sense::click());
+ if name_response.double_clicked() {
+ app.ui.timeline.search.clear();
+ app.ui.timeline.scroll_to = Some(crate::state::ScrollTo::Property(uid));
+ if let Err(e) = crate::menus::frontend(app, ui.ctx(), "timeline.revealProps", json!({"props": [{"layer": layer.id.0, "prop": uid}]})) {
+ app.ui.status = e;
+ }
+ app.show_panel(crate::dock::PanelKind::Timeline);
+ }
+ app.auto.add(&format!("effectControls.prop.{uid}.name"), name_clip, &prop.name);
+ // 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 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 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;
+ };
+ 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);
+ 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 (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,
+ );
+ 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 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],
+ &widgets::HotSpec { speed: 1.0, range: (-1e9, 1e9), decimals: 1, suffix: "" },
+ &t,
+ );
+ 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]);
+ }
+ }
+ 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() {
++ if widgets::checkbox(ui, cr, *b, &t, egui::Id::unique(("ec-b", uid))).changed() {
+ 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);
+ }
+ 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));
+ }
+ }
+ }
+
+ 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));
+ }
+ 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})));
+ }
+ }
+ }
+ }
+
+ 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})));
+ }
+ }
+ None => app.ui.status = "no file dialog available: set the path with prop.set".into(),
+ }
+ }
+ 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));
+ }
+ }
+
+ 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).
+ fn shown_dims(layer: &Layer, prop: &Property, value: &Value) -> usize {
+ let n = value.components().len();
+ if prop.shown_dims > 0 && !(layer.is_3d() && n == 3) { prop.shown_dims as usize } else { n }
+ }
+
+ /// Colour of a gradient at `f` (colour stops only).
+ fn gradient_at(g: &effectcraft_engine::keyframe::Gradient, f: f64) -> Color32 {
+ let stops = &g.colors;
+ let c = if stops.is_empty() {
+ [0.0, 0.0, 0.0, 1.0]
+ } else if f <= stops[0].0 {
+ stops[0].1
+ } else if f >= stops[stops.len() - 1].0 {
+ stops[stops.len() - 1].1
+ } else {
+ let i = stops.iter().position(|s| s.0 > f).unwrap_or(stops.len() - 1).max(1);
+ let (a, b) = (stops[i - 1], stops[i]);
+ let k = ((f - a.0) / (b.0 - a.0).max(1e-9)) as f32;
+ [0, 1, 2, 3].map(|j| a.1[j] + (b.1[j] - a.1[j]) * k)
+ };
+ Color32::from_rgb((c[0].clamp(0.0, 1.0) * 255.0) as u8, (c[1].clamp(0.0, 1.0) * 255.0) as u8, (c[2].clamp(0.0, 1.0) * 255.0) as u8)
+ }
+
+ /// The twirled-open slider under a slider param: track, knob and the slider range's ends.
+ #[allow(clippy::too_many_arguments)]
+ fn slider_row(
+ app: &mut EffectcraftApp,
+ ui: &mut egui::Ui,
+ p: &egui::Painter,
+ layer: &Layer,
+ prop: &Property,
+ ectx: &EvalCtx,
+ r: Rect,
+ x0: f32,
+ actions: &mut Actions,
+ ) {
+ let t = app.tokens;
+ let ParamUi::Slider { slider_min, slider_max, decimals, .. } = prop.ui else { return };
+ let Value::Scalar(v) = ectx.value(layer, prop) else { return };
+ let uid = prop.uid;
+ let tr = Rect::from_min_max(pos2(r.min.x + x0, r.min.y + 8.0), pos2(r.max.x - 16.0, r.min.y + 12.0));
+ if tr.width() < 40.0 {
+ return;
+ }
+ p.rect_filled(tr, 2.0, t.field_bg);
+ let f = ((v - slider_min) / (slider_max - slider_min)).clamp(0.0, 1.0) as f32;
+ p.rect_filled(Rect::from_min_max(tr.min, pos2(tr.min.x + tr.width() * f, tr.max.y)), 2.0, t.accent.gamma_multiply(0.7));
+ p.circle_filled(pos2(tr.min.x + tr.width() * f, tr.center().y), 5.0, t.text);
+ let dec = decimals as usize;
+ p.text(pos2(tr.min.x, tr.max.y + 4.0), Align2::LEFT_TOP, format!("{slider_min:.dec$}"), Tokens::ui(10.5), t.text_dim);
+ p.text(pos2(tr.max.x, tr.max.y + 4.0), Align2::RIGHT_TOP, format!("{slider_max:.dec$}"), Tokens::ui(10.5), t.text_dim);
+ let sresp = ui.interact(tr.expand2(vec2(4.0, 6.0)), egui::Id::unique(("ec-slider", uid)), Sense::click_and_drag());
+ app.auto.add(&format!("effectControls.prop.{uid}.slider"), tr, &prop.name);
+ if (sresp.dragged() || sresp.clicked())
+ && let Some(pt) = sresp.interact_pointer_pos()
+ {
+ let f = ((pt.x - tr.min.x) / tr.width()).clamp(0.0, 1.0) as f64;
+ actions.push((
+ "prop.set".into(),
+ json!({"layer": layer.id.0, "prop": uid, "value": slider_min + (slider_max - slider_min) * f, "merge": format!("ec-{uid}")}),
+ ));
+ }
+ }
+
+ /// The twirled-open angle dial under an angle param.
+ #[allow(clippy::too_many_arguments)]
+ fn dial_row(app: &mut EffectcraftApp, ui: &mut egui::Ui, layer: &Layer, prop: &Property, ectx: &EvalCtx, r: Rect, x0: f32, actions: &mut Actions) {
+ let t = app.tokens;
+ let Value::Scalar(v) = ectx.value(layer, prop) else { return };
+ let uid = prop.uid;
+ let d = (r.height() - 12.0).min(52.0);
+ let dr = Rect::from_min_size(pos2(r.min.x + x0 + 40.0, r.min.y + 6.0), vec2(d, d));
+ let id = egui::Id::unique(("ec-dial", uid));
+ let (resp, nv) = fw::angle_dial(ui, dr, v, id, &t);
+ app.auto.add(&format!("effectControls.prop.{uid}.dial"), dr, &prop.name);
+ if let Some(nv) = nv {
+ let key = gesture_key(ui, id, resp.drag_started() || resp.clicked());
+ actions.push(("prop.set".into(), json!({"layer": layer.id.0, "prop": uid, "value": nv, "merge": key})));
+ }
+ }
+
+ /// The effect instance a row belongs to, for conditional visibility
+ /// ([`effectcraft_engine::effects::catalog::param_shown`]): effect id, the instance's root
+ /// group and the spec-id path of the group being drawn (`""` or `cameraPosition/`).
+ pub(super) struct FxScope<'a> {
+ pub(super) effect: &'a str,
+ pub(super) root: &'a PropGroup,
+ pub(super) path: String,
+ }
+
+ impl<'a> FxScope<'a> {
+ pub(super) fn sub(&self, m: &str) -> FxScope<'a> {
+ FxScope { effect: self.effect, root: self.root, path: format!("{}{m}/", self.path) }
+ }
+ /// Whether child `m` of the current group is shown.
+ pub(super) fn shown(&self, layer: &Layer, ectx: &EvalCtx, m: &str) -> bool {
+ let root = self.root;
+ let value = |id: &str| -> Option<Value> {
+ let mut g = root;
+ let mut parts = id.split('/').peekable();
+ while let Some(part) = parts.next() {
+ if parts.peek().is_none() {
+ return g.get(part).map(|p| ectx.value(layer, p));
+ }
+ g = g.sub(part)?;
+ }
+ None
+ };
+ effectcraft_engine::effects::catalog::param_shown(self.effect, &format!("{}{m}", self.path), &value)
+ }
+ }
+
+ /// Twirl `g` closed (it was `open`) or open; with `all` (Alt/Cmd-click) every group under it follows.
+ pub(super) fn toggle_closed(app: &mut EffectcraftApp, g: &PropGroup, open: bool, all: bool) {
+ fn walk(g: &PropGroup, out: &mut Vec<u64>) {
+ for sg in g.groups() {
+ out.push(sg.uid);
+ walk(sg, out);
+ }
+ }
+ let mut uids = vec![g.uid];
+ if all {
+ walk(g, &mut uids);
+ }
+ for u in uids {
+ if open {
+ app.ui.fx_closed.insert(u);
+ } else {
+ app.ui.fx_closed.remove(&u);
+ }
+ }
+ }
+
+ /// Lays out one property group's rows below `*y` (which it advances), recursing into open
+ /// subgroups: one row per visible property with its controls, plus the dial or slider row when its
+ /// slider is open, and an inline editor for groups that have one. Rows scrolled out of `rect` are
+ /// skipped without being drawn or registered, though their height is still counted. Pick-whip
+ /// drops are registered for each visible property; edits go on `actions`.
+ #[allow(clippy::too_many_arguments)]
+ pub(super) fn group_rows(
+ app: &mut EffectcraftApp,
+ ui: &mut egui::Ui,
+ p: &egui::Painter,
+ layer: &Layer,
+ g: &PropGroup,
+ ectx: &EvalCtx,
+ rect: Rect,
+ y: &mut f32,
+ depth: usize,
+ fx: &FxScope,
+ actions: &mut Actions,
+ ) {
+ let t = app.tokens;
+ for c in &g.children {
+ let r = Rect::from_min_size(pos2(rect.min.x, *y), vec2(rect.width(), ROW));
+ match c {
+ Node::Prop(pr) => {
+ if matches!(pr.ui, ParamUi::Hidden) || pr.three_d_only && !layer.is_3d() || !fx.shown(layer, ectx, &pr.match_id) {
+ continue;
+ }
+ *y += ROW;
+ let indent = PARAM_NAME_X - 13.0 + TREE_INDENT * depth as f32;
+ let visible = !(r.max.y < rect.min.y || r.min.y > rect.max.y);
+ if visible {
+ app.auto.add(&format!("effectControls.row.{}", pr.uid), r, &pr.name);
+ let dims = prop_row(app, ui, p, layer, g, pr, ectx, r, indent, actions);
+ // A Timeline pick whip can be dropped here (After Effects).
+ crate::panels::timeline::whip_target(ui.ctx(), r.intersect(rect), layer.id.0, pr.uid, dims);
+ }
+ if app.ui.fx_slider_open.contains(&pr.uid) {
+ if matches!(pr.ui, ParamUi::Angle) {
+ let sr = Rect::from_min_size(pos2(rect.min.x, *y), vec2(rect.width(), DIAL_ROW));
+ *y += DIAL_ROW;
+ if sr.max.y >= rect.min.y && sr.min.y <= rect.max.y {
+ dial_row(app, ui, layer, pr, ectx, sr, indent + 22.0, actions);
+ }
+ } else if matches!(pr.ui, ParamUi::Slider { .. }) {
+ let sr = Rect::from_min_size(pos2(rect.min.x, *y), vec2(rect.width(), 34.0));
+ *y += 34.0;
+ if sr.max.y >= rect.min.y && sr.min.y <= rect.max.y {
+ slider_row(app, ui, p, layer, pr, ectx, sr, indent + 22.0, actions);
+ }
+ }
+ }
+ }
+ Node::Group(sg) => {
+ // Paint strokes live in the Timeline only (AE's Paint shows Paint on Transparent).
+ if effectcraft_engine::effects::paint::is_paint(g) || !fx.shown(layer, ectx, &sg.match_id) {
+ continue;
+ }
+ *y += ROW;
+ let open = !app.ui.fx_closed.contains(&sg.uid);
+ let tw = Rect::from_center_size(pos2(r.min.x + PARAM_NAME_X - 12.0 + TREE_INDENT * depth as f32, r.center().y), vec2(12.0, 12.0));
+ if r.max.y >= rect.min.y && r.min.y <= rect.max.y {
+ app.auto.add(&format!("effectControls.row.{}", sg.uid), r, &sg.name);
+ app.auto.add(&format!("effectControls.group.{}.twirl", sg.uid), tw, &sg.name);
+ if widgets::twirl(ui, tw, open, egui::Id::unique(("ec-g", sg.uid)), &t).clicked() {
+ toggle_closed(app, sg, open, ui.input(|i| i.modifiers.alt || i.modifiers.command));
+ }
+ let name = p.text(pos2(tw.max.x + 6.0, r.center().y), Align2::LEFT_CENTER, &sg.name, Tokens::ui(12.0), t.text);
+ app.auto.add(&format!("effectControls.group.{}.name", sg.uid), name, &sg.name);
+ }
+ if open {
+ let sub = fx.sub(&sg.match_id);
+ // A visual editor for the group's hidden parameters (Lumetri curves, …).
+ let eh = crate::panels::fx_editors::inline_height(fx.effect, &sub.path, rect.width());
+ if eh > 0.0 {
+ let er = Rect::from_min_size(pos2(rect.min.x, *y), vec2(rect.width(), eh));
+ *y += eh;
+ if er.max.y >= rect.min.y && er.min.y <= rect.max.y {
+ crate::panels::fx_editors::inline_editor(app, ui, p, layer, fx.root, sg, fx.effect, &sub.path, ectx, er, actions);
+ }
+ }
+ group_rows(app, ui, p, layer, sg, ectx, rect, y, depth + 1, &sub, actions);
+ }
+ }
+ }
+ }
+ }
diff --cc crates/ui-egui/src/panels/misc.rs
index 5a1b77c07,dfa9a42e0..8dc99e5fd
--- a/crates/ui-egui/src/panels/misc.rs
+++ b/crates/ui-egui/src/panels/misc.rs
@@@ -240,7 -260,7 +260,7 @@@ fn fmt_rate(r: f64) -> String
fn check_row(app: &mut EffectcraftApp, ui: &mut egui::Ui, p: &egui::Painter, at: egui::Pos2, key: &str, text: &str, on: bool) -> bool {
let t = app.tokens;
let r = Rect::from_min_size(pos2(at.x, at.y - 8.0), vec2(16.0, 16.0));
- let clicked = widgets::checkbox(ui, r, on, &t, egui::Id::new(("pv-check", key))).changed();
- let clicked = widgets::checkbox(ui, r, on, &t, egui::Id::unique(("pv-check", key))).clicked();
++ let clicked = widgets::checkbox(ui, r, on, &t, egui::Id::unique(("pv-check", key))).changed();
p.text(pos2(r.max.x + 5.0, at.y), Align2::LEFT_CENTER, text, Tokens::ui(12.0), t.text);
app.auto.add(&format!("preview.{key}"), r, text);
clicked
diff --cc crates/ui-egui/src/panels/paint_panels.rs
index 3c9332aea,c867eb63a..edf12ed7a
--- a/crates/ui-egui/src/panels/paint_panels.rs
+++ b/crates/ui-egui/src/panels/paint_panels.rs
@@@ -210,7 -239,7 +239,7 @@@ pub fn paint(app: &mut EffectcraftApp,
.enumerate()
{
let r = Rect::from_min_size(pos2(x0 + i as f32 * (w / 2.0), y), vec2(18.0, 20.0));
- if widgets::checkbox(ui, r, on, &t, egui::Id::new(key)).changed() {
- if widgets::checkbox(ui, r, on, &t, egui::Id::unique(key)).clicked() {
++ if widgets::checkbox(ui, r, on, &t, egui::Id::unique(key)).changed() {
set(app, json!({k: !on}));
}
p.text(pos2(r.max.x + 4.0, r.center().y), Align2::LEFT_CENTER, label, Tokens::ui(11.5), t.text_dim);
@@@ -237,7 -273,7 +273,7 @@@
}
y += 26.0;
let r = Rect::from_min_size(pos2(x0, y), vec2(18.0, 20.0));
- if widgets::checkbox(ui, r, o.show_overlay, &t, egui::Id::new("paint.showOverlay")).changed() {
- if widgets::checkbox(ui, r, o.show_overlay, &t, egui::Id::unique("paint.showOverlay")).clicked() {
++ if widgets::checkbox(ui, r, o.show_overlay, &t, egui::Id::unique("paint.showOverlay")).changed() {
set(app, json!({"showOverlay": !o.show_overlay}));
}
app.auto.add("paint.showOverlay", r, "Clone Source Overlay");
@@@ -246,7 -282,7 +282,7 @@@
set(app, json!({"overlayOpacity": nv}));
}
let dr = Rect::from_min_size(pos2(x0 + w - 18.0, y), vec2(18.0, 20.0));
- if widgets::checkbox(ui, dr, o.overlay_difference, &t, egui::Id::new("paint.overlayDifference")).changed() {
- if widgets::checkbox(ui, dr, o.overlay_difference, &t, egui::Id::unique("paint.overlayDifference")).clicked() {
++ if widgets::checkbox(ui, dr, o.overlay_difference, &t, egui::Id::unique("paint.overlayDifference")).changed() {
set(app, json!({"overlayDifference": !o.overlay_difference}));
}
app.auto.add("paint.overlayDifference", dr, "Difference mode overlay");
diff --cc crates/ui-egui/src/panels/panel_kit.rs
index 06dc8b4db,501ddf64f..c1d88a417
--- a/crates/ui-egui/src/panels/panel_kit.rs
+++ b/crates/ui-egui/src/panels/panel_kit.rs
@@@ -23,7 -23,7 +23,7 @@@ pub fn dropdown(app: &mut EffectcraftAp
pub fn checkbox(app: &mut EffectcraftApp, ui: &mut egui::Ui, at: egui::Pos2, auto: &str, text: &str, on: bool) -> bool {
let t = app.tokens;
let r = Rect::from_min_size(at, vec2(16.0, 16.0));
- let clicked = widgets::checkbox(ui, r, on, &t, egui::Id::new(("kit-cb", auto))).changed();
- let clicked = widgets::checkbox(ui, r, on, &t, egui::Id::unique(("kit-cb", auto))).clicked();
++ let clicked = widgets::checkbox(ui, r, on, &t, egui::Id::unique(("kit-cb", auto))).changed();
ui.painter().text(pos2(r.max.x + 6.0, r.center().y), Align2::LEFT_CENTER, text, Tokens::ui(12.0), t.text);
let full = Rect::from_min_size(at, vec2(22.0 + text.len() as f32 * 6.5, 16.0));
app.auto.add(auto, full, text);
diff --cc crates/ui-egui/src/panels/project.rs
index 62938e635,1944f333f..36260d8d8
--- a/crates/ui-egui/src/panels/project.rs
+++ b/crates/ui-egui/src/panels/project.rs
@@@ -1094,7 -1344,7 +1344,7 @@@ fn column_menu(app: &mut EffectcraftApp
ui.label(egui::RichText::new(crate::i18n::tr("Columns")).weak());
for (key, label, _) in COLUMNS {
let mut on = app.ui.project_columns.iter().any(|c| c == key);
- if crate::widgets::labelled_checkbox(ui, &mut on, label).changed() {
- if ui.checkbox(&mut on, crate::i18n::tr(label)).changed() {
++ if crate::widgets::labelled_checkbox(ui, &mut on, crate::i18n::tr(label)).changed() {
set_column(&mut app.ui.project_columns, key, on);
}
}
diff --cc crates/ui-egui/src/panels/properties.rs
index 9939b56fa,c35108937..ee46be3e0
--- a/crates/ui-egui/src/panels/properties.rs
+++ b/crates/ui-egui/src/panels/properties.rs
@@@ -402,7 -445,7 +445,7 @@@ fn text_section
for (i, (key, label, on, c)) in [("fill", "Fill", doc.apply_fill, doc.fill), ("stroke", "Stroke", doc.apply_stroke, doc.stroke)].into_iter().enumerate() {
let ry = y + i as f32 * 24.0;
let cr = Rect::from_min_size(pos2(x0, ry + 2.0), vec2(14.0, 14.0));
- if widgets::checkbox(ui, cr, on, &t, egui::Id::new(("props-apply", key))).changed() {
- if widgets::checkbox(ui, cr, on, &t, egui::Id::unique(("props-apply", key))).clicked() {
++ if widgets::checkbox(ui, cr, on, &t, egui::Id::unique(("props-apply", key))).changed() {
let k = if key == "fill" { "applyFill" } else { "applyStroke" };
set(actions, json!({k: !on}));
}
diff --cc crates/ui-egui/src/panels/render_queue.rs
index 539fb2af1,5e39a30c2..75ada9a99
--- a/crates/ui-egui/src/panels/render_queue.rs
+++ b/crates/ui-egui/src/panels/render_queue.rs
@@@ -463,7 -481,7 +481,7 @@@ fn current_render_strip(app: &mut Effec
// Notify (sound + notification when the queue finishes).
let notify = app.session.project.render_prefs.notify;
let nb = Rect::from_min_size(pos2(render_b.min.x - 8.0 - 2.0 * bw - 8.0, render_b.min.y + 4.0), vec2(18.0, 18.0));
- if widgets::checkbox(ui, nb, notify, &t, egui::Id::new("rq-notify")).changed() {
- if widgets::checkbox(ui, nb, notify, &t, egui::Id::unique("rq-notify")).clicked() {
++ if widgets::checkbox(ui, nb, notify, &t, egui::Id::unique("rq-notify")).changed() {
actions.push(("renderQueue.setNotify", json!({"notify": !notify})));
}
p.text(pos2(nb.max.x + 5.0, nb.center().y), Align2::LEFT_CENTER, tr("Notify"), Tokens::ui(11.5), t.text_dim);
@@@ -589,7 -777,7 +777,7 @@@ pub fn show(app: &mut EffectcraftApp, u
}
app.auto.add(&aid("twirl"), tw, "Twirl");
let cb = Rect::from_center_size(pos2(cx_render + 20.0, row.center().y), vec2(18.0, 18.0));
- if ui.add_enabled_ui(!rendering, |ui| widgets::checkbox(ui, cb, it.render, &t, egui::Id::new(("rq-cb", it.id)))).inner.changed() && !rendering {
- if widgets::checkbox(ui, cb, it.render, &t, egui::Id::unique(("rq-cb", it.id))).clicked() && !rendering {
++ if ui.add_enabled_ui(!rendering, |ui| widgets::checkbox(ui, cb, it.render, &t, egui::Id::unique(("rq-cb", it.id)))).inner.changed() && !rendering {
actions.push(("renderQueue.setRender", json!({"item": it.id, "render": !it.render})));
}
app.auto.add(&aid("render"), cb, if it.render { "Render: on" } else { "Render: off" });
diff --cc crates/ui-egui/src/panels/text_panels.rs
index fd5e4e17b,8a8e604e2..fed0a6206
--- a/crates/ui-egui/src/panels/text_panels.rs
+++ b/crates/ui-egui/src/panels/text_panels.rs
@@@ -188,7 -229,7 +229,7 @@@ pub fn character(app: &mut EffectcraftA
for (i, (key, label, on, c)) in [("fill", "Fill", doc.apply_fill, doc.fill), ("stroke", "Stroke", doc.apply_stroke, doc.stroke)].into_iter().enumerate() {
let fx = x0 + i as f32 * (w / 2.0);
let cr = Rect::from_min_size(pos2(fx, y + 3.0), vec2(14.0, 14.0));
- if ui.add_enabled_ui(enabled, |ui| widgets::checkbox(ui, cr, on, &t, egui::Id::new(("char-apply", key)))).inner.changed() && enabled {
- if widgets::checkbox(ui, cr, on, &t, egui::Id::unique(("char-apply", key))).clicked() && enabled {
++ if ui.add_enabled_ui(enabled, |ui| widgets::checkbox(ui, cr, on, &t, egui::Id::unique(("char-apply", key)))).inner.changed() && enabled {
actions.push(json!({if key == "fill" { "applyFill" } else { "applyStroke" }: !on}));
}
app.auto.add(&format!("character.{key}.enabled"), cr, label);
@@@ -240,7 -281,7 +281,7 @@@
y += 32.0;
// Ligatures.
let lr = Rect::from_min_size(pos2(x0, y), vec2(14.0, 14.0));
- if ui.add_enabled_ui(enabled, |ui| widgets::checkbox(ui, lr, doc.ligatures, &t, egui::Id::new("char-ligatures"))).inner.changed() && enabled {
- if widgets::checkbox(ui, lr, doc.ligatures, &t, egui::Id::unique("char-ligatures")).clicked() && enabled {
++ if ui.add_enabled_ui(enabled, |ui| widgets::checkbox(ui, lr, doc.ligatures, &t, egui::Id::unique("char-ligatures"))).inner.changed() && enabled {
actions.push(json!({"ligatures": !doc.ligatures}));
}
app.auto.add("character.ligatures", lr, "Ligatures");
@@@ -264,7 -305,7 +305,7 @@@
.enumerate()
{
let cr = Rect::from_min_size(pos2(x0 + i as f32 * 120.0, y), vec2(14.0, 14.0));
- if ui.add_enabled_ui(enabled, |ui| widgets::checkbox(ui, cr, on, &t, egui::Id::new(("char-vert", key)))).inner.changed() && enabled {
- if widgets::checkbox(ui, cr, on, &t, egui::Id::unique(("char-vert", key))).clicked() && enabled {
++ if ui.add_enabled_ui(enabled, |ui| widgets::checkbox(ui, cr, on, &t, egui::Id::unique(("char-vert", key)))).inner.changed() && enabled {
actions.push(json!({key: !on}));
}
app.auto.add(&format!("character.{key}"), cr, label);
@@@ -544,7 -605,7 +605,7 @@@ pub fn paragraph(app: &mut EffectcraftA
}
y += 30.0;
let hr = Rect::from_min_size(pos2(x0, y), vec2(14.0, 14.0));
- if ui.add_enabled_ui(enabled, |ui| widgets::checkbox(ui, hr, doc.hanging_punctuation, &t, egui::Id::new("para-hanging"))).inner.changed() && enabled {
- if widgets::checkbox(ui, hr, doc.hanging_punctuation, &t, egui::Id::unique("para-hanging")).clicked() && enabled {
++ if ui.add_enabled_ui(enabled, |ui| widgets::checkbox(ui, hr, doc.hanging_punctuation, &t, egui::Id::unique("para-hanging"))).inner.changed() && enabled {
actions.push(json!({"hangingPunctuation": !doc.hanging_punctuation}));
}
app.auto.add("paragraph.hangingPunctuation", hr, "Roman Hanging Punctuation");
@@@ -616,128 -680,131 +680,129 @@@ pub(super) fn font_picker(app: &mut Eff
return None;
}
app.auto.add(&format!("{auto}.toggle"), arrow, "Close font list");
- let mut chosen = None;
- let screen = ui.ctx().content_rect();
- let below = screen.bottom() - rect.bottom() - 16.0;
- let above = below < 100.0 && rect.top() - screen.top() > below;
- let max_height = (if above { rect.top() - screen.top() - 16.0 } else { below }).clamp(28.0, 380.0);
- let anchor = if above { rect.left_top() } else { rect.left_bottom() };
- let pivot = if above { Align2::LEFT_BOTTOM } else { Align2::LEFT_TOP };
widgets::note_open_popup_list(ui.ctx());
- let area = egui::Area::new(id.with("area")).order(egui::Order::Foreground).pivot(pivot).fixed_pos(anchor).show(ui.ctx(), |ui| {
- egui::Frame::popup(ui.style()).show(ui, |ui| {
- ui.set_width(rect.width().max(180.0));
- // Filter row: a checkbox that keeps only the variable fonts.
- let filter_h = 22.0;
- let row = ui.add_sized([ui.available_width(), filter_h], widgets::DragCheckbox::new(&mut only_variable, tr("Variable fonts only")));
- app.auto.add(&format!("{auto}.variable"), row.rect, "Variable fonts only");
- let toggled = row.changed();
- if toggled {
- ui.data_mut(|d| d.insert_temp(variable_id, only_variable));
- }
- // The native checkbox can take focus on release after changing on press.
- // Typing goes on into the search field after either event.
- if toggled || row.clicked() {
- ui.memory_mut(|m| m.request_focus(search_id));
- }
- let query = state.query.trim().to_lowercase();
- let mut seen = std::collections::HashSet::new();
- let filtered: Vec<_> = rows
- .iter()
- .filter(|r| {
- !r.family.is_empty()
- && (!only_variable || r.variable)
- && (query.is_empty()
- || ((r.family.to_lowercase().contains(&query) || r.display.to_lowercase().contains(&query)) && seen.insert(&r.family)))
- })
- .collect();
- if fresh {
- state.selected = filtered.iter().position(|r| r.family == current).unwrap_or(0);
- }
- if search.changed() || toggled {
- state.selected = 0;
- }
- let last = filtered.len().saturating_sub(1);
- state.selected = state.selected.min(last);
- if down {
- state.selected = state.selected.saturating_add(1).min(last);
- }
- if up {
- state.selected = state.selected.saturating_sub(1);
+ let changed = search.changed();
+ let mut open = true;
+ // The search lives in the field; the menu's header is the filter row, its list the fonts.
+ let menu = craft_ui::combo::Menu::new(ui, &search)
+ .open(&mut open)
+ .height(380.0)
+ .close_behavior(egui::PopupCloseBehavior::CloseOnClickOutside)
+ .style(egui::style::StyleModifier::default());
+ let app_ref = &mut *app;
+ let header = |ui: &mut egui::Ui| {
+ ui.set_width(rect.width().max(180.0));
+ // Filter row: a checkbox that keeps only the variable fonts.
+ let filter_h = 22.0;
- let row = ui.add_sized([ui.available_width(), filter_h], egui::Button::selectable(false, ""));
- let box_rect = Rect::from_min_size(row.rect.min, vec2(18.0, filter_h));
- let label_rect = Rect::from_min_max(pos2(box_rect.max.x + 2.0, row.rect.min.y), row.rect.max);
- let boxed = widgets::checkbox(ui, box_rect, only_variable, &t, id.with("variable-check"));
- ui.painter().text(label_rect.left_center(), Align2::LEFT_CENTER, tr("Variable fonts only"), Tokens::ui(11.5), t.text);
++ let row = ui.add_sized([ui.available_width(), filter_h], widgets::DragCheckbox::new(&mut only_variable, tr("Variable fonts only")));
+ app_ref.auto.add(&format!("{auto}.variable"), row.rect, "Variable fonts only");
- let toggled = row.clicked() || boxed.clicked();
++ let toggled = row.changed();
+ if toggled {
- only_variable = !only_variable;
+ ui.data_mut(|d| d.insert_temp(variable_id, only_variable));
- // Typing goes on into the search field.
++ }
++ // The native checkbox can take focus on release after changing on press.
++ // Typing goes on into the search field after either event.
++ if toggled || row.clicked() {
+ ui.memory_mut(|m| m.request_focus(search_id));
+ }
+ let query = state.query.trim().to_lowercase();
+ let mut seen = std::collections::HashSet::new();
+ let filtered: Vec<_> = rows
+ .iter()
+ .filter(|r| {
+ !r.family.is_empty()
+ && (!only_variable || r.variable)
+ && (query.is_empty() || ((r.family.to_lowercase().contains(&query) || r.display.to_lowercase().contains(&query)) && seen.insert(&r.family)))
+ })
+ .collect();
+ if fresh {
+ state.selected = filtered.iter().position(|r| r.family == current).unwrap_or(0);
+ }
+ if changed || toggled {
+ state.selected = 0;
+ }
+ let last = filtered.len().saturating_sub(1);
+ state.selected = state.selected.min(last);
+ if down {
+ state.selected = state.selected.saturating_add(1).min(last);
+ }
+ if up {
+ state.selected = state.selected.saturating_sub(1);
+ }
+ let entered = if enter { filtered.get(state.selected).map(|r| r.family.clone()) } else { None };
+ (app_ref, filtered, query.is_empty(), state.selected, changed || toggled, entered)
+ };
+ let list = |ui: &mut egui::Ui,
+ (app, filtered, all, selected, restart, entered): (
+ &mut EffectcraftApp,
+ Vec<&effectcraft_engine::FontRow>,
+ bool,
+ usize,
+ bool,
+ Option<String>,
+ )| {
+ if restart {
+ ui.scroll_to_cursor(Some(egui::Align::TOP));
+ }
+ let mut chosen = entered;
+ if filtered.is_empty() {
+ let r = ui.label(tr("No matching fonts"));
+ app.auto.add(&format!("{auto}.empty"), r.rect, "No matching fonts");
+ }
+ let mut was_recent = false;
+ for (index, r) in filtered.iter().enumerate() {
+ if all && was_recent && !r.recent {
+ ui.separator();
}
- if enter {
- chosen = filtered.get(state.selected).map(|r| r.family.clone());
+ was_recent = r.recent;
+ let row_width = ui.available_width();
+ let label_width = if preview { (row_width - 100.0).max(40.0) } else { row_width };
+ let resp = ui.add_sized([row_width, 24.0], egui::Button::selectable(index == selected, ""));
+ resp.widget_info(|| egui::WidgetInfo::selected(egui::Role::Button, ui.is_enabled(), index == selected, &r.display));
+ let label_rect = Rect::from_min_size(resp.rect.min + vec2(5.0, 0.0), vec2(label_width - 5.0, resp.rect.height()));
+ ui.painter().with_clip_rect(label_rect.intersect(ui.clip_rect())).text(
+ label_rect.left_center(),
+ Align2::LEFT_CENTER,
+ &r.display,
+ Tokens::ui(12.0),
+ t.text,
+ );
+ if ui.is_rect_visible(resp.rect) {
+ app.auto.add(&format!("{auto}.option.{}", r.family), resp.rect, &r.display);
}
- // Give the result list its actual height even when the previous query had
- // only one row. A cached tiny Area must not collapse a reopened long list.
- let filter_room = filter_h + ui.spacing().item_spacing.y;
- let height = (filtered.len() as f32 * (24.0 + ui.spacing().item_spacing.y) + 16.0).clamp(28.0, (max_height - filter_room).max(28.0));
- // A minimum, from below the filter row (a maximum would move the cursor back up).
- ui.set_min_height(height);
- let mut scroll = egui::ScrollArea::vertical().id_salt(id.with("results")).max_height(height).min_scrolled_height(height);
- if search.changed() || toggled {
- scroll = scroll.vertical_scroll_offset(0.0);
+ if index == selected && (fresh || up || down) {
+ resp.scroll_to_me(None);
}
- scroll.show(ui, |ui| {
- if filtered.is_empty() {
- let r = ui.label(tr("No matching fonts"));
- app.auto.add(&format!("{auto}.empty"), r.rect, "No matching fonts");
- }
- let mut was_recent = false;
- for (index, r) in filtered.iter().enumerate() {
- if query.is_empty() && was_recent && !r.recent {
- ui.separator();
- }
- was_recent = r.recent;
- let row_width = ui.available_width();
- let label_width = if preview { (row_width - 100.0).max(40.0) } else { row_width };
- let resp = ui.add_sized([row_width, 24.0], egui::Button::selectable(index == state.selected, ""));
- resp.widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::SelectableLabel, ui.is_enabled(), index == state.selected, &r.display));
- let label_rect = Rect::from_min_size(resp.rect.min + vec2(5.0, 0.0), vec2(label_width - 5.0, resp.rect.height()));
- ui.painter().with_clip_rect(label_rect.intersect(ui.clip_rect())).text(
- label_rect.left_center(),
- Align2::LEFT_CENTER,
- &r.display,
- Tokens::ui(12.0),
- t.text,
- );
- if ui.is_rect_visible(resp.rect) {
- app.auto.add(&format!("{auto}.option.{}", r.family), resp.rect, &r.display);
- }
- if index == state.selected && (fresh || up || down) {
- resp.scroll_to_me(None);
+ if preview && ui.is_rect_visible(resp.rect) {
+ let key = egui::Id::unique(("font-preview", &r.family));
+ let lines: std::sync::Arc<Vec<Vec<[f32; 2]>>> = match ui.data(|d| d.get_temp(key)) {
+ Some(l) => l,
+ None => {
+ let l = std::sync::Arc::new(effectcraft_engine::font_preview(&r.family, 14.0));
+ ui.data_mut(|d| d.insert_temp(key, l.clone()));
+ l
}
- if preview && ui.is_rect_visible(resp.rect) {
- let key = egui::Id::new(("font-preview", &r.family));
- let lines: std::sync::Arc<Vec<Vec<[f32; 2]>>> = match ui.data(|d| d.get_temp(key)) {
- Some(l) => l,
- None => {
- let l = std::sync::Arc::new(effectcraft_engine::font_preview(&r.family, 14.0));
- ui.data_mut(|d| d.insert_temp(key, l.clone()));
- l
- }
- };
- // Scaled and placed to fit the row's preview column, and clipped to the row (#577).
- let room = Rect::from_min_max(pos2(resp.rect.max.x - 95.0, resp.rect.min.y + 1.0), pos2(resp.rect.max.x - 6.0, resp.rect.max.y - 1.0));
- if let Some((k, o)) = fit_preview(&lines, room, resp.rect.center().y + 5.0) {
- let painter = ui.painter().with_clip_rect(resp.rect.intersect(ui.clip_rect()));
- for poly in lines.iter() {
- let pts: Vec<egui::Pos2> =
- poly.iter().filter(|p| p[0].is_finite() && p[1].is_finite()).map(|p| (o + vec2(p[0], p[1]) * k).to_pos2()).collect();
- painter.add(egui::Shape::line(pts, egui::Stroke::new(1.0, t.text_dim)));
- }
- }
- }
- if resp.clicked() {
- chosen = Some(r.family.clone());
+ };
+ // Scaled and placed to fit the row's preview column, and clipped to the row (#577).
+ let room = Rect::from_min_max(pos2(resp.rect.max.x - 95.0, resp.rect.min.y + 1.0), pos2(resp.rect.max.x - 6.0, resp.rect.max.y - 1.0));
+ if let Some((k, o)) = fit_preview(&lines, room, resp.rect.center().y + 5.0) {
+ let painter = ui.painter().with_clip_rect(resp.rect.intersect(ui.clip_rect()));
+ for poly in lines.iter() {
+ let pts: Vec<egui::Pos2> =
+ poly.iter().filter(|p| p[0].is_finite() && p[1].is_finite()).map(|p| (o + vec2(p[0], p[1]) * k).to_pos2()).collect();
+ painter.add(egui::Shape::line(pts, egui::Stroke::new(1.0, t.text_dim)));
}
- resp.on_hover_text(&r.display);
}
- });
- });
- });
- let outside = widgets::pressed_outside(ui.ctx(), &area.response) && !ui.input(|i| i.pointer.interact_pos().is_some_and(|p| rect.contains(p)));
- if chosen.is_some() || outside || escape {
+ }
+ if resp.clicked() {
+ chosen = Some(r.family.clone());
+ }
+ resp.on_hover_text(&r.display);
+ }
+ chosen
+ };
+ let chosen = menu.show_ui_with_header(header, list).flatten();
+ if chosen.is_some() || !open || escape {
ui.data_mut(|d| {
d.insert_temp(id.with("open"), false);
d.remove::<FontSearch>(state_id);
diff --cc crates/ui-egui/src/panels/timeline.rs
index 79bfe7174,a45d8e708..65ecf2cb5
--- a/crates/ui-egui/src/panels/timeline.rs
+++ b/crates/ui-egui/src/panels/timeline.rs
@@@ -1933,1016 -2708,1453 +2708,1453 @@@ fn pick_whip_edge_scroll(app: &mut Effe
}
}
app.ui.timeline.scroll_y = app.ui.timeline.scroll_y.clamp(0.0, max_scroll);
- let snap_project = app.session.project.clone();
- let snap_expr = app.session.expr.clone();
- let ectx = EvalCtx { project: &snap_project, comp_id: cid, comp: &comp, time, expr: snap_expr.as_deref(), footage: None };
- let lp = p.with_clip_rect(rows_rect.intersect(Rect::from_min_max(rows_rect.min, pos2(graph_x0 - 1.0, rows_rect.max.y))));
- let gp = p.with_clip_rect(rows_rect.intersect(Rect::from_min_max(pos2(graph_x0, rows_rect.min.y), rows_rect.max)));
- let mut y = rows_rect.min.y - app.ui.timeline.scroll_y;
- let selected = app.session.state.selected_layers.clone();
- let sel_keys = app.session.state.selected_keys.clone();
- let mut ui_actions: Vec<UiAct> = Vec::new();
- let idx_of = |id: LayerId| comp.index_of(id).unwrap_or(0);
- let graph_on = app.ui.timeline.graph_editor;
- super::graph::track_open(ui.ctx(), graph_on);
- let full_clip = ui.clip_rect();
- let left_clip = full_clip.intersect(Rect::from_min_max(pos2(rect.min.x, rows_rect.min.y), pos2(graph_x0 - 1.0, rows_rect.max.y)));
- let right_clip = full_clip.intersect(Rect::from_min_max(pos2(graph_x0, rows_rect.min.y), rows_rect.max));
- // Registered before the rows so keys, bars and editors on top of it get the pointer first.
- let empty_rect = if graph_on { Rect::NOTHING } else { Rect::from_min_max(pos2(graph_x0, rows_rect.min.y), rows_rect.max) };
- let empty = ui.interact(empty_rect, egui::Id::new("tl-graph-bg"), Sense::click_and_drag());
- let outline_rect = Rect::from_min_max(rows_rect.min, pos2(graph_x0 - 1.0, rows_rect.max.y));
- let outline_empty = ui.interact(outline_rect, egui::Id::new("tl-layer-bg"), Sense::click_and_drag());
- app.auto.add("timeline.layerMarquee", outline_rect, "Drag empty outline to select layers");
- let mut hit_rows: Vec<(Rect, Row)> = vec![];
- // The value fields of multi-dimension properties (per dimension), for the pick whip.
- let mut dim_hits: Vec<(u64, Vec<Rect>)> = vec![];
- // Rows stripe by their index among the rows that are not expression editors, so adding or
- // removing an expression leaves every other row's stripe alone; an editor takes the index
- // (and so the stripe) of its property's row, the one just above.
- let mut striped = 0usize;
- for row in rows.iter() {
- let ri = if matches!(row.kind, RowKind::Expr { .. }) {
- striped.saturating_sub(1)
+ }
+
+ fn layer_row_background(g: &Rw, rc: &RowCtx<'_>) {
+ let t = g.tl.t;
+ let rect = g.tl.rect;
+ let graph_x0 = g.tl.graph_x0;
+ let lp = g.lp.clone();
+ let gp = g.gp.clone();
+ let r = rc.r;
+ let left = rc.left;
+ let is_sel = rc.is_sel;
+ lp.rect_filled(left, 0.0, if is_sel { t.row_selected } else { t.row_alt });
+ gp.rect_filled(Rect::from_min_max(pos2(graph_x0, r.min.y), r.max), 0.0, if is_sel { t.tl_graph_selected } else { t.tl_bg });
+ lp.line_segment([pos2(rect.min.x, r.max.y - 0.5), pos2(graph_x0, r.max.y - 0.5)], Stroke::new(1.0, t.app_bg));
+ gp.line_segment([pos2(graph_x0, r.max.y - 0.5), pos2(r.max.x, r.max.y - 0.5)], Stroke::new(1.0, t.app_bg));
+ }
+
+ /// The A/V feature switches (video, audio, solo, lock).
+ fn layer_av_switches(app: &mut EffectcraftApp, ui: &mut egui::Ui, g: &mut Rw, rc: &RowCtx<'_>) {
+ let t = g.tl.t;
+ let vis = g.tl.vis;
+ let comp = g.tl.comp.clone();
+ let cw = &g.tl.cw;
+ let actions = &mut g.tl.actions;
+ let lp = g.lp.clone();
+ let selected = &g.selected;
+ let layer = rc.layer;
+ let r = rc.r;
+ let cy = rc.cy;
+ let sw = &layer.switches;
+ // Every layer has the Video switch (the eye), nulls, cameras and lights included,
+ // as in After Effects: it hides a null's outline in the viewer and turns a camera or
+ // light off.
+ let av_items: [(Icon, bool, &str, bool); 4] = [
+ (Icon::Eye, sw.video, "video", switch_applies(layer, "video", &app.session.project)),
+ (Icon::Speaker, sw.audio, "audio", switch_applies(layer, "audio", &app.session.project)),
+ (Icon::Solo, sw.solo, "solo", switch_applies(layer, "solo", &app.session.project)),
+ (Icon::Lock, sw.locked, "lock", switch_applies(layer, "lock", &app.session.project)),
+ ];
+ for (i, (icon, on, name, applicable)) in av_items.into_iter().enumerate() {
+ let br = Rect::from_center_size(pos2(cw.av + 10.0 + 18.0 * i as f32, cy), vec2(15.0, 15.0));
+ if !applicable || !vis.av {
+ continue;
+ }
+ lp.rect_filled(br.shrink(0.5), 1.0, t.switch_well);
+ layer_switch(
+ ui,
+ &t,
+ &SwitchSpec { row: r, br, icon, on, id: egui::Id::unique(("av", layer.id.0, i)), layer: layer.id.0, name, others: true },
+ &comp,
+ &app.session.project,
+ selected,
+ &mut *actions,
+ );
+ app.auto.add(&format!("timeline.layer.{}.{name}", layer.id.0), br, name);
+ }
+ }
+
+ /// The label swatch and its colour menu.
+ fn layer_label_swatch(app: &mut EffectcraftApp, ui: &mut egui::Ui, g: &mut Rw, rc: &RowCtx<'_>) {
+ let t = g.tl.t;
+ let vis = g.tl.vis;
+ let cw = &g.tl.cw;
+ let actions = &mut g.tl.actions;
+ let lp = g.lp.clone();
+ let selected = &g.selected;
+ let layer = rc.layer;
+ let cy = rc.cy;
+ // Label swatch.
+ if vis.label {
+ let lr = Rect::from_center_size(pos2(cw.label + 10.0, cy), vec2(12.0, 12.0));
+ lp.rect_filled(lr, 2.0, t.label(layer.label));
+ let lresp = ui.interact(lr, egui::Id::unique(("label", layer.id.0)), Sense::click());
+ app.auto.add(&format!("timeline.layer.{}.label", layer.id.0), lr, layer.label.name());
+ // Click (or right-click) the swatch for the label menu (After Effects).
+ let pop = egui::Id::unique(("label-pop", layer.id.0));
+ if lresp.clicked() || lresp.secondary_clicked() {
+ widgets::open_popup(ui, pop);
+ }
+ if let Some(lab) = widgets::label_popup(ui, pop, lr.left_bottom(), layer.label, |l| app.session.prefs.label_name(l), &t) {
+ actions.push(("edit.label".into(), json!({"layers": edited_layers(layer.id, selected), "label": lab.name()})));
+ }
+ }
+ }
+
+ fn layer_number_and_cells(app: &mut EffectcraftApp, ui: &mut egui::Ui, g: &mut Rw, rc: &RowCtx<'_>) {
+ let t = g.tl.t;
+ let vis = g.tl.vis;
+ let comp = g.tl.comp.clone();
+ let cw = &g.tl.cw;
+ let actions = &mut g.tl.actions;
+ let lp = g.lp.clone();
+ let layer = rc.layer;
+ let cy = rc.cy;
+ if vis.num {
+ lp.text(pos2(cw.num + 13.0, cy), Align2::CENTER_CENTER, format!("{}", comp.index_of(layer.id).unwrap_or(0)), Tokens::ui(11.5), t.text_dim);
+ }
+ layer_cells(app, ui, &lp, cw, &comp, rc, &mut *actions);
+ }
+
+ /// The row's click target, twirl, icon and guide mark; returns the row response and the name's x.
+ fn layer_twirl_and_icon(app: &mut EffectcraftApp, ui: &mut egui::Ui, g: &mut Rw, rc: &RowCtx<'_>) -> (egui::Response, f32) {
+ let t = g.tl.t;
+ let vis = g.tl.vis;
+ let cw = &g.tl.cw;
+ let lp = g.lp.clone();
+ let ui_actions = &mut g.ui_actions;
+ let layer = rc.layer;
+ let r = rc.r;
+ let cy = rc.cy;
+ // Row click → select; double-click → rename; drag → reorder. Registered before the
+ // twirl and the name field so those sit on top and get their clicks.
+ let row_x0 = if vis.num { cw.num } else { cw.name + 16.0 };
+ let row_resp =
+ ui.interact(Rect::from_min_max(pos2(row_x0, r.min.y), pos2(cw.name_end, r.max.y)), egui::Id::unique(("row", layer.id.0)), Sense::click_and_drag());
+ // Twirl + icon + name.
+ let tw = Rect::from_center_size(pos2(cw.name + 8.0, cy), vec2(14.0, 14.0));
+ let open = app.ui.timeline.open_layers.contains(&layer.id.0);
+ if widgets::twirl(ui, tw, open, egui::Id::unique(("twirl", layer.id.0)), &t).clicked() {
+ ui_actions.push(UiAct::ToggleLayer(layer.id.0, ui.input(|i| i.modifiers.alt || i.modifiers.command)));
+ }
+ app.auto.add(&format!("timeline.layer.{}.twirl", layer.id.0), tw, "twirl");
+ icons::paint(&lp, Rect::from_center_size(pos2(cw.name + 24.0, cy), vec2(13.0, 13.0)), layer_icon(layer, &app.session.project), t.text_dim);
+ // A guide layer carries a guide mark before its name (After Effects).
+ let name_x = if layer.switches.guide {
+ let mark = Rect::from_center_size(pos2(cw.name + 40.0, cy), vec2(11.0, 11.0));
+ icons::paint(&lp, mark, Icon::Grid, t.text_dim);
+ app.auto.add(&format!("timeline.layer.{}.guide", layer.id.0), mark, "Guide Layer");
+ cw.name + 50.0
+ } else {
+ cw.name + 34.0
+ };
+ (row_resp, name_x)
+ }
+
+ /// The layer name: the rename field or the (selected) name cell.
+ fn layer_name(app: &mut EffectcraftApp, ui: &mut egui::Ui, g: &mut Rw, rc: &RowCtx<'_>, name_x: f32) {
+ let t = g.tl.t;
+ let ctx = g.tl.ctx.clone();
+ let cw = &g.tl.cw;
+ let actions = &mut g.tl.actions;
+ let lp = g.lp.clone();
+ let layer = rc.layer;
+ let r = rc.r;
+ let cy = rc.cy;
+ let is_sel = rc.is_sel;
+ let name_rect = Rect::from_min_max(pos2(name_x, r.min.y), pos2(cw.name_end - 4.0, r.max.y));
+ let rename_id = egui::Id::unique("tl-rename");
+ let renaming: Option<(u64, String)> = ctx.data(|d| d.get_temp(rename_id));
+ if let Some((rl, mut buf)) = renaming.filter(|(rl, _)| *rl == layer.id.0) {
+ let mut child = ui.new_child(egui::UiBuilder::new().max_rect(name_rect.shrink2(vec2(0.0, 2.0))));
+ let er = child.add(egui::TextEdit::singleline(&mut buf).font(Tokens::ui(12.0)).desired_width(name_rect.width()));
+ app.auto.add(&format!("timeline.layer.{rl}.nameEdit"), er.rect, &buf);
+ if ctx.data_mut(|d| d.remove_temp::<bool>(rename_focus_id())).unwrap_or(false) {
+ // Just started: focus the field with the whole name selected.
+ er.request_focus();
+ widgets::select_all(&ctx, er.id, &buf);
+ }
+ if er.lost_focus() {
+ if !ui.input(|i| i.key_pressed(egui::Key::Escape)) {
+ actions.push(("layer.rename".into(), json!({"layer": rl, "name": buf})));
+ }
+ ctx.data_mut(|d| d.remove::<(u64, String)>(rename_id));
} else {
- striped += 1;
- striped - 1
- };
- // Outline widgets never spill into the time graph (narrow timelines).
- ui.set_clip_rect(left_clip);
- let hh = row_height(row, rh);
- let r = Rect::from_min_size(pos2(rect.min.x, y), vec2(rect.width(), hh));
- y += hh;
- if r.max.y < rows_rect.min.y || r.min.y > rows_rect.max.y {
+ ctx.data_mut(|d| d.insert_temp(rename_id, (rl, buf)));
+ }
+ } else {
+ // The selected layer's name sits in a light cell with dark text.
+ let name_col = if is_sel { Color32::from_gray(0x16) } else { t.text };
+ if is_sel {
+ let g = lp.layout_no_wrap(display_name(app, layer), Tokens::ui(12.0), name_col);
+ let cell = Rect::from_min_max(
+ pos2(name_rect.min.x - 3.0, r.min.y + 1.0),
+ pos2((name_rect.min.x + g.size().x + 4.0).max(cw.name_end - 4.0).min(cw.name_end - 2.0), r.max.y - 1.0),
+ );
+ lp.rect_filled(cell, 0.0, SELECTED_NAME_BG);
+ }
+ let lpn = lp.with_clip_rect(name_rect.intersect(lp.clip_rect()));
+ lpn.text(pos2(name_rect.min.x, cy), Align2::LEFT_CENTER, display_name(app, layer), Tokens::ui(12.0), name_col);
+ }
+ }
+
+ /// Row click, drag, double-click and context menu.
+ fn layer_row_actions(app: &mut EffectcraftApp, ui: &mut egui::Ui, g: &mut Rw, rc: &RowCtx<'_>, row_resp: &egui::Response) {
+ let cid = g.tl.cid;
+ let ctx = g.tl.ctx.clone();
+ let comp = g.tl.comp.clone();
+ let rows = &g.tl.rows;
+ let actions = &mut g.tl.actions;
+ let selected = &g.selected;
+ let layer = rc.layer;
+ let left = rc.left;
+ let is_sel = rc.is_sel;
+ // Locked layers can't be selected or moved (unlock them with the lock switch).
+ let locked = layer.switches.locked;
+ if row_resp.drag_started() && !locked {
+ // The selected layers move together; an unselected row moves alone.
+ let moving: Vec<u64> = if is_sel { comp.layers.iter().filter(|l| selected.contains(&l.id)).map(|l| l.id.0).collect() } else { vec![layer.id.0] };
+ ctx.data_mut(|d| d.insert_temp(layer_drag_id(), moving));
+ }
+ if row_resp.drag_stopped() {
+ ctx.data_mut(|d| d.insert_temp(layer_drop_id(), true));
+ }
+ app.auto.add(&format!("timeline.layer.{}.row", layer.id.0), left, &layer.name);
+ if row_resp.clicked() && !locked {
+ let m = ui.input(|i| i.modifiers);
+ if let Some(layers) = m.shift.then(|| shift_range(&ctx, cid, &comp, rows, selected, layer.id)).flatten() {
+ actions.push(("layer.select".into(), json!({"layers": layers})));
+ } else {
+ actions.push(("layer.select".into(), json!({"layers": [layer.id.0], "toggle": m.command})));
+ set_anchor(&ctx, cid, layer.id);
+ }
+ }
+ if row_resp.double_clicked() {
+ match double_click_action(layer) {
+ Some(a) => actions.push(a),
+ None => start_rename(&ctx, layer.id.0, &layer.name),
+ }
+ }
+ layer_context_menu(row_resp, &comp, layer, selected, LayerMenuCaps::of(&app.session.project, layer), &mut app.auto, &mut *actions);
+ }
+
+ /// The eight layer switches.
+ fn layer_switches(app: &mut EffectcraftApp, ui: &mut egui::Ui, g: &mut Rw, rc: &RowCtx<'_>) {
+ let t = g.tl.t;
+ let vis = g.tl.vis;
+ let comp = g.tl.comp.clone();
+ let cw = &g.tl.cw;
+ let actions = &mut g.tl.actions;
+ let lp = g.lp.clone();
+ let selected = &g.selected;
+ let layer = rc.layer;
+ let r = rc.r;
+ let cy = rc.cy;
+ let sw = &layer.switches;
+ let sws: [(Icon, bool, &str, bool); 8] = [
+ (Icon::Shy, sw.shy, "shy", switch_applies(layer, "shy", &app.session.project)),
+ (Icon::Collapse, sw.collapse, "collapse", switch_applies(layer, "collapse", &app.session.project)),
+ (Icon::Quality, sw.quality == effectcraft_engine::project::Quality::Best, "quality", switch_applies(layer, "quality", &app.session.project)),
+ (Icon::Fx, sw.effects, "fx", switch_applies(layer, "fx", &app.session.project)),
+ (
+ Icon::FrameBlend,
+ sw.frame_blend != effectcraft_engine::project::FrameBlend::Off,
+ "frameBlend",
+ switch_applies(layer, "frameBlend", &app.session.project),
+ ),
+ (Icon::MotionBlur, sw.motion_blur, "motionBlur", switch_applies(layer, "motionBlur", &app.session.project)),
+ (Icon::Adjustment, sw.adjustment, "adjustment", switch_applies(layer, "adjustment", &app.session.project)),
+ (Icon::Cube, layer.is_3d(), "threeD", switch_applies(layer, "threeD", &app.session.project)),
+ ];
+ for (i, (icon, on, name, applicable)) in sws.into_iter().enumerate() {
+ if !applicable || !vis.switches {
continue;
}
- hit_rows.push((r, row.clone()));
- let Some(layer) = comp.layer(row.layer) else { continue };
- let is_sel = selected.contains(&layer.id);
- let left = Rect::from_min_max(r.min, pos2(graph_x0 - 1.0, r.max.y));
- let cy = r.min.y + rh / 2.0;
- match &row.kind {
- RowKind::Layer => {
- // After Effects draws layer rows as one flat tone separated by dark hairlines
- // (outline and time graph alike), not as alternating stripes.
- let _ = ri;
- lp.rect_filled(left, 0.0, if is_sel { t.row_selected } else { t.row_alt });
- gp.rect_filled(Rect::from_min_max(pos2(graph_x0, r.min.y), r.max), 0.0, if is_sel { t.tl_graph_selected } else { t.tl_bg });
- lp.line_segment([pos2(rect.min.x, r.max.y - 0.5), pos2(graph_x0, r.max.y - 0.5)], Stroke::new(1.0, t.app_bg));
- gp.line_segment([pos2(graph_x0, r.max.y - 0.5), pos2(r.max.x, r.max.y - 0.5)], Stroke::new(1.0, t.app_bg));
- // A/V features.
- let sw = &layer.switches;
- let av_items: [(Icon, bool, &str, bool); 4] = [
- (Icon::Eye, sw.video, "video", layer.source.is_av()),
- (Icon::Speaker, sw.audio, "audio", layer.props.sub("audio").is_some()),
- (Icon::Solo, sw.solo, "solo", layer.source.is_av()),
- (Icon::Lock, sw.locked, "lock", true),
- ];
- for (i, (icon, on, name, applicable)) in av_items.into_iter().enumerate() {
- let br = Rect::from_center_size(pos2(cw.av + 10.0 + 18.0 * i as f32, cy), vec2(15.0, 15.0));
- if !applicable || !vis.av {
- continue;
- }
- lp.rect_filled(br.shrink(0.5), 1.0, t.switch_well);
- layer_switch(ui, &t, r, br, icon, on, egui::Id::new(("av", layer.id.0, i)), layer.id.0, name, true, &mut actions);
- app.auto.add(&format!("timeline.layer.{}.{name}", layer.id.0), br, name);
- }
- // Label swatch.
- if vis.label {
- let lr = Rect::from_center_size(pos2(cw.label + 10.0, cy), vec2(12.0, 12.0));
- lp.rect_filled(lr, 2.0, t.label(layer.label));
- let lresp = ui.interact(lr, egui::Id::new(("label", layer.id.0)), Sense::click());
- app.auto.add(&format!("timeline.layer.{}.label", layer.id.0), lr, layer.label.name());
- // Click (or right-click) the swatch for the label menu (After Effects).
- let pop = egui::Id::new(("label-pop", layer.id.0));
- if lresp.clicked() || lresp.secondary_clicked() {
- widgets::open_popup(ui, pop);
- }
- if let Some(lab) = widgets::label_popup(ui, pop, lr.left_bottom(), layer.label, |l| app.session.prefs.label_name(l), &t) {
- actions.push(("edit.label".into(), json!({"layers": [layer.id.0], "label": lab.name()})));
- }
- }
- if vis.num {
- lp.text(pos2(cw.num + 13.0, cy), Align2::CENTER_CENTER, format!("{}", idx_of(layer.id)), Tokens::ui(11.5), t.text_dim);
- }
- layer_cells(app, ui, &lp, &cw, &comp, layer, r, cy, &mut actions);
- // Row click → select; double-click → rename; drag → reorder. Registered before the
- // twirl and the name field so those sit on top and get their clicks.
- let row_x0 = if vis.num { cw.num } else { cw.name + 16.0 };
- let row_resp = ui.interact(
- Rect::from_min_max(pos2(row_x0, r.min.y), pos2(cw.name_end, r.max.y)),
- egui::Id::new(("row", layer.id.0)),
- Sense::click_and_drag(),
- );
- // Twirl + icon + name.
- let tw = Rect::from_center_size(pos2(cw.name + 8.0, cy), vec2(14.0, 14.0));
- let open = app.ui.timeline.open_layers.contains(&layer.id.0);
- if widgets::twirl(ui, tw, open, egui::Id::new(("twirl", layer.id.0)), &t).clicked() {
- ui_actions.push(UiAct::ToggleLayer(layer.id.0, ui.input(|i| i.modifiers.alt || i.modifiers.command)));
- }
- app.auto.add(&format!("timeline.layer.{}.twirl", layer.id.0), tw, "twirl");
- icons::paint(&lp, Rect::from_center_size(pos2(cw.name + 24.0, cy), vec2(13.0, 13.0)), layer_icon(layer, &app.session.project), t.text_dim);
- let name_rect = Rect::from_min_max(pos2(cw.name + 34.0, r.min.y), pos2(cw.name_end - 4.0, r.max.y));
- let rename_id = egui::Id::new("tl-rename");
- let renaming: Option<(u64, String)> = ctx.data(|d| d.get_temp(rename_id));
- if let Some((rl, mut buf)) = renaming.filter(|(rl, _)| *rl == layer.id.0) {
- let mut child = ui.new_child(egui::UiBuilder::new().max_rect(name_rect.shrink2(vec2(0.0, 2.0))));
- let er = child.add(egui::TextEdit::singleline(&mut buf).font(Tokens::ui(12.0)).desired_width(name_rect.width()));
- app.auto.add(&format!("timeline.layer.{rl}.nameEdit"), er.rect, &buf);
- if ctx.data_mut(|d| d.remove_temp::<bool>(rename_focus_id())).unwrap_or(false) {
- // Just started: focus the field with the whole name selected.
- er.request_focus();
- widgets::select_all(&ctx, er.id, &buf);
- }
- if er.lost_focus() {
- if !ui.input(|i| i.key_pressed(egui::Key::Escape)) {
- actions.push(("layer.rename".into(), json!({"layer": rl, "name": buf})));
- }
- ctx.data_mut(|d| d.remove::<(u64, String)>(rename_id));
- } else {
- ctx.data_mut(|d| d.insert_temp(rename_id, (rl, buf)));
- }
- } else {
- // The selected layer's name sits in a light cell with dark text.
- let name_col = if is_sel { Color32::from_gray(0x16) } else { t.text };
- if is_sel {
- let g = lp.layout_no_wrap(display_name(app, layer), Tokens::ui(12.0), name_col);
- let cell = Rect::from_min_max(
- pos2(name_rect.min.x - 3.0, r.min.y + 1.0),
- pos2((name_rect.min.x + g.size().x + 4.0).max(cw.name_end - 4.0).min(cw.name_end - 2.0), r.max.y - 1.0),
- );
- lp.rect_filled(cell, 0.0, SELECTED_NAME_BG);
- }
- let lpn = lp.with_clip_rect(name_rect.intersect(lp.clip_rect()));
- lpn.text(pos2(name_rect.min.x, cy), Align2::LEFT_CENTER, display_name(app, layer), Tokens::ui(12.0), name_col);
- }
- // Locked layers can't be selected or moved (unlock them with the lock switch).
- let locked = layer.switches.locked;
- if row_resp.drag_started() && !locked {
- // The selected layers move together; an unselected row moves alone.
- let moving: Vec<u64> =
- if is_sel { comp.layers.iter().filter(|l| selected.contains(&l.id)).map(|l| l.id.0).collect() } else { vec![layer.id.0] };
- ctx.data_mut(|d| d.insert_temp(layer_drag_id(), moving));
- }
- if row_resp.drag_stopped() {
- ctx.data_mut(|d| d.insert_temp(layer_drop_id(), true));
- }
- app.auto.add(&format!("timeline.layer.{}.row", layer.id.0), left, &layer.name);
- if row_resp.clicked() && !locked {
- let m = ui.input(|i| i.modifiers);
- if let Some(layers) = m.shift.then(|| shift_range(&ctx, cid, &comp, &rows, &selected, layer.id)).flatten() {
- actions.push(("layer.select".into(), json!({"layers": layers})));
- } else {
- actions.push(("layer.select".into(), json!({"layers": [layer.id.0], "toggle": m.command})));
- set_anchor(&ctx, cid, layer.id);
- }
- }
- if row_resp.double_clicked() {
- match double_click_action(layer) {
- Some(a) => actions.push(a),
- None => start_rename(&ctx, layer.id.0, &layer.name),
- }
- }
- layer_context_menu(&row_resp, &comp, layer, &selected, LayerMenuCaps::of(&app.session.project, layer), &mut actions);
- // Switches.
- let sws: [(Icon, bool, &str, bool); 8] = [
- (Icon::Shy, sw.shy, "shy", true),
- (Icon::Collapse, sw.collapse, "collapse", collapse_applies(layer, &app.session.project)),
- (Icon::Quality, sw.quality == effectcraft_engine::project::Quality::Best, "quality", layer.source.is_av()),
- (Icon::Fx, sw.effects, "fx", layer.effects().is_some_and(|f| !f.children.is_empty())),
- (
- Icon::FrameBlend,
- sw.frame_blend != effectcraft_engine::project::FrameBlend::Off,
- "frameBlend",
- matches!(layer.source, LayerSource::Footage { .. } | LayerSource::Comp { .. }),
- ),
- (Icon::MotionBlur, sw.motion_blur, "motionBlur", layer.source.is_av()),
- (Icon::Adjustment, sw.adjustment, "adjustment", layer.source.is_av()),
- (Icon::Cube, layer.is_3d(), "threeD", layer.source.is_av() || matches!(layer.source, LayerSource::Null)),
- ];
- for (i, (icon, on, name, applicable)) in sws.into_iter().enumerate() {
- if !applicable || !vis.switches {
- continue;
- }
- let br = Rect::from_center_size(pos2(cw.switches + SW * i as f32 + SW / 2.0, cy), vec2(16.0, 16.0));
- lp.rect_filled(br.shrink(1.0), 1.0, t.switch_well);
- layer_switch(ui, &t, r, br, icon, on, egui::Id::new(("sw", layer.id.0, i)), layer.id.0, name, false, &mut actions);
- app.auto.add(&format!("timeline.layer.{}.switch.{name}", layer.id.0), br, name);
- }
- // Modes.
- if app.ui.timeline.show_modes && layer.source.is_av() {
- let mr = Rect::from_min_size(pos2(cw.mode + 2.0, cy - 9.0), vec2(80.0, 18.0));
- let mresp = widgets::dropdown(ui, mr, layer.blend_mode.label(), &t, egui::Id::new(("mode", layer.id.0)));
- app.auto.add(&format!("timeline.layer.{}.mode", layer.id.0), mr, "Mode");
- let pop = egui::Id::new(("mode-pop", layer.id.0));
- if mresp.clicked() {
- widgets::open_popup(ui, pop);
- }
- let opts: Vec<String> = BlendMode::ALL
- .iter()
- .flat_map(|m| if m.ends_group() { vec![m.label().to_string(), "-".to_string()] } else { vec![m.label().to_string()] })
- .collect();
- if let Some(i) = widgets::popup_menu(ui, pop, mr.left_bottom(), &opts, opts.iter().position(|o| o == layer.blend_mode.label())) {
- actions.push(("layer.setBlendMode".into(), json!({"layers": [layer.id.0], "mode": opts[i]})));
- }
- let tr = Rect::from_center_size(pos2(cw.mode + 76.0 + 6.0, cy), vec2(14.0, 14.0));
- if widgets::checkbox(ui, tr, layer.preserve_transparency, &t, egui::Id::new(("pt", layer.id.0))).changed() {
- actions.push(("layer.setSwitch".into(), json!({"layers": [layer.id.0], "switch": "preserveTransparency"})));
- }
- // Track matte: layer picker + kind.
- let mr = Rect::from_min_size(pos2(cw.trkmat + 2.0, cy - 9.0), vec2(104.0, 18.0));
- let label = match layer.track_matte {
- Some(m) => comp.layer(m.layer).map(|l| format!("{} {}", idx_of(l.id), l.name)).unwrap_or("None".into()),
- None => "No Track Matte".into(),
- };
- // The cell is too narrow for the mode as well: it is in the tooltip and ticked in the menu.
- let tip = layer.track_matte.map(|m| format!("{label} · {}", crate::i18n::tr(m.kind.label())));
- let tresp = widgets::dropdown_tip(ui, mr, &label, tip.as_deref(), &t, egui::Id::new(("trkmat", layer.id.0)));
- app.auto.add(&format!("timeline.layer.{}.trackMatte", layer.id.0), mr, "Track Matte");
- let pop = egui::Id::new(("trk-pop", layer.id.0));
- if tresp.clicked() {
- widgets::open_popup(ui, pop);
- }
- // The menu lists every layer: built only while it is open (per visible row
- // it made a big comp's timeline quadratic).
- let mut opts = vec!["No Track Matte".to_string(), "-".to_string()];
- let mut candidates: Vec<&Layer> = vec![];
- if widgets::popup_is_open(ui, pop) {
- for (i, l) in comp.layers.iter().enumerate().filter(|(_, l)| l.id != layer.id && l.source.is_av()) {
- opts.push(format!("{}. {}", i + 1, l.name));
- candidates.push(l);
- }
- opts.push("-".into());
- for k in MatteKind::ALL {
- opts.push(k.label().into());
- }
- }
- let current = layer.track_matte.and_then(|m| opts.iter().position(|o| o == m.kind.label()));
- if let Some(i) = widgets::popup_menu(ui, pop, mr.left_bottom(), &opts, current) {
- let ids: Vec<LayerId> = candidates.iter().map(|l| l.id).collect();
- if let Some(a) = opts.get(i).and_then(|o| track_matte_pick(layer, &ids, i, o)) {
- actions.push(a);
- }
- }
- if layer.track_matte.is_some() {
- let kr = Rect::from_center_size(pos2(mr.max.x - 26.0, cy), vec2(10.0, 10.0));
- let _ = kr;
- }
- }
- // Parent.
- if vis.parent {
- pick_whip(
- app,
- ui,
- &lp,
- Rect::from_center_size(pos2(cw.parent + 9.0, cy), vec2(15.0, 15.0)),
- (WHIP_PARENT, layer.id.0, 0),
- &format!("timeline.layer.{}.pickWhip", layer.id.0),
- "Parent pick whip",
- crate::i18n::tr("Parent pick whip: drag onto a layer"),
- );
- let pr_rect = Rect::from_min_size(pos2(cw.parent + 20.0, cy - 9.0), vec2(94.0, 18.0));
- let plabel = layer.parent.and_then(|p| comp.layer(p)).map(|l| format!("{}. {}", idx_of(l.id), l.name)).unwrap_or_else(|| "None".into());
- let presp = widgets::dropdown(ui, pr_rect, &plabel, &t, egui::Id::new(("parent", layer.id.0)));
- app.auto.add(&format!("timeline.layer.{}.parent", layer.id.0), pr_rect, "Parent");
- let pop = egui::Id::new(("par-pop", layer.id.0));
- if presp.clicked() {
- widgets::open_popup(ui, pop);
- }
- let mut cands: Vec<&Layer> = vec![];
- let mut popts = vec!["None".to_string(), "-".to_string()];
- if widgets::popup_is_open(ui, pop) {
- for (i, l) in comp.layers.iter().enumerate().filter(|(_, l)| l.id != layer.id) {
- popts.push(format!("{}. {}", i + 1, l.name));
- cands.push(l);
- }
- }
- if let Some(i) = widgets::popup_menu(ui, pop, pr_rect.left_bottom(), &popts, None) {
- let par = if i == 0 { serde_json::Value::Null } else { json!(cands[i - 2].id.0) };
- actions.push(("layer.setParent".into(), json!({"layers": [layer.id.0], "parent": par})));
- }
- }
- // Layer bar.
- ui.set_clip_rect(right_clip);
- if !graph_on {
- let x_in = tm.x(layer.in_point.seconds());
- let x_out = tm.x(layer.out_point.seconds());
- let bar = Rect::from_min_max(pos2(x_in, r.min.y + 1.0), pos2(x_out, r.max.y - 1.0));
- let lc = t.label(layer.label);
- let fill = bar_color(lc, is_sel);
- gp.rect_filled(bar, 0.0, fill);
- if is_sel {
- gp.rect_stroke(bar, 0.0, Stroke::new(1.0, Color32::from_white_alpha(90)), StrokeKind::Inside);
- }
- // Source extent (e.g. trimmed footage) shown faint.
- if let LayerSource::Footage { .. } | LayerSource::Comp { .. } = layer.source
- && let Some(d) = layer.source.item().and_then(|i| app.session.project.item(i)).and_then(|i| i.duration())
- {
- let xs = tm.x(layer.start_time.seconds());
- let xe = tm.x(layer.comp_time(d).seconds());
- let ghost = Rect::from_min_max(pos2(xs.min(xe), r.min.y + 9.0), pos2(xs.max(xe), r.max.y - 9.0));
- gp.rect_filled(ghost, 1.0, lc.gamma_multiply(0.18));
- // The bar past the source's end (its last frame held) or before its start
- // is striped, so the source's own span shows (#290). Time remapping
- // decides what shows there itself.
- if layer.props.get("timeRemap").is_none() {
- for (side, part) in [
- ("beforeSource", Rect::from_min_max(bar.min, pos2(ghost.min.x, bar.max.y))),
- ("afterSource", Rect::from_min_max(pos2(ghost.max.x, bar.min.y), bar.max)),
- ] {
- if part.width() >= 1.0 {
- stripes(&gp, part, lc);
- app.auto.add(&format!("timeline.layer.{}.bar.{side}", layer.id.0), part, "Past the source");
- }
- }
- }
- // Dragging the source bar outside the in/out span slips the source.
- for (side, gr) in [
- ("l", Rect::from_min_max(ghost.min, pos2(bar.min.x, ghost.max.y))),
- ("r", Rect::from_min_max(pos2(bar.max.x, ghost.min.y), ghost.max)),
- ] {
- if gr.width() < 2.0 {
- continue;
- }
- let gresp = ui
- .interact(gr, egui::Id::new(("ghost", side, layer.id.0)), Sense::click_and_drag())
- .on_hover_text(crate::i18n::tr("Drag to slip the source"));
- // Outside the bar it is empty track area: a plain click deselects.
- if gresp.clicked() && !ui.input(|i| i.modifiers.shift || i.modifiers.command) {
- actions.push(("layer.select".into(), json!({"layers": []})));
- }
- app.auto.add(&format!("timeline.layer.{}.source{}", layer.id.0, side), gr, "Slip");
- if gresp.hovered() || gresp.dragged() {
- ctx.set_cursor_icon(egui::CursorIcon::ResizeHorizontal);
- }
- let acc_id = egui::Id::new(("slip-acc", layer.id.0));
- if gresp.dragged() {
- let mut acc: f32 = ctx.data(|d| d.get_temp(acc_id).unwrap_or(0.0));
- acc += gresp.drag_delta().x;
- let frames = ((acc as f64 / pps) / fd).trunc() as i64;
- if frames != 0 {
- acc -= (frames as f64 * fd * pps) as f32;
- actions.push((
- "layer.slip".into(),
- json!({"layers": [layer.id.0], "frames": frames, "merge": format!("slip-{}", layer.id.0)}),
- ));
- }
- ctx.data_mut(|d| d.insert_temp(acc_id, acc));
- }
- if gresp.drag_stopped() {
- ctx.data_mut(|d| d.remove::<f32>(acc_id));
- ui_actions.push(UiAct::EndMerge);
- }
- }
- }
- app.auto.add(&format!("timeline.layer.{}.bar", layer.id.0), bar, &layer.name);
- // Interactions: move body, trim edges.
- let (body_r, in_r, out_r) = trim_zones(bar);
- let body = ui.interact(body_r, egui::Id::new(("bar", layer.id.0)), Sense::click_and_drag());
- let lin = ui.interact(in_r, egui::Id::new(("bar-in", layer.id.0)), Sense::drag());
- let lout = ui.interact(out_r, egui::Id::new(("bar-out", layer.id.0)), Sense::drag());
- app.auto.add(&format!("timeline.layer.{}.bar.in", layer.id.0), in_r, "Trim In");
- app.auto.add(&format!("timeline.layer.{}.bar.out", layer.id.0), out_r, "Trim Out");
- if lin.hovered() || lout.hovered() || lin.dragged() || lout.dragged() {
- trim_cursor(&ctx);
- }
- if body.double_clicked()
- && let Some(a) = double_click_action(layer)
- {
- actions.push(a);
- }
- let shift = ui.input(|i| i.modifiers.shift);
- if let Some(layers) = (body.clicked() && shift).then(|| shift_range(&ctx, cid, &comp, &rows, &selected, layer.id)).flatten() {
- // Shift-click: the layers from the last one clicked to this one, as in
- // the layer outline.
- actions.push(("layer.select".into(), json!({"layers": layers})));
- } else {
- if (body.clicked() || body.drag_started()) && !is_sel {
- actions.push(("layer.select".into(), json!({"layers": [layer.id.0], "add": shift})));
- }
- if (body.clicked() || body.drag_started()) && !shift {
- set_anchor(&ctx, cid, layer.id);
- }
- }
- layer_context_menu(&body, &comp, layer, &selected, LayerMenuCaps::of(&app.session.project, layer), &mut actions);
- let drag_key = format!("bar-{}", layer.id.0);
- // Ctrl/Cmd+Alt dragging a selected bar: Quick Offset (#1012), chosen as the
- // drag starts and followed below the rows until the button is released.
- let mods = ui.input(|i| i.modifiers);
- if body.drag_started()
- && is_sel
- && mods.command
- && mods.alt
- && let Some(n) = quick_offset_layers(&comp, selected.iter().copied())
- && let Some(p) = ctx.input(|i| i.pointer.press_origin())
- {
- ctx.data_mut(|d| d.insert_temp(quick_bar_id(), QuickBar { layer: layer.id, origin_x: p.x, layers: n, applied: 0 }));
- }
- let quick = ctx.data(|d| d.get_temp::<QuickBar>(quick_bar_id())).is_some_and(|q| q.layer == layer.id);
- for (resp, kind) in [(&body, "move"), (&lin, "in"), (&lout, "out")] {
- if kind == "move" && quick {
- continue;
- }
- if resp.dragged() {
- let acc_id = egui::Id::new(("bar-acc", layer.id.0, kind));
- let mut acc: f32 = ctx.data(|d| d.get_temp(acc_id).unwrap_or(0.0));
- acc += resp.drag_delta().x;
- let frames = ((acc as f64 / pps) / fd).trunc() as i64;
- if frames != 0 {
- acc -= (frames as f64 * fd * pps) as f32;
- let d = frames as f64 * fd;
- // Moving or trimming a selected layer acts on the whole
- // selection; each layer trims from its own in/out point.
- let targets = if is_sel { json!(selected.iter().map(|l| l.0).collect::<Vec<_>>()) } else { json!([layer.id.0]) };
- let params = match kind {
- "move" => json!({"layers": targets, "delta": d, "merge": drag_key}),
- "in" => json!({"layers": targets, "inDelta": d, "merge": drag_key}),
- _ => json!({"layers": targets, "outDelta": d, "merge": drag_key}),
- };
- actions.push(("layer.timing".into(), params));
- }
- ctx.data_mut(|d| d.insert_temp(acc_id, acc));
- }
- if resp.drag_stopped() {
- ctx.data_mut(|d| d.remove::<f32>(egui::Id::new(("bar-acc", layer.id.0, kind))));
- ui_actions.push(UiAct::EndMerge);
- }
- }
- // Markers on the layer (drag, Alt-drag duration, Cmd-click delete, dialog).
- let gclip = rows_rect.intersect(Rect::from_min_max(pos2(graph_x0, rows_rect.min.y), rows_rect.max));
- super::markers_ui::layer_markers(app, ui, gclip, &comp, layer, tm, r);
+ let br = Rect::from_center_size(pos2(cw.switches + SW * i as f32 + SW / 2.0, cy), vec2(16.0, 16.0));
+ lp.rect_filled(br.shrink(1.0), 1.0, t.switch_well);
+ layer_switch(
+ ui,
+ &t,
+ &SwitchSpec { row: r, br, icon, on, id: egui::Id::unique(("sw", layer.id.0, i)), layer: layer.id.0, name, others: false },
+ &comp,
+ &app.session.project,
+ selected,
+ &mut *actions,
+ );
+ app.auto.add(&format!("timeline.layer.{}.switch.{name}", layer.id.0), br, name);
+ }
+ }
+
+ /// The blend mode dropdown and Preserve Transparency.
+ fn layer_mode_cell(app: &mut EffectcraftApp, ui: &mut egui::Ui, g: &mut Rw, rc: &RowCtx<'_>) {
+ let t = g.tl.t;
+ let comp = g.tl.comp.clone();
+ let cw = &g.tl.cw;
+ let actions = &mut g.tl.actions;
+ let selected = &g.selected;
+ let layer = rc.layer;
+ let cy = rc.cy;
+ let mr = Rect::from_min_size(pos2(cw.mode + 2.0, cy - 9.0), vec2(80.0, 18.0));
+ let mresp = widgets::dropdown(ui, mr, layer.blend_mode.label(), &t, egui::Id::unique(("mode", layer.id.0)));
+ app.auto.add(&format!("timeline.layer.{}.mode", layer.id.0), mr, "Mode");
+ let pop = egui::Id::unique(("mode-pop", layer.id.0));
+ if mresp.clicked() {
+ widgets::open_popup(ui, pop);
+ }
+ let opts: Vec<String> =
+ BlendMode::ALL.iter().flat_map(|m| if m.ends_group() { vec![m.label().to_string(), "-".to_string()] } else { vec![m.label().to_string()] }).collect();
+ if let Some(i) = widgets::popup_menu(ui, pop, mr.left_bottom(), &opts, opts.iter().position(|o| o == layer.blend_mode.label())) {
+ actions.push(("layer.setBlendMode".into(), json!({"layers": mode_targets(&comp, layer.id, selected), "mode": opts[i]})));
+ }
+ let tr = Rect::from_center_size(pos2(cw.mode + 76.0 + 6.0, cy), vec2(14.0, 14.0));
+ app.auto.add(&format!("timeline.layer.{}.preserveTransparency", layer.id.0), tr, "Preserve Transparency");
- if widgets::checkbox(ui, tr, layer.preserve_transparency, &t, egui::Id::unique(("pt", layer.id.0))).clicked() {
++ if widgets::checkbox(ui, tr, layer.preserve_transparency, &t, egui::Id::unique(("pt", layer.id.0))).changed() {
+ // The click gives the selection the state the clicked row toggles to,
+ // whatever the first selected layer's value (as the switches do).
+ actions.push((
+ "layer.setSwitch".into(),
+ json!({
+ "layers": mode_targets(&comp, layer.id, selected),
+ "switch": "preserveTransparency",
+ "value": !layer.preserve_transparency
+ }),
+ ));
+ }
+ }
+
+ /// The track matte picker.
+ fn layer_matte_cell(app: &mut EffectcraftApp, ui: &mut egui::Ui, g: &mut Rw, rc: &RowCtx<'_>) {
+ let t = g.tl.t;
+ let comp = g.tl.comp.clone();
+ let cw = &g.tl.cw;
+ let actions = &mut g.tl.actions;
+ let layer = rc.layer;
+ let cy = rc.cy;
+ // Track matte: layer picker + kind.
+ let mr = Rect::from_min_size(pos2(cw.trkmat + 2.0, cy - 9.0), vec2(104.0, 18.0));
+ let label = match layer.track_matte {
+ Some(m) => comp.layer(m.layer).map(|l| format!("{} {}", comp.index_of(l.id).unwrap_or(0), l.name)).unwrap_or("None".into()),
+ None => "No Track Matte".into(),
+ };
+ // The cell is too narrow for the mode as well: it is in the tooltip and ticked in the menu.
+ let tip = layer.track_matte.map(|m| format!("{label} · {}", crate::i18n::tr(m.kind.label())));
+ let tresp = widgets::dropdown_tip(ui, mr, &label, tip.as_deref(), &t, egui::Id::unique(("trkmat", layer.id.0)));
+ app.auto.add(&format!("timeline.layer.{}.trackMatte", layer.id.0), mr, "Track Matte");
+ let pop = egui::Id::unique(("trk-pop", layer.id.0));
+ if tresp.clicked() {
+ widgets::open_popup(ui, pop);
+ }
+ // The menu lists every layer: built only while it is open (per visible row
+ // it made a big comp's timeline quadratic).
+ let mut opts = vec!["No Track Matte".to_string(), "-".to_string()];
+ let mut candidates: Vec<&Layer> = vec![];
+ if widgets::popup_is_open(ui, pop) {
+ for (i, l) in comp.layers.iter().enumerate().filter(|(_, l)| l.id != layer.id && l.source.is_av()) {
+ opts.push(format!("{}. {}", i + 1, l.name));
+ candidates.push(l);
+ }
+ opts.push("-".into());
+ for k in MatteKind::ALL {
+ opts.push(k.label().into());
+ }
+ }
+ let current = layer.track_matte.and_then(|m| opts.iter().position(|o| o == m.kind.label()));
+ if let Some(i) = widgets::popup_menu(ui, pop, mr.left_bottom(), &opts, current) {
+ let ids: Vec<LayerId> = candidates.iter().map(|l| l.id).collect();
+ if let Some(a) = opts.get(i).and_then(|o| track_matte_pick(layer, &ids, i, o)) {
+ actions.push(a);
+ }
+ }
+ if layer.track_matte.is_some() {
+ let kr = Rect::from_center_size(pos2(mr.max.x - 26.0, cy), vec2(10.0, 10.0));
+ let _ = kr;
+ }
+ }
+
+ /// The parent pick whip and dropdown.
+ fn layer_parent_cell(app: &mut EffectcraftApp, ui: &mut egui::Ui, g: &mut Rw, rc: &RowCtx<'_>) {
+ let t = g.tl.t;
+ let comp = g.tl.comp.clone();
+ let cw = &g.tl.cw;
+ let actions = &mut g.tl.actions;
+ let lp = g.lp.clone();
+ let layer = rc.layer;
+ let cy = rc.cy;
+ pick_whip(
+ app,
+ ui,
+ &lp,
+ Rect::from_center_size(pos2(cw.parent + 9.0, cy), vec2(15.0, 15.0)),
+ (WHIP_PARENT, layer.id.0, 0),
+ WhipText {
+ auto: &format!("timeline.layer.{}.pickWhip", layer.id.0),
+ label: "Parent pick whip",
+ hint: crate::i18n::tr("Parent pick whip: drag onto a layer"),
+ },
+ );
+ let pr_rect = Rect::from_min_size(pos2(cw.parent + 20.0, cy - 9.0), vec2(94.0, 18.0));
+ let plabel = layer.parent.and_then(|p| comp.layer(p)).map(|l| format!("{}. {}", comp.index_of(l.id).unwrap_or(0), l.name)).unwrap_or_else(|| "None".into());
+ let presp = widgets::dropdown(ui, pr_rect, &plabel, &t, egui::Id::unique(("parent", layer.id.0)));
+ app.auto.add(&format!("timeline.layer.{}.parent", layer.id.0), pr_rect, "Parent");
+ let pop = egui::Id::unique(("par-pop", layer.id.0));
+ if presp.clicked() {
+ widgets::open_popup(ui, pop);
+ }
+ let mut cands: Vec<&Layer> = vec![];
+ let mut popts = vec!["None".to_string(), "-".to_string()];
+ if widgets::popup_is_open(ui, pop) {
+ for (i, l) in comp.layers.iter().enumerate().filter(|(_, l)| l.id != layer.id) {
+ popts.push(format!("{}. {}", i + 1, l.name));
+ cands.push(l);
+ }
+ }
+ if let Some(i) = widgets::popup_menu(ui, pop, pr_rect.left_bottom(), &popts, None) {
+ let par = if i == 0 { serde_json::Value::Null } else { json!(cands[i - 2].id.0) };
+ actions.push(("layer.setParent".into(), json!({"layers": [layer.id.0], "parent": par})));
+ }
+ }
+
+ /// Paints the layer bar; returns it and its label colour.
+ fn layer_bar_paint(g: &Rw, rc: &RowCtx<'_>) -> (Rect, Color32) {
+ let t = g.tl.t;
+ let tm = g.tl.tm;
+ let gp = g.gp.clone();
+ let layer = rc.layer;
+ let r = rc.r;
+ let is_sel = rc.is_sel;
+ let x_in = tm.x(layer.in_point.seconds());
+ let x_out = tm.x(layer.out_point.seconds());
+ let bar = Rect::from_min_max(pos2(x_in, r.min.y + 1.0), pos2(x_out, r.max.y - 1.0));
+ let lc = t.label(layer.label);
+ let fill = bar_color(lc, is_sel);
+ gp.rect_filled(bar, 0.0, fill);
+ if is_sel {
+ gp.rect_stroke(bar, 0.0, Stroke::new(1.0, Color32::from_white_alpha(90)), StrokeKind::Inside);
+ }
+ (bar, lc)
+ }
+
+ /// Dragging the source bar outside the in/out span slips the source.
+ fn slip_source_handles(app: &mut EffectcraftApp, ui: &mut egui::Ui, g: &mut Rw, rc: &RowCtx<'_>, ghost: Rect, bar: Rect) {
+ let pps = g.tl.pps;
+ let fd = g.tl.fd;
+ let ctx = g.tl.ctx.clone();
+ let actions = &mut g.tl.actions;
+ let ui_actions = &mut g.ui_actions;
+ let layer = rc.layer;
+ // Dragging the source bar outside the in/out span slips the source.
+ for (side, gr) in [("l", Rect::from_min_max(ghost.min, pos2(bar.min.x, ghost.max.y))), ("r", Rect::from_min_max(pos2(bar.max.x, ghost.min.y), ghost.max))] {
+ if gr.width() < 2.0 {
+ continue;
+ }
+ let gresp =
+ ui.interact(gr, egui::Id::unique(("ghost", side, layer.id.0)), Sense::click_and_drag()).on_hover_text(crate::i18n::tr("Drag to slip the source"));
+ // Outside the bar it is empty track area: a plain click deselects.
+ if gresp.clicked() && !ui.input(|i| i.modifiers.shift || i.modifiers.command) {
+ actions.push(("layer.select".into(), json!({"layers": []})));
+ }
+ app.auto.add(&format!("timeline.layer.{}.source{}", layer.id.0, side), gr, "Slip");
+ if gresp.hovered() || gresp.dragged() {
+ ctx.set_cursor_icon(egui::CursorIcon::ResizeHorizontal);
+ }
+ let acc_id = egui::Id::unique(("slip-acc", layer.id.0));
+ if gresp.dragged() {
+ let mut acc: f32 = ctx.data(|d| d.get_temp(acc_id).unwrap_or(0.0));
+ acc += gresp.drag_delta().x;
+ let frames = ((acc as f64 / pps) / fd).trunc() as i64;
+ if frames != 0 {
+ acc -= (frames as f64 * fd * pps) as f32;
+ actions.push(("layer.slip".into(), json!({"layers": [layer.id.0], "frames": frames, "merge": format!("slip-{}", layer.id.0)})));
+ }
+ ctx.data_mut(|d| d.insert_temp(acc_id, acc));
+ }
+ if gresp.drag_stopped() {
+ ctx.data_mut(|d| d.remove::<f32>(acc_id));
+ ui_actions.push(UiAct::EndMerge);
+ }
+ }
+ }
+
+ /// The source extent behind the bar (striped past its ends).
+ fn layer_source_extent(app: &mut EffectcraftApp, ui: &mut egui::Ui, g: &mut Rw, rc: &RowCtx<'_>, bar: Rect, lc: Color32) {
+ let tm = g.tl.tm;
+ let gp = g.gp.clone();
+ let layer = rc.layer;
+ let r = rc.r;
+ if let LayerSource::Footage { .. } | LayerSource::Comp { .. } = layer.source
+ && let Some(d) = layer.source.item().and_then(|i| app.session.project.item(i)).and_then(|i| i.duration())
+ {
+ let xs = tm.x(layer.start_time.seconds());
+ let xe = tm.x(layer.comp_time(d).seconds());
+ let ghost = Rect::from_min_max(pos2(xs.min(xe), r.min.y + 9.0), pos2(xs.max(xe), r.max.y - 9.0));
+ gp.rect_filled(ghost, 1.0, lc.gamma_multiply(0.18));
+ // The bar past the source's end (its last frame held) or before its start
+ // is striped, so the source's own span shows (#290). Time remapping
+ // decides what shows there itself.
+ if layer.props.get("timeRemap").is_none() {
+ for (side, part) in [
+ ("beforeSource", Rect::from_min_max(bar.min, pos2(ghost.min.x, bar.max.y))),
+ ("afterSource", Rect::from_min_max(pos2(ghost.max.x, bar.min.y), bar.max)),
+ ] {
+ if part.width() >= 1.0 {
+ stripes(&gp, part, lc);
+ app.auto.add(&format!("timeline.layer.{}.bar.{side}", layer.id.0), part, "Past the source");
}
}
- RowKind::Group { uid, name, open, has_children, fx, eye } => {
- // The row draws an effect's name in the interface language (#821); `name` stays
- // the property tree's, which the automation labels below keep. Any other group
- // (a mask, a shape group, a layer style) draws its own name.
- let group = layer.props.find_group(*uid);
- let shown = match group.and_then(|g| match &g.kind {
- GroupKind::Effect { effect } => Some(effect.as_str()),
- _ => None,
- }) {
- Some(effect) => crate::i18n::effects::group(effect, name),
- None => name.clone(),
+ }
+ slip_source_handles(app, ui, g, rc, ghost, bar);
+ }
+ }
+
+ /// The bar's move body and trim edges, click selection.
+ fn layer_bar_hits(app: &mut EffectcraftApp, ui: &mut egui::Ui, g: &mut Rw, rc: &RowCtx<'_>, bar: Rect) -> BarResps {
+ let cid = g.tl.cid;
+ let ctx = g.tl.ctx.clone();
+ let comp = g.tl.comp.clone();
+ let rows = &g.tl.rows;
+ let actions = &mut g.tl.actions;
+ let selected = &g.selected;
+ let layer = rc.layer;
+ let is_sel = rc.is_sel;
+ app.auto.add(&format!("timeline.layer.{}.bar", layer.id.0), bar, &layer.name);
+ // Interactions: move body, trim edges.
+ let (body_r, in_r, out_r) = trim_zones(bar);
+ let body = ui.interact(body_r, egui::Id::unique(("bar", layer.id.0)), Sense::click_and_drag());
+ let lin = ui.interact(in_r, egui::Id::unique(("bar-in", layer.id.0)), Sense::drag());
+ let lout = ui.interact(out_r, egui::Id::unique(("bar-out", layer.id.0)), Sense::drag());
+ app.auto.add(&format!("timeline.layer.{}.bar.in", layer.id.0), in_r, "Trim In");
+ app.auto.add(&format!("timeline.layer.{}.bar.out", layer.id.0), out_r, "Trim Out");
+ if lin.hovered() || lout.hovered() || lin.dragged() || lout.dragged() {
+ trim_cursor(&ctx);
+ }
+ if body.double_clicked()
+ && let Some(a) = double_click_action(layer)
+ {
+ actions.push(a);
+ }
+ let shift = ui.input(|i| i.modifiers.shift);
+ if let Some(layers) = (body.clicked() && shift).then(|| shift_range(&ctx, cid, &comp, rows, selected, layer.id)).flatten() {
+ // Shift-click: the layers from the last one clicked to this one, as in
+ // the layer outline.
+ actions.push(("layer.select".into(), json!({"layers": layers})));
+ } else {
+ if (body.clicked() || body.drag_started()) && !is_sel {
+ actions.push(("layer.select".into(), json!({"layers": [layer.id.0], "add": shift})));
+ }
+ if (body.clicked() || body.drag_started()) && !shift {
+ set_anchor(&ctx, cid, layer.id);
+ }
+ }
+ layer_context_menu(&body, &comp, layer, selected, LayerMenuCaps::of(&app.session.project, layer), &mut app.auto, &mut *actions);
+ BarResps { body, lin, lout }
+ }
+
+ fn layer_quick_offset_begin(ui: &mut egui::Ui, g: &Rw, rc: &RowCtx<'_>, body: &egui::Response) -> bool {
+ let ctx = g.tl.ctx.clone();
+ let comp = g.tl.comp.clone();
+ let selected = &g.selected;
+ let layer = rc.layer;
+ let is_sel = rc.is_sel;
+ let mods = ui.input(|i| i.modifiers);
+ if body.drag_started()
+ && is_sel
+ && mods.command
+ && mods.alt
+ && let Some(n) = quick_offset_layers(&comp, selected.iter().copied())
+ && let Some(p) = ctx.input(|i| i.pointer.press_origin())
+ {
+ ctx.data_mut(|d| d.insert_temp(quick_bar_id(), QuickBar { layer: layer.id, origin_x: p.x, layers: n, applied: 0 }));
+ }
+ ctx.data(|d| d.get_temp::<QuickBar>(quick_bar_id())).is_some_and(|q| q.layer == layer.id)
+ }
+
+ /// Moving and trimming a layer bar by whole frames.
+ fn layer_bar_drag(g: &mut Rw, rc: &RowCtx<'_>, bars: &BarResps, quick: bool) {
+ let BarResps { body, lin, lout } = bars;
+ let pps = g.tl.pps;
+ let fd = g.tl.fd;
+ let ctx = g.tl.ctx.clone();
+ let actions = &mut g.tl.actions;
+ let selected = &g.selected;
+ let ui_actions = &mut g.ui_actions;
+ let layer = rc.layer;
+ let is_sel = rc.is_sel;
+ let drag_key = format!("bar-{}", layer.id.0);
+ for (resp, kind) in [(&body, "move"), (&lin, "in"), (&lout, "out")] {
+ if kind == "move" && quick {
+ continue;
+ }
+ if resp.dragged() {
+ let acc_id = egui::Id::unique(("bar-acc", layer.id.0, kind));
+ let mut acc: f32 = ctx.data(|d| d.get_temp(acc_id).unwrap_or(0.0));
+ acc += resp.drag_delta().x;
+ let frames = ((acc as f64 / pps) / fd).trunc() as i64;
+ if frames != 0 {
+ acc -= (frames as f64 * fd * pps) as f32;
+ let d = frames as f64 * fd;
+ // Moving or trimming a selected layer acts on the whole
+ // selection; each layer trims from its own in/out point.
+ let targets = if is_sel { json!(selected.iter().map(|l| l.0).collect::<Vec<_>>()) } else { json!([layer.id.0]) };
+ let params = match kind {
+ "move" => json!({"layers": targets, "delta": d, "merge": drag_key}),
+ "in" => json!({"layers": targets, "inDelta": d, "merge": drag_key}),
+ _ => json!({"layers": targets, "outDelta": d, "merge": drag_key}),
};
- // Selected groups (an effect, a mask, a shape group…) highlight like selected
- // property rows.
- let sel_group = app.session.state.selected_props.contains(&(layer.id, *uid));
- lp.rect_filled(
- left,
- 0.0,
- if sel_group {
- t.row_selected
- } else if ri % 2 == 0 {
- t.row
- } else {
- t.row_alt
- },
- );
- gp.rect_filled(Rect::from_min_max(pos2(graph_x0, r.min.y), r.max), 0.0, t.tl_bg);
- let indent = cw.name + 6.0 + 14.0 * row.depth as f32;
- if *has_children {
- let tw = Rect::from_center_size(pos2(indent, cy), vec2(13.0, 13.0));
- if widgets::twirl(ui, tw, *open, egui::Id::new(("gtw", uid)), &t).clicked() {
- // Alt/Cmd-click twirls the whole tree under the group (as on a layer).
- ui_actions.push(UiAct::ToggleGroup(layer.id.0, *uid, ui.input(|i| i.modifiers.alt || i.modifiers.command)));
- }
- app.auto.add(&format!("timeline.group.{uid}.twirl"), tw, name);
- }
- if let Some(en) = fx {
- let fr_ = Rect::from_center_size(pos2(cw.switches + SW * 3.0 + SW / 2.0, cy), vec2(16.0, 16.0));
- if widgets::icon_toggle(ui, fr_, Icon::Fx, *en, &t, egui::Id::new(("gfx", uid)), Sense::click()).clicked() {
- actions.push(("effect.toggle".into(), json!({"layer": layer.id.0, "effect": uid})));
- }
- app.auto.add(&format!("timeline.group.{uid}.fx"), fr_, name);
- }
- if let Some(en) = eye {
- // Layer style eye switch in the A/V column, like AE.
- let er = Rect::from_center_size(pos2(cw.av + 10.0, cy), vec2(15.0, 15.0));
- lp.rect_stroke(er.shrink(1.5), 2.0, Stroke::new(1.0, t.separator), StrokeKind::Inside);
- if widgets::icon_toggle(ui, er, Icon::Eye, *en, &t, egui::Id::new(("geye", uid)), Sense::click()).clicked() {
- actions.push(("layer.style.toggle".into(), json!({"layer": layer.id.0, "style": uid})));
- }
- app.auto.add(&format!("timeline.group.{uid}.eye"), er, name);
- }
- let group_edit: Option<(u64, u64, String)> = ctx.data(|d| d.get_temp(group_rename_id()));
- if let Some((_, _, mut buf)) = group_edit.filter(|(rl, ru, _)| *rl == layer.id.0 && ru == uid) {
- let field = Rect::from_min_max(pos2(indent + 8.0, r.min.y + 2.0), pos2((cw.switches - 4.0).max(indent + 60.0), r.max.y - 2.0));
- let mut child = ui.new_child(egui::UiBuilder::new().max_rect(field));
- let er = child.add(egui::TextEdit::singleline(&mut buf).font(Tokens::ui(12.0)).desired_width(field.width()));
- app.auto.add(&format!("timeline.group.{uid}.nameEdit"), er.rect, &buf);
- if ctx.data_mut(|d| d.remove_temp::<bool>(rename_focus_id())).unwrap_or(false) {
- er.request_focus();
- widgets::select_all(&ctx, er.id, &buf);
- }
- if er.lost_focus() {
- if !ui.input(|i| i.key_pressed(egui::Key::Escape)) && !buf.trim().is_empty() && buf != *name {
- actions.push(("prop.renameGroup".into(), json!({"layer": layer.id.0, "prop": uid, "name": buf})));
- }
- ctx.data_mut(|d| d.remove::<(u64, u64, String)>(group_rename_id()));
- } else {
- ctx.data_mut(|d| d.insert_temp(group_rename_id(), (layer.id.0, *uid, buf)));
- }
- } else {
- lp.text(pos2(indent + 10.0, cy), Align2::LEFT_CENTER, &shown, Tokens::ui(12.0), t.text);
- }
- text_anim_popups(app, ui, &lp, layer, *uid, cw.switches, cy, &mut actions);
- shape_add_popup(app, ui, &lp, layer, *uid, cw.switches, cy, &mut actions);
- if *uid == GEOM_BIT | layer.id.0 {
- let lr = lp.text(pos2(cw.switches + 6.0, cy), Align2::LEFT_CENTER, crate::i18n::tr("Change Renderer…"), Tokens::ui(11.5), t.accent);
- let resp = ui
- .interact(lr, egui::Id::new(("tl-change-renderer", layer.id.0)), Sense::click())
- .on_hover_text(crate::i18n::tr("Composition Settings ▸ 3D Renderer"));
- if resp.hovered() {
- ctx.set_cursor_icon(egui::CursorIcon::PointingHand);
- }
- app.auto.add(&format!("timeline.layer.{}.changeRenderer", layer.id.0), lr, "Change Renderer…");
- if resp.clicked() {
- ui_actions.push(UiAct::ChangeRenderer);
- }
- }
- dash_buttons(app, ui, &lp, layer, *uid, cw.switches, cy, &mut actions);
- // Mask mode + inverted inline.
- if let Some(g) = layer.props.find_group(*uid)
- && let GroupKind::Mask { mode, inverted, .. } = g.kind
- {
- let mr = Rect::from_min_size(pos2(cw.switches + 4.0, cy - 9.0), vec2(80.0, 18.0));
- let pop = egui::Id::new(("maskmode", uid));
- if widgets::dropdown(ui, mr, mode.label(), &t, egui::Id::new(("mm", uid))).clicked() {
- widgets::open_popup(ui, pop);
- }
- let opts: Vec<String> = effectcraft_engine::project::MaskMode::ALL.iter().map(|m| m.label().to_string()).collect();
- if let Some(i) = widgets::popup_menu(ui, pop, mr.left_bottom(), &opts, None) {
- actions.push(("layer.setMask".into(), json!({"layer": layer.id.0, "mask": uid, "mode": opts[i]})));
- }
- let ir = Rect::from_min_size(pos2(mr.max.x + 8.0, cy - 8.0), vec2(16.0, 16.0));
- if widgets::checkbox(ui, ir, inverted, &t, egui::Id::new(("minv", uid))).changed() {
- actions.push(("layer.setMask".into(), json!({"layer": layer.id.0, "mask": uid, "inverted": !inverted})));
- }
- lp.text(pos2(ir.max.x + 4.0, cy), Align2::LEFT_CENTER, crate::i18n::tr("Inverted"), Tokens::ui(11.0), t.text_dim);
- }
- let gr_rect = Rect::from_min_max(pos2(indent + 8.0, r.min.y), pos2(cw.switches, r.max.y));
- let gr = ui.interact(gr_rect, egui::Id::new(("grow", uid)), Sense::click());
- app.auto.add(&format!("timeline.group.{uid}.name"), gr_rect, name);
- if gr.clicked() && uid & (WAVE_BIT | GEOM_BIT) == 0 {
- actions.push(("prop.select".into(), json!({"layer": layer.id.0, "prop": uid, "selectKeys": false})));
- }
- if gr.double_clicked() {
- if fx.is_some() {
- // An effect's name: open it in Effect Controls (as in After Effects).
- actions.push(("layer.select".into(), json!({"layers": [layer.id.0]})));
- actions.push(("prop.select".into(), json!({"layer": layer.id.0, "prop": uid, "selectKeys": false})));
- actions.push(("window.panel".into(), json!({"panel": "EffectControls"})));
- } else {
- ui_actions.push(UiAct::ToggleGroup(layer.id.0, *uid, false));
- }
- }
+ actions.push(("layer.timing".into(), params));
}
- RowKind::Waveform { item } => {
- lp.rect_filled(left, 0.0, if ri % 2 == 0 { t.row } else { t.row_alt });
- let indent = cw.name + 6.0 + 14.0 * row.depth as f32;
- lp.text(pos2(indent + 10.0, cy), Align2::LEFT_CENTER, "Waveform", Tokens::ui(12.0), t.text);
- let wr = Rect::from_min_max(pos2(graph_x0, r.min.y), r.max);
- gp.rect_filled(wr, 0.0, t.tl_bg);
- app.auto.add(&format!("timeline.layer.{}.waveform", layer.id.0), wr, "Waveform");
- match super::waveform::summary(app, &ctx, ItemId(*item)) {
- Some(s) => super::waveform::draw(&gp, wr.shrink2(vec2(0.0, 2.0)), &tm, layer, &s, Color32::from_rgb(0x5f, 0xc8, 0x8a)),
- None => {
- gp.text(
- pos2(tm.x(layer.in_point.seconds()).max(wr.min.x) + 6.0, wr.center().y),
- Align2::LEFT_CENTER,
- "Building waveform…",
- Tokens::ui(11.0),
- t.text_faint,
- );
- }
- }
+ ctx.data_mut(|d| d.insert_temp(acc_id, acc));
+ }
+ if resp.drag_stopped() {
+ ctx.data_mut(|d| d.remove::<f32>(egui::Id::unique(("bar-acc", layer.id.0, kind))));
+ ui_actions.push(UiAct::EndMerge);
+ }
+ }
+ }
+
+ fn layer_bar_markers(app: &mut EffectcraftApp, ui: &mut egui::Ui, g: &Rw, rc: &RowCtx<'_>) {
+ let graph_x0 = g.tl.graph_x0;
+ let tm = g.tl.tm;
+ let rows_rect = g.tl.rows_rect;
+ let comp = g.tl.comp.clone();
+ let layer = rc.layer;
+ let r = rc.r;
+ let gclip = rows_rect.intersect(Rect::from_min_max(pos2(graph_x0, rows_rect.min.y), rows_rect.max));
+ super::markers_ui::layer_markers(app, ui, gclip, &comp, layer, tm, r);
+ }
+
+ /// The group row's background and effect label bar; returns the name to draw.
+ fn group_background(app: &mut EffectcraftApp, g: &Rw, rc: &RowCtx<'_>) -> String {
+ let t = g.tl.t;
+ let graph_x0 = g.tl.graph_x0;
+ let lp = g.lp.clone();
+ let gp = g.gp.clone();
+ let layer = rc.layer;
+ let r = rc.r;
+ let left = rc.left;
+ let ri = rc.ri;
+ let RowKind::Group { uid, name, .. } = &rc.row.kind else { return String::new() };
+ let group = layer.props.find_group(*uid);
+ let shown = match group.and_then(|g| match &g.kind {
+ GroupKind::Effect { effect } => Some(effect.as_str()),
+ _ => None,
+ }) {
+ Some(effect) => crate::i18n::effects::group(effect, name),
+ None => name.clone(),
+ };
+ // Selected groups (an effect, a mask, a shape group…) highlight like selected
+ // property rows.
+ let sel_group = app.session.state.selected_props.contains(&(layer.id, *uid));
+ lp.rect_filled(
+ left,
+ 0.0,
+ if sel_group {
+ t.row_selected
+ } else if ri.is_multiple_of(2) {
+ t.row
+ } else {
+ t.row_alt
+ },
+ );
+ gp.rect_filled(Rect::from_min_max(pos2(graph_x0, r.min.y), r.max), 0.0, t.tl_bg);
+ // An effect's colour label (26.5): the same bar the Effect Controls header wears,
+ // on the row's left edge.
+ if let Some(lab) =
+ group.filter(|g| matches!(g.kind, GroupKind::Effect { .. })).and_then(|g| g.label).filter(|l| *l != effectcraft_engine::color::Label::None)
+ {
+ let [lr, lg, lb] = app.session.prefs.label_rgb(lab);
+ let bar = Rect::from_min_size(left.min, vec2(4.0, left.height()));
+ lp.rect_filled(bar, 0.0, Color32::from_rgb(lr, lg, lb));
+ app.auto.add(&format!("timeline.group.{uid}.label"), bar, &app.session.prefs.label_name(lab));
+ }
+ shown
+ }
+
+ /// The group's twirl, effect switch and style eye.
+ fn group_switches(app: &mut EffectcraftApp, ui: &mut egui::Ui, g: &mut Rw, rc: &RowCtx<'_>) {
+ let t = g.tl.t;
+ let cw = &g.tl.cw;
+ let actions = &mut g.tl.actions;
+ let lp = g.lp.clone();
+ let ui_actions = &mut g.ui_actions;
+ let layer = rc.layer;
+ let cy = rc.cy;
+ let indent = rc.indent;
+ let RowKind::Group { uid, name, open, has_children, fx, eye, .. } = &rc.row.kind else { return };
+ if *has_children {
+ let tw = Rect::from_center_size(pos2(indent, cy), vec2(13.0, 13.0));
+ if widgets::twirl(ui, tw, *open, egui::Id::unique(("gtw", uid)), &t).clicked() {
+ // Alt/Cmd-click twirls the whole tree under the group (as on a layer).
+ ui_actions.push(UiAct::ToggleGroup(layer.id.0, *uid, ui.input(|i| i.modifiers.alt || i.modifiers.command)));
+ }
+ app.auto.add(&format!("timeline.group.{uid}.twirl"), tw, name);
+ }
+ if let Some(en) = fx {
+ let fr_ = Rect::from_center_size(pos2(cw.switches + SW * 3.0 + SW / 2.0, cy), vec2(16.0, 16.0));
+ if widgets::icon_toggle(ui, fr_, Icon::Fx, *en, &t, egui::Id::unique(("gfx", uid)), Sense::click()).clicked() {
+ actions.push(("effect.toggle".into(), json!({"layer": layer.id.0, "effect": uid})));
+ }
+ app.auto.add(&format!("timeline.group.{uid}.fx"), fr_, name);
+ }
+ if let Some(en) = eye {
+ // Layer style eye switch in the A/V column, like AE.
+ let er = Rect::from_center_size(pos2(cw.av + 10.0, cy), vec2(15.0, 15.0));
+ lp.rect_stroke(er.shrink(1.5), 2.0, Stroke::new(1.0, t.separator), StrokeKind::Inside);
+ if widgets::icon_toggle(ui, er, Icon::Eye, *en, &t, egui::Id::unique(("geye", uid)), Sense::click()).clicked() {
+ actions.push(("layer.style.toggle".into(), json!({"layer": layer.id.0, "style": uid})));
+ }
+ app.auto.add(&format!("timeline.group.{uid}.eye"), er, name);
+ }
+ }
+
+ /// The group name, or its rename field.
+ fn group_name(app: &mut EffectcraftApp, ui: &mut egui::Ui, g: &mut Rw, rc: &RowCtx<'_>, shown: &str) {
+ let t = g.tl.t;
+ let ctx = g.tl.ctx.clone();
+ let cw = &g.tl.cw;
+ let actions = &mut g.tl.actions;
+ let lp = g.lp.clone();
+ let layer = rc.layer;
+ let r = rc.r;
+ let cy = rc.cy;
+ let indent = rc.indent;
+ let RowKind::Group { uid, name, .. } = &rc.row.kind else { return };
+ let group_edit: Option<(u64, u64, String)> = ctx.data(|d| d.get_temp(group_rename_id()));
+ if let Some((_, _, mut buf)) = group_edit.filter(|(rl, ru, _)| *rl == layer.id.0 && ru == uid) {
+ let field = Rect::from_min_max(pos2(indent + 8.0, r.min.y + 2.0), pos2((cw.switches - 4.0).max(indent + 60.0), r.max.y - 2.0));
+ let mut child = ui.new_child(egui::UiBuilder::new().max_rect(field));
+ let er = child.add(egui::TextEdit::singleline(&mut buf).font(Tokens::ui(12.0)).desired_width(field.width()));
+ app.auto.add(&format!("timeline.group.{uid}.nameEdit"), er.rect, &buf);
+ if ctx.data_mut(|d| d.remove_temp::<bool>(rename_focus_id())).unwrap_or(false) {
+ er.request_focus();
+ widgets::select_all(&ctx, er.id, &buf);
+ }
+ if er.lost_focus() {
+ if !ui.input(|i| i.key_pressed(egui::Key::Escape)) && !buf.trim().is_empty() && buf != *name {
+ actions.push(("prop.renameGroup".into(), json!({"layer": layer.id.0, "prop": uid, "name": buf})));
}
- RowKind::Expr { uid, lines } => {
- let Some(prop) = layer.props.find(*uid) else { continue };
- let Some(ex) = prop.expr.clone() else { continue };
- let (buf_id, edit_id) = (expr_buf_id(*uid), egui::Id::new(("expr-edit", uid)));
- // The same background as its property's row, selection included.
- let sel_prop = app.session.state.selected_props.contains(&(layer.id, *uid));
- lp.rect_filled(
- left,
- 0.0,
- if sel_prop {
- t.row_selected
- } else if ri % 2 == 0 {
- t.row
- } else {
- t.row_alt
- },
- );
- let indent = cw.name + 6.0 + 14.0 * row.depth as f32;
- lp.text(pos2(indent + 12.0, cy), Align2::LEFT_CENTER, crate::i18n::tr("Expression:"), Tokens::ui(11.5), t.text_dim);
- lp.text(pos2(indent + 82.0, cy), Align2::LEFT_CENTER, &prop.name, Tokens::ui(11.5), t.text);
- // "=" enable switch and the property pick whip (AE's expression controls).
- let en_r = Rect::from_center_size(pos2(cw.switches + 10.0, cy), vec2(16.0, 16.0));
- let en = ui.interact(en_r, egui::Id::new(("expr-en", uid)), Sense::click()).on_hover_text(crate::i18n::tr("Enable Expression"));
- lp.rect_stroke(en_r.shrink(1.0), 2.0, Stroke::new(1.0, t.separator), StrokeKind::Inside);
- let expr_col = t.expr_text;
- lp.text(
- en_r.center(),
- Align2::CENTER_CENTER,
- if ex.enabled { "=" } else { "≠" },
- Tokens::semibold(13.0),
- if ex.enabled { expr_col } else { t.text_dim },
- );
- app.auto.add(&format!("timeline.prop.{uid}.exprEnable"), en_r, "Enable Expression");
- if en.clicked() {
- actions.push(("prop.setExpression".into(), json!({"layer": layer.id.0, "prop": uid, "enabled": !ex.enabled})));
- }
- let pw = pick_whip(
- app,
- ui,
- &lp,
- Rect::from_center_size(pos2(cw.switches + 30.0, cy), vec2(15.0, 15.0)),
- (WHIP_EXPR, layer.id.0, *uid),
- &format!("timeline.prop.{uid}.pickWhip"),
- "Expression pick whip",
- crate::i18n::tr("Expression pick whip: drag onto a property"),
- );
- if pw.is_pointer_button_down_on() && ui.input(|i| i.pointer.primary_pressed()) {
- // Pressed while the expression is being edited (its text is buffered while
- // the editor has the focus): the reference will go in at the cursor,
- // replacing the selection (#284).
- let into = ctx.data(|d| d.get_temp::<String>(buf_id)).map(|buf| {
- let n = buf.chars().count();
- let sel = egui::text_edit::TextEditState::load(&ctx, edit_id)
- .and_then(|st| st.cursor.char_range())
- .map_or([n, n], |r| [r.primary.index.0.min(r.secondary.index.0).min(n), r.primary.index.0.max(r.secondary.index.0).min(n)]);
- (buf, sel)
- });
- ctx.data_mut(|d| {
- if let Some(into) = into {
- d.insert_temp(whip_into_id(*uid), into);
- } else {
- d.remove::<WhipInto>(whip_into_id(*uid));
- }
- });
- }
- // Syntax errors: warning in the outline (the expression is disabled).
- if let Some(check) = app.session.expr_check
- && let Err(e) = check(&ex.text)
- {
- let wr = Rect::from_center_size(pos2(cw.switches + 50.0, cy), vec2(14.0, 14.0));
- lp.text(wr.center(), Align2::CENTER_CENTER, "⚠", Tokens::ui(12.0), Color32::from_rgb(0xf0, 0xa0, 0x30));
- let _ = ui.interact(wr, egui::Id::new(("expr-err", uid)), Sense::hover()).on_hover_text(e);
- }
- // ⓕ: the Expression Language menu inserts at the cursor.
- let lang_r = Rect::from_center_size(pos2(cw.switches + 70.0, cy), vec2(16.0, 16.0));
- let lang = ui.interact(lang_r, egui::Id::new(("expr-lang", uid)), Sense::click()).on_hover_text(crate::i18n::tr("Expression Language Menu"));
- lp.circle_stroke(lang_r.center(), 6.5, Stroke::new(1.0, if lang.hovered() { t.text } else { t.text_dim }));
- lp.text(lang_r.center(), Align2::CENTER_CENTER, "f", Tokens::semibold(10.0), if lang.hovered() { t.text } else { t.text_dim });
- app.auto.add(&format!("timeline.prop.{uid}.exprLanguage"), lang_r, "Expression Language Menu");
- let mut picked: Option<&'static str> = None;
- egui::Popup::menu(&lang).style(crate::widgets::menu_style).show(|ui| {
- for (cat, items) in effectcraft_engine::commands::expr_tools::language_menu() {
- ui.menu_button(cat, |ui| {
- widgets::menu_scroll(ui, |ui| {
- for (label, text) in items {
- if ui.button(label).clicked() {
- picked = Some(text);
- ui.close();
- }
- }
- })
- });
- }
- });
- if let Some(text) = picked {
- let cur: String = ctx.data(|d| d.get_temp(buf_id)).unwrap_or_else(|| ex.text.clone());
- let at = egui::text_edit::TextEditState::load(&ctx, edit_id)
- .and_then(|st| st.cursor.char_range())
- .map(|r| r.primary.index.0)
- .unwrap_or(cur.chars().count())
- .min(cur.chars().count());
- let byte = cur.char_indices().nth(at).map(|(b, _)| b).unwrap_or(cur.len());
- let mut next = cur.clone();
- next.insert_str(byte, text);
- actions.push(("prop.setExpression".into(), json!({"layer": layer.id.0, "prop": uid, "expression": next})));
- ctx.data_mut(|d| d.remove::<String>(buf_id));
- }
- // The editor in the time-graph area.
- ui.set_clip_rect(right_clip);
- gp.rect_filled(Rect::from_min_max(pos2(graph_x0, r.min.y), r.max), 0.0, t.expr_bg);
- let er = Rect::from_min_max(pos2(graph_x0 + 8.0, r.min.y + 3.0), pos2(rect.max.x - 14.0, r.max.y - 3.0));
- let mut buf: String = ctx.data(|d| d.get_temp(buf_id)).unwrap_or_else(|| ex.text.clone());
- if let Some(after) = ctx.data_mut(|d| d.remove_temp::<usize>(expr_refocus_id(*uid))) {
- // A pick whip just put a reference in: editing goes on in the new text,
- // the cursor after the reference.
- buf = ex.text.clone();
- let mut st = egui::text_edit::TextEditState::load(&ctx, edit_id).unwrap_or_default();
- st.cursor.set_char_range(Some(egui::text::CCursorRange::one(egui::text::CCursor::new(buf.chars().count().saturating_sub(after)))));
- st.store(&ctx, edit_id);
- ctx.memory_mut(|m| m.request_focus(edit_id));
- }
- // Settings ▸ Scripting & Expressions ▸ Expressions Editor.
- let sp = app.session.prefs.scripting.clone();
- let resp = super::expr_editor::editor(ui, edit_id, &mut buf, er, &sp, if ex.enabled { expr_col } else { t.text_dim }, *lines, &t);
- app.auto.add(&format!("timeline.prop.{uid}.expression"), er, &prop.name);
- // Its bottom edge drags to set its height in whole lines, as in After Effects.
- let edge = Rect::from_min_max(pos2(er.min.x, r.max.y - 4.0), pos2(er.max.x, r.max.y));
- let eresp = ui.interact(edge, egui::Id::new(("expr-edge", uid)), Sense::drag());
- app.auto.add(&format!("timeline.prop.{uid}.expressionHeight"), edge, "Expression field height");
- if eresp.hovered() || eresp.dragged() {
- ctx.set_cursor_icon(egui::CursorIcon::ResizeVertical);
- }
- if let Some(py) = eresp.interact_pointer_pos().filter(|_| eresp.dragged()).map(|p| p.y) {
- let n = ((py - r.min.y) / rh).round().clamp(1.0, EXPR_MAX_LINES as f32);
- app.ui.timeline.expr_lines.insert(*uid, n as usize);
- }
- let commit = resp.has_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter) && (i.modifiers.command || i.modifiers.ctrl));
- if commit {
- resp.surrender_focus();
- }
- if resp.has_focus() && !commit {
- ctx.data_mut(|d| d.insert_temp(buf_id, buf));
- } else {
- if (resp.lost_focus() || commit) && buf.trim_end() != ex.text {
- actions.push(("prop.setExpression".into(), json!({"layer": layer.id.0, "prop": uid, "expression": buf.trim_end()})));
- }
- ctx.data_mut(|d| d.remove::<String>(buf_id));
- }
+ ctx.data_mut(|d| d.remove::<(u64, u64, String)>(group_rename_id()));
+ } else {
+ ctx.data_mut(|d| d.insert_temp(group_rename_id(), (layer.id.0, *uid, buf)));
+ }
+ } else {
+ lp.text(pos2(indent + 10.0, cy), Align2::LEFT_CENTER, shown, Tokens::ui(12.0), t.text);
+ }
+ }
+
+ /// Add / animate popups, Change Renderer and dash buttons.
+ fn group_popups(app: &mut EffectcraftApp, ui: &mut egui::Ui, g: &mut Rw, rc: &RowCtx<'_>) {
+ let t = g.tl.t;
+ let ctx = g.tl.ctx.clone();
+ let cw = &g.tl.cw;
+ let actions = &mut g.tl.actions;
+ let lp = g.lp.clone();
+ let ui_actions = &mut g.ui_actions;
+ let layer = rc.layer;
+ let cy = rc.cy;
+ let RowKind::Group { uid, .. } = &rc.row.kind else { return };
+ text_anim_popups(app, ui, &lp, layer, *uid, pos2(cw.switches, cy), &mut *actions);
+ shape_add_popup(app, ui, &lp, layer, *uid, pos2(cw.switches, cy), &mut *actions);
+ if *uid == GEOM_BIT | layer.id.0 {
+ let lr = lp.text(pos2(cw.switches + 6.0, cy), Align2::LEFT_CENTER, crate::i18n::tr("Change Renderer…"), Tokens::ui(11.5), t.accent);
+ let resp = ui
+ .interact(lr, egui::Id::unique(("tl-change-renderer", layer.id.0)), Sense::click())
+ .on_hover_text(crate::i18n::tr("Composition Settings ▸ 3D Renderer"));
+ if resp.hovered() {
+ ctx.set_cursor_icon(egui::CursorIcon::PointingHand);
+ }
+ app.auto.add(&format!("timeline.layer.{}.changeRenderer", layer.id.0), lr, "Change Renderer…");
+ if resp.clicked() {
+ ui_actions.push(UiAct::ChangeRenderer);
+ }
+ }
+ dash_buttons(app, ui, &lp, layer, *uid, pos2(cw.switches, cy), &mut *actions);
+ }
+
+ /// Mask mode and inverted, inline.
+ fn group_mask_mode(ui: &mut egui::Ui, g: &mut Rw, rc: &RowCtx<'_>) {
+ let t = g.tl.t;
+ let cw = &g.tl.cw;
+ let actions = &mut g.tl.actions;
+ let lp = g.lp.clone();
+ let layer = rc.layer;
+ let cy = rc.cy;
+ let RowKind::Group { uid, .. } = &rc.row.kind else { return };
+ // Mask mode + inverted inline.
+ if let Some(g) = layer.props.find_group(*uid)
+ && let GroupKind::Mask { mode, inverted, .. } = g.kind
+ {
+ let mr = Rect::from_min_size(pos2(cw.switches + 4.0, cy - 9.0), vec2(80.0, 18.0));
+ let pop = egui::Id::unique(("maskmode", uid));
+ if widgets::dropdown(ui, mr, mode.label(), &t, egui::Id::unique(("mm", uid))).clicked() {
+ widgets::open_popup(ui, pop);
+ }
+ let opts: Vec<String> = effectcraft_engine::project::MaskMode::ALL.iter().map(|m| m.label().to_string()).collect();
+ if let Some(i) = widgets::popup_menu(ui, pop, mr.left_bottom(), &opts, None) {
+ actions.push(("layer.setMask".into(), json!({"layer": layer.id.0, "mask": uid, "mode": opts[i]})));
+ }
+ let ir = Rect::from_min_size(pos2(mr.max.x + 8.0, cy - 8.0), vec2(16.0, 16.0));
- if widgets::checkbox(ui, ir, inverted, &t, egui::Id::unique(("minv", uid))).clicked() {
++ if widgets::checkbox(ui, ir, inverted, &t, egui::Id::unique(("minv", uid))).changed() {
+ actions.push(("layer.setMask".into(), json!({"layer": layer.id.0, "mask": uid, "inverted": !inverted})));
+ }
+ lp.text(pos2(ir.max.x + 4.0, cy), Align2::LEFT_CENTER, crate::i18n::tr("Inverted"), Tokens::ui(11.0), t.text_dim);
+ }
+ }
+
+ /// Group row click and double-click.
+ fn group_row_click(app: &mut EffectcraftApp, ui: &mut egui::Ui, g: &mut Rw, rc: &RowCtx<'_>) {
+ let cw = &g.tl.cw;
+ let actions = &mut g.tl.actions;
+ let ui_actions = &mut g.ui_actions;
+ let layer = rc.layer;
+ let r = rc.r;
+ let indent = rc.indent;
+ let RowKind::Group { uid, name, fx, .. } = &rc.row.kind else { return };
+ let gr_rect = Rect::from_min_max(pos2(indent + 8.0, r.min.y), pos2(cw.switches, r.max.y));
+ let gr = ui.interact(gr_rect, egui::Id::unique(("grow", uid)), Sense::click());
+ app.auto.add(&format!("timeline.group.{uid}.name"), gr_rect, name);
+ if gr.clicked() && uid & (WAVE_BIT | GEOM_BIT) == 0 {
+ actions.push(("prop.select".into(), json!({"layer": layer.id.0, "prop": uid, "selectKeys": false})));
+ }
+ if gr.double_clicked() {
+ if fx.is_some() {
+ // An effect's name: open it in Effect Controls (as in After Effects).
+ actions.push(("layer.select".into(), json!({"layers": [layer.id.0]})));
+ actions.push(("prop.select".into(), json!({"layer": layer.id.0, "prop": uid, "selectKeys": false})));
+ actions.push(("window.panel".into(), json!({"panel": "EffectControls"})));
+ } else {
+ ui_actions.push(UiAct::ToggleGroup(layer.id.0, *uid, false));
+ }
+ }
+ }
+
+ fn waveform_row(app: &mut EffectcraftApp, g: &Rw, rc: &RowCtx<'_>) {
+ let t = g.tl.t;
+ let graph_x0 = g.tl.graph_x0;
+ let tm = g.tl.tm;
+ let ctx = g.tl.ctx.clone();
+ let cw = &g.tl.cw;
+ let lp = g.lp.clone();
+ let gp = g.gp.clone();
+ let row = rc.row;
+ let layer = rc.layer;
+ let r = rc.r;
+ let left = rc.left;
+ let cy = rc.cy;
+ let ri = rc.ri;
+ let RowKind::Waveform { item, .. } = &rc.row.kind else { return };
+ lp.rect_filled(left, 0.0, if ri.is_multiple_of(2) { t.row } else { t.row_alt });
+ let indent = cw.name + 6.0 + 14.0 * row.depth as f32;
+ lp.text(pos2(indent + 10.0, cy), Align2::LEFT_CENTER, "Waveform", Tokens::ui(12.0), t.text);
+ let wr = Rect::from_min_max(pos2(graph_x0, r.min.y), r.max);
+ gp.rect_filled(wr, 0.0, t.tl_bg);
+ app.auto.add(&format!("timeline.layer.{}.waveform", layer.id.0), wr, "Waveform");
+ match super::waveform::summary(app, &ctx, ItemId(*item)) {
+ Some(s) => super::waveform::draw(&gp, wr.shrink2(vec2(0.0, 2.0)), &tm, layer, &s, Color32::from_rgb(0x5f, 0xc8, 0x8a)),
+ None => {
+ gp.text(
+ pos2(tm.x(layer.in_point.seconds()).max(wr.min.x) + 6.0, wr.center().y),
+ Align2::LEFT_CENTER,
+ "Building waveform…",
+ Tokens::ui(11.0),
+ t.text_faint,
+ );
+ }
+ }
+ }
+
+ /// The expression row's outline side: enable, pick whip and syntax warning.
+ fn expr_controls(app: &mut EffectcraftApp, ui: &mut egui::Ui, g: &mut Rw, rc: &RowCtx<'_>, st: &ExprRow<'_>) {
+ let ExprRow { prop, ex, buf_id, edit_id, .. } = *st;
+ let t = g.tl.t;
+ let ctx = g.tl.ctx.clone();
+ let cw = &g.tl.cw;
+ let actions = &mut g.tl.actions;
+ let lp = g.lp.clone();
+ let row = rc.row;
+ let layer = rc.layer;
+ let left = rc.left;
+ let cy = rc.cy;
+ let ri = rc.ri;
+ let RowKind::Expr { uid, .. } = &rc.row.kind else { return };
+ let sel_prop = app.session.state.selected_props.contains(&(layer.id, *uid));
+ lp.rect_filled(
+ left,
+ 0.0,
+ if sel_prop {
+ t.row_selected
+ } else if ri.is_multiple_of(2) {
+ t.row
+ } else {
+ t.row_alt
+ },
+ );
+ let indent = cw.name + 6.0 + 14.0 * row.depth as f32;
+ lp.text(pos2(indent + 12.0, cy), Align2::LEFT_CENTER, crate::i18n::tr("Expression:"), Tokens::ui(11.5), t.text_dim);
+ lp.text(pos2(indent + 82.0, cy), Align2::LEFT_CENTER, &prop.name, Tokens::ui(11.5), t.text);
+ // "=" enable switch and the property pick whip (AE's expression controls).
+ let en_r = Rect::from_center_size(pos2(cw.switches + 10.0, cy), vec2(16.0, 16.0));
+ let en = ui.interact(en_r, egui::Id::unique(("expr-en", uid)), Sense::click()).on_hover_text(crate::i18n::tr("Enable Expression"));
+ lp.rect_stroke(en_r.shrink(1.0), 2.0, Stroke::new(1.0, t.separator), StrokeKind::Inside);
+ let expr_col = t.expr_text;
+ lp.text(en_r.center(), Align2::CENTER_CENTER, if ex.enabled { "=" } else { "≠" }, Tokens::semibold(13.0), if ex.enabled { expr_col } else { t.text_dim });
+ app.auto.add(&format!("timeline.prop.{uid}.exprEnable"), en_r, "Enable Expression");
+ if en.clicked() {
+ actions.push(("prop.setExpression".into(), json!({"layer": layer.id.0, "prop": uid, "enabled": !ex.enabled})));
+ }
+ let pw = pick_whip(
+ app,
+ ui,
+ &lp,
+ Rect::from_center_size(pos2(cw.switches + 30.0, cy), vec2(15.0, 15.0)),
+ (WHIP_EXPR, layer.id.0, *uid),
+ WhipText {
+ auto: &format!("timeline.prop.{uid}.pickWhip"),
+ label: "Expression pick whip",
+ hint: crate::i18n::tr("Expression pick whip: drag onto a property"),
+ },
+ );
+ if pw.is_pointer_button_down_on() && ui.input(|i| i.pointer.primary_pressed()) {
+ // Pressed while the expression is being edited (its text is buffered while
+ // the editor has the focus): the reference will go in at the cursor,
+ // replacing the selection (#284).
+ let into = ctx.data(|d| d.get_temp::<String>(buf_id)).map(|buf| {
+ let n = buf.chars().count();
+ let sel = egui::text_edit::TextEditState::load(&ctx, edit_id)
+ .and_then(|st| st.cursor.char_range())
+ .map_or([n, n], |r| [r.primary.index.0.min(r.secondary.index.0).min(n), r.primary.index.0.max(r.secondary.index.0).min(n)]);
+ (buf, sel)
+ });
+ ctx.data_mut(|d| {
+ if let Some(into) = into {
+ d.insert_temp(whip_into_id(*uid), into);
+ } else {
+ d.remove::<WhipInto>(whip_into_id(*uid));
}
- RowKind::Prop { uid } => {
- let Some(prop) = layer.props.find(*uid) else { continue };
- app.auto.add(&format!("timeline.prop.{uid}.row"), r, &prop.name);
- let sel_prop = app.session.state.selected_props.contains(&(layer.id, *uid));
- lp.rect_filled(
- left,
- 0.0,
- if sel_prop {
- t.row_selected
- } else if ri % 2 == 0 {
- t.row
- } else {
- t.row_alt
- },
- );
- gp.rect_filled(Rect::from_min_max(pos2(graph_x0, r.min.y), r.max), 0.0, t.tl_bg);
- let indent = cw.name + 6.0 + 14.0 * row.depth as f32;
- // Keyframe navigator (in the A/V column, like AE).
- // (in the Keys column when it is shown).
- if prop.is_animated() && (vis.keys || vis.av) {
- let lt = layer.layer_time(time);
- let at_key = effectcraft_engine::keyframe::key_at(&prop.keys, lt).is_some();
- let nav_x = if vis.keys { cw.keys + 12.0 } else { cw.av + 18.0 };
- let prev = Rect::from_center_size(pos2(nav_x, cy), vec2(12.0, 14.0));
- let mid = Rect::from_center_size(pos2(nav_x + 16.0, cy), vec2(14.0, 14.0));
- let next = Rect::from_center_size(pos2(nav_x + 32.0, cy), vec2(12.0, 14.0));
- icons::paint(&lp, prev.shrink(2.0), Icon::ChevronLeft, t.text_dim);
- icons::paint(&lp, next.shrink(2.0), Icon::ChevronRight, t.text_dim);
- let kc = if at_key { t.keyframe_selected } else { Color32::TRANSPARENT };
- lp.add(egui::Shape::convex_polygon(
- vec![mid.center() + vec2(0.0, -5.0), mid.center() + vec2(5.0, 0.0), mid.center() + vec2(0.0, 5.0), mid.center() + vec2(-5.0, 0.0)],
- kc,
- Stroke::new(1.0, t.text_dim),
- ));
- if ui.interact(prev, egui::Id::new(("kprev", uid)), Sense::click()).clicked()
- && let Some(k) = prop.keys.iter().rev().find(|k| layer.comp_time(k.time).0 < time.0 - fr.frame_duration().0 / 2)
- {
- ui_actions.push(UiAct::SetTime(layer.comp_time(k.time)));
- }
- if ui.interact(next, egui::Id::new(("knext", uid)), Sense::click()).clicked()
- && let Some(k) = prop.keys.iter().find(|k| layer.comp_time(k.time).0 > time.0 + fr.frame_duration().0 / 2)
- {
- ui_actions.push(UiAct::SetTime(layer.comp_time(k.time)));
- }
- if ui.interact(mid, egui::Id::new(("kmid", uid)), Sense::click()).clicked() {
- actions.push(("prop.toggleKey".into(), json!({"layer": layer.id.0, "prop": uid})));
- }
- app.auto.add(&format!("timeline.prop.{uid}.addKey"), mid, "Add or remove keyframe");
- }
- // Stopwatch: Alt+click adds an expression; a press toggles the animation, and
- // dragging on over other stopwatches gives them the same state (#284).
- if !prop.static_only {
- let swr = Rect::from_center_size(pos2(indent, cy), vec2(15.0, 15.0));
- let resp = ui.interact(swr, egui::Id::new(("stopwatch", uid)), Sense::click_and_drag());
- let col = if prop.is_animated() {
- t.hot_text
- } else if resp.hovered() {
- t.text
- } else {
- t.text_dim
- };
- icons::paint(&lp, swr, Icon::Stopwatch, col);
- app.auto.add(&format!("timeline.prop.{uid}.stopwatch"), swr, &prop.name);
- if ui.input(|i| i.modifiers.alt) {
- if resp.clicked() {
- actions.push(("prop.setExpression".into(), json!({"layer": layer.id.0, "prop": uid})));
+ });
+ }
+ // Syntax errors: warning in the outline (the expression is disabled).
+ if let Some(check) = app.session.expr_check
+ && let Err(e) = check(&ex.text)
+ {
+ let wr = Rect::from_center_size(pos2(cw.switches + 50.0, cy), vec2(14.0, 14.0));
+ lp.text(wr.center(), Align2::CENTER_CENTER, "⚠", Tokens::ui(12.0), Color32::from_rgb(0xf0, 0xa0, 0x30));
+ let _ = ui.interact(wr, egui::Id::unique(("expr-err", uid)), Sense::hover()).on_hover_text(e);
+ }
+ }
+
+ /// The Expression Language menu inserts at the cursor.
+ fn expr_language_menu(app: &mut EffectcraftApp, ui: &mut egui::Ui, g: &mut Rw, rc: &RowCtx<'_>, st: &ExprRow<'_>) {
+ let ExprRow { ex, buf_id, edit_id, .. } = *st;
+ let t = g.tl.t;
+ let ctx = g.tl.ctx.clone();
+ let cw = &g.tl.cw;
+ let actions = &mut g.tl.actions;
+ let lp = g.lp.clone();
+ let layer = rc.layer;
+ let cy = rc.cy;
+ let RowKind::Expr { uid, .. } = &rc.row.kind else { return };
+ // ⓕ: the Expression Language menu inserts at the cursor.
+ let lang_r = Rect::from_center_size(pos2(cw.switches + 70.0, cy), vec2(16.0, 16.0));
+ let lang = ui.interact(lang_r, egui::Id::unique(("expr-lang", uid)), Sense::click()).on_hover_text(crate::i18n::tr("Expression Language Menu"));
+ lp.circle_stroke(lang_r.center(), 6.5, Stroke::new(1.0, if lang.hovered() { t.text } else { t.text_dim }));
+ lp.text(lang_r.center(), Align2::CENTER_CENTER, "f", Tokens::semibold(10.0), if lang.hovered() { t.text } else { t.text_dim });
+ app.auto.add(&format!("timeline.prop.{uid}.exprLanguage"), lang_r, "Expression Language Menu");
+ let mut picked: Option<&'static str> = None;
+ egui::Popup::menu(&lang).style(crate::widgets::menu_style).show(|ui| {
+ for (cat, items) in effectcraft_engine::commands::expr_tools::language_menu() {
+ ui.menu_button(cat, |ui| {
+ widgets::menu_scroll(ui, false, |ui| {
+ for (label, text) in items {
+ if ui.button(label).clicked() {
+ picked = Some(text);
+ ui.close();
}
- } else if let Some((value, merge)) = switch_gesture(ui, &resp, r, "stopwatch", prop.is_animated()) {
- actions.push(("prop.toggleAnimation".into(), json!({"layer": layer.id.0, "prop": uid, "value": value, "merge": merge})));
- } else if resp.clicked() && !resp.clicked_by(egui::PointerButton::Primary) {
- // Keyboard or accessibility activation.
- actions.push(("prop.toggleAnimation".into(), json!({"layer": layer.id.0, "prop": uid})));
}
+ })
+ });
+ }
+ });
+ if let Some(text) = picked {
+ let cur: String = ctx.data(|d| d.get_temp(buf_id)).unwrap_or_else(|| ex.text.clone());
+ let at = egui::text_edit::TextEditState::load(&ctx, edit_id)
+ .and_then(|st| st.cursor.char_range())
+ .map(|r| r.primary.index.0)
+ .unwrap_or(cur.chars().count())
+ .min(cur.chars().count());
+ let byte = cur.char_indices().nth(at).map(|(b, _)| b).unwrap_or(cur.len());
+ let mut next = cur.clone();
+ next.insert_str(byte, text);
+ actions.push(("prop.setExpression".into(), json!({"layer": layer.id.0, "prop": uid, "expression": next})));
+ ctx.data_mut(|d| d.remove::<String>(buf_id));
+ }
+ }
+
+ /// The expression editor in the time-graph area.
+ fn expr_editor_cell(app: &mut EffectcraftApp, ui: &mut egui::Ui, g: &mut Rw, rc: &RowCtx<'_>, st: &ExprRow<'_>) {
+ let ExprRow { prop, ex, buf_id, edit_id, .. } = *st;
+ let t = g.tl.t;
+ let rect = g.tl.rect;
+ let graph_x0 = g.tl.graph_x0;
+ let rh = g.tl.rh;
+ let ctx = g.tl.ctx.clone();
+ let actions = &mut g.tl.actions;
+ let right_clip = g.right_clip;
+ let gp = g.gp.clone();
+ let layer = rc.layer;
+ let r = rc.r;
+ let RowKind::Expr { uid, lines, .. } = &rc.row.kind else { return };
+ let expr_col = t.expr_text;
+ // The editor in the time-graph area.
+ ui.set_clip_rect(right_clip);
+ gp.rect_filled(Rect::from_min_max(pos2(graph_x0, r.min.y), r.max), 0.0, t.expr_bg);
+ let er = Rect::from_min_max(pos2(graph_x0 + 8.0, r.min.y + 3.0), pos2(rect.max.x - 14.0, r.max.y - 3.0));
+ let mut buf: String = ctx.data(|d| d.get_temp(buf_id)).unwrap_or_else(|| ex.text.clone());
+ if let Some(f) = ctx.data(|d| d.get_temp::<ExprFocus>(expr_focus_id())).filter(|f| f.prop == *uid) {
+ // Asked for once (a pick whip put a reference in, or an Alt-click added the
+ // expression): editing starts in the expression as it is now.
+ ctx.data_mut(|d| d.remove::<ExprFocus>(expr_focus_id()));
+ buf = ex.text.clone();
+ let n = buf.chars().count();
+ let [a, b] = f.select.map(|before_end| egui::text::CCursor::new(n.saturating_sub(before_end)));
+ let mut st = egui::text_edit::TextEditState::load(&ctx, edit_id).unwrap_or_default();
+ st.cursor.set_char_range(Some(egui::text::CCursorRange::two(a, b)));
+ st.store(&ctx, edit_id);
+ ctx.memory_mut(|m| m.request_focus(edit_id));
+ }
+ // Settings ▸ Scripting & Expressions ▸ Expressions Editor.
+ let sp = app.session.prefs.scripting.clone();
+ let resp = super::expr_editor::editor(
+ ui,
+ edit_id,
+ &mut buf,
+ er,
+ super::expr_editor::EditorOpts { prefs: &sp, color: if ex.enabled { expr_col } else { t.text_dim }, rows: *lines },
+ &t,
+ );
+ app.auto.add(&format!("timeline.prop.{uid}.expression"), er, &prop.name);
+ // Its bottom edge drags to set its height in whole lines, as in After Effects.
+ let edge = Rect::from_min_max(pos2(er.min.x, r.max.y - 4.0), pos2(er.max.x, r.max.y));
+ let eresp = ui.interact(edge, egui::Id::unique(("expr-edge", uid)), Sense::drag());
+ app.auto.add(&format!("timeline.prop.{uid}.expressionHeight"), edge, "Expression field height");
+ if eresp.hovered() || eresp.dragged() {
+ ctx.set_cursor_icon(egui::CursorIcon::ResizeVertical);
+ }
+ if let Some(py) = eresp.interact_pointer_pos().filter(|_| eresp.dragged()).map(|p| p.y) {
+ let n = ((py - r.min.y) / rh).round().clamp(1.0, EXPR_MAX_LINES as f32);
+ app.ui.timeline.expr_lines.insert(*uid, n as usize);
+ }
+ let commit = resp.has_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter) && (i.modifiers.command || i.modifiers.ctrl));
+ if commit {
+ resp.surrender_focus();
+ }
+ if resp.has_focus() && !commit {
+ ctx.data_mut(|d| d.insert_temp(buf_id, buf));
+ } else {
+ if (resp.lost_focus() || commit) && buf.trim_end() != ex.text {
+ actions.push(("prop.setExpression".into(), json!({"layer": layer.id.0, "prop": uid, "expression": buf.trim_end()})));
+ }
+ ctx.data_mut(|d| d.remove::<String>(buf_id));
+ }
+ }
+
+ fn prop_background(app: &mut EffectcraftApp, g: &Rw, rc: &RowCtx<'_>, prop: &Property) {
+ let t = g.tl.t;
+ let graph_x0 = g.tl.graph_x0;
+ let lp = g.lp.clone();
+ let gp = g.gp.clone();
+ let layer = rc.layer;
+ let r = rc.r;
+ let left = rc.left;
+ let ri = rc.ri;
+ let uid = &prop.uid;
+
+ app.auto.add(&format!("timeline.prop.{uid}.row"), r, &prop.name);
+ let sel_prop = app.session.state.selected_props.contains(&(layer.id, *uid));
+ lp.rect_filled(
+ left,
+ 0.0,
+ if sel_prop {
+ t.row_selected
+ } else if ri.is_multiple_of(2) {
+ t.row
+ } else {
+ t.row_alt
+ },
+ );
+ gp.rect_filled(Rect::from_min_max(pos2(graph_x0, r.min.y), r.max), 0.0, t.tl_bg);
+ }
+
+ /// The keyframe navigator (previous, toggle, next).
+ fn prop_key_navigator(app: &mut EffectcraftApp, ui: &mut egui::Ui, g: &mut Rw, rc: &RowCtx<'_>, prop: &Property) {
+ let t = g.tl.t;
+ let time = g.tl.time;
+ let fr = g.tl.fr;
+ let vis = g.tl.vis;
+ let cw = &g.tl.cw;
+ let actions = &mut g.tl.actions;
+ let lp = g.lp.clone();
+ let ui_actions = &mut g.ui_actions;
+ let layer = rc.layer;
+ let cy = rc.cy;
+ let uid = &prop.uid;
+
+ // Keyframe navigator (in the A/V column, like AE).
+ // (in the Keys column when it is shown).
+ if prop.is_animated() && (vis.keys || vis.av) {
+ let lt = layer.layer_time(time);
+ let at_key = effectcraft_engine::keyframe::key_at(&prop.keys, lt).is_some();
+ let nav_x = if vis.keys { cw.keys + 12.0 } else { cw.av + 18.0 };
+ let prev = Rect::from_center_size(pos2(nav_x, cy), vec2(12.0, 14.0));
+ let mid = Rect::from_center_size(pos2(nav_x + 16.0, cy), vec2(14.0, 14.0));
+ let next = Rect::from_center_size(pos2(nav_x + 32.0, cy), vec2(12.0, 14.0));
+ icons::paint(&lp, prev.shrink(2.0), Icon::ChevronLeft, t.text_dim);
+ icons::paint(&lp, next.shrink(2.0), Icon::ChevronRight, t.text_dim);
+ let kc = if at_key { t.keyframe_selected } else { Color32::TRANSPARENT };
+ lp.add(egui::Shape::convex_polygon(
+ vec![mid.center() + vec2(0.0, -5.0), mid.center() + vec2(5.0, 0.0), mid.center() + vec2(0.0, 5.0), mid.center() + vec2(-5.0, 0.0)],
+ kc,
+ Stroke::new(1.0, t.text_dim),
+ ));
+ if ui.interact(prev, egui::Id::unique(("kprev", uid)), Sense::click()).clicked()
+ && let Some(k) = prop.keys.iter().rev().find(|k| layer.comp_time(k.time).0 < time.0 - fr.frame_duration().0 / 2)
+ {
+ ui_actions.push(UiAct::SetTime(layer.comp_time(k.time)));
+ }
+ if ui.interact(next, egui::Id::unique(("knext", uid)), Sense::click()).clicked()
+ && let Some(k) = prop.keys.iter().find(|k| layer.comp_time(k.time).0 > time.0 + fr.frame_duration().0 / 2)
+ {
+ ui_actions.push(UiAct::SetTime(layer.comp_time(k.time)));
+ }
+ if ui.interact(mid, egui::Id::unique(("kmid", uid)), Sense::click()).clicked() {
+ actions.push(("prop.toggleKey".into(), json!({"layer": layer.id.0, "prop": uid})));
+ }
+ app.auto.add(&format!("timeline.prop.{uid}.addKey"), mid, "Add or remove keyframe");
+ }
+ }
+
+ /// The stopwatch.
+ fn prop_stopwatch(app: &mut EffectcraftApp, ui: &mut egui::Ui, g: &mut Rw, rc: &RowCtx<'_>, prop: &Property) {
+ let t = g.tl.t;
+ let ctx = g.tl.ctx.clone();
+ let actions = &mut g.tl.actions;
+ let lp = g.lp.clone();
+ let layer = rc.layer;
+ let r = rc.r;
+ let cy = rc.cy;
+ let indent = rc.indent;
+ let uid = &prop.uid;
+
+ // Stopwatch: Alt+click adds an expression; a press toggles the animation, and
+ // dragging on over other stopwatches gives them the same state (#284).
+ if !prop.static_only {
+ let swr = Rect::from_center_size(pos2(indent, cy), vec2(15.0, 15.0));
+ let resp = ui.interact(swr, egui::Id::unique(("stopwatch", uid)), Sense::click_and_drag());
+ let col = if prop.is_animated() {
+ t.hot_text
+ } else if resp.hovered() {
+ t.text
+ } else {
+ t.text_dim
+ };
+ icons::paint(&lp, swr, Icon::Stopwatch, col);
+ app.auto.add(&format!("timeline.prop.{uid}.stopwatch"), swr, &prop.name);
+ if ui.input(|i| i.modifiers.alt) {
+ if resp.clicked() {
+ actions.push(("prop.setExpression".into(), json!({"layer": layer.id.0, "prop": uid})));
+ if prop.expr.is_none() {
+ // Adding one: its editor opens, comes into view and takes the
+ // keyboard with the new expression selected (#1072).
+ app.ui.timeline.expr_closed.remove(uid);
+ focus_expression(&ctx, *uid, [usize::MAX, 0]);
+ } else if ctx.data(|d| d.get_temp::<ExprFocus>(expr_focus_id())).is_some_and(|f| f.prop == *uid) {
+ // Removing it: nothing is left to take the keyboard.
+ ctx.data_mut(|d| d.remove::<ExprFocus>(expr_focus_id()));
}
- let name_x = indent + 12.0;
- // 3D layers show Rotation as "Z Rotation" next to X/Y Rotation.
- let is_tr_rot = layer.transform().and_then(|t| t.get("rotation")).is_some_and(|r| r.uid == prop.uid);
- let base = if is_tr_rot && prop.name == "Rotation" && layer.is_3d() { "Z Rotation".to_string() } else { prop.name.clone() };
- let pname = if prop.has_expression() { format!("{base} =") } else { base };
- lp.text(pos2(name_x, cy), Align2::LEFT_CENTER, &pname, Tokens::ui(12.0), if prop.has_expression() { t.expr_text } else { t.text });
- let name_rect = Rect::from_min_max(pos2(name_x, r.min.y), pos2(cw.switches - 2.0, r.max.y));
- let name_resp = ui.interact(name_rect, egui::Id::new(("pname", uid)), Sense::click_and_drag());
- app.auto.add(&format!("timeline.prop.{uid}.name"), name_rect, &prop.name);
- if name_resp.drag_started() {
- // Drop on the Essential Graphics panel to expose the property.
- egui::DragAndDrop::set_payload(&ctx, crate::panels::DragPayload::Property { layer: layer.id.0, prop: *uid });
- }
- if name_resp.dragged() {
- egui::Tooltip::always_open(ctx.clone(), ui.layer_id(), egui::Id::new("prop-drag-tip"), egui::PopupAnchor::Pointer)
- .show(|ui| ui.label(&prop.name));
- }
- if name_resp.clicked() {
- actions.push(("prop.select".into(), json!({"layer": layer.id.0, "prop": uid, "add": ui.input(|i| i.modifiers.shift)})));
- }
- crate::widgets::context_menu(&name_resp, |ui| prop_menu(ui, &mut app.auto, cid, layer, prop, &mut actions));
- // Value editors.
- let value = ectx.value(layer, prop);
- let vx = (cw.switches + 4.0).max(name_x + 120.0);
- let dims = value_editor(app, ui, &lp, layer, prop, &value, pos2(vx, cy), &mut actions);
- if !dims.is_empty() {
- dim_hits.push((*uid, dims));
- }
- // The property pick whip (Parent & Link column, AE CC 2018 and later): dropped on
- // a property it links this one to it, adding the expression if there is none.
- if vis.parent && !prop.static_only {
- pick_whip(
- app,
- ui,
- &lp,
- Rect::from_center_size(pos2(cw.parent + 9.0, cy), vec2(15.0, 15.0)),
- (WHIP_PROP, layer.id.0, *uid),
- &format!("timeline.prop.{uid}.propertyPickWhip"),
- "Property pick whip",
- crate::i18n::tr("Property pick whip: drag onto a property"),
- );
- }
- ui.set_clip_rect(right_clip);
- // Expression text row hint.
- if let Some(e) = prop.expr.as_ref().filter(|e| e.enabled && app.ui.timeline.expr_closed.contains(uid)) {
- gp.text(
- pos2(graph_x0 + 8.0, cy),
- Align2::LEFT_CENTER,
- format!("= {}", e.text.lines().next().unwrap_or("")),
- Tokens::mono(11.0),
- t.expr_text,
- );
- }
- // Keyframes.
- if !graph_on {
- for k in &prop.keys {
- let ct = layer.comp_time(k.time);
- let x = tm.x(ct.seconds());
- if x < graph_x0 - 8.0 || x > rect.max.x + 8.0 {
- continue;
- }
- let kref = effectcraft_engine::KeyRef { layer: layer.id, prop: *uid, time: k.time };
- let ks = sel_keys.contains(&kref);
- let icon = k.icon();
- let c = pos2(x, cy);
- // Labelled keys take their label colour (brighter when selected).
- let kcol = match effectcraft_engine::color::Label::ALL.get(k.label as usize).filter(|_| k.label > 0) {
- Some(l) => {
- let c = t.label(*l);
- if ks { c } else { c.gamma_multiply(0.75) }
- }
- None if ks => t.keyframe_selected,
- None => t.keyframe,
- };
- if k.roving {
- // Roving keys: a small dot (their time follows their neighbours).
- gp.circle_filled(c, 2.5, kcol);
- } else {
- icons::keyframe(&gp, c, 11.0, icon.left, icon.right, kcol);
- }
- let kr = Rect::from_center_size(c, vec2(12.0, 14.0));
- let kresp = ui.interact(kr, egui::Id::new(("key", uid, k.time.0)), Sense::click_and_drag());
- app.auto.add(&format!("timeline.key.{uid}.{}", fr.frame_at(ct)), kr, &format!("{} key", prop.name));
- // Exact (layer-time ticks): keys a Quick Offset puts on subframes can share a frame.
- app.auto.add(&format!("timeline.keyAt.{uid}.{}", k.time.0), kr, &format!("{} key", prop.name));
- let mods = ui.input(|i| i.modifiers);
- let this_key = json!({"keys": [{"layer": layer.id.0, "prop": uid, "time": k.time.seconds()}], "selectProperties": true});
- if kresp.clicked() && mods.command {
- // Ctrl+click: Linear ↔ Auto Bezier; Ctrl+Alt+click: Hold on / off.
- actions.push(("keys.select".into(), this_key.clone()));
- if mods.alt {
- actions.push(("keys.toggleHold".into(), json!({})));
- } else {
- let linear = k.in_interp == Interp::Linear && k.out_interp == Interp::Linear;
- actions.push(("keys.interpolation".into(), json!({"interpolation": if linear { "autoBezier" } else { "linear" }})));
- }
- } else if kresp.clicked() && mods.shift {
- // Shift+click: in or out of the selection.
- let mut p = this_key.clone();
- p["toggle"] = json!(true);
- actions.push(("keys.select".into(), p));
- } else if (kresp.clicked() || kresp.drag_started()) && !ks {
- let mut p = this_key.clone();
- p["add"] = json!(mods.shift);
- actions.push(("keys.select".into(), p));
- }
- if kresp.double_clicked() {
- // Edit the key's value (numeric properties), as After Effects does.
- if matches!(k.value, Value::Scalar(_) | Value::Vec2(_) | Value::Vec3(_)) {
- actions.push(("keys.set".into(), json!({"layer": layer.id.0, "prop": uid, "time": k.time.seconds()})));
- } else {
- ui_actions.push(UiAct::SetTime(ct));
- }
- }
- crate::widgets::context_menu(&kresp, |ui| {
- for (lbl, cmd, params) in [
- ("Edit Value…", "keys.set", json!({"layer": layer.id.0, "prop": uid, "time": k.time.seconds()})),
- ("-", "", json!({})),
- ("Copy", "keys.copy", json!({})),
- ("Paste", "keys.paste", json!({})),
- ("-", "", json!({})),
- ("Select Equal Keyframes", "keys.selectEqual", json!({})),
- ("Select Previous Keyframes", "keys.selectPrevious", json!({})),
- ("Select Following Keyframes", "keys.selectFollowing", json!({})),
- ("-", "", json!({})),
- ("Keyframe Interpolation…", "keys.interpolation", json!({})),
- ("Keyframe Velocity…", "keys.velocity", json!({})),
- ("Toggle Hold Keyframe", "keys.toggleHold", json!({})),
- ("Rove Across Time", "keys.interpolation", json!({"roving": !k.roving})),
- ("-", "", json!({})),
- ("Easy Ease", "keys.easyEase", json!({})),
- ("Easy Ease In", "keys.easyEaseIn", json!({})),
- ("Easy Ease Out", "keys.easyEaseOut", json!({})),
- ("Time-Reverse Keyframes", "keys.timeReverse", json!({})),
- ("-", "", json!({})),
- ("Linear", "keys.interpolation", json!({"interpolation": "linear"})),
- ("Bezier", "keys.interpolation", json!({"interpolation": "bezier"})),
- ("Auto Bezier", "keys.interpolation", json!({"interpolation": "autoBezier"})),
- ("Select All Keyframes", "keys.selectAll", json!({})),
- ("Delete", "keys.delete", json!({})),
- ] {
- if lbl == "Select All Keyframes" {
- // Keyframe colour labels.
- ui.menu_button(crate::i18n::tr("Label"), |ui| {
- for (i, l) in effectcraft_engine::color::Label::ALL.into_iter().enumerate() {
- if widgets::label_entry(ui, l, &app.session.prefs.label_name(l), k.label as usize == i, &t).clicked() {
- if !ks {
- actions.push((
- "keys.select".into(),
- json!({"keys": [{"layer": layer.id.0, "prop": uid, "time": k.time.seconds()}]}),
- ));
- }
- actions.push(("keys.setLabel".into(), json!({"label": i})));
- ui.close();
- }
- }
- });
- }
- if lbl == "-" {
- ui.separator();
- continue;
- }
- if lbl == "Rove Across Time" && !prop.spatial {
- continue;
- }
- if lbl == "Edit Value…" && !matches!(k.value, Value::Scalar(_) | Value::Vec2(_) | Value::Vec3(_)) {
- continue;
- }
- if ui.button(lbl).clicked() {
- if !ks {
- actions.push(("keys.select".into(), json!({"keys": [{"layer": layer.id.0, "prop": uid, "time": k.time.seconds()}]})));
- }
- actions.push((cmd.into(), params));
- ui.close();
- }
+ }
+ } else if let Some((value, merge)) = switch_gesture(ui, &resp, r, "stopwatch", prop.is_animated()) {
+ actions.push(("prop.toggleAnimation".into(), json!({"layer": layer.id.0, "prop": uid, "value": value, "merge": merge})));
+ } else if resp.clicked() && !resp.clicked_by(egui::PointerButton::Primary) {
+ // Keyboard or accessibility activation.
+ actions.push(("prop.toggleAnimation".into(), json!({"layer": layer.id.0, "prop": uid})));
+ }
+ }
+ }
+
+ /// The property name; returns its x.
+ fn prop_name(app: &mut EffectcraftApp, ui: &mut egui::Ui, g: &mut Rw, rc: &RowCtx<'_>, prop: &Property) -> f32 {
+ let t = g.tl.t;
+ let cid = g.tl.cid;
+ let ctx = g.tl.ctx.clone();
+ let cw = &g.tl.cw;
+ let actions = &mut g.tl.actions;
+ let lp = g.lp.clone();
+ let layer = rc.layer;
+ let r = rc.r;
+ let cy = rc.cy;
+ let indent = rc.indent;
+ let uid = &prop.uid;
+
+ let name_x = indent + 12.0;
+ // 3D layers show Rotation as "Z Rotation" next to X/Y Rotation.
+ let is_tr_rot = layer.transform().and_then(|t| t.get("rotation")).is_some_and(|r| r.uid == prop.uid);
+ let base = if is_tr_rot && prop.name == "Rotation" && layer.is_3d() { "Z Rotation".to_string() } else { prop.name.clone() };
+ let pname = if prop.has_expression() { format!("{base} =") } else { base };
+ lp.text(pos2(name_x, cy), Align2::LEFT_CENTER, &pname, Tokens::ui(12.0), if prop.has_expression() { t.expr_text } else { t.text });
+ let name_rect = Rect::from_min_max(pos2(name_x, r.min.y), pos2(cw.switches - 2.0, r.max.y));
+ let name_resp = ui.interact(name_rect, egui::Id::unique(("pname", uid)), Sense::click_and_drag());
+ app.auto.add(&format!("timeline.prop.{uid}.name"), name_rect, &prop.name);
+ if name_resp.drag_started() {
+ // Drop on the Essential Graphics panel to expose the property.
+ egui::DragAndDrop::set_payload(&ctx, crate::panels::DragPayload::Property { layer: layer.id.0, prop: *uid });
+ }
+ if name_resp.dragged() {
+ egui::Tooltip::always_open(ctx.clone(), ui.layer_id(), egui::Id::unique("prop-drag-tip"), egui::PopupAnchor::Pointer).show(|ui| ui.label(&prop.name));
+ }
+ if name_resp.clicked() {
+ actions.push(("prop.select".into(), json!({"layer": layer.id.0, "prop": uid, "add": ui.input(|i| i.modifiers.shift)})));
+ }
+ crate::widgets::context_menu(&name_resp, |ui| prop_menu(ui, &mut app.auto, cid, layer, prop, &mut *actions));
+ name_x
+ }
+
+ /// The value editors and the property pick whip.
+ fn prop_value_cell(app: &mut EffectcraftApp, ui: &mut egui::Ui, g: &mut Rw, rc: &RowCtx<'_>, ectx: &EvalCtx<'_>, prop: &Property, name_x: f32) {
+ let vis = g.tl.vis;
+ let cw = &g.tl.cw;
+ let actions = &mut g.tl.actions;
+ let lp = g.lp.clone();
+ let dim_hits = &mut g.dim_hits;
+ let layer = rc.layer;
+ let cy = rc.cy;
+ let uid = &prop.uid;
+
+ let value = ectx.value(layer, prop);
+ let vx = (cw.switches + 4.0).max(name_x + 120.0);
+ let ve = ValueEdit::new(ui, &lp, layer, prop, pos2(vx, cy));
+ let dims = value_editor(app, ui, &ve, &value, &mut *actions);
+ if !dims.is_empty() {
+ dim_hits.push((*uid, dims));
+ }
+ // The property pick whip (Parent & Link column, AE CC 2018 and later): dropped on
+ // a property it links this one to it, adding the expression if there is none.
+ if vis.parent && !prop.static_only {
+ pick_whip(
+ app,
+ ui,
+ &lp,
+ Rect::from_center_size(pos2(cw.parent + 9.0, cy), vec2(15.0, 15.0)),
+ (WHIP_PROP, layer.id.0, *uid),
+ WhipText {
+ auto: &format!("timeline.prop.{uid}.propertyPickWhip"),
+ label: "Property pick whip",
+ hint: crate::i18n::tr("Property pick whip: drag onto a property"),
+ },
+ );
+ }
+ }
+
+ /// The one-line expression hint when its editor is closed.
+ fn prop_expression_hint(app: &mut EffectcraftApp, ui: &mut egui::Ui, g: &Rw, rc: &RowCtx<'_>, prop: &Property) {
+ let t = g.tl.t;
+ let graph_x0 = g.tl.graph_x0;
+ let right_clip = g.right_clip;
+ let gp = g.gp.clone();
+ let cy = rc.cy;
+ let uid = &prop.uid;
+
+ ui.set_clip_rect(right_clip);
+ // Expression text row hint.
+ if let Some(e) = prop.expr.as_ref().filter(|e| e.enabled && app.ui.timeline.expr_closed.contains(uid)) {
+ gp.text(pos2(graph_x0 + 8.0, cy), Align2::LEFT_CENTER, format!("= {}", e.text.lines().next().unwrap_or("")), Tokens::mono(11.0), t.expr_text);
+ }
+ }
+
+ /// Key click selection and interpolation shortcuts.
+ fn key_select(g: &mut Rw, kh: &KeyHit<'_>) {
+ let KeyHit { k, ks, mods, ref kresp, ref this_key, .. } = *kh;
+ let actions = &mut g.tl.actions;
+ if kresp.clicked() && mods.command {
+ // Ctrl+click: Linear ↔ Auto Bezier; Ctrl+Alt+click: Hold on / off.
+ actions.push(("keys.select".into(), this_key.clone()));
+ if mods.alt {
+ actions.push(("keys.toggleHold".into(), json!({})));
+ } else {
+ let linear = k.in_interp == Interp::Linear && k.out_interp == Interp::Linear;
+ actions.push(("keys.interpolation".into(), json!({"interpolation": if linear { "autoBezier" } else { "linear" }})));
+ }
+ } else if kresp.clicked() && mods.shift {
+ // Shift+click: in or out of the selection.
+ let mut p = this_key.clone();
+ p["toggle"] = json!(true);
+ actions.push(("keys.select".into(), p));
+ } else if (kresp.clicked() || kresp.drag_started()) && !ks {
+ let mut p = this_key.clone();
+ p["add"] = json!(mods.shift);
+ actions.push(("keys.select".into(), p));
+ }
+ }
+
+ fn key_double_click(g: &mut Rw, rc: &RowCtx<'_>, prop: &Property, kh: &KeyHit<'_>) {
+ let KeyHit { k, ct, ref kresp, .. } = *kh;
+ let actions = &mut g.tl.actions;
+ let ui_actions = &mut g.ui_actions;
+ let layer = rc.layer;
+ let uid = &prop.uid;
+
+ if kresp.double_clicked() {
+ // Edit the key's value (numeric properties), as After Effects does.
+ if matches!(k.value, Value::Scalar(_) | Value::Vec2(_) | Value::Vec3(_)) {
+ actions.push(("keys.set".into(), json!({"layer": layer.id.0, "prop": uid, "time": k.time.seconds()})));
+ } else {
+ ui_actions.push(UiAct::SetTime(ct));
+ }
+ }
+ }
+
+ /// The keyframe right-click menu.
+ fn key_context_menu(app: &mut EffectcraftApp, g: &mut Rw, rc: &RowCtx<'_>, prop: &Property, kh: &KeyHit<'_>) {
+ let KeyHit { k, ks, ref kresp, .. } = *kh;
+ let t = g.tl.t;
+ let actions = &mut g.tl.actions;
+ let layer = rc.layer;
+ let uid = &prop.uid;
+
+ crate::widgets::context_menu(kresp, |ui| {
+ for (lbl, cmd, params) in [
+ ("Edit Value…", "keys.set", json!({"layer": layer.id.0, "prop": uid, "time": k.time.seconds()})),
+ ("-", "", json!({})),
+ ("Copy", "keys.copy", json!({})),
+ ("Paste", "keys.paste", json!({})),
+ ("-", "", json!({})),
+ ("Select Equal Keyframes", "keys.selectEqual", json!({})),
+ ("Select Previous Keyframes", "keys.selectPrevious", json!({})),
+ ("Select Following Keyframes", "keys.selectFollowing", json!({})),
+ ("-", "", json!({})),
+ ("Keyframe Interpolation…", "keys.interpolation", json!({})),
+ ("Keyframe Velocity…", "keys.velocity", json!({})),
+ ("Toggle Hold Keyframe", "keys.toggleHold", json!({})),
+ ("Rove Across Time", "keys.interpolation", json!({"roving": !k.roving})),
+ ("-", "", json!({})),
+ ("Easy Ease", "keys.easyEase", json!({})),
+ ("Easy Ease In", "keys.easyEaseIn", json!({})),
+ ("Easy Ease Out", "keys.easyEaseOut", json!({})),
+ ("Time-Reverse Keyframes", "keys.timeReverse", json!({})),
+ ("-", "", json!({})),
+ ("Linear", "keys.interpolation", json!({"interpolation": "linear"})),
+ ("Bezier", "keys.interpolation", json!({"interpolation": "bezier"})),
+ ("Auto Bezier", "keys.interpolation", json!({"interpolation": "autoBezier"})),
+ ("Select All Keyframes", "keys.selectAll", json!({})),
+ ("Delete", "keys.delete", json!({})),
+ ] {
+ if lbl == "Select All Keyframes" {
+ // Keyframe colour labels.
+ ui.menu_button(crate::i18n::tr("Label"), |ui| {
+ for (i, l) in effectcraft_engine::color::Label::ALL.into_iter().enumerate() {
+ if widgets::label_entry(ui, l, &app.session.prefs.label_name(l), k.label as usize == i, &t).clicked() {
+ if !ks {
+ actions.push(("keys.select".into(), json!({"keys": [{"layer": layer.id.0, "prop": uid, "time": k.time.seconds()}]})));
}
- });
- // Alt-drag the first or last key of a selected group: scale the group in time.
- if kresp.drag_started()
- && mods.alt
- && !mods.command
- && let Some(c) = app.session.active_comp_arc()
- {
- super::graph_tools::alt_scale_begin(app, &ctx, &c, ct.seconds());
- }
- // A plain drag moves the selected keys. The timeline follows it (below): this
- // widget's id changes with the key's time, so its own drag would end after
- // the first frame of movement.
- // (From where the button went down: a drag starts a few pixels later.)
- if kresp.drag_started()
- && !super::graph_tools::alt_scale_active(&ctx)
- && let Some(p) = ctx.input(|i| i.pointer.press_origin())
- {
- // Ctrl/Cmd+Alt: Quick Offset of the selected keys' layers (#1012).
- let quick = (mods.command && mods.alt && ks).then(|| quick_offset_layers(&comp, sel_keys.iter().map(|k| k.layer))).flatten();
- ctx.data_mut(|d| d.insert_temp(key_drag_id(), KeyDrag { origin_x: p.x, anchor: ct.seconds(), applied: 0, quick }));
+ actions.push(("keys.setLabel".into(), json!({"label": i})));
+ ui.close();
}
}
+ });
+ }
+ if lbl == "-" {
+ ui.separator();
+ continue;
+ }
+ if lbl == "Rove Across Time" && !prop.spatial {
+ continue;
+ }
+ if lbl == "Edit Value…" && !matches!(k.value, Value::Scalar(_) | Value::Vec2(_) | Value::Vec3(_)) {
+ continue;
+ }
+ if ui.button(lbl).clicked() {
+ if !ks {
+ actions.push(("keys.select".into(), json!({"keys": [{"layer": layer.id.0, "prop": uid, "time": k.time.seconds()}]})));
}
+ actions.push((cmd.into(), params));
+ ui.close();
}
}
+ });
+ }
+
+ /// Starts a key drag (or Alt-scale).
+ fn key_drag_begin(app: &mut EffectcraftApp, g: &Rw, kh: &KeyHit<'_>) {
+ let KeyHit { ct, ks, mods, ref kresp, .. } = *kh;
+ let ctx = g.tl.ctx.clone();
+ let comp = g.tl.comp.clone();
+ let sel_keys = &g.sel_keys;
+ // Alt-drag the first or last key of a selected group: scale the group in time.
+ if kresp.drag_started()
+ && mods.alt
+ && !mods.command
+ && let Some(c) = app.session.active_comp_arc()
+ {
+ super::graph_tools::alt_scale_begin(app, &ctx, &c, ct.seconds());
+ }
+ // A plain drag moves the selected keys. The timeline follows it (below): this
+ // widget's id changes with the key's time, so its own drag would end after
+ // the first frame of movement.
+ // (From where the button went down: a drag starts a few pixels later.)
+ if kresp.drag_started()
+ && !super::graph_tools::alt_scale_active(&ctx)
+ && let Some(p) = ctx.input(|i| i.pointer.press_origin())
+ {
+ // Ctrl/Cmd+Alt: Quick Offset of the selected keys' layers (#1012).
+ let quick = (mods.command && mods.alt && ks).then(|| quick_offset_layers(&comp, sel_keys.iter().map(|k| k.layer))).flatten();
+ ctx.data_mut(|d| d.insert_temp(key_drag_id(), KeyDrag { origin_x: p.x, anchor: ct.seconds(), applied: 0, quick }));
+ }
+ }
+
+ /// Paints one keyframe marker; returns its hit rect.
+ fn key_paint(g: &Rw, rc: &RowCtx<'_>, k: &effectcraft_engine::keyframe::Keyframe, x: f32, ks: bool) -> Rect {
+ let t = g.tl.t;
+ let gp = g.gp.clone();
+ let cy = rc.cy;
+ let icon = k.icon();
+ let c = pos2(x, cy);
+ // Labelled keys take their label colour (brighter when selected).
+ let kcol = match effectcraft_engine::color::Label::ALL.get(k.label as usize).filter(|_| k.label > 0) {
+ Some(l) => {
+ let c = t.label(*l);
+ if ks { c } else { c.gamma_multiply(0.75) }
+ }
+ None if ks => t.keyframe_selected,
+ None => t.keyframe,
+ };
+ if k.roving {
+ // Roving keys: a small dot (their time follows their neighbours).
+ gp.circle_filled(c, 2.5, kcol);
+ } else {
+ icons::keyframe(&gp, c, 11.0, icon.left, icon.right, kcol);
}
+ Rect::from_center_size(c, vec2(12.0, 14.0))
+ }
+
+ /// The key's hit target and automation ids.
+ fn key_hit(
+ app: &mut EffectcraftApp,
+ ui: &mut egui::Ui,
+ g: &Rw,
+ rc: &RowCtx<'_>,
+ prop: &Property,
+ k: &effectcraft_engine::keyframe::Keyframe,
+ kr: Rect,
+ ) -> egui::Response {
+ let fr = g.tl.fr;
+ let layer = rc.layer;
+ let uid = &prop.uid;
+ let ct = layer.comp_time(k.time);
+ let kresp = ui.interact(kr, egui::Id::unique(("key", uid, k.time.0)), Sense::click_and_drag());
+ app.auto.add(&format!("timeline.key.{uid}.{}", fr.frame_at(ct)), kr, &format!("{} key", prop.name));
+ // Exact (layer-time ticks): keys a Quick Offset puts on subframes can share a frame.
+ app.auto.add(&format!("timeline.keyAt.{uid}.{}", k.time.0), kr, &format!("{} key", prop.name));
+ kresp
+ }
+
+ /// Right-click menus on the empty outline and graph areas.
+ fn background_menus(app: &mut EffectcraftApp, ui: &mut egui::Ui, g: &mut Rw) {
+ let actions = &mut g.tl.actions;
+ let graph_on = g.graph_on;
+ let full_clip = g.full_clip;
+ let empty_rect = g.empty_rect;
+ let empty = g.empty.clone();
+ let outline_empty = g.outline_empty.clone();
ui.set_clip_rect(full_clip);
// The background responses sit below rows, bars and editors, preserving their menus.
if !graph_on {
@@@ -4158,389 -5545,112 +5545,112 @@@ fn vector_editor(app: &mut EffectcraftA
dims
}
- #[cfg(test)]
- mod tests {
- use super::*;
-
- /// Alt/Cmd-click twirls Audio's Waveform row (not in the property tree) with the rest.
- #[test]
- fn the_waveform_row_twirls_with_its_tree() {
- let mut root = PropGroup::new(1, "", "");
- let mut audio = PropGroup::new(2, "audio", "Audio");
- audio.children.push(PropGroup::new(3, "x", "X").into());
- root.children.push(audio.into());
- let mut uids = vec![];
- walk_groups(&root, &mut uids);
- assert_eq!(uids, vec![2, WAVE_BIT | 2, 3]);
- let mut uids = vec![];
- walk_groups(find_group(&root, 2).unwrap(), &mut uids);
- assert_eq!(uids, vec![WAVE_BIT | 2, 3]);
- }
-
- /// #710: with Time Display set to Frames the ruler labels are frame numbers (as under the
- /// CTI, from Start Numbering Frames At); otherwise seconds:frames.
- #[test]
- fn ruler_labels_follow_the_time_display_style() {
- use effectcraft_engine::project::{ProjectSettings, TimeDisplayStyle};
- let mut st = ProjectSettings { time_display: TimeDisplayStyle::Timecode, frame_start: 0, ..ProjectSettings::default() };
- assert_eq!(ruler_label(15, 30, &st), "00:15f");
- assert_eq!(ruler_label(45, 30, &st), "01:15f");
- assert_eq!(ruler_label(30 * 3600 + 31, 30, &st), "60:01:01f");
- st.time_display = TimeDisplayStyle::Frames;
- assert_eq!(ruler_label(0, 30, &st), "00000");
- assert_eq!(ruler_label(45, 30, &st), "00045");
- st.frame_start = 1;
- assert_eq!(ruler_label(45, 30, &st), "00046");
- assert_eq!(ruler_label(i64::MAX, 30, &st), format!("{:05}", i64::MAX));
- }
-
- /// #468: playback pages the view to the CTI; a scrub past either end scrolls that way.
- #[test]
- fn the_view_pages_to_the_cti() {
- assert_eq!(page_to_cti(10.0, 5.0, 60.0, 12.0), 10.0, "in view: unchanged");
- assert_eq!(page_to_cti(10.0, 5.0, 60.0, 16.0), 16.0, "past the right end: the page from the CTI");
- assert_eq!(page_to_cti(10.0, 5.0, 60.0, 3.0), 3.0, "before the start");
- assert_eq!(page_to_cti(10.0, 5.0, 60.0, 58.0), 55.0, "not past the comp's end");
- assert_eq!(page_to_cti(10.0, 80.0, 60.0, 95.0), 0.0);
- assert_eq!(page_to_cti(10.0, f64::NAN, 60.0, 95.0), 10.0);
- assert_eq!(edge_scroll_speed_x(100.0, 500.0, 300.0), 0.0);
- assert!(edge_scroll_speed_x(100.0, 500.0, 501.0) > 0.0 && edge_scroll_speed_x(100.0, 500.0, 99.0) < 0.0);
- assert!(edge_scroll_speed_x(100.0, 500.0, 600.0) > edge_scroll_speed_x(100.0, 500.0, 520.0));
- }
-
- /// #864: picking only a mode in a layer's Track Matte menu sets a matte (the layer above);
- /// it used to close the menu and change nothing.
- #[test]
- fn a_track_matte_mode_without_a_matte_takes_the_layer_above() {
- let mut s = effectcraft_engine::Session::default();
- s.execute("comp.new", json!({"name": "T", "width": 64, "height": 64, "duration": 1})).unwrap();
- for name in ["Chain Bottom", "Matte", "Chain Top"] {
- s.execute("layer.newSolid", json!({"name": name, "color": "#ffffff", "width": 64, "height": 64})).unwrap();
- }
- let find = |s: &effectcraft_engine::Session, n: &str| s.active_comp().unwrap().layers.iter().find(|l| l.name == n).unwrap().clone();
- let (bottom, matte, top) = (find(&s, "Chain Bottom"), find(&s, "Matte"), find(&s, "Chain Top"));
- let candidates = [top.id, matte.id];
- let pick = |s: &mut effectcraft_engine::Session, name: &str, i: usize, choice: &str| {
- let (id, params) = track_matte_pick(&find(s, name), &candidates, i, choice).expect("a menu item is an action");
- s.execute(&id, params)
- };
- pick(&mut s, "Chain Bottom", 5, "Alpha Inverted Matte").unwrap();
- let m = find(&s, "Chain Bottom").track_matte.expect("a matte");
- assert_eq!((m.layer, m.kind), (matte.id, MatteKind::AlphaInverted));
- assert!(!find(&s, "Matte").switches.video, "the matte layer is hidden");
- // A mode change keeps the matte layer; a matte change keeps the mode.
- pick(&mut s, "Chain Bottom", 6, "Luma Matte").unwrap();
- assert_eq!(find(&s, "Chain Bottom").track_matte.map(|m| (m.layer, m.kind)), Some((matte.id, MatteKind::Luma)));
- pick(&mut s, "Chain Bottom", 2, "1. Chain Top").unwrap();
- assert_eq!(find(&s, "Chain Bottom").track_matte.map(|m| (m.layer, m.kind)), Some((top.id, MatteKind::Luma)));
- assert!(s.undo());
- assert_eq!(find(&s, "Chain Bottom").track_matte.map(|m| m.layer), Some(matte.id), "one undo step per pick");
- // The top layer has nothing above it: an error for the status bar, not a silent no-op.
- assert!(pick(&mut s, "Chain Top", 5, "Alpha Matte").is_err());
- pick(&mut s, "Chain Bottom", 0, "No Track Matte").unwrap();
- assert!(find(&s, "Chain Bottom").track_matte.is_none());
- assert!(track_matte_pick(&bottom, &candidates, 1, "-").is_none(), "a separator does nothing");
- }
-
- /// #957: vector footage gets the Continuously Rasterize switch; raster footage does not.
- #[test]
- fn collapse_switch_shows_for_vector_footage_only() {
- use effectcraft_engine::color::Label;
- use effectcraft_engine::project::{Footage, ItemKind, Project};
- let mut p = Project::default();
- let mut layer_for = |name: &str, codec: &str| {
- let footage = Footage { path: name.into(), codec: codec.into(), ..Default::default() };
- let item = p.add_item(name, Label::SeaFoam, None, ItemKind::Footage(footage));
- let comp = Comp::new(64, 36, effectcraft_engine::time::FrameRate::new(30, 1), Tick::from_seconds_f64(1.0));
- effectcraft_engine::project::build::layer(&mut p, &comp, name, LayerSource::Footage { item }, (0, 0), None)
- };
- let svg = layer_for("logo.svg", "SVG");
- let png = layer_for("photo.png", "PNG");
- assert!(collapse_applies(&svg, &p));
- assert!(!collapse_applies(&png, &p));
- }
-
- /// A comp with two solids; "Box" has an animated Position and a Gaussian Blur.
- fn app() -> EffectcraftApp {
- let mut s = effectcraft_engine::Session::default();
- s.execute("comp.new", json!({"name": "T", "width": 320, "height": 180, "duration": 4})).unwrap();
- s.execute("layer.newSolid", json!({"name": "Plate", "color": "#406080", "width": 320, "height": 180})).unwrap();
- s.execute("layer.newSolid", json!({"name": "Box", "color": "#e04020", "width": 40, "height": 40})).unwrap();
- let comp = s.active_comp().unwrap();
- let bx = comp.layers.iter().find(|l| l.name == "Box").unwrap().id.0;
- s.execute("layer.select", json!({"layers": [bx]})).unwrap();
- s.execute("effect.apply", json!({"effect": "ec.blur.gaussian"})).unwrap();
- let pos = s.active_comp().unwrap().layer(LayerId(bx)).unwrap().transform().unwrap().get("position").unwrap().uid;
- s.execute("prop.toggleAnimation", json!({"layer": bx, "prop": pos})).unwrap();
- EffectcraftApp::new(s)
- }
-
- fn labels(app: &EffectcraftApp) -> Vec<String> {
- let comp = app.session.active_comp().unwrap().clone();
- build_rows(app, &comp)
- .into_iter()
- .map(|r| {
- let l = comp.layer(r.layer).unwrap();
- match r.kind {
- RowKind::Layer => l.name.clone(),
- RowKind::Group { name, .. } => format!("{}>{name}", " ".repeat(r.depth)),
- RowKind::Prop { uid } => format!("{}{}", " ".repeat(r.depth), l.props.find(uid).unwrap().name),
- _ => "?".into(),
- }
- })
- .collect()
- }
-
- #[test]
- fn search_filters_layers_and_reveals_matching_properties() {
- let mut app = app();
- app.ui.timeline.search = "opac".into();
- let rows = labels(&app);
- // Both layers have Transform > Opacity; nothing else shows.
- assert_eq!(rows.iter().filter(|r| r.trim() == "Opacity").count(), 2, "{rows:?}");
- assert!(rows.iter().any(|r| r.trim() == ">Transform"), "{rows:?}");
- assert!(!rows.iter().any(|r| r.trim() == "Position"), "{rows:?}");
- // A layer name match shows the layer alone; a group match brings its contents.
- app.ui.timeline.search = "plate".into();
- assert_eq!(labels(&app), vec!["Plate".to_string()]);
- app.ui.timeline.search = "GAUSSIAN".into();
- let rows = labels(&app);
- assert_eq!(rows[0], "Box");
- assert!(rows.iter().any(|r| r.trim() == ">Effects") && rows.iter().any(|r| r.trim() == "Blurriness"), "{rows:?}");
- assert!(!rows.contains(&"Plate".to_string()));
- // Nothing matches → no rows.
- app.ui.timeline.search = "zzz".into();
- assert!(labels(&app).is_empty());
- // Through the command.
- let ctx = egui::Context::default();
- crate::menus::invoke(&mut app, &ctx, "timeline.search", json!({"query": "scale"})).unwrap();
- assert!(labels(&app).iter().any(|r| r.trim() == "Scale"));
- }
-
- #[test]
- fn columns_toggle_and_layout() {
- let mut app = app();
- let tl = &mut app.ui.timeline;
- assert!(column_visible(tl, "switches") && !column_visible(tl, "comment") && !column_visible(tl, "modes"));
- set_column(tl, "comment", true).unwrap();
- set_column(tl, "stretch", true).unwrap();
- set_column(tl, "keys", false).unwrap();
- set_column(tl, "label", false).unwrap();
- set_column(tl, "modes", true).unwrap();
- assert!(tl.show_modes && column_visible(tl, "comment") && !column_visible(tl, "label"));
- assert!(set_column(tl, "name", false).is_err());
- assert!(set_column(tl, "bogus", true).is_err());
- let vis = Vis::of(tl);
- let cw = cols(0.0, 1400.0, vis);
- // Hidden columns take no room; visible ones are in After Effects' order.
- assert_eq!(cw.keys, cw.label);
- assert_eq!(cw.label, cw.num);
- assert!(cw.name < cw.comment && cw.comment < cw.switches && cw.switches < cw.mode && cw.parent < cw.stretch);
- assert_eq!(column_at(&cw, cw.comment + 5.0), Some("comment"));
- assert_eq!(column_at(&cw, cw.name + 5.0), Some("name"));
- assert_eq!(column_at(&cw, cw.stretch + 5.0), Some("stretch"));
- // Through the command (as agents do).
- let ctx = egui::Context::default();
- let r = crate::menus::invoke(&mut app, &ctx, "timeline.column", json!({"column": "duration"})).unwrap();
- assert!(r["columns"].as_array().unwrap().iter().any(|c| c == "duration"));
- crate::menus::invoke(&mut app, &ctx, "timeline.column", json!({"column": "duration", "visible": false})).unwrap();
- assert!(!column_visible(&app.ui.timeline, "duration"));
- crate::menus::invoke(&mut app, &ctx, "timeline.sourceName", json!({})).unwrap();
- assert!(app.ui.timeline.source_name);
- }
-
- #[test]
- fn reveal_keys_add_with_shift_and_uu_reveals_modified() {
- let mut app = app();
- let ctx = egui::Context::default();
- crate::menus::invoke(&mut app, &ctx, "timeline.reveal.opacity", json!({})).unwrap();
- assert_eq!(app.ui.timeline.reveal, vec!["opacity"]);
- crate::menus::invoke(&mut app, &ctx, "timeline.revealAdd.scale", json!({})).unwrap();
- crate::menus::invoke(&mut app, &ctx, "timeline.revealAdd.effects", json!({})).unwrap();
- assert_eq!(app.ui.timeline.reveal, vec!["opacity", "scale", "effects"]);
- let rows = labels(&app);
- assert!(rows.iter().any(|r| r.trim() == "Scale") && rows.iter().any(|r| r.trim() == "Opacity"), "{rows:?}");
- assert!(rows.iter().any(|r| r.trim() == ">Gaussian Blur"), "{rows:?}");
- // Tree order: Scale before Opacity.
- let si = rows.iter().position(|r| r.trim() == "Scale").unwrap();
- let oi = rows.iter().position(|r| r.trim() == "Opacity").unwrap();
- assert!(si < oi);
- // Shift+S again removes Scale.
- crate::menus::invoke(&mut app, &ctx, "timeline.revealAdd.scale", json!({})).unwrap();
- assert_eq!(app.ui.timeline.reveal, vec!["opacity", "effects"]);
- // U: keyframed properties (Position); UU (twice quickly): every modified property.
- crate::menus::invoke(&mut app, &ctx, "anim.reveal", json!({"kind": "keyframes"})).unwrap();
- let n_keys = app.ui.timeline.reveal_props.len();
- assert_eq!(app.ui.timeline.reveal, vec!["props"]);
- assert!(n_keys >= 1);
- let bx = app.session.state.selected_layers[0].0;
- app.session.execute("prop.set", json!({"layer": bx, "path": "effects/#1/blurriness", "value": 12})).unwrap();
- crate::menus::invoke(&mut app, &ctx, "anim.reveal", json!({"kind": "keyframes"})).unwrap();
- assert!(app.ui.timeline.reveal_props.len() > n_keys, "UU reveals modified properties too");
- }
-
- #[test]
- fn scroll_to_time_centres_the_current_time_inside_the_comp() {
- assert_eq!(centered_on(4.0, 10.0, 5.0), 3.0);
- // Near the ends the view stops at the comp's start and end.
- assert_eq!(centered_on(4.0, 10.0, 1.0), 0.0);
- assert_eq!(centered_on(4.0, 10.0, 9.5), 6.0);
- // A span longer than the comp, and bad numbers, start at zero.
- assert_eq!(centered_on(20.0, 10.0, 5.0), 0.0);
- assert_eq!(centered_on(f64::NAN, 10.0, 5.0), 0.0);
- }
-
- /// U and the other reveal shortcuts act on the selected layers only: other layers keep their
- /// twirl state and their own reveal (#160).
- #[test]
- fn reveal_shortcuts_leave_unselected_layers_alone() {
- let mut app = app();
- let ctx = egui::Context::default();
- let comp = app.session.active_comp().unwrap().clone();
- let id = |n: &str| comp.layers.iter().find(|l| l.name == n).unwrap().id.0;
- let (plate, bx) = (id("Plate"), id("Box"));
- let select = |app: &mut EffectcraftApp, l: u64| app.session.execute("layer.select", json!({"layers": [l]})).unwrap();
- // Plate shows Scale (S); then U on Box.
- select(&mut app, plate);
- crate::menus::invoke(&mut app, &ctx, "timeline.reveal.scale", json!({})).unwrap();
- select(&mut app, bx);
- crate::menus::invoke(&mut app, &ctx, "anim.reveal", json!({"kind": "keyframes"})).unwrap();
- let tl = &app.ui.timeline;
- assert!(tl.open_layers.contains(&plate) && tl.open_layers.contains(&bx), "{:?}", tl.open_layers);
- assert_eq!(tl.layer_reveal.get(&plate), Some(&vec!["scale".to_string()]), "Plate keeps its reveal");
- assert_eq!(tl.layer_reveal.get(&bx), Some(&vec!["props".to_string()]));
- let rows = labels(&app);
- let at = |n: &str| rows.iter().position(|r| r == n).unwrap();
- assert_eq!(rows[at("Plate") + 1].trim(), "Scale", "{rows:?}");
- assert_eq!(rows[at("Box") + 1].trim(), "Position", "{rows:?}");
- // UU (modified): the effect's changed parameter only, under the effect twirled open.
- // Then U later: Box shows its keyframed properties only again.
- app.session.execute("prop.set", json!({"layer": bx, "path": "effects/#1/blurriness", "value": 12})).unwrap();
- crate::menus::invoke(&mut app, &ctx, "anim.reveal", json!({"kind": "keyframes"})).unwrap();
- let rows = labels(&app);
- let fx = rows.iter().position(|r| r.trim().ends_with("Gaussian Blur")).unwrap_or_else(|| panic!("UU shows the effect: {rows:?}"));
- assert_eq!(rows[fx + 1].trim(), "Blurriness", "{rows:?}");
- assert!(!rows.iter().any(|r| r.trim() == "Blur Dimensions"), "unchanged parameters stay hidden: {rows:?}");
- // Collapsed and expanded by hand, the effect shows all its parameters; UU filters again.
- let fx_uid = app.session.active_comp().unwrap().layer(LayerId(bx)).unwrap().effects().unwrap().groups().next().unwrap().uid;
- app.ui.timeline.toggle_group(bx, fx_uid);
- assert!(!labels(&app).iter().any(|r| r.trim() == "Blurriness"), "collapsed");
- app.ui.timeline.toggle_group(bx, fx_uid);
- let rows = labels(&app);
- assert!(rows.iter().any(|r| r.trim() == "Blurriness") && rows.iter().any(|r| r.trim() == "Blur Dimensions"), "{rows:?}");
- app.last_reveal = Some(("keyframes".into(), f64::MAX));
- crate::menus::invoke(&mut app, &ctx, "anim.reveal", json!({"kind": "keyframes"})).unwrap();
- assert!(!labels(&app).iter().any(|r| r.trim() == "Blur Dimensions"), "UU again shows the changed ones only");
- app.last_reveal = Some(("keyframes".into(), -10.0));
- crate::menus::invoke(&mut app, &ctx, "anim.reveal", json!({"kind": "keyframes"})).unwrap();
- app.last_reveal = Some(("keyframes".into(), -10.0));
- crate::menus::invoke(&mut app, &ctx, "anim.reveal", json!({"kind": "keyframes"})).unwrap();
- let rows = labels(&app);
- assert!(!rows.iter().any(|r| r.trim() == ">Gaussian Blur") && rows.iter().any(|r| r.trim() == "Position"), "{rows:?}");
- // U again on Box (later than a double press) hides only Box's.
- app.last_reveal = Some(("keyframes".into(), -10.0));
- crate::menus::invoke(&mut app, &ctx, "anim.reveal", json!({"kind": "keyframes"})).unwrap();
- let tl = &app.ui.timeline;
- assert!(!tl.open_layers.contains(&bx) && tl.open_layers.contains(&plate), "{:?}", tl.open_layers);
- // A layer twirled open by hand shows its whole tree, whatever was revealed elsewhere.
- app.session.execute("layer.select", json!({"layers": []})).unwrap();
- app.ui.timeline.open_layers.insert(bx);
- let rows = labels(&app);
- assert!(rows.iter().any(|r| r.trim() == ">Transform"), "{rows:?}");
- }
-
- /// U and UU show Time Remap on a layer with time remapping enabled.
- #[test]
- fn u_and_uu_reveal_time_remap() {
- let mut s = effectcraft_engine::Session::default();
- let inner = s.execute("comp.new", json!({"name": "Inner", "width": 32, "height": 32, "duration": 2})).unwrap()["comp"].as_u64().unwrap();
- s.execute("comp.new", json!({"name": "Main", "width": 64, "height": 64, "duration": 4})).unwrap();
- let nested = s.execute("layer.addItem", json!({"item": inner})).unwrap()["layer"].as_u64().unwrap();
- let mut app = EffectcraftApp::new(s);
- let ctx = egui::Context::default();
- crate::menus::invoke(&mut app, &ctx, "layer.enableTimeRemap", json!({"layers": [nested]})).unwrap();
- app.session.execute("layer.select", json!({"layers": [nested]})).unwrap();
- for uu in [false, true] {
- app.ui.timeline.layer_reveal.clear();
- app.last_reveal = uu.then(|| ("keyframes".into(), f64::MAX));
- crate::menus::invoke(&mut app, &ctx, "anim.reveal", json!({"kind": "keyframes"})).unwrap();
- assert_eq!(app.ui.timeline.layer_reveal.get(&nested), Some(&vec!["props".to_string()]), "UU: {uu}");
- let rows = labels(&app);
- let at = rows.iter().position(|r| r == "Inner").unwrap();
- assert_eq!(rows[at + 1].trim(), "Time Remap", "UU: {uu}: {rows:?}");
- }
- }
-
- /// U shows Time Remap while remapping is enabled even after its keys are deleted (#990):
- /// enabling remapping is itself the modification.
- #[test]
- fn u_reveals_keyless_time_remap() {
- let mut s = effectcraft_engine::Session::default();
- let inner = s.execute("comp.new", json!({"name": "Inner", "width": 32, "height": 32, "duration": 2})).unwrap()["comp"].as_u64().unwrap();
- s.execute("comp.new", json!({"name": "Main", "width": 64, "height": 64, "duration": 4})).unwrap();
- let nested = s.execute("layer.addItem", json!({"item": inner})).unwrap()["layer"].as_u64().unwrap();
- let mut app = EffectcraftApp::new(s);
- let ctx = egui::Context::default();
- crate::menus::invoke(&mut app, &ctx, "layer.enableTimeRemap", json!({"layers": [nested]})).unwrap();
- let uid = app.session.active_comp().unwrap().layer(LayerId(nested)).unwrap().props.prop("timeRemap").unwrap().uid;
- for _ in 0..2 {
- let t = app.session.active_comp().unwrap().layer(LayerId(nested)).unwrap().props.prop("timeRemap").unwrap().keys[0].time.seconds();
- app.session.execute("keys.select", json!({"keys": [{"layer": nested, "prop": uid, "time": t}]})).unwrap();
- app.session.execute("edit.clear", json!({})).unwrap();
- }
- assert!(app.session.active_comp().unwrap().layer(LayerId(nested)).unwrap().props.prop("timeRemap").unwrap().keys.is_empty());
- app.session.execute("layer.select", json!({"layers": [nested]})).unwrap();
- crate::menus::invoke(&mut app, &ctx, "anim.reveal", json!({"kind": "keyframes"})).unwrap();
- assert_eq!(app.ui.timeline.layer_reveal.get(&nested), Some(&vec!["props".to_string()]));
- let rows = labels(&app);
- let at = rows.iter().position(|r| r == "Inner").unwrap();
- assert_eq!(rows[at + 1].trim(), "Time Remap", "{rows:?}");
- }
-
- /// Enabling time remapping twirls the layer open on Time Remap (#157); disabling it reveals
- /// nothing.
- #[test]
- fn enabling_time_remapping_reveals_time_remap() {
- let mut s = effectcraft_engine::Session::default();
- let inner = s.execute("comp.new", json!({"name": "Inner", "width": 32, "height": 32, "duration": 2})).unwrap()["comp"].as_u64().unwrap();
- s.execute("comp.new", json!({"name": "Main", "width": 64, "height": 64, "duration": 4})).unwrap();
- s.execute("layer.newSolid", json!({"name": "Other"})).unwrap();
- let nested = s.execute("layer.addItem", json!({"item": inner})).unwrap()["layer"].as_u64().unwrap();
- let mut app = EffectcraftApp::new(s);
- let ctx = egui::Context::default();
- crate::menus::invoke(&mut app, &ctx, "layer.enableTimeRemap", json!({"layers": [nested]})).unwrap();
- assert_eq!(app.ui.timeline.layer_reveal.get(&nested), Some(&vec!["timeRemap".to_string()]));
- let rows = labels(&app);
- let at = rows.iter().position(|r| r == "Inner").unwrap();
- assert_eq!(rows[at + 1].trim(), "Time Remap", "{rows:?}");
- // Through the selection (the Layer menu), turning it off again: nothing new is revealed.
- app.session.execute("layer.select", json!({"layers": [nested]})).unwrap();
- app.ui.timeline.layer_reveal.clear();
- crate::menus::invoke(&mut app, &ctx, "layer.enableTimeRemap", json!({})).unwrap();
- assert!(app.ui.timeline.layer_reveal.is_empty());
- }
-
- #[test]
- fn cti_snaps_to_the_nearest_candidate() {
- assert_eq!(snap_time(&[0.0, 1.0, 2.0], 1.04, 0.1), 1.0);
- assert_eq!(snap_time(&[0.0, 1.0, 2.0], 1.5, 0.1), 1.5);
- assert_eq!(snap_time(&[1.0, 1.1], 1.06, 0.1), 1.1);
- let app = app();
- let comp = app.session.active_comp().unwrap().clone();
- let c = snap_candidates(&comp, &build_rows(&app, &comp));
- assert!(c.contains(&comp.duration.seconds()) && c.contains(&0.0));
- }
-
- /// UI fidelity (M13.5): compact After Effects-like rows and muted label-coloured bars.
- #[test]
- fn rows_and_bars_follow_after_effects_proportions() {
- let t = crate::theme::Tokens::for_kind(crate::theme::ThemeKind::Dark);
- assert_eq!(t.row_h, 19.0);
- let red = t.label(effectcraft_engine::color::Label::Red);
- let bar = bar_color(red, false);
- // Muted: darker and less saturated than the label, still reddish.
- assert!(bar.r() < red.r() && bar.r() > bar.g() + 30 && bar.g() >= red.g().min(0x3a) - 1);
- let sel = bar_color(red, true);
- assert!(sel.r() > bar.r());
+ /// 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() {
++ if widgets::checkbox(ui, r, *b, &t, egui::Id::unique(("cb", uid))).changed() {
+ 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);
+ }
+ }
+
+ /// 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;
diff --cc crates/ui-egui/src/panels/tracker.rs
index aa537ff8c,3edde09df..82f6d9f44
--- a/crates/ui-egui/src/panels/tracker.rs
+++ b/crates/ui-egui/src/panels/tracker.rs
@@@ -246,10 -257,10 +257,10 @@@ pub fn show(app: &mut EffectcraftApp, u
("scale", "Scale", settings.as_ref().is_some_and(|s| s.scale)),
] {
let cr = Rect::from_min_size(pos2(xx, y + 2.0), vec2(16.0, 16.0));
- let resp = ui.add_enabled_ui(transformish, |ui| widgets::checkbox(ui, cr, on && transformish, &t, egui::Id::new(("tracker-cb", key)))).inner;
- let resp = widgets::checkbox(ui, cr, on && transformish, &t, egui::Id::unique(("tracker-cb", key)));
++ let resp = ui.add_enabled_ui(transformish, |ui| widgets::checkbox(ui, cr, on && transformish, &t, egui::Id::unique(("tracker-cb", key)))).inner;
app.auto.add(&format!("tracker.{key}"), cr, text);
p.text(pos2(cr.max.x + 4.0, cr.center().y), Align2::LEFT_CENTER, text, Tokens::ui(12.0), if transformish { t.text } else { t.text_faint });
- if resp.clicked() && transformish {
+ if resp.changed() && transformish {
run(app, &ctx, "track.setType", with(json!({ key: !on })));
}
xx += 84.0;
diff --cc crates/ui-egui/src/widgets.rs
index 1ab352730,58383fe43..cc6da8ebb
--- a/crates/ui-egui/src/widgets.rs
+++ b/crates/ui-egui/src/widgets.rs
@@@ -382,96 -415,9 +415,96 @@@ pub fn text_button(ui: &mut Ui, rect: R
resp
}
-/// Checkbox in the AE look (small square).
+/// A primary-button gesture shared by custom and labelled checkboxes in this context.
+#[derive(Clone, Default)]
+struct CheckboxDrag {
+ press_frame: u64,
+ target: Option<bool>,
+ visited: std::collections::HashSet<egui::Id>,
+}
+
+/// Returns the requested value. Mixed checkboxes (`None`) and disabled controls are
+/// skipped. Each checkbox is visited once, so crossing it again cannot toggle it back.
+fn drag_toggle(ui: &Ui, response: &Response, value: Option<bool>) -> Option<bool> {
+ let (pressed, down, released) = ui.input(|i| (i.pointer.primary_pressed(), i.pointer.primary_down(), i.pointer.primary_released()));
+ let frame = ui.ctx().cumulative_frame_nr();
+ // clicked() reads Context input; do not call it while Context data is locked.
+ let clicked = response.clicked();
+ ui.data_mut(|data| {
- let drag = data.get_temp_mut_or_default::<CheckboxDrag>(egui::Id::new("checkbox-drag"));
++ let drag = data.get_temp_mut_or_default::<CheckboxDrag>(egui::Id::unique("checkbox-drag"));
+ if (!down && !released) || (pressed && drag.press_frame != frame) {
+ *drag = CheckboxDrag { press_frame: frame, ..Default::default() };
+ }
+ let on = value?;
+ if !response.enabled() {
+ return None;
+ }
+ if pressed && drag.target.is_none() && response.is_pointer_button_down_on() && response.contains_pointer() {
+ drag.target = Some(!on);
+ }
+ if down
+ && response.contains_pointer()
+ && let Some(target) = drag.target
+ {
+ if drag.visited.insert(response.id) && on != target {
+ return Some(target);
+ }
+ return None;
+ }
+ // The source already changed on press. Suppress its ordinary release click.
+ if released && drag.target.is_some() {
+ return None;
+ }
+ clicked.then_some(!on)
+ })
+}
+
+/// A labelled checkbox with the same drag behavior as the custom panel checkbox.
+/// Use through `ui.add`, `ui.put`, or `ui.add_enabled` like `egui::Checkbox`.
+pub struct DragCheckbox<'a> {
+ value: &'a mut bool,
+ text: egui::WidgetText,
+}
+
+impl<'a> DragCheckbox<'a> {
+ pub fn new(value: &'a mut bool, text: impl Into<egui::WidgetText>) -> Self {
+ Self { value, text: text.into() }
+ }
+}
+
+impl egui::Widget for DragCheckbox<'_> {
+ fn ui(self, ui: &mut Ui) -> Response {
+ let before = *self.value;
+ let mut response = ui.add(egui::Checkbox::new(self.value, self.text));
+ // egui changes on release; our shared gesture changes on press and entry.
+ *self.value = before;
+ response.flags.remove(egui::response::Flags::CHANGED);
+ if response.clicked() {
+ ui.ctx().request_repaint();
+ }
+ if let Some(value) = drag_toggle(ui, &response, Some(before)) {
+ *self.value = value;
+ response.mark_changed();
+ ui.ctx().request_repaint();
+ }
+ response
+ }
+}
+
+/// A labelled checkbox that allocates its own rectangle.
+pub fn labelled_checkbox(ui: &mut Ui, value: &mut bool, text: impl Into<egui::WidgetText>) -> Response {
+ ui.add(DragCheckbox::new(value, text))
+}
+
+/// Checkbox in the AE look (small square). `changed()` requests a toggle, including
+/// keyboard activation and entry during a drag begun on another checkbox.
pub fn checkbox(ui: &mut Ui, rect: Rect, on: bool, t: &Tokens, id: egui::Id) -> Response {
- let resp = ui.interact(rect, id, Sense::click());
+ let mut resp = ui.interact(rect, id, Sense::click());
+ let next = drag_toggle(ui, &resp, Some(on));
+ if next.is_some() {
+ resp.mark_changed();
+ }
+ let on = next.unwrap_or(on);
let b = Rect::from_center_size(rect.center(), vec2(12.0, 12.0));
ui.painter().rect_filled(b, 2.0, if on { t.accent } else { t.field_bg });
ui.painter().rect_stroke(b, 2.0, Stroke::new(1.0, if on { t.accent } else { t.field_border }), StrokeKind::Inside);
@@@ -753,106 -824,15 +911,115 @@@ pub(crate) fn constrained(c: &[f64], d
mod tests {
use super::*;
+ fn checkbox_frame(ctx: &egui::Context, values: &mut [Option<bool>; 5], events: Vec<egui::Event>) {
+ let t = Tokens::for_kind(Default::default());
+ let input = egui::RawInput { events, ..Default::default() };
+ let mut output = ctx.run_ui(input, |ui| {
+ for (index, value) in values.iter_mut().enumerate() {
+ let rect = Rect::from_min_size(pos2(20.0, 20.0 + index as f32 * 30.0), vec2(120.0, 20.0));
+ ui.add_enabled_ui(index != 3, |ui| {
+ if index == 4 {
+ if let Some(on) = value {
+ ui.put(rect, DragCheckbox::new(on, crate::i18n::tr("Grid")));
+ }
+ } else if let Some(on) = value {
- if checkbox(ui, rect, *on, &t, egui::Id::new(index)).changed() {
++ if checkbox(ui, rect, *on, &t, egui::Id::unique(index)).changed() {
+ *on = !*on;
+ }
+ } else {
- let response = ui.interact(rect, egui::Id::new(index), Sense::click());
++ let response = ui.interact(rect, egui::Id::unique(index), Sense::click());
+ assert_eq!(drag_toggle(ui, &response, None), None);
+ }
+ });
+ }
+ });
+ output.textures_delta.clear();
+ }
+
+ fn checkbox_pointer(y: f32, pressed: Option<bool>) -> Vec<egui::Event> {
+ let pos = pos2(28.0, y);
+ let mut events = vec![egui::Event::PointerMoved(pos)];
+ if let Some(pressed) = pressed {
+ events.push(egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() });
+ }
+ events
+ }
+
+ #[test]
+ fn checkbox_drag_sets_one_state_skips_mixed_and_disabled_and_ends_on_release() {
+ let ctx = egui::Context::default();
+ let mut values = [Some(false), Some(true), None, Some(false), Some(false)];
+ checkbox_frame(&ctx, &mut values, vec![]);
+ checkbox_frame(&ctx, &mut values, checkbox_pointer(28.0, Some(true)));
+ assert_eq!(values[0], Some(true));
+ // An already-matching neighbour must not invert, even after revisiting.
+ for y in [58.0, 88.0, 118.0, 148.0, 58.0, 28.0] {
+ checkbox_frame(&ctx, &mut values, checkbox_pointer(y, None));
+ }
+ assert_eq!(values, [Some(true), Some(true), None, Some(false), Some(true)]);
+ checkbox_frame(&ctx, &mut values, checkbox_pointer(28.0, Some(false)));
+ assert_eq!(values[0], Some(true), "release must not toggle the source again");
+ // Begin on the labelled wrapper and drag back into custom checkboxes.
+ checkbox_frame(&ctx, &mut values, checkbox_pointer(148.0, Some(true)));
+ assert_eq!(values[4], Some(false));
+ for y in [58.0, 28.0] {
+ checkbox_frame(&ctx, &mut values, checkbox_pointer(y, None));
+ }
+ checkbox_frame(&ctx, &mut values, checkbox_pointer(28.0, Some(false)));
+ assert_eq!(values, [Some(false), Some(false), None, Some(false), Some(false)]);
+ checkbox_frame(&ctx, &mut values, checkbox_pointer(58.0, None));
+ assert_eq!(values[1], Some(false), "hover after release must not paint");
+ }
+
+ #[test]
+ fn checkbox_click_and_keyboard_toggle_once_and_drag_must_start_on_a_checkbox() {
+ let ctx = egui::Context::default();
+ let mut values = [Some(false), Some(false), None, Some(false), Some(false)];
+ checkbox_frame(&ctx, &mut values, vec![]);
+ // Pressing outside the checkboxes must not start a gesture on entry.
+ checkbox_frame(&ctx, &mut values, checkbox_pointer(200.0, Some(true)));
+ checkbox_frame(&ctx, &mut values, checkbox_pointer(28.0, None));
+ checkbox_frame(&ctx, &mut values, checkbox_pointer(28.0, Some(false)));
+ assert_eq!(values[0], Some(false));
+ for source_y in [88.0, 118.0] {
+ checkbox_frame(&ctx, &mut values, checkbox_pointer(source_y, Some(true)));
+ checkbox_frame(&ctx, &mut values, checkbox_pointer(28.0, None));
+ checkbox_frame(&ctx, &mut values, checkbox_pointer(28.0, Some(false)));
+ assert_eq!(values[0], Some(false), "mixed and disabled sources cannot begin a drag");
+ }
+ for y in [28.0, 148.0] {
+ checkbox_frame(&ctx, &mut values, checkbox_pointer(y, Some(true)));
+ checkbox_frame(&ctx, &mut values, checkbox_pointer(y, Some(false)));
+ }
+ assert_eq!(values[0], Some(true));
+ assert_eq!(values[4], Some(true));
- ctx.memory_mut(|m| m.request_focus(egui::Id::new(0usize)));
++ ctx.memory_mut(|m| m.request_focus(egui::Id::unique(0usize)));
+ checkbox_frame(
+ &ctx,
+ &mut values,
+ vec![egui::Event::Key { key: egui::Key::Space, physical_key: None, pressed: true, repeat: false, modifiers: Default::default() }],
+ );
+ assert_eq!(values[0], Some(false), "keyboard activation still works");
+ // Fast clicks may deliver press and release together in one input frame.
+ // This also exercises clicked() without an active drag (outside the data lock).
+ for (index, y) in [(0, 28.0), (4, 148.0)] {
+ let before = values[index];
+ let mut events = checkbox_pointer(y, Some(true));
+ events.extend(checkbox_pointer(y, Some(false)));
+ checkbox_frame(&ctx, &mut values, events);
+ assert_eq!(values[index], before.map(|on| !on));
+ }
+ }
+
+ /// #2097: the drag speed comes from the slider range, not a much wider hard range.
+ #[test]
+ fn slider_scrub_speed_uses_the_slider_range() {
+ let slider = |min, max, slider_min, slider_max| ParamUi::Slider { min, max, slider_min, slider_max, decimals: 1 };
+ assert!((slider_scrub_speed(&slider(0.0, 10_000.0, 0.0, 1_000.0)) - 1_000.0 / 300.0).abs() < 1e-9);
+ assert!((slider_scrub_speed(&slider(0.0, 1.0e9, 0.0, 1.0)) - 1.0 / 300.0).abs() < 1e-9);
+ assert_eq!(slider_scrub_speed(&ParamUi::Number), 0.5);
+ }
+
/// #488: an inline editor selects its whole text only as it opens. Should it be without the
/// keyboard for a frame later (an input method, another handler), it takes the keyboard back
/// with the caret where the user put it instead of selecting everything again, which made
diff --cc crates/ui-egui/tests/it/main.rs
index 000000000,6b4c08912..00d852ee2
mode 000000,100644..100644
--- a/crates/ui-egui/tests/it/main.rs
+++ b/crates/ui-egui/tests/it/main.rs
@@@ -1,0 -1,105 +1,106 @@@
+ //! The crate's integration tests, one binary (each module is a former `tests/<name>.rs`).
+
+ mod native_menu_text_keys;
+ mod render_queue_snapshot;
+ mod shared_docking_ui;
+ mod ui_3d;
+ mod ui_agent_audit;
+ mod ui_angles;
+ mod ui_audio_scrub;
+ mod ui_azerty_shortcuts;
+ mod ui_batch_switches;
+ mod ui_blank_context_menus;
+ mod ui_camera_tracker;
+ mod ui_character_eyedropper;
++mod ui_checkbox_drag;
+ mod ui_color_hex;
+ mod ui_comp_presets;
+ mod ui_control_modifiers;
+ mod ui_dock_resize;
+ mod ui_drag_drop;
+ mod ui_effect_controls;
+ mod ui_effect_drop_highlight;
+ mod ui_effect_names;
+ mod ui_font_search;
+ mod ui_form_fit;
+ mod ui_frame_step;
+ mod ui_fx_editors;
+ mod ui_gpu;
+ mod ui_gradient_editor;
+ mod ui_gradient_handles;
+ mod ui_gradient_value;
+ mod ui_graph_fit;
+ mod ui_group_rename;
+ mod ui_guide_layers;
+ mod ui_inline_edit;
+ mod ui_keyframes;
+ mod ui_large_project;
+ mod ui_layer_panel_zoom;
+ mod ui_layer_source_picker;
+ mod ui_light_settings;
+ mod ui_live_preview;
+ mod ui_locked_color;
+ mod ui_media_browser_cache;
+ mod ui_media_browser_copy_path;
+ mod ui_menus;
+ mod ui_new_primitive;
+ mod ui_object_matte;
+ mod ui_panel_focus;
+ mod ui_panel_windows;
+ mod ui_panels;
+ mod ui_parameter_spacing;
+ mod ui_presets_folder;
+ mod ui_preview_align;
+ mod ui_project_delete;
+ mod ui_project_duplicate;
+ mod ui_project_keyboard;
+ mod ui_project_new_folder;
+ mod ui_project_rows;
+ mod ui_quick_offset;
+ mod ui_ram_preview;
+ mod ui_render_queue;
+ mod ui_script_console;
+ mod ui_scriptui;
+ mod ui_scrolling;
+ mod ui_settings_info;
+ mod ui_tabs;
+ mod ui_tail;
+ mod ui_text_edit;
+ mod ui_text_range_handles;
+ mod ui_theme_favorites;
+ mod ui_time_zoom_controls;
+ mod ui_timeline_effect_label;
+ mod ui_timeline_pan;
+ mod ui_timeline_shapes;
+ mod ui_timeline_switches;
+ mod ui_timeline_trim;
+ mod ui_timeline_zoom;
+ mod ui_toolbar_gradient;
+ mod ui_tracker;
+ mod ui_unreadable_footage;
+ mod ui_video_preview_off;
+ mod ui_viewer;
+ mod ui_viewers;
+ mod ui_visual_review;
+ mod ui_web_gpu_storage;
+ mod ui_web_job_gpu;
+ mod ui_web_offload;
+ mod ui_workflow_selection;
+ mod ui_workspace_focus;
+ mod viewer_geometry;
+ mod viewer_passive_display;
+
+ /// Register the managed build's canonical craft-fonts checkout (`CRAFT_FONTS_DIR/fonts`) through
+ /// the same directory source production scans for `EFFECTCRAFT_FONT_DIRS`. The UI tests then render
+ /// real Japanese glyphs from the canonical external input instead of relying on host fonts.
+ pub(crate) fn add_canonical_test_fonts() {
+ use effectcraft_text::fonts::{self, DirectorySource};
+ static REGISTER: std::sync::Once = std::sync::Once::new();
+ REGISTER.call_once(|| {
+ let Some(root) = std::env::var_os("CRAFT_FONTS_DIR") else { return };
+ let dir = std::path::PathBuf::from(root).join("fonts");
+ if dir.is_dir() {
+ fonts::add_source(&DirectorySource { dirs: vec![dir] });
+ }
+ });
+ }
diff --cc crates/ui-egui/tests/it/ui_checkbox_drag.rs
index ba65e54dc,000000000..ba65e54dc
mode 100644,000000..100644
--- a/crates/ui-egui/tests/it/ui_checkbox_drag.rs
+++ b/crates/ui-egui/tests/it/ui_checkbox_drag.rs