M14.2: preferences
A real Settings model in the engine (`engine::prefs`): serde, versioned, dotted keys
(`general.undoLevels`, `labels.3.name`), migration of older layouts, unknown keys kept,
persisted through a `ConfigStore` trait (platform config dir on the desktop; MemoryConfig
for tests; the web app can back it with localStorage).
- After Effects 2026 pages (General … Scripting & Expressions) as a schema shared by the
dialog, `prefs.pages` and docs/preferences.md (rows not wired yet are listed there and
kept in step by a test).
- Commands: prefs.get, prefs.set {key, value | values}, prefs.reset {page?}, prefs.open
{page?}, prefs.pages.
- Wired settings: undo levels, path point size, tool tips, layers at comp start / CTI,
default spatial interpolation linear, Home screen on launch, new project template,
rendering progress in Info, adaptive resolution limit, cache when idle, fast previews,
theme + UI brightness, label names/colours everywhere (Label menu, timeline, project,
render queue, viewer), label colour for handles, grid colour/spacing/subdivisions, guide
colour, safe margins, still footage duration, sequence fps, audio output device and
output mapping, layer / footage / preview cache budgets, default 3D renderer.
- Settings dialog: AE's left page list + right content, OK / Cancel (restores) / Previous /
Next, every widget with an automation id.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
5273f1ba96
commit
47f7712364
@@ -38,7 +38,22 @@ pub trait AudioDevice: Send {
|
||||
}
|
||||
|
||||
/// Opens the default output device (`None` when there is none).
|
||||
pub type AudioDeviceFactory = Box<dyn Fn() -> Option<Box<dyn AudioDevice>>>;
|
||||
pub type AudioDeviceFactory = Box<dyn Fn(&AudioOutput) -> Option<Box<dyn AudioDevice>>>;
|
||||
|
||||
/// Which output to open (Settings ▸ Audio): device name (empty = the system default) and the
|
||||
/// 1-based device channels for left and right.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct AudioOutput {
|
||||
pub device: String,
|
||||
pub left: u32,
|
||||
pub right: u32,
|
||||
}
|
||||
|
||||
impl AudioOutput {
|
||||
pub fn from_prefs(p: &effectcraft_engine::prefs::Prefs) -> AudioOutput {
|
||||
AudioOutput { device: p.audio.output_device.clone(), left: p.audio.output_left, right: p.audio.output_right }
|
||||
}
|
||||
}
|
||||
|
||||
/// Lock-protected sample queue between the feeder thread and the device callback.
|
||||
#[derive(Default)]
|
||||
|
||||
@@ -129,6 +129,24 @@ impl Frames {
|
||||
v
|
||||
}
|
||||
|
||||
/// Change the RAM preview cache budget (Settings ▸ Memory & CPU), evicting the oldest
|
||||
/// frames when it shrinks.
|
||||
pub fn set_budget(&self, bytes: usize) {
|
||||
if let Ok(mut c) = self.cache.lock() {
|
||||
c.budget = bytes;
|
||||
while c.bytes > c.budget {
|
||||
let Some(old) = c.order.pop_front() else { break };
|
||||
if let Some(i) = c.map.remove(&old) {
|
||||
c.bytes -= i.pixels.len() * 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn budget(&self) -> usize {
|
||||
self.cache.lock().map(|c| c.budget).unwrap_or(0)
|
||||
}
|
||||
|
||||
pub fn clear(&self) {
|
||||
if let Ok(mut c) = self.cache.lock() {
|
||||
c.map.clear();
|
||||
|
||||
@@ -67,6 +67,10 @@ pub struct Hooks {
|
||||
pub pick_open_project: Option<Box<dyn Fn() -> Option<String>>>,
|
||||
/// Opens the audio output for preview playback (the desktop app uses cpal).
|
||||
pub audio_device: Option<audio::AudioDeviceFactory>,
|
||||
/// Lists audio output devices (Settings ▸ Audio).
|
||||
pub audio_devices: Option<Box<dyn Fn() -> Vec<String>>>,
|
||||
/// Picks a folder (Settings paths).
|
||||
pub pick_folder: Option<Box<dyn Fn() -> Option<String>>>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
@@ -122,6 +126,8 @@ pub struct EffectcraftApp {
|
||||
pub(crate) waveforms: panels::waveform::Cache,
|
||||
/// Last reveal shortcut and when (double-press shortcuts such as LL).
|
||||
pub(crate) last_reveal: Option<(String, f64)>,
|
||||
/// Settings revision applied to the theme, tooltips and caches.
|
||||
applied_prefs: Option<u64>,
|
||||
}
|
||||
|
||||
impl EffectcraftApp {
|
||||
@@ -158,18 +164,48 @@ impl EffectcraftApp {
|
||||
meter: Default::default(),
|
||||
waveforms: Default::default(),
|
||||
last_reveal: None,
|
||||
applied_prefs: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Apply changed settings: theme and brightness, label colours, tool tips, preview caches.
|
||||
pub fn apply_prefs(&mut self, ctx: &egui::Context) {
|
||||
if self.applied_prefs == Some(self.session.prefs_revision) {
|
||||
return;
|
||||
}
|
||||
self.applied_prefs = Some(self.session.prefs_revision);
|
||||
let p = &self.session.prefs;
|
||||
self.ui.theme = theme::ThemeKind::from_name(&p.appearance.theme).unwrap_or_default();
|
||||
self.tokens = Tokens::from_prefs(p);
|
||||
theme::apply_visuals(ctx, &self.tokens);
|
||||
let tips = p.general.show_tool_tips;
|
||||
ctx.all_styles_mut(|s| s.interaction.tooltip_delay = if tips { 0.5 } else { f32::INFINITY });
|
||||
self.ui.cache_when_idle = p.previews.cache_frames_when_idle;
|
||||
self.ui.viewer.fast_preview = p.previews.fast_previews;
|
||||
self.frames.set_budget(p.preview_cache_bytes());
|
||||
}
|
||||
|
||||
/// Change settings from the UI (applied next frame and saved).
|
||||
pub fn set_pref(&mut self, key: &str, value: serde_json::Value) -> Result<(), String> {
|
||||
self.session.prefs.set(key, value)?;
|
||||
self.session.prefs_changed();
|
||||
self.session.save_prefs();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn with_control(mut self, rx: Receiver<ControlRequest>) -> Self {
|
||||
self.control_rx = Some(rx);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn set_theme(&mut self, ctx: &egui::Context, k: theme::ThemeKind) {
|
||||
self.ui.theme = k;
|
||||
self.tokens = Tokens::for_kind(k);
|
||||
theme::apply_visuals(ctx, &self.tokens);
|
||||
let name = match k {
|
||||
theme::ThemeKind::Dark => "dark",
|
||||
theme::ThemeKind::Darker => "darker",
|
||||
theme::ThemeKind::Light => "light",
|
||||
};
|
||||
let _ = self.set_pref("appearance.theme", json!(name));
|
||||
self.apply_prefs(ctx);
|
||||
}
|
||||
|
||||
pub fn set_workspace(&mut self, name: &str) {
|
||||
@@ -203,8 +239,10 @@ impl EffectcraftApp {
|
||||
/// The render scale used by the viewer right now.
|
||||
pub fn viewer_scale(&self, zoom: f32, ppp: f32) -> f64 {
|
||||
if self.playback.playing && self.ui.viewer.res == state::Resolution::Auto {
|
||||
// Keep previews snappy: never more than the displayed size.
|
||||
return self.ui.viewer.res.scale(zoom, ppp).min(0.5);
|
||||
// Keep previews snappy: half the displayed size, but no lower than Settings ▸
|
||||
// Previews ▸ Adaptive Resolution Limit.
|
||||
let full = self.ui.viewer.res.scale(zoom, ppp);
|
||||
return full.min((full * 0.5).max(self.session.prefs.adaptive_limit()));
|
||||
}
|
||||
self.ui.viewer.res.scale(zoom, ppp)
|
||||
}
|
||||
@@ -285,7 +323,8 @@ impl EffectcraftApp {
|
||||
if !effectcraft_engine::render::audio::comp_has_audio(&self.session.project, cid) {
|
||||
return;
|
||||
}
|
||||
let Some(dev) = self.hooks.audio_device.as_ref().and_then(|f| f()) else { return };
|
||||
let out = audio::AudioOutput::from_prefs(&self.session.prefs);
|
||||
let Some(dev) = self.hooks.audio_device.as_ref().and_then(|f| f(&out)) else { return };
|
||||
match audio::AudioPlayback::start(dev, self.render_source(), cid, t, c.work_area.0, c.work_area.1, self.ui.preview_loop) {
|
||||
Ok(a) => self.audio = Some(a),
|
||||
Err(e) => log::warn!("audio preview: {e}"),
|
||||
@@ -536,6 +575,7 @@ impl EffectcraftApp {
|
||||
self.session.poll_render();
|
||||
ctx.request_repaint_after(std::time::Duration::from_millis(100));
|
||||
}
|
||||
self.apply_prefs(&ctx);
|
||||
self.handle_events(&ctx);
|
||||
if let Some(rx) = self.command_inbox.take() {
|
||||
while let Ok(id) = rx.try_recv() {
|
||||
|
||||
@@ -193,7 +193,11 @@ pub fn invoke(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, params: V
|
||||
}
|
||||
"view.safeMargins" => app.ui.viewer.safe_margins = !app.ui.viewer.safe_margins,
|
||||
"view.transparencyGrid" => app.ui.viewer.transparency_grid = !app.ui.viewer.transparency_grid,
|
||||
"view.fastPreviews" => app.ui.viewer.fast_preview = !app.ui.viewer.fast_preview,
|
||||
"view.fastPreviews" => {
|
||||
let on = !app.ui.viewer.fast_preview;
|
||||
app.set_pref("previews.fastPreviews", json!(on))?;
|
||||
app.ui.viewer.fast_preview = on;
|
||||
}
|
||||
"timeline.zoomIn" | "timeline.zoomOut" => {
|
||||
let k = if id == "timeline.zoomIn" { 1.5 } else { 1.0 / 1.5 };
|
||||
crate::panels::timeline::zoom(app, ctx, k);
|
||||
@@ -310,8 +314,21 @@ pub fn frontend(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, p: Valu
|
||||
Value::Null
|
||||
}
|
||||
"app.settings" => {
|
||||
app.dialog_state.settings_page = p.get("page").and_then(Value::as_str).unwrap_or("general").to_string();
|
||||
app.dialog = Some(crate::Dialog::Settings);
|
||||
let page = p.get("page").and_then(Value::as_str).unwrap_or("general");
|
||||
crate::panels::settings::open(app, effectcraft_engine::prefs::page_id(page).unwrap_or("general"));
|
||||
Value::Null
|
||||
}
|
||||
"app.gpuInfo" => {
|
||||
let threads = std::thread::available_parallelism().map(|n| n.get()).unwrap_or(1);
|
||||
crate::panels::dialogs::info(
|
||||
app,
|
||||
"GPU Information",
|
||||
&format!(
|
||||
"Compositing: CPU, {threads} threads (pure Rust, rayon).\nDisplay: egui on wgpu.\nLayer cache: {} MB • Preview cache: {} MB.",
|
||||
app.session.layer_cache.budget() >> 20,
|
||||
app.frames.budget() >> 20
|
||||
),
|
||||
);
|
||||
Value::Null
|
||||
}
|
||||
"app.hide" => {
|
||||
@@ -349,7 +366,11 @@ pub fn frontend(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, p: Valu
|
||||
app.toggle_play(now);
|
||||
json!({"playing": app.playback.playing})
|
||||
}
|
||||
"playback.cacheWhenIdle" => toggle(&mut app.ui.cache_when_idle, &p),
|
||||
"playback.cacheWhenIdle" => {
|
||||
let r = toggle(&mut app.ui.cache_when_idle, &p);
|
||||
app.set_pref("previews.cacheFramesWhenIdle", r.clone())?;
|
||||
r
|
||||
}
|
||||
"playback.audio" => {
|
||||
let r = toggle(&mut app.ui.preview_audio, &p);
|
||||
if !app.ui.preview_audio {
|
||||
@@ -559,7 +580,7 @@ fn entry_label(app: &EffectcraftApp, e: &MenuEntry) -> String {
|
||||
match e.command.as_str() {
|
||||
"edit.undo" => app.session.history.undo.last().map(|u| format!("Undo {}", u.0)).unwrap_or_else(|| "Can't Undo".into()),
|
||||
"edit.redo" => app.session.history.redo.last().map(|u| format!("Redo {}", u.0)).unwrap_or_else(|| "Can't Redo".into()),
|
||||
_ => e.label.clone(),
|
||||
_ => effectcraft_engine::menus::entry_label(&app.session, e),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -771,6 +792,13 @@ pub fn handle_shortcuts(app: &mut EffectcraftApp, ctx: &egui::Context) {
|
||||
for (key, mods) in events {
|
||||
// Escape closes dialogs.
|
||||
if key == egui::Key::Escape && app.dialog.is_some() {
|
||||
// Escape in Settings is Cancel: restore the settings from when it opened.
|
||||
if app.dialog == Some(crate::Dialog::Settings)
|
||||
&& let Some(p) = app.dialog_state.prefs_snapshot.take()
|
||||
{
|
||||
app.session.prefs = p;
|
||||
app.session.prefs_changed();
|
||||
}
|
||||
app.dialog = None;
|
||||
continue;
|
||||
}
|
||||
@@ -888,6 +916,15 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn renamed_label_shows_in_the_label_menu() {
|
||||
let mut app = EffectcraftApp::new(effectcraft_engine::Session::default());
|
||||
app.set_pref("labels.1.name", json!("Sunflower")).unwrap();
|
||||
let labels: Vec<String> = menu_items(&app).into_iter().filter(|i| i.id == "edit.label").map(|i| i.label).collect();
|
||||
assert!(labels.contains(&"Sunflower".to_string()), "{labels:?}");
|
||||
assert!(!labels.contains(&"Yellow".to_string()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn menu_items_cover_the_tree() {
|
||||
assert_eq!(menus().last(), Some(&"Help"));
|
||||
|
||||
@@ -22,6 +22,8 @@ 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>,
|
||||
/// The open parameter form.
|
||||
pub form: super::forms::Form,
|
||||
/// Message box (title, body).
|
||||
@@ -98,7 +100,7 @@ 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::Settings => super::settings::show(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),
|
||||
|
||||
@@ -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…), Keyboard Shortcuts, View Options and simple message boxes
|
||||
//! (Settings: `settings`). 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,98 +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;
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -13,6 +13,7 @@ pub mod misc;
|
||||
pub mod project;
|
||||
pub mod properties;
|
||||
pub mod render_queue;
|
||||
pub mod settings;
|
||||
pub mod text_panels;
|
||||
pub mod timeline;
|
||||
pub mod viewer;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -0,0 +1,346 @@
|
||||
//! 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;
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
@@ -936,7 +937,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 {
|
||||
|
||||
@@ -319,7 +319,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);
|
||||
}
|
||||
@@ -328,22 +330,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;
|
||||
@@ -372,8 +393,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
|
||||
@@ -438,10 +464,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 });
|
||||
@@ -467,7 +493,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));
|
||||
@@ -930,7 +956,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> {
|
||||
@@ -1283,3 +1309,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)?])
|
||||
}
|
||||
|
||||
@@ -66,6 +66,8 @@ pub struct Tokens {
|
||||
pub timecode: Color32,
|
||||
pub danger: Color32,
|
||||
pub warning: Color32,
|
||||
/// Label colours (`Label::ALL` order), from Settings ▸ Labels.
|
||||
pub labels: [Color32; 17],
|
||||
pub radius: f32,
|
||||
pub radius_sm: f32,
|
||||
pub gap: f32,
|
||||
@@ -112,6 +114,7 @@ impl Tokens {
|
||||
timecode: Color32::from_rgb(0x3d, 0x8f, 0xf5),
|
||||
danger: Color32::from_rgb(0xe0, 0x4a, 0x3c),
|
||||
warning: Color32::from_rgb(0xe8, 0x9a, 0x2c),
|
||||
labels: default_labels(),
|
||||
radius: 6.0,
|
||||
radius_sm: 3.0,
|
||||
gap: 4.0,
|
||||
@@ -172,11 +175,65 @@ impl Tokens {
|
||||
pub fn medium(size: f32) -> FontId {
|
||||
FontId::new(size, FontFamily::Name("medium".into()))
|
||||
}
|
||||
/// sRGB colour of an item/layer label.
|
||||
pub fn label(l: effectcraft_color::Label) -> Color32 {
|
||||
/// sRGB colour of an item/layer label (Settings ▸ Labels).
|
||||
pub fn label(&self, l: effectcraft_color::Label) -> Color32 {
|
||||
let i = effectcraft_color::Label::ALL.iter().position(|x| *x == l).unwrap_or(0);
|
||||
self.labels[i]
|
||||
}
|
||||
|
||||
/// Theme tokens for the current settings: theme, UI brightness and label colours.
|
||||
pub fn from_prefs(p: &effectcraft_engine::prefs::Prefs) -> Tokens {
|
||||
let kind = ThemeKind::from_name(&p.appearance.theme).unwrap_or_default();
|
||||
let mut t = Tokens::for_kind(kind).with_brightness(p.appearance.brightness as f32);
|
||||
for (i, l) in effectcraft_color::Label::ALL.iter().enumerate() {
|
||||
let [r, g, b] = p.label_rgb(*l);
|
||||
t.labels[i] = Color32::from_rgb(r, g, b);
|
||||
}
|
||||
t
|
||||
}
|
||||
|
||||
/// Lighten (b > 0) or darken (b < 0) the interface greys, like After Effects' brightness
|
||||
/// slider. Accent colours, labels and keyframe colours are kept.
|
||||
pub fn with_brightness(mut self, b: f32) -> Tokens {
|
||||
let b = b.clamp(-1.0, 1.0);
|
||||
if b.abs() < 1e-3 {
|
||||
return self;
|
||||
}
|
||||
let adj = |c: &mut Color32| {
|
||||
let f = |v: u8| -> u8 {
|
||||
let v = v as f32;
|
||||
(if b > 0.0 { v + (110.0 - v).max(0.0) * b * 0.8 + 10.0 * b } else { v * (1.0 + b * 0.6) }).round().clamp(0.0, 255.0) as u8
|
||||
};
|
||||
*c = Color32::from_rgb(f(c.r()), f(c.g()), f(c.b()));
|
||||
};
|
||||
for c in [
|
||||
&mut self.app_bg,
|
||||
&mut self.header_bg,
|
||||
&mut self.panel_bg,
|
||||
&mut self.hover,
|
||||
&mut self.pressed,
|
||||
&mut self.field_bg,
|
||||
&mut self.field_border,
|
||||
&mut self.separator,
|
||||
&mut self.row,
|
||||
&mut self.row_alt,
|
||||
&mut self.row_selected,
|
||||
&mut self.tl_bg,
|
||||
&mut self.tl_ruler_bg,
|
||||
&mut self.pasteboard,
|
||||
&mut self.work_area,
|
||||
] {
|
||||
adj(c);
|
||||
}
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
fn default_labels() -> [Color32; 17] {
|
||||
effectcraft_color::Label::ALL.map(|l| {
|
||||
let [r, g, b] = l.rgb();
|
||||
Color32::from_rgb(r, g, b)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
static INTER_REGULAR: &[u8] = include_bytes!("../../../assets/fonts/Inter-Regular.ttf");
|
||||
|
||||
Reference in New Issue
Block a user