M3.4: After Effects menu-bar parity (engine menu tree, ~190 new commands, menu dialogs)

- engine::menus: the AE 2026 menu bar as an indented tree (same menus, order,
  submenus, separators, "..." labels, AE default macOS shortcuts; [mac]/[!mac]
  app menu vs Edit > Preferences / File > Exit), entries bind command params,
  check-mark state, Effect categories from the registry.
- New engine commands: Layer (quality/sampling, frame blending, switch ops,
  numeric Transform values, Center Anchor Point, Auto-Orient, mask ops on
  existing masks, layer markers + lock, track-matte menu, open/reveal source,
  expression errors), Edit (keyframe clipboard + Paste Reversed, Copy with
  (Relative) Property Links, Copy Expression Only, Lift/Extract Work Area,
  Select Label Group, Purge, Edit Original), Animation (JSON animation
  presets, Add Keyframe, Exponential Scale, Time-Reverse Keyframes, Sequence
  Layers, text selectors, Remove All Text Animators, Reveal Properties),
  File (New Folder, Close/Close Project, Save a Copy, placeholders/solids,
  New Comp from Selection, Dependencies, Run Script File, Interpret/Remember/
  Apply Interpretation, Replace/Reload Footage, Reveal in Finder),
  Composition (crop to ROI / layer bounds, Save Frame As PNG, Responsive
  Design - Time), View (guides add/clear/import/export, region of interest),
  Help docs links.
- Frontend commands (viewer, panels, workspaces, dialogs) are registered
  engine commands that emit Event::Frontend; owned-elsewhere items (3D,
  render queue, time remap, pen, tracking, layer styles) are disabled stubs.
- UI renders the engine tree (check gutter, scrolling long submenus, dynamic
  Undo/Redo labels), bindings include param'd entries, generic parameter
  forms, Settings, Keyboard Shortcuts, View Options, guides/ROI/pasteboard in
  the viewer, timeline reveal of engine-picked properties; snapshot example
  gains a `pointer` step for opening menus headlessly.
- Tests: menu order, every entry resolves, spec/tree consistency, shortcut
  uniqueness, per-family command tests with undo.
