Timeline: the composition marker bin adds comp markers where they are dropped (#275)
As in After Effects, the right end of the Timeline's time ruler has a composition marker bin (an original icon drawn in code). Dragging out of it shows a marker following the pointer along the ruler's marker strip, snapping like a dragged marker (current time, work area, other markers); releasing over the time ruler's width adds a composition marker there with comp.addMarker (one "Add Marker" undo step). Dropped back on the bin, nothing is added. The time graph ends 18 px before the panel edge to leave the bin a column above the layers' scroll bar. Automation id: timeline.markerBin. Numpad * (or * typed with Shift+8), the keymap's Add Marker, now works in the window too: egui has no key for it, so it comes as text. The marker glyph and colour are shared helpers now (markers, nested markers, the dragged marker). Test: ui_timeline_zoom dragging_out_of_the_marker_bin_adds_a_comp_marker. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
6bb9bd8dab
commit
7056801eb2
@@ -59,6 +59,8 @@ pub enum Icon {
|
||||
Keyframe,
|
||||
PickWhip,
|
||||
Flowchart,
|
||||
/// The Timeline's composition marker bin: a marker tab resting in an open tray.
|
||||
MarkerBin,
|
||||
// project items
|
||||
Folder,
|
||||
Comp,
|
||||
@@ -412,6 +414,10 @@ pub fn paint(painter: &Painter, rect: Rect, icon: Icon, color: Color32) {
|
||||
pen.rect(10.0, 9.5, 14.5, 13.5);
|
||||
pen.line(&[(6.0, 4.5), (12.25, 4.5), (12.25, 9.5)]);
|
||||
}
|
||||
MarkerBin => {
|
||||
pen.fill(&[(5.0, 2.0), (11.0, 2.0), (11.0, 7.5), (8.0, 10.5), (5.0, 7.5)]);
|
||||
pen.line(&[(2.0, 9.0), (2.0, 14.0), (14.0, 14.0), (14.0, 9.0)]);
|
||||
}
|
||||
Folder => pen.closed(&[(1.5, 4.0), (6.0, 4.0), (7.5, 5.5), (14.5, 5.5), (14.5, 13.0), (1.5, 13.0)]),
|
||||
Comp => {
|
||||
pen.rect(2.0, 3.0, 14.0, 13.0);
|
||||
|
||||
@@ -1512,6 +1512,16 @@ pub fn handle_shortcuts(app: &mut EffectcraftApp, ctx: &egui::Context) {
|
||||
})
|
||||
.collect()
|
||||
});
|
||||
// Numpad * (or `*` typed with Shift+8): Add Marker (#275). egui has no key for it, so it
|
||||
// comes as text.
|
||||
if clipboard && app.dialog.is_none() && ctx.input(|i| i.events.iter().any(|e| matches!(e, egui::Event::Text(t) if t == "*"))) {
|
||||
let bound = app.session.shortcuts().bindings().into_iter().find(|(k, _)| *k == "Num*").map(|(_, b)| (b.command.clone(), b.params.clone()));
|
||||
if let Some((id, params)) = bound
|
||||
&& let Err(e) = invoke(app, ctx, &id, if params.is_null() { json!({}) } else { params })
|
||||
{
|
||||
app.ui.status = e;
|
||||
}
|
||||
}
|
||||
if events.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -4,15 +4,17 @@
|
||||
//! Gestures, as in After Effects: drag moves a marker (snapping to the current time, the work
|
||||
//! area and other markers), Alt-drag sets its duration, Cmd-click (Ctrl-click elsewhere)
|
||||
//! deletes it, double-click opens the Marker dialog, right-click offers Settings / Convert /
|
||||
//! Delete. Protected regions (Responsive Design) shade the timeline. Every change is a
|
||||
//! `markers.*` engine command, so it is undoable and agent-drivable.
|
||||
//! Delete. Protected regions (Responsive Design) shade the timeline. A marker dragged out of the
|
||||
//! composition marker bin, at the right end of the time ruler, adds a composition marker where it
|
||||
//! is dropped. Every change is an engine command, so it is undoable and agent-drivable.
|
||||
|
||||
use effectcraft_engine::project::{Comp, Layer, Marker};
|
||||
use effectcraft_engine::time::Tick;
|
||||
use egui::{Align2, Color32, Rect, Sense, Stroke, pos2, vec2};
|
||||
use egui::{Align2, Color32, Pos2, Rect, Sense, Stroke, pos2, vec2};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use super::timeline::TMap;
|
||||
use crate::icons::{self, Icon};
|
||||
use crate::theme::Tokens;
|
||||
use crate::{Dialog, EffectcraftApp};
|
||||
|
||||
@@ -253,6 +255,17 @@ fn snap(app: &EffectcraftApp, comp: &Comp, tm: TMap, t: f64, skip: MarkerRef) ->
|
||||
t
|
||||
}
|
||||
|
||||
/// A marker's colour: its label's, pale yellow without one.
|
||||
fn marker_color(t: &Tokens, label: effectcraft_engine::color::Label) -> Color32 {
|
||||
if label == effectcraft_engine::color::Label::None { Color32::from_rgb(0xd8, 0xd8, 0x60) } else { t.label(label) }
|
||||
}
|
||||
|
||||
/// The marker glyph at `x` from `y0`, `h` points tall: a tab pointing down at the time.
|
||||
fn marker_shape(x: f32, y0: f32, h: f32) -> Vec<Pos2> {
|
||||
let ym = y0 + h * 0.6;
|
||||
vec![pos2(x - 4.0, y0), pos2(x + 4.0, y0), pos2(x + 4.0, ym), pos2(x, y0 + h), pos2(x - 4.0, ym)]
|
||||
}
|
||||
|
||||
/// Draw one marker (triangle + duration bar + comment) at `x` in a strip `[y0, y1]` and handle
|
||||
/// its gestures. `comp_t` is the marker's comp time.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
@@ -260,9 +273,8 @@ fn marker(app: &mut EffectcraftApp, ui: &mut egui::Ui, p: &egui::Painter, comp:
|
||||
let t = app.tokens;
|
||||
let ctx = ui.ctx().clone();
|
||||
let x = tm.x(comp_t);
|
||||
let col = if m.label == effectcraft_engine::color::Label::None { Color32::from_rgb(0xd8, 0xd8, 0x60) } else { t.label(m.label) };
|
||||
let col = marker_color(&t, m.label);
|
||||
let h = (y1 - y0).min(10.0);
|
||||
let ym = y0 + h * 0.6;
|
||||
if m.duration > Tick(0) {
|
||||
let xe = tm.x(comp_t + m.duration.seconds());
|
||||
let bar = Rect::from_min_max(pos2(x, y0 + 1.0), pos2(xe, y0 + h - 1.0));
|
||||
@@ -276,7 +288,7 @@ fn marker(app: &mut EffectcraftApp, ui: &mut egui::Ui, p: &egui::Painter, comp:
|
||||
}
|
||||
p.line_segment([pos2(xe, y0), pos2(xe, y0 + h)], Stroke::new(1.0, col));
|
||||
}
|
||||
p.add(egui::Shape::convex_polygon(vec![pos2(x - 4.0, y0), pos2(x + 4.0, y0), pos2(x + 4.0, ym), pos2(x, y0 + h), pos2(x - 4.0, ym)], col, Stroke::NONE));
|
||||
p.add(egui::Shape::convex_polygon(marker_shape(x, y0, h), col, Stroke::NONE));
|
||||
if !m.comment.is_empty() {
|
||||
p.text(pos2(x + 7.0, y0 + h / 2.0), Align2::LEFT_CENTER, m.comment.lines().next().unwrap_or_default(), Tokens::ui(10.0), t.text);
|
||||
}
|
||||
@@ -365,6 +377,37 @@ pub(crate) fn comp_markers(app: &mut EffectcraftApp, ui: &mut egui::Ui, comp: &C
|
||||
}
|
||||
}
|
||||
|
||||
/// The composition marker bin at the right end of the time ruler (`bin`), as in After Effects
|
||||
/// (#275): drag a marker out of it and it follows the pointer along the marker strip `strip`
|
||||
/// (snapping like a dragged marker); dropping it there adds a composition marker at that time,
|
||||
/// one undo step. Dropped back on the bin or outside the time graph's width, nothing is added.
|
||||
pub(crate) fn marker_bin(app: &mut EffectcraftApp, ui: &mut egui::Ui, comp: &Comp, tm: TMap, bin: Rect, strip: Rect) {
|
||||
let t = app.tokens;
|
||||
let resp = ui.interact(bin, egui::Id::new("marker-bin"), Sense::drag()).on_hover_text("Composition marker bin: drag a marker to the time ruler");
|
||||
app.auto.add("timeline.markerBin", bin, "Composition marker bin");
|
||||
let hot = resp.hovered() || resp.dragged();
|
||||
if hot {
|
||||
ui.ctx().set_cursor_icon(if resp.dragged() { egui::CursorIcon::Grabbing } else { egui::CursorIcon::Grab });
|
||||
}
|
||||
icons::paint(ui.painter(), bin, Icon::MarkerBin, if hot { t.icon_active } else { t.icon });
|
||||
let at = resp.interact_pointer_pos().filter(|p| p.x >= strip.min.x && p.x < strip.max.x).map(|p| {
|
||||
let snapped = snap(app, comp, tm, tm.t(p.x), MarkerRef { layer: None, index: usize::MAX });
|
||||
snapped.min(comp.duration.seconds())
|
||||
});
|
||||
let Some(at) = at else { return };
|
||||
if resp.dragged() {
|
||||
let h = strip.height().min(10.0);
|
||||
let col = marker_color(&t, effectcraft_engine::color::Label::None);
|
||||
let p = ui.painter().with_clip_rect(strip);
|
||||
p.add(egui::Shape::convex_polygon(marker_shape(tm.x(at), strip.min.y, h), col, Stroke::NONE));
|
||||
}
|
||||
if resp.drag_stopped()
|
||||
&& let Err(e) = app.session.execute("comp.addMarker", json!({"time": at}))
|
||||
{
|
||||
app.ui.status = e.to_string();
|
||||
}
|
||||
}
|
||||
|
||||
/// Layer markers on a layer's row `r`; on a precomp layer, its comp's markers too (read-only,
|
||||
/// outlined: hover names them, a double-click opens the nested comp at the marker).
|
||||
pub(crate) fn layer_markers(app: &mut EffectcraftApp, ui: &mut egui::Ui, clip: Rect, comp: &Comp, layer: &Layer, tm: TMap, r: Rect) {
|
||||
@@ -399,10 +442,8 @@ fn nested_markers(app: &mut EffectcraftApp, ui: &mut egui::Ui, p: &egui::Painter
|
||||
let (y0, h) = (r.min.y + 3.0, (r.height() - 6.0).min(10.0));
|
||||
for (ct, i, m) in list {
|
||||
let x = tm.x(ct.seconds());
|
||||
let col = if m.label == effectcraft_engine::color::Label::None { Color32::from_rgb(0xd8, 0xd8, 0x60) } else { t.label(m.label) }.gamma_multiply(0.75);
|
||||
let ym = y0 + h * 0.6;
|
||||
let pts = vec![pos2(x - 4.0, y0), pos2(x + 4.0, y0), pos2(x + 4.0, ym), pos2(x, y0 + h), pos2(x - 4.0, ym)];
|
||||
p.add(egui::Shape::closed_line(pts, Stroke::new(1.2, col)));
|
||||
let col = marker_color(&t, m.label).gamma_multiply(0.75);
|
||||
p.add(egui::Shape::closed_line(marker_shape(x, y0, h), Stroke::new(1.2, col)));
|
||||
if !m.comment.is_empty() {
|
||||
p.text(pos2(x + 7.0, y0 + h / 2.0), Align2::LEFT_CENTER, m.comment.lines().next().unwrap_or_default(), Tokens::ui(10.0), t.text_dim);
|
||||
}
|
||||
|
||||
@@ -394,6 +394,9 @@ fn tl_map_id() -> egui::Id {
|
||||
egui::Id::new("timeline-map")
|
||||
}
|
||||
|
||||
/// The column right of the time graph: the composition marker bin over the layers' scroll bar.
|
||||
const GUTTER_W: f32 = 18.0;
|
||||
|
||||
/// The most a time ruler zooms in (pixels per second).
|
||||
const MAX_PPS: f64 = 4000.0;
|
||||
|
||||
@@ -1128,7 +1131,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
let oscroll = app.ui.timeline.outline_scroll;
|
||||
let cw = cols(rect.min.x - oscroll, left_w + overflow, vis);
|
||||
let graph_x0 = rect.min.x + left_w + 1.0;
|
||||
let graph_x1 = rect.max.x - 10.0;
|
||||
let graph_x1 = rect.max.x - GUTTER_W;
|
||||
ctx.data_mut(|d| d.insert_temp(egui::Id::new("timeline-graph-area"), (graph_x0, graph_x1 - graph_x0)));
|
||||
let fit_pps = fit_pps(graph_x1 - graph_x0, &comp);
|
||||
let pps = app.ui.timeline.pps.unwrap_or(fit_pps);
|
||||
@@ -1140,7 +1143,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
let top = rect.min.y;
|
||||
let rows_top = top + header_h + colhdr_h;
|
||||
let rows_rect = Rect::from_min_max(pos2(rect.min.x, rows_top), pos2(rect.max.x, rect.max.y - footer_h));
|
||||
let graph_rect = Rect::from_min_max(pos2(graph_x0, top + header_h - ruler_h + colhdr_h), pos2(graph_x1 + 10.0, rect.max.y - footer_h));
|
||||
let graph_rect = Rect::from_min_max(pos2(graph_x0, top + header_h - ruler_h + colhdr_h), pos2(rect.max.x, rect.max.y - footer_h));
|
||||
p.rect_filled(Rect::from_min_max(pos2(graph_x0, top), rect.max), 0.0, t.tl_bg);
|
||||
p.line_segment([pos2(graph_x0 - 1.0, top), pos2(graph_x0 - 1.0, rect.max.y)], Stroke::new(1.0, t.app_bg));
|
||||
|
||||
@@ -1208,6 +1211,8 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
|
||||
// ---- ruler (right).
|
||||
let ruler = Rect::from_min_max(pos2(graph_x0, top + header_h - ruler_h), pos2(rect.max.x, top + header_h));
|
||||
// The composition marker bin, at the right end of the ruler above the layers' scroll bar.
|
||||
let bin = Rect::from_min_max(pos2(graph_x1 + 2.0, ruler.max.y - 16.0), pos2(rect.max.x - 2.0, ruler.max.y - 2.0));
|
||||
let nav = Rect::from_min_max(pos2(graph_x0 + 6.0, top + 6.0), pos2(graph_x1, top + 14.0));
|
||||
// Time navigator: the visible span as a grey bar with blue end handles (as in After
|
||||
// Effects), over a dark track.
|
||||
@@ -1366,7 +1371,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
let secs_per_label = label_frames as f64 * fd;
|
||||
let first = (tm.start / secs_per_label).floor() * secs_per_label;
|
||||
let mut s = first;
|
||||
let pr = p.with_clip_rect(Rect::from_min_max(pos2(graph_x0, ruler.min.y), ruler.max));
|
||||
let pr = p.with_clip_rect(Rect::from_min_max(pos2(graph_x0, ruler.min.y), pos2(bin.min.x, ruler.max.y)));
|
||||
while s <= tm.t(graph_x1) + secs_per_label {
|
||||
let x = tm.x(s);
|
||||
pr.line_segment([pos2(x, ruler.max.y - 10.0), pos2(x, ruler.max.y)], Stroke::new(1.0, t.tl_ruler_tick));
|
||||
@@ -1385,7 +1390,8 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
}
|
||||
// Scrub in the ruler: the current time jumps to the pointer as soon as the button goes down
|
||||
// (After Effects), then follows it.
|
||||
let rresp = ui.interact(Rect::from_min_max(pos2(graph_x0, ruler.min.y + 12.0), ruler.max), egui::Id::new("tl-ruler"), Sense::click_and_drag());
|
||||
let rresp =
|
||||
ui.interact(Rect::from_min_max(pos2(graph_x0, ruler.min.y + 12.0), pos2(bin.min.x, ruler.max.y)), egui::Id::new("tl-ruler"), Sense::click_and_drag());
|
||||
if ((rresp.is_pointer_button_down_on() && ui.input(|i| i.pointer.primary_down())) || rresp.clicked())
|
||||
&& let Some(pt) = rresp.interact_pointer_pos()
|
||||
{
|
||||
@@ -2721,9 +2727,10 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
}
|
||||
|
||||
// Composition markers in the ruler; protected regions shade the layer rows.
|
||||
let mstrip = Rect::from_min_max(pos2(graph_x0, ruler.max.y - 12.0), pos2(graph_x1 + 10.0, ruler.max.y));
|
||||
let mstrip = Rect::from_min_max(pos2(graph_x0, ruler.max.y - 12.0), pos2(bin.min.x, ruler.max.y));
|
||||
let mrows = rows_rect.intersect(Rect::from_min_max(pos2(graph_x0, rows_rect.min.y), rows_rect.max));
|
||||
super::markers_ui::comp_markers(app, ui, &comp, tm, mstrip, mrows);
|
||||
super::markers_ui::marker_bin(app, ui, &comp, tm, bin, mstrip);
|
||||
|
||||
// Spacebar held: the Hand tool. Dragging the ruler or the time graph scrolls it in time when
|
||||
// zoomed in (registered last, so it takes the drag from the bars, keys and markers there).
|
||||
|
||||
Reference in New Issue
Block a user