Merge branch 'worktree-agent-a798505697e9a8db3'

# Conflicts:
#	crates/engine/src/commands/mod.rs
#	crates/engine/src/lib.rs
#	crates/ui-egui/src/lib.rs
This commit is contained in:
Brandon Thomas
2026-10-02 09:23:25 -04:00
41 changed files with 4390 additions and 252 deletions
+7 -2
View File
@@ -22,6 +22,10 @@ pub struct DialogState {
pub palette_sel: usize,
/// Settings dialog page id (`general`, `appearance`…).
pub settings_page: String,
/// Settings when the dialog opened (Cancel restores them).
pub prefs_snapshot: Option<effectcraft_engine::prefs::Prefs>,
/// Keyboard Shortcuts editor.
pub shortcuts: super::shortcut_editor::EditorState,
/// The open parameter form.
pub form: super::forms::Form,
/// Message box (title, body).
@@ -101,8 +105,9 @@ 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::Settings => super::settings::show(app, ctx, &t),
Dialog::Shortcuts => super::shortcut_editor::show(app, ctx, &t),
Dialog::Recovery => super::settings::recovery(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),
+2 -143
View File
@@ -1,7 +1,7 @@
//! 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
//! Settings, placeholders…), View Options and simple message boxes (Settings: `settings`;
//! Keyboard Shortcuts: `shortcut_editor`). 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};
@@ -359,147 +359,6 @@ pub fn show_info(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
}
}
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| {
+6 -2
View File
@@ -83,8 +83,12 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
ly += 18.0;
}
}
let ms = app.frames.last_ms.lock().map(|v| *v).unwrap_or(0.0);
p.text(pos2(x0, ly), Align2::LEFT_CENTER, format!("Render: {ms:.0} ms • UI {:.0} fps", app.fps), Tokens::ui(11.5), t.text_faint);
// Settings ▸ Composition ▸ Show Rendering Progress in Info Panel.
if app.session.prefs.composition.show_rendering_progress {
let ms = app.frames.last_ms.lock().map(|v| *v).unwrap_or(0.0);
let rq = app.session.render_job.as_ref().map(|_| " • Rendering queue…").unwrap_or("");
p.text(pos2(x0, ly), Align2::LEFT_CENTER, format!("Render: {ms:.0} ms • UI {:.0} fps{rq}", app.fps), Tokens::ui(11.5), t.text_faint);
}
if !app.session.state.selected_keys.is_empty() {
p.text(
pos2(x0, ly + 18.0),
+2
View File
@@ -17,6 +17,8 @@ pub mod project;
pub mod properties;
pub mod puppet_tool;
pub mod render_queue;
pub mod settings;
pub mod shortcut_editor;
pub mod text_panels;
pub mod timeline;
pub mod tracker;
+1 -1
View File
@@ -217,7 +217,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
Tokens::ui(12.0),
if selected { Color32::WHITE } else { t.text },
);
lp.rect_filled(Rect::from_center_size(pos2(r.min.x + name_w + 14.0, r.center().y), vec2(10.0, 10.0)), 2.0, Tokens::label(it.label));
lp.rect_filled(Rect::from_center_size(pos2(r.min.x + name_w + 14.0, r.center().y), vec2(10.0, 10.0)), 2.0, t.label(it.label));
lp.text(pos2(col_type, r.center().y), Align2::LEFT_CENTER, it.type_name(), Tokens::ui(11.5), t.text_dim);
if let Some(b) = file_size(&it) {
lp.text(pos2(col_size, r.center().y), Align2::LEFT_CENTER, fmt_size(b), Tokens::ui(11.5), t.text_dim);
+1 -1
View File
@@ -313,7 +313,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
}
app.auto.add(&aid("render"), cb, if it.render { "Render: on" } else { "Render: off" });
let comp_item = app.session.project.item(it.comp);
let label_col = comp_item.map(|i| Tokens::label(i.label)).unwrap_or(t.text_faint);
let label_col = comp_item.map(|i| t.label(i.label)).unwrap_or(t.text_faint);
lp.rect_filled(Rect::from_center_size(pos2(cx_label + 6.0, row.center().y), vec2(10.0, 10.0)), 2.0, label_col);
lp.text(pos2(cx_num + 2.0, row.center().y), Align2::LEFT_CENTER, n.to_string(), Tokens::ui(12.0), t.text_dim);
let name = comp_item.map(|i| i.name.clone()).unwrap_or_else(|| "(missing composition)".into());
+411
View File
@@ -0,0 +1,411 @@
//! The Settings dialog (After Effects' Preferences): the page list on the left, the page on the
//! right, OK / Cancel / Previous / Next. Pages are built from the engine's schema
//! (`effectcraft_engine::prefs::pages`), so the dialog, `prefs.pages` and the docs agree. Edits
//! apply live; Cancel restores the settings from when the dialog opened, OK saves them.
//!
//! Automation ids: `settings.page.<id>`, `settings.<key>` (e.g. `settings.general.undoLevels`),
//! `settings.labels.<n>.name` / `.color`, `settings.button.<label>`, `settings.ok`,
//! `settings.cancel`, `settings.previous`, `settings.next`.
use effectcraft_engine::prefs::{Item, Kind, Page, pages};
use egui::{Color32, RichText, vec2};
use serde_json::{Value, json};
use crate::theme::Tokens;
use crate::{Dialog, EffectcraftApp};
/// Open the dialog on a page, remembering the settings for Cancel.
pub fn open(app: &mut EffectcraftApp, page: &str) {
if app.dialog != Some(Dialog::Settings) {
app.dialog_state.prefs_snapshot = Some(app.session.prefs.clone());
}
app.dialog_state.settings_page = page.to_string();
app.dialog = Some(Dialog::Settings);
}
enum Act {
Set(String, Value),
Run(String, Value),
PickFolder(String),
PickProject(String),
}
fn hex(c: [u8; 3]) -> String {
format!("#{:02x}{:02x}{:02x}", c[0], c[1], c[2])
}
fn reg(app: &mut EffectcraftApp, id: &str, r: &egui::Response, label: &str) {
app.auto.add(id, r.rect, label);
}
/// One page's rows.
fn page_ui(app: &mut EffectcraftApp, ui: &mut egui::Ui, page: &Page, cur: &Value, t: &Tokens, acts: &mut Vec<Act>) {
let get = |key: &str| cur.pointer(&format!("/{}", key.replace('.', "/"))).cloned().unwrap_or(Value::Null);
let label_w = 250.0;
for item in &page.items {
match *item {
Item::Section(title) => {
ui.add_space(6.0);
ui.label(RichText::new(title).font(Tokens::semibold(12.5)).color(t.tab_text_active));
ui.separator();
}
Item::Note(text) => {
ui.label(RichText::new(text).color(t.text_dim));
}
Item::Button { label, command, params } => {
let r = ui.button(label);
reg(app, &format!("settings.button.{}", label.trim_end_matches('.')), &r, label);
if r.clicked() {
acts.push(Act::Run(command.into(), serde_json::from_str(params).unwrap_or(json!({}))));
}
}
Item::Labels => labels_ui(app, ui, cur, acts),
Item::AudioDevices { key } => {
let devices: Vec<String> = app.hooks.audio_devices.as_ref().map(|f| f()).unwrap_or_default();
let sel = get(key).as_str().unwrap_or("").to_string();
ui.horizontal(|ui| {
ui.add_sized(vec2(label_w, 18.0), egui::Label::new("Default Output:"));
let shown = if sel.is_empty() { "System Default".to_string() } else { sel.clone() };
let r = egui::ComboBox::from_id_salt(("settings", key)).selected_text(shown).width(260.0).show_ui(ui, |ui| {
if ui.selectable_label(sel.is_empty(), "System Default").clicked() {
acts.push(Act::Set(key.into(), json!("")));
}
for d in &devices {
if ui.selectable_label(*d == sel, d).clicked() {
acts.push(Act::Set(key.into(), json!(d)));
}
}
});
reg(app, &format!("settings.{key}"), &r.response, "Default Output");
});
if devices.is_empty() {
ui.label(RichText::new("No device list from this host; the system default output is used.").color(t.text_dim));
}
}
Item::Setting { key, label, kind, live } => {
let v = get(key);
let id = format!("settings.{key}");
let tip = (!live).then_some("Stored, but not used by EffectCraft yet");
let mut resp: Option<egui::Response> = None;
match kind {
Kind::Bool => {
let mut b = v.as_bool().unwrap_or(false);
let r = ui.checkbox(&mut b, label);
if r.changed() {
acts.push(Act::Set(key.into(), json!(b)));
}
resp = Some(r);
}
_ => {
ui.horizontal(|ui| {
ui.add_sized(vec2(label_w, 18.0), egui::Label::new(format!("{label}:")).truncate());
let r = match kind {
Kind::Int(lo, hi, unit) => {
let mut x = v.as_i64().unwrap_or(0);
let r = ui.add(egui::DragValue::new(&mut x).range(lo..=hi).speed(0.25));
if !unit.is_empty() {
ui.label(RichText::new(unit).color(t.text_dim));
}
if r.changed() {
acts.push(Act::Set(key.into(), json!(x)));
}
r
}
Kind::Float(lo, hi, unit) => {
let mut x = v.as_f64().unwrap_or(0.0);
let r = ui.add(egui::DragValue::new(&mut x).range(lo..=hi).speed(0.1).max_decimals(3));
if !unit.is_empty() {
ui.label(RichText::new(unit).color(t.text_dim));
}
if r.changed() {
acts.push(Act::Set(key.into(), json!(x)));
}
r
}
Kind::Slider(lo, hi) => {
let mut x = v.as_f64().unwrap_or(0.0);
ui.label(RichText::new("Darker").color(t.text_dim));
let r = ui.add(egui::Slider::new(&mut x, lo..=hi).show_value(false));
ui.label(RichText::new("Lighter").color(t.text_dim));
if ui.small_button("Default").clicked() {
acts.push(Act::Set(key.into(), json!(0.0)));
}
if r.changed() {
acts.push(Act::Set(key.into(), json!(x)));
}
r
}
Kind::Choice(opts) => {
let curv = v.as_str().unwrap_or("").to_string();
let shown = opts.iter().find(|o| o.1 == curv).map(|o| o.0).unwrap_or(curv.as_str()).to_string();
egui::ComboBox::from_id_salt(("settings", key))
.selected_text(shown)
.width(220.0)
.show_ui(ui, |ui| {
for (l, val) in opts {
if ui.selectable_label(*val == curv, *l).clicked() {
acts.push(Act::Set(key.into(), json!(val)));
}
}
})
.response
}
Kind::Text | Kind::Path => {
let mut s = v.as_str().unwrap_or("").to_string();
let r = ui.add(egui::TextEdit::singleline(&mut s).desired_width(if kind == Kind::Path { 230.0 } else { 260.0 }));
if r.changed() {
acts.push(Act::Set(key.into(), json!(s)));
}
if kind == Kind::Path {
let b = ui.button("Choose...");
reg(app, &format!("{id}.choose"), &b, "Choose...");
if b.clicked() {
acts.push(if key.ends_with("Path") { Act::PickProject(key.into()) } else { Act::PickFolder(key.into()) });
}
}
r
}
Kind::Color => {
let c = crate::panels::viewer::hex_rgb(v.as_str().unwrap_or("")).unwrap_or([128, 128, 128]);
let mut rgb = c;
let r = ui.color_edit_button_srgb(&mut rgb);
ui.label(RichText::new(hex(rgb)).monospace().color(t.text_dim));
if rgb != c {
acts.push(Act::Set(key.into(), json!(hex(rgb))));
}
r
}
Kind::Bool => unreachable!(),
};
resp = Some(r);
});
}
}
if let Some(r) = resp {
let r = match tip {
Some(tip) => r.on_hover_text(tip),
None => r,
};
reg(app, &id, &r, label);
}
}
}
}
}
fn labels_ui(app: &mut EffectcraftApp, ui: &mut egui::Ui, cur: &Value, acts: &mut Vec<Act>) {
ui.label("Label Colors and Names:");
ui.add_space(4.0);
let labels = cur.get("labels").and_then(Value::as_array).cloned().unwrap_or_default();
egui::Grid::new("settings-labels").num_columns(4).spacing([10.0, 4.0]).show(ui, |ui| {
for (i, l) in labels.iter().enumerate() {
let c = crate::panels::viewer::hex_rgb(l["color"].as_str().unwrap_or("")).unwrap_or([128, 128, 128]);
let mut rgb = c;
let r = ui.color_edit_button_srgb(&mut rgb);
app.auto.add(&format!("settings.labels.{i}.color"), r.rect, "label colour");
if rgb != c {
acts.push(Act::Set(format!("labels.{i}.color"), json!(hex(rgb))));
}
let mut name = l["name"].as_str().unwrap_or("").to_string();
let r = ui.add_sized(vec2(160.0, 20.0), egui::TextEdit::singleline(&mut name));
app.auto.add(&format!("settings.labels.{i}.name"), r.rect, "label name");
if r.changed() {
acts.push(Act::Set(format!("labels.{i}.name"), json!(name)));
}
if i % 2 == 1 {
ui.end_row();
}
}
});
ui.add_space(8.0);
let r = ui.button("Reset Labels");
app.auto.add("settings.button.Reset Labels", r.rect, "Reset Labels");
if r.clicked() {
acts.push(Act::Run("prefs.reset".into(), json!({"page": "labels"})));
}
}
pub fn show(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
let all = pages();
let mut page = app.dialog_state.settings_page.clone();
if !all.iter().any(|p| p.id == page) {
page = "general".into();
}
let idx = all.iter().position(|p| p.id == page).unwrap_or(0);
let cur = serde_json::to_value(&app.session.prefs).unwrap_or_default();
let mut acts: Vec<Act> = vec![];
let (mut ok, mut cancel) = (false, false);
super::dialogs::modal(ctx, "Settings", vec2(820.0, 600.0), t, |ui| {
let body_h = 470.0;
ui.allocate_ui_with_layout(vec2(ui.available_width(), body_h), egui::Layout::left_to_right(egui::Align::Min), |ui| {
ui.set_height(body_h);
// Page list (left, like After Effects).
ui.vertical(|ui| {
ui.set_width(180.0);
for p in &all {
let (r, resp) = ui.allocate_exact_size(vec2(176.0, 24.0), egui::Sense::click());
let sel = page == p.id;
if sel {
ui.painter().rect_filled(r, 3.0, t.accent);
} else if resp.hovered() {
ui.painter().rect_filled(r, 3.0, t.hover);
}
ui.painter().text(
r.left_center() + vec2(10.0, 0.0),
egui::Align2::LEFT_CENTER,
p.title,
Tokens::ui(12.5),
if sel { Color32::WHITE } else { t.text },
);
app.auto.add(&format!("settings.page.{}", p.id), r, p.title);
if resp.clicked() {
page = p.id.to_string();
}
}
});
ui.separator();
ui.vertical(|ui| {
ui.set_width(590.0);
let p = &all[idx];
ui.label(RichText::new(p.title).font(Tokens::semibold(14.0)).color(t.tab_text_active));
ui.add_space(6.0);
egui::ScrollArea::vertical().max_height(body_h - 30.0).auto_shrink([false, false]).show(ui, |ui| {
page_ui(app, ui, p, &cur, t, &mut acts);
});
});
});
ui.add_space(8.0);
ui.separator();
ui.horizontal(|ui| {
let r = ui.add_enabled(idx > 0, egui::Button::new("Previous"));
app.auto.add("settings.previous", r.rect, "Previous");
if r.clicked() {
page = all[idx - 1].id.to_string();
}
let r = ui.add_enabled(idx + 1 < all.len(), egui::Button::new("Next"));
app.auto.add("settings.next", r.rect, "Next");
if r.clicked() {
page = all[idx + 1].id.to_string();
}
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
let r = ui.add(egui::Button::new(RichText::new(" OK ").color(Color32::WHITE)).fill(t.accent));
app.auto.add("settings.ok", r.rect, "OK");
ok |= r.clicked();
let r = ui.button("Cancel");
app.auto.add("settings.cancel", r.rect, "Cancel");
cancel |= r.clicked();
});
});
});
app.dialog_state.settings_page = page;
for a in acts {
match a {
Act::Set(k, v) => {
if let Err(e) = app.session.prefs.set(&k, v) {
app.ui.status = e;
}
app.session.prefs_changed();
}
Act::Run(cmd, params) => {
if let Err(e) = crate::menus::invoke(app, ctx, &cmd, params) {
app.ui.status = e;
}
// Buttons such as Reset Settings change the baseline Cancel returns to.
if cmd.starts_with("prefs.") {
app.dialog_state.prefs_snapshot = Some(app.session.prefs.clone());
}
if app.dialog != Some(Dialog::Settings) && app.dialog != Some(Dialog::Info) {
app.dialog = Some(Dialog::Settings);
}
}
Act::PickFolder(k) => {
if let Some(f) = app.hooks.pick_folder.as_ref().and_then(|f| f()) {
let _ = app.session.prefs.set(&k, json!(f));
app.session.prefs_changed();
}
}
Act::PickProject(k) => {
if let Some(f) = app.hooks.pick_open_project.as_ref().and_then(|f| f()) {
let _ = app.session.prefs.set(&k, json!(f));
app.session.prefs_changed();
}
}
}
}
if cancel {
if let Some(p) = app.dialog_state.prefs_snapshot.take() {
app.session.prefs = p;
app.session.prefs_changed();
}
app.dialog = None;
} else if ok {
app.dialog_state.prefs_snapshot = None;
app.session.save_prefs();
app.dialog = None;
}
}
/// Crash recovery: the previous session didn't exit cleanly; offer its latest auto-save.
pub fn recovery(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
let Some(r) = app.recovery.clone() else {
app.dialog = None;
return;
};
let mut choice: Option<&str> = None;
super::dialogs::modal(ctx, "Recover Project", vec2(560.0, 230.0), t, |ui| {
ui.label("EffectCraft didn't quit normally last time.");
ui.add_space(6.0);
if let Some(p) = &r.project {
ui.label(format!("Project: {p}"));
}
if let Some(a) = &r.autosave {
let when = std::fs::metadata(a).and_then(|m| m.modified()).ok().and_then(|m| m.elapsed().ok()).map(|d| {
let m = d.as_secs() / 60;
if m < 1 {
"less than a minute ago".to_string()
} else if m < 120 {
format!("{m} minutes ago")
} else {
format!("{} hours ago", m / 60)
}
});
ui.label(format!("Latest auto-save: {a}"));
if let Some(w) = when {
ui.label(RichText::new(format!("Saved {w}")).color(t.text_dim));
}
}
ui.add_space(14.0);
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
let b = ui.add(egui::Button::new(RichText::new(" Open Auto-Save ").color(Color32::WHITE)).fill(t.accent));
app.auto.add("recovery.openAutoSave", b.rect, "Open Auto-Save");
if b.clicked() {
choice = Some("autosave");
}
if r.project.is_some() {
let b = ui.button("Open Last Saved Project");
app.auto.add("recovery.openProject", b.rect, "Open Last Saved Project");
if b.clicked() {
choice = Some("project");
}
}
let b = ui.button("Don't Recover");
app.auto.add("recovery.dismiss", b.rect, "Don't Recover");
if b.clicked() {
choice = Some("none");
}
});
});
let Some(c) = choice else { return };
app.dialog = None;
app.recovery = None;
let path = match c {
"autosave" => r.autosave,
"project" => r.project,
_ => None,
};
if let Some(p) = path
&& let Err(e) = crate::menus::invoke(app, ctx, "file.open", json!({"path": p}))
{
app.ui.status = e;
}
}
@@ -0,0 +1,590 @@
//! Edit ▸ Keyboard Shortcuts: After Effects' visual shortcut editor.
//!
//! Top: the preset menu (EffectCraft Default = After Effects' defaults, read-only; custom presets
//! can be duplicated, renamed, deleted, imported and exported) and the search field. Middle: an
//! on-screen keyboard for the toggled (or held) modifiers, keys coloured by what they run in
//! that combination: purple for application-wide commands, green for panel-specific ones, both
//! when a key has each. Clicking a key lists everything bound to it. Bottom: every bindable
//! command with its shortcuts; select one, then record keys (press them in the shortcut field)
//! or assign the key selected on the keyboard. Conflicts are shown before assigning.
//!
//! All changes go through the `shortcuts.*` engine commands, so agents can do the same.
//! Automation ids: `shortcuts.preset`, `shortcuts.search`, `shortcuts.mod.<ctrl|cmd|alt|shift>`,
//! `shortcuts.key.<Key>`, `shortcuts.row.<n>`, `shortcuts.record`, `shortcuts.assign`,
//! `shortcuts.removeKey.<n>`, `shortcuts.resetCommand`, `shortcuts.duplicate`,
//! `shortcuts.rename`, `shortcuts.delete`, `shortcuts.import`, `shortcuts.export`,
//! `shortcuts.resetPreset`, `shortcuts.close`.
use effectcraft_engine::shortcuts::{APP_SCOPE, Bindable, DEFAULT_PRESET, normalize};
use egui::{Align2, Color32, Rect, RichText, Sense, Stroke, StrokeKind, pos2, vec2};
use serde_json::{Value, json};
use crate::theme::Tokens;
use crate::{Dialog, EffectcraftApp};
/// Editor state (in `DialogState`).
#[derive(Clone, Debug, Default)]
pub struct EditorState {
pub query: String,
/// Binding key of the selected command.
pub selected: Option<String>,
/// Keyboard key selected on the on-screen keyboard (shortcut key name).
pub key: Option<String>,
/// Modifier toggles: Ctrl, Cmd, Alt, Shift.
pub mods: [bool; 4],
/// Recording a shortcut from the keyboard.
pub recording: bool,
/// Recorded (or typed) shortcut waiting to be assigned.
pub pending: String,
/// Rename field for the active preset.
pub rename: Option<String>,
}
const APP_COLOR: Color32 = Color32::from_rgb(0x8e, 0x6c, 0xe8);
const PANEL_COLOR: Color32 = Color32::from_rgb(0x3f, 0xa8, 0x6c);
pub fn open(app: &mut EffectcraftApp) {
app.dialog_state.shortcuts = EditorState::default();
app.dialog = Some(Dialog::Shortcuts);
}
/// `true` while the editor records keys (the dispatcher must not close the dialog on Escape).
pub fn recording(app: &EffectcraftApp) -> bool {
app.dialog == Some(Dialog::Shortcuts) && app.dialog_state.shortcuts.recording
}
/// Shortcut text of a key event (`Cmd+Shift+K`).
pub fn combo_text(m: egui::Modifiers, k: egui::Key) -> Option<String> {
use egui::Key::*;
let key = match k {
Semicolon => ";",
Quote => "'",
Comma => ",",
Period => ".",
Slash => "/",
Backslash => "\\",
Equals => "=",
Minus => "-",
Backtick => "`",
OpenBracket => "[",
CloseBracket => "]",
Plus => "+",
Colon => ";",
_ => k.name(),
};
let mut s = String::new();
if cfg!(target_os = "macos") {
if m.ctrl {
s.push_str("Ctrl+");
}
if m.mac_cmd || m.command {
s.push_str("Cmd+");
}
} else if m.ctrl || m.command {
s.push_str("Cmd+");
}
if m.alt {
s.push_str("Alt+");
}
if m.shift {
s.push_str("Shift+");
}
if key == "+" {
// `Cmd++` names the plus key.
return normalize(&format!("{s}+"));
}
s.push_str(key);
normalize(&s)
}
/// Split normalized shortcut text into (ctrl, cmd, alt, shift) and the key.
fn split(sc: &str) -> ([bool; 4], String) {
let (head, key) = match sc.strip_suffix("++") {
Some(h) => (h.to_string(), "+".to_string()),
None if sc == "+" => (String::new(), "+".into()),
None => match sc.rsplit_once('+') {
Some((h, k)) => (h.to_string(), k.to_string()),
None => (String::new(), sc.to_string()),
},
};
let has = |m: &str| head.split('+').any(|p| p == m);
([has("Ctrl"), has("Cmd"), has("Alt"), has("Shift")], key)
}
fn mods_text(m: [bool; 4]) -> String {
let mut s = String::new();
for (on, n) in m.iter().zip(["Ctrl+", "Cmd+", "Alt+", "Shift+"]) {
if *on {
s.push_str(n);
}
}
s
}
/// The on-screen keyboard: rows of (label, key name, width in key units).
fn keyboard_rows() -> Vec<Vec<(&'static str, &'static str, f32)>> {
let mut rows: Vec<Vec<(&str, &str, f32)>> = vec![];
rows.push(vec![
("Esc", "Escape", 1.0),
("", "", 0.5),
("F1", "F1", 1.0),
("F2", "F2", 1.0),
("F3", "F3", 1.0),
("F4", "F4", 1.0),
("", "", 0.3),
("F5", "F5", 1.0),
("F6", "F6", 1.0),
("F7", "F7", 1.0),
("F8", "F8", 1.0),
("", "", 0.3),
("F9", "F9", 1.0),
("F10", "F10", 1.0),
("F11", "F11", 1.0),
("F12", "F12", 1.0),
]);
let mut r: Vec<(&str, &str, f32)> = vec![("`", "`", 1.0)];
for d in ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"] {
r.push((d, d, 1.0));
}
r.extend([("-", "-", 1.0), ("=", "=", 1.0), ("Delete", "Backspace", 1.6)]);
rows.push(r);
let mut r: Vec<(&str, &str, f32)> = vec![("Tab", "Tab", 1.5)];
for c in ["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"] {
r.push((c, c, 1.0));
}
r.extend([("[", "[", 1.0), ("]", "]", 1.0), ("\\", "\\", 1.1)]);
rows.push(r);
let mut r: Vec<(&str, &str, f32)> = vec![("Caps", "", 1.8)];
for c in ["A", "S", "D", "F", "G", "H", "J", "K", "L"] {
r.push((c, c, 1.0));
}
r.extend([(";", ";", 1.0), ("'", "'", 1.0), ("Return", "Enter", 1.8)]);
rows.push(r);
let mut r: Vec<(&str, &str, f32)> = vec![("Shift", "#shift", 2.3)];
for c in ["Z", "X", "C", "V", "B", "N", "M"] {
r.push((c, c, 1.0));
}
r.extend([(",", ",", 1.0), (".", ".", 1.0), ("/", "/", 1.0), ("Shift", "#shift", 2.3)]);
rows.push(r);
let (cmd, alt) = if cfg!(target_os = "macos") { ("⌘ Cmd", "⌥ Opt") } else { ("Ctrl", "Alt") };
rows.push(vec![
("Ctrl", if cfg!(target_os = "macos") { "#ctrl" } else { "#cmd" }, 1.4),
(alt, "#alt", 1.4),
(cmd, "#cmd", 1.6),
("Space", "Space", 6.0),
(cmd, "#cmd", 1.6),
(alt, "#alt", 1.4),
]);
rows
}
/// Navigation and numeric keypad block: (label, key name, column, row).
const SIDE_KEYS: &[(&str, &str, f32, f32)] = &[
("Home", "Home", 0.0, 1.0),
("PgUp", "PageUp", 1.0, 1.0),
("Del", "Delete", 0.0, 2.0),
("End", "End", 1.0, 2.0),
("PgDn", "PageDown", 2.0, 2.0),
("↑", "ArrowUp", 1.0, 4.0),
("←", "ArrowLeft", 0.0, 5.0),
("↓", "ArrowDown", 1.0, 5.0),
("→", "ArrowRight", 2.0, 5.0),
];
pub fn show(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
let mut st = std::mem::take(&mut app.dialog_state.shortcuts);
let mut run: Vec<(String, Value)> = vec![];
let mut close = false;
// Record keys while the shortcut field listens.
if st.recording {
let got = ctx.input(|i| {
i.events.iter().find_map(|e| match e {
egui::Event::Key { key, pressed: true, modifiers, .. } => Some((*key, *modifiers)),
_ => None,
})
});
if let Some((k, m)) = got {
st.recording = false;
if k != egui::Key::Escape
&& let Some(txt) = combo_text(m, k)
{
st.pending = txt;
}
}
}
// Modifiers: toggles, or the ones held on the keyboard.
let held = ctx.input(|i| i.modifiers);
let held = [held.ctrl && cfg!(target_os = "macos"), held.command, held.alt, held.shift];
let mods = if held.iter().any(|m| *m) && !st.recording { held } else { st.mods };
let table = app.session.shortcuts().clone();
let presets = app.session.keymaps.names();
let active = app.session.keymaps.active.clone();
// key name → (app?, panel?) for the current modifiers.
let mut keymap: std::collections::HashMap<String, (bool, bool)> = Default::default();
for (sc, b) in table.bindings() {
let (m, k) = split(sc);
if m == mods {
let e = keymap.entry(k).or_default();
if b.scope == APP_SCOPE {
e.0 = true;
} else {
e.1 = true;
}
}
}
super::dialogs::modal(ctx, "Keyboard Shortcuts", vec2(1000.0, 720.0), t, |ui| {
// ---- preset bar
ui.horizontal(|ui| {
ui.label("Preset:");
let r = egui::ComboBox::from_id_salt("sc-preset").selected_text(&active).width(220.0).show_ui(ui, |ui| {
for n in &presets {
if ui.selectable_label(*n == active, n).clicked() {
run.push(("shortcuts.preset".into(), json!({"op": "select", "name": n})));
}
}
});
app.auto.add("shortcuts.preset", r.response.rect, "Preset");
let custom = active != DEFAULT_PRESET;
let b = ui.button("Duplicate");
app.auto.add("shortcuts.duplicate", b.rect, "Duplicate");
if b.clicked() {
run.push(("shortcuts.preset".into(), json!({"op": "duplicate", "from": active, "name": format!("{active} copy")})));
}
if let Some(name) = &mut st.rename {
let r = ui.add(egui::TextEdit::singleline(name).desired_width(140.0));
app.auto.add("shortcuts.renameField", r.rect, "New name");
if ui.button("Rename").clicked() || (r.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter))) {
run.push(("shortcuts.preset".into(), json!({"op": "rename", "name": active, "newName": name})));
st.rename = None;
}
} else {
let b = ui.add_enabled(custom, egui::Button::new("Rename"));
app.auto.add("shortcuts.rename", b.rect, "Rename");
if b.clicked() {
st.rename = Some(active.clone());
}
}
let b = ui.add_enabled(custom, egui::Button::new("Delete"));
app.auto.add("shortcuts.delete", b.rect, "Delete");
if b.clicked() {
run.push(("shortcuts.preset".into(), json!({"op": "delete", "name": active})));
}
let b = ui.add_enabled(custom, egui::Button::new("Reset Preset"));
app.auto.add("shortcuts.resetPreset", b.rect, "Reset Preset");
if b.clicked() {
run.push(("shortcuts.reset".into(), json!({})));
}
let b = ui.button("Import...");
app.auto.add("shortcuts.import", b.rect, "Import");
if b.clicked()
&& let Some(p) = app.hooks.pick_files.as_ref().and_then(|f| f(&["json"]).into_iter().next())
{
run.push(("shortcuts.import".into(), json!({"path": p})));
}
let b = ui.button("Export...");
app.auto.add("shortcuts.export", b.rect, "Export");
if b.clicked()
&& let Some(p) = app.hooks.pick_save_file.as_ref().and_then(|f| f(&format!("{active}.json"), "json"))
{
run.push(("shortcuts.export".into(), json!({"preset": active, "path": p})));
}
});
ui.add_space(6.0);
// ---- modifiers + legend
ui.horizontal(|ui| {
ui.label("Modifiers:");
let names = if cfg!(target_os = "macos") { ["⌃ Ctrl", "⌘ Cmd", "⌥ Opt", "⇧ Shift"] } else { ["", "Ctrl", "Alt", "Shift"] };
for (i, (n, id)) in names.iter().zip(["ctrl", "cmd", "alt", "shift"]).enumerate() {
if n.is_empty() {
continue;
}
let r = ui.add(egui::Button::selectable(mods[i], *n));
app.auto.add(&format!("shortcuts.mod.{id}"), r.rect, n);
if r.clicked() {
st.mods[i] = !st.mods[i];
}
}
ui.add_space(20.0);
for (c, l) in [(APP_COLOR, "Application-wide"), (PANEL_COLOR, "Panel-specific")] {
let (r, _) = ui.allocate_exact_size(vec2(14.0, 14.0), Sense::hover());
ui.painter().rect_filled(r, 2.0, c);
ui.label(RichText::new(l).color(t.text_dim));
}
});
ui.add_space(6.0);
// ---- keyboard
let unit = 40.0;
let gap = 3.0;
let (area, _) = ui.allocate_exact_size(vec2(ui.available_width(), unit * 6.0 + gap * 6.0 + 4.0), Sense::hover());
let p = ui.painter_at(area);
let draw_key = |app: &mut EffectcraftApp, r: Rect, label: &str, name: &str, st: &mut EditorState| {
let mod_idx = match name {
"#ctrl" => Some(0),
"#cmd" => Some(1),
"#alt" => Some(2),
"#shift" => Some(3),
_ => None,
};
let (a, pn) = keymap.get(name).copied().unwrap_or((false, false));
let fill = match mod_idx {
Some(i) if mods[i] => t.accent,
_ => t.field_bg,
};
p.rect_filled(r, 4.0, fill);
if a && pn {
let half = Rect::from_min_max(r.min, pos2(r.center().x, r.max.y));
p.rect_filled(half, 4.0, APP_COLOR);
p.rect_filled(Rect::from_min_max(pos2(r.center().x, r.min.y), r.max), 4.0, PANEL_COLOR);
} else if a {
p.rect_filled(r, 4.0, APP_COLOR);
} else if pn {
p.rect_filled(r, 4.0, PANEL_COLOR);
}
let sel = st.key.as_deref() == Some(name) && !name.is_empty();
p.rect_stroke(r, 4.0, Stroke::new(if sel { 2.0 } else { 1.0 }, if sel { Color32::WHITE } else { t.field_border }), StrokeKind::Inside);
p.text(
r.left_top() + vec2(5.0, 4.0),
Align2::LEFT_TOP,
label,
Tokens::ui(11.0),
if a || pn || mod_idx.is_some_and(|i| mods[i]) { Color32::WHITE } else { t.text },
);
if name.is_empty() {
return;
}
let id = format!("shortcuts.key.{}", name.trim_start_matches('#'));
app.auto.add(&id, r, label);
let resp = ui.interact(r, egui::Id::new(("sc-key", name, r.min.x as i32)), Sense::click());
if resp.clicked() {
if let Some(i) = mod_idx {
st.mods[i] = !st.mods[i];
} else {
st.key = Some(name.to_string());
st.pending = format!("{}{}", mods_text(mods), name);
}
}
if !name.starts_with('#') {
let who: Vec<String> =
table.bindings().into_iter().filter(|(sc, _)| split(sc) == (mods, name.to_string())).map(|(_, b)| b.label.clone()).collect();
if !who.is_empty() {
resp.on_hover_text(who.join("\n"));
}
}
};
let mut y = area.min.y + 2.0;
for row in keyboard_rows() {
let mut x = area.min.x + 2.0;
for (label, name, w) in row {
let r = Rect::from_min_size(pos2(x, y), vec2(unit * w - gap, unit - gap));
if !(label.is_empty() && name.is_empty()) {
draw_key(app, r, label, name, &mut st);
}
x += unit * w;
}
y += unit + gap;
}
let side_x = area.min.x + unit * 16.0;
for (label, name, c, r) in SIDE_KEYS {
let rect = Rect::from_min_size(pos2(side_x + c * unit, area.min.y + 2.0 + r * (unit + gap)), vec2(unit - gap, unit - gap));
draw_key(app, rect, label, name, &mut st);
}
// Key details: everything bound to the selected key.
let info_x = side_x + unit * 3.5;
let info = Rect::from_min_max(pos2(info_x, area.min.y + 2.0), pos2(area.max.x - 2.0, area.max.y - 2.0));
p.rect_filled(info, 4.0, t.row);
let p = ui.painter_at(info.shrink(2.0));
if let Some(k) = &st.key {
p.text(info.left_top() + vec2(8.0, 6.0), Align2::LEFT_TOP, format!("Key: {k}"), Tokens::semibold(12.0), t.tab_text_active);
let mut yy = info.min.y + 26.0;
let mut list: Vec<(String, String, String)> =
table.bindings().into_iter().filter(|(sc, _)| split(sc).1 == *k).map(|(sc, b)| (sc.to_string(), b.label.clone(), b.scope.clone())).collect();
list.sort();
if list.is_empty() {
p.text(pos2(info.min.x + 8.0, yy), Align2::LEFT_TOP, "Not assigned", Tokens::ui(11.5), t.text_dim);
}
for (sc, label, scope) in list.into_iter().take(9) {
let col = if scope == APP_SCOPE { APP_COLOR } else { PANEL_COLOR };
p.text(pos2(info.min.x + 8.0, yy), Align2::LEFT_TOP, crate::menus::shortcut_text(&sc), Tokens::ui(11.5), col);
p.text(pos2(info.min.x + 78.0, yy), Align2::LEFT_TOP, label, Tokens::ui(11.5), t.text);
yy += 17.0;
}
} else {
p.text(info.left_top() + vec2(8.0, 6.0), Align2::LEFT_TOP, "Click a key to see its commands.", Tokens::ui(11.5), t.text_dim);
}
ui.add_space(4.0);
// ---- search + command list + editor
ui.horizontal(|ui| {
let r = ui.add(egui::TextEdit::singleline(&mut st.query).hint_text("Search commands or shortcuts").desired_width(360.0));
app.auto.add("shortcuts.search", r.rect, "Search");
});
ui.add_space(4.0);
let q = st.query.to_lowercase();
let rows: Vec<&Bindable> = table
.bindables
.iter()
.filter(|b| {
if q.is_empty() {
return true;
}
let keys = table.keys.get(&b.key).map(|k| k.join(" ")).unwrap_or_default();
let hay = format!("{} {} {} {}", b.label, b.command, b.path.join(" "), keys).to_lowercase();
q.split_whitespace().all(|w| hay.contains(w))
})
.collect();
ui.allocate_ui_with_layout(vec2(ui.available_width(), 270.0), egui::Layout::left_to_right(egui::Align::Min), |ui| {
ui.set_height(270.0);
// Command list.
ui.vertical(|ui| {
ui.set_width(620.0);
let row_h = 20.0;
egui::ScrollArea::vertical().id_salt("sc-rows").max_height(230.0).auto_shrink([false, false]).show_rows(ui, row_h, rows.len(), |ui, range| {
for i in range {
let b = rows[i];
let keys = table.keys.get(&b.key).cloned().unwrap_or_default();
let (r, resp) = ui.allocate_exact_size(vec2(ui.available_width(), row_h), Sense::click());
let sel = st.selected.as_deref() == Some(b.key.as_str());
if sel {
ui.painter().rect_filled(r, 0.0, t.row_selected);
} else if i % 2 == 1 {
ui.painter().rect_filled(r, 0.0, t.row_alt);
}
let pp = ui.painter();
pp.text(pos2(r.min.x + 6.0, r.center().y), Align2::LEFT_CENTER, &b.label, Tokens::ui(11.5), t.text);
pp.text(pos2(r.min.x + 230.0, r.center().y), Align2::LEFT_CENTER, b.path.join(" > "), Tokens::ui(10.5), t.text_faint);
let ks: Vec<String> = keys.iter().map(|k| crate::menus::shortcut_text(k)).collect();
let col = if b.scope == APP_SCOPE { APP_COLOR } else { PANEL_COLOR };
pp.text(
pos2(r.max.x - 8.0, r.center().y),
Align2::RIGHT_CENTER,
ks.join(", "),
Tokens::ui(11.5),
if keys.is_empty() { t.text_faint } else { col },
);
app.auto.add(&format!("shortcuts.row.{i}"), r, &b.label);
if resp.clicked() {
st.selected = Some(b.key.clone());
st.pending.clear();
}
}
});
ui.label(RichText::new(format!("{} of {} commands", rows.len(), table.bindables.len())).color(t.text_faint));
});
ui.separator();
// Selected command editor.
ui.vertical(|ui| {
ui.set_width(310.0);
let Some(b) = st.selected.as_ref().and_then(|k| table.find(k)).cloned() else {
ui.label(RichText::new("Select a command to change its shortcut.").color(t.text_dim));
return;
};
ui.label(RichText::new(&b.label).font(Tokens::semibold(13.0)).color(t.tab_text_active));
ui.label(RichText::new(format!("{} • {}", b.command, b.scope)).color(t.text_faint));
ui.add_space(6.0);
let keys = table.keys.get(&b.key).cloned().unwrap_or_default();
if keys.is_empty() {
ui.label(RichText::new("No shortcut").color(t.text_dim));
}
for (n, k) in keys.iter().enumerate() {
ui.horizontal(|ui| {
ui.label(RichText::new(crate::menus::shortcut_text(k)).monospace());
let r = ui.small_button("Remove");
app.auto.add(&format!("shortcuts.removeKey.{n}"), r.rect, "Remove");
if r.clicked() {
let rest: Vec<&String> = keys.iter().filter(|x| *x != k).collect();
run.push(("shortcuts.set".into(), json!({"command": b.command, "params": b.params, "keys": rest})));
}
});
}
ui.add_space(6.0);
ui.horizontal(|ui| {
let hint = if st.recording { "Press keys…" } else { "Click, then press keys" };
let r = ui.add(egui::TextEdit::singleline(&mut st.pending).hint_text(hint).desired_width(170.0));
app.auto.add("shortcuts.record", r.rect, "Shortcut");
if r.gained_focus() || (r.clicked() && !st.recording) {
st.recording = true;
}
if r.lost_focus() {
st.recording = false;
}
let norm = normalize(&st.pending);
let b2 = ui.add_enabled(norm.is_some(), egui::Button::new("Assign"));
app.auto.add("shortcuts.assign", b2.rect, "Assign");
if b2.clicked()
&& let Some(k) = norm
{
let mut all = keys.clone();
if !all.contains(&k) {
all.push(k);
}
run.push(("shortcuts.set".into(), json!({"command": b.command, "params": b.params, "keys": all})));
st.pending.clear();
}
});
if let Some(k) = normalize(&st.pending) {
let conflicts = table.conflicts(&b, &k);
if !conflicts.is_empty() {
ui.add_space(4.0);
ui.label(RichText::new(format!("⚠ {} is used by:", crate::menus::shortcut_text(&k))).color(t.warning));
for c in conflicts.iter().take(4) {
ui.label(RichText::new(format!(" {} ({})", c.label, c.scope)).color(t.warning));
}
}
}
ui.add_space(6.0);
let r = ui.add_enabled(keys != b.defaults, egui::Button::new("Reset to Default"));
app.auto.add("shortcuts.resetCommand", r.rect, "Reset to Default");
if r.clicked() {
run.push(("shortcuts.reset".into(), json!({"command": b.command, "params": b.params})));
}
if !b.defaults.is_empty() {
let d: Vec<String> = b.defaults.iter().map(|k| crate::menus::shortcut_text(k)).collect();
ui.label(RichText::new(format!("Default: {}", d.join(", "))).color(t.text_faint));
}
if active == DEFAULT_PRESET {
ui.add_space(6.0);
ui.label(RichText::new("Changing a shortcut creates a custom preset; the default stays as it is.").color(t.text_faint).small());
}
});
});
ui.add_space(6.0);
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
let r = ui.add(egui::Button::new(RichText::new(" OK ").color(Color32::WHITE)).fill(t.accent));
app.auto.add("shortcuts.close", r.rect, "OK");
close |= r.clicked();
});
});
app.dialog_state.shortcuts = st;
for (cmd, params) in run {
if let Err(e) = app.session.execute(&cmd, params) {
app.ui.status = e.to_string();
}
}
if close {
app.dialog = None;
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn combo_text_round_trips_through_the_parser() {
let cases = [
(egui::Modifiers::COMMAND | egui::Modifiers::SHIFT, egui::Key::K),
(egui::Modifiers::ALT, egui::Key::OpenBracket),
(egui::Modifiers::NONE, egui::Key::F9),
];
for (m, k) in cases {
let txt = combo_text(m, k).unwrap();
let (pm, pk) = crate::menus::parse_shortcut(&txt).unwrap();
assert_eq!(pk, k, "{txt}");
assert_eq!((pm.command, pm.alt, pm.shift), (m.command, m.alt, m.shift), "{txt}");
}
assert_eq!(split("Cmd+Shift+K"), ([false, true, false, true], "K".into()));
assert_eq!(split("Cmd++"), ([false, true, false, false], "+".into()));
assert_eq!(split("F9"), ([false; 4], "F9".into()));
}
}
+5 -4
View File
@@ -635,7 +635,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
let x = tm.x(m.time.seconds());
pr.add(egui::Shape::convex_polygon(
vec![pos2(x - 4.0, ruler.max.y - 10.0), pos2(x + 4.0, ruler.max.y - 10.0), pos2(x, ruler.max.y - 4.0)],
Tokens::label(m.label),
t.label(m.label),
Stroke::NONE,
));
}
@@ -763,11 +763,12 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
}
// Label swatch.
let lr = Rect::from_center_size(pos2(cw.label + 10.0, cy), vec2(12.0, 12.0));
lp.rect_filled(lr, 2.0, Tokens::label(layer.label));
lp.rect_filled(lr, 2.0, t.label(layer.label));
let lresp = ui.interact(lr, egui::Id::new(("label", layer.id.0)), Sense::click());
lresp.context_menu(|ui| {
for lab in effectcraft_engine::color::Label::ALL {
if ui.button(lab.name()).clicked() {
let name = if lab == effectcraft_engine::color::Label::None { lab.name().to_string() } else { app.session.prefs.label_name(lab) };
if ui.button(name).clicked() {
actions.push(("edit.label".into(), json!({"layers": [layer.id.0], "label": lab.name()})));
ui.close();
}
@@ -940,7 +941,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
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 + 3.0), pos2(x_out, r.max.y - 3.0));
let lc = Tokens::label(layer.label);
let lc = t.label(layer.label);
let fill = if is_sel { lc.gamma_multiply(0.85) } else { lc.gamma_multiply(0.55) };
gp.rect_filled(bar, 2.0, fill);
if is_sel {
+49 -13
View File
@@ -331,7 +331,9 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
// Guides.
if app.ui.viewer.safe_margins {
for (k, a) in [(0.9, 120u8), (0.8, 160)] {
let g = &app.session.prefs.grids;
let (act, title) = (1.0 - g.action_safe as f32 / 100.0, 1.0 - g.title_safe as f32 / 100.0);
for (k, a) in [(act, 120u8), (title, 160)] {
let r = Rect::from_center_size(comp_rect.center(), comp_rect.size() * k);
painter.rect_stroke(r, 0.0, Stroke::new(1.0, Color32::from_white_alpha(a)), StrokeKind::Middle);
}
@@ -340,22 +342,41 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
painter.line_segment([c - vec2(0.0, 10.0), c + vec2(0.0, 10.0)], Stroke::new(1.0, Color32::from_white_alpha(140)));
}
if app.ui.viewer.grid {
let step = 100.0 * zoom;
// Settings ▸ Grids & Guides: gridline spacing, subdivisions and colour.
let g = &app.session.prefs.grids;
let [r, gg, b] = hex_rgb(&g.grid_color).unwrap_or([120, 160, 255]);
let major = Stroke::new(1.0, Color32::from_rgba_unmultiplied(r, gg, b, 90));
let minor = Stroke::new(1.0, Color32::from_rgba_unmultiplied(r, gg, b, 35));
let step = (g.grid_spacing as f32 * zoom).max(2.0);
let sub = g.grid_subdivisions.max(1) as f32;
let sstep = step / sub;
let draw_minor = sstep >= 4.0;
let mut i = 0u32;
let mut gx = comp_rect.min.x;
while gx <= comp_rect.max.x {
painter.line_segment([pos2(gx, comp_rect.min.y), pos2(gx, comp_rect.max.y)], Stroke::new(1.0, Color32::from_rgba_unmultiplied(120, 160, 255, 50)));
gx += step;
let is_major = i.is_multiple_of(g.grid_subdivisions.max(1));
if is_major || draw_minor {
painter.line_segment([pos2(gx, comp_rect.min.y), pos2(gx, comp_rect.max.y)], if is_major { major } else { minor });
}
gx += sstep;
i += 1;
}
let mut i = 0u32;
let mut gy = comp_rect.min.y;
while gy <= comp_rect.max.y {
painter.line_segment([pos2(comp_rect.min.x, gy), pos2(comp_rect.max.x, gy)], Stroke::new(1.0, Color32::from_rgba_unmultiplied(120, 160, 255, 50)));
gy += step;
let is_major = i.is_multiple_of(g.grid_subdivisions.max(1));
if is_major || draw_minor {
painter.line_segment([pos2(comp_rect.min.x, gy), pos2(comp_rect.max.x, gy)], if is_major { major } else { minor });
}
gy += sstep;
i += 1;
}
}
// 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));
let [r, gg, b] = hex_rgb(&app.session.prefs.grids.guide_color).unwrap_or([0x3c, 0xc8, 0xf0]);
let stroke = Stroke::new(1.0, Color32::from_rgb(r, gg, b));
for g in &comp.guides {
if g.vertical {
let x = comp_rect.min.x + g.position as f32 * zoom;
@@ -384,8 +405,13 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
ui.data_mut(|d| d.remove::<(LayerId, u64)>(pen_id()));
}
if app.ui.viewer.show_layer_controls {
// Settings ▸ General ▸ Path Point and Handle Size; Appearance ▸ Use Label Color for
// Layer Handles and Paths.
let hs = app.session.prefs.general.path_point_size as f32 + 2.0;
let vs = app.session.prefs.general.path_point_size as f32 + 1.0;
let label_handles = app.session.prefs.appearance.use_label_color_for_handles;
for l in comp.layers.iter().filter(|l| selected.contains(&l.id) && l.is_active_at(time)) {
let col = Tokens::label(l.label);
let col = if label_handles { t.label(l.label) } else { t.accent };
// Motion path of animated position.
if let Some(pos) = l.transform().and_then(|tr| tr.get("position"))
&& pos.keys.len() > 1
@@ -450,10 +476,10 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
painter.circle_filled(h, 3.0, mc);
vertex_hits.push(VertexHit { layer: l.id, mask: g.uid, index: i, pos: h, tangent: Some(out), vertex: *v, l2c: m });
}
painter.rect_filled(Rect::from_center_size(s, vec2(6.0, 6.0)), 0.0, mc);
painter.rect_filled(Rect::from_center_size(s, vec2(vs, vs)), 0.0, mc);
} else {
painter.rect_filled(Rect::from_center_size(s, vec2(6.0, 6.0)), 0.0, Color32::from_black_alpha(160));
painter.rect_stroke(Rect::from_center_size(s, vec2(6.0, 6.0)), 0.0, Stroke::new(1.0, mc), StrokeKind::Inside);
painter.rect_filled(Rect::from_center_size(s, vec2(vs, vs)), 0.0, Color32::from_black_alpha(160));
painter.rect_stroke(Rect::from_center_size(s, vec2(vs, vs)), 0.0, Stroke::new(1.0, mc), StrokeKind::Inside);
}
app.auto.add(&format!("viewer.mask.{}.vertex.{i}", g.uid), Rect::from_center_size(s, vec2(8.0, 8.0)), &g.name);
vertex_hits.push(VertexHit { layer: l.id, mask: g.uid, index: i, pos: s, tangent: None, vertex: *v, l2c: m });
@@ -479,7 +505,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
painter.add(egui::Shape::closed_line(sq.clone(), Stroke::new(1.0, col)));
for i in 0..8 {
let hp = if i < 4 { sq[i] } else { sq[i - 4] + (sq[(i - 3) % 4] - sq[i - 4]) * 0.5 };
let hr = Rect::from_center_size(hp, vec2(HANDLE, HANDLE));
let hr = Rect::from_center_size(hp, vec2(hs, hs));
painter.rect_filled(hr, 0.0, col);
painter.rect_stroke(hr, 0.0, Stroke::new(1.0, Color32::from_black_alpha(120)), StrokeKind::Outside);
handle_hits.push((l.id, i, hp));
@@ -1019,7 +1045,7 @@ fn draw_rigs(app: &mut EffectcraftApp, painter: &egui::Painter, map: &ViewerMap,
};
for l in ectx.comp.layers.iter().filter(|l| (l.is_camera() || l.is_light()) && l.is_active_at(ectx.time)) {
let sel = selected.contains(&l.id);
let col = Tokens::label(l.label).gamma_multiply(if sel { 1.0 } else { 0.6 });
let col = app.tokens.label(l.label).gamma_multiply(if sel { 1.0 } else { 0.6 });
let stroke = Stroke::new(if sel { 1.5 } else { 1.0 }, col);
let (eye, fwd, down) = three_d::camera::layer_frame(ectx, l);
let poi = |l: &Layer| -> Option<Vec3> {
@@ -1372,3 +1398,13 @@ fn empty_state(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
}
app.auto.add("viewer.empty.import", b2, "New Composition From Footage");
}
/// `#rrggbb` → sRGB bytes.
pub(crate) fn hex_rgb(s: &str) -> Option<[u8; 3]> {
let h = s.trim().trim_start_matches('#');
if h.len() != 6 || !h.is_ascii() {
return None;
}
let p = |i: usize| u8::from_str_radix(&h[i..i + 2], 16).ok();
Some([p(0)?, p(2)?, p(4)?])
}