Merge M13.14 agent-interface audit + lazy open (worktree-agent-a5f8967ebd42ce98b)
The branch's commits say M13.14; on main that id is the puppet work, so this arc is M13.21. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
//! UI-side everyday-operation timings for `effectcraft-cli bench --ops` (see
|
||||
//! `effectcraft_engine::perf` for the engine side): the app's first frame, and steady frames of
|
||||
//! the Timeline (scrolling a 5,000-layer comp) and the Project panel (300+ items), measured
|
||||
//! headless — layout, painting and tessellation, without a window or GPU upload.
|
||||
|
||||
use effectcraft_engine::Session;
|
||||
use effectcraft_engine::perf::Measure;
|
||||
|
||||
use crate::EffectcraftApp;
|
||||
use crate::dock::PanelKind;
|
||||
|
||||
/// A headless egui driver for [`EffectcraftApp`].
|
||||
pub struct Driver {
|
||||
pub ctx: egui::Context,
|
||||
pub app: EffectcraftApp,
|
||||
frame: eframe::Frame,
|
||||
time: f64,
|
||||
size: egui::Vec2,
|
||||
}
|
||||
|
||||
impl Driver {
|
||||
pub fn new(app: EffectcraftApp, size: egui::Vec2) -> Driver {
|
||||
Driver { ctx: egui::Context::default(), app, frame: eframe::Frame::_new_kittest(), time: 0.0, size }
|
||||
}
|
||||
|
||||
/// Run one frame (layout + paint + tessellation); its wall time in ms.
|
||||
pub fn step(&mut self) -> f64 {
|
||||
self.step_with(vec![])
|
||||
}
|
||||
|
||||
pub fn step_with(&mut self, events: Vec<egui::Event>) -> f64 {
|
||||
self.time += 1.0 / 60.0;
|
||||
let input =
|
||||
egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, self.size)), time: Some(self.time), events, ..Default::default() };
|
||||
let t0 = web_time::Instant::now();
|
||||
let (app, frame) = (&mut self.app, &mut self.frame);
|
||||
let mut out = self.ctx.run_ui(input, |ui| {
|
||||
eframe::App::logic(app, ui.ctx(), frame);
|
||||
eframe::App::ui(app, ui, frame);
|
||||
});
|
||||
// No GPU here: texture uploads are dropped (counted in the frame time up to here).
|
||||
out.textures_delta.clear();
|
||||
let _ = self.ctx.tessellate(out.shapes, out.pixels_per_point);
|
||||
t0.elapsed().as_secs_f64() * 1000.0
|
||||
}
|
||||
|
||||
/// Mean and max of `n` frames, calling `before` ahead of each.
|
||||
pub fn frames(&mut self, n: usize, mut before: impl FnMut(&mut EffectcraftApp, usize)) -> (f64, f64) {
|
||||
let (mut sum, mut max) = (0.0, 0.0f64);
|
||||
for i in 0..n {
|
||||
before(&mut self.app, i);
|
||||
let ms = self.step();
|
||||
sum += ms;
|
||||
max = max.max(ms);
|
||||
}
|
||||
(sum / n.max(1) as f64, max)
|
||||
}
|
||||
}
|
||||
|
||||
/// The UI timings for a session holding the large project (`perf::large_project`), opened by
|
||||
/// `open` (whose time counts as part of startup).
|
||||
pub fn ui_ops(open: impl FnOnce() -> Session) -> Vec<Measure> {
|
||||
let mut out = vec![];
|
||||
let t0 = web_time::Instant::now();
|
||||
let session = open();
|
||||
let opened = t0.elapsed().as_secs_f64() * 1000.0;
|
||||
let t1 = web_time::Instant::now();
|
||||
let app = EffectcraftApp::new(session);
|
||||
let built = t1.elapsed().as_secs_f64() * 1000.0;
|
||||
let mut d = Driver::new(app, egui::vec2(1680.0, 1020.0));
|
||||
// The first pass installs the theme and fonts; the second draws the workspace.
|
||||
let f1 = d.step();
|
||||
let f2 = d.step();
|
||||
out.push(Measure {
|
||||
name: "startupToFirstFrame",
|
||||
ms: opened + built + f1 + f2,
|
||||
note: format!("open {opened:.1} + app {built:.1} + frames {f1:.1}/{f2:.1} ms"),
|
||||
});
|
||||
let (mean, max) = d.frames(10, |_, _| {});
|
||||
out.push(Measure { name: "workspaceFrame", ms: mean, note: format!("Standard workspace, steady (max {max:.1} ms)") });
|
||||
|
||||
// Timeline maximized, scrolling through every layer of the main comp.
|
||||
let layers = d.app.session.active_comp().map_or(0, |c| c.layers.len());
|
||||
d.app.show_panel(PanelKind::Timeline);
|
||||
d.app.ui.maximized = Some(PanelKind::Timeline);
|
||||
d.step();
|
||||
let step = (layers as f32 * 20.0 / 60.0).max(40.0);
|
||||
let (mean, max) = d.frames(60, |app, i| app.ui.timeline.scroll_y = i as f32 * step);
|
||||
out.push(Measure { name: "timelineScrollFrame", ms: mean, note: format!("{layers} layers, 60 frames scrolling to the end (max {max:.1} ms)") });
|
||||
// Every 10th layer twirled open (property rows).
|
||||
let open: Vec<u64> = d.app.session.active_comp().map(|c| c.layers.iter().step_by(10).map(|l| l.id.0).collect()).unwrap_or_default();
|
||||
d.app.ui.timeline.open_layers.extend(open.iter().copied());
|
||||
let (mean, max) = d.frames(30, |app, i| app.ui.timeline.scroll_y = i as f32 * step * 2.0);
|
||||
out.push(Measure { name: "timelineOpenFrame", ms: mean, note: format!("{} layers twirled open (max {max:.1} ms)", open.len()) });
|
||||
d.app.ui.timeline.open_layers.clear();
|
||||
d.app.ui.timeline.scroll_y = 0.0;
|
||||
|
||||
// Project panel maximized with every folder open.
|
||||
let items = d.app.session.project.items.len();
|
||||
let folders: Vec<u64> = d.app.session.project.items.values().filter(|i| i.is_folder()).map(|i| i.id.0).collect();
|
||||
d.app.ui.project_open_folders.extend(folders);
|
||||
d.app.show_panel(PanelKind::Project);
|
||||
d.app.ui.maximized = Some(PanelKind::Project);
|
||||
d.step();
|
||||
let (mean, max) = d.frames(30, |app, i| app.ui.project_scroll = i as f32 * 400.0);
|
||||
out.push(Measure { name: "projectPanelFrame", ms: mean, note: format!("{items} items, folders open, scrolling (max {max:.1} ms)") });
|
||||
d.app.ui.maximized = None;
|
||||
out
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn ui_ops_runs_on_a_small_project() {
|
||||
let m = ui_ops(|| {
|
||||
let mut s = Session::default();
|
||||
s.replace_project(effectcraft_engine::perf::large_project(&effectcraft_engine::perf::LargeSpec::small()), None);
|
||||
s
|
||||
});
|
||||
let names: Vec<&str> = m.iter().map(|m| m.name).collect();
|
||||
assert_eq!(names, ["startupToFirstFrame", "workspaceFrame", "timelineScrollFrame", "timelineOpenFrame", "projectPanelFrame"]);
|
||||
assert!(m.iter().all(|m| m.ms.is_finite() && m.ms > 0.0), "{m:?}");
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
pub mod audio;
|
||||
pub mod automation;
|
||||
pub mod bench;
|
||||
pub mod control;
|
||||
pub mod dock;
|
||||
pub mod dock_ui;
|
||||
@@ -547,7 +548,7 @@ impl EffectcraftApp {
|
||||
/// Start the preview of a Preview panel shortcut (its range, play-from, rate, skip,
|
||||
/// resolution, loop, caching, full screen and include options).
|
||||
pub fn play_with(&mut self, now: f64, sc: effectcraft_engine::preview::PreviewShortcut) {
|
||||
let Some(c) = self.session.active_comp().cloned() else { return };
|
||||
let Some(c) = self.session.active_comp_arc() else { return };
|
||||
let preset = self.session.prefs.preview.get(sc).clone();
|
||||
let plan = effectcraft_engine::preview::plan(&preset, &c, self.session.time());
|
||||
let fr = c.frame_rate;
|
||||
@@ -590,7 +591,7 @@ impl EffectcraftApp {
|
||||
return;
|
||||
}
|
||||
let Some(cid) = self.session.active_comp_id() else { return };
|
||||
let Some(c) = self.session.project.comp(cid).cloned() else { return };
|
||||
let Some(c) = self.session.project.comp_arc(cid) else { return };
|
||||
// A preview at another frame rate plays slower or faster than real time: silent.
|
||||
if (pl.fps - c.frame_rate.as_f64()).abs() > 0.01 {
|
||||
return;
|
||||
@@ -687,7 +688,7 @@ impl EffectcraftApp {
|
||||
/// and keep rendering ahead (the green cache bar fills, then playback runs in real time).
|
||||
fn advance_playback(&mut self, ctx: &egui::Context, scale: f64) {
|
||||
let Some(cid) = self.session.active_comp_id() else { return };
|
||||
let Some(c) = self.session.project.comp(cid).cloned() else { return };
|
||||
let Some(c) = self.session.project.comp_arc(cid) else { return };
|
||||
let now = ctx.input(|i| i.time);
|
||||
let fr = c.frame_rate;
|
||||
let plan = self.playback.plan.filter(|_| self.playback.playing);
|
||||
|
||||
@@ -22,7 +22,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
let w = (rect.max.x - xv - 12.0).clamp(90.0, 220.0);
|
||||
let mut y = rect.min.y + 10.0;
|
||||
let st = app.session.state.content_fill.clone();
|
||||
let comp = app.session.active_comp().cloned();
|
||||
let comp = app.session.active_comp_arc();
|
||||
let layer = comp.as_ref().and_then(|c| app.session.state.selected_layers.first().and_then(|l| c.layer(*l)).cloned());
|
||||
// Fill Target.
|
||||
p.text(pos2(x0, y + 9.0), Align2::LEFT_CENTER, "Fill Target", Tokens::semibold(12.0), t.text);
|
||||
|
||||
@@ -317,7 +317,7 @@ fn prop_row(
|
||||
}
|
||||
}
|
||||
Value::Layer(l) => {
|
||||
let comp = app.session.active_comp().cloned();
|
||||
let comp = app.session.active_comp_arc();
|
||||
if let Some(comp) = comp {
|
||||
let dr = Rect::from_min_size(pos2(vx, cy - 9.0), vec2(((r.max.x - vx) * 0.55).clamp(90.0, 170.0), 18.0));
|
||||
let idx_of = |id: u64| comp.layers.iter().position(|x| x.id.0 == id);
|
||||
@@ -883,7 +883,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
return;
|
||||
};
|
||||
let Some(cid) = app.session.active_comp_id() else { return };
|
||||
let comp = app.session.project.comp(cid).cloned().unwrap_or_else(|| effectcraft_engine::project::Comp::new(1, 1, Default::default(), Default::default()));
|
||||
let comp = app.session.project.comp_arc(cid).unwrap_or_else(|| effectcraft_engine::project::Comp::new(1, 1, Default::default(), Default::default()).into());
|
||||
let comp_name = app.session.project.item(cid).map(|i| i.name.clone()).unwrap_or_default();
|
||||
let snap_project = app.session.project.clone();
|
||||
let snap_expr = app.session.expr.clone();
|
||||
|
||||
@@ -453,7 +453,7 @@ fn value_widget(app: &mut EffectcraftApp, ui: &mut egui::Ui, auto: &str, ty: Opt
|
||||
/// Revert and Push to Comp.
|
||||
fn instance(app: &mut EffectcraftApp, ui: &mut egui::Ui, actions: &mut Actions) {
|
||||
let t = app.tokens;
|
||||
let Some(comp) = app.session.active_comp().cloned() else { return };
|
||||
let Some(comp) = app.session.active_comp_arc() else { return };
|
||||
let Some(layer) = app.session.state.selected_layers.iter().filter_map(|l| comp.layer(*l)).find(|l| essential::group(l).is_some()).cloned() else { return };
|
||||
let LayerSource::Comp { item: src } = layer.source else { return };
|
||||
let Some(eg) = app.session.project.comp(src).and_then(|c| c.essential.clone()) else { return };
|
||||
|
||||
@@ -60,7 +60,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
y += 82.0;
|
||||
p.line_segment([pos2(rect.min.x + 8.0, y), pos2(rect.max.x - 8.0, y)], egui::Stroke::new(1.0, t.separator));
|
||||
y += 14.0;
|
||||
let comp = app.session.active_comp().cloned();
|
||||
let comp = app.session.active_comp_arc();
|
||||
if let Some(c) = comp {
|
||||
let sel: Vec<String> = app.session.state.selected_layers.iter().filter_map(|id| c.layer(*id)).map(|l| l.name.clone()).collect();
|
||||
let tc = crate::panels::timecode(&app.session, &c, app.session.time());
|
||||
|
||||
@@ -71,7 +71,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
app.auto.add("layerPanel.empty", rect, "Layer panel (empty)");
|
||||
return;
|
||||
};
|
||||
let comp = app.session.project.comp(cid).cloned().unwrap_or_else(|| effectcraft_engine::project::Comp::new(1, 1, Default::default(), Default::default()));
|
||||
let comp = app.session.project.comp_arc(cid).unwrap_or_else(|| effectcraft_engine::project::Comp::new(1, 1, Default::default(), Default::default()).into());
|
||||
let time = app.session.time();
|
||||
let fx_count = layer.effects().map(|f| f.groups().count()).unwrap_or(0);
|
||||
let view = app.ui.layer_view.map(|v| v.min(fx_count)).unwrap_or_else(|| default_view(&layer, app.ui.tool));
|
||||
|
||||
@@ -215,7 +215,7 @@ pub fn preview(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
}
|
||||
|
||||
// Cache bar over the preview range.
|
||||
if let Some(c) = app.session.active_comp().cloned() {
|
||||
if let Some(c) = app.session.active_comp_arc() {
|
||||
let cid = app.session.active_comp_id().map(|i| i.0).unwrap_or(0);
|
||||
let scale = app.viewer_shown.as_ref().map(|(_, k)| k.scale).unwrap_or(1000);
|
||||
let pl = match app.playback.plan.filter(|_| app.playback.playing) {
|
||||
@@ -431,7 +431,7 @@ pub fn history(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
pub fn markers(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
let t = app.tokens;
|
||||
let p = ui.painter().with_clip_rect(rect);
|
||||
let Some(c) = app.session.active_comp().cloned() else { return };
|
||||
let Some(c) = app.session.active_comp_arc() else { return };
|
||||
let mut y = rect.min.y + 8.0;
|
||||
if c.markers.is_empty() {
|
||||
p.text(rect.center(), Align2::CENTER_CENTER, "No composition markers", Tokens::ui(12.0), t.text_faint);
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
//! the label colour picker, and the bottom bar (interpret, new folder, new comp, bit depth,
|
||||
//! delete). Edits are `project.*` engine commands, so they are undoable.
|
||||
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use effectcraft_engine::project::{Item, ItemId, ItemKind};
|
||||
use egui::{Align2, Color32, Rect, Sense, Stroke, pos2, vec2};
|
||||
use serde_json::json;
|
||||
@@ -102,41 +104,69 @@ pub fn drop_folder(project: &effectcraft_engine::project::Project, row: Option<I
|
||||
if it.is_folder() { Some(it.id) } else { it.parent }
|
||||
}
|
||||
|
||||
/// A thumbnail being rendered off the UI thread: (revision, result slot).
|
||||
type PendingThumb = (u64, Arc<Mutex<Option<Option<(u32, u32, Vec<u8>)>>>>);
|
||||
|
||||
/// Thumbnail of a comp (its current time) or footage (first frame), cached per item/revision.
|
||||
/// Rendered on a background thread (inline on wasm32): until the new one lands the previous
|
||||
/// thumbnail stays up, so selecting a big comp or editing it never stalls the panel.
|
||||
fn thumbnail(app: &EffectcraftApp, ctx: &egui::Context, it: &Item) -> Option<egui::TextureHandle> {
|
||||
let key = egui::Id::new(("proj-thumb", it.id.0));
|
||||
let pkey = egui::Id::new(("proj-thumb-pending", it.id.0));
|
||||
let rev = app.session.revision;
|
||||
if let Some((r, tex)) = ctx.data(|d| d.get_temp::<(u64, egui::TextureHandle)>(key))
|
||||
&& r == rev
|
||||
{
|
||||
return Some(tex);
|
||||
}
|
||||
let (w, h, px) = match &it.kind {
|
||||
ItemKind::Comp(_) => {
|
||||
let t = app.session.state.times.get(&it.id).copied().unwrap_or_default();
|
||||
app.session.render_rgba8(it.id, t, 192).ok()?
|
||||
}
|
||||
ItemKind::Footage(f) if f.has_video => {
|
||||
let img = app.session.footage.frame(it.id, f, effectcraft_engine::time::Tick(0))?;
|
||||
// Point-sample down to at most 192 px on the long side.
|
||||
let step = (img.width.max(img.height) as f32 / 192.0).ceil().max(1.0) as u32;
|
||||
let (w, h) = (img.width.div_ceil(step), img.height.div_ceil(step));
|
||||
let full = img.to_rgba8();
|
||||
let mut px = Vec::with_capacity((w * h * 4) as usize);
|
||||
for y in 0..h {
|
||||
for x in 0..w {
|
||||
let i = (((y * step) * img.width + x * step) * 4) as usize;
|
||||
px.extend_from_slice(&full[i..i + 4]);
|
||||
let cached: Option<(u64, egui::TextureHandle)> = ctx.data(|d| d.get_temp(key));
|
||||
let mut tex = cached.as_ref().map(|(_, t)| t.clone());
|
||||
let have = cached.as_ref().map(|(r, _)| *r);
|
||||
// A finished render: upload it.
|
||||
let pending: Option<PendingThumb> = ctx.data(|d| d.get_temp(pkey));
|
||||
if let Some((prev, slot)) = &pending {
|
||||
let done = slot.lock().ok().and_then(|mut s| s.take());
|
||||
match done {
|
||||
Some(Some((w, h, px))) => {
|
||||
let ci = egui::ColorImage::from_rgba_unmultiplied([w as usize, h as usize], &px);
|
||||
let t = ctx.load_texture(format!("proj-thumb-{}", it.id.0), ci, egui::TextureOptions::LINEAR);
|
||||
ctx.data_mut(|d| {
|
||||
d.insert_temp(key, (*prev, t.clone()));
|
||||
d.remove::<PendingThumb>(pkey);
|
||||
});
|
||||
tex = Some(t);
|
||||
if *prev == rev {
|
||||
return tex;
|
||||
}
|
||||
}
|
||||
(w, h, px)
|
||||
Some(None) => {
|
||||
ctx.data_mut(|d| d.remove::<PendingThumb>(pkey));
|
||||
return tex;
|
||||
}
|
||||
None => {
|
||||
ctx.request_repaint_after(std::time::Duration::from_millis(50));
|
||||
return tex;
|
||||
}
|
||||
}
|
||||
_ => return None,
|
||||
};
|
||||
let ci = egui::ColorImage::from_rgba_unmultiplied([w as usize, h as usize], &px);
|
||||
let tex = ctx.load_texture(format!("proj-thumb-{}", it.id.0), ci, egui::TextureOptions::LINEAR);
|
||||
ctx.data_mut(|d| d.insert_temp(key, (rev, tex.clone())));
|
||||
Some(tex)
|
||||
}
|
||||
if have == Some(rev) {
|
||||
return tex;
|
||||
}
|
||||
let t = app.session.state.times.get(&it.id).copied().unwrap_or_default();
|
||||
let job = app.session.thumbnail_job(it.id, t, 192)?;
|
||||
let slot: Arc<Mutex<Option<Option<(u32, u32, Vec<u8>)>>>> = Arc::default();
|
||||
if cfg!(target_arch = "wasm32") {
|
||||
*slot.lock().ok()? = Some(job());
|
||||
} else {
|
||||
let s = slot.clone();
|
||||
let spawned = std::thread::Builder::new().name("proj-thumb".into()).spawn(move || {
|
||||
let r = job();
|
||||
if let Ok(mut s) = s.lock() {
|
||||
*s = Some(r);
|
||||
}
|
||||
});
|
||||
if spawned.is_err() {
|
||||
return tex;
|
||||
}
|
||||
}
|
||||
ctx.data_mut(|d| d.insert_temp::<PendingThumb>(pkey, (rev, slot)));
|
||||
ctx.request_repaint();
|
||||
tex
|
||||
}
|
||||
|
||||
fn fit(r: Rect, w: f32, h: f32) -> Rect {
|
||||
@@ -290,7 +320,6 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
app.ui.project_hscroll = (hscroll + sresp.drag_delta().x * overflow / (track.width() - tw).max(1.0)).clamp(0.0, overflow);
|
||||
}
|
||||
}
|
||||
let mut y = list.min.y;
|
||||
let query = app.ui.project_search.to_lowercase();
|
||||
let mut rows: Vec<(ItemId, usize)> = vec![];
|
||||
fn walk(app: &EffectcraftApp, folder: Option<ItemId>, depth: usize, q: &str, out: &mut Vec<(ItemId, usize)>) {
|
||||
@@ -324,8 +353,48 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
let hover_y = ctx.pointer_hover_pos().filter(|p| list.contains(*p)).map(|p| p.y);
|
||||
let mut drop_row: Option<ItemId> = None;
|
||||
let mut actions: Vec<(String, serde_json::Value)> = vec![];
|
||||
for (i, (id, depth)) in rows.iter().enumerate() {
|
||||
let Some(it) = app.session.project.item(*id).cloned() else { continue };
|
||||
// Vertical scrolling: only the rows in view are drawn (and registered), so a project with
|
||||
// thousands of items costs what one screenful does.
|
||||
let content_h = rows.len() as f32 * ROW_H;
|
||||
let max_scroll = (content_h - list.height() + ROW_H).max(0.0);
|
||||
if ui.rect_contains_pointer(list) {
|
||||
let (dy, shift) = ui.input(|i| (i.smooth_scroll_delta.y, i.modifiers.shift));
|
||||
if !shift && dy != 0.0 {
|
||||
app.ui.project_scroll -= dy;
|
||||
}
|
||||
}
|
||||
// A selection made elsewhere (a command, an agent, the viewer) scrolls into view.
|
||||
let sel_key = egui::Id::new("proj-sel-seen");
|
||||
let sel_now = app.session.state.project_selection.last().map(|i| i.0);
|
||||
if ctx.data(|d| d.get_temp::<Option<u64>>(sel_key)) != Some(sel_now) {
|
||||
ctx.data_mut(|d| d.insert_temp(sel_key, sel_now));
|
||||
if let Some(row) = sel_now.and_then(|s| rows.iter().position(|(id, _)| id.0 == s)) {
|
||||
let top = row as f32 * ROW_H;
|
||||
if top < app.ui.project_scroll {
|
||||
app.ui.project_scroll = top;
|
||||
} else if top + ROW_H > app.ui.project_scroll + list.height() {
|
||||
app.ui.project_scroll = top + ROW_H - list.height();
|
||||
}
|
||||
}
|
||||
}
|
||||
app.ui.project_scroll = app.ui.project_scroll.clamp(0.0, max_scroll);
|
||||
let scroll = app.ui.project_scroll;
|
||||
if max_scroll > 0.0 {
|
||||
let track = Rect::from_min_max(pos2(rect.max.x - 6.0, list.min.y + 1.0), pos2(rect.max.x - 2.0, list.max.y - 7.0));
|
||||
let th = (track.height() * list.height() / content_h).clamp(16.0, track.height());
|
||||
let thumb = Rect::from_min_size(pos2(track.min.x, track.min.y + (track.height() - th) * (scroll / max_scroll)), vec2(track.width(), th));
|
||||
let vresp = ui.interact(track.expand2(vec2(2.0, 0.0)), egui::Id::new("proj-vscroll"), Sense::drag());
|
||||
p.rect_filled(thumb, 2.0, if vresp.hovered() || vresp.dragged() { t.text_dim } else { t.text_faint });
|
||||
app.auto.add("project.vscroll", track, &format!("{scroll}/{max_scroll}"));
|
||||
if vresp.dragged() {
|
||||
app.ui.project_scroll = (scroll + vresp.drag_delta().y * max_scroll / (track.height() - th).max(1.0)).clamp(0.0, max_scroll);
|
||||
}
|
||||
}
|
||||
let first = ((scroll / ROW_H).floor() as usize).min(rows.len());
|
||||
let mut y = list.min.y - (scroll - first as f32 * ROW_H);
|
||||
let project = app.session.project.clone();
|
||||
for (i, (id, depth)) in rows.iter().enumerate().skip(first) {
|
||||
let Some(it) = project.item(*id) else { continue };
|
||||
let r = Rect::from_min_size(pos2(list.min.x, y), vec2(list.width(), ROW_H));
|
||||
y += ROW_H;
|
||||
if r.min.y > list.max.y {
|
||||
@@ -355,7 +424,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
}
|
||||
app.auto.add(&format!("project.item.{}.twirl", id.0), tw, &it.name);
|
||||
}
|
||||
icons::paint(&lp, Rect::from_center_size(pos2(x0 + 18.0, r.center().y), vec2(14.0, 14.0)), item_icon(&it), t.text_dim);
|
||||
icons::paint(&lp, Rect::from_center_size(pos2(x0 + 18.0, r.center().y), vec2(14.0, 14.0)), item_icon(it), t.text_dim);
|
||||
// Proxy indicator: filled = the proxy is used, hollow = set but off. Click to switch.
|
||||
if let Some(px) = it.proxy.as_ref() {
|
||||
let pr = Rect::from_center_size(pos2(x0 + 4.0, r.center().y), vec2(9.0, 9.0));
|
||||
@@ -437,10 +506,10 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
let cp = lp.with_clip_rect(cell);
|
||||
let txt = match *key {
|
||||
"type" => it.type_name().to_string(),
|
||||
"size" => file_size(&it).map(fmt_size).unwrap_or_default(),
|
||||
"size" => file_size(it).map(fmt_size).unwrap_or_default(),
|
||||
"duration" => it.duration().map(|d| fmt_dur(d.seconds(), it.frame_rate().map(|r| r.as_f64()).unwrap_or(30.0))).unwrap_or_default(),
|
||||
"fps" => it.frame_rate().map(|f| format!("{:.2}", f.as_f64())).unwrap_or_default(),
|
||||
"path" => file_path(&it).to_string(),
|
||||
"path" => file_path(it).to_string(),
|
||||
"comment" => {
|
||||
let cr = Rect::from_min_size(pos2(*cx - 2.0, r.min.y + 2.0), vec2(*w, r.height() - 4.0));
|
||||
if cell_edit(app, ui, &mut actions, "comment", cr) {
|
||||
|
||||
@@ -60,7 +60,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
let t = app.tokens;
|
||||
let p = ui.painter().with_clip_rect(rect);
|
||||
let ctx = ui.ctx().clone();
|
||||
let comp = app.session.active_comp().cloned();
|
||||
let comp = app.session.active_comp_arc();
|
||||
let layer = comp.as_ref().and_then(|c| app.session.state.selected_layers.first().and_then(|id| c.layer(*id)).cloned());
|
||||
let (Some(comp), Some(cid), Some(layer)) = (comp, app.session.active_comp_id(), layer) else {
|
||||
p.text(rect.center(), Align2::CENTER_CENTER, "Select a layer to see its properties", Tokens::ui(12.0), t.text_faint);
|
||||
|
||||
@@ -75,15 +75,23 @@ fn row_height(row: &Row, rh: f32) -> f32 {
|
||||
/// Insert an expression editor row after every property that has an expression.
|
||||
fn with_expr_rows(rows: Vec<Row>, comp: &Comp, closed: &std::collections::BTreeSet<u64>) -> Vec<Row> {
|
||||
let mut out = Vec::with_capacity(rows.len());
|
||||
// Rows come grouped by layer: look each layer up once (a linear search per property row
|
||||
// made twirling open many layers of a big comp quadratic).
|
||||
let mut cur: Option<&Layer> = None;
|
||||
for r in rows {
|
||||
let extra = match r.kind {
|
||||
RowKind::Prop { uid } if !closed.contains(&uid) => comp.layer(r.layer).and_then(|l| l.props.find(uid)).and_then(|p| p.expr.as_ref()).map(|e| Row {
|
||||
let mut extra = None;
|
||||
if let RowKind::Prop { uid } = r.kind
|
||||
&& !closed.contains(&uid)
|
||||
{
|
||||
if cur.is_none_or(|l| l.id != r.layer) {
|
||||
cur = comp.layer(r.layer);
|
||||
}
|
||||
extra = cur.and_then(|l| l.props.find(uid)).and_then(|p| p.expr.as_ref()).map(|e| Row {
|
||||
layer: r.layer,
|
||||
depth: r.depth,
|
||||
kind: RowKind::Expr { uid, lines: e.text.lines().count().max(1) },
|
||||
}),
|
||||
_ => None,
|
||||
};
|
||||
});
|
||||
}
|
||||
out.push(r);
|
||||
out.extend(extra);
|
||||
}
|
||||
@@ -336,7 +344,7 @@ fn tl_map_id() -> egui::Id {
|
||||
/// Zoom the time ruler around the CTI.
|
||||
pub fn zoom(app: &mut EffectcraftApp, ctx: &egui::Context, k: f64) {
|
||||
let Some((x0, w)) = ctx.data(|d| d.get_temp::<(f32, f32)>(egui::Id::new("timeline-graph-area"))) else { return };
|
||||
let comp = app.session.active_comp().cloned();
|
||||
let comp = app.session.active_comp_arc();
|
||||
let Some(comp) = comp else { return };
|
||||
let fit = (w as f64 - 20.0) / comp.duration.seconds().max(0.01);
|
||||
let pps = app.ui.timeline.pps.unwrap_or(fit);
|
||||
@@ -783,7 +791,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
ui.painter().text(rect.center(), Align2::CENTER_CENTER, "(no composition)", Tokens::ui(12.0), t.text_faint);
|
||||
return;
|
||||
};
|
||||
let Some(comp) = app.session.project.comp(cid).cloned() else { return };
|
||||
let Some(comp) = app.session.project.comp_arc(cid) else { return };
|
||||
let p = ui.painter().clone();
|
||||
let time = app.session.time();
|
||||
let fr = comp.frame_rate;
|
||||
@@ -891,6 +899,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
p.rect_filled(Rect::from_min_max(pos2(x - 3.0, nav.min.y - 1.0), pos2(x + 3.0, nav.max.y + 1.0)), 3.0, t.accent);
|
||||
}
|
||||
let nresp = ui.interact(nav, egui::Id::new("tl-nav"), Sense::drag());
|
||||
app.auto.add("timeline.navigator", nav, "Time navigator");
|
||||
if nresp.dragged() {
|
||||
let d = nresp.drag_delta().x as f64 / nav.width() as f64 * comp.duration.seconds();
|
||||
app.ui.timeline.start = (app.ui.timeline.start + d).clamp(0.0, comp.duration.seconds());
|
||||
@@ -1211,6 +1220,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
let lr = Rect::from_center_size(pos2(cw.label + 10.0, cy), vec2(12.0, 12.0));
|
||||
lp.rect_filled(lr, 2.0, t.label(layer.label));
|
||||
let lresp = ui.interact(lr, egui::Id::new(("label", layer.id.0)), Sense::click());
|
||||
app.auto.add(&format!("timeline.layer.{}.label", layer.id.0), lr, layer.label.name());
|
||||
lresp.context_menu(|ui| {
|
||||
for lab in effectcraft_engine::color::Label::ALL {
|
||||
let name = if lab == effectcraft_engine::color::Label::None { lab.name().to_string() } else { app.session.prefs.label_name(lab) };
|
||||
@@ -1363,14 +1373,19 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
if tresp.clicked() {
|
||||
widgets::open_popup(ui, pop);
|
||||
}
|
||||
// The menu lists every layer: built only while it is open (per visible row
|
||||
// it made a big comp's timeline quadratic).
|
||||
let mut opts = vec!["No Track Matte".to_string(), "-".to_string()];
|
||||
let candidates: Vec<&Layer> = comp.layers.iter().filter(|l| l.id != layer.id && l.source.is_av()).collect();
|
||||
for l in &candidates {
|
||||
opts.push(format!("{}. {}", idx_of(l.id), l.name));
|
||||
}
|
||||
opts.push("-".into());
|
||||
for k in MatteKind::ALL {
|
||||
opts.push(k.label().into());
|
||||
let mut candidates: Vec<&Layer> = vec![];
|
||||
if widgets::popup_is_open(ui, pop) {
|
||||
for (i, l) in comp.layers.iter().enumerate().filter(|(_, l)| l.id != layer.id && l.source.is_av()) {
|
||||
opts.push(format!("{}. {}", i + 1, l.name));
|
||||
candidates.push(l);
|
||||
}
|
||||
opts.push("-".into());
|
||||
for k in MatteKind::ALL {
|
||||
opts.push(k.label().into());
|
||||
}
|
||||
}
|
||||
if let Some(i) = widgets::popup_menu(ui, pop, mr.left_bottom(), &opts, None) {
|
||||
if i == 0 {
|
||||
@@ -1409,9 +1424,14 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
if presp.clicked() {
|
||||
widgets::open_popup(ui, pop);
|
||||
}
|
||||
let cands: Vec<&Layer> = comp.layers.iter().filter(|l| l.id != layer.id).collect();
|
||||
let mut cands: Vec<&Layer> = vec![];
|
||||
let mut popts = vec!["None".to_string(), "-".to_string()];
|
||||
popts.extend(cands.iter().map(|l| format!("{}. {}", idx_of(l.id), l.name)));
|
||||
if widgets::popup_is_open(ui, pop) {
|
||||
for (i, l) in comp.layers.iter().enumerate().filter(|(_, l)| l.id != layer.id) {
|
||||
popts.push(format!("{}. {}", i + 1, l.name));
|
||||
cands.push(l);
|
||||
}
|
||||
}
|
||||
if let Some(i) = widgets::popup_menu(ui, pop, pr_rect.left_bottom(), &popts, None) {
|
||||
let par = if i == 0 { serde_json::Value::Null } else { json!(cands[i - 2].id.0) };
|
||||
actions.push(("layer.setParent".into(), json!({"layers": [layer.id.0], "parent": par})));
|
||||
@@ -1474,10 +1494,12 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
// Interactions: move body, trim edges.
|
||||
let edge_w = 6.0;
|
||||
let body = ui.interact(bar.shrink2(vec2(edge_w, 0.0)), egui::Id::new(("bar", layer.id.0)), Sense::click_and_drag());
|
||||
let lin =
|
||||
ui.interact(Rect::from_min_max(bar.min, pos2(bar.min.x + edge_w, bar.max.y)), egui::Id::new(("bar-in", layer.id.0)), Sense::drag());
|
||||
let lout =
|
||||
ui.interact(Rect::from_min_max(pos2(bar.max.x - edge_w, bar.min.y), bar.max), egui::Id::new(("bar-out", layer.id.0)), Sense::drag());
|
||||
let (in_r, out_r) =
|
||||
(Rect::from_min_max(bar.min, pos2(bar.min.x + edge_w, bar.max.y)), Rect::from_min_max(pos2(bar.max.x - edge_w, bar.min.y), bar.max));
|
||||
let lin = ui.interact(in_r, egui::Id::new(("bar-in", layer.id.0)), Sense::drag());
|
||||
let lout = ui.interact(out_r, egui::Id::new(("bar-out", layer.id.0)), Sense::drag());
|
||||
app.auto.add(&format!("timeline.layer.{}.bar.in", layer.id.0), in_r, "Trim In");
|
||||
app.auto.add(&format!("timeline.layer.{}.bar.out", layer.id.0), out_r, "Trim Out");
|
||||
if lin.hovered() || lout.hovered() || lin.dragged() || lout.dragged() {
|
||||
ctx.set_cursor_icon(egui::CursorIcon::ResizeHorizontal);
|
||||
}
|
||||
@@ -1567,7 +1589,9 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
}
|
||||
lp.text(pos2(ir.max.x + 4.0, cy), Align2::LEFT_CENTER, "Inverted", Tokens::ui(11.0), t.text_dim);
|
||||
}
|
||||
let gr = ui.interact(Rect::from_min_max(pos2(indent + 8.0, r.min.y), pos2(cw.switches, r.max.y)), egui::Id::new(("grow", uid)), Sense::click());
|
||||
let gr_rect = Rect::from_min_max(pos2(indent + 8.0, r.min.y), pos2(cw.switches, r.max.y));
|
||||
let gr = ui.interact(gr_rect, egui::Id::new(("grow", uid)), Sense::click());
|
||||
app.auto.add(&format!("timeline.group.{uid}.name"), gr_rect, name);
|
||||
if gr.clicked() && uid & WAVE_BIT == 0 {
|
||||
actions.push(("prop.select".into(), json!({"layer": layer.id.0, "prop": uid, "selectKeys": false})));
|
||||
}
|
||||
@@ -1781,11 +1805,9 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
Tokens::ui(12.0),
|
||||
if prop.has_expression() { Color32::from_rgb(0xe8, 0x7c, 0x5c) } else { t.text },
|
||||
);
|
||||
let name_resp = ui.interact(
|
||||
Rect::from_min_max(pos2(name_x, r.min.y), pos2(cw.switches - 2.0, r.max.y)),
|
||||
egui::Id::new(("pname", uid)),
|
||||
Sense::click_and_drag(),
|
||||
);
|
||||
let name_rect = Rect::from_min_max(pos2(name_x, r.min.y), pos2(cw.switches - 2.0, r.max.y));
|
||||
let name_resp = ui.interact(name_rect, egui::Id::new(("pname", uid)), Sense::click_and_drag());
|
||||
app.auto.add(&format!("timeline.prop.{uid}.name"), name_rect, &prop.name);
|
||||
if name_resp.drag_started() {
|
||||
// Drop on the Essential Graphics panel to expose the property.
|
||||
egui::DragAndDrop::set_payload(&ctx, crate::panels::DragPayload::Property { layer: layer.id.0, prop: *uid });
|
||||
@@ -1906,7 +1928,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
// Alt-drag the first or last key of a selected group: scale the group in time.
|
||||
if kresp.drag_started()
|
||||
&& ui.input(|i| i.modifiers.alt)
|
||||
&& let Some(c) = app.session.active_comp().cloned()
|
||||
&& let Some(c) = app.session.active_comp_arc()
|
||||
{
|
||||
super::graph_tools::alt_scale_begin(app, &ctx, &c, ct.seconds());
|
||||
}
|
||||
@@ -1956,7 +1978,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
}
|
||||
}
|
||||
// Alt-drag key group scaling (follows the pointer until release).
|
||||
if let Some(c) = app.session.active_comp().cloned() {
|
||||
if let Some(c) = app.session.active_comp_arc() {
|
||||
super::graph_tools::alt_scale_update(app, &ctx, &c, tm, &mut actions);
|
||||
}
|
||||
// Graph editor.
|
||||
|
||||
@@ -152,7 +152,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
run(app, &ctx, "track.stabilize", src_p.clone());
|
||||
}
|
||||
y += 34.0;
|
||||
let Some(comp) = app.session.active_comp().cloned() else {
|
||||
let Some(comp) = app.session.active_comp_arc() else {
|
||||
p.text(pos2(x0, y + 8.0), Align2::LEFT_CENTER, "Open a composition to track motion.", Tokens::ui(12.0), t.text_faint);
|
||||
return;
|
||||
};
|
||||
|
||||
@@ -352,7 +352,7 @@ fn aux_views(
|
||||
/// (its comp and 3D view stay put whatever comp is active). Returns the main viewer's rectangle.
|
||||
fn locked_pane(app: &mut EffectcraftApp, ui: &mut egui::Ui, full: Rect, bg: Color32) -> Rect {
|
||||
let Some(lv) = app.session.state.locked_viewer else { return full };
|
||||
let Some(comp) = app.session.project.comp(lv.comp).cloned() else { return full };
|
||||
let Some(comp) = app.session.project.comp_arc(lv.comp) else { return full };
|
||||
let name = app.session.project.item(lv.comp).map(|i| i.name.clone()).unwrap_or_default();
|
||||
let gap = 2.0;
|
||||
let mid = full.center().x;
|
||||
@@ -435,7 +435,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
empty_state(app, ui, rect);
|
||||
return;
|
||||
};
|
||||
let comp = app.session.project.comp(cid).cloned().unwrap_or_else(|| effectcraft_engine::project::Comp::new(1920, 1080, Default::default(), Tick::ZERO));
|
||||
let comp = app.session.project.comp_arc(cid).unwrap_or_else(|| effectcraft_engine::project::Comp::new(1920, 1080, Default::default(), Tick::ZERO).into());
|
||||
let comp_name = app.session.project.item(cid).map(|i| i.name.clone()).unwrap_or_default();
|
||||
let p = ui.painter().clone();
|
||||
VIEW_CAM.with(|c| c.set(app.session.view_camera(cid)));
|
||||
@@ -1726,7 +1726,7 @@ fn create_shape(app: &mut EffectcraftApp, tool: Tool, a: [f64; 2], b: [f64; 2],
|
||||
&& matches!(kind, "rect" | "ellipse")
|
||||
{
|
||||
// Mask in layer space: invert the layer transform.
|
||||
let comp = app.session.active_comp().cloned();
|
||||
let comp = app.session.active_comp_arc();
|
||||
if let Some(comp) = comp {
|
||||
let ectx = EvalCtx {
|
||||
project: &app.session.project,
|
||||
|
||||
@@ -565,6 +565,9 @@ pub struct UiState {
|
||||
/// Horizontal scroll of the Project panel's optional columns (Name and Label stay put).
|
||||
#[serde(default)]
|
||||
pub project_hscroll: f32,
|
||||
/// Vertical scroll of the Project panel's item list (points); only visible rows are drawn.
|
||||
#[serde(default)]
|
||||
pub project_scroll: f32,
|
||||
/// Effect Controls twirl state (group uids that are collapsed).
|
||||
pub fx_closed: BTreeSet<u64>,
|
||||
/// Slider params whose slider row is twirled open (AE hides sliders by default).
|
||||
@@ -656,6 +659,7 @@ impl Default for UiState {
|
||||
project_sort: default_project_sort(),
|
||||
project_sort_desc: false,
|
||||
project_hscroll: 0.0,
|
||||
project_scroll: 0.0,
|
||||
project_columns: default_project_columns(),
|
||||
fx_closed: BTreeSet::new(),
|
||||
fx_slider_open: BTreeSet::new(),
|
||||
|
||||
@@ -238,6 +238,11 @@ pub fn popup_menu(ui: &mut Ui, id: egui::Id, pos: egui::Pos2, options: &[String]
|
||||
chosen
|
||||
}
|
||||
|
||||
/// Whether a [`popup_menu`] is open (build its options only then: they can be long).
|
||||
pub fn popup_is_open(ui: &Ui, id: egui::Id) -> bool {
|
||||
ui.data(|d| d.get_temp(id.with("open")).unwrap_or(false))
|
||||
}
|
||||
|
||||
pub fn open_popup(ui: &Ui, id: egui::Id) {
|
||||
ui.data_mut(|d| d.insert_temp(id.with("open"), true));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
//! The agent-interface audit (UI side, M13.14):
|
||||
//!
|
||||
//! - every registered engine command is reachable over the control channel (`engine.commands`
|
||||
//! lists it; `engine.execute` routes it: an unknown parameter is rejected by that command);
|
||||
//! - every panel kind, opened headless, registers an automation id for every interactive widget
|
||||
//! it draws: egui's interactive widget rects of the frame are matched against the registered
|
||||
//! automation elements, and any widget no element covers is a gap.
|
||||
|
||||
use effectcraft_engine::Session;
|
||||
use effectcraft_ui_egui::EffectcraftApp;
|
||||
use effectcraft_ui_egui::control::{self, ControlRequest, Outcome};
|
||||
use effectcraft_ui_egui::dock::PanelKind;
|
||||
use egui::Rect;
|
||||
use egui_kittest::Harness;
|
||||
use serde_json::{Value, json};
|
||||
|
||||
fn session() -> Session {
|
||||
let mut s = Session::default();
|
||||
s.execute("file.openDemoProject", json!({})).unwrap();
|
||||
s
|
||||
}
|
||||
|
||||
fn harness(s: Session) -> Harness<'static, EffectcraftApp> {
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1680.0, 1020.0)).build_eframe(|_| EffectcraftApp::new(s));
|
||||
h.run_steps(3);
|
||||
h
|
||||
}
|
||||
|
||||
fn send(h: &mut Harness<'_, EffectcraftApp>, method: &str, params: Value) -> Value {
|
||||
let ctx = h.ctx.clone();
|
||||
let (req, _rx) = ControlRequest::new(method, params);
|
||||
match control::handle(h.state_mut(), &ctx, &req) {
|
||||
Outcome::Done(v) => v,
|
||||
_ => panic!("{method}: no immediate reply"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_engine_command_is_reachable_over_the_control_channel() {
|
||||
let mut h = harness(session());
|
||||
let listed = send(&mut h, "engine.commands", json!({}));
|
||||
let ids: std::collections::HashSet<String> = listed["result"].as_array().unwrap().iter().map(|c| c["id"].as_str().unwrap().to_string()).collect();
|
||||
for spec in effectcraft_engine::command_specs() {
|
||||
assert!(ids.contains(spec.id), "engine.commands misses {}", spec.id);
|
||||
let v = send(&mut h, "engine.execute", json!({"command": spec.id, "params": {"__audit": 1}}));
|
||||
let e = v["error"].as_str().unwrap_or_default();
|
||||
assert!(v["ok"] == false && e.contains("unknown parameter") && e.contains(spec.id), "{}: {v}", spec.id);
|
||||
}
|
||||
}
|
||||
|
||||
/// Interactive widgets (click or drag sense, enabled, visible) of the last frame, in screen
|
||||
/// points, with their accessibility label when egui knows one.
|
||||
fn interactive(ctx: &egui::Context) -> Vec<(Rect, String)> {
|
||||
let screen = ctx.content_rect();
|
||||
ctx.viewport(|v| {
|
||||
let w = &v.this_pass.widgets;
|
||||
let mut out = vec![];
|
||||
for (layer, rects) in w.layers() {
|
||||
if layer.order == egui::Order::Tooltip || layer.order == egui::Order::Debug {
|
||||
continue;
|
||||
}
|
||||
for r in rects {
|
||||
let sense = r.sense;
|
||||
if !(sense.senses_click() || sense.senses_drag()) || !r.enabled {
|
||||
continue;
|
||||
}
|
||||
let ir = r.interact_rect.intersect(screen);
|
||||
if ir.width() < 2.0 || ir.height() < 2.0 {
|
||||
continue;
|
||||
}
|
||||
let info = w.info(r.id);
|
||||
// Selectable text (labels sense drags to select their text) is not a control.
|
||||
if info.is_some_and(|i| i.typ == egui::WidgetType::Label) {
|
||||
continue;
|
||||
}
|
||||
out.push((ir, info.and_then(|i| i.label.clone()).unwrap_or_default()));
|
||||
}
|
||||
}
|
||||
out
|
||||
})
|
||||
}
|
||||
|
||||
/// Automation elements that cover a widget: overlapping at least half of the smaller of the two,
|
||||
/// and not a container many times the widget's size (a panel or a whole row).
|
||||
fn covered(w: Rect, elements: &[Rect]) -> bool {
|
||||
elements.iter().any(|e| {
|
||||
let i = e.intersect(w);
|
||||
if i.width() <= 0.0 || i.height() <= 0.0 {
|
||||
return false;
|
||||
}
|
||||
let (aw, ae) = (w.area(), e.area());
|
||||
i.area() >= 0.5 * aw.min(ae) && ae <= 40.0 * aw.max(64.0)
|
||||
})
|
||||
}
|
||||
|
||||
/// (panel, widget rect, label) of every interactive widget no automation element covers, for
|
||||
/// one panel shown maximized.
|
||||
fn gaps_of(h: &mut Harness<'_, EffectcraftApp>, p: PanelKind) -> Vec<String> {
|
||||
h.state_mut().show_panel(p);
|
||||
h.state_mut().ui.maximized = Some(p);
|
||||
h.run_steps(4);
|
||||
let ctx = h.ctx.clone();
|
||||
let widgets = interactive(&ctx);
|
||||
let app = h.state();
|
||||
let elements: Vec<Rect> = app
|
||||
.auto
|
||||
.previous
|
||||
.iter()
|
||||
.chain(app.auto.elements.iter())
|
||||
.map(|e| Rect::from_min_size(egui::pos2(e.rect[0], e.rect[1]), egui::vec2(e.rect[2], e.rect[3])))
|
||||
.collect();
|
||||
let Some(panel) =
|
||||
app.auto.find(&format!("panel.{}", p.id())).map(|e| Rect::from_min_size(egui::pos2(e.rect[0], e.rect[1]), egui::vec2(e.rect[2], e.rect[3])))
|
||||
else {
|
||||
return vec![format!("{}: panel.{} not registered", p.title(), p.id())];
|
||||
};
|
||||
widgets
|
||||
.into_iter()
|
||||
.filter(|(r, _)| panel.contains(r.center()))
|
||||
.filter(|(r, _)| !covered(*r, &elements))
|
||||
.map(|(r, l)| format!("{}: [{:.0},{:.0} {:.0}x{:.0}] {l:?}", p.title(), r.min.x, r.min.y, r.width(), r.height()))
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_panel_registers_automation_ids_for_its_widgets() {
|
||||
let mut s = session();
|
||||
// Content for the selection-driven panels: the title (text with effects), a Render Queue
|
||||
// item, a comp marker.
|
||||
s.execute("layer.select", json!({"layers": ["EFFECTCRAFT"]})).unwrap();
|
||||
s.execute("renderQueue.add", json!({"format": "png", "output": "/tmp/ec-audit-[#####].png"})).unwrap();
|
||||
s.execute("markers.add", json!({})).ok();
|
||||
let title = s.active_comp().unwrap().layers.iter().find(|l| l.name == "EFFECTCRAFT").map(|l| l.id.0).unwrap();
|
||||
let mut h = harness(s);
|
||||
h.state_mut().ui.layer_panel = Some(title);
|
||||
// egui records widget types (to tell labels from controls) with this debug option.
|
||||
h.ctx.all_styles_mut(|st| st.debug.show_interactive_widgets = true);
|
||||
let mut gaps = vec![];
|
||||
for p in PanelKind::ALL {
|
||||
gaps.extend(gaps_of(&mut h, p));
|
||||
}
|
||||
// The timeline again with the title twirled open (properties, keys) and in the Graph Editor.
|
||||
send(&mut h, "ui.set", json!({"timeline": {"openLayers": [title]}}));
|
||||
gaps.extend(gaps_of(&mut h, PanelKind::Timeline));
|
||||
send(&mut h, "ui.set", json!({"timeline": {"graphEditor": true}}));
|
||||
gaps.extend(gaps_of(&mut h, PanelKind::Timeline));
|
||||
send(&mut h, "ui.set", json!({"timeline": {"graphEditor": false}}));
|
||||
// Outside the panels: the header and the menu bar.
|
||||
h.state_mut().ui.maximized = None;
|
||||
h.run_steps(3);
|
||||
let ctx = h.ctx.clone();
|
||||
let widgets = interactive(&ctx);
|
||||
let app = h.state();
|
||||
let elements: Vec<Rect> =
|
||||
app.auto.previous.iter().map(|e| Rect::from_min_size(egui::pos2(e.rect[0], e.rect[1]), egui::vec2(e.rect[2], e.rect[3]))).collect();
|
||||
let panels: Vec<Rect> = app
|
||||
.auto
|
||||
.previous
|
||||
.iter()
|
||||
.filter(|e| e.id.starts_with("panel.") && e.id.matches('.').count() == 1)
|
||||
.map(|e| Rect::from_min_size(egui::pos2(e.rect[0], e.rect[1]), egui::vec2(e.rect[2], e.rect[3])))
|
||||
.collect();
|
||||
for (r, l) in widgets {
|
||||
if !panels.iter().any(|p| p.contains(r.center())) && !covered(r, &elements) {
|
||||
gaps.push(format!("chrome: [{:.0},{:.0} {:.0}x{:.0}] {l:?}", r.min.x, r.min.y, r.width(), r.height()));
|
||||
}
|
||||
}
|
||||
assert!(gaps.is_empty(), "{} interactive widgets without an automation id:\n{}", gaps.len(), gaps.join("\n"));
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
//! M13.14: the UI with a large project. The Project panel scrolls (only the rows in view are
|
||||
//! drawn), reveals an item selected elsewhere and renders thumbnails off the UI thread; the
|
||||
//! Timeline reaches the last of thousands of layers; the Progress panel lists the footage check
|
||||
//! started by a lazy open.
|
||||
|
||||
use effectcraft_engine::Session;
|
||||
use effectcraft_engine::perf::{LargeSpec, large_project};
|
||||
use effectcraft_ui_egui::EffectcraftApp;
|
||||
use effectcraft_ui_egui::dock::PanelKind;
|
||||
use egui_kittest::Harness;
|
||||
use serde_json::json;
|
||||
|
||||
fn spec() -> LargeSpec {
|
||||
LargeSpec { comps: 8, main_layers: 1500, comp_layers: 3, footage: 90, sequence_frames: 12, nest_depth: 3, expression_every: 5, ..Default::default() }
|
||||
}
|
||||
|
||||
fn harness(s: Session) -> Harness<'static, EffectcraftApp> {
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(|_| EffectcraftApp::new(s));
|
||||
h.run_steps(3);
|
||||
h
|
||||
}
|
||||
|
||||
fn large() -> Session {
|
||||
let mut s = Session::default();
|
||||
s.replace_project(large_project(&spec()), None);
|
||||
s
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn project_panel_scrolls_and_reveals_the_selection() {
|
||||
let mut h = harness(large());
|
||||
let folders: Vec<u64> = h.state().session.project.items.values().filter(|i| i.is_folder()).map(|i| i.id.0).collect();
|
||||
h.state_mut().ui.project_open_folders.extend(folders);
|
||||
h.state_mut().show_panel(PanelKind::Project);
|
||||
h.run_steps(3);
|
||||
// Far more rows than fit: a scroll bar, and the bottom rows aren't drawn yet.
|
||||
assert!(h.state().auto.find("project.vscroll").is_some());
|
||||
let drawn = |h: &Harness<'_, EffectcraftApp>| {
|
||||
h.state().auto.previous.iter().filter(|e| e.id.starts_with("project.item.") && e.id.matches('.').count() == 2).count()
|
||||
};
|
||||
let rows = drawn(&h);
|
||||
assert!(rows > 5 && rows < 80, "only the rows in view are drawn: {rows}");
|
||||
// Selecting an item (a command, an agent) scrolls it into view.
|
||||
let footage =
|
||||
h.state().session.project.items.values().filter(|i| matches!(i.kind, effectcraft_engine::project::ItemKind::Footage(_))).map(|i| i.id.0).max().unwrap();
|
||||
h.state_mut().session.execute("project.select", json!({"items": [footage]})).unwrap();
|
||||
h.run_steps(3);
|
||||
assert!(h.state().auto.find(&format!("project.item.{footage}")).is_some(), "selected item scrolled into view");
|
||||
assert!(h.state().ui.project_scroll > 0.0);
|
||||
// Scrolling to the end shows the last rows.
|
||||
h.state_mut().ui.project_scroll = 1.0e6;
|
||||
h.run_steps(2);
|
||||
let shown: Vec<String> = h.state().auto.previous.iter().filter(|e| e.id.starts_with("project.item.")).map(|e| e.id.clone()).collect();
|
||||
assert!(!shown.is_empty() && drawn(&h) < 80, "{shown:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn comp_thumbnail_renders_off_the_ui_thread() {
|
||||
let mut h = harness(large());
|
||||
let main = h.state().session.active_comp_id().unwrap();
|
||||
h.state_mut().session.execute("project.select", json!({"items": [main.0]})).unwrap();
|
||||
h.state_mut().show_panel(PanelKind::Project);
|
||||
// The frame that asks for the thumbnail doesn't wait for it; it lands a few frames later.
|
||||
let mut landed = false;
|
||||
for _ in 0..400 {
|
||||
h.step();
|
||||
if h.state().auto.find("project.thumbnail").is_some()
|
||||
&& h.ctx.data(|d| d.get_temp::<(u64, egui::TextureHandle)>(egui::Id::new(("proj-thumb", main.0)))).is_some()
|
||||
{
|
||||
landed = true;
|
||||
break;
|
||||
}
|
||||
std::thread::sleep(std::time::Duration::from_millis(10));
|
||||
}
|
||||
assert!(landed, "thumbnail texture");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn timeline_reaches_the_last_of_many_layers() {
|
||||
let mut h = harness(large());
|
||||
h.state_mut().show_panel(PanelKind::Timeline);
|
||||
h.state_mut().ui.maximized = Some(PanelKind::Timeline);
|
||||
let last = h.state().session.active_comp().unwrap().layers.last().unwrap().id.0;
|
||||
let first = h.state().session.active_comp().unwrap().layers[0].id.0;
|
||||
h.run_steps(2);
|
||||
assert!(h.state().auto.find(&format!("timeline.layer.{first}.bar")).is_some());
|
||||
assert!(h.state().auto.find(&format!("timeline.layer.{last}.bar")).is_none(), "off-screen rows aren't drawn");
|
||||
h.state_mut().ui.timeline.scroll_y = 1.0e7;
|
||||
h.run_steps(2);
|
||||
assert!(h.state().auto.find(&format!("timeline.layer.{last}.bar")).is_some());
|
||||
// Track matte and parent menus list every layer only while open.
|
||||
let pop = h.state().auto.find(&format!("timeline.layer.{last}.parent")).cloned();
|
||||
assert!(pop.is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lazy_open_lists_the_footage_check_in_the_progress_panel() {
|
||||
let path = std::env::temp_dir().join(format!("ec-ui-lazy-open-{}.ecproj", std::process::id()));
|
||||
let mut s = large();
|
||||
s.execute("file.saveAs", json!({"path": path.to_string_lossy()})).unwrap();
|
||||
let mut o = Session { check_footage_on_open: true, ..Default::default() };
|
||||
o.execute("file.open", json!({"path": path.to_string_lossy()})).unwrap();
|
||||
assert!(o.jobs().iter().any(|j| j.kind == "footageCheck"));
|
||||
let mut h = harness(o);
|
||||
h.state_mut().show_panel(PanelKind::Progress);
|
||||
// The check finishes in the background; polling applies it: every file is missing.
|
||||
for _ in 0..500 {
|
||||
h.step();
|
||||
if h.state().session.tasks.is_empty() {
|
||||
break;
|
||||
}
|
||||
std::thread::sleep(std::time::Duration::from_millis(10));
|
||||
}
|
||||
assert!(h.state().session.tasks.is_empty());
|
||||
let missing =
|
||||
h.state().session.project.items.values().filter(|i| matches!(&i.kind, effectcraft_engine::project::ItemKind::Footage(f) if f.missing)).count();
|
||||
assert_eq!(missing, spec().footage);
|
||||
assert!(!h.state().session.is_dirty(), "the check doesn't modify the project");
|
||||
let _ = std::fs::remove_file(path);
|
||||
}
|
||||
Reference in New Issue
Block a user