- Workspace clippy -D warnings clean (rust 1.96 lints).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Brandon Thomas
2026-10-01 22:36:31 -04:00
co-authored by Claude Opus 5.5
parent 4f47a01fed
commit b4b2950c5d
36 changed files with 5673 additions and 283 deletions
+14 -2
View File
@@ -4,9 +4,10 @@
use egui::{Align2, Color32, Rect, Sense, pos2, vec2};
use serde_json::json;
pub use super::forms::{Field, form, info, open_form};
use crate::icons::{self, Icon};
use crate::theme::Tokens;
use crate::{Dialog, EffectcraftApp, widgets};
use crate::{Dialog, EffectcraftApp};
#[derive(Clone, Debug)]
pub struct CompDraft {
@@ -34,6 +35,12 @@ pub struct DialogState {
pub solid_size: [u32; 2],
pub palette_query: String,
pub palette_sel: usize,
/// Settings dialog page id (`general`, `appearance`…).
pub settings_page: String,
/// The open parameter form.
pub form: super::forms::Form,
/// Message box (title, body).
pub info: (String, String),
}
pub fn open_new_comp(app: &mut EffectcraftApp) {
@@ -72,7 +79,7 @@ pub fn open_new_solid(app: &mut EffectcraftApp) -> Result<(), String> {
Ok(())
}
fn modal(ctx: &egui::Context, title: &str, size: egui::Vec2, t: &Tokens, body: impl FnOnce(&mut egui::Ui)) {
pub(crate) fn modal(ctx: &egui::Context, title: &str, size: egui::Vec2, t: &Tokens, body: impl FnOnce(&mut egui::Ui)) {
// Dim the app.
let screen = ctx.content_rect();
ctx.layer_painter(egui::LayerId::new(egui::Order::Middle, egui::Id::new("modal-dim"))).rect_filled(screen, 0.0, Color32::from_black_alpha(120));
@@ -95,6 +102,11 @@ pub fn show(app: &mut EffectcraftApp, ctx: &egui::Context) {
Dialog::NewComp | Dialog::CompSettings => comp_settings(app, ctx, &t, d == Dialog::CompSettings),
Dialog::SolidSettings => solid(app, ctx, &t),
Dialog::CommandPalette => palette(app, ctx, &t),
Dialog::Settings => super::forms::show_settings(app, ctx, &t),
Dialog::Shortcuts => super::forms::show_shortcuts(app, ctx, &t),
Dialog::Form => super::forms::show_form(app, ctx, &t),
Dialog::Info => super::forms::show_info(app, ctx, &t),
Dialog::ViewOptions => super::forms::show_view_options(app, ctx, &t),
}
}
+547
View File
@@ -0,0 +1,547 @@
//! Menu dialogs: a generic parameter form (numeric Transform dialogs, Mask Feather/Opacity/
//! Expansion, Auto-Orient, Go to Time, Add Guide, Sequence Layers, Interpret Footage, Project
//! Settings, placeholders…), Settings (Preferences), Keyboard Shortcuts, View Options and simple
//! message boxes. Every form runs an engine command with the collected parameters, so whatever a
//! dialog does an agent can do with one `engine.execute`.
use egui::{Color32, vec2};
use serde_json::{Map, Value, json};
use crate::theme::Tokens;
use crate::{Dialog, EffectcraftApp};
#[derive(Clone, Debug)]
pub enum FieldKind {
Number {
value: f64,
speed: f64,
},
Text(String),
Bool(bool),
/// Options as (label, value); `sel` is the chosen index.
Choice {
options: Vec<(String, Value)>,
sel: usize,
},
}
/// One form field. `key` may index into an array param (`value[1]`).
#[derive(Clone, Debug)]
pub struct Field {
pub key: String,
pub label: String,
pub kind: FieldKind,
}
impl Field {
pub fn num(key: &str, label: &str, value: f64) -> Field {
Field { key: key.into(), label: label.into(), kind: FieldKind::Number { value, speed: 1.0 } }
}
pub fn text(key: &str, label: &str, value: &str) -> Field {
Field { key: key.into(), label: label.into(), kind: FieldKind::Text(value.into()) }
}
pub fn bool(key: &str, label: &str, value: bool) -> Field {
Field { key: key.into(), label: label.into(), kind: FieldKind::Bool(value) }
}
pub fn choice(key: &str, label: &str, options: &[(&str, Value)], sel: usize) -> Field {
Field {
key: key.into(),
label: label.into(),
kind: FieldKind::Choice { options: options.iter().map(|(l, v)| (l.to_string(), v.clone())).collect(), sel },
}
}
}
#[derive(Clone, Debug, Default)]
pub struct Form {
pub title: String,
pub command: String,
pub base: Value,
pub fields: Vec<Field>,
}
impl Form {
/// The command parameters: `base` plus every field.
pub fn params(&self) -> Value {
let mut m: Map<String, Value> = self.base.as_object().cloned().unwrap_or_default();
for f in &self.fields {
let v = match &f.kind {
FieldKind::Number { value, .. } => json!(value),
FieldKind::Text(s) => json!(s),
FieldKind::Bool(b) => json!(b),
FieldKind::Choice { options, sel } => options.get(*sel).map(|o| o.1.clone()).unwrap_or(Value::Null),
};
match f.key.split_once('[') {
Some((name, idx)) => {
let i: usize = idx.trim_end_matches(']').parse().unwrap_or(0);
let arr = m.entry(name.to_string()).or_insert_with(|| json!([]));
if let Value::Array(a) = arr {
while a.len() <= i {
a.push(json!(0));
}
a[i] = v;
}
}
None => {
m.insert(f.key.clone(), v);
}
}
}
Value::Object(m)
}
}
/// Open a form dialog.
pub fn form(app: &mut EffectcraftApp, title: &str, command: &str, base: Value, fields: Vec<Field>) {
app.dialog_state.form = Form { title: title.into(), command: command.into(), base, fields };
app.dialog = Some(Dialog::Form);
}
/// Open a message box.
pub fn info(app: &mut EffectcraftApp, title: &str, body: &str) {
app.dialog_state.info = (title.into(), body.into());
app.dialog = Some(Dialog::Info);
}
fn has(p: &Value, keys: &[&str]) -> bool {
keys.iter().any(|k| p.get(*k).is_some())
}
/// If `id` is a dialog command invoked without its parameters, open its form and return true.
pub fn open_form(app: &mut EffectcraftApp, id: &str, p: &Value) -> bool {
let s = &app.session;
let comp = s.active_comp();
let layer = comp.and_then(|c| s.state.selected_layers.first().and_then(|l| c.layer(*l)));
let t = s.time();
let lt = layer.map(|l| l.layer_time(t)).unwrap_or(t);
let base = p.clone();
let (title, fields): (String, Vec<Field>) = match id {
"layer.setTransform" if !has(p, &["value"]) => {
let prop = p.get("prop").and_then(Value::as_str).unwrap_or("position");
let cur = layer.and_then(|l| l.transform()).and_then(|tr| tr.get(if prop == "anchorPoint" { "anchor" } else { prop })).map(|pr| pr.value_at(lt));
let v = cur.map(|c| c.as_vec3()).unwrap_or([0.0; 3]);
let three = layer.is_some_and(|l| l.is_3d());
let title = match prop {
"anchor" => "Anchor Point",
"position" => "Position",
"scale" => "Scale",
"orientation" => "Orientation",
"rotation" => "Rotation",
_ => "Opacity",
};
let fields = match prop {
"rotation" | "opacity" => vec![Field::num("value", if prop == "rotation" { "Degrees" } else { "Opacity (%)" }, v[0])],
"orientation" => vec![Field::num("value[0]", "X", v[0]), Field::num("value[1]", "Y", v[1]), Field::num("value[2]", "Z", v[2])],
_ if three => vec![Field::num("value[0]", "X", v[0]), Field::num("value[1]", "Y", v[1]), Field::num("value[2]", "Z", v[2])],
_ => vec![Field::num("value[0]", "X", v[0]), Field::num("value[1]", "Y", v[1])],
};
(title.into(), fields)
}
"layer.mask.set" if !has(p, &["value"]) => {
let field = p.get("field").and_then(Value::as_str).unwrap_or("feather");
let first = layer.and_then(|l| l.masks()).and_then(|m| m.groups().next()).and_then(|g| g.get(field)).map(|pr| pr.value_at(lt).as_f64());
let (title, label, d) = match field {
"feather" => ("Mask Feather", "Feather (pixels)", 0.0),
"opacity" => ("Mask Opacity", "Opacity (%)", 100.0),
_ => ("Mask Expansion", "Expansion (pixels)", 0.0),
};
(title.into(), vec![Field::num("value", label, first.unwrap_or(d))])
}
"layer.mask.shape" if !has(p, &["rect"]) => {
let (w, h) = layer.map(|l| effectcraft_engine::render::source_size(&s.project, l)).unwrap_or((100, 100));
(
"Mask Shape".into(),
vec![
Field::num("rect[0]", "Left", 0.0),
Field::num("rect[1]", "Top", 0.0),
Field::num("rect[2]", "Width", w as f64),
Field::num("rect[3]", "Height", h as f64),
Field::choice("shape", "Shape", &[("Rectangle", json!("rect")), ("Ellipse", json!("ellipse"))], 0),
],
)
}
"layer.autoOrient" if !has(p, &["mode"]) => {
let cur = layer.map(|l| l.auto_orient as usize).unwrap_or(0);
(
"Auto-Orientation".into(),
vec![Field::choice(
"mode",
"Mode",
&[
("Off", json!("off")),
("Orient Along Path", json!("alongPath")),
("Orient Towards Camera", json!("towardsCamera")),
("Orient Towards Point of Interest", json!("towardsPointOfInterest")),
],
cur.min(3),
)],
)
}
"time.set" if !has(p, &["time", "frame", "timecode"]) => {
let frame = comp.map(|c| c.frame_rate.frame_at(t)).unwrap_or(0);
("Go to Time".into(), vec![Field::num("frame", "Frame", frame as f64)])
}
"view.addGuide" if !has(p, &["position"]) => {
let (w, _) = comp.map(|c| (c.width, c.height)).unwrap_or((1920, 1080));
(
"Add Guide".into(),
vec![
Field::choice("orientation", "Orientation", &[("Vertical", json!("vertical")), ("Horizontal", json!("horizontal"))], 0),
Field::num("position", "Position (pixels)", w as f64 / 2.0),
],
)
}
"layer.sequence" if !has(p, &["overlap"]) => (
"Sequence Layers".into(),
vec![
Field::bool("overlap", "Overlap", false),
Field::num("duration", "Duration (seconds)", 1.0),
Field::choice(
"transition",
"Transition",
&[
("Off", json!("off")),
("Dissolve Front Layer", json!("dissolveFront")),
("Cross Dissolve Front and Back Layers", json!("crossDissolve")),
],
0,
),
],
),
"file.interpretFootage" if !has(p, &["frameRate", "alpha", "loop", "pixelAspect"]) => {
let f = s.state.project_selection.first().and_then(|i| s.project.item(*i)).and_then(|it| match &it.kind {
effectcraft_engine::project::ItemKind::Footage(f) => Some(f.clone()),
_ => None,
});
let Some(f) = f else { return false };
(
"Interpret Footage".into(),
vec![
Field::num("frameRate", "Frame rate", f.frame_rate.as_f64()),
Field::choice(
"alpha",
"Alpha",
&[("Straight", json!("straight")), ("Premultiplied", json!("premultiplied")), ("Ignore", json!("ignore"))],
f.alpha as usize,
),
Field::num("loop", "Loop (times)", f.loop_count as f64),
Field::num("pixelAspect", "Pixel aspect ratio", f.pixel_aspect),
],
)
}
"file.projectSettings" if p.as_object().is_none_or(|m| m.is_empty()) => {
let st = &s.project.settings;
let depth = match st.bit_depth.label() {
l if l.starts_with("16") => 1,
l if l.starts_with("32") => 2,
_ => 0,
};
(
"Project Settings".into(),
vec![
Field::choice(
"bitDepth",
"Depth",
&[("8 bits per channel", json!(8)), ("16 bits per channel", json!(16)), ("32 bits per channel (float)", json!(32))],
depth,
),
Field::choice(
"timeDisplay",
"Time display style",
&[("Timecode", json!("timecode")), ("Frames", json!("frames"))],
usize::from(matches!(st.time_display, effectcraft_engine::project::TimeDisplayStyle::Frames)),
),
Field::bool("linearize", "Linearize working space", st.linearize),
],
)
}
"layer.timeStretch" if !has(p, &["percent", "op"]) => {
("Time Stretch".into(), vec![Field::num("percent", "Stretch factor (%)", layer.map(|l| l.stretch).unwrap_or(100.0))])
}
"layer.precompose" if !has(p, &["name"]) => {
let n = s.project.comps().count() + 1;
("Pre-compose".into(), vec![Field::text("name", "New composition name", &format!("Pre-comp {n}"))])
}
"file.importPlaceholder" | "file.replaceWithPlaceholder" if p.as_object().is_none_or(|m| m.is_empty()) => (
"New Placeholder".into(),
vec![
Field::text("name", "Name", "Placeholder"),
Field::num("width", "Width", 1920.0),
Field::num("height", "Height", 1080.0),
Field::num("frameRate", "Frame rate", 29.97),
Field::num("duration", "Duration (seconds)", 30.0),
],
),
"file.importSolid" | "file.replaceWithSolid" if p.as_object().is_none_or(|m| m.is_empty()) => {
let (w, h) = comp.map(|c| (c.width, c.height)).unwrap_or((1920, 1080));
(
"Solid Settings".into(),
vec![
Field::text("name", "Name", "Solid"),
Field::text("color", "Color (#rrggbb)", "#808080"),
Field::num("width", "Width", w as f64),
Field::num("height", "Height", h as f64),
],
)
}
_ => return false,
};
form(app, &title, id, base, fields);
true
}
pub fn show_form(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
let mut f = app.dialog_state.form.clone();
let (mut ok, mut close) = (false, false);
let h = 120.0 + f.fields.len() as f32 * 30.0;
super::dialogs::modal(ctx, &f.title.clone(), vec2(440.0, h), t, |ui| {
egui::Grid::new("form-grid").num_columns(2).spacing([14.0, 10.0]).show(ui, |ui| {
for fl in &mut f.fields {
ui.label(&fl.label);
match &mut fl.kind {
FieldKind::Number { value, speed } => {
ui.add(egui::DragValue::new(value).speed(*speed).max_decimals(3));
}
FieldKind::Text(s) => {
ui.add(egui::TextEdit::singleline(s).desired_width(220.0));
}
FieldKind::Bool(b) => {
ui.checkbox(b, "");
}
FieldKind::Choice { options, sel } => {
let cur = options.get(*sel).map(|o| o.0.clone()).unwrap_or_default();
egui::ComboBox::from_id_salt(("form", fl.key.as_str())).selected_text(cur).width(240.0).show_ui(ui, |ui| {
for (i, (l, _)) in options.iter().enumerate() {
ui.selectable_value(sel, i, l);
}
});
}
}
ui.end_row();
}
});
ui.add_space(14.0);
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
if ui.add(egui::Button::new(egui::RichText::new(" OK ").color(Color32::WHITE)).fill(t.accent)).clicked() {
ok = true;
}
if ui.button("Cancel").clicked() {
close = true;
}
});
});
let enter = !ctx.egui_wants_keyboard_input() && ctx.input(|i| i.key_pressed(egui::Key::Enter));
app.dialog_state.form = f.clone();
if ok || enter {
app.dialog = None;
let params = f.params();
if let Err(e) = app.session.execute(&f.command, params) {
app.ui.status = e.to_string();
}
return;
}
if close {
app.dialog = None;
}
}
pub fn show_info(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
let (title, body) = app.dialog_state.info.clone();
let mut close = false;
super::dialogs::modal(ctx, &title, vec2(440.0, 160.0), t, |ui| {
ui.label(body);
ui.add_space(16.0);
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
if ui.add(egui::Button::new(egui::RichText::new(" OK ").color(Color32::WHITE)).fill(t.accent)).clicked() {
close = true;
}
});
});
if close {
app.dialog = None;
}
}
pub const SETTINGS_PAGES: [(&str, &str); 17] = [
("general", "General"),
("startup", "Startup & Repair"),
("project", "Project"),
("composition", "Composition"),
("previews", "Previews"),
("appearance", "Appearance"),
("grids", "Grids & Guides"),
("labels", "Labels"),
("type", "Type"),
("import", "Import"),
("export", "Export"),
("audio", "Audio"),
("disk", "Disk"),
("memory", "Memory & CPU"),
("video", "Video"),
("3d", "3D"),
("scripting", "Scripting & Expressions"),
];
pub fn show_settings(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
let mut page = app.dialog_state.settings_page.clone();
let mut close = false;
let mut theme = None;
super::dialogs::modal(ctx, "Settings", vec2(640.0, 440.0), t, |ui| {
ui.horizontal_top(|ui| {
ui.vertical(|ui| {
ui.set_width(170.0);
for (id, label) in SETTINGS_PAGES {
if ui.selectable_label(page == id, label).clicked() {
page = id.to_string();
}
}
});
ui.separator();
ui.vertical(|ui| {
let title = SETTINGS_PAGES.iter().find(|p| p.0 == page).map(|p| p.1).unwrap_or("General");
ui.label(egui::RichText::new(title).font(Tokens::semibold(13.0)));
ui.add_space(8.0);
match page.as_str() {
"general" => {
ui.checkbox(&mut app.ui.show_menu_bar, "Show the in-window menu bar");
ui.checkbox(&mut app.ui.snapping, "Snapping");
}
"appearance" => {
for (k, name) in [("dark", "Dark"), ("darker", "Darker"), ("light", "Light")] {
if ui.button(name).clicked() {
theme = crate::theme::ThemeKind::from_name(k);
}
}
}
"previews" => {
ui.checkbox(&mut app.ui.cache_when_idle, "Cache frames when idle");
ui.checkbox(&mut app.ui.viewer.fast_preview, "Fast previews");
}
"grids" => {
ui.checkbox(&mut app.ui.viewer.grid, "Show grid");
ui.checkbox(&mut app.ui.viewer.guides, "Show guides");
ui.checkbox(&mut app.ui.viewer.safe_margins, "Show title/action safe");
}
"labels" => {
for l in effectcraft_engine::color::Label::ALL.into_iter().skip(1) {
ui.horizontal(|ui| {
let [r, g, b] = l.rgb();
let (rect, _) = ui.allocate_exact_size(vec2(26.0, 14.0), egui::Sense::hover());
ui.painter().rect_filled(rect, 2.0, Color32::from_rgb(r, g, b));
ui.label(l.name());
});
}
}
_ => {
ui.label(egui::RichText::new("No options on this page yet.").color(t.text_dim));
}
}
});
});
ui.add_space(10.0);
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
if ui.add(egui::Button::new(egui::RichText::new(" OK ").color(Color32::WHITE)).fill(t.accent)).clicked() {
close = true;
}
});
});
app.dialog_state.settings_page = page;
if let Some(k) = theme {
app.set_theme(ctx, k);
}
if close {
app.dialog = None;
}
}
pub fn show_shortcuts(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
let mut q = app.dialog_state.palette_query.clone();
let mut close = false;
// (shortcut, where, label)
let mut rows: Vec<(String, String, String)> = vec![];
for (path, e) in effectcraft_engine::menus::entries() {
if let Some(sc) = &e.shortcut {
rows.push((crate::menus::shortcut_text(sc), path.join(" ▸ "), e.label.clone()));
}
}
for c in effectcraft_engine::command_specs().iter().filter(|c| c.menu.is_empty()) {
if let Some(sc) = c.shortcut
&& !rows.iter().any(|r| r.2 == c.label)
{
rows.push((crate::menus::shortcut_text(sc), "Commands".into(), c.label.to_string()));
}
}
for c in crate::menus::UI_COMMANDS {
if let Some(sc) = c.shortcut {
rows.push((crate::menus::shortcut_text(sc), "Panels & Tools".into(), c.label.to_string()));
}
}
super::dialogs::modal(ctx, "Keyboard Shortcuts", vec2(640.0, 520.0), t, |ui| {
ui.add(egui::TextEdit::singleline(&mut q).hint_text("Search commands or shortcuts").desired_width(f32::INFINITY));
ui.add_space(8.0);
let ql = q.to_lowercase();
egui::ScrollArea::vertical().max_height(400.0).show(ui, |ui| {
egui::Grid::new("shortcut-grid").num_columns(3).striped(true).spacing([18.0, 4.0]).show(ui, |ui| {
for (sc, place, label) in rows.iter().filter(|r| ql.is_empty() || format!("{} {} {}", r.0, r.1, r.2).to_lowercase().contains(&ql)) {
ui.label(egui::RichText::new(sc).monospace());
ui.label(label);
ui.label(egui::RichText::new(place).color(t.text_dim));
ui.end_row();
}
});
});
ui.add_space(8.0);
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
if ui.add(egui::Button::new(egui::RichText::new(" OK ").color(Color32::WHITE)).fill(t.accent)).clicked() {
close = true;
}
});
});
app.dialog_state.palette_query = q;
if close {
app.dialog = None;
}
}
pub fn show_view_options(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
let mut close = false;
super::dialogs::modal(ctx, "View Options", vec2(360.0, 330.0), t, |ui| {
let v = &mut app.ui.viewer;
ui.checkbox(&mut v.show_layer_controls, "Layer controls");
ui.checkbox(&mut v.show_masks, "Masks");
ui.checkbox(&mut v.rulers, "Rulers");
ui.checkbox(&mut v.guides, "Guides");
ui.checkbox(&mut v.grid, "Grid");
ui.checkbox(&mut v.safe_margins, "Title/action safe");
ui.checkbox(&mut v.transparency_grid, "Transparency grid");
ui.add_space(12.0);
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
if ui.add(egui::Button::new(egui::RichText::new(" OK ").color(Color32::WHITE)).fill(t.accent)).clicked() {
close = true;
}
});
});
if close {
app.dialog = None;
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn form_params_build_arrays_and_choices() {
let f = Form {
title: "T".into(),
command: "layer.setTransform".into(),
base: json!({"prop": "position"}),
fields: vec![
Field::num("value[0]", "X", 10.0),
Field::num("value[1]", "Y", 20.0),
Field::choice("mode", "M", &[("A", json!("a")), ("B", json!("b"))], 1),
],
};
assert_eq!(f.params(), json!({"prop": "position", "value": [10.0, 20.0], "mode": "b"}));
}
}
+1
View File
@@ -3,6 +3,7 @@
pub mod dialogs;
pub mod effect_controls;
pub mod effects_presets;
pub mod forms;
pub mod info;
pub mod misc;
pub mod project;
+2 -4
View File
@@ -167,10 +167,8 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
if resp.double_clicked() {
match &it.kind {
ItemKind::Comp(_) => actions.push(("comp.open".into(), json!({"comp": id.0}))),
ItemKind::Folder => {
if !app.ui.project_open_folders.remove(&id.0) {
app.ui.project_open_folders.insert(id.0);
}
ItemKind::Folder if !app.ui.project_open_folders.remove(&id.0) => {
app.ui.project_open_folders.insert(id.0);
}
_ => {}
}
+35 -6
View File
@@ -42,6 +42,7 @@ struct Cols {
label: f32,
num: f32,
name: f32,
#[allow(dead_code)]
name_w: f32,
switches: f32,
mode: f32,
@@ -211,6 +212,36 @@ fn build_rows(app: &EffectcraftApp, comp: &Comp) -> Vec<Row> {
}
}
}
"props" => {
// Animation ▸ Reveal Properties…: the engine picked the uids.
fn groups_in<'a>(g: &'a PropGroup, set: &std::collections::BTreeSet<u64>, out: &mut Vec<&'a PropGroup>) {
for sg in g.groups() {
if set.contains(&sg.uid) {
out.push(sg);
} else {
groups_in(sg, set, out);
}
}
}
let mut groups = vec![];
groups_in(&l.props, &tl.reveal_props, &mut groups);
for g in groups {
let open = tl.open_groups.contains(&g.uid);
rows.push(Row {
layer: l.id,
depth: 1,
kind: RowKind::Group { uid: g.uid, name: g.name.clone(), open, has_children: !g.children.is_empty(), fx: None },
});
if open {
push_group(&mut rows, l, g, 2, &tl.open_groups);
}
}
let mut found = vec![];
collect_props(&l.props, &mut found, &|p| prop_visible(p, l) && tl.reveal_props.contains(&p.uid));
for uid in found {
rows.push(Row { layer: l.id, depth: 1, kind: RowKind::Prop { uid } });
}
}
_ => {
let mut found = vec![];
let root = if group.is_empty() {
@@ -439,7 +470,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
let fd = comp.frame_duration().seconds();
let cy0 = ruler.min.y + 11.0;
let mut run: Option<(i64, i64)> = None;
let mut draw_run = |a: i64, b: i64| {
let draw_run = |a: i64, b: i64| {
let x0 = tm.x(a as f64 * fd);
let x1 = tm.x((b + 1) as f64 * fd);
p.rect_filled(Rect::from_min_max(pos2(x0, cy0), pos2(x1, cy0 + 2.5)), 0.0, t.cache_green);
@@ -785,10 +816,8 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
if lin.hovered() || lout.hovered() || lin.dragged() || lout.dragged() {
ctx.set_cursor_icon(egui::CursorIcon::ResizeHorizontal);
}
if body.clicked() || body.drag_started() {
if !is_sel {
actions.push(("layer.select".into(), json!({"layers": [layer.id.0], "add": ui.input(|i| i.modifiers.shift)})));
}
if (body.clicked() || body.drag_started()) && !is_sel {
actions.push(("layer.select".into(), json!({"layers": [layer.id.0], "add": ui.input(|i| i.modifiers.shift)})));
}
layer_context_menu(&body, layer, &mut actions);
let drag_key = format!("bar-{}", layer.id.0);
@@ -1049,7 +1078,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
actions.push(("keys.select".into(), json!({"keys": []})));
}
if let (true, Some(origin), Some(cur)) =
(empty.dragged(), empty.interact_pointer_pos().map(|_| ctx.input(|i| i.pointer.press_origin())).flatten(), empty.interact_pointer_pos())
(empty.dragged(), empty.interact_pointer_pos().and_then(|_| ctx.input(|i| i.pointer.press_origin())), empty.interact_pointer_pos())
{
let br = Rect::from_two_pos(origin, cur);
gp.rect_filled(br, 0.0, t.accent.gamma_multiply(0.12));
+69 -11
View File
@@ -55,13 +55,43 @@ pub fn last_fit(ctx: &egui::Context) -> f32 {
/// What a drag in the viewer is doing.
#[derive(Clone, Debug)]
enum Gesture {
Move { layers: Vec<(LayerId, [f64; 3], Mat3)>, start: [f64; 2] },
Scale { layer: LayerId, anchor_screen: Pos2, start_scale: [f64; 3], start_local: [f64; 2], inv: Mat3, uniform: bool },
Rotate { layer: LayerId, center: Pos2, start_angle: f64, start_rot: f64 },
Anchor { layer: LayerId, start_anchor: [f64; 3], start_pos: [f64; 3], start: [f64; 2], inv: Mat3, l2p: Mat3 },
Pan { start_pan: [f32; 2] },
Create { tool: Tool, start: [f64; 2] },
Marquee { start: Pos2 },
Move {
layers: Vec<(LayerId, [f64; 3], Mat3)>,
start: [f64; 2],
},
#[allow(dead_code)]
Scale {
layer: LayerId,
anchor_screen: Pos2,
start_scale: [f64; 3],
start_local: [f64; 2],
inv: Mat3,
uniform: bool,
},
Rotate {
layer: LayerId,
center: Pos2,
start_angle: f64,
start_rot: f64,
},
Anchor {
layer: LayerId,
start_anchor: [f64; 3],
start_pos: [f64; 3],
start: [f64; 2],
inv: Mat3,
l2p: Mat3,
},
Pan {
start_pan: [f32; 2],
},
Create {
tool: Tool,
start: [f64; 2],
},
Marquee {
start: Pos2,
},
}
const HANDLE: f32 = 7.0;
@@ -168,7 +198,8 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
let bar_h = 30.0;
let bar = Rect::from_min_max(pos2(rect.min.x, rect.max.y - bar_h), rect.max);
let area = Rect::from_min_max(pos2(rect.min.x, nav.max.y), pos2(rect.max.x, bar.min.y));
p.rect_filled(area, 0.0, t.pasteboard);
let pasteboard = app.ui.viewer.pasteboard.map(|[r, g, b]| Color32::from_rgb(r, g, b)).unwrap_or(t.pasteboard);
p.rect_filled(area, 0.0, pasteboard);
let (cw, ch) = (comp.width as f32, comp.height as f32);
let fit = ((area.width() - 40.0) / cw).min((area.height() - 40.0) / ch).max(0.01);
@@ -241,6 +272,24 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
}
}
// Comp guides (View ▸ Show Guides) and the region of interest.
if app.ui.viewer.guides {
let stroke = Stroke::new(1.0, Color32::from_rgb(0x3c, 0xc8, 0xf0));
for g in &comp.guides {
if g.vertical {
let x = comp_rect.min.x + g.position as f32 * zoom;
painter.line_segment([pos2(x, area.min.y), pos2(x, area.max.y)], stroke);
} else {
let y = comp_rect.min.y + g.position as f32 * zoom;
painter.line_segment([pos2(area.min.x, y), pos2(area.max.x, y)], stroke);
}
}
}
if let Some([rx, ry, rw, rh]) = app.session.state.region_of_interest {
let r = Rect::from_min_size(comp_rect.min + vec2(rx as f32 * zoom, ry as f32 * zoom), vec2(rw as f32 * zoom, rh as f32 * zoom));
painter.rect_stroke(r, 0.0, Stroke::new(1.0, Color32::WHITE), StrokeKind::Middle);
}
// Overlays + interaction.
let snap_project = app.session.project.clone();
let snap_expr = app.session.expr.clone();
@@ -491,14 +540,14 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
let _ = app.session.execute("prop.set", json!({"layer": lid.0, "path": "transform/position", "value": v, "merge": merge}));
}
}
Gesture::Scale { layer, start_scale, start_local, inv, uniform, .. } => {
Gesture::Scale { layer, start_scale, start_local, inv, .. } => {
let lp = inv.apply(gv2(cpt[0], cpt[1]));
// Local point relative to the anchor in *unscaled* layer space.
let a = comp.layer(layer).and_then(|l| l.transform().map(|tr| ectx.v3(l, tr, "anchor", [0.0; 3]))).unwrap_or([0.0; 3]);
let cur = [lp.x - a[0], lp.y - a[1]];
let fx = if start_local[0].abs() > 1e-6 { cur[0] / start_local[0] } else { 1.0 };
let fy = if start_local[1].abs() > 1e-6 { cur[1] / start_local[1] } else { 1.0 };
let (fx, fy) = if mods.shift || uniform && start_local[0].abs() > 1e-6 && start_local[1].abs() > 1e-6 && mods.shift {
let (fx, fy) = if mods.shift {
let f = (fx + fy) / 2.0;
(f, f)
} else {
@@ -847,7 +896,16 @@ fn bottom_bar(app: &mut EffectcraftApp, ui: &mut egui::Ui, bar: Rect, zoom: f32,
app.ui.viewer.res = Resolution::ALL[i];
}
x = r.max.x + 6.0;
if tog(ui, &mut app.auto, &mut x, Icon::Region, false, "roi", "Region of Interest") {}
let has_roi = app.session.state.region_of_interest.is_some();
if tog(ui, &mut app.auto, &mut x, Icon::Region, has_roi, "roi", "Region of Interest") {
// Toggle a centred region of interest (Composition ▸ Crop Comp to Region of Interest).
let rect = if has_roi {
serde_json::Value::Null
} else {
json!([comp.width as f64 / 4.0, comp.height as f64 / 4.0, comp.width as f64 / 2.0, comp.height as f64 / 2.0])
};
let _ = app.session.execute("view.setRegionOfInterest", json!({"rect": rect}));
}
if tog(ui, &mut app.auto, &mut x, Icon::Checker, app.ui.viewer.transparency_grid, "transparency", "Toggle Transparency Grid") {
app.ui.viewer.transparency_grid = !app.ui.viewer.transparency_grid;
}