mirror of
https://github.com/storytold/AniCraft.git
synced 2026-11-19 09:01:29 +01:00
feat(shell): the timeline's parenting view: a parent column with draggable dots, a parent menu, the arm sample (M7)
This commit is contained in:
1 parent
44f4f1227b
commit
ce8315ddda
11 files changed
+450
-7
No files matched your search
@@ -0,0 +1,7 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||
<circle cx="6" cy="5" r="2.5" />
|
||||
<path d="M6 7.5 V17 a2 2 0 0 0 2 2 H15.5" />
|
||||
<path d="M6 12 H15.5" />
|
||||
<circle cx="18" cy="12" r="2.5" />
|
||||
<circle cx="18" cy="19" r="2.5" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 372 B |
@@ -1,6 +1,6 @@
|
||||
# Command reference
|
||||
|
||||
Everything you can do in AniCraft is a command: the menus, the shortcuts, the command palette (**Ctrl+K**, macOS **⌘K**), `anicraft-cli` and AI assistants over MCP all run the same 373 commands, listed here by menu. The id is what scripts and [working headless](../working-headless.md) use; the parameters are what a command takes as JSON. Commands that change the document are one undo step each. Your own shortcuts (**Help › Keyboard Shortcuts**) replace the defaults shown here; see the [shortcut reference](shortcuts.md).
|
||||
Everything you can do in AniCraft is a command: the menus, the shortcuts, the command palette (**Ctrl+K**, macOS **⌘K**), `anicraft-cli` and AI assistants over MCP all run the same 376 commands, listed here by menu. The id is what scripts and [working headless](../working-headless.md) use; the parameters are what a command takes as JSON. Commands that change the document are one undo step each. Your own shortcuts (**Help › Keyboard Shortcuts**) replace the defaults shown here; see the [shortcut reference](shortcuts.md).
|
||||
|
||||
This page is generated from the command registry, so it always matches the version of AniCraft it came with.
|
||||
|
||||
@@ -9,7 +9,7 @@ This page is generated from the command registry, so it always matches the versi
|
||||
- **New** `file.new` · **Ctrl+N** (macOS **⌘N**)
|
||||
Parameters: `{width?, height?, fps?}`
|
||||
- **New from Sample** `file.new_sample`
|
||||
Parameters: `{which?: demo (default) | interactive (a menu with a Play button, for Test Movie)}`
|
||||
Parameters: `{which?: demo (default) | interactive (a menu with a Play button, for Test Movie) | arm (three parented layers, ADR 0113)}`
|
||||
- **New from Template…** `file.new_from_template`
|
||||
Parameters: `{template? (a built-in template's id, from file.templates) | path? (a template file: any .anicraft opens as a new, untitled document)}`
|
||||
- **Open…** `file.open` · **Ctrl+O** (macOS **⌘O**)
|
||||
@@ -164,6 +164,8 @@ This page is generated from the command registry, so it always matches the versi
|
||||
Parameters: `{layer?, name?, type?: normal|mask|masked|guide|guided, mask?: coverage|alpha|luminance (a mask layer's mask type), color?, outline?: bool (view as outlines), height?: 100|200|300, opacity?: 0..100 (percent), visible?, locked?, onion?} sets several at once, as one undo step; answers with the layer's properties`
|
||||
- **Remove Camera** `camera.remove` · Modify › Timeline · changes the document
|
||||
Parameters: `{} (removes the camera layer and its moves; asks first when the camera is animated)`
|
||||
- **Remove Parent** `layer.remove_parent` · Modify › Timeline · changes the document
|
||||
Parameters: `{layer? (default: the active layer), layers?: [ids], keep?: bool (default true)} the layer stops following its parent layer and stays where it is on stage at the playhead (layer.set_parent with parent: null)`
|
||||
- **Add Warp Mesh** `warp.add` · Modify › Asset Warp · changes the document
|
||||
Parameters: `{element? (a shape or bitmap; default the one selected), resolution? (cells along the longer side, 2…48; default 12)} → {element, created, resolution, columns, rows}. Covers the artwork with a warp mesh on every keyframe of its layer that holds it (it becomes a drawing object); on artwork that has one, changes the mesh's resolution`
|
||||
- **Remove Warp** `warp.remove` · Modify › Asset Warp · changes the document
|
||||
@@ -375,6 +377,10 @@ These commands have no menu item: the panels, the stage and the timeline use the
|
||||
Parameters: `{attached?: bool (default: toggles), layer?} an attached layer stays where it is on screen while the camera moves (titles, HUDs); its depth plays no part (ADR 0082)`
|
||||
- **Layer Depths** `layer.depths`
|
||||
Parameters: `{frame?} → {camera: bool, layers: [{layer, name, depth, keyed, key_here, attached}]} the layers that can have a depth, nearest first (ties in timeline order), at the frame`
|
||||
- **Parent Layer** `layer.set_parent` · changes the document
|
||||
Parameters: ``{parent: layer id | null (null removes the parent), layer? (default: the active layer), layers?: [ids] (several at once), keep?: bool (default true)} layer parenting (ADR 0113): the layer's artwork follows the first object on the parent layer at every frame (position, rotation, scale, skew; not colour or filters), while keeping its own keys and tweens. With `keep` the layer stays where it is on stage at the playhead: every key is re-expressed for the new parent, in one undo step. A layer can't follow itself or a layer that follows it; folders, guides, the camera and armature layers can't follow, and folders, guides and the camera can't lead``
|
||||
- **Layer Parents** `layer.parents`
|
||||
Parameters: `{frame?} → {layers: [{layer, name, parent, parent_name, ancestors: [ids, nearest first], children: [ids], can_follow, can_lead, space: [a, b, c, d, tx, ty] (the layer's own coordinates → the stage's at the frame)}]} top to bottom`
|
||||
- **Add Bone** `bone.add` · changes the document
|
||||
Parameters: ``{from? (instance or shape id: the bone starts on it) | parent? (bone id: the bone starts on its end; for a bone inside a shape, on its joint), to (instance or shape id: the bone moves it as a whole), head?: [x, y] (the joint on a root, stage px, default its registration point; from something that hangs from a bone the joint is always that bone's end, so chains stay joined), tail?: [x, y] (default `to`'s registration point), name?} → {bone, layer}. Both go to an armature layer (made for the first bone). Instances and shapes mix in one armature: a bone inside a shape can carry an instance (parent), and a bone can end on a shape that then gets bones of its own (bone.add_in_shape with parent)``
|
||||
- **Add Bone in Shape** `bone.add_in_shape` · changes the document
|
||||
|
||||
@@ -471,6 +471,7 @@ mod tests {
|
||||
a.open_panel(Some("testmovie"));
|
||||
}));
|
||||
// The layer depth row shows on artwork layers once the scene has a camera.
|
||||
found.extend(check("parenting view", |a, _| a.open_panel(Some("parenting"))));
|
||||
found.extend(check("layer depth", |a, _| {
|
||||
a.open_panel(Some("camera"));
|
||||
a.run("layer.select", serde_json::json!({"index": 1}));
|
||||
|
||||
+16
@@ -505,6 +505,10 @@ pub struct App {
|
||||
pub tl_drag: timeline::TlDrag,
|
||||
/// The layer being dragged by its name to another place in the stack (#407).
|
||||
pub tl_layer_drag: Option<anicraft_engine::doc::LayerId>,
|
||||
/// The layer whose dot is being dragged to its new parent layer in the parenting view
|
||||
/// (ADR 0113), and where the dots were drawn this frame.
|
||||
pub tl_parent_drag: Option<anicraft_engine::doc::LayerId>,
|
||||
pub tl_parent_dots: Vec<crate::parenting::Dot>,
|
||||
/// The layer column's width while its edge is dragged (#384); the preference takes it on
|
||||
/// release.
|
||||
pub tl_layer_w_drag: Option<f32>,
|
||||
@@ -814,6 +818,8 @@ impl App {
|
||||
frame_sel: None,
|
||||
tl_drag: timeline::TlDrag::None,
|
||||
tl_layer_drag: None,
|
||||
tl_parent_drag: None,
|
||||
tl_parent_dots: Vec::new(),
|
||||
tl_layer_w_drag: None,
|
||||
dock: prefs.workspaces.layout(),
|
||||
dock_view: Default::default(),
|
||||
@@ -2055,6 +2061,16 @@ impl App {
|
||||
self.raw_ends = Vec::new();
|
||||
self.raw_anchors = vec![anicraft_engine::geom::Vec2::new(620.0, 270.0)];
|
||||
}
|
||||
Some("parenting") | Some("parentmenu") => {
|
||||
// Layer parenting (ADR 0113): an arm of three parented layers, mid-tween, the
|
||||
// timeline's parenting view open and the forearm selected.
|
||||
self.run("file.new_sample", json!({"which": "arm"}));
|
||||
self.prefs.timeline_parenting = true;
|
||||
self.run("timeline.goto", json!({"frame": 12}));
|
||||
let fore = self.s.timeline().layers.get(1).map(|l| l.id.0);
|
||||
self.run("layer.select", json!({"layer": fore, "select": true}));
|
||||
self.view.fit = true;
|
||||
}
|
||||
Some("rawsnap") => {
|
||||
// Snapping while drawing (ADR 0045): a line being drawn from a corner of a raw
|
||||
// square, its end snapping onto the square's other corner (the ring).
|
||||
|
||||
+7
-1
@@ -73,6 +73,7 @@ pub enum Icon {
|
||||
Warp,
|
||||
EditMultiple,
|
||||
Layer,
|
||||
Parent,
|
||||
InsertFrame,
|
||||
InsertKeyframe,
|
||||
InsertBlankKeyframe,
|
||||
@@ -92,7 +93,7 @@ pub enum Icon {
|
||||
|
||||
impl Icon {
|
||||
#[cfg(test)]
|
||||
pub const ALL: [Icon; 74] = [
|
||||
pub const ALL: [Icon; 75] = [
|
||||
Icon::PanelProperties,
|
||||
Icon::PanelSwatches,
|
||||
Icon::PanelLibrary,
|
||||
@@ -111,6 +112,7 @@ impl Icon {
|
||||
Icon::InsertBlankKeyframe,
|
||||
Icon::Bind,
|
||||
Icon::Layer,
|
||||
Icon::Parent,
|
||||
Icon::EditMultiple,
|
||||
Icon::Bone,
|
||||
Icon::Magnet,
|
||||
@@ -257,6 +259,9 @@ impl Icon {
|
||||
Icon::FolderOpen => ("folder-open", false),
|
||||
// A layer: a row with a keyframe and its span (AniCraft original, on Lucide's grid).
|
||||
Icon::Layer => ("anicraft-layer", false),
|
||||
// A layer's dot joined to the layers that follow it (AniCraft original, on Lucide's
|
||||
// grid): the timeline's parenting view (ADR 0113).
|
||||
Icon::Parent => ("anicraft-parent", false),
|
||||
// Insert Frame / Keyframe / Blank Keyframe: the timeline's own marks (a frame cell, a
|
||||
// filled keyframe dot, a hollow blank-keyframe dot), each with a plus (AniCraft
|
||||
// originals, on Lucide's grid).
|
||||
@@ -343,6 +348,7 @@ static FILES: &[(&str, &str)] = &[
|
||||
("anicraft-camera", include_str!("../assets/icons/anicraft-camera.svg")),
|
||||
("anicraft-bone", include_str!("../assets/icons/anicraft-bone.svg")),
|
||||
("anicraft-bind", include_str!("../assets/icons/anicraft-bind.svg")),
|
||||
("anicraft-parent", include_str!("../assets/icons/anicraft-parent.svg")),
|
||||
("anicraft-warp", include_str!("../assets/icons/anicraft-warp.svg")),
|
||||
("anicraft-edit-multiple", include_str!("../assets/icons/anicraft-edit-multiple.svg")),
|
||||
("folder", include_str!("../assets/icons/folder.svg")),
|
||||
|
||||
@@ -63,6 +63,7 @@ mod mixed;
|
||||
mod motion_editor;
|
||||
mod movie_explorer;
|
||||
mod panels;
|
||||
mod parenting;
|
||||
mod motion_path;
|
||||
mod onion;
|
||||
mod pathtools;
|
||||
@@ -479,6 +480,8 @@ mod retime_ui_tests;
|
||||
#[cfg(test)]
|
||||
mod layer_ui_tests;
|
||||
#[cfg(test)]
|
||||
mod parenting_ui_tests;
|
||||
#[cfg(test)]
|
||||
mod tilt_ui_tests;
|
||||
#[cfg(test)]
|
||||
mod zoom_tests;
|
||||
@@ -644,6 +644,9 @@ pub(crate) fn menu_contents(app: &mut App, ui: &mut egui::Ui, top: &str, cmds: &
|
||||
crate::onion::toggle_edit_multiple(app);
|
||||
}
|
||||
ui.menu_button(tr!("Onion Skin Options"), |ui| crate::onion::menu(app, ui));
|
||||
if ui_item(ui, tr!("Parenting View"), "", Some(app.prefs.timeline_parenting)) {
|
||||
crate::parenting::toggle_view(app);
|
||||
}
|
||||
if ui_item(ui, tr!("Clip Content Outside the Stage"), "", Some(app.view.clip_to_stage)) {
|
||||
app.view.clip_to_stage = !app.view.clip_to_stage;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,202 @@
|
||||
//! The timeline's parenting view (ADR 0113): a column in the layer list where each layer has a
|
||||
//! dot, joined to its parent layer's dot by a line in its colour.
|
||||
//!
|
||||
//! Drag from a layer's dot to another layer to parent it; click the dot (or focus it and press
|
||||
//! Enter or Space) to pick the parent from a menu, or remove it. The same menu is in every
|
||||
//! layer's context menu, parenting view open or not. Everything runs `layer.set_parent`, so the
|
||||
//! layer stays where it is on stage and the change is one undo step.
|
||||
|
||||
use crate::a11y;
|
||||
use crate::app::App;
|
||||
use crate::icons::{self, Icon};
|
||||
use crate::menus;
|
||||
use crate::theme::{T, to_color32};
|
||||
use anicraft_engine::doc::{Layer, LayerId, Timeline};
|
||||
use egui::{Pos2, Rect, Sense, Stroke, StrokeKind, WidgetType, pos2, vec2};
|
||||
use serde_json::json;
|
||||
|
||||
/// Width of one step of the tree, and the most steps drawn (deeper chains share the last).
|
||||
const LANE: f32 = 9.0;
|
||||
const MAX_LANES: usize = 6;
|
||||
/// The dot's radius.
|
||||
const DOT: f32 = 4.5;
|
||||
|
||||
/// Where the parent column is in the layer list.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct Column {
|
||||
pub left: f32,
|
||||
pub right: f32,
|
||||
}
|
||||
|
||||
impl Column {
|
||||
/// How wide the column is for `tl`: as wide as its deepest chain needs.
|
||||
pub fn width(tl: &Timeline) -> f32 {
|
||||
let lanes = tl.layers.iter().map(|l| tl.rig_ancestors(l.id).len()).max().unwrap_or(0).min(MAX_LANES - 1) + 1;
|
||||
2.0 * DOT + 8.0 + lanes as f32 * LANE
|
||||
}
|
||||
|
||||
/// The column for `tl`, ending at `right`.
|
||||
pub fn new(tl: &Timeline, right: f32) -> Column {
|
||||
Column { left: right - Column::width(tl), right }
|
||||
}
|
||||
|
||||
fn dot(&self, tl: &Timeline, layer: LayerId, y: f32) -> Pos2 {
|
||||
let lane = tl.rig_ancestors(layer).len().min(MAX_LANES - 1);
|
||||
pos2(self.left + DOT + 4.0 + lane as f32 * LANE, y)
|
||||
}
|
||||
}
|
||||
|
||||
/// A layer's dot as drawn this frame.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct Dot {
|
||||
pub layer: LayerId,
|
||||
pub at: Pos2,
|
||||
}
|
||||
|
||||
/// The toggle beside the "Layers" heading: opens and closes the parenting view.
|
||||
pub fn head_toggle(app: &mut App, ui: &mut egui::Ui, painter: &egui::Painter, rect: Rect) {
|
||||
let on = app.prefs.timeline_parenting;
|
||||
let r = ui.interact(rect, ui.id().with("parenting_view"), Sense::click());
|
||||
if r.hovered() || on {
|
||||
painter.rect_filled(rect, T.rc(), if on { T.accent_dim } else { T.hover });
|
||||
}
|
||||
icons::paint(painter, Rect::from_center_size(rect.center(), vec2(15.0, 15.0)), Icon::Parent, if on { T.accent_text } else { T.text_dim });
|
||||
a11y::control(ui, &r, WidgetType::Checkbox, tr!("Parenting view"), Some(on));
|
||||
if r.on_hover_text(tr!("Parenting View: show which layer each layer follows. Drag from a layer's dot to another layer to parent it; click the dot to pick or remove the parent")).clicked() {
|
||||
toggle_view(app);
|
||||
}
|
||||
}
|
||||
|
||||
/// Opens or closes the parenting view (kept with the preferences).
|
||||
pub fn toggle_view(app: &mut App) {
|
||||
let on = !app.prefs.timeline_parenting;
|
||||
app.prefs.timeline_parenting = on;
|
||||
app.save_prefs();
|
||||
if on {
|
||||
app.status_ok(tr!("Parenting view: drag from a layer's dot to another layer, or click the dot to pick its parent"));
|
||||
}
|
||||
}
|
||||
|
||||
/// What a screen reader hears for a layer's dot.
|
||||
fn dot_name(tl: &Timeline, layer: &Layer) -> String {
|
||||
match layer.rig_parent.and_then(|p| tl.layer(p)) {
|
||||
Some(p) => tr!("Parent of {name}: {parent}", name = layer.name, parent = p.name),
|
||||
None => tr!("Parent of {name}: none", name = layer.name),
|
||||
}
|
||||
}
|
||||
|
||||
/// One row of the parent column: the dot's target, its name for assistive technology, the
|
||||
/// start of a drag, and its menu. `None` for a layer that can neither follow nor lead.
|
||||
pub fn row(app: &mut App, ui: &mut egui::Ui, tl: &Timeline, layer: &Layer, col: Column, y: f32, size: f32) -> Option<Dot> {
|
||||
if !layer.can_follow() && !layer.can_lead() {
|
||||
return None;
|
||||
}
|
||||
let at = col.dot(tl, layer.id, y);
|
||||
let hit = Rect::from_center_size(at, vec2(size, size));
|
||||
let r = ui.interact(hit, ui.id().with(("parent_dot", layer.id.0)), Sense::click_and_drag());
|
||||
a11y::control(ui, &r, WidgetType::Button, &dot_name(tl, layer), None);
|
||||
if r.drag_started_by(egui::PointerButton::Primary) && layer.can_follow() {
|
||||
app.tl_parent_drag = Some(layer.id);
|
||||
}
|
||||
let tip = match layer.rig_parent.and_then(|p| tl.layer(p)) {
|
||||
Some(p) => tr!("{name} follows {parent}. Drag to another layer to change its parent; click to pick or remove it", name = layer.name, parent = p.name),
|
||||
None if layer.can_follow() => tr!("Drag to another layer to make it the parent of {name}; click to pick one", name = layer.name),
|
||||
None => tr!("{name} can lead other layers: drag from their dots to this layer", name = layer.name),
|
||||
};
|
||||
let r = r.on_hover_text(tip);
|
||||
let id = layer.id;
|
||||
let shown = egui::Popup::menu(&r).id(egui::Id::new(("layer_parent", id.0))).show(|ui| menu(app, ui, id));
|
||||
if let Some(m) = shown {
|
||||
ui.ctx().accesskit_node_builder(m.response.id, |node| {
|
||||
node.set_role(egui::accesskit::Role::Menu);
|
||||
node.set_label(tr!("Parent layer"));
|
||||
});
|
||||
}
|
||||
Some(Dot { layer: id, at })
|
||||
}
|
||||
|
||||
/// The parent picker: no parent, then every layer, the ones this layer can't follow greyed.
|
||||
pub fn menu(app: &mut App, ui: &mut egui::Ui, layer: LayerId) {
|
||||
ui.set_min_width(180.0);
|
||||
let tl = app.s.timeline().clone();
|
||||
let Some(me) = tl.layer(layer) else { return };
|
||||
if !me.can_follow() {
|
||||
ui.add_enabled(false, egui::Button::new(tr!("This kind of layer can't follow a parent")));
|
||||
return;
|
||||
}
|
||||
if menus::check_item(ui, tr!("No Parent"), me.rig_parent.is_none(), true) && me.rig_parent.is_some() {
|
||||
app.run("layer.remove_parent", json!({"layer": layer.0}));
|
||||
}
|
||||
ui.separator();
|
||||
for cand in tl.layers.iter().filter(|l| l.id != layer && l.can_lead()) {
|
||||
let current = me.rig_parent == Some(cand.id);
|
||||
let ok = current || tl.rig_check(layer, cand.id).is_ok();
|
||||
if menus::check_item(ui, &cand.name, current, ok) && !current {
|
||||
app.run("layer.set_parent", json!({"layer": layer.0, "parent": cand.id.0}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// After the rows: the tree's lines and dots, and a dot being dragged to its new parent.
|
||||
/// `rows` are the layer rows on screen; `left` is the layer list's area.
|
||||
pub fn finish(app: &mut App, ui: &mut egui::Ui, painter: &egui::Painter, tl: &Timeline, dots: &[Dot], rows: &[(Rect, LayerId)], left: Rect) {
|
||||
let at = |id: LayerId| dots.iter().find(|d| d.layer == id).map(|d| d.at);
|
||||
let p = painter.with_clip_rect(left);
|
||||
// Lines first, each in the follower's colour: down (or up) the parent's lane, then across.
|
||||
for d in dots {
|
||||
let Some(layer) = tl.layer(d.layer) else { continue };
|
||||
let Some(parent) = layer.rig_parent else { continue };
|
||||
let stroke = Stroke::new(1.5, to_color32(layer.color));
|
||||
match at(parent) {
|
||||
Some(from) => {
|
||||
p.line_segment([from, pos2(from.x, d.at.y)], stroke);
|
||||
p.line_segment([pos2(from.x, d.at.y), d.at], stroke);
|
||||
}
|
||||
// Its parent's row isn't showing (scrolled away, or in a closed folder): a stub.
|
||||
None => {
|
||||
p.line_segment([pos2(d.at.x - LANE, d.at.y), d.at], stroke);
|
||||
}
|
||||
}
|
||||
}
|
||||
for d in dots {
|
||||
let Some(layer) = tl.layer(d.layer) else { continue };
|
||||
let c = to_color32(layer.color);
|
||||
let linked = layer.rig_parent.is_some() || tl.layers.iter().any(|l| l.rig_parent == Some(layer.id));
|
||||
if linked {
|
||||
p.circle_filled(d.at, DOT, c);
|
||||
p.circle_stroke(d.at, DOT, Stroke::new(1.0, T.panel));
|
||||
} else {
|
||||
// A free layer: a ring, so a rig's dots stand out.
|
||||
p.circle_filled(d.at, DOT, T.panel);
|
||||
p.circle_stroke(d.at, DOT - 0.5, Stroke::new(1.5, if layer.can_follow() { c } else { T.text_faint }));
|
||||
}
|
||||
}
|
||||
let Some(dragged) = app.tl_parent_drag else { return };
|
||||
let (pointer, down, cancel) = ui.input(|i| (i.pointer.latest_pos(), i.pointer.primary_down(), i.key_pressed(egui::Key::Escape)));
|
||||
let Some(from) = at(dragged).filter(|_| !cancel) else {
|
||||
app.tl_parent_drag = None;
|
||||
return;
|
||||
};
|
||||
let over = pointer.filter(|q| left.contains(*q)).and_then(|q| rows.iter().find(|(r, _)| q.y >= r.top() && q.y < r.bottom())).map(|(r, id)| (*r, *id)).filter(|(_, id)| *id != dragged);
|
||||
if !down {
|
||||
app.tl_parent_drag = None;
|
||||
// The engine says why when the layer can't follow that one (shown in the status bar).
|
||||
if let Some((_, target)) = over {
|
||||
app.run("layer.set_parent", json!({"layer": dragged.0, "parent": target.0}));
|
||||
}
|
||||
return;
|
||||
}
|
||||
let ok = over.is_some_and(|(_, t)| tl.rig_check(dragged, t).is_ok());
|
||||
ui.ctx().set_cursor_icon(if ok { egui::CursorIcon::Grabbing } else if over.is_some() { egui::CursorIcon::NoDrop } else { egui::CursorIcon::Grabbing });
|
||||
if let Some((r, _)) = over.filter(|_| ok) {
|
||||
let band = Rect::from_min_max(pos2(left.left(), r.top()), pos2(left.right(), r.bottom()));
|
||||
painter.rect_filled(band, 0.0, T.accent.gamma_multiply(0.22));
|
||||
painter.rect_stroke(band, 0.0, Stroke::new(1.0, T.accent), StrokeKind::Inside);
|
||||
}
|
||||
if let Some(q) = pointer {
|
||||
let c = tl.layer(dragged).map_or(T.accent, |l| to_color32(l.color));
|
||||
painter.line_segment([from, q], Stroke::new(2.0, c));
|
||||
painter.circle_filled(q, 3.0, c);
|
||||
}
|
||||
ui.ctx().request_repaint();
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
//! The timeline's parenting view (ADR 0113), driven by pointer events and by assistive
|
||||
//! technology: a dot dragged to another layer parents it, a cycle is refused, and every dot is a
|
||||
//! named button whose menu picks the parent without a pointer.
|
||||
|
||||
use crate::app::App;
|
||||
use anicraft_engine::doc::LayerId;
|
||||
use egui::accesskit::{Action, ActionRequest, Node, Role, TreeId};
|
||||
use egui::{Event, Modifiers, PointerButton, Pos2, Rect, pos2, vec2};
|
||||
use serde_json::json;
|
||||
|
||||
/// The arm sample with its links removed (the limbs where they stand), parenting view open.
|
||||
fn opened() -> (App, egui::Context) {
|
||||
let ctx = egui::Context::default();
|
||||
ctx.enable_accesskit();
|
||||
let mut session = anicraft_engine::Session::new(anicraft_engine::doc::sample::arm());
|
||||
let ids: Vec<u64> = session.timeline().layers.iter().map(|l| l.id.0).collect();
|
||||
session.execute("layer.remove_parent", &json!({"layers": ids})).expect("unparented");
|
||||
let mut app = App::with_context(&ctx, session, Some(std::path::PathBuf::from("unused.png")));
|
||||
app.prefs.timeline_parenting = true;
|
||||
settle(&ctx, &mut app);
|
||||
(app, ctx)
|
||||
}
|
||||
|
||||
fn frame(ctx: &egui::Context, app: &mut App, events: Vec<Event>) -> Vec<(egui::accesskit::NodeId, Node)> {
|
||||
let mut all = vec![Event::ModifiersChanged(Modifiers::NONE)];
|
||||
all.extend(events);
|
||||
let input = egui::RawInput { screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(1600.0, 940.0))), events: all, ..Default::default() };
|
||||
let mut out = ctx.run_ui(input, |ui| app.frame(ui));
|
||||
out.textures_delta.clear();
|
||||
out.platform_output.accesskit_update.map(|u| u.nodes).unwrap_or_default()
|
||||
}
|
||||
|
||||
fn settle(ctx: &egui::Context, app: &mut App) -> Vec<(egui::accesskit::NodeId, Node)> {
|
||||
let mut nodes = Vec::new();
|
||||
for _ in 0..3 {
|
||||
nodes = frame(ctx, app, Vec::new());
|
||||
}
|
||||
nodes
|
||||
}
|
||||
|
||||
fn button(pos: Pos2, pressed: bool) -> Event {
|
||||
Event::PointerButton { pos, button: PointerButton::Primary, pressed, modifiers: Modifiers::NONE }
|
||||
}
|
||||
|
||||
fn drag(ctx: &egui::Context, app: &mut App, from: Pos2, to: Pos2) {
|
||||
frame(ctx, app, vec![Event::PointerMoved(from)]);
|
||||
frame(ctx, app, vec![button(from, true)]);
|
||||
for i in 1..=10 {
|
||||
frame(ctx, app, vec![Event::PointerMoved(from + (to - from) * (i as f32 / 10.0))]);
|
||||
}
|
||||
frame(ctx, app, vec![button(to, false)]);
|
||||
settle(ctx, app);
|
||||
}
|
||||
|
||||
fn layer(app: &App, name: &str) -> LayerId {
|
||||
app.s.timeline().layers.iter().find(|l| l.name == name).map(|l| l.id).expect("the layer")
|
||||
}
|
||||
|
||||
fn parent(app: &App, name: &str) -> Option<String> {
|
||||
let tl = app.s.timeline();
|
||||
tl.layer(layer(app, name)).and_then(|l| l.rig_parent).and_then(|p| tl.layer(p)).map(|l| l.name.clone())
|
||||
}
|
||||
|
||||
fn dot(app: &App, name: &str) -> Pos2 {
|
||||
let id = layer(app, name);
|
||||
app.tl_parent_dots.iter().find(|d| d.layer == id).map(|d| d.at).expect("its dot shows")
|
||||
}
|
||||
|
||||
/// A point on the layer's name.
|
||||
fn on_row(app: &App, name: &str) -> Pos2 {
|
||||
let geo = app.drop.timeline.as_ref().expect("the timeline is drawn");
|
||||
let id = layer(app, name);
|
||||
let r = geo.rows.iter().find(|(_, l)| *l == id).map(|(r, _)| *r).expect("its row shows");
|
||||
pos2(r.left() + 60.0, r.center().y)
|
||||
}
|
||||
|
||||
/// Where the layer's object shows on stage at the playhead.
|
||||
fn shown(app: &App, name: &str) -> anicraft_engine::geom::Affine {
|
||||
let id = layer(app, name);
|
||||
app.s.display_list().items.iter().find(|i| i.layer == id).map(|i| i.transform).expect("it shows")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_dot_dragged_to_another_layer_parents_it_in_one_undo_step() {
|
||||
let (mut app, ctx) = opened();
|
||||
assert_eq!(app.tl_parent_dots.len(), 3, "every layer with artwork has a dot");
|
||||
let before = shown(&app, "Forearm");
|
||||
let steps = app.s.info()["history"]["undo"].as_u64().unwrap_or(0);
|
||||
let (from, to) = (dot(&app, "Forearm"), on_row(&app, "Upper arm"));
|
||||
drag(&ctx, &mut app, from, to);
|
||||
assert_eq!(parent(&app, "Forearm").as_deref(), Some("Upper arm"));
|
||||
assert_eq!(app.s.info()["history"]["undo"].as_u64().unwrap_or(0), steps + 1, "one step");
|
||||
// It stays where it was on stage.
|
||||
let after = shown(&app, "Forearm");
|
||||
assert!(before.m.iter().zip(after.m).all(|(a, b)| (a - b).abs() < 1e-2), "{before:?} → {after:?}");
|
||||
// A chain: the hand onto the forearm; its dot moves one lane in.
|
||||
let (from, to) = (dot(&app, "Hand"), on_row(&app, "Forearm"));
|
||||
drag(&ctx, &mut app, from, to);
|
||||
assert_eq!(parent(&app, "Hand").as_deref(), Some("Forearm"));
|
||||
assert!(dot(&app, "Hand").x > dot(&app, "Forearm").x && dot(&app, "Forearm").x > dot(&app, "Upper arm").x, "the tree steps in with each link");
|
||||
assert!(app.tl_parent_drag.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_drop_on_a_follower_or_on_nothing_changes_nothing() {
|
||||
let (mut app, ctx) = opened();
|
||||
let (from, to) = (dot(&app, "Forearm"), on_row(&app, "Upper arm"));
|
||||
drag(&ctx, &mut app, from, to);
|
||||
let doc = app.s.doc.clone();
|
||||
// The upper arm can't follow the forearm that follows it: refused, and said so.
|
||||
let (from, to) = (dot(&app, "Upper arm"), on_row(&app, "Forearm"));
|
||||
drag(&ctx, &mut app, from, to);
|
||||
assert_eq!(app.s.doc, doc);
|
||||
assert!(app.status.as_ref().is_some_and(|s| s.error && s.text.contains("follows")), "{:?}", app.status.as_ref().map(|s| s.text.clone()));
|
||||
// Released away from the layers, or back on itself: nothing.
|
||||
let from = dot(&app, "Hand");
|
||||
drag(&ctx, &mut app, from, pos2(900.0, 300.0));
|
||||
let (from, to) = (dot(&app, "Hand"), on_row(&app, "Hand"));
|
||||
drag(&ctx, &mut app, from, to);
|
||||
assert_eq!(app.s.doc, doc);
|
||||
assert!(app.tl_parent_drag.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_view_closes_and_the_column_goes() {
|
||||
let (mut app, ctx) = opened();
|
||||
crate::parenting::toggle_view(&mut app);
|
||||
settle(&ctx, &mut app);
|
||||
assert!(!app.prefs.timeline_parenting && app.tl_parent_dots.is_empty());
|
||||
}
|
||||
|
||||
fn named<'a>(nodes: &'a [(egui::accesskit::NodeId, Node)], label: &str) -> Option<&'a (egui::accesskit::NodeId, Node)> {
|
||||
nodes.iter().find(|(_, n)| n.label().is_some_and(|l| l.trim() == label))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_dot_is_a_named_button_and_its_menu_picks_the_parent_without_a_pointer() {
|
||||
let (mut app, ctx) = opened();
|
||||
let nodes = settle(&ctx, &mut app);
|
||||
let toggle = named(&nodes, "Parenting view").expect("the view's toggle is named");
|
||||
assert_eq!(toggle.1.role(), Role::CheckBox);
|
||||
for l in ["Hand", "Forearm", "Upper arm"] {
|
||||
let n = named(&nodes, &format!("Parent of {l}: none")).unwrap_or_else(|| panic!("no dot named for {l}"));
|
||||
assert_eq!(n.1.role(), Role::Button);
|
||||
assert!(n.1.supports_action(Action::Focus) && n.1.supports_action(Action::Click), "{l}: reachable and pressable by keyboard");
|
||||
}
|
||||
// Pressing the hand's dot opens its menu; choosing the forearm there parents it.
|
||||
let request = |id, action| Event::AccessKitActionRequest(ActionRequest { action, target_tree: TreeId::ROOT, target_node: id, data: None });
|
||||
let hand = named(&nodes, "Parent of Hand: none").map(|n| n.0).expect("the dot");
|
||||
frame(&ctx, &mut app, vec![request(hand, Action::Click)]);
|
||||
let nodes = settle(&ctx, &mut app);
|
||||
assert!(named(&nodes, "✔ No Parent").is_some(), "the menu is open, No Parent ticked");
|
||||
let pick = named(&nodes, "Forearm").map(|n| n.0).expect("the forearm is offered");
|
||||
frame(&ctx, &mut app, vec![request(pick, Action::Click)]);
|
||||
let nodes = settle(&ctx, &mut app);
|
||||
assert_eq!(parent(&app, "Hand").as_deref(), Some("Forearm"));
|
||||
assert!(named(&nodes, "Parent of Hand: Forearm").is_some(), "the dot says what it follows");
|
||||
}
|
||||
@@ -132,6 +132,8 @@ pub struct Prefs {
|
||||
/// How wide the timeline's layer column is, in points: the line between the layers and
|
||||
/// the frames drags (#384). A narrow dock still takes what it needs for the frames.
|
||||
pub timeline_layer_w: f32,
|
||||
/// The timeline's parenting view (ADR 0113): the layer list shows each layer's parent.
|
||||
pub timeline_parenting: bool,
|
||||
/// Keyboard shortcuts the user changed: action id → its full list of keys (empty =
|
||||
/// unbound). Actions not listed keep their defaults (`keymap`).
|
||||
pub shortcuts: std::collections::BTreeMap<String, Vec<String>>,
|
||||
@@ -242,6 +244,7 @@ impl Default for Prefs {
|
||||
timeline_start_gap: 0.0,
|
||||
timeline_short_rows: false,
|
||||
timeline_layer_w: LAYER_W_DEFAULT,
|
||||
timeline_parenting: false,
|
||||
shortcuts: Default::default(),
|
||||
autosave: true,
|
||||
autosave_secs: 60,
|
||||
|
||||
+42
-4
@@ -474,7 +474,9 @@ pub fn show(app: &mut App, ui: &mut egui::Ui) {
|
||||
// In a narrow dock (ADR 0087) the layer column gives up width to keep a strip of frames;
|
||||
// the layers' toggles stay whole and their names are cut short.
|
||||
// Its width is the user's (the line between the layers and the frames drags, #384).
|
||||
let layer_w = app.tl_layer_w_drag.unwrap_or(app.prefs.timeline_layer_w).min(body.width() - MIN_FRAMES_W).max(MIN_LAYER_W);
|
||||
// The parenting view's column (ADR 0113) is added to it while open, so names keep their room.
|
||||
let parent_w = if app.prefs.timeline_parenting { crate::parenting::Column::width(app.s.timeline()) } else { 0.0 };
|
||||
let layer_w = (app.tl_layer_w_drag.unwrap_or(app.prefs.timeline_layer_w) + parent_w).min(body.width() - MIN_FRAMES_W).max(MIN_LAYER_W);
|
||||
let grid = Rect::from_min_max(pos2(body.left() + layer_w, body.top()), body.right_bottom());
|
||||
let frames_total = app.s.frame_count();
|
||||
app.tl_cell_w = app.tl_cell_w.clamp(*CELL_RANGE.start(), *CELL_RANGE.end());
|
||||
@@ -578,7 +580,12 @@ pub fn show(app: &mut App, ui: &mut egui::Ui) {
|
||||
let ruler = Rect::from_min_max(grid.left_top(), pos2(grid.right(), grid.top() + RULER_H));
|
||||
painter.rect_filled(ruler, 0.0, T.panel_alt);
|
||||
painter.rect_filled(Rect::from_min_max(body.left_top(), pos2(grid.left(), ruler.bottom())), 0.0, T.panel_alt);
|
||||
painter.text(pos2(body.left() + 10.0, ruler.center().y), Align2::LEFT_CENTER, tr!("Layers"), font(Type::Heading), color(Type::Heading));
|
||||
let heading = painter.text(pos2(body.left() + 10.0, ruler.center().y), Align2::LEFT_CENTER, tr!("Layers"), font(Type::Heading), color(Type::Heading));
|
||||
// The parenting view's toggle sits beside the heading, as in Animate (ADR 0113).
|
||||
{
|
||||
let side = TOGGLE.min(RULER_H);
|
||||
crate::parenting::head_toggle(app, ui, &painter, Rect::from_center_size(pos2(heading.right() + 8.0 + side * 0.5, ruler.center().y), vec2(side, side)));
|
||||
}
|
||||
// The eye, the padlock and the square above the columns they head show, lock or outline
|
||||
// every layer at once, as in Animate (#422). Each shows its other face once every layer
|
||||
// is that way, and the next click brings them all back.
|
||||
@@ -678,6 +685,15 @@ pub fn show(app: &mut App, ui: &mut egui::Ui) {
|
||||
let rows_top = ruler.bottom();
|
||||
let rows_bottom = body.bottom() - FOOTER_H;
|
||||
let tl_now = app.s.timeline().clone();
|
||||
// The parenting view (ADR 0113): a column of dots left of the toggles, the same place on
|
||||
// every row (a row has at most six toggles).
|
||||
let parent_col = app.prefs.timeline_parenting.then(|| {
|
||||
// Left of the leftmost toggle any row of this timeline has: eye, lock, outline and onion,
|
||||
// a speaker when a layer has sounds, the camera's attach toggle when there is a camera.
|
||||
let most = 3.0 + f32::from(u8::from(tl_now.layers.iter().any(|l| l.has_sounds()))) + f32::from(u8::from(tl_now.camera_layer().is_some() && app.s.editing.is_empty()));
|
||||
crate::parenting::Column::new(&tl_now, grid.left() - 16.0 - most * (TOGGLE + 2.0) - TOGGLE * 0.5 - 4.0)
|
||||
});
|
||||
let mut parent_dots: Vec<crate::parenting::Dot> = Vec::new();
|
||||
let mut next_y = rows_top;
|
||||
// Where each row is, for files dropped on a layer's frame (ADR 0065).
|
||||
let mut drop_rows = Vec::new();
|
||||
@@ -788,7 +804,17 @@ pub fn show(app: &mut App, ui: &mut egui::Ui) {
|
||||
} else {
|
||||
painter.rect_filled(sw, 0.0, to_color32(layer.color));
|
||||
}
|
||||
let name_rect = Rect::from_min_max(left.left_top(), pos2(attach_t.or(speaker).or(onion_t).unwrap_or(eye).left() - 4.0, left.bottom()));
|
||||
let name_end = match parent_col {
|
||||
Some(col) => col.left - 2.0,
|
||||
None => attach_t.or(speaker).or(onion_t).unwrap_or(eye).left() - 4.0,
|
||||
};
|
||||
let name_rect = Rect::from_min_max(left.left_top(), pos2(name_end.max(left.left() + 8.0), left.bottom()));
|
||||
if let Some(col) = parent_col {
|
||||
// The name gives way to the column: what is under it is painted over.
|
||||
let until = attach_t.or(speaker).or(onion_t).unwrap_or(eye).left() - 1.0;
|
||||
painter.rect_filled(Rect::from_min_max(pos2(col.left - 2.0, left.top()), pos2(until.max(col.right), left.bottom())), 0.0, if is_active { T.accent_dim } else if r % 2 == 0 { T.panel } else { T.panel_alt });
|
||||
parent_dots.extend(crate::parenting::row(app, ui, &tl_now, layer, col, left.center().y, tg));
|
||||
}
|
||||
// The name is the row's handle too: drag it to move the layer (#407). The camera stays
|
||||
// on top.
|
||||
let nr = ui.interact(name_rect, ui.id().with(("lname", layer.id.0)), if layer.kind == LayerKind::Camera { Sense::click() } else { Sense::click_and_drag() });
|
||||
@@ -968,6 +994,10 @@ pub fn show(app: &mut App, ui: &mut egui::Ui) {
|
||||
crate::layer_props::open(app, Some(layer.id));
|
||||
ui.close();
|
||||
}
|
||||
// Layer parenting (ADR 0113): the layer follows the object on its parent layer.
|
||||
if layer.can_follow() {
|
||||
ui.menu_button(tr!("Parent"), |ui| crate::parenting::menu(app, ui, layer.id));
|
||||
}
|
||||
ui.separator();
|
||||
// Layer type, as check items: Mask (masks the layer below) and Masked.
|
||||
if menus::check_item(ui, tr!("Mask"), layer.kind == LayerKind::Mask, !is_folder) {
|
||||
@@ -1412,6 +1442,14 @@ pub fn show(app: &mut App, ui: &mut egui::Ui) {
|
||||
});
|
||||
painter.line_segment([row.left_bottom(), row.right_bottom()], Stroke::new(1.0, T.separator));
|
||||
}
|
||||
// The parenting view's tree, and a dot being dragged to its new parent (ADR 0113).
|
||||
if parent_col.is_some() {
|
||||
let list = Rect::from_min_max(pos2(body.left(), rows_top), pos2(grid.left(), rows_bottom));
|
||||
crate::parenting::finish(app, ui, &painter, &tl_now, &parent_dots, &drop_rows, list);
|
||||
} else {
|
||||
app.tl_parent_drag = None;
|
||||
}
|
||||
app.tl_parent_dots = parent_dots;
|
||||
// A layer dragged by its name (#407): a line shows where it will land, a folder lights up
|
||||
// when it goes inside. Released there it moves in one undo step; Esc, or a release away
|
||||
// from the layers, leaves it where it was.
|
||||
@@ -1501,7 +1539,7 @@ pub fn show(app: &mut App, ui: &mut egui::Ui) {
|
||||
if sr.dragged()
|
||||
&& let Some(p) = sr.interact_pointer_pos()
|
||||
{
|
||||
app.tl_layer_w_drag = Some((p.x - body.left()).clamp(*range.start(), *range.end()));
|
||||
app.tl_layer_w_drag = Some((p.x - body.left() - parent_w).clamp(*range.start(), *range.end()));
|
||||
}
|
||||
let set = if sr.double_clicked() {
|
||||
app.tl_layer_w_drag = None;
|
||||
|
||||
Reference in new issue
Block a user