Merge pull request #1144 from tylerjenningsw/enhance/quick-offset

# Conflicts:
#	crates/ui-egui/src/i18n/ui.rs
This commit is contained in:
Brandon Thomas
2026-10-13 04:28:43 -04:00
12 changed files with 896 additions and 68 deletions
+12
View File
@@ -622,6 +622,8 @@ const JAPANESE: &[(&str, &str)] = &[
("After Effects project", "After Effectsプロジェクト"),
("Lottie animation", "Lottieアニメーション"),
("Project", "プロジェクト"),
("Total Offset", "合計オフセット"),
("Per Layer", "レイヤーごと"),
];
const SIMPLIFIED_CHINESE: &[(&str, &str)] = &[
@@ -1344,6 +1346,8 @@ const SIMPLIFIED_CHINESE: &[(&str, &str)] = &[
("Match System", "跟随系统"),
("Default", "默认"),
("Stored, but not used by EffectCraft yet", "已保存,但 EffectCraft 尚未使用"),
("Total Offset", "总偏移"),
("Per Layer", "每个图层"),
];
const TRADITIONAL_CHINESE: &[(&str, &str)] = &[
@@ -2061,6 +2065,8 @@ const TRADITIONAL_CHINESE: &[(&str, &str)] = &[
("Match System", "跟隨系統"),
("Default", "預設"),
("Stored, but not used by EffectCraft yet", "已儲存,但 EffectCraft 尚未使用"),
("Total Offset", "總偏移"),
("Per Layer", "每個圖層"),
];
/// Ukrainian (uk): original translations of the same interface rows as the Chinese catalogs.
@@ -2618,6 +2624,8 @@ const UKRAINIAN: &[(&str, &str)] = &[
("After Effects project", "Проєкт After Effects"),
("Lottie animation", "Анімація Lottie"),
("Project", "Проєкт"),
("Total Offset", "Загальний зсув"),
("Per Layer", "На шар"),
];
// Brazilian Portuguese.
@@ -3052,6 +3060,8 @@ const PORTUGUESE: &[(&str, &str)] = &[
("⌘/Ctrl-drag a pin to record its motion", "⌘/Ctrl+arraste um pino para gravar seu movimento"),
("▣ {}", "▣ {}"),
("⚠ {} is used by:", "⚠ {} é usado por:"),
("Total Offset", "Deslocamento total"),
("Per Layer", "Por camada"),
];
/// Czech (cs): original translations covering every row in the Chinese panel catalogs.
@@ -3587,6 +3597,8 @@ const CZECH: &[(&str, &str)] = &[
"Tyto sousední klíčové snímky nelze interpolovat, protože mají různý počet bodů přechodu.",
),
("Variable fonts only", "Jen proměnná písma"),
("Total Offset", "Celkový posun"),
("Per Layer", "Na vrstvu"),
];
#[cfg(test)]
+98 -11
View File
@@ -1127,18 +1127,62 @@ fn layer_drag_id() -> egui::Id {
}
/// A keyframe drag in progress: where the pointer started, the grabbed key's comp time
/// (seconds) and how many frames the selected keys have moved so far.
/// (seconds), how many frames the selected keys have moved so far and, for a Quick Offset
/// (Ctrl/Cmd+Alt), how many layers it staggers.
#[derive(Clone, Copy, Debug)]
struct KeyDrag {
origin_x: f32,
anchor: f64,
applied: i64,
quick: Option<usize>,
}
fn key_drag_id() -> egui::Id {
egui::Id::new("tl-key-drag")
}
/// A Quick Offset drag of selected layer bars (Ctrl/Cmd+Alt, #1012): the bar it started on, where
/// the pointer started, how many layers it staggers and how many frames the last one has moved.
#[derive(Clone, Copy, Debug)]
struct QuickBar {
layer: LayerId,
origin_x: f32,
layers: usize,
applied: i64,
}
fn quick_bar_id() -> egui::Id {
egui::Id::new("tl-quick-bar")
}
/// How many layers a Quick Offset of `layers` staggers (#1012): the unlocked ones, each once, if
/// there are at least two.
fn quick_offset_layers(comp: &Comp, layers: impl IntoIterator<Item = LayerId>) -> Option<usize> {
let mut seen: Vec<LayerId> = vec![];
for id in layers {
if !seen.contains(&id) && comp.layer(id).is_some_and(|l| !l.switches.locked) {
seen.push(id);
}
}
(seen.len() >= 2).then_some(seen.len())
}
/// A Quick Offset's feedback: the last layer's move and the step from one layer to the next.
fn quick_offset_note(frames: i64, layers: usize) -> String {
let per = frames as f64 / layers.saturating_sub(1).max(1) as f64;
format!("{}: {:+} f {}: {:+.2} f", tr("Total Offset"), frames, tr("Per Layer"), per)
}
/// A Timeline drag's readout by the pointer (After Effects shows it in the Info panel).
fn drag_tip(ctx: &egui::Context, t: &Tokens, ptr: Pos2, note: String) {
let fg = ctx.layer_painter(egui::LayerId::new(egui::Order::Tooltip, egui::Id::new("tl-key-drag-tip")));
let g = fg.layout_no_wrap(note, Tokens::ui(11.5), t.text);
let r = Rect::from_min_size(ptr + vec2(14.0, 14.0), g.size() + vec2(10.0, 6.0));
fg.rect_filled(r, 3.0, t.panel_bg);
fg.rect_stroke(r, 3.0, Stroke::new(1.0, t.field_border), StrokeKind::Inside);
fg.galley(r.min + vec2(5.0, 3.0), g, t.text);
}
/// A switch pressed and dragged over other rows: the switch, the state the press gave it, and
/// the undo step the drag folds into.
#[derive(Clone, Debug)]
@@ -2136,7 +2180,23 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
}
layer_context_menu(&body, &comp, layer, &selected, vector_footage_layer(&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));
@@ -2586,6 +2646,8 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
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 {
@@ -2680,7 +2742,8 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
});
// Alt-drag the first or last key of a selected group: scale the group in time.
if kresp.drag_started()
&& ui.input(|i| i.modifiers.alt)
&& mods.alt
&& !mods.command
&& let Some(c) = app.session.active_comp_arc()
{
super::graph_tools::alt_scale_begin(app, &ctx, &c, ct.seconds());
@@ -2693,7 +2756,9 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
&& !super::graph_tools::alt_scale_active(&ctx)
&& let Some(p) = ctx.input(|i| i.pointer.press_origin())
{
ctx.data_mut(|d| d.insert_temp(key_drag_id(), KeyDrag { origin_x: p.x, anchor: ct.seconds(), applied: 0 }));
// 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 }));
}
}
}
@@ -2877,6 +2942,27 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
ctx.data_mut(|d| d.remove::<Vec<u64>>(layer_drag_id()));
}
}
// Quick Offset of layer bars: the last selected layer moves by whole frames with the pointer
// until the button is released, wherever the bar's row has scrolled to.
if let Some(mut q) = ctx.data(|d| d.get_temp::<QuickBar>(quick_bar_id())) {
let (down, ptr) = ctx.input(|i| (i.pointer.primary_down(), i.pointer.latest_pos()));
match ptr.filter(|_| down) {
Some(ptr) => {
let frames = (((ptr.x - q.origin_x) as f64 / pps) / fd).round() as i64;
if frames != q.applied {
q.applied = frames;
ctx.data_mut(|d| d.insert_temp(quick_bar_id(), q));
let merge = format!("bar-quick-{}", q.layer.0);
actions.push(("layer.quickOffset".into(), json!({"delta": frames as f64 * fd, "merge": merge, "fromStart": true})));
}
drag_tip(&ctx, &t, ptr, quick_offset_note(q.applied, q.layers));
}
None => {
ctx.data_mut(|d| d.remove::<QuickBar>(quick_bar_id()));
ui_actions.push(UiAct::EndMerge);
}
}
}
// Keyframe drag: the selected keys move by whole frames with the pointer until it is
// released (one undo step); Shift snaps the grabbed key to the current time, the work area
// and composition markers.
@@ -2897,7 +2983,10 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
}
let total = ((target - kd.anchor) / fd).round() as i64;
if total != kd.applied {
actions.push(("keys.move".into(), json!({"delta": (total - kd.applied) as f64 * fd, "merge": "key-drag"})));
actions.push(match kd.quick {
Some(_) => ("keys.quickOffset".into(), json!({"delta": total as f64 * fd, "merge": "key-quick-offset", "fromStart": true})),
None => ("keys.move".into(), json!({"delta": (total - kd.applied) as f64 * fd, "merge": "key-drag"})),
});
kd.applied = total;
ctx.data_mut(|d| d.insert_temp(key_drag_id(), kd));
}
@@ -2905,13 +2994,11 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
// Where the grabbed key is and how far the keys moved (After Effects shows this
// in the Info panel).
let at = Tick::from_seconds_f64(kd.anchor + kd.applied as f64 * fd);
let note = format!("{} {:+} f", super::timecode(&app.session, &comp, at), kd.applied);
let fg = ctx.layer_painter(egui::LayerId::new(egui::Order::Tooltip, egui::Id::new("tl-key-drag-tip")));
let g = fg.layout_no_wrap(note, Tokens::ui(11.5), t.text);
let r = Rect::from_min_size(ptr + vec2(14.0, 14.0), g.size() + vec2(10.0, 6.0));
fg.rect_filled(r, 3.0, t.panel_bg);
fg.rect_stroke(r, 3.0, Stroke::new(1.0, t.field_border), StrokeKind::Inside);
fg.galley(r.min + vec2(5.0, 3.0), g, t.text);
let note = match kd.quick {
Some(n) => quick_offset_note(kd.applied, n),
None => format!("{} {:+} f", super::timecode(&app.session, &comp, at), kd.applied),
};
drag_tip(&ctx, &t, ptr, note);
app.ui.status = format!("Keyframe at {}", super::timecode(&app.session, &comp, at));
}
None => {