mirror of
https://github.com/storytold/effectcraft.git
synced 2026-11-29 17:44:05 +01:00
Merge pull request #4153 from aiongg/minimal-port-next
EffectCraft: move to craft-libs next (minimal port)
This commit is contained in:
198 files changed
+4722
-1960
No files matched your search
Generated
+1318
-146
File diff suppressed because it is too large.
Load diff
+41
-36
@@ -11,29 +11,28 @@ rust-version = "1.95"
|
||||
repository = "https://github.com/storytold/effectcraft"
|
||||
|
||||
[workspace.dependencies]
|
||||
craft-timeline = { git = "https://github.com/storytold/craft-libs", rev = "0d6dd8bed815b8366869a800d2bf22588ca62dcb", default-features = false }
|
||||
craft-mime = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" }
|
||||
craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "068e079c7be4b100a8a6b305b31ac881e069727e", version = "=0.1.0", default-features = false, features = ["read"] }
|
||||
craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" }
|
||||
craft-jsonrpc = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "bc186ca719958fcce3b6ee24794277eabed14609" }
|
||||
craft-quit = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" }
|
||||
craft-ecproj-format = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" }
|
||||
craft-dpx = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" }
|
||||
craft-ps = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "068e079c7be4b100a8a6b305b31ac881e069727e", default-features = false, features = ["read"] }
|
||||
craft-exr = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "3b8e426a260695af840a2cd79a064d40778f939e" }
|
||||
craft-gif = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "ba25ccd233934d1b2f74e3c0f235168bf5f13ef3" }
|
||||
craft-timeline = { git = "https://github.com/storytold/craft-libs", rev = "33be35625e252cc4f06aa375b3b428521faea37d", default-features = false }
|
||||
craft-mime = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21" }
|
||||
craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21", version = "=0.1.0", default-features = false, features = ["read"] }
|
||||
craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21" }
|
||||
craft-jsonrpc = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21" }
|
||||
craft-ecproj-format = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21" }
|
||||
craft-dpx = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21" }
|
||||
craft-ps = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21", default-features = false, features = ["read"] }
|
||||
craft-exr = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21" }
|
||||
craft-gif = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21" }
|
||||
craft-tga = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "33be35625e252cc4f06aa375b3b428521faea37d" }
|
||||
craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "53198114310dbc2b41e18e4eaf2fd83e69964189" }
|
||||
craft-codepage = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" }
|
||||
craft-svg = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "3dff4793f1a5bd1f99a4fe3280d48f515158dff3" }
|
||||
craft-webp = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" }
|
||||
craft-lottie = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" }
|
||||
craft-mesh = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87", default-features = false, features = ["stl", "obj", "gltf", "fbx"] }
|
||||
craft-aep = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" }
|
||||
craft-doc = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" }
|
||||
craft-vectorcraft-format = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87" }
|
||||
craft-psd = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21" }
|
||||
craft-codepage = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21" }
|
||||
craft-svg = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21" }
|
||||
craft-webp = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21" }
|
||||
craft-lottie = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21" }
|
||||
craft-mesh = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21", default-features = false, features = ["stl", "obj", "gltf", "fbx"] }
|
||||
craft-aep = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21" }
|
||||
craft-doc = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21" }
|
||||
craft-vectorcraft-format = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21" }
|
||||
# craft-update: app-specific pretend versions apply to startup and manual checks.
|
||||
craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87", features = ["egui"] }
|
||||
craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "8fa4db64a9bb943520259ea95331a303ba788f21", features = ["ui"] }
|
||||
# internal
|
||||
effectcraft-time = { path = "crates/time" }
|
||||
effectcraft-geom = { path = "crates/geom" }
|
||||
@@ -97,7 +96,8 @@ image = { version = "0.25", default-features = false, features = ["png", "jpeg"]
|
||||
same-file = "1.0"
|
||||
tempfile = "3.27"
|
||||
|
||||
# codecs + containers shared by the Craft apps (crates/media, crates/export); keep all in sync.
|
||||
# codecs + containers shared by the Craft apps (crates/media, crates/export); keep all in sync, with
|
||||
# filmcraft-media's craft-libs rev: their types cross between the two.
|
||||
craft-media = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "33be35625e252cc4f06aa375b3b428521faea37d", default-features = false, features = ["isobmff", "matroska"] }
|
||||
craft-media-source = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "33be35625e252cc4f06aa375b3b428521faea37d" }
|
||||
craft-frame = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "33be35625e252cc4f06aa375b3b428521faea37d" }
|
||||
@@ -127,7 +127,12 @@ half = "2.7"
|
||||
# ui
|
||||
# Shared frontend components; keep this dependency above the engine boundary.
|
||||
# Shared UI and the complete egui family select reviewed immutable commits below.
|
||||
craft-ui = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "5a7a63a21dd03dd1a2bc6c308a3a6ce818caae87", features = ["serde"] }
|
||||
craft-ui = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21" }
|
||||
craft-behavior = { git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21" }
|
||||
craft-host = { git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21" }
|
||||
craft-keymap = { git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21" }
|
||||
craft-theme = { git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21" }
|
||||
craft-window = { git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21" }
|
||||
# `default_fonts` and `monochrome_emoji_fonts` are explicit: the app's `FontDefinitions::default()`
|
||||
# and its `✔`/`▣` chrome glyphs need both, and kittest's own dev-dependencies do not propagate.
|
||||
egui = { version = "0.37", default-features = false, features = ["default_fonts", "monochrome_emoji_fonts"] }
|
||||
@@ -232,19 +237,19 @@ lto = "thin"
|
||||
codegen-units = 1
|
||||
|
||||
[patch.crates-io]
|
||||
hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "068e079c7be4b100a8a6b305b31ac881e069727e", version = "=0.7.2" }
|
||||
hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "068e079c7be4b100a8a6b305b31ac881e069727e", version = "=0.3.0" }
|
||||
ecolor = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
|
||||
emath = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
|
||||
epaint = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
|
||||
epaint_default_fonts = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
|
||||
egui = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
|
||||
egui-winit = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
|
||||
egui-wgpu = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
|
||||
egui_glow = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
|
||||
egui_extras = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
|
||||
egui_kittest = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
|
||||
eframe = { git = "https://github.com/storytold/egui.git", rev = "6d518fc799681571963842f95b55a6b68431b15a" }
|
||||
hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21", version = "=0.7.2" }
|
||||
hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21", version = "=0.3.0" }
|
||||
ecolor = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
|
||||
emath = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
|
||||
epaint = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
|
||||
epaint_default_fonts = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
|
||||
egui = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
|
||||
egui-winit = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
|
||||
egui-wgpu = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
|
||||
egui_glow = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
|
||||
egui_extras = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
|
||||
egui_kittest = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
|
||||
eframe = { git = "https://github.com/storytold/egui.git", rev = "b9770908e0f304896f9658d239a7b29cf8af1564" }
|
||||
# Patch a crate only together with the dependency that needs it: an unused patch makes the Nix
|
||||
# build, which uses vendored sources, fail (`cargo xtask lock-patches`).
|
||||
winit = { git = "https://github.com/storytold/winit.git", rev = "a517b3846ee8457d84ee4975110bfda6797c44dc" }
|
||||
@@ -113,8 +113,8 @@ impl eframe::App for WebApp {
|
||||
}
|
||||
|
||||
/// The browser host's logic tick: run queued UI actions, tick the shared app, poll API replies, flush Render
|
||||
/// Queue downloads, persist the session snapshot when enabled, publish GPU/frame-worker/disk-cache info and close
|
||||
/// the IME pass.
|
||||
/// Queue downloads, persist the session snapshot when enabled, publish GPU/frame-worker/disk-cache info, close
|
||||
/// the IME pass and run the root window's close path.
|
||||
fn logic(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
|
||||
let actions = ACTIONS.with(|a| std::mem::take(&mut *a.borrow_mut()));
|
||||
for f in actions {
|
||||
@@ -146,6 +146,7 @@ impl eframe::App for WebApp {
|
||||
diskcache::configure(d.disk_cache_enabled, d.disk_cache_max_gb, storage::quota());
|
||||
api::set_info("diskCache", diskcache::stats());
|
||||
self.app.finish_ime_logic(ctx);
|
||||
self.app.close_path(ctx);
|
||||
}
|
||||
|
||||
fn ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame) {
|
||||
@@ -277,6 +278,7 @@ pub async fn start(canvas_id: String) -> Result<(), JsValue> {
|
||||
canvas,
|
||||
eframe::WebOptions::default(),
|
||||
Box::new(move |cc| {
|
||||
effectcraft_ui_egui::framework::install_headless(&cc.egui_ctx);
|
||||
EffectcraftApp::install_ime_reset_hooks(&cc.egui_ctx);
|
||||
CTX.with(|c| *c.borrow_mut() = Some(cc.egui_ctx.clone()));
|
||||
// The page owns this shared presentation device; worker devices retain their
|
||||
|
||||
@@ -445,6 +445,7 @@ fn run_desktop(reporter: &crash_report::Shutdown, arguments: &[std::ffi::OsStrin
|
||||
effectcraft_ui_egui::channel::name_for(effectcraft_ui_egui::channel::identity()),
|
||||
options,
|
||||
Box::new(move |cc| {
|
||||
effectcraft_ui_egui::framework::install(&cc.egui_ctx)?;
|
||||
EffectcraftApp::install_ime_reset_hooks(&cc.egui_ctx);
|
||||
match &cc.wgpu_render_state {
|
||||
Some(rs) => {
|
||||
@@ -716,7 +717,7 @@ struct Desktop {
|
||||
|
||||
impl eframe::App for Desktop {
|
||||
/// The desktop host's logic tick: update the macOS menu bar, run the shared app tick, close the IME pass, show the
|
||||
/// file dialogs asked for and, last, hand a close to the platform quit.
|
||||
/// file dialogs asked for and, last, the root window's close path.
|
||||
fn logic(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
|
||||
#[cfg(target_os = "macos")]
|
||||
self.menu_sync.before(&mut self.app, |app| self.menu.update(app, ctx));
|
||||
@@ -728,7 +729,7 @@ impl eframe::App for Desktop {
|
||||
if let Some(asked) = &self.file_dialogs {
|
||||
file_dialogs::show_asked(asked, frame, ctx);
|
||||
}
|
||||
effectcraft_ui_egui::panels::unsaved::quit_on_close(ctx);
|
||||
self.app.close_path(ctx);
|
||||
}
|
||||
|
||||
fn ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame) {
|
||||
|
||||
@@ -2,7 +2,4 @@ allow-unwrap-in-tests = true
|
||||
allow-expect-in-tests = true
|
||||
allow-panic-in-tests = true
|
||||
allow-indexing-slicing-in-tests = true
|
||||
disallowed-types = [
|
||||
{ path = "egui::ComboBox", reason = "use craft_ui::ComboBox: egui's combo box menu can't grow back while open (egui#5225)" },
|
||||
]
|
||||
cognitive-complexity-threshold = 30
|
||||
@@ -10,7 +10,7 @@ rust-version.workspace = true
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
craft-cms = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "58964adec11197594d9b6b79a94ae6232221211a" }
|
||||
craft-cms = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "8fa4db64a9bb943520259ea95331a303ba788f21" }
|
||||
effectcraft-geom = { workspace = true }
|
||||
effectcraft-color = { workspace = true }
|
||||
effectcraft-keyframe = { workspace = true }
|
||||
|
||||
@@ -10,7 +10,6 @@ rust-version.workspace = true
|
||||
workspace = true
|
||||
|
||||
[dependencies]
|
||||
craft-audio-markers = { package = "craft-audio", version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "30596f73c5ef851ba3dad9cf145669f391e2eb0d", default-features = false }
|
||||
craft-docpath = { workspace = true }
|
||||
effectcraft-time = { workspace = true }
|
||||
effectcraft-color = { workspace = true }
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//! WAV cue/adtl/RF64/XMP metadata is parsed by craft-audio; timeline policy remains here.
|
||||
use craft_audio_markers::wav_markers as shared;
|
||||
use craft_audio::wav_markers as shared;
|
||||
use effectcraft_color::Label;
|
||||
use effectcraft_project::Marker;
|
||||
use effectcraft_time::Tick;
|
||||
|
||||
@@ -440,7 +440,7 @@ mod tests {
|
||||
// The decoded image has already taken four pixels from this budget.
|
||||
let mut pixels_left = 4;
|
||||
let mut warnings = vec![];
|
||||
let clamped = cm::TextureRef { image: 0, uv_set: 0, wrap: [cm::Wrap::Clamp; 2] };
|
||||
let clamped = cm::TextureRef { image: 0, uv_set: 0, wrap: [cm::Wrap::Clamp; 2], transform: None };
|
||||
|
||||
let first = ensure_texture(&scene, &decoded, clamped, &mut textures, &mut texture_of, &mut pixels_left, &mut warnings).unwrap();
|
||||
let shared = ensure_texture(&scene, &decoded, clamped, &mut textures, &mut texture_of, &mut pixels_left, &mut warnings).unwrap();
|
||||
|
||||
@@ -12,7 +12,11 @@ workspace = true
|
||||
[dependencies]
|
||||
craft-mime = { workspace = true }
|
||||
craft-ui = { workspace = true }
|
||||
craft-quit = { workspace = true, features = ["egui"] }
|
||||
craft-behavior = { workspace = true }
|
||||
craft-host = { workspace = true }
|
||||
craft-keymap = { workspace = true, features = ["egui"] }
|
||||
craft-theme = { workspace = true }
|
||||
craft-window = { workspace = true }
|
||||
effectcraft-time = { workspace = true }
|
||||
effectcraft-geom = { workspace = true }
|
||||
effectcraft-color = { workspace = true }
|
||||
@@ -40,7 +44,7 @@ bytemuck = { workspace = true }
|
||||
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
# Floating panels open in OS windows of their own on desktop; the web keeps them in the page.
|
||||
craft-ui = { workspace = true, features = ["native-windows"] }
|
||||
craft-ui = { workspace = true }
|
||||
craft-update = { workspace = true }
|
||||
# Waits for the display pass's error scopes (immediately ready on native wgpu).
|
||||
pollster = { workspace = true }
|
||||
|
||||
@@ -225,7 +225,10 @@ fn main() {
|
||||
fn play(session: effectcraft_engine::Session, cid: ItemId, secs: f64, gpu: bool) {
|
||||
use effectcraft_ui_egui::{ControlRequest, EffectcraftApp};
|
||||
let (tx, rx) = std::sync::mpsc::channel::<ControlRequest>();
|
||||
let builder = egui_kittest::Harness::builder().with_size(egui::vec2(1920.0, 1200.0)).with_pixels_per_point(1.0);
|
||||
let builder = egui_kittest::Harness::builder()
|
||||
.with_size(egui::vec2(1920.0, 1200.0))
|
||||
.with_pixels_per_point(1.0)
|
||||
.with_context_setup(effectcraft_ui_egui::framework::install_headless);
|
||||
let builder = if gpu { builder.wgpu() } else { builder };
|
||||
let mut h = builder.build_eframe(move |_| EffectcraftApp::new(session).with_control(rx));
|
||||
{
|
||||
|
||||
@@ -103,6 +103,7 @@ fn main() {
|
||||
.with_size(egui::vec2(args.size.0, args.size.1))
|
||||
.with_pixels_per_point(args.scale)
|
||||
.wgpu()
|
||||
.with_context_setup(effectcraft_ui_egui::framework::install_headless)
|
||||
.build_eframe(move |_cc| EffectcraftApp::new(session).with_control(rx));
|
||||
settle(&mut harness, args.settle);
|
||||
for step in &args.steps {
|
||||
|
||||
@@ -122,12 +122,15 @@ impl EffectcraftApp {
|
||||
native_viewports: vec![],
|
||||
unpublished_viewports: vec![],
|
||||
pending_panel_raise: None,
|
||||
live_dock: Default::default(),
|
||||
home_thumbs: Default::default(),
|
||||
home_thumb_saved: None,
|
||||
window_title: String::new(),
|
||||
template_thumbs: Default::default(),
|
||||
template_list: None,
|
||||
updates_rt: updates_ui::Runtime::default(),
|
||||
framework_dialogs: craft_ui::dialog::DialogHost::new(),
|
||||
framework_host: crate::framework::host(),
|
||||
}
|
||||
.with_ui_commands()
|
||||
}
|
||||
@@ -158,10 +161,12 @@ impl eframe::App for EffectcraftApp {
|
||||
}
|
||||
}
|
||||
|
||||
/// Feed pending synthetic input into `raw_input` only once fonts are ready (so a non-drawing pass never consumes
|
||||
/// Hand the runtime this frame's root values (`before_input`), then feed pending synthetic input into `raw_input`
|
||||
/// only once fonts are ready (so a non-drawing pass never consumes
|
||||
/// a batch), then prepare pointer wrapping; ending a numeric scrub clears the history merge key so the next edit
|
||||
/// starts a new undo step.
|
||||
fn raw_input_hook(&mut self, ctx: &egui::Context, raw_input: &mut egui::RawInput) {
|
||||
self.before_input(ctx);
|
||||
raw_input.events.append(&mut self.forwarded.events);
|
||||
raw_input.dropped_files.append(&mut self.forwarded.files);
|
||||
let injected = self.synthetic_in_flight || !self.synthetic.is_empty();
|
||||
@@ -177,19 +182,19 @@ impl eframe::App for EffectcraftApp {
|
||||
}
|
||||
}
|
||||
|
||||
/// The logic-only tick: run `tick`, close the IME pass with `finish_ime_logic` and, last, hand a close to the
|
||||
/// platform quit (`panels::unsaved::quit_on_close`). It does not read pass-time
|
||||
/// input state (events, pointer and time are stale here), only the viewport information eframe refreshed.
|
||||
/// The logic-only tick: run `tick`, close the IME pass with `finish_ime_logic` and, last, the root window's close
|
||||
/// path (`close_path`, which asks about unsaved changes, and on macOS quits through the platform). It does not
|
||||
/// read pass-time input state (events, pointer and time are stale here), only the viewport information eframe
|
||||
/// refreshed. A close request must be answered while hidden too; an answered file dialog can change the project,
|
||||
/// so the tick's dialog answers run first.
|
||||
fn logic(&mut self, ctx: &egui::Context, frame: &mut eframe::Frame) {
|
||||
// Never `ctx.input(|i| i.time)` here: `Context::run_logic` leaves events, pointer state and
|
||||
// time at the previous full pass's values (only the viewport information is refreshed).
|
||||
self.tick(ctx, frame);
|
||||
self.finish_ime_logic(ctx);
|
||||
crate::panels::unsaved::quit_on_close(ctx);
|
||||
self.logic_pass(ctx, frame);
|
||||
}
|
||||
|
||||
/// Draw one UI pass through `draw`.
|
||||
fn ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame) {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
crate::framework::before_ui(ui.ctx(), &*frame);
|
||||
self.draw(ui, frame);
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,7 @@ mod copy_frame_tests {
|
||||
session.execute("layer.newSolid", json!({"color": "#ff0000"})).unwrap();
|
||||
let mut app = EffectcraftApp::new(session);
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
let mut output = ctx.run_ui(egui::RawInput::default(), |ui| {
|
||||
crate::menus::invoke(&mut app, ui.ctx(), "comp.copyFrame", json!({})).unwrap();
|
||||
app.handle_events(ui.ctx());
|
||||
@@ -52,6 +53,7 @@ mod copy_frame_tests {
|
||||
#[test]
|
||||
fn a_malformed_image_is_an_error_not_a_crash() {
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
let mut output = ctx.run_ui(egui::RawInput::default(), |ui| {
|
||||
assert!(copy_image(ui.ctx(), 4, 4, &[0; 10]).is_err());
|
||||
assert!(copy_image(ui.ctx(), 0, 4, &[]).is_err());
|
||||
|
||||
@@ -122,11 +122,6 @@ impl EffectcraftApp {
|
||||
}
|
||||
});
|
||||
}
|
||||
// Do not interpret a close as permission to abandon the still-running script. Once
|
||||
// Stop finishes it, the normal unsaved-changes prompt can handle a new close request.
|
||||
if ctx.input(|i| i.viewport().close_requested()) {
|
||||
ctx.send_viewport_cmd(egui::ViewportCommand::CancelClose);
|
||||
}
|
||||
self.drain_control(ctx, self.now);
|
||||
ctx.request_repaint_after(std::time::Duration::from_millis(50));
|
||||
}
|
||||
@@ -172,6 +167,15 @@ impl EffectcraftApp {
|
||||
}
|
||||
}
|
||||
|
||||
/// The shared app's `App::logic`: `tick`, the IME pass's close and, last, the root window's close path.
|
||||
pub(crate) fn logic_pass(&mut self, ctx: &egui::Context, frame: &eframe::Frame) {
|
||||
// Never `ctx.input(|i| i.time)` here: `Context::run_logic` leaves events, pointer state and
|
||||
// time at the previous full pass's values (only the viewport information is refreshed).
|
||||
self.tick(ctx, frame);
|
||||
self.finish_ime_logic(ctx);
|
||||
self.close_path(ctx);
|
||||
}
|
||||
|
||||
/// The app's only non-paint entry: one tick of background work.
|
||||
///
|
||||
/// This runs for every eframe logic callback, including the logic-only ticks of a hidden
|
||||
@@ -187,9 +191,6 @@ impl EffectcraftApp {
|
||||
self.apply_gpu_failure(ctx);
|
||||
if self.gpu_failure_applied == Some(true) {
|
||||
self.close_after_device_loss(ctx);
|
||||
// On macOS the app quits through `-[NSApplication terminate:]` instead of closing the
|
||||
// window while AppKit's run loop is running (#341).
|
||||
craft_quit::on_close_request(ctx);
|
||||
return;
|
||||
}
|
||||
if self.session.script_ui.render_host.is_some() {
|
||||
@@ -281,10 +282,6 @@ impl EffectcraftApp {
|
||||
self.tick_script_render(ctx);
|
||||
return;
|
||||
}
|
||||
// A close request (the window's button, Quit, `app.quit`) must be answered while hidden.
|
||||
// An answered file dialog can change the project, so the answers above run first. The host
|
||||
// calls `panels::unsaved::quit_on_close` last in its `logic`.
|
||||
panels::unsaved::on_close_requested(self, ctx);
|
||||
let title = panels::unsaved::window_title(self);
|
||||
if title != self.window_title {
|
||||
ctx.send_viewport_cmd(egui::ViewportCommand::Title(title.clone()));
|
||||
@@ -321,7 +318,7 @@ impl EffectcraftApp {
|
||||
// A hidden window paints when work needs a UI pass: queued input and waits, a settled
|
||||
// screenshot, or playback into a child viewport.
|
||||
let focused = self.focused;
|
||||
let child_viewports = !self.ui.dock.layout.floating.is_empty() || prefs_live::video_preview_active(self, focused);
|
||||
let child_viewports = !self.ui.dock.layout().floating.is_empty() || prefs_live::video_preview_active(self, focused);
|
||||
let paint = self.want_paint
|
||||
|| !self.synthetic.is_empty()
|
||||
|| !self.input_waiters.is_empty()
|
||||
@@ -494,6 +491,7 @@ impl EffectcraftApp {
|
||||
if let Some(rect) = crate::color_picker::take_automation(&ctx) {
|
||||
self.auto.add("colorPicker.eyedropper", rect, "Eyedropper");
|
||||
}
|
||||
crate::framework::return_window_keys(&ctx);
|
||||
let tab_had_widget_focus = ctx.egui_wants_keyboard_input();
|
||||
menus::handle_shortcuts(self, &ctx);
|
||||
if !ctx.input(|i| i.pointer.primary_down()) {
|
||||
@@ -544,6 +542,7 @@ impl EffectcraftApp {
|
||||
panels::learn::coach(self, &ctx);
|
||||
let lift = panels::media_panels::import_card(self, ui, full);
|
||||
self.draw_toast(ui, full, lift);
|
||||
self.framework_dialogs.run(ui);
|
||||
}
|
||||
|
||||
/// Workspace-layout auto-save: a background write that also runs while hidden, once the
|
||||
@@ -763,6 +762,7 @@ mod tests {
|
||||
let mut app = EffectcraftApp::new(effectcraft_engine::Session::default());
|
||||
app.session.events.push(effectcraft_engine::Event::Toast { message: "Earlier background error".into(), error: true });
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
app.handle_events(&ctx);
|
||||
app.report_import_errors("file.import", &json!({"errors":["Later import error"]}));
|
||||
ctx.run_ui(egui::RawInput::default(), |ui| app.draw_toast(ui, ui.max_rect(), 0.0)).textures_delta.clear();
|
||||
@@ -793,6 +793,7 @@ mod tests {
|
||||
app.report_import_errors("file.import", &json!({"errors":[first, "Earlier details"]}));
|
||||
app.report_import_errors("file.import", &json!({"errors":[first, "Later details"]}));
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
ctx.run_ui(egui::RawInput::default(), |ui| app.draw_toast(ui, ui.max_rect(), 0.0)).textures_delta.clear();
|
||||
let r = app.auto.elements.iter().find(|e| e.id == "toast").unwrap().rect;
|
||||
let pos = egui::pos2(r[0] + 4.0, r[1] + 4.0);
|
||||
@@ -816,6 +817,7 @@ mod tests {
|
||||
let mut app = EffectcraftApp::new(effectcraft_engine::Session::default());
|
||||
app.session.events.extend((0..40).map(|i| effectcraft_engine::Event::Toast { message: format!("Error {i}"), error: true }));
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
app.handle_events(&ctx);
|
||||
assert!(app.error_toasts.len() <= 32);
|
||||
assert_eq!(app.error_toasts.front().unwrap().message, "Error 0");
|
||||
@@ -843,6 +845,7 @@ mod tests {
|
||||
effectcraft_engine::Event::Toast { message: "Second.vectorcraft failed".into(), error: true },
|
||||
]);
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
app.handle_events(&ctx);
|
||||
ctx.run_ui(egui::RawInput::default(), |ui| app.draw_toast(ui, ui.max_rect(), 0.0)).textures_delta.clear();
|
||||
assert!(app.auto.elements.iter().any(|e| e.id == "toast" && e.label.contains("First.vectorcraft")));
|
||||
@@ -878,6 +881,7 @@ mod tests {
|
||||
app.ui.status = "First foreground status".into();
|
||||
app.session.events.push(effectcraft_engine::Event::Toast { message: "An unseen import error".into(), error: true });
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
app.handle_events(&ctx);
|
||||
ctx.run_ui(egui::RawInput::default(), |ui| app.draw_toast(ui, ui.max_rect(), 0.0)).textures_delta.clear();
|
||||
app.ui.status = "Another foreground status".into();
|
||||
@@ -895,6 +899,7 @@ mod tests {
|
||||
app.ui.status = "A local drop failed".into();
|
||||
app.session.events.push(effectcraft_engine::Event::Toast { message: "A later background import failed".into(), error: true });
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
app.handle_events(&ctx);
|
||||
ctx.run_ui(egui::RawInput::default(), |ui| app.draw_toast(ui, ui.max_rect(), 0.0)).textures_delta.clear();
|
||||
let click = |app: &mut EffectcraftApp| {
|
||||
@@ -929,6 +934,7 @@ mod tests {
|
||||
let mut app = EffectcraftApp::new(effectcraft_engine::Session::default());
|
||||
app.session.events.push(effectcraft_engine::Event::Toast { message: "An earlier error".into(), error: true });
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
app.handle_events(&ctx);
|
||||
ctx.run_ui(egui::RawInput::default(), |ui| app.draw_toast(ui, ui.max_rect(), 0.0)).textures_delta.clear();
|
||||
app.ui.status = "An unrelated later status".into();
|
||||
@@ -946,6 +952,7 @@ mod tests {
|
||||
app.report_import_errors("file.import", &json!({"errors": ["first failed file", "second failed file"]}));
|
||||
app.session.events.push(effectcraft_engine::Event::Toast { message: "Sequence has missing frames".into(), error: false });
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
app.handle_events(&ctx);
|
||||
ctx.run_ui(egui::RawInput::default(), |ui| app.draw_toast(ui, ui.max_rect(), 0.0)).textures_delta.clear();
|
||||
assert!(app.auto.elements.iter().any(|e| e.id == "toast" && e.label.contains("second failed file")));
|
||||
@@ -958,6 +965,7 @@ mod tests {
|
||||
app.ui.status = "A foreground status".into();
|
||||
app.toast = Some(("Saved".into(), 0.0));
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
for now in [0.0, 3.0, 6.0, 6.1] {
|
||||
app.now = now;
|
||||
app.auto.elements.clear();
|
||||
@@ -973,6 +981,7 @@ mod tests {
|
||||
app.toast = Some(("An old toast".into(), 0.0));
|
||||
app.now = 8.0;
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
ctx.run_ui(egui::RawInput::default(), |ui| app.draw_toast(ui, ui.max_rect(), 0.0)).textures_delta.clear();
|
||||
assert!(app.auto.elements.iter().all(|e| !e.label.contains("old toast")));
|
||||
app.ui.status.clear();
|
||||
@@ -988,6 +997,7 @@ mod tests {
|
||||
app.ui.status = "A local drop failed".into();
|
||||
app.session.events.push(effectcraft_engine::Event::Toast { message: "Imported 1 item. Failed first file\nFailed second file".into(), error: true });
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
app.handle_events(&ctx);
|
||||
for now in [0.0, 3.0, 6.0] {
|
||||
app.now = now;
|
||||
|
||||
@@ -17,10 +17,9 @@ impl EffectcraftApp {
|
||||
ctx.set_theme(theme::theme_preference(&p.appearance.appearance_mode, self.ui.theme.is_light()));
|
||||
let tips = p.general.show_tool_tips;
|
||||
ctx.all_styles_mut(|s| s.interaction.tooltip_delay = if tips { 0.5 } else { f32::INFINITY });
|
||||
// Settings ▸ Appearance ▸ UI Scale (#284). egui's own Ctrl+= / Ctrl+- / Ctrl+0 zoom stays
|
||||
// off: Ctrl+0 is Window ▸ Project, and the scale is a setting.
|
||||
ctx.options_mut(|o| o.zoom_with_keyboard = false);
|
||||
ctx.set_zoom_factor(p.appearance.ui_scale as f32 / 100.0);
|
||||
// Settings ▸ Appearance ▸ UI Scale (#284) is the runtime's root scale (`frame_input`), which
|
||||
// writes the zoom factor; egui's own Ctrl+= / Ctrl+- / Ctrl+0 zoom is off under the runtime
|
||||
// (Ctrl+0 is Window ▸ Project).
|
||||
self.ui.cache_when_idle = p.previews.cache_frames_when_idle;
|
||||
self.ui.viewer.fast_preview = p.previews.fast_previews;
|
||||
// No limit of its own below the common budget on the desktop, the browser's cap there:
|
||||
@@ -129,6 +128,7 @@ mod appearance_tests {
|
||||
#[test]
|
||||
fn auto_mode_leaves_the_native_window_following_the_system() {
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
let mut app = app();
|
||||
app.hooks.system_theme = Some(Box::new(|_| Some(egui::Theme::Light)));
|
||||
app.set_pref("appearance.appearanceMode", json!("auto")).unwrap();
|
||||
|
||||
@@ -206,7 +206,7 @@ impl EffectcraftApp {
|
||||
fn drain_completed_screenshots(&mut self, geom: DrawGeometry) {
|
||||
let mut i = 0;
|
||||
while i < self.pending_screenshots.len() {
|
||||
let taken = self.pending_screenshots.get(i).and_then(|s| s.slot.as_ref()).and_then(craft_ui::capture::CaptureSlot::take);
|
||||
let taken = self.pending_screenshots.get(i).and_then(|s| s.slot.as_ref()).and_then(crate::capture::CaptureSlot::take);
|
||||
let Some(result) = taken else {
|
||||
i += 1;
|
||||
continue;
|
||||
@@ -324,7 +324,7 @@ impl EffectcraftApp {
|
||||
continue;
|
||||
}
|
||||
};
|
||||
let (slot, callback) = craft_ui::capture::CaptureSlot::new(ctx, egui::ViewportId::ROOT, MAX_SHOT_BYTES);
|
||||
let (slot, callback) = crate::capture::CaptureSlot::new(ctx, egui::ViewportId::ROOT, MAX_SHOT_BYTES);
|
||||
ctx.send_viewport_cmd(egui::ViewportCommand::Screenshot(callback));
|
||||
let s = &mut self.pending_screenshots[i];
|
||||
s.slot = Some(slot);
|
||||
@@ -356,7 +356,7 @@ mod tests {
|
||||
assert!(app.session.refuse_export(&text).is_ok());
|
||||
let (tx, rx) = std::sync::mpsc::channel();
|
||||
app.admit_screenshot(&ctx, Some(text.clone()), ShotTarget::Window, tx);
|
||||
let (slot, callback) = craft_ui::capture::CaptureSlot::new(&ctx, egui::ViewportId::ROOT, MAX_SHOT_BYTES);
|
||||
let (slot, callback) = crate::capture::CaptureSlot::new(&ctx, egui::ViewportId::ROOT, MAX_SHOT_BYTES);
|
||||
let shot = app.pending_screenshots.last_mut().unwrap();
|
||||
shot.issued = Some(geom);
|
||||
shot.slot = Some(slot);
|
||||
|
||||
@@ -256,10 +256,15 @@ impl EffectcraftApp {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
/// The LUT generation is process-wide: a test that changes a LUT file moves it for every
|
||||
/// viewer in the process, so the tests that read frame keys run one at a time.
|
||||
static LUT_GENERATION: std::sync::Mutex<()> = std::sync::Mutex::new(());
|
||||
|
||||
/// #3493: the viewer shows the frame again once the LUT file it was graded with changes,
|
||||
/// though its key was otherwise the same (same project revision, frame and options).
|
||||
#[test]
|
||||
fn the_viewer_shows_a_lut_file_changed_on_disk() {
|
||||
let _serial = LUT_GENERATION.lock().unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let lut = dir.path().join("viewer.cube");
|
||||
let write = |text: &str, secs: u64| {
|
||||
@@ -273,7 +278,10 @@ mod tests {
|
||||
session.execute("layer.newSolid", serde_json::json!({"color": "#808080"})).unwrap();
|
||||
session.execute("effect.apply", serde_json::json!({"layer": 1, "effect": "Apply Color LUT"})).unwrap();
|
||||
session.execute("prop.set", serde_json::json!({"layer": 1, "path": "effects/#1/lut", "value": lut.to_string_lossy()})).unwrap();
|
||||
let mut harness = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_eframe(|_| crate::EffectcraftApp::new(session));
|
||||
let mut harness = egui_kittest::Harness::builder()
|
||||
.with_size(egui::vec2(1200.0, 800.0))
|
||||
.with_context_setup(crate::framework::install_headless)
|
||||
.build_eframe(|_| crate::EffectcraftApp::new(session));
|
||||
let centre = |h: &egui_kittest::Harness<'_, crate::EffectcraftApp>| {
|
||||
h.state().viewer_image.as_ref().map(|img| img.pixels[img.pixels.len() / 2 + img.size[0] / 2].r())
|
||||
};
|
||||
@@ -299,6 +307,7 @@ mod tests {
|
||||
/// frame having the key of the one on screen. A reload's purge gives the frames new keys, once.
|
||||
#[test]
|
||||
fn the_viewers_show_a_still_reloaded_at_the_same_size() {
|
||||
let _serial = LUT_GENERATION.lock().unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let png = dir.path().join("still.png");
|
||||
let save = |rgb: [u8; 3]| image::RgbaImage::from_pixel(64, 36, image::Rgba([rgb[0], rgb[1], rgb[2], 255])).save(&png).unwrap();
|
||||
@@ -308,7 +317,10 @@ mod tests {
|
||||
let cid = session.active_comp_id().unwrap();
|
||||
let item = session.execute("file.import", serde_json::json!({"paths": [png.to_string_lossy()]})).unwrap()["items"][0].clone();
|
||||
session.execute("layer.addItem", serde_json::json!({"item": item})).unwrap();
|
||||
let mut harness = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_eframe(|_| crate::EffectcraftApp::new(session));
|
||||
let mut harness = egui_kittest::Harness::builder()
|
||||
.with_size(egui::vec2(1200.0, 800.0))
|
||||
.with_context_setup(crate::framework::install_headless)
|
||||
.build_eframe(|_| crate::EffectcraftApp::new(session));
|
||||
let centre = |h: &egui_kittest::Harness<'_, crate::EffectcraftApp>| {
|
||||
h.state().viewer_image.as_ref().map(|img| img.pixels[img.pixels.len() / 2 + img.size[0] / 2].r())
|
||||
};
|
||||
|
||||
@@ -101,22 +101,23 @@ impl EffectcraftApp {
|
||||
}
|
||||
.filter(|q| self.ui.dock.is_open(*q));
|
||||
let mut workspace = self.ui.dock.clone();
|
||||
let known = workspace.hidden.iter().any(|(q, _)| *q == p);
|
||||
let known = workspace.hidden().iter().any(|(q, _)| *q == p);
|
||||
let opened = if p == PanelKind::Composition && near.is_none() && !known && self.ui.dock.is_docked(PanelKind::Timeline) {
|
||||
workspace
|
||||
.apply(
|
||||
craft_ui::docking::Action::OpenAt {
|
||||
panel: p,
|
||||
anchor: PanelKind::Timeline,
|
||||
placement: craft_ui::docking::Placement::Split(craft_ui::docking::Zone::Top),
|
||||
},
|
||||
craft_behavior::dock::Action::open_at(
|
||||
p,
|
||||
PanelKind::Timeline,
|
||||
craft_behavior::dock::DockPlacement::Split(craft_behavior::DockSide::Top),
|
||||
),
|
||||
self.ui.dock_locked,
|
||||
dock::permissions,
|
||||
)
|
||||
.map(|_| ())
|
||||
} else if known {
|
||||
workspace.set_visible(p, true, near, dock::permissions)
|
||||
workspace.set_visible(p, true, near, self.ui.dock_locked, dock::permissions)
|
||||
} else {
|
||||
workspace.apply(craft_ui::docking::Action::Open { panel: p, anchor: near }, dock::permissions).map(|_| ())
|
||||
workspace.apply(craft_behavior::dock::Action::open(p, near), self.ui.dock_locked, dock::permissions).map(|_| ())
|
||||
};
|
||||
match opened {
|
||||
Ok(()) => self.ui.dock = workspace,
|
||||
@@ -126,7 +127,7 @@ impl EffectcraftApp {
|
||||
}
|
||||
}
|
||||
}
|
||||
let _ = self.ui.dock.apply(craft_ui::docking::Action::Activate { panel: p }, dock::permissions);
|
||||
let _ = self.ui.dock.apply(craft_behavior::dock::Action::activate(p), self.ui.dock_locked, dock::permissions);
|
||||
if self.ui.dock.is_floating(p) {
|
||||
self.pending_panel_raise = Some(p);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,9 @@ pub struct Driver {
|
||||
|
||||
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 }
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
Driver { ctx, app, frame: eframe::Frame::_new_kittest(), time: 0.0, size }
|
||||
}
|
||||
|
||||
/// Run one frame (layout + paint + tessellation); its wall time in ms.
|
||||
@@ -30,10 +32,11 @@ impl Driver {
|
||||
|
||||
pub fn step_with(&mut self, events: Vec<egui::Event>) -> f64 {
|
||||
self.time += 1.0 / 60.0;
|
||||
let input =
|
||||
let mut 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);
|
||||
eframe::App::raw_input_hook(app, &self.ctx, &mut input);
|
||||
let mut out = self.ctx.run_ui(input, |ui| {
|
||||
eframe::App::logic(app, ui.ctx(), frame);
|
||||
eframe::App::ui(app, ui, frame);
|
||||
|
||||
@@ -0,0 +1,211 @@
|
||||
//! One-shot completion slots for `ui.screenshot` captures.
|
||||
//!
|
||||
//! The app keeps request ids, paths, deadlines, settling and budgets in its request record
|
||||
//! (`control::PendingShot`). A slot only correlates one capture with one record, checks the image against
|
||||
//! a per-image byte bound, and wakes the owning viewport.
|
||||
//!
|
||||
//! [`CaptureSlot::new`] sends nothing: send its callback with [`egui::ViewportCommand::Screenshot`]
|
||||
//! when the capture is due. The callback holds only a weak reference to the slot, so dropping the
|
||||
//! slot releases its image and makes a late result inert. Every retry needs a
|
||||
//! fresh slot and callback.
|
||||
//!
|
||||
//! The slot holds a strong [`egui::Context`]: keep it in the app's request record, never in
|
||||
//! `Context`-owned data, which would form a cycle.
|
||||
|
||||
use std::mem::size_of;
|
||||
use std::sync::{Arc, Mutex, MutexGuard, PoisonError, Weak};
|
||||
|
||||
use egui::{Color32, ColorImage, Context, ScreenshotCallback, ViewportId};
|
||||
|
||||
/// Why a completed screenshot was rejected and released.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub(crate) enum CaptureError {
|
||||
/// The checked pixel count, or its byte count, overflowed `usize`.
|
||||
DimensionsOverflow { width: usize, height: usize },
|
||||
/// The pixel buffer does not match the dimensions, or the image has no area.
|
||||
MalformedImage { width: usize, height: usize, pixels: usize },
|
||||
/// The image is larger than the slot's per-image byte bound.
|
||||
ImageTooLarge { bytes: usize, max_bytes: usize },
|
||||
}
|
||||
|
||||
impl core::fmt::Display for CaptureError {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
match self {
|
||||
Self::DimensionsOverflow { width, height } => {
|
||||
write!(f, "screenshot dimensions {width}×{height} overflow the checked pixel or byte count")
|
||||
}
|
||||
Self::MalformedImage { width, height, pixels } => write!(f, "screenshot has {pixels} pixels for its {width}×{height} dimensions"),
|
||||
Self::ImageTooLarge { bytes, max_bytes } => write!(f, "screenshot uses {bytes} bytes, over the {max_bytes}-byte per-image limit"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for CaptureError {}
|
||||
|
||||
enum SlotState {
|
||||
Pending,
|
||||
Ready(Result<Arc<ColorImage>, CaptureError>),
|
||||
Taken,
|
||||
Cancelled,
|
||||
}
|
||||
|
||||
struct Shared {
|
||||
state: Mutex<SlotState>,
|
||||
/// The live request owns the strong context; the callback only upgrades it briefly to wake.
|
||||
context: Context,
|
||||
viewport: ViewportId,
|
||||
max_image_bytes: usize,
|
||||
}
|
||||
|
||||
/// The live request side of a capture. Dropping it cancels the completion and releases any
|
||||
/// retained image.
|
||||
#[must_use = "the slot must be kept alive to receive and take the screenshot"]
|
||||
pub(crate) struct CaptureSlot {
|
||||
shared: Arc<Shared>,
|
||||
}
|
||||
|
||||
impl CaptureSlot {
|
||||
/// A completion slot for a capture of `viewport` and its one-shot callback. `max_image_bytes`
|
||||
/// bounds this one image; the app reserves its aggregate budget itself.
|
||||
pub(crate) fn new(context: &Context, viewport: ViewportId, max_image_bytes: usize) -> (Self, ScreenshotCallback) {
|
||||
let shared = Arc::new(Shared { state: Mutex::new(SlotState::Pending), context: context.clone(), viewport, max_image_bytes });
|
||||
let weak = Arc::downgrade(&shared);
|
||||
let callback = ScreenshotCallback::new(move |image| complete(&weak, image));
|
||||
(Self { shared }, callback)
|
||||
}
|
||||
|
||||
/// The completed result, at most once; `None` while pending and after an
|
||||
/// earlier take. The request record knows which.
|
||||
pub(crate) fn take(&self) -> Option<Result<Arc<ColorImage>, CaptureError>> {
|
||||
let mut state = lock(&self.shared.state);
|
||||
if !matches!(&*state, SlotState::Ready(_)) {
|
||||
return None;
|
||||
}
|
||||
match core::mem::replace(&mut *state, SlotState::Taken) {
|
||||
SlotState::Ready(result) => Some(result),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for CaptureSlot {
|
||||
fn drop(&mut self) {
|
||||
close(&self.shared);
|
||||
}
|
||||
}
|
||||
|
||||
impl core::fmt::Debug for CaptureSlot {
|
||||
/// The viewport only: logging never holds or dumps screenshot contents.
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
f.debug_struct("CaptureSlot").field("viewport", &self.shared.viewport).finish_non_exhaustive()
|
||||
}
|
||||
}
|
||||
|
||||
/// Locks the slot state, recovering from poisoning. Release the guard before calling into the
|
||||
/// context: a repaint observer may take or cancel re-entrantly.
|
||||
fn lock(state: &Mutex<SlotState>) -> MutexGuard<'_, SlotState> {
|
||||
state.lock().unwrap_or_else(PoisonError::into_inner)
|
||||
}
|
||||
|
||||
/// Marks the slot closed; the retained image drops after the mutex is released.
|
||||
fn close(shared: &Shared) {
|
||||
let previous = {
|
||||
let mut state = lock(&shared.state);
|
||||
core::mem::replace(&mut *state, SlotState::Cancelled)
|
||||
};
|
||||
drop(previous);
|
||||
}
|
||||
|
||||
/// Checks and stores a completed image, then wakes the owning viewport, with the slot lock
|
||||
/// released. A cancelled, taken or dropped slot stores nothing and does not wake.
|
||||
fn complete(weak: &Weak<Shared>, image: Arc<ColorImage>) {
|
||||
let Some(shared) = weak.upgrade() else { return };
|
||||
let result = checked_image(image, shared.max_image_bytes);
|
||||
let wake = {
|
||||
let mut state = lock(&shared.state);
|
||||
if matches!(&*state, SlotState::Pending) {
|
||||
*state = SlotState::Ready(result);
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
};
|
||||
if wake {
|
||||
shared.context.request_repaint_of(shared.viewport);
|
||||
}
|
||||
}
|
||||
|
||||
/// `image` when it has area, its buffer matches its size, and its byte count (checked) is within
|
||||
/// `max_image_bytes`.
|
||||
fn checked_image(image: Arc<ColorImage>, max_image_bytes: usize) -> Result<Arc<ColorImage>, CaptureError> {
|
||||
let [width, height] = image.size;
|
||||
if width == 0 || height == 0 {
|
||||
return Err(CaptureError::MalformedImage { width, height, pixels: image.pixels.len() });
|
||||
}
|
||||
let pixels = width.checked_mul(height).ok_or(CaptureError::DimensionsOverflow { width, height })?;
|
||||
let bytes = pixels.checked_mul(size_of::<Color32>()).ok_or(CaptureError::DimensionsOverflow { width, height })?;
|
||||
if image.pixels.len() != pixels {
|
||||
return Err(CaptureError::MalformedImage { width, height, pixels: image.pixels.len() });
|
||||
}
|
||||
if bytes > max_image_bytes {
|
||||
return Err(CaptureError::ImageTooLarge { bytes, max_bytes: max_image_bytes });
|
||||
}
|
||||
Ok(image)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn image(size: [usize; 2]) -> Arc<ColorImage> {
|
||||
Arc::new(ColorImage::filled(size, Color32::RED))
|
||||
}
|
||||
|
||||
fn observe_repaints(ctx: &Context) -> Arc<Mutex<Vec<ViewportId>>> {
|
||||
let requests = Arc::new(Mutex::new(Vec::new()));
|
||||
let observed = requests.clone();
|
||||
ctx.set_repaint_observer(move |info| observed.lock().unwrap().push(info.viewport_id));
|
||||
requests
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_completion_wakes_its_viewport_and_is_taken_once() {
|
||||
let ctx = Context::default();
|
||||
let requests = observe_repaints(&ctx);
|
||||
let viewport = ViewportId::from_hash_of("window");
|
||||
let (slot, callback) = CaptureSlot::new(&ctx, viewport, 1024);
|
||||
assert!(slot.take().is_none(), "pending");
|
||||
let shot = image([2, 1]);
|
||||
callback.complete(shot.clone());
|
||||
assert!(Arc::ptr_eq(&slot.take().unwrap().unwrap(), &shot));
|
||||
assert!(slot.take().is_none(), "taken once");
|
||||
assert_eq!(*requests.lock().unwrap(), [viewport]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_dropped_slot_releases_a_late_image_without_waking() {
|
||||
let ctx = Context::default();
|
||||
let requests = observe_repaints(&ctx);
|
||||
let (slot, callback) = CaptureSlot::new(&ctx, ViewportId::ROOT, 1024);
|
||||
drop(slot);
|
||||
let late = image([2, 2]);
|
||||
let weak = Arc::downgrade(&late);
|
||||
callback.complete(late);
|
||||
assert!(weak.upgrade().is_none());
|
||||
assert!(requests.lock().unwrap().is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn oversized_malformed_and_overflowing_images_are_errors() {
|
||||
let ctx = Context::default();
|
||||
let (slot, callback) = CaptureSlot::new(&ctx, ViewportId::ROOT, 16);
|
||||
callback.complete(image([3, 3]));
|
||||
assert!(matches!(slot.take(), Some(Err(CaptureError::ImageTooLarge { bytes: 36, max_bytes: 16 }))));
|
||||
let (slot, callback) = CaptureSlot::new(&ctx, ViewportId::ROOT, 1024);
|
||||
callback.complete(Arc::new(ColorImage { size: [2, 2], source_size: egui::Vec2::ZERO, pixels: vec![Color32::RED; 3] }));
|
||||
assert!(matches!(slot.take(), Some(Err(CaptureError::MalformedImage { width: 2, height: 2, pixels: 3 }))));
|
||||
let (slot, callback) = CaptureSlot::new(&ctx, ViewportId::ROOT, 1024);
|
||||
callback.complete(Arc::new(ColorImage { size: [usize::MAX, 2], source_size: egui::Vec2::ZERO, pixels: Vec::new() }));
|
||||
assert!(matches!(slot.take(), Some(Err(CaptureError::DimensionsOverflow { .. }))));
|
||||
}
|
||||
}
|
||||
@@ -674,7 +674,10 @@ mod tests {
|
||||
let mut session = effectcraft_engine::Session::default();
|
||||
session.execute("comp.new", serde_json::json!({"width": 320, "height": 180, "duration": 2})).unwrap();
|
||||
session.execute("layer.newSolid", serde_json::json!({"color": "#204060"})).unwrap();
|
||||
let mut harness = egui_kittest::Harness::builder().with_size(vec2(1200.0, 800.0)).build_eframe(|_| crate::EffectcraftApp::new(session));
|
||||
let mut harness = egui_kittest::Harness::builder()
|
||||
.with_size(vec2(1200.0, 800.0))
|
||||
.with_context_setup(crate::framework::install_headless)
|
||||
.build_eframe(|_| crate::EffectcraftApp::new(session));
|
||||
settle_sampling_viewer(&mut harness);
|
||||
harness
|
||||
}
|
||||
@@ -751,7 +754,10 @@ mod tests {
|
||||
let lid = s.execute("layer.newSolid", serde_json::json!({"color": "#ffffff"})).unwrap()["layer"].as_u64().unwrap();
|
||||
s.execute("effect.apply", serde_json::json!({"layers": [lid], "effect": "Exposure"})).unwrap();
|
||||
s.execute("prop.set", serde_json::json!({"layer": lid, "path": "effects/#1/master/exposure", "value": 2.0})).unwrap();
|
||||
let mut harness = egui_kittest::Harness::builder().with_size(vec2(1200.0, 800.0)).build_eframe(|_| crate::EffectcraftApp::new(s));
|
||||
let mut harness = egui_kittest::Harness::builder()
|
||||
.with_size(vec2(1200.0, 800.0))
|
||||
.with_context_setup(crate::framework::install_headless)
|
||||
.build_eframe(|_| crate::EffectcraftApp::new(s));
|
||||
for _ in 0..400 {
|
||||
harness.step();
|
||||
if harness.state().frames.inflight() == 0 && harness.state().viewer_f16.is_some() {
|
||||
@@ -840,6 +846,7 @@ mod tests {
|
||||
#[test]
|
||||
fn a_picker_can_sample_behind_its_own_dialog_but_not_a_new_modal() {
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
let point = pos2(20.0, 20.0);
|
||||
let mut output = ctx.run_ui(egui::RawInput { events: vec![egui::Event::PointerMoved(point)], ..Default::default() }, |ui| {
|
||||
let ctx = ui.ctx();
|
||||
|
||||
@@ -813,9 +813,9 @@ pub fn base64(data: &[u8]) -> String {
|
||||
pub fn inspect(app: &EffectcraftApp, ctx: &egui::Context) -> Value {
|
||||
// A logic-only tick refreshes the viewport information but not `InputState`'s screen rect.
|
||||
let size = ctx.input(|i| i.viewport().inner_rect).map_or_else(|| ctx.content_rect().size(), |r| r.size());
|
||||
let keyboard_focus = ctx.memory(|m| m.focused()).map(|id| {
|
||||
let response = ctx.read_response(id);
|
||||
let rect = response.as_ref().map(|r| [r.rect.min.x, r.rect.min.y, r.rect.width(), r.rect.height()]);
|
||||
let keyboard_focus = craft_ui::runtime::access::focused_node(ctx).or_else(|| ctx.memory(|m| m.focused())).map(|id| {
|
||||
let automation = app.auto.elements.iter().chain(app.auto.previous.iter()).find(|e| e.response_id == Some(id));
|
||||
let rect = ctx.read_response(id).map(|r| [r.rect.min.x, r.rect.min.y, r.rect.width(), r.rect.height()]).or_else(|| automation.map(|e| e.rect));
|
||||
// The registry names screen elements independently of egui's internal ids. Report
|
||||
// exact rectangle matches rather than guessing which enclosing panel owns focus.
|
||||
let candidates: Vec<&str> = app
|
||||
@@ -825,7 +825,7 @@ pub fn inspect(app: &EffectcraftApp, ctx: &egui::Context) -> Value {
|
||||
.filter(|e| rect.is_some_and(|r| e.rect.iter().zip(r).all(|(a, b)| (*a - b).abs() < 0.01)))
|
||||
.map(|e| e.id.as_str())
|
||||
.collect();
|
||||
let automation_id = app.auto.elements.iter().chain(app.auto.previous.iter()).find(|e| e.response_id == Some(id)).map(|e| e.id.as_str());
|
||||
let automation_id = automation.map(|e| e.id.as_str());
|
||||
json!({"id": format!("{:016x}", id.value()), "rect": rect, "automationId": automation_id, "registryCandidates": candidates})
|
||||
});
|
||||
let mut ui = json!(app.ui);
|
||||
|
||||
@@ -253,7 +253,7 @@ pub fn contributors_ui(ui: &mut egui::Ui, auto: &mut Registry) {
|
||||
}
|
||||
ui.separator();
|
||||
ui.label(tr("Sort"));
|
||||
let combo = craft_ui::ComboBox::from_id_salt("credits_sort").selected_text(tr(v.key.label().0)).show_ui(ui, |ui| {
|
||||
let combo = egui::ComboBox::from_id_salt("credits_sort").selected_text(tr(v.key.label().0)).show_ui(ui, |ui| {
|
||||
for k in SortKey::ALL {
|
||||
let r = ui.selectable_label(v.key == k, tr(k.label().0));
|
||||
auto.add(&format!("about.credits.sort.{}", k.id()), r.rect, k.label().0);
|
||||
|
||||
+59
-237
@@ -1,14 +1,14 @@
|
||||
//! EffectCraft's panels and built-in workspaces in craft-ui's shared docking model
|
||||
//! ([`craft_ui::docking`]): splits, tab groups, After Effects' stacked panels and floating
|
||||
//! windows. craft-ui owns the layout model, its validation and every transaction; EffectCraft
|
||||
//! owns the panel ids, the built-in workspaces and the decorations of its tabs (the comp tabs of
|
||||
//! the Timeline, label swatches and viewer locks).
|
||||
//! owns the panel ids, the built-in workspaces and the viewer locks in its group headers.
|
||||
|
||||
use egui::{Align2, Rect, Sense, Stroke, pos2, vec2};
|
||||
use egui::{Align2, Rect, Sense, pos2, vec2};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub use craft_ui::docking::{Floating, Node, PanelState, Permissions, StackEntry};
|
||||
pub use craft_ui::layout::{SplitAxis, SplitSize};
|
||||
pub use craft_behavior::dock::SplitSize;
|
||||
pub use craft_behavior::dock::{Floating, Node, PanelState, Permissions, StackEntry};
|
||||
pub use craft_behavior::flow::Axis;
|
||||
|
||||
use crate::icons::{self, Icon};
|
||||
use crate::theme::Tokens;
|
||||
@@ -172,9 +172,9 @@ impl PanelKind {
|
||||
}
|
||||
|
||||
/// The docked tree plus floating windows.
|
||||
pub type Layout = craft_ui::docking::Layout<PanelKind>;
|
||||
pub type Layout = craft_behavior::dock::Layout<PanelKind>;
|
||||
/// What a workspace saves: the layout, closed panels with where each goes back, and the lock.
|
||||
pub type Workspace = craft_ui::docking::Workspace<PanelKind>;
|
||||
pub type Workspace = craft_behavior::dock::Workspace<PanelKind>;
|
||||
|
||||
/// What may happen to a panel. Every panel moves, floats and closes, as in After Effects
|
||||
/// (the Composition panel too: Window ▸ Composition reopens it); the last docked group staying
|
||||
@@ -185,25 +185,34 @@ pub fn permissions(_panel: &PanelKind) -> Permissions {
|
||||
|
||||
/// A tab group.
|
||||
pub fn tabs(p: &[PanelKind], active: usize) -> Node<PanelKind> {
|
||||
Node::Tabs { panels: p.to_vec(), active }
|
||||
Node::tabs(p.to_vec(), active)
|
||||
}
|
||||
/// Stacked panels: (panel, open, height). Open entries share the stack's height in proportion to
|
||||
/// their heights; an entry without one counts as craft-ui's `DockStyle::min_pane` (40).
|
||||
/// their heights; an entry without one shares the stack's height with the others.
|
||||
pub fn stack(e: &[(PanelKind, bool, Option<f32>)]) -> Node<PanelKind> {
|
||||
Node::Stack { entries: e.iter().map(|&(panel, open, height)| StackEntry { panel, open, height }).collect() }
|
||||
Node::stack(
|
||||
e.iter()
|
||||
.map(|&(panel, open, height)| {
|
||||
let mut entry = StackEntry::new(panel);
|
||||
entry.open = open;
|
||||
entry.height = height;
|
||||
entry
|
||||
})
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
/// Two frames side by side.
|
||||
pub fn hsplit(size: SplitSize, a: Node<PanelKind>, b: Node<PanelKind>) -> Node<PanelKind> {
|
||||
Node::Split { axis: SplitAxis::Horizontal, size, first: Box::new(a), second: Box::new(b) }
|
||||
Node::split(Axis::X, size, a, b)
|
||||
}
|
||||
/// Two frames one above the other.
|
||||
pub fn vsplit(size: SplitSize, a: Node<PanelKind>, b: Node<PanelKind>) -> Node<PanelKind> {
|
||||
Node::Split { axis: SplitAxis::Vertical, size, first: Box::new(a), second: Box::new(b) }
|
||||
Node::split(Axis::Y, size, a, b)
|
||||
}
|
||||
|
||||
/// A workspace of just `root`, with no floating windows.
|
||||
pub fn docked(root: Node<PanelKind>) -> Workspace {
|
||||
Workspace::new(Layout { root: Some(root), floating: Vec::new() })
|
||||
Workspace::new(Layout::new(Some(root), Vec::new()))
|
||||
}
|
||||
|
||||
/// The built-in workspaces: After Effects 2026's (Window ▸ Workspace), less Libraries (an Adobe
|
||||
@@ -233,7 +242,7 @@ pub const WORKSPACES: &[&str] = &[
|
||||
/// id, so a built-in layout built again is the same set of windows.
|
||||
fn workspace_floating(name: &str) -> Vec<Floating<PanelKind>> {
|
||||
use PanelKind::*;
|
||||
let f = |id: u64, panels: &[PanelKind], rect: [f32; 4]| Floating::single(panels.to_vec(), 0, rect).with_id(id);
|
||||
let f = |id: u64, panels: &[PanelKind], [x, y, w, h]: [f32; 4]| Floating::single(id, panels.to_vec(), 0, Rect::from_min_size(pos2(x, y), vec2(w, h)));
|
||||
match name {
|
||||
"Undocked Panels" => vec![
|
||||
f(1, &[Project, EffectControls], [24.0, 110.0, 320.0, 420.0]),
|
||||
@@ -246,14 +255,14 @@ fn workspace_floating(name: &str) -> Vec<Floating<PanelKind>> {
|
||||
}
|
||||
|
||||
/// The height of a frame's tab strip ([`Tokens::tab_h`]).
|
||||
pub const TAB_STRIP: f32 = 30.0;
|
||||
pub const TAB_STRIP: f32 = 28.0;
|
||||
/// The height of Default's Preview frame: its tab strip over a 46-point body that fits the
|
||||
/// playback controls.
|
||||
pub const PREVIEW_FRAME: f32 = TAB_STRIP + 46.0;
|
||||
|
||||
/// The built-in layout of a named workspace (an unknown name gets Default's).
|
||||
pub fn workspace(name: &str) -> Layout {
|
||||
Layout { root: Some(workspace_root(name)), floating: workspace_floating(name) }
|
||||
Layout::new(Some(workspace_root(name)), workspace_floating(name))
|
||||
}
|
||||
|
||||
/// The docked tree of a named workspace.
|
||||
@@ -430,7 +439,7 @@ pub(crate) fn node_panels(node: &Node<PanelKind>, out: &mut Vec<PanelKind>) {
|
||||
node_panels(second, out);
|
||||
}
|
||||
Node::Tabs { panels, .. } => out.extend(panels.iter().copied()),
|
||||
Node::Stack { entries } => out.extend(entries.iter().map(|e| e.panel)),
|
||||
Node::Stack { entries, .. } => out.extend(entries.iter().map(|e| e.panel)),
|
||||
Node::Dock { columns, .. } => {
|
||||
for group in columns.iter().flat_map(|c| c.groups.iter()) {
|
||||
out.extend(group.panels.iter().copied());
|
||||
@@ -444,7 +453,7 @@ fn node_group(node: &Node<PanelKind>, p: PanelKind) -> Option<Vec<PanelKind>> {
|
||||
match node {
|
||||
Node::Split { first, second, .. } => node_group(first, p).or_else(|| node_group(second, p)),
|
||||
Node::Tabs { panels, .. } => panels.contains(&p).then(|| panels.clone()),
|
||||
Node::Stack { entries } => entries.iter().any(|e| e.panel == p).then(|| vec![p]),
|
||||
Node::Stack { entries, .. } => entries.iter().any(|e| e.panel == p).then(|| vec![p]),
|
||||
Node::Dock { columns, .. } => columns.iter().flat_map(|c| c.groups.iter()).find(|g| g.panels.contains(&p)).map(|g| g.panels.clone()),
|
||||
_ => None,
|
||||
}
|
||||
@@ -452,25 +461,33 @@ fn node_group(node: &Node<PanelKind>, p: PanelKind) -> Option<Vec<PanelKind>> {
|
||||
|
||||
impl WorkspaceExt for Workspace {
|
||||
fn is_docked(&self, p: PanelKind) -> bool {
|
||||
self.layout.root.as_ref().is_some_and(|root| node_group(root, p).is_some())
|
||||
self.layout().root.as_ref().is_some_and(|root| node_group(root, p).is_some())
|
||||
}
|
||||
fn is_floating(&self, p: PanelKind) -> bool {
|
||||
self.layout.floating.iter().any(|w| w.contains(&p))
|
||||
self.layout().floating.iter().any(|w| w.contains(&p))
|
||||
}
|
||||
fn is_open(&self, p: PanelKind) -> bool {
|
||||
self.layout.contains(&p)
|
||||
self.layout().contains(&p)
|
||||
}
|
||||
fn is_visible(&self, p: PanelKind) -> bool {
|
||||
self.layout.panel_state(&p) == PanelState::Front
|
||||
self.layout().panel_state(&p) == PanelState::Front
|
||||
}
|
||||
fn group_of(&self, p: PanelKind) -> Vec<PanelKind> {
|
||||
self.layout.root.iter().chain(self.layout.floating.iter().map(|w| &w.root)).find_map(|node| node_group(node, p)).unwrap_or_default()
|
||||
let layout = self.layout();
|
||||
layout
|
||||
.root
|
||||
.as_ref()
|
||||
.and_then(|root| node_group(root, p))
|
||||
.or_else(|| layout.floating.iter().flat_map(|w| w.groups()).find(|g| g.panels.contains(&p)).map(|g| g.panels.clone()))
|
||||
.unwrap_or_default()
|
||||
}
|
||||
fn panels(&self) -> Vec<PanelKind> {
|
||||
let layout = self.layout();
|
||||
let mut out = Vec::new();
|
||||
for node in self.layout.root.iter().chain(self.layout.floating.iter().map(|w| &w.root)) {
|
||||
node_panels(node, &mut out);
|
||||
if let Some(root) = &layout.root {
|
||||
node_panels(root, &mut out);
|
||||
}
|
||||
out.extend(layout.floating.iter().flat_map(|w| w.panels().copied()));
|
||||
out
|
||||
}
|
||||
}
|
||||
@@ -478,201 +495,7 @@ impl WorkspaceExt for Workspace {
|
||||
/// Every panel a workspace names: open, or closed with a recorded place.
|
||||
pub fn referenced_panels(workspace: &Workspace) -> Vec<PanelKind> {
|
||||
let mut out = workspace.panels();
|
||||
out.extend(workspace.hidden.iter().map(|(p, _)| *p));
|
||||
if let Some(saved) = &workspace.saved {
|
||||
for node in saved.root.iter().chain(saved.floating.iter().map(|w| &w.root)) {
|
||||
node_panels(node, &mut out);
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// The automation id of the gap below stacked panel `p`: `dock.gutter.<path>s<i>`, with the
|
||||
/// stack's split path (`a`/`b` per level) and the entry's index.
|
||||
pub fn stack_gutter_id(layout: &Layout, p: PanelKind) -> Option<String> {
|
||||
fn rec(node: &Node<PanelKind>, p: PanelKind, path: &mut String, depth: usize) -> Option<String> {
|
||||
if depth > craft_ui::docking::MAX_DEPTH {
|
||||
return None;
|
||||
}
|
||||
match node {
|
||||
Node::Split { first, second, .. } => {
|
||||
path.push('a');
|
||||
if let Some(id) = rec(first, p, path, depth + 1) {
|
||||
return Some(id);
|
||||
}
|
||||
path.pop();
|
||||
path.push('b');
|
||||
let found = rec(second, p, path, depth + 1);
|
||||
path.pop();
|
||||
found
|
||||
}
|
||||
Node::Stack { entries } => entries.iter().position(|e| e.panel == p).map(|i| format!("dock.gutter.{path}s{i}")),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
rec(layout.root.as_ref()?, p, &mut String::new(), 0)
|
||||
}
|
||||
|
||||
/// One document a panel shows as a tab of its own (the Timeline: one tab per open comp, as in
|
||||
/// After Effects).
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct DocTab {
|
||||
pub id: u64,
|
||||
pub title: String,
|
||||
/// The comp's label colour.
|
||||
pub swatch: egui::Color32,
|
||||
/// The document the panel shows now.
|
||||
pub active: bool,
|
||||
}
|
||||
|
||||
/// What the Timeline's comp tabs did this frame.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum DocAction {
|
||||
/// Show comp `id`.
|
||||
Activate(u64),
|
||||
/// Close comp `id`'s Timeline (its ×, or a middle click).
|
||||
Close(u64),
|
||||
}
|
||||
|
||||
/// Room around a tab's label, as craft-ui gives its dock tabs.
|
||||
const TAB_PADDING: f32 = 24.0;
|
||||
/// Width of the » button that lists the comp tabs with no room in the strip.
|
||||
const DOC_OVERFLOW: f32 = 22.0;
|
||||
/// Room for the × after a comp's name. Every comp tab keeps it, so a tab keeps its width when it
|
||||
/// is shown or hovered.
|
||||
const DOC_CLOSE: f32 = 16.0;
|
||||
|
||||
/// A comp tab's text: the label swatch, then the name, as the panel tabs with a swatch show it.
|
||||
fn doc_job(doc: &DocTab, font: &egui::FontId, color: egui::Color32) -> egui::text::LayoutJob {
|
||||
let mut job = egui::text::LayoutJob::default();
|
||||
job.append("\u{25a0} ", 0.0, egui::TextFormat::simple(font.clone(), doc.swatch));
|
||||
job.append(&doc.title, 0.0, egui::TextFormat::simple(font.clone(), color));
|
||||
job
|
||||
}
|
||||
|
||||
/// The width of one line of `job` at the fonts' current size.
|
||||
fn text_width(ctx: &egui::Context, job: egui::text::LayoutJob) -> f32 {
|
||||
ctx.fonts_mut(|f| f.layout_job(job)).size().x
|
||||
}
|
||||
|
||||
/// The width each comp tab asks for in the Timeline group's tab row.
|
||||
pub fn doc_widths(ctx: &egui::Context, docs: &[DocTab], font: &egui::FontId) -> Vec<f32> {
|
||||
docs.iter().map(|d| text_width(ctx, doc_job(d, font, egui::Color32::WHITE)) + TAB_PADDING + DOC_CLOSE).collect()
|
||||
}
|
||||
|
||||
/// The × of comp tab `doc` at `rect`, clipped to `clip`; true when clicked. `shown` is the comp
|
||||
/// the Timeline shows while it is the group's shown panel. Automation:
|
||||
/// `panel.tab.Timeline.<comp>.close`, and `panel.tab.Timeline.close` for the shown comp's.
|
||||
fn doc_close(
|
||||
ui: &mut egui::Ui,
|
||||
rect: Rect,
|
||||
clip: Rect,
|
||||
doc: &DocTab,
|
||||
shown: bool,
|
||||
style: &craft_ui::docking::DockStyle,
|
||||
reg: &mut crate::automation::Registry,
|
||||
) -> bool {
|
||||
let timeline = PanelKind::Timeline.id();
|
||||
let hit = ui.interact(rect.expand(2.0), egui::Id::unique(("comp-tab-close", doc.id)), Sense::click());
|
||||
hit.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, hit.enabled(), "Close"));
|
||||
let cc = if hit.hovered() { style.text } else { style.inactive_text };
|
||||
let k = 3.5;
|
||||
let painter = ui.painter().with_clip_rect(clip);
|
||||
painter.line_segment([rect.center() + vec2(-k, -k), rect.center() + vec2(k, k)], Stroke::new(1.2, cc));
|
||||
painter.line_segment([rect.center() + vec2(-k, k), rect.center() + vec2(k, -k)], Stroke::new(1.2, cc));
|
||||
reg.add_response(&format!("panel.tab.{timeline}.{}.close", doc.id), &hit, "Close");
|
||||
if shown {
|
||||
reg.add_response(&format!("panel.tab.{timeline}.close"), &hit, "Close");
|
||||
}
|
||||
hit.clicked()
|
||||
}
|
||||
|
||||
/// Draw the Timeline's comp tabs into `strip`, the part of the Timeline group's tab row after its
|
||||
/// panel tabs. Each is a tab like the panel tabs: the comp's label swatch and name, then a ×
|
||||
/// that closes the comp's Timeline: always on the shown comp while the Timeline is the group's
|
||||
/// shown panel (`selected`), on the other comp tabs while the pointer is over them. Tabs that do
|
||||
/// not fit go to a » menu at the end; the shown comp's tab always stays in the row. Shift+, and
|
||||
/// Shift+. step through every open comp. Automation: `panel.tab.Timeline.<comp>`, the ×s (see
|
||||
/// [`doc_close`]), `panel.tab.Timeline.more` for », and `panel.tab.Timeline.more.<comp>` for its
|
||||
/// items.
|
||||
pub fn doc_tabs(
|
||||
ui: &mut egui::Ui,
|
||||
strip: Rect,
|
||||
docs: &[DocTab],
|
||||
selected: bool,
|
||||
style: &craft_ui::docking::DockStyle,
|
||||
reg: &mut crate::automation::Registry,
|
||||
) -> Vec<DocAction> {
|
||||
let mut out = Vec::new();
|
||||
let timeline = PanelKind::Timeline.id();
|
||||
let widths = doc_widths(ui.ctx(), docs, &style.font);
|
||||
let active = docs.iter().position(|d| d.active).unwrap_or(0);
|
||||
let fit = craft_ui::tabs::fit_whole(&widths, active, strip.width(), DOC_OVERFLOW);
|
||||
let clip = strip.intersect(ui.clip_rect());
|
||||
let mid = strip.center().y;
|
||||
let mut x = strip.min.x;
|
||||
for (index, width) in &fit.shown {
|
||||
let Some(doc) = docs.get(*index) else { continue };
|
||||
let tab = Rect::from_min_size(pos2(x, strip.min.y), vec2(*width, strip.height()));
|
||||
x += width;
|
||||
let on = selected && doc.active;
|
||||
let color = if on { style.text } else { style.inactive_text };
|
||||
let mut job = doc_job(doc, &style.font, color);
|
||||
job.wrap = egui::text::TextWrapping {
|
||||
max_width: (tab.width() - TAB_PADDING - DOC_CLOSE).max(0.0),
|
||||
max_rows: 1,
|
||||
break_anywhere: true,
|
||||
overflow_character: Some('\u{2026}'),
|
||||
};
|
||||
let galley = ui.fonts_mut(|f| f.layout_job(job));
|
||||
let label_end = tab.min.x + TAB_PADDING * 0.5 + galley.size().x;
|
||||
let resp = craft_ui::tabs::Tab::new(egui::Id::unique(("comp-tab", doc.id)), &doc.title, on).focus_stroke(Stroke::new(1.0, style.accent)).show_at(
|
||||
ui,
|
||||
tab,
|
||||
|ui, response| {
|
||||
let painter = ui.painter().with_clip_rect(tab.intersect(clip));
|
||||
painter.rect_filled(tab, 0.0, if on || response.hovered() { style.active_background } else { style.tab_background });
|
||||
painter.galley(pos2(tab.min.x + TAB_PADDING * 0.5, mid - galley.size().y * 0.5), galley.clone(), color);
|
||||
},
|
||||
);
|
||||
let resp = if galley.elided { resp.on_hover_text(&doc.title) } else { resp };
|
||||
reg.add_response(&format!("panel.tab.{timeline}.{}", doc.id), &resp, &doc.title);
|
||||
// After the tab, so the × takes the clicks over it.
|
||||
if on || ui.rect_contains_pointer(tab.intersect(clip)) {
|
||||
let cr = Rect::from_center_size(pos2(label_end + DOC_CLOSE / 2.0, mid), vec2(10.0, 10.0));
|
||||
if doc_close(ui, cr, tab.intersect(clip), doc, on, style, reg) {
|
||||
out.push(DocAction::Close(doc.id));
|
||||
}
|
||||
}
|
||||
if resp.clicked() {
|
||||
out.push(DocAction::Activate(doc.id));
|
||||
}
|
||||
if resp.middle_clicked() {
|
||||
out.push(DocAction::Close(doc.id));
|
||||
}
|
||||
}
|
||||
if !fit.overflow.is_empty() && fit.overflow_width > 0.0 {
|
||||
let more = Rect::from_min_size(pos2(x, strip.min.y), vec2(fit.overflow_width, strip.height()));
|
||||
let resp = ui.interact(more, egui::Id::unique("comp-tabs-more"), Sense::click());
|
||||
resp.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, resp.enabled(), "More compositions"));
|
||||
reg.add_response(&format!("panel.tab.{timeline}.more"), &resp, "More compositions");
|
||||
let color = if resp.hovered() { style.text } else { style.inactive_text };
|
||||
ui.painter().with_clip_rect(more.intersect(clip)).text(more.center(), Align2::CENTER_CENTER, "\u{bb}", style.font.clone(), color);
|
||||
egui::Popup::menu(&resp).show(|ui| {
|
||||
egui::ScrollArea::vertical().max_height(360.0).show(ui, |ui| {
|
||||
for index in &fit.overflow {
|
||||
let Some(doc) = docs.get(*index) else { continue };
|
||||
let item = ui.button(doc_job(doc, &style.font, style.text));
|
||||
item.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, item.enabled(), &doc.title));
|
||||
reg.add_response(&format!("panel.tab.{timeline}.more.{}", doc.id), &item, &doc.title);
|
||||
if item.clicked() {
|
||||
out.push(DocAction::Activate(doc.id));
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
out.extend(workspace.hidden().iter().map(|(p, _)| *p));
|
||||
out
|
||||
}
|
||||
|
||||
@@ -703,10 +526,11 @@ pub fn placeholder(ui: &mut egui::Ui, rect: Rect, t: &Tokens, text: &str) {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use PanelKind::*;
|
||||
use craft_ui::docking::{Action, Placement, Zone};
|
||||
use craft_behavior::DockSide;
|
||||
use craft_behavior::dock::{Action, DockPlacement};
|
||||
|
||||
fn apply(w: &mut Workspace, action: Action<PanelKind>) {
|
||||
w.apply(action, permissions).unwrap();
|
||||
w.apply(action, false, permissions).unwrap();
|
||||
}
|
||||
|
||||
/// Only the title changes: existing saved workspace layouts still deserialize.
|
||||
@@ -743,7 +567,7 @@ mod tests {
|
||||
}
|
||||
for name in WORKSPACES {
|
||||
let layout = workspace(name);
|
||||
assert!(layout.root.iter().chain(layout.floating.iter().map(|f| &f.root)).all(no_stack), "{name}");
|
||||
assert!(layout.root.iter().all(no_stack), "{name}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -751,15 +575,13 @@ mod tests {
|
||||
fn default_right_column_is_a_short_preview_frame_over_the_properties_frame() {
|
||||
let default = workspace("Default");
|
||||
let Some(Node::Split { second, size: SplitSize::FixedSecond(300.0), .. }) = &default.root else { panic!("{default:?}") };
|
||||
let Node::Split { axis: SplitAxis::Vertical, size: SplitSize::FixedFirst(PREVIEW_FRAME), first, second } = second.as_ref() else {
|
||||
panic!("{second:?}")
|
||||
};
|
||||
let Node::Split { axis: Axis::Y, size: SplitSize::FixedFirst(PREVIEW_FRAME), first, second, .. } = second.as_ref() else { panic!("{second:?}") };
|
||||
assert_eq!(**first, tabs(&[Preview], 0));
|
||||
assert_eq!(**second, tabs(&[Properties, Align, Audio, EffectsPresets], 0));
|
||||
let mut w = Workspace::new(default);
|
||||
assert!(w.is_visible(Preview) && w.is_visible(Properties) && !w.is_visible(Align));
|
||||
// The Properties frame takes tabs; the Preview frame stays a frame of its own.
|
||||
apply(&mut w, Action::Move { panel: Project, anchor: Properties, placement: Placement::Tab { before: None } });
|
||||
apply(&mut w, Action::move_beside(Project, Properties, DockPlacement::tab(None)));
|
||||
assert_eq!(w.group_of(Project), vec![Properties, Align, Audio, EffectsPresets, Project]);
|
||||
assert_eq!(w.group_of(Preview), vec![Preview]);
|
||||
}
|
||||
@@ -767,35 +589,35 @@ mod tests {
|
||||
#[test]
|
||||
fn panels_split_off_and_join_tab_groups() {
|
||||
let mut w = docked(hsplit(SplitSize::FixedFirst(300.0), tabs(&[Project, EffectControls], 0), tabs(&[Composition, Layer], 0)));
|
||||
apply(&mut w, Action::Move { panel: EffectControls, anchor: Composition, placement: Placement::Split(Zone::Right) });
|
||||
apply(&mut w, Action::move_beside(EffectControls, Composition, DockPlacement::Split(DockSide::End)));
|
||||
assert_eq!(w.group_of(EffectControls), vec![EffectControls]);
|
||||
assert_eq!(w.group_of(Project), vec![Project]);
|
||||
apply(&mut w, Action::Move { panel: EffectControls, anchor: Composition, placement: Placement::Tab { before: Some(Layer) } });
|
||||
apply(&mut w, Action::move_beside(EffectControls, Composition, DockPlacement::tab(Some(Layer))));
|
||||
assert_eq!(w.group_of(Composition), vec![Composition, EffectControls, Layer]);
|
||||
assert!(w.is_visible(EffectControls));
|
||||
// A rejected move (onto itself, onto a closed panel) changes nothing.
|
||||
let before = w.clone();
|
||||
assert!(w.apply(Action::Move { panel: Project, anchor: Info, placement: Placement::Split(Zone::Left) }, permissions).is_err());
|
||||
assert!(w.apply(Action::move_beside(Project, Info, DockPlacement::Split(DockSide::Start)), false, permissions).is_err());
|
||||
assert_eq!(w, before);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn closed_panels_reopen_where_they_were_docked_or_floating() {
|
||||
let mut w = Workspace::new(workspace("Standard"));
|
||||
apply(&mut w, Action::Close { panel: Info });
|
||||
apply(&mut w, Action::close(Info));
|
||||
assert!(!w.is_open(Info));
|
||||
w.set_visible(Info, true, None, permissions).unwrap();
|
||||
w.set_visible(Info, true, None, false, permissions).unwrap();
|
||||
assert_eq!(w.group_of(Info), vec![Info, Audio]);
|
||||
apply(&mut w, Action::Float { panel: Audio, rect: [40.0, 50.0, 300.0, 200.0] });
|
||||
apply(&mut w, Action::Close { panel: Audio });
|
||||
w.set_visible(Audio, true, None, permissions).unwrap();
|
||||
apply(&mut w, Action::float(Audio, Rect::from_min_size(pos2(40.0, 50.0), vec2(300.0, 200.0))));
|
||||
apply(&mut w, Action::close(Audio));
|
||||
w.set_visible(Audio, true, None, false, permissions).unwrap();
|
||||
assert!(w.is_floating(Audio));
|
||||
// Closing an earlier, inactive tab keeps the shown panel.
|
||||
let mut w = docked(tabs(&[Properties, Align, EffectsPresets], 2));
|
||||
apply(&mut w, Action::Close { panel: Properties });
|
||||
apply(&mut w, Action::close(Properties));
|
||||
assert!(w.is_visible(EffectsPresets));
|
||||
// A panel never laid out opens beside its anchor.
|
||||
apply(&mut w, Action::Open { panel: History, anchor: Some(Align) });
|
||||
apply(&mut w, Action::open(History, Some(Align)));
|
||||
assert_eq!(w.group_of(History), vec![Align, EffectsPresets, History]);
|
||||
assert_eq!(referenced_panels(&w).iter().filter(|p| **p == Properties).count(), 1, "the closed panel is still known");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,466 @@
|
||||
//! EffectCraft's docking command vocabulary: `window.panel.*` and `ui.dock`, as the control
|
||||
//! channel, the menus and the dock area's own changes write them. Each command becomes the
|
||||
//! craft-behavior layout actions it stands for on the current workspace.
|
||||
|
||||
use craft_behavior::DockSide;
|
||||
use craft_behavior::dock::{Action, DockEdge, DockError, DockPlacement, Layout, PanelPlace, SplitSize, Target, node_at};
|
||||
use craft_ui::docking::FloatSpace;
|
||||
use egui::{Rect, pos2, vec2};
|
||||
use serde::{Deserialize, Deserializer};
|
||||
|
||||
use crate::dock::{Node, PanelKind, Workspace};
|
||||
|
||||
/// A drop zone by name. PascalCase names of the side zones also parse.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum ZoneName {
|
||||
Tab,
|
||||
#[serde(alias = "Center")]
|
||||
Center,
|
||||
#[serde(alias = "Left")]
|
||||
Left,
|
||||
#[serde(alias = "Right")]
|
||||
Right,
|
||||
#[serde(alias = "Top")]
|
||||
Top,
|
||||
#[serde(alias = "Bottom")]
|
||||
Bottom,
|
||||
Above,
|
||||
Below,
|
||||
}
|
||||
|
||||
/// A present field, `null` included: `Some(None)` for `null`, `None` when absent.
|
||||
fn present<'de, D: Deserializer<'de>, T: Deserialize<'de>>(deserializer: D) -> Result<Option<T>, D::Error> {
|
||||
T::deserialize(deserializer).map(Some)
|
||||
}
|
||||
|
||||
/// A required field that may be `null`.
|
||||
fn required<'de, D: Deserializer<'de>, T: Deserialize<'de>>(deserializer: D) -> Result<T, D::Error> {
|
||||
T::deserialize(deserializer)
|
||||
}
|
||||
|
||||
/// A `ui.dock` operation, tagged by `operation`. Rects are `[x, y, width, height]`.
|
||||
#[derive(Clone, Debug, PartialEq, Deserialize)]
|
||||
#[serde(tag = "operation", rename_all = "camelCase")]
|
||||
pub enum DockOperation {
|
||||
Open {
|
||||
panel: PanelKind,
|
||||
},
|
||||
Close {
|
||||
panel: PanelKind,
|
||||
},
|
||||
Activate {
|
||||
panel: PanelKind,
|
||||
},
|
||||
Float {
|
||||
panel: PanelKind,
|
||||
rect: [f32; 4],
|
||||
},
|
||||
MoveFloating {
|
||||
panel: PanelKind,
|
||||
rect: [f32; 4],
|
||||
},
|
||||
/// `zone` defaults to `center`; `before` only applies to a center or tab move.
|
||||
Move {
|
||||
panel: PanelKind,
|
||||
target: PanelKind,
|
||||
#[serde(default)]
|
||||
zone: Option<ZoneName>,
|
||||
#[serde(default, deserialize_with = "present")]
|
||||
before: Option<Option<PanelKind>>,
|
||||
},
|
||||
SetStackOpen {
|
||||
panel: PanelKind,
|
||||
open: bool,
|
||||
},
|
||||
/// `height` is required; `null` clears it.
|
||||
ResizeStack {
|
||||
panel: PanelKind,
|
||||
#[serde(deserialize_with = "required")]
|
||||
height: Option<f32>,
|
||||
},
|
||||
ResizeSplit {
|
||||
path: Vec<bool>,
|
||||
size: SplitSize,
|
||||
},
|
||||
}
|
||||
|
||||
/// `ui.dock`: a raw layout action or an operation.
|
||||
#[derive(Clone, Debug, PartialEq, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
pub enum UiDock {
|
||||
Action { action: Action<PanelKind> },
|
||||
Operation(DockOperation),
|
||||
}
|
||||
|
||||
/// A docking command, tagged by `command` (its id).
|
||||
#[derive(Clone, Debug, PartialEq, Deserialize)]
|
||||
#[serde(tag = "command")]
|
||||
pub enum DockCommand {
|
||||
/// A raw layout action.
|
||||
#[serde(rename = "window.panel.layout")]
|
||||
Layout { action: Action<PanelKind> },
|
||||
/// Move a panel (or its group, with `group`) next to `anchor`; `zone` defaults to `tab`.
|
||||
#[serde(rename = "window.panel.move")]
|
||||
Move {
|
||||
panel: PanelKind,
|
||||
anchor: PanelKind,
|
||||
#[serde(default)]
|
||||
zone: Option<ZoneName>,
|
||||
#[serde(default, deserialize_with = "present")]
|
||||
before: Option<Option<PanelKind>>,
|
||||
#[serde(default)]
|
||||
group: bool,
|
||||
#[serde(default)]
|
||||
placement: Option<DockPlacement<PanelKind>>,
|
||||
},
|
||||
/// Float a panel, its group or its column; given values replace the rect's.
|
||||
#[serde(rename = "window.panel.float")]
|
||||
Float {
|
||||
panel: PanelKind,
|
||||
#[serde(default)]
|
||||
x: Option<f32>,
|
||||
#[serde(default)]
|
||||
y: Option<f32>,
|
||||
#[serde(default)]
|
||||
width: Option<f32>,
|
||||
#[serde(default)]
|
||||
height: Option<f32>,
|
||||
#[serde(default)]
|
||||
group: bool,
|
||||
#[serde(default)]
|
||||
column: bool,
|
||||
},
|
||||
/// Dock a panel: beside `anchor` in `zone` (default `tab`), as the last column of the dock on
|
||||
/// `side`, along an outer edge (a side `zone` alone), or back into the docked layout.
|
||||
#[serde(rename = "window.panel.dock")]
|
||||
Dock {
|
||||
panel: PanelKind,
|
||||
#[serde(default)]
|
||||
anchor: Option<PanelKind>,
|
||||
#[serde(default)]
|
||||
zone: Option<ZoneName>,
|
||||
#[serde(default, deserialize_with = "present")]
|
||||
before: Option<Option<PanelKind>>,
|
||||
#[serde(default)]
|
||||
group: bool,
|
||||
#[serde(default)]
|
||||
column: bool,
|
||||
#[serde(default)]
|
||||
side: Option<DockEdge>,
|
||||
},
|
||||
#[serde(rename = "window.panel.activate")]
|
||||
Activate { panel: PanelKind },
|
||||
#[serde(rename = "window.panel.close")]
|
||||
Close { panel: PanelKind },
|
||||
#[serde(rename = "window.panel.closeGroup")]
|
||||
CloseGroup { panel: PanelKind },
|
||||
#[serde(rename = "window.panel.closeOthers")]
|
||||
CloseOthers { panel: PanelKind },
|
||||
/// Minimize or restore the panel's group; without `minimized` it toggles.
|
||||
#[serde(rename = "window.panel.minimize")]
|
||||
Minimize {
|
||||
panel: PanelKind,
|
||||
#[serde(default)]
|
||||
minimized: Option<bool>,
|
||||
},
|
||||
/// Collapse the panel's column to icons or expand it; without `iconic` it toggles.
|
||||
#[serde(rename = "window.panel.iconic")]
|
||||
Iconic {
|
||||
panel: PanelKind,
|
||||
#[serde(default)]
|
||||
iconic: Option<bool>,
|
||||
},
|
||||
/// The panel in a floating window of its own (`native` true, the default) or docked again.
|
||||
#[serde(rename = "window.panel.window")]
|
||||
Window {
|
||||
panel: PanelKind,
|
||||
#[serde(default)]
|
||||
native: Option<bool>,
|
||||
},
|
||||
#[serde(rename = "ui.dock")]
|
||||
UiDock(UiDock),
|
||||
}
|
||||
|
||||
/// The size a command floats a panel at when the dock has drawn nothing yet.
|
||||
const DEFAULT_FLOAT: egui::Vec2 = vec2(420.0, 320.0);
|
||||
|
||||
/// `[x, y, width, height]` as a rect.
|
||||
pub fn rect_of([x, y, width, height]: [f32; 4]) -> Rect {
|
||||
Rect::from_min_size(pos2(x, y), vec2(width, height))
|
||||
}
|
||||
|
||||
/// How much of the layout a command moves.
|
||||
#[derive(Clone, Copy)]
|
||||
enum Unit {
|
||||
Panel,
|
||||
Group,
|
||||
Column,
|
||||
}
|
||||
|
||||
impl Unit {
|
||||
fn of(group: bool, column: bool) -> Self {
|
||||
if column {
|
||||
Self::Column
|
||||
} else if group {
|
||||
Self::Group
|
||||
} else {
|
||||
Self::Panel
|
||||
}
|
||||
}
|
||||
|
||||
/// The action that moves this unit of `panel` to `to`. A floating panel's column is its whole window.
|
||||
fn to(self, layout: &Layout<PanelKind>, panel: PanelKind, to: Target<PanelKind>) -> Action<PanelKind> {
|
||||
let floating = matches!(layout.place(&panel), Some(PanelPlace::Floating { .. }));
|
||||
match (self, to) {
|
||||
(Self::Panel, Target::At { anchor, placement, .. }) => Action::move_beside(panel, anchor, placement),
|
||||
(Self::Panel, to) => Action::move_panel(panel, to),
|
||||
(Self::Group, to) => Action::move_group(panel, to),
|
||||
(Self::Column, to) if floating => Action::move_window(panel, to),
|
||||
(Self::Column, to) => Action::move_column(panel, to),
|
||||
}
|
||||
}
|
||||
|
||||
/// The panels that move with `panel`.
|
||||
fn members(self, layout: &Layout<PanelKind>, panel: PanelKind) -> Vec<PanelKind> {
|
||||
let place = layout.place(&panel);
|
||||
match self {
|
||||
Self::Panel => vec![panel],
|
||||
Self::Group => match place.as_ref() {
|
||||
Some(PanelPlace::Node(_)) => match place.as_ref().and_then(|place| layout.node_of(place)) {
|
||||
Some(Node::Tabs { panels, .. }) => panels.clone(),
|
||||
_ => vec![panel],
|
||||
},
|
||||
Some(place) => layout.group(place).map(|group| group.panels.clone()).unwrap_or_else(|| vec![panel]),
|
||||
None => vec![panel],
|
||||
},
|
||||
Self::Column => match place.as_ref() {
|
||||
Some(place @ (PanelPlace::Dock { .. } | PanelPlace::Floating { .. })) => {
|
||||
layout.column(place).map(|column| column.panels().copied().collect()).unwrap_or_else(|| vec![panel])
|
||||
}
|
||||
_ => vec![panel],
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Where a command puts what it moves relative to `anchor`: `zone` (default `default`) and
|
||||
/// `before`, with side zones mapped onto the anchor's container by [`DockPlacement::for_zone`].
|
||||
fn placement(
|
||||
layout: &Layout<PanelKind>,
|
||||
anchor: PanelKind,
|
||||
zone: Option<ZoneName>,
|
||||
before: Option<Option<PanelKind>>,
|
||||
default: ZoneName,
|
||||
) -> Result<DockPlacement<PanelKind>, DockError> {
|
||||
let side = |side| DockPlacement::for_zone(layout, &anchor, side);
|
||||
Ok(match (zone.unwrap_or(default), before) {
|
||||
(ZoneName::Tab | ZoneName::Center, Some(before)) => DockPlacement::tab(before),
|
||||
(ZoneName::Tab, None) => DockPlacement::tab(None),
|
||||
(ZoneName::Center, None) => DockPlacement::Split(DockSide::Center),
|
||||
(_, Some(_)) => return Err(DockError::InvalidPlacement),
|
||||
(ZoneName::Left, None) => side(DockSide::Start)?,
|
||||
(ZoneName::Right, None) => side(DockSide::End)?,
|
||||
(ZoneName::Top, None) => side(DockSide::Top)?,
|
||||
(ZoneName::Bottom, None) => side(DockSide::Bottom)?,
|
||||
(ZoneName::Above, None) => DockPlacement::group(false, None),
|
||||
(ZoneName::Below, None) => DockPlacement::group(true, None),
|
||||
})
|
||||
}
|
||||
|
||||
/// The panels of the last column of the dock on `side`, or `None` without such a dock.
|
||||
fn last_column(layout: &Layout<PanelKind>, side: DockEdge) -> Option<Vec<PanelKind>> {
|
||||
let path = layout.dock_path(side)?;
|
||||
match node_at(layout.root.as_ref()?, &path)? {
|
||||
Node::Dock { columns, .. } => Some(columns.last()?.panels().copied().collect()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
impl DockCommand {
|
||||
/// Every `window.panel.*` command id.
|
||||
pub const IDS: &'static [&'static str] = &[
|
||||
"window.panel.layout",
|
||||
"window.panel.move",
|
||||
"window.panel.float",
|
||||
"window.panel.dock",
|
||||
"window.panel.activate",
|
||||
"window.panel.close",
|
||||
"window.panel.closeGroup",
|
||||
"window.panel.closeOthers",
|
||||
"window.panel.minimize",
|
||||
"window.panel.iconic",
|
||||
"window.panel.window",
|
||||
];
|
||||
|
||||
/// The command `id` with `params`. Its own `command` key is set from `id`.
|
||||
pub fn parse(id: &str, params: &serde_json::Value) -> Result<Self, String> {
|
||||
let mut tagged = if params.is_object() { params.clone() } else { serde_json::json!({}) };
|
||||
if let Some(fields) = tagged.as_object_mut() {
|
||||
fields.insert("command".into(), serde_json::json!(id));
|
||||
}
|
||||
serde_json::from_value(tagged).map_err(|error| error.to_string())
|
||||
}
|
||||
|
||||
/// The raw layout action the command carries, if it is one.
|
||||
pub fn raw_action(&self) -> Option<&Action<PanelKind>> {
|
||||
match self {
|
||||
Self::Layout { action } | Self::UiDock(UiDock::Action { action }) => Some(action),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// The panel the command shows: opening or activating it, or docking it back into the layout.
|
||||
pub fn shown(&self) -> Option<PanelKind> {
|
||||
match self {
|
||||
Self::Activate { panel }
|
||||
| Self::Dock { panel, anchor: None, side: None, .. }
|
||||
| Self::UiDock(UiDock::Operation(DockOperation::Open { panel } | DockOperation::Activate { panel })) => Some(*panel),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// The outer edge `window.panel.dock` goes to: a side zone without an anchor or side.
|
||||
pub fn edge(&self) -> Option<DockSide> {
|
||||
match self {
|
||||
Self::Dock { anchor: None, side: None, zone: Some(zone), .. } => match zone {
|
||||
ZoneName::Left => Some(DockSide::Start),
|
||||
ZoneName::Right => Some(DockSide::End),
|
||||
ZoneName::Top => Some(DockSide::Top),
|
||||
ZoneName::Bottom => Some(DockSide::Bottom),
|
||||
_ => None,
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// The layout actions this command makes on `workspace`, to apply all or none. A panel or
|
||||
/// anchor that is not shown is [`DockError::MissingPanel`] or [`DockError::MissingTarget`].
|
||||
/// `space` is where a float without a rect goes: the dock's last [`FloatSpace`].
|
||||
pub fn to_actions(&self, workspace: &Workspace, space: Option<&FloatSpace<PanelKind>>) -> Result<Vec<Action<PanelKind>>, DockError> {
|
||||
let layout = workspace.layout();
|
||||
let shown = |panel: &PanelKind| if layout.contains(panel) { Ok(()) } else { Err(DockError::MissingPanel) };
|
||||
let one = |action: Action<PanelKind>| Ok(vec![action]);
|
||||
match self {
|
||||
Self::Layout { action } | Self::UiDock(UiDock::Action { action }) => one(action.clone()),
|
||||
Self::Move { panel, anchor, zone, before, group, placement: given } => {
|
||||
shown(panel)?;
|
||||
let placement = match given {
|
||||
Some(placement) => placement.clone(),
|
||||
None => placement(layout, *anchor, *zone, *before, ZoneName::Tab)?,
|
||||
};
|
||||
one(Unit::of(*group, false).to(layout, *panel, Target::at(*anchor, placement)))
|
||||
}
|
||||
Self::Float { panel, x, y, width, height, group, column } => {
|
||||
shown(panel)?;
|
||||
let given = [*x, *y, *width, *height];
|
||||
let rect = |base: Rect| {
|
||||
let mut values = [base.min.x, base.min.y, base.width(), base.height()];
|
||||
for (value, given) in values.iter_mut().zip(given) {
|
||||
*value = given.unwrap_or(*value);
|
||||
}
|
||||
rect_of(values)
|
||||
};
|
||||
let unit = Unit::of(*group, *column);
|
||||
let window = layout.floating.iter().find(|window| window.contains(panel));
|
||||
let lone = window.is_some_and(|window| window.panels().count() == 1);
|
||||
let whole = window.is_some_and(|window| window.groups().len() == 1);
|
||||
let placed = || {
|
||||
let size = space.and_then(|space| space.panel(panel)).or(space.map(|space| space.default_size)).unwrap_or(DEFAULT_FLOAT);
|
||||
rect(space.map_or_else(|| Rect::from_center_size(pos2(840.0, 510.0), size), |space| space.place(size)))
|
||||
};
|
||||
match (unit, window.map(|window| window.rect)) {
|
||||
(Unit::Panel, Some(base)) if lone => one(Action::move_floating(*panel, rect(base))),
|
||||
(Unit::Column, Some(base)) => one(Action::move_floating(*panel, rect(base))),
|
||||
(Unit::Group, Some(base)) if whole => one(Action::move_floating(*panel, rect(base))),
|
||||
(Unit::Panel, _) => one(Action::float(*panel, placed())),
|
||||
(unit, _) => one(unit.to(layout, *panel, Target::float(placed()))),
|
||||
}
|
||||
}
|
||||
Self::Dock { panel, anchor, zone, before, group, column, side } => {
|
||||
shown(panel)?;
|
||||
let unit = Unit::of(*group, *column);
|
||||
if let Some(anchor) = anchor {
|
||||
let placement = placement(layout, *anchor, *zone, *before, ZoneName::Tab)?;
|
||||
return one(unit.to(layout, *panel, Target::at(*anchor, placement)));
|
||||
}
|
||||
let members = unit.members(layout, *panel);
|
||||
if let Some(side) = side {
|
||||
let to = match last_column(layout, *side) {
|
||||
Some(column) => match column.into_iter().find(|p| !members.contains(p)) {
|
||||
Some(anchor) => Target::at(anchor, DockPlacement::column(true)),
|
||||
// What moves already is that dock's last column.
|
||||
None => return Ok(Vec::new()),
|
||||
},
|
||||
None => Target::new_dock(*side),
|
||||
};
|
||||
let unit = match (unit, &to) {
|
||||
(Unit::Panel, Target::NewDock { .. }) if Unit::Group.members(layout, *panel).len() == 1 => Unit::Group,
|
||||
(unit, _) => unit,
|
||||
};
|
||||
return one(unit.to(layout, *panel, to));
|
||||
}
|
||||
if let Some(zone) = self.edge() {
|
||||
if before.is_some() {
|
||||
return Err(DockError::InvalidPlacement);
|
||||
}
|
||||
// Every EffectCraft panel moves and closes: no edge narrows to a protected canvas.
|
||||
let anchor = layout.edge_anchor(false, &|_| false, &|p| members.contains(p)).ok_or(DockError::MissingTarget)?;
|
||||
return one(unit.to(layout, *panel, Target::at(anchor, DockPlacement::Edge(zone))));
|
||||
}
|
||||
if !matches!(layout.place(panel), Some(PanelPlace::Floating { .. })) {
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
let anchor = layout
|
||||
.panels()
|
||||
.into_iter()
|
||||
.copied()
|
||||
.filter(|p| !members.contains(p))
|
||||
.find(|p| !matches!(layout.place(p), Some(PanelPlace::Floating { .. })))
|
||||
.ok_or(DockError::MissingTarget)?;
|
||||
one(unit.to(layout, *panel, Target::at(anchor, DockPlacement::tab(None))))
|
||||
}
|
||||
Self::Activate { panel } => {
|
||||
shown(panel)?;
|
||||
one(Action::activate(*panel))
|
||||
}
|
||||
Self::Close { panel } => one(Action::close(*panel)),
|
||||
Self::CloseGroup { panel } => one(Action::close_group(*panel)),
|
||||
Self::CloseOthers { panel } => one(Action::close_others(*panel)),
|
||||
Self::Minimize { panel, minimized } => {
|
||||
let place = layout.place(panel).ok_or(DockError::MissingPanel)?;
|
||||
// An accordion entry is minimized while it is closed.
|
||||
let current = match &place {
|
||||
PanelPlace::Node(path) => match layout.root.as_ref().and_then(|root| node_at(root, path)) {
|
||||
Some(Node::Stack { entries, .. }) => entries.iter().any(|entry| entry.panel == *panel && !entry.open),
|
||||
_ => false,
|
||||
},
|
||||
place => layout.group(place).is_some_and(|group| group.minimized),
|
||||
};
|
||||
one(Action::set_minimized(*panel, minimized.unwrap_or(!current)))
|
||||
}
|
||||
Self::Iconic { panel, iconic } => {
|
||||
let place = layout.place(panel).ok_or(DockError::MissingPanel)?;
|
||||
let current = layout.column(&place).is_some_and(|column| column.iconic);
|
||||
one(Action::set_iconic(*panel, iconic.unwrap_or(!current)))
|
||||
}
|
||||
// A floating window of its own is the app's (`EffectcraftApp::set_panel_window`).
|
||||
Self::Window { .. } => Err(DockError::NotAllowed),
|
||||
Self::UiDock(UiDock::Operation(operation)) => match operation {
|
||||
DockOperation::Open { panel } | DockOperation::Activate { panel } => {
|
||||
shown(panel)?;
|
||||
one(Action::activate(*panel))
|
||||
}
|
||||
DockOperation::Close { panel } => one(Action::close(*panel)),
|
||||
DockOperation::Float { panel, rect } => one(Action::float(*panel, rect_of(*rect))),
|
||||
DockOperation::MoveFloating { panel, rect } => one(Action::move_floating(*panel, rect_of(*rect))),
|
||||
DockOperation::Move { panel, target, zone, before } => {
|
||||
one(Action::move_beside(*panel, *target, placement(layout, *target, *zone, *before, ZoneName::Center)?))
|
||||
}
|
||||
DockOperation::SetStackOpen { panel, open } => one(Action::set_stack_open(*panel, *open)),
|
||||
DockOperation::ResizeStack { panel, height } => one(Action::resize_stack(*panel, *height)),
|
||||
DockOperation::ResizeSplit { path, size } => one(Action::resize_split(path.clone(), *size)),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
+416
-431
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,222 @@
|
||||
//! The craft-ui runtime, hosted from EffectCraft's own eframe `App` (craft-libs docs/craft-framework.md, section 2.2).
|
||||
//! The desktop app calls [`install`] once, [`EffectcraftApp::before_input`] in `raw_input_hook`,
|
||||
//! [`EffectcraftApp::close_path`] last in `logic`, and [`before_ui`] first in `ui`; the browser build and tests
|
||||
//! install with [`install_headless`]. The framework dialogs run on [`EffectcraftApp::framework_dialogs`] after
|
||||
//! EffectCraft's own UI.
|
||||
//!
|
||||
//! The runtime takes Escape, Tab and the clipboard events for the whole window unless one of EffectCraft's own egui
|
||||
//! widgets has the keyboard. [`return_window_keys`] puts the window's Escape back into egui's input for EffectCraft's
|
||||
//! own handlers (the window's plain Enter stays in egui's input); the Composition viewer is declared to the runtime with [`host_canvas`], which keeps
|
||||
//! the edit chords and the clipboard events in egui's input for EffectCraft's shortcuts.
|
||||
|
||||
use std::sync::{Arc, OnceLock};
|
||||
|
||||
use craft_host::target::ShellInfo;
|
||||
use craft_host::{AppInfo, Host};
|
||||
use craft_keymap::Overrides;
|
||||
use craft_ui::fonts::{I18nScripts, SystemFonts, UiFonts};
|
||||
use craft_ui::runtime::commands::{CommandInput, CommandSet as _, NavCommand, QuitCommand};
|
||||
use craft_ui::runtime::env::{RootEnv, Scale};
|
||||
use craft_ui::runtime::focus::{EditSet, KeyUse};
|
||||
use craft_ui::runtime::frame::{FrameInput, FrameOutput};
|
||||
use craft_ui::runtime::keys::{Intent, escape_mods, with_window_intents};
|
||||
use craft_ui::shell::embed::{self, CloseDecision};
|
||||
use craft_window::system::WindowSystem;
|
||||
use egui::ViewportId;
|
||||
|
||||
use crate::EffectcraftApp;
|
||||
|
||||
/// Each pass of the root window, first in `App::ui`: hands the runtime the native window it answers the hit test of
|
||||
/// (Windows) and fits the window to its monitor once.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub use craft_ui::shell::embed::before_ui;
|
||||
|
||||
/// The scripts of the interface languages, for the font stack.
|
||||
static SCRIPTS: I18nScripts = I18nScripts;
|
||||
|
||||
/// The runtime's first font stack: egui's bundled faces and no installed system fonts. EffectCraft's own definitions
|
||||
/// ([`crate::theme::install`]) replace it before anything is drawn.
|
||||
fn ui_fonts() -> UiFonts<'static> {
|
||||
UiFonts::new(&SCRIPTS).system_fonts(SystemFonts::Off)
|
||||
}
|
||||
|
||||
fn install_with(ctx: &egui::Context, shell: ShellInfo, windows: Arc<dyn WindowSystem>) -> Result<(), String> {
|
||||
let spec = craft_ui::InstallSpec::new(shell, windows).app_id(crate::channel::app_id());
|
||||
embed::install(ctx, spec, &ui_fonts()).map(drop).map_err(|error| format!("the UI runtime could not be installed: {error}"))
|
||||
}
|
||||
|
||||
/// Installs the runtime on the desktop window's context, once, before the first pass. EffectCraft keeps the system
|
||||
/// title bar, so the window gets no frame decision.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn install(ctx: &egui::Context) -> Result<(), String> {
|
||||
let shell = ShellInfo::default().backend(craft_host::target::Backend::from_env());
|
||||
install_with(ctx, shell, Arc::new(craft_window::system::SystemWindows))
|
||||
}
|
||||
|
||||
/// Installs the runtime on a context with no native window of its own: the browser build's canvas and test windows.
|
||||
pub fn install_headless(ctx: &egui::Context) {
|
||||
if let Err(error) = install_with(ctx, ShellInfo::default(), Arc::new(craft_window::system::NoWindows)) {
|
||||
log::warn!("{error}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Who EffectCraft is to the framework's dialogs (the update dialogs show its name and icon).
|
||||
pub(crate) fn host() -> Arc<Host> {
|
||||
Arc::new(
|
||||
Host::builder(AppInfo { id: "effectcraft", name: "EffectCraft", version: env!("CARGO_PKG_VERSION") })
|
||||
.icon_png(include_bytes!("../../../assets/app-icon/hicolor/128x128/apps/ai.storyteller.effectcraft.png"))
|
||||
.build(),
|
||||
)
|
||||
}
|
||||
|
||||
/// EffectCraft's own shortcut table keeps the keys the framework binds by default: Cmd+Q is `app.quit`, and F6 is
|
||||
/// free for the user to bind there, so the framework's quit and pane moves are unbound. Overrides are keyed by command
|
||||
/// id, which the command sets give.
|
||||
fn command_overrides() -> Arc<Overrides> {
|
||||
static OVERRIDES: OnceLock<Arc<Overrides>> = OnceLock::new();
|
||||
OVERRIDES
|
||||
.get_or_init(|| {
|
||||
let mut overrides = Overrides::new();
|
||||
for id in [QuitCommand::Quit.id(), NavCommand::NextPane.id(), NavCommand::PreviousPane.id()] {
|
||||
overrides.insert(id, Vec::new());
|
||||
}
|
||||
Arc::new(overrides)
|
||||
})
|
||||
.clone()
|
||||
}
|
||||
|
||||
impl EffectcraftApp {
|
||||
/// The framework's part of `App::raw_input_hook`, once per frame before the first pass: takes what the runtime
|
||||
/// gathered since the last frame and gives the coming passes the root values (theme mode and interface scale).
|
||||
pub fn before_input(&mut self, ctx: &egui::Context) {
|
||||
embed::before_input(ctx, |output| self.frame_input(ctx, output));
|
||||
}
|
||||
|
||||
/// The root values of this frame. EffectCraft registers no commands with the runtime (its own shortcut table runs
|
||||
/// every key, [`command_overrides`]) and lets it toggle no chrome. The one output it acts on is the clipboard
|
||||
/// chords of a window with no canvas ([`clipboard_events`]). The
|
||||
/// interface scale is Settings > Appearance > UI Scale; the runtime writes it to the context. While one of
|
||||
/// EffectCraft's own dialogs or a command's file dialog is up, the runtime blocks the panels floated into windows
|
||||
/// of their own.
|
||||
pub(crate) fn frame_input(&mut self, ctx: &egui::Context, output: FrameOutput) -> FrameInput {
|
||||
self.forwarded.clips.extend(clipboard_events(&output));
|
||||
let mode = if self.tokens.kind.is_light() { craft_theme::Mode::Light } else { craft_theme::Mode::Dark };
|
||||
let scale = self.session.prefs.appearance.ui_scale as f32 / 100.0;
|
||||
let root = RootEnv::new().mode(mode).scale(Scale::new(scale));
|
||||
let app_modal = self.floats_blocked(ctx).then_some(ViewportId::ROOT);
|
||||
FrameInput::new(root).commands(CommandInput::new().overrides(command_overrides())).host(Arc::clone(&self.framework_host)).app_modal(app_modal)
|
||||
}
|
||||
|
||||
/// The framework's part of `App::logic`, after EffectCraft's own: the root window's close path
|
||||
/// ([`crate::panels::unsaved::close_decision`]).
|
||||
pub fn close_path(&mut self, ctx: &egui::Context) {
|
||||
embed::logic(ctx, || crate::panels::unsaved::close_decision(self));
|
||||
}
|
||||
}
|
||||
|
||||
/// The Copy, Cut and Paste the runtime took in a window with no canvas, as the clipboard events that window's chord
|
||||
/// would have been. Only a command a key press fired, and a Paste only with the platform's content, which a key press
|
||||
/// never carries (so a pasted key press cannot run twice). A Copy or Cut from a synthetic key press that egui kept
|
||||
/// as well runs twice. Native only: the web sends the key press with the clipboard event.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn clipboard_events(output: &FrameOutput) -> Vec<egui::Event> {
|
||||
use craft_ui::runtime::commands::{EditCommands, FirePhase, FireSource};
|
||||
output
|
||||
.fired
|
||||
.iter()
|
||||
.filter(|fired| fired.source == FireSource::Key && fired.phase == FirePhase::Press && fired.target.is_none())
|
||||
.filter_map(|fired| match fired.command.id.as_str() {
|
||||
id if id == EditCommands::Copy.id() => Some(egui::Event::Copy),
|
||||
id if id == EditCommands::Cut.id() => Some(egui::Event::Cut),
|
||||
id if id == EditCommands::Paste.id() => fired.pasted.as_ref()?.text.as_ref().map(|text| egui::Event::Paste(text.to_string())),
|
||||
_ => None,
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
fn clipboard_events(_: &FrameOutput) -> Vec<egui::Event> {
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
/// The Composition viewer's widget, its window's document canvas.
|
||||
pub(crate) fn viewer_id() -> egui::Id {
|
||||
egui::Id::unique("viewer-interact")
|
||||
}
|
||||
|
||||
/// Declares the Composition viewer, drawn in this pass, as the window's document canvas. With nothing focused it
|
||||
/// is the window's key target: the edit chords and the clipboard events stay in
|
||||
/// egui's input for EffectCraft's shortcuts. The focused viewer keeps its focus at Escape, which EffectCraft's own
|
||||
/// handlers read from egui.
|
||||
pub(crate) fn host_canvas(ctx: &egui::Context) {
|
||||
const KEYS: KeyUse = KeyUse::CANVAS.with_edits(EditSet::ALL);
|
||||
craft_ui::runtime::focus::host_canvas(ctx, viewer_id(), KEYS);
|
||||
}
|
||||
|
||||
/// The widget other than the Composition viewer that has the keyboard. The viewer as the focused Tab stop leaves the
|
||||
/// keys to EffectCraft, as with nothing focused.
|
||||
pub(crate) fn focused_widget(ctx: &egui::Context) -> Option<egui::Id> {
|
||||
ctx.memory(|m| m.focused()).filter(|id| *id != viewer_id())
|
||||
}
|
||||
|
||||
/// Whether a widget other than the Composition viewer has the keyboard ([`focused_widget`]).
|
||||
pub(crate) fn widget_has_keyboard(ctx: &egui::Context) -> bool {
|
||||
focused_widget(ctx).is_some()
|
||||
}
|
||||
|
||||
/// Puts the window's Escape (the key the runtime routes to no component while nothing has framework focus) back into
|
||||
/// egui's input as a key press, first in the pass, so EffectCraft's dialogs, popups, tools and shortcuts read it from
|
||||
/// egui as they read every other key. The window's plain Enter is its Submit and also stays in egui's input, where
|
||||
/// EffectCraft reads it.
|
||||
pub(crate) fn return_window_keys(ctx: &egui::Context) {
|
||||
if take_window_intent(ctx, Intent::Cancel) {
|
||||
let held = escape_mods(ctx).unwrap_or_default();
|
||||
let modifiers = egui::Modifiers { shift: held.shift, alt: held.alt, ..Default::default() };
|
||||
ctx.input_mut(|i| {
|
||||
i.events.insert(0, egui::Event::Key { key: egui::Key::Escape, physical_key: Some(egui::Key::Escape), pressed: true, repeat: false, modifiers });
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// Takes the window's `intent` when it is there: no later reader sees it.
|
||||
fn take_window_intent(ctx: &egui::Context, intent: Intent) -> bool {
|
||||
let mut taken = false;
|
||||
with_window_intents(ctx, false, |intents| {
|
||||
taken = intents.take(intent.clone());
|
||||
taken
|
||||
});
|
||||
taken
|
||||
}
|
||||
|
||||
/// Whether the close decision is `Close`.
|
||||
pub(crate) fn decide(close: bool) -> CloseDecision {
|
||||
if close { CloseDecision::Close } else { CloseDecision::Hold }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use craft_ui::runtime::commands::{ClipContent, CommandRef, FirePhase, FireSource, Fired};
|
||||
|
||||
fn fired(id: &str, pasted: Option<&str>) -> Fired {
|
||||
let mut fired = Fired::new(CommandRef::new(id), FireSource::Key, FirePhase::Press, 0.0);
|
||||
fired.pasted = pasted.map(|text| {
|
||||
let mut content = ClipContent::default();
|
||||
content.text = Some(text.into());
|
||||
content
|
||||
});
|
||||
fired
|
||||
}
|
||||
|
||||
/// Copy pressed in a window with no canvas reaches the shortcuts once; a Paste with no content of its own is a key
|
||||
/// press the app already reads, and so is any other edit command.
|
||||
#[test]
|
||||
fn clipboard_chords_of_a_window_with_no_canvas_queue_once() {
|
||||
let mut output = FrameOutput::default();
|
||||
output.fired = vec![fired("edit.copy", None), fired("edit.paste", None), fired("edit.undo", None), fired("edit.paste", Some("x"))];
|
||||
let mut app = EffectcraftApp::new(effectcraft_engine::Session::default());
|
||||
let ctx = egui::Context::default();
|
||||
app.frame_input(&ctx, output);
|
||||
assert_eq!(app.forwarded.clips, [egui::Event::Copy, egui::Event::Paste("x".into())]);
|
||||
}
|
||||
}
|
||||
@@ -9347,6 +9347,7 @@ mod tests {
|
||||
fn general_settings_exposes_the_language_automation_id() {
|
||||
let mut app = EffectcraftApp::new(effectcraft_engine::Session::default());
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
let tokens = crate::theme::Tokens::for_kind(crate::theme::ThemeKind::Dark);
|
||||
crate::theme::install(&ctx, &tokens, language(&app));
|
||||
crate::panels::settings::open(&mut app, "general");
|
||||
|
||||
@@ -21,15 +21,18 @@ pub const UPDATE_APP: craft_update::app::App = craft_update::app::App {
|
||||
pub mod audio;
|
||||
pub mod automation;
|
||||
pub mod bench;
|
||||
pub(crate) mod capture;
|
||||
pub mod channel;
|
||||
pub mod color_picker;
|
||||
pub mod control;
|
||||
pub mod credits;
|
||||
pub mod display_gpu;
|
||||
pub mod dock;
|
||||
pub mod dock_command;
|
||||
pub mod dock_ui;
|
||||
mod expression_diagnostics;
|
||||
pub mod frames;
|
||||
pub mod framework;
|
||||
pub mod gpu_failure;
|
||||
pub mod header;
|
||||
pub mod i18n;
|
||||
@@ -104,7 +107,7 @@ struct PendingShot {
|
||||
/// The geometry epoch bound to the issued capture command, if it was issued.
|
||||
issued: Option<DrawGeometry>,
|
||||
/// The shared completion slot; dropping it cancels a late callback.
|
||||
slot: Option<craft_ui::capture::CaptureSlot>,
|
||||
slot: Option<crate::capture::CaptureSlot>,
|
||||
/// Bytes reserved against [`EffectcraftApp::shot_bytes`].
|
||||
reserved_bytes: usize,
|
||||
/// Geometry retries used.
|
||||
@@ -473,6 +476,10 @@ pub struct EffectcraftApp {
|
||||
/// Audio scrubbing's open output (Ctrl/Cmd-drag the current time, `playback.scrubAudio`).
|
||||
pub scrub: Option<audio::AudioScrub>,
|
||||
pub(crate) updates_rt: updates_ui::Runtime,
|
||||
/// The framework dialogs (the update dialogs), run once per pass after EffectCraft's own UI.
|
||||
pub framework_dialogs: craft_ui::dialog::DialogHost,
|
||||
/// Who EffectCraft is to the framework's dialogs.
|
||||
pub(crate) framework_host: std::sync::Arc<craft_host::Host>,
|
||||
/// Audio panel VU meters.
|
||||
pub meter: audio::Meter,
|
||||
/// Waveform peak summaries per footage item (see `panels::waveform`).
|
||||
@@ -495,6 +502,8 @@ pub struct EffectcraftApp {
|
||||
pub(crate) unpublished_viewports: Vec<egui::ViewportId>,
|
||||
/// A floating panel shown by a command: its window comes to the front next frame.
|
||||
pub(crate) pending_panel_raise: Option<PanelKind>,
|
||||
/// What the dock area keeps between frames.
|
||||
pub(crate) live_dock: dock_ui::LiveDock,
|
||||
/// Home screen: recent-project thumbnail textures by path (None = no thumbnail).
|
||||
pub(crate) home_thumbs: std::collections::HashMap<String, Option<egui::TextureHandle>>,
|
||||
/// The (project path, saved revision) whose thumbnail was stored last.
|
||||
@@ -573,6 +582,9 @@ impl FileDialogsUp {
|
||||
#[derive(Default)]
|
||||
pub(crate) struct ForwardedInput {
|
||||
pub(crate) events: Vec<egui::Event>,
|
||||
/// Copy, Cut and Paste the runtime took from a window with no canvas ([`crate::framework`]), for the
|
||||
/// next pass of the shortcuts to read after that pass's own events.
|
||||
pub(crate) clips: Vec<egui::Event>,
|
||||
pub(crate) files: Vec<egui::DroppedFileHandle>,
|
||||
/// Files handed over by a floating window whose panel under the pointer was the Timeline. The
|
||||
/// paths lose the window they came from, so this keeps the one thing the import still needs
|
||||
|
||||
@@ -23,7 +23,14 @@ fn raw(size: egui::Vec2) -> egui::RawInput {
|
||||
}
|
||||
|
||||
fn tick_with(app: &mut EffectcraftApp, ctx: &egui::Context, frame: &eframe::Frame, raw: &egui::RawInput) -> egui::LogicOutput {
|
||||
ctx.run_logic(raw, |ctx| app.tick(ctx, frame))
|
||||
ctx.run_logic(raw, |ctx| app.logic_pass(ctx, frame))
|
||||
}
|
||||
|
||||
/// A context with the runtime installed, as the app's window has it.
|
||||
fn headless() -> egui::Context {
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
ctx
|
||||
}
|
||||
|
||||
fn hidden_tick(app: &mut EffectcraftApp, ctx: &egui::Context, frame: &eframe::Frame) {
|
||||
@@ -58,7 +65,7 @@ fn send(app: &mut EffectcraftApp, method: &str, params: serde_json::Value) -> st
|
||||
|
||||
#[test]
|
||||
fn a_logic_only_tick_installs_no_fonts_and_records_no_geometry() {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = headless();
|
||||
let frame = eframe::Frame::_new_kittest();
|
||||
let mut app = app_with_comp();
|
||||
hidden_tick(&mut app, &ctx, &frame);
|
||||
@@ -69,7 +76,7 @@ fn a_logic_only_tick_installs_no_fonts_and_records_no_geometry() {
|
||||
|
||||
#[test]
|
||||
fn a_control_command_that_needs_no_ui_completes_without_a_pass() {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = headless();
|
||||
let frame = eframe::Frame::_new_kittest();
|
||||
let mut app = app_with_comp();
|
||||
let reply = send(&mut app, "engine.execute", json!({"command": "comp.new", "params": {"name": "Queued", "width": 32, "height": 18, "duration": 1}}));
|
||||
@@ -81,7 +88,7 @@ fn a_control_command_that_needs_no_ui_completes_without_a_pass() {
|
||||
|
||||
#[test]
|
||||
fn a_pass_that_cannot_draw_receives_no_synthetic_input() {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = headless();
|
||||
let frame = eframe::Frame::_new_kittest();
|
||||
let mut app = app_with_comp();
|
||||
assert!(!app.is_ready(), "a fresh app installs its fonts in its first pass");
|
||||
@@ -97,7 +104,9 @@ fn a_pass_that_cannot_draw_receives_no_synthetic_input() {
|
||||
assert!(app.pending_synthetic_events().is_empty());
|
||||
let mut setup_pass = ctx.run_ui(setup.take(), |ui| app.draw(ui, &frame));
|
||||
setup_pass.textures_delta.clear();
|
||||
assert!(!app.is_ready(), "the pass that installs the fonts draws nothing");
|
||||
// The font install asks egui for a discard pass, which draws with the fonts and gets no input.
|
||||
assert!(app.is_ready(), "the frame that installs the fonts draws in its discard pass");
|
||||
assert_eq!(app.synthetic.len(), 5, "the discard pass got no synthetic input: the whole gesture still waits");
|
||||
// Once fonts are ready the click reaches the UI exactly once, one event per pass.
|
||||
let mut passes = 0;
|
||||
while reply.try_recv().is_err() {
|
||||
@@ -113,7 +122,7 @@ fn a_pass_that_cannot_draw_receives_no_synthetic_input() {
|
||||
|
||||
#[test]
|
||||
fn one_pending_synthetic_batch_is_never_duplicated_while_hidden() {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = headless();
|
||||
let frame = eframe::Frame::_new_kittest();
|
||||
let mut app = app_with_comp();
|
||||
ready(&mut app, &ctx, &frame);
|
||||
@@ -147,7 +156,7 @@ fn one_pending_synthetic_batch_is_never_duplicated_while_hidden() {
|
||||
|
||||
#[test]
|
||||
fn geometry_epoch_tracks_size_and_scale_but_not_window_position() {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = headless();
|
||||
let frame = eframe::Frame::_new_kittest();
|
||||
let mut app = app_with_comp();
|
||||
let first = ready(&mut app, &ctx, &frame);
|
||||
@@ -165,7 +174,7 @@ fn geometry_epoch_tracks_size_and_scale_but_not_window_position() {
|
||||
|
||||
#[test]
|
||||
fn only_a_viewer_that_draws_records_a_prefetch_scale() {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = headless();
|
||||
let frame = eframe::Frame::_new_kittest();
|
||||
let mut app = app_with_comp();
|
||||
ready(&mut app, &ctx, &frame);
|
||||
@@ -184,7 +193,7 @@ fn only_a_viewer_that_draws_records_a_prefetch_scale() {
|
||||
|
||||
#[test]
|
||||
fn playback_advances_on_a_logic_only_tick() {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = headless();
|
||||
let frame = eframe::Frame::_new_kittest();
|
||||
let mut app = app_with_comp();
|
||||
app.playback.playing = true;
|
||||
@@ -217,7 +226,7 @@ fn workspace_layout_autosave_writes_on_a_hidden_tick() {
|
||||
app.use_manual_clock();
|
||||
app.ui.focused = PanelKind::Timeline;
|
||||
app.clock_mut().advance(2.0);
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = headless();
|
||||
let frame = eframe::Frame::_new_kittest();
|
||||
hidden_tick(&mut app, &ctx, &frame);
|
||||
assert!(store.read(WORKSPACES_FILE).is_some(), "the layout is saved while the window is hidden");
|
||||
@@ -235,7 +244,7 @@ fn asks_to_close(ctx: &egui::Context, mut f: impl FnMut(&egui::Context)) -> bool
|
||||
#[test]
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn restart_to_update_with_unsaved_changes_opens_the_unsaved_changes_prompt() {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = headless();
|
||||
let frame = eframe::Frame::_new_kittest();
|
||||
let mut app = app_with_comp();
|
||||
assert!(app.session.is_dirty(), "creating a comp and a layer leaves unsaved changes");
|
||||
@@ -252,7 +261,7 @@ fn restart_to_update_with_unsaved_changes_opens_the_unsaved_changes_prompt() {
|
||||
#[test]
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn restart_to_update_with_nothing_unsaved_leaves_the_close_to_the_updater() {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = headless();
|
||||
let mut app = app_with_comp();
|
||||
app.updates_rt.manual_window_open = true;
|
||||
assert!(!asks_to_close(&ctx, |ctx| updates_ui::restart_to_update(&mut app.updates_rt, ctx, true)));
|
||||
@@ -262,7 +271,7 @@ fn restart_to_update_with_nothing_unsaved_leaves_the_close_to_the_updater() {
|
||||
#[test]
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn restart_to_update_with_the_startup_prompt_open_leaves_the_window_open() {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = headless();
|
||||
let mut app = app_with_comp();
|
||||
app.updates_rt.updater.offer(craft_update::Release {
|
||||
tag: "v99.0.0".into(),
|
||||
@@ -271,6 +280,14 @@ fn restart_to_update_with_the_startup_prompt_open_leaves_the_window_open() {
|
||||
html_url: "https://github.com/storytold/effectcraft/releases/tag/v99.0.0".into(),
|
||||
..Default::default()
|
||||
});
|
||||
// The offer reads on a thread whether this copy installs itself; a tick opens the prompt with its answer.
|
||||
for _ in 0..400 {
|
||||
if app.updates_rt.updater.prompt_open() {
|
||||
break;
|
||||
}
|
||||
std::thread::sleep(std::time::Duration::from_millis(5));
|
||||
app.updates_rt.updater.tick(&ctx);
|
||||
}
|
||||
assert!(app.updates_rt.updater.prompt_open());
|
||||
app.updates_rt.manual_window_open = true;
|
||||
assert!(!asks_to_close(&ctx, |ctx| updates_ui::restart_to_update(&mut app.updates_rt, ctx, false)), "the prompt carries the restart");
|
||||
@@ -280,7 +297,7 @@ fn restart_to_update_with_the_startup_prompt_open_leaves_the_window_open() {
|
||||
|
||||
#[test]
|
||||
fn the_close_guard_answers_a_close_request_without_a_pass() {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = headless();
|
||||
let frame = eframe::Frame::_new_kittest();
|
||||
let mut app = app_with_comp();
|
||||
assert!(app.session.is_dirty(), "creating a comp and a layer leaves unsaved changes");
|
||||
@@ -362,7 +379,7 @@ fn image(width: usize, height: usize) -> Arc<egui::ColorImage> {
|
||||
#[test]
|
||||
fn a_script_file_dialog_asks_for_a_pass_while_the_window_is_hidden() {
|
||||
use effectcraft_engine::scriptui::{FileDialogKind, ScriptFileDialog};
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = headless();
|
||||
let frame = eframe::Frame::_new_kittest();
|
||||
let mut app = app_with_comp();
|
||||
ready(&mut app, &ctx, &frame);
|
||||
@@ -391,7 +408,7 @@ fn a_script_file_dialog_asks_for_a_pass_while_the_window_is_hidden() {
|
||||
|
||||
#[test]
|
||||
fn a_screenshot_is_issued_only_after_settled_passes_and_writes_from_the_tick() {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = headless();
|
||||
let frame = eframe::Frame::_new_kittest();
|
||||
let mut app = app_with_comp();
|
||||
ready(&mut app, &ctx, &frame);
|
||||
@@ -417,7 +434,7 @@ fn a_screenshot_is_issued_only_after_settled_passes_and_writes_from_the_tick() {
|
||||
|
||||
#[test]
|
||||
fn a_resize_between_issue_and_completion_rejects_the_pixels_and_retries() {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = headless();
|
||||
let frame = eframe::Frame::_new_kittest();
|
||||
let mut app = app_with_comp();
|
||||
ready(&mut app, &ctx, &frame);
|
||||
@@ -444,7 +461,7 @@ fn a_resize_between_issue_and_completion_rejects_the_pixels_and_retries() {
|
||||
|
||||
#[test]
|
||||
fn screenshot_admission_bounds_requests_and_a_timeout_releases_its_reservation() {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = headless();
|
||||
let frame = eframe::Frame::_new_kittest();
|
||||
let mut app = app_with_comp();
|
||||
ready(&mut app, &ctx, &frame);
|
||||
@@ -470,7 +487,7 @@ fn screenshot_admission_bounds_requests_and_a_timeout_releases_its_reservation()
|
||||
|
||||
#[test]
|
||||
fn a_late_callback_after_cancellation_writes_nothing_and_replies_once() {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = headless();
|
||||
let frame = eframe::Frame::_new_kittest();
|
||||
let mut app = app_with_comp();
|
||||
ready(&mut app, &ctx, &frame);
|
||||
@@ -499,7 +516,7 @@ fn wake_requests(ctx: &egui::Context) -> Arc<std::sync::Mutex<Vec<std::time::Dur
|
||||
|
||||
#[test]
|
||||
fn an_issued_capture_schedules_a_wake_up_for_its_deadline() {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = headless();
|
||||
let frame = eframe::Frame::_new_kittest();
|
||||
let mut app = app_with_comp();
|
||||
ready(&mut app, &ctx, &frame);
|
||||
@@ -531,7 +548,7 @@ fn an_issued_capture_schedules_a_wake_up_for_its_deadline() {
|
||||
|
||||
#[test]
|
||||
fn a_downscaled_capture_is_cropped_with_the_images_own_scale() {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = headless();
|
||||
let frame = eframe::Frame::_new_kittest();
|
||||
let mut app = app_with_comp();
|
||||
let geom = ready(&mut app, &ctx, &frame);
|
||||
@@ -562,7 +579,7 @@ fn a_downscaled_capture_is_cropped_with_the_images_own_scale() {
|
||||
|
||||
#[test]
|
||||
fn a_capture_before_any_pass_never_uses_the_window_frame_rect() {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = headless();
|
||||
let frame = eframe::Frame::_new_kittest();
|
||||
let mut app = app_with_comp();
|
||||
// Only the outer (title bar included) rectangle is known: it is not the captured surface.
|
||||
@@ -582,7 +599,7 @@ fn a_capture_before_any_pass_never_uses_the_window_frame_rect() {
|
||||
|
||||
#[test]
|
||||
fn an_element_that_moves_while_the_ui_settles_is_captured_where_it_is() {
|
||||
let ctx = egui::Context::default();
|
||||
let ctx = headless();
|
||||
let frame = eframe::Frame::_new_kittest();
|
||||
let mut app = app_with_comp();
|
||||
let geom = ready(&mut app, &ctx, &frame);
|
||||
|
||||
@@ -132,7 +132,7 @@ pub(crate) fn entry_enabled(app: &EffectcraftApp, e: &MenuEntry) -> bool {
|
||||
return !app.session.is_rendering() && !app.session.project.render_queue.is_empty();
|
||||
}
|
||||
if e.command == "file.close" && super::invoke::no_params(&e.params) && app.ui.focused == PanelKind::RenderQueue {
|
||||
return !app.ui.dock.locked;
|
||||
return !app.ui.dock_locked;
|
||||
}
|
||||
if e.command == "window.panel" {
|
||||
return true;
|
||||
|
||||
@@ -363,7 +363,6 @@ pub fn frontend(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, p: Valu
|
||||
Value::Null
|
||||
}
|
||||
"window.saveWorkspace" => {
|
||||
crate::workspace_state::ensure_positions_ready(&app.ui)?;
|
||||
let name = app.ui.workspace.clone();
|
||||
app.ui.saved_workspaces.insert(name.clone(), app.ui.dock.clone());
|
||||
app.store_saved_workspaces()?;
|
||||
@@ -380,7 +379,6 @@ pub fn frontend(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, p: Valu
|
||||
);
|
||||
return Ok(Value::Null);
|
||||
};
|
||||
crate::workspace_state::ensure_positions_ready(&app.ui)?;
|
||||
app.ui.saved_workspaces.insert(name.clone(), app.ui.dock.clone());
|
||||
app.ui.workspace = name.clone();
|
||||
app.store_saved_workspaces()?;
|
||||
@@ -404,7 +402,6 @@ pub fn frontend(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, p: Valu
|
||||
};
|
||||
let builtin = crate::dock::WORKSPACES.contains(&name.as_str());
|
||||
if p.get("delete").and_then(Value::as_bool) == Some(true) {
|
||||
crate::workspace_state::ensure_positions_ready(&app.ui)?;
|
||||
if app.ui.saved_workspaces.remove(&name).is_none() && !builtin {
|
||||
return Err(format!("no workspace `{name}`"));
|
||||
}
|
||||
@@ -419,7 +416,6 @@ pub fn frontend(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, p: Valu
|
||||
if builtin {
|
||||
return Err(format!("`{name}` is a built-in workspace: save it as a new workspace instead"));
|
||||
}
|
||||
crate::workspace_state::ensure_positions_ready(&app.ui)?;
|
||||
let dock = app.ui.saved_workspaces.remove(&name).ok_or_else(|| format!("no workspace `{name}`"))?;
|
||||
app.ui.saved_workspaces.insert(new.to_string(), dock);
|
||||
if app.ui.workspace == name {
|
||||
|
||||
@@ -243,7 +243,7 @@ pub fn invoke(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, params: V
|
||||
// Close follows panel focus too: with the Render Queue active, Cmd+W closes that panel and
|
||||
// leaves the active composition open (it used to close the composition next to it).
|
||||
if id == "file.close" && no_params(¶ms) && app.ui.focused == PanelKind::RenderQueue {
|
||||
app.apply_dock(craft_ui::docking::Action::Close { panel: PanelKind::RenderQueue })?;
|
||||
app.apply_dock(craft_behavior::dock::Action::close(PanelKind::RenderQueue))?;
|
||||
// The focus goes to a panel that is still there, so the next Close acts on the composition
|
||||
// instead of on the queue that is gone.
|
||||
let next = [PanelKind::Timeline, PanelKind::Composition, PanelKind::Project].into_iter().find(|p| panel_shown(app, *p)).unwrap_or(PanelKind::Project);
|
||||
@@ -443,17 +443,23 @@ pub fn invoke(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, params: V
|
||||
"closePanel" => {
|
||||
let p = panel_of("panel").ok_or("closePanel: need `panel`")??;
|
||||
if app.ui.dock.is_open(p) {
|
||||
app.apply_dock(craft_ui::docking::Action::Close { panel: p })?;
|
||||
app.apply_dock(craft_behavior::dock::Action::close(p))?;
|
||||
}
|
||||
return Ok(Value::Null);
|
||||
}
|
||||
"floatPanel" => {
|
||||
let p = panel_of("panel").ok_or("floatPanel: need `panel`")??;
|
||||
let r = match params.get("rect") {
|
||||
Some(value) => serde_json::from_value::<[f32; 4]>(value.clone()).map_err(|_| "rect must contain four finite numbers")?,
|
||||
Some(value) => {
|
||||
let rect = serde_json::from_value::<[f32; 4]>(value.clone()).map_err(|_| "rect must contain four finite numbers")?;
|
||||
if !rect.iter().all(|v| v.is_finite()) {
|
||||
return Err("rect must contain four finite numbers".into());
|
||||
}
|
||||
crate::dock_command::rect_of(rect)
|
||||
}
|
||||
None => crate::dock_ui::default_float_rect(ctx.content_rect()),
|
||||
};
|
||||
app.apply_dock(craft_ui::docking::Action::Float { panel: p, rect: r }).map_err(|e| format!("can't undock {}: {e}", p.title()))?;
|
||||
app.apply_dock(craft_behavior::dock::Action::float(p, r)).map_err(|e| format!("can't undock {}: {e}", p.title()))?;
|
||||
return Ok(Value::Null);
|
||||
}
|
||||
_ => {
|
||||
@@ -475,8 +481,8 @@ pub fn invoke(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, params: V
|
||||
if let Some(before) = panel_of("before") {
|
||||
command["before"] = json!(before?);
|
||||
}
|
||||
let command: craft_ui::docking::DockCommand<PanelKind> =
|
||||
serde_json::from_value(command).map_err(|e| format!("dockPanel: zone: center|tab|left|right|top|bottom|above|below ({e})"))?;
|
||||
let command = crate::dock_command::DockCommand::parse("window.panel.dock", &command)
|
||||
.map_err(|e| format!("dockPanel: zone: center|tab|left|right|top|bottom|above|below ({e})"))?;
|
||||
app.run_dock_command(ctx, command).map_err(|e| format!("can't dock {}: {e}", p.title()))?;
|
||||
app.show_panel(p);
|
||||
return Ok(Value::Null);
|
||||
|
||||
@@ -278,7 +278,7 @@ fn cancel_dialog(app: &mut EffectcraftApp, ctx: &egui::Context) {
|
||||
type KeyEvent = (egui::Key, egui::Modifiers, bool, Option<egui::Key>);
|
||||
|
||||
/// The frame's key presses, with clipboard events mapped back to Ctrl+C / X / V.
|
||||
fn collect_key_events(ctx: &egui::Context, start: Option<egui::Modifiers>, clipboard: bool, project: bool) -> Vec<KeyEvent> {
|
||||
fn collect_key_events(ctx: &egui::Context, start: Option<egui::Modifiers>, clipboard: bool, project: bool, queued: &[egui::Event]) -> Vec<KeyEvent> {
|
||||
ctx.input(|i| {
|
||||
// The windowing layer turns Ctrl+C / Ctrl+X / Ctrl+V into clipboard events instead of
|
||||
// key presses: map them back to the keys (with the modifiers held) so Edit ▸ Copy, Cut,
|
||||
@@ -290,7 +290,7 @@ fn collect_key_events(ctx: &egui::Context, start: Option<egui::Modifiers>, clipb
|
||||
let mut at = if changed { start } else { Some(i.modifiers) };
|
||||
let held = |at: Option<egui::Modifiers>| at.filter(|m| m.command).unwrap_or(egui::Modifiers::COMMAND);
|
||||
let mut out = Vec::new();
|
||||
for e in &i.events {
|
||||
for e in i.events.iter().chain(queued) {
|
||||
match e {
|
||||
egui::Event::ModifiersChanged(m) => at = Some(*m),
|
||||
// egui forgets the modifiers held when the window loses focus.
|
||||
@@ -349,6 +349,8 @@ fn panel_owns_enter(kind: PanelKind) -> bool {
|
||||
}
|
||||
|
||||
fn handle_shortcuts_impl(app: &mut EffectcraftApp, ctx: &egui::Context, tab_only: bool) {
|
||||
// The clipboard chords of a window with no canvas wait for this frame's pass only, whatever stops it.
|
||||
let queued = if tab_only { Vec::new() } else { std::mem::take(&mut app.forwarded.clips) };
|
||||
let start = modifiers_at_start(ctx);
|
||||
if !tab_only && app.dialog.is_some() && ctx.input(|i| i.key_pressed(egui::Key::Escape)) {
|
||||
escape_dialog(app, ctx);
|
||||
@@ -356,12 +358,12 @@ fn handle_shortcuts_impl(app: &mut EffectcraftApp, ctx: &egui::Context, tab_only
|
||||
}
|
||||
// A mouse button down while Spacebar is held belongs to the Hand tool: its release won't
|
||||
// preview.
|
||||
if ctx.input(|i| i.pointer.any_down()) || ctx.egui_wants_keyboard_input() {
|
||||
if ctx.input(|i| i.pointer.any_down()) || crate::framework::widget_has_keyboard(ctx) {
|
||||
ctx.data_mut(|d| d.remove::<bool>(space_tap_id()));
|
||||
}
|
||||
// While a menu or popup list is open, keys go to it, not to the app (Space must not start a
|
||||
// preview behind the menu, #279).
|
||||
if ctx.egui_wants_keyboard_input() || crate::widgets::any_menu_open(ctx) {
|
||||
if crate::framework::widget_has_keyboard(ctx) || crate::widgets::any_menu_open(ctx) {
|
||||
return;
|
||||
}
|
||||
// Text editing in the viewer takes the clipboard events itself.
|
||||
@@ -370,7 +372,7 @@ fn handle_shortcuts_impl(app: &mut EffectcraftApp, ctx: &egui::Context, tab_only
|
||||
// The paste event's text: Edit ▸ Paste pastes SVG markup as a shape layer.
|
||||
let pasted =
|
||||
if clipboard { ctx.input(|i| i.events.iter().rev().find_map(|e| if let egui::Event::Paste(t) = e { Some(t.clone()) } else { None })) } else { None };
|
||||
let mut events = collect_key_events(ctx, start, clipboard, project);
|
||||
let mut events = collect_key_events(ctx, start, clipboard, project, &queued);
|
||||
events.retain(|(key, _, _, _)| (*key == egui::Key::Tab) == tab_only);
|
||||
if !tab_only && clipboard && app.dialog.is_none() {
|
||||
numpad_star_marker(app, ctx);
|
||||
|
||||
@@ -16,6 +16,7 @@ fn zoom_steps_land_on_whole_screen_magnifications() {
|
||||
#[test]
|
||||
fn shortcut_passes_share_frame_start_modifiers() {
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
let mut starts = Vec::new();
|
||||
let mut output = ctx.run_ui(egui::RawInput { events: vec![egui::Event::ModifiersChanged(egui::Modifiers::SHIFT)], ..Default::default() }, |ui| {
|
||||
let ctx = ui.ctx();
|
||||
@@ -84,6 +85,7 @@ fn ctrl_backslash_maximizes_or_restores_the_window() {
|
||||
assert!(m.command && k == egui::Key::Backslash, "{m:?} {k:?}");
|
||||
assert!(bindings(&app.session).iter().any(|b| (b.0, b.1) == (m, k) && b.2 == "window.maximizeApp"));
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
let run = |app: &mut EffectcraftApp, maximized: bool| {
|
||||
let input = egui::RawInput {
|
||||
viewports: std::iter::once((egui::ViewportId::ROOT, egui::ViewportInfo { maximized: Some(maximized), ..Default::default() })).collect(),
|
||||
@@ -408,6 +410,7 @@ fn file_dialogs_block_floating_windows_only_while_up() {
|
||||
use std::sync::{Arc, Mutex};
|
||||
let mut app = EffectcraftApp::new(effectcraft_engine::Session::default());
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
let pending: Arc<Mutex<Vec<crate::DialogDone>>> = Arc::default();
|
||||
let queue = pending.clone();
|
||||
app.hooks.file_dialog_async = Some(Box::new(move |_dialog, done| queue.lock().unwrap().push(done)));
|
||||
@@ -491,6 +494,7 @@ fn a_dialog_that_cannot_open_reports_an_error() {
|
||||
use std::sync::{Arc, Mutex};
|
||||
let mut app = EffectcraftApp::new(effectcraft_engine::Session::default());
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
let pending: Arc<Mutex<Vec<crate::DialogDone>>> = Arc::default();
|
||||
let queue = pending.clone();
|
||||
app.hooks.file_dialog_async = Some(Box::new(move |_dialog, done| queue.lock().unwrap().push(done)));
|
||||
@@ -588,6 +592,7 @@ fn dropped_files_keep_import_errors_alongside_local_drop_errors() {
|
||||
let mut app = EffectcraftApp::new(effectcraft_host::session());
|
||||
app.session.prefs.import.drag_import_as = "comp".into();
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
let mut dropped_files: Vec<egui::DroppedFileHandle> = vec![std::sync::Arc::new(Drop("no-local-path".into()))];
|
||||
if bad_import {
|
||||
dropped_files.push(std::sync::Arc::new(Drop(path.clone())));
|
||||
@@ -680,7 +685,7 @@ fn closing_the_render_queue_reveals_the_panel_receiving_focus() {
|
||||
assert!(!app.ui.dock.is_visible(PanelKind::Project));
|
||||
app.show_panel(PanelKind::RenderQueue);
|
||||
if maximized {
|
||||
app.apply_dock(craft_ui::docking::Action::Float { panel: PanelKind::RenderQueue, rect: [50.0, 60.0, 400.0, 200.0] }).unwrap();
|
||||
app.apply_dock(craft_behavior::dock::Action::float(PanelKind::RenderQueue, crate::dock_command::rect_of([50.0, 60.0, 400.0, 200.0]))).unwrap();
|
||||
app.toggle_maximize(PanelKind::EffectControls);
|
||||
app.ui.focused = PanelKind::RenderQueue;
|
||||
assert!(app.ui.dock.is_floating(PanelKind::RenderQueue));
|
||||
@@ -697,13 +702,16 @@ fn closing_the_render_queue_reveals_the_panel_receiving_focus() {
|
||||
fn closing_a_floating_queue_preserves_the_maximized_composition() {
|
||||
let mut session = effectcraft_engine::Session::default();
|
||||
session.execute("comp.new", json!({"name": "A", "width": 32, "height": 32, "duration": 2})).unwrap();
|
||||
let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_eframe(|_| EffectcraftApp::new(session));
|
||||
let mut h = egui_kittest::Harness::builder()
|
||||
.with_size(egui::vec2(1200.0, 800.0))
|
||||
.with_context_setup(crate::framework::install_headless)
|
||||
.build_eframe(|_| EffectcraftApp::new(session));
|
||||
h.run_steps(3);
|
||||
let ctx = h.ctx.clone();
|
||||
let app = h.state_mut();
|
||||
app.show_panel(PanelKind::Composition);
|
||||
app.show_panel(PanelKind::RenderQueue);
|
||||
app.apply_dock(craft_ui::docking::Action::Float { panel: PanelKind::RenderQueue, rect: [50.0, 60.0, 400.0, 200.0] }).unwrap();
|
||||
app.apply_dock(craft_behavior::dock::Action::float(PanelKind::RenderQueue, crate::dock_command::rect_of([50.0, 60.0, 400.0, 200.0]))).unwrap();
|
||||
app.toggle_maximize(PanelKind::Composition);
|
||||
app.ui.focused = PanelKind::RenderQueue;
|
||||
assert!(app.ui.dock.is_visible(PanelKind::Timeline), "the hidden underlying tab triggers the regression");
|
||||
@@ -722,7 +730,7 @@ fn queue_close_preserves_state_when_workspace_is_locked() {
|
||||
let mut app = EffectcraftApp::new(effectcraft_engine::Session::default());
|
||||
app.session.execute("comp.new", json!({"name": "A", "duration": 2})).unwrap();
|
||||
app.show_panel(PanelKind::RenderQueue);
|
||||
app.ui.dock.locked = true;
|
||||
app.ui.dock_locked = true;
|
||||
let workspace = app.ui.dock.clone();
|
||||
let comp = app.session.active_comp_id();
|
||||
for _ in 0..2 {
|
||||
@@ -732,7 +740,7 @@ fn queue_close_preserves_state_when_workspace_is_locked() {
|
||||
assert_eq!(app.session.active_comp_id(), comp);
|
||||
}
|
||||
assert!(!menu_items(&app).iter().find(|item| item.id == "file.close").unwrap().enabled);
|
||||
app.ui.dock.locked = false;
|
||||
app.ui.dock_locked = false;
|
||||
invoke(&mut app, &ctx, "file.close", Value::Null).unwrap();
|
||||
assert!(!app.ui.dock.is_open(PanelKind::RenderQueue));
|
||||
}
|
||||
@@ -747,12 +755,8 @@ fn queue_close_preserves_viewer_command_target() {
|
||||
app.ui.viewers.insert(0, Some(a));
|
||||
app.ui.viewers.insert(1, Some(b));
|
||||
app.ui.active_viewer = 1;
|
||||
app.apply_dock(craft_ui::docking::Action::Move {
|
||||
panel: PanelKind::Timeline,
|
||||
anchor: PanelKind::Composition,
|
||||
placement: craft_ui::docking::Placement::Tab { before: None },
|
||||
})
|
||||
.unwrap();
|
||||
app.apply_dock(craft_behavior::dock::Action::move_beside(PanelKind::Timeline, PanelKind::Composition, craft_behavior::dock::DockPlacement::tab(None)))
|
||||
.unwrap();
|
||||
app.close_panel(PanelKind::Timeline);
|
||||
app.show_panel(PanelKind::Composition);
|
||||
app.show_panel(PanelKind::RenderQueue);
|
||||
@@ -771,7 +775,10 @@ fn queue_close_keeps_passive_viewer_focus_across_frames() {
|
||||
let mut session = effectcraft_engine::Session::default();
|
||||
let a = session.execute("comp.new", json!({"name": "A", "width": 32, "height": 32, "duration": 2})).unwrap()["comp"].as_u64().unwrap();
|
||||
let b = session.execute("comp.new", json!({"name": "B", "width": 32, "height": 32, "duration": 2})).unwrap()["comp"].as_u64().unwrap();
|
||||
let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(1200.0, 800.0)).build_eframe(|_| EffectcraftApp::new(session));
|
||||
let mut h = egui_kittest::Harness::builder()
|
||||
.with_size(egui::vec2(1200.0, 800.0))
|
||||
.with_context_setup(crate::framework::install_headless)
|
||||
.build_eframe(|_| EffectcraftApp::new(session));
|
||||
h.run_steps(3);
|
||||
let ctx = h.ctx.clone();
|
||||
let app = h.state_mut();
|
||||
@@ -779,12 +786,8 @@ fn queue_close_keeps_passive_viewer_focus_across_frames() {
|
||||
app.ui.viewers.insert(0, Some(a));
|
||||
app.ui.viewers.insert(1, Some(b));
|
||||
app.ui.active_viewer = 1;
|
||||
app.apply_dock(craft_ui::docking::Action::Move {
|
||||
panel: PanelKind::Timeline,
|
||||
anchor: PanelKind::Composition,
|
||||
placement: craft_ui::docking::Placement::Tab { before: None },
|
||||
})
|
||||
.unwrap();
|
||||
app.apply_dock(craft_behavior::dock::Action::move_beside(PanelKind::Timeline, PanelKind::Composition, craft_behavior::dock::DockPlacement::tab(None)))
|
||||
.unwrap();
|
||||
app.close_panel(PanelKind::Timeline);
|
||||
app.show_panel(PanelKind::Composition);
|
||||
app.show_panel(PanelKind::RenderQueue);
|
||||
|
||||
@@ -441,9 +441,12 @@ impl MenuSync {
|
||||
|
||||
/// The window whose text field has the keyboard: a floating panel's own OS window, or the main
|
||||
/// window, where any widget that holds the keyboard counts (the Viewer's text editor is not an
|
||||
/// egui text field).
|
||||
/// egui text field) except the Composition viewer itself.
|
||||
pub fn text_field_window(ctx: &egui::Context) -> Option<egui::ViewportId> {
|
||||
craft_ui::docking::typing_window(ctx).or_else(|| ctx.egui_wants_keyboard_input().then_some(egui::ViewportId::ROOT))
|
||||
let host = craft_ui::runtime::windows::WindowHost::of(ctx);
|
||||
let window = host.key_window();
|
||||
let floating = (window != egui::ViewportId::ROOT && host.typing()).then_some(window);
|
||||
floating.or_else(|| crate::framework::widget_has_keyboard(ctx).then_some(egui::ViewportId::ROOT))
|
||||
}
|
||||
|
||||
/// Whether a focused text field takes the menu command `command` ([`activate`]): the native menu
|
||||
@@ -476,8 +479,9 @@ fn text_field_event(command: &str) -> Option<Vec<egui::Event>> {
|
||||
|
||||
/// Hand a text field's Edit command to the window `window` whose field has the keyboard. The
|
||||
/// main window gets the clipboard text itself and the events through the synthetic queue; a
|
||||
/// floating panel's OS window gets each key pressed and released, and asks for the clipboard
|
||||
/// text on Cmd+V (`craft_ui::docking::send_keys`).
|
||||
/// floating panel's OS window gets each command as the key equivalent the platform's menu took
|
||||
/// from it (Copy and Cut as egui's copy and cut events, the rest as the key's tap), and the
|
||||
/// clipboard text as typed text on Cmd+V.
|
||||
fn send_to_text_field(app: &mut EffectcraftApp, ctx: &egui::Context, window: egui::ViewportId, events: Vec<egui::Event>) {
|
||||
if window == egui::ViewportId::ROOT {
|
||||
for event in events {
|
||||
@@ -493,19 +497,27 @@ fn send_to_text_field(app: &mut EffectcraftApp, ctx: &egui::Context, window: egu
|
||||
ctx.request_repaint();
|
||||
return;
|
||||
}
|
||||
let events = events
|
||||
.into_iter()
|
||||
.flat_map(|event| {
|
||||
let release = match &event {
|
||||
egui::Event::Key { key, physical_key, modifiers, .. } => {
|
||||
Some(egui::Event::Key { key: *key, physical_key: *physical_key, pressed: false, repeat: false, modifiers: *modifiers })
|
||||
use craft_ui::runtime::windows::{KeyEquivalent, WindowHost};
|
||||
let host = WindowHost::of(ctx);
|
||||
let platform = craft_keymap::egui::platform(ctx);
|
||||
for event in events {
|
||||
let equivalent = match event {
|
||||
egui::Event::Key { key: egui::Key::V, .. } => {
|
||||
if let Some(text) = app.hooks.clipboard_text.as_ref().and_then(|f| f()) {
|
||||
host.inject_text(window, &text);
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
std::iter::once(event).chain(release)
|
||||
})
|
||||
.collect();
|
||||
craft_ui::docking::send_keys(ctx, window, events);
|
||||
continue;
|
||||
}
|
||||
egui::Event::Key { key, modifiers, .. } => match craft_keymap::Key::from_egui(key) {
|
||||
Some(key) => KeyEquivalent::Tap(craft_keymap::Chord::new(craft_keymap::Mods::from_egui(&modifiers, platform), key)),
|
||||
None => continue,
|
||||
},
|
||||
egui::Event::Copy => KeyEquivalent::Copy,
|
||||
egui::Event::Cut => KeyEquivalent::Cut,
|
||||
_ => continue,
|
||||
};
|
||||
host.key_equivalent(window, equivalent);
|
||||
}
|
||||
}
|
||||
|
||||
/// Run a native menu item (by id) the way the in-window menu bar does. While a text field has
|
||||
@@ -768,6 +780,7 @@ mod tests {
|
||||
let spec = build(&app);
|
||||
let dup = spec.items().into_iter().find(|i| i.command == "edit.duplicate").map(|i| i.id.clone()).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
app.dialog_state.delete_items.command = Some((json!({"items": []}), json!({"items": 1, "layers": 1, "comps": 1})));
|
||||
app.dialog = Some(crate::Dialog::DeleteItems);
|
||||
// Chosen with the mouse, Duplicate still runs.
|
||||
@@ -915,6 +928,7 @@ mod tests {
|
||||
fn a_file_dialog_takes_the_edit_keys_from_a_focused_text_field() {
|
||||
let mut app = app();
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
let mut text = String::new();
|
||||
for _ in 0..2 {
|
||||
let mut out = ctx.run_ui(egui::RawInput::default(), |ui| ui.text_edit_singleline(&mut text).request_focus());
|
||||
@@ -996,6 +1010,7 @@ mod tests {
|
||||
app.session.execute("layer.newNull", json!({})).unwrap();
|
||||
app.session.execute("edit.undo", json!({})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
let history = label(&build_now(&app, &ctx), "edit.undo");
|
||||
let redo_history = label(&build_now(&app, &ctx), "edit.redo");
|
||||
assert!(history.starts_with(undo) && history != undo, "{history}");
|
||||
|
||||
@@ -368,6 +368,7 @@ mod tests {
|
||||
fn a_drag_value_reads_typed_arithmetic() {
|
||||
use egui::{Context, Event, Key, Modifiers, PointerButton, Pos2, RawInput, Rect, pos2, vec2};
|
||||
let ctx = Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
let mut value = 10.0_f64;
|
||||
let mut time = 0.0;
|
||||
let field = Rect::from_min_size(pos2(100.0, 100.0), vec2(80.0, 20.0));
|
||||
|
||||
@@ -184,7 +184,7 @@ pub(crate) fn toggle_time_display(app: &mut EffectcraftApp, resp: &egui::Respons
|
||||
/// Spacebar held outside a text field: the Hand tool (drags pan the viewer and scroll the
|
||||
/// Timeline).
|
||||
pub(crate) fn space_hand(ctx: &egui::Context) -> bool {
|
||||
ctx.input(|i| i.key_down(egui::Key::Space)) && !ctx.egui_wants_keyboard_input()
|
||||
ctx.input(|i| i.key_down(egui::Key::Space)) && !crate::framework::widget_has_keyboard(ctx)
|
||||
}
|
||||
|
||||
/// What a scroll gesture over a viewer (Composition, Layer) does this frame.
|
||||
@@ -344,13 +344,13 @@ pub(crate) fn panel_menu_area(app: &mut EffectcraftApp, ui: &mut egui::Ui) {
|
||||
// only ever narrows what the area measured: the separator fills whatever width it is given
|
||||
ui.set_max_width(ui.max_rect().width().min(width));
|
||||
if ui.button(tr("Close Panel")).clicked() {
|
||||
let _ = app.dock_command(ui.ctx(), craft_ui::docking::Action::Close { panel });
|
||||
let _ = app.dock_command(ui.ctx(), craft_behavior::dock::Action::close(panel));
|
||||
close = true;
|
||||
}
|
||||
let floating = crate::dock::WorkspaceExt::is_floating(&app.ui.dock, panel);
|
||||
if !floating && ui.button(tr("Undock Panel")).clicked() {
|
||||
let r = crate::dock_ui::default_float_rect(ui.ctx().content_rect());
|
||||
let _ = app.dock_command(ui.ctx(), craft_ui::docking::Action::Float { panel, rect: r });
|
||||
let _ = app.dock_command(ui.ctx(), craft_behavior::dock::Action::float(panel, r));
|
||||
close = true;
|
||||
}
|
||||
// Multiple monitors: an OS window of its own, which can go on another screen. Where
|
||||
|
||||
@@ -347,7 +347,7 @@ pub fn viewer_hook(
|
||||
&& app.dialog.is_none()
|
||||
&& !selected.is_empty()
|
||||
&& ui.input(|i| i.key_pressed(egui::Key::Delete) || i.key_pressed(egui::Key::Backspace))
|
||||
&& !ctx.egui_wants_keyboard_input()
|
||||
&& !crate::framework::widget_has_keyboard(&ctx)
|
||||
{
|
||||
run(app, &ctx, "camera.deletePoints", json!({"layer": a.layer.0, "effect": a.uid, "points": selected}));
|
||||
}
|
||||
|
||||
@@ -268,7 +268,7 @@ fn tab_body(
|
||||
.or_else(|| PRESETS.iter().find(|(_, w, h, par, f)| matches(d, *w, *h, *par, *f)).map(|p| p.0))
|
||||
.unwrap_or("Custom");
|
||||
ui.horizontal(|ui| {
|
||||
let r = craft_ui::ComboBox::from_id_salt("comp-preset").width(300.0).selected_text(current).show_ui(ui, |ui| {
|
||||
let r = egui::ComboBox::from_id_salt("comp-preset").width(300.0).selected_text(current).show_ui(ui, |ui| {
|
||||
// Your own presets first, then the built-in ones.
|
||||
for q in custom {
|
||||
if ui.selectable_label(q.name == current, &q.name).clicked() {
|
||||
@@ -332,7 +332,7 @@ fn tab_body(
|
||||
.find(|(_, v)| (v - d.pixel_aspect).abs() < 1e-3)
|
||||
.map(|p| tr(p.0).to_string())
|
||||
.unwrap_or_else(|| format!("{:.2}", d.pixel_aspect));
|
||||
let r = craft_ui::ComboBox::from_id_salt("comp-par").width(220.0).selected_text(cur).show_ui(ui, |ui| {
|
||||
let r = egui::ComboBox::from_id_salt("comp-par").width(220.0).selected_text(cur).show_ui(ui, |ui| {
|
||||
for (name, v) in PIXEL_ASPECTS {
|
||||
if ui.selectable_label((v - d.pixel_aspect).abs() < 1e-3, tr(name)).clicked() {
|
||||
d.pixel_aspect = *v;
|
||||
@@ -351,7 +351,7 @@ fn tab_body(
|
||||
// Any rate can be typed; the list holds the common ones.
|
||||
let r = ui.add(crate::widgets::drag_value(egui::DragValue::new(&mut d.fps).range(1.0..=999.0).speed(0.01).max_decimals(3)));
|
||||
auto.add("dialog.comp.frameRate", r.rect, "Frame Rate");
|
||||
let r = craft_ui::ComboBox::from_id_salt("comp-fps").width(18.0).selected_text("").show_ui(ui, |ui| {
|
||||
let r = egui::ComboBox::from_id_salt("comp-fps").width(18.0).selected_text("").show_ui(ui, |ui| {
|
||||
for f in FRAME_RATES {
|
||||
if ui.selectable_label((d.fps - f).abs() < 1e-3, format!("{f}")).clicked() {
|
||||
d.fps = *f;
|
||||
@@ -369,7 +369,7 @@ fn tab_body(
|
||||
// the frame it renders beside it.
|
||||
ui.label(tr("Resolution:"));
|
||||
ui.horizontal(|ui| {
|
||||
let r = craft_ui::ComboBox::from_id_salt("comp-resolution").width(90.0).selected_text(tr(d.resolution.label())).show_ui(ui, |ui| {
|
||||
let r = egui::ComboBox::from_id_salt("comp-resolution").width(90.0).selected_text(tr(d.resolution.label())).show_ui(ui, |ui| {
|
||||
for res in Resolution::ALL {
|
||||
ui.selectable_value(&mut d.resolution, res, tr(res.label()));
|
||||
}
|
||||
@@ -456,7 +456,7 @@ fn tab_body(
|
||||
Tab::Renderer => {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(tr("Renderer:"));
|
||||
let r = craft_ui::ComboBox::from_id_salt("comp-renderer").selected_text(tr(if d.advanced_3d { "Advanced 3D" } else { "Classic 3D" })).show_ui(
|
||||
let r = egui::ComboBox::from_id_salt("comp-renderer").selected_text(tr(if d.advanced_3d { "Advanced 3D" } else { "Classic 3D" })).show_ui(
|
||||
ui,
|
||||
|ui| {
|
||||
ui.selectable_value(&mut d.advanced_3d, false, tr("Classic 3D"));
|
||||
|
||||
@@ -626,7 +626,7 @@ fn solid(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
|
||||
.find(|(_, v)| (v - par).abs() < 1e-3)
|
||||
.map(|p| p.0.to_string())
|
||||
.unwrap_or_else(|| format!("{par:.2}"));
|
||||
let r = craft_ui::ComboBox::from_id_salt("solid-par").width(240.0).selected_text(cur).show_ui(ui, |ui| {
|
||||
let r = egui::ComboBox::from_id_salt("solid-par").width(240.0).selected_text(cur).show_ui(ui, |ui| {
|
||||
for (label, v) in super::comp_settings::PIXEL_ASPECTS {
|
||||
if ui.selectable_label((v - par).abs() < 1e-3, *label).clicked() {
|
||||
par = *v;
|
||||
|
||||
@@ -197,7 +197,7 @@ pub fn camera(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
|
||||
super::dialogs::modal_placed(ctx, "Camera Settings", vec2(520.0, 420.0), t, place, |ui| {
|
||||
egui::Grid::new("cam-grid").num_columns(2).spacing([14.0, 9.0]).show(ui, |ui| {
|
||||
ui.label(tr("Type"));
|
||||
craft_ui::ComboBox::from_id_salt("cam-type").selected_text(if d.two_node { "Two-Node Camera" } else { "One-Node Camera" }).show_ui(ui, |ui| {
|
||||
egui::ComboBox::from_id_salt("cam-type").selected_text(if d.two_node { "Two-Node Camera" } else { "One-Node Camera" }).show_ui(ui, |ui| {
|
||||
ui.selectable_value(&mut d.two_node, true, tr("Two-Node Camera"));
|
||||
ui.selectable_value(&mut d.two_node, false, tr("One-Node Camera"));
|
||||
});
|
||||
@@ -209,7 +209,7 @@ pub fn camera(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
|
||||
ui.label(tr("Preset"));
|
||||
let focal = focal_for_zoom(w, d.zoom);
|
||||
let cur = PRESETS.iter().find(|(_, f)| (f - focal).abs() < 1e-6).map(|(n, _)| *n).unwrap_or("Custom");
|
||||
craft_ui::ComboBox::from_id_salt("cam-preset").selected_text(cur).show_ui(ui, |ui| {
|
||||
egui::ComboBox::from_id_salt("cam-preset").selected_text(cur).show_ui(ui, |ui| {
|
||||
for (n, f) in PRESETS {
|
||||
if ui.selectable_label(cur == n, n).clicked() {
|
||||
d.zoom = zoom_for_focal(w, f);
|
||||
@@ -313,7 +313,7 @@ pub fn light(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
|
||||
crate::widgets::focus_on_open(ui.ctx(), &r, &d.name);
|
||||
ui.end_row();
|
||||
ui.label(tr("Light Type"));
|
||||
let combo = craft_ui::ComboBox::from_id_salt("light-type").selected_text(tr(d.kind.label())).show_ui(ui, |ui| {
|
||||
let combo = egui::ComboBox::from_id_salt("light-type").selected_text(tr(d.kind.label())).show_ui(ui, |ui| {
|
||||
for (i, k) in LightKind::ALL.into_iter().enumerate() {
|
||||
let item = ui.selectable_value(&mut d.kind, k, tr(k.label()));
|
||||
app.auto.add(&format!("dialog.light.typeItem.{i}"), item.rect, k.label());
|
||||
@@ -337,7 +337,7 @@ pub fn light(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
|
||||
}
|
||||
if falls_off(d.kind) {
|
||||
ui.label(tr("Falloff"));
|
||||
craft_ui::ComboBox::from_id_salt("light-falloff").selected_text(FALLOFFS[d.falloff.min(2)]).show_ui(ui, |ui| {
|
||||
egui::ComboBox::from_id_salt("light-falloff").selected_text(FALLOFFS[d.falloff.min(2)]).show_ui(ui, |ui| {
|
||||
for (i, f) in FALLOFFS.iter().enumerate() {
|
||||
ui.selectable_value(&mut d.falloff, i, *f);
|
||||
}
|
||||
|
||||
@@ -422,7 +422,7 @@ fn list_keys(app: &mut EffectcraftApp, ctx: &egui::Context, nav: &Nav, list: Rec
|
||||
ctx.data_mut(|d| d.remove::<egui::Id>(cursor_id()));
|
||||
ctx.request_repaint();
|
||||
}
|
||||
let focused = ctx.memory(|m| m.focused());
|
||||
let focused = crate::framework::focused_widget(ctx);
|
||||
let on_row = focused.is_some_and(|f| nav.rows.iter().any(|r| r.id == f || r.star == Some(f)));
|
||||
// Enter / Space on the star are the star button's (it toggles the favourite), not the row's.
|
||||
let on_star = focused.is_some_and(|f| nav.rows.iter().any(|r| r.star == Some(f)));
|
||||
@@ -882,6 +882,7 @@ mod tests {
|
||||
assert_eq!(v.iter().map(|p| p.name.as_str()).collect::<Vec<_>>(), vec!["bounce", "Zoom In"]);
|
||||
assert!(scan_presets(&d.join("missing")).is_empty());
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
let set_time = |time| {
|
||||
let mut output = ctx.run_ui(egui::RawInput { time: Some(time), ..Default::default() }, |_| {});
|
||||
output.textures_delta.clear();
|
||||
|
||||
@@ -76,7 +76,7 @@ fn body(app: &mut EffectcraftApp, ui: &mut egui::Ui) -> (Actions, Actions) {
|
||||
// ---- Primary + Solo.
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(RichText::new(tr("Primary:")).color(t.text_dim));
|
||||
let r = craft_ui::ComboBox::from_id_salt("eg-primary").selected_text(&comp_name).width(150.0).show_ui(ui, |ui| {
|
||||
let r = egui::ComboBox::from_id_salt("eg-primary").selected_text(&comp_name).width(150.0).show_ui(ui, |ui| {
|
||||
for (id, _) in project.comps() {
|
||||
let name = project.item(*id).map(|i| i.name.clone()).unwrap_or_default();
|
||||
if ui.selectable_label(*id == cid, name).clicked() {
|
||||
@@ -374,7 +374,7 @@ fn value_widget(app: &mut EffectcraftApp, ui: &mut egui::Ui, auto: &str, ty: Opt
|
||||
_ => vec![],
|
||||
};
|
||||
let cur = v.as_enum() as usize;
|
||||
let r = craft_ui::ComboBox::from_id_salt(("eg-dd", auto)).selected_text(opts.get(cur).cloned().unwrap_or_default()).show_ui(ui, |ui| {
|
||||
let r = egui::ComboBox::from_id_salt(("eg-dd", auto)).selected_text(opts.get(cur).cloned().unwrap_or_default()).show_ui(ui, |ui| {
|
||||
for (i, o) in opts.iter().enumerate() {
|
||||
if ui.selectable_label(i == cur, o).clicked() {
|
||||
out = Some(json!(i));
|
||||
@@ -443,7 +443,7 @@ fn value_widget(app: &mut EffectcraftApp, ui: &mut egui::Ui, auto: &str, ty: Opt
|
||||
let fams = effectcraft_engine::text::fonts::families();
|
||||
let mut d = (**doc).clone();
|
||||
let mut changed = false;
|
||||
let r1 = craft_ui::ComboBox::from_id_salt(("eg-font", auto)).selected_text(&d.font).width(110.0).show_ui(ui, |ui| {
|
||||
let r1 = egui::ComboBox::from_id_salt(("eg-font", auto)).selected_text(&d.font).width(110.0).show_ui(ui, |ui| {
|
||||
for (f, _) in &fams {
|
||||
if ui.selectable_label(*f == d.font, f).clicked() {
|
||||
d.font = f.clone();
|
||||
@@ -452,7 +452,7 @@ fn value_widget(app: &mut EffectcraftApp, ui: &mut egui::Ui, auto: &str, ty: Opt
|
||||
}
|
||||
});
|
||||
let styles: Vec<String> = fams.iter().find(|(f, _)| *f == d.font).map(|(_, st)| st.clone()).unwrap_or_default();
|
||||
let r2 = craft_ui::ComboBox::from_id_salt(("eg-style", auto)).selected_text(&d.style).width(70.0).show_ui(ui, |ui| {
|
||||
let r2 = egui::ComboBox::from_id_salt(("eg-style", auto)).selected_text(&d.style).width(70.0).show_ui(ui, |ui| {
|
||||
for st in &styles {
|
||||
if ui.selectable_label(*st == d.style, st).clicked() {
|
||||
d.style = st.clone();
|
||||
@@ -538,7 +538,7 @@ fn instance(app: &mut EffectcraftApp, ui: &mut egui::Ui, actions: &mut Actions)
|
||||
.filter(|i| matches!(&i.kind, ItemKind::Footage(f) if f.has_video))
|
||||
.map(|i| (i.id, i.name.clone()))
|
||||
.collect();
|
||||
let r = craft_ui::ComboBox::from_id_salt(("eg-media", layer.id.0, c.id)).selected_text(cur_name).show_ui(ui, |ui| {
|
||||
let r = egui::ComboBox::from_id_salt(("eg-media", layer.id.0, c.id)).selected_text(cur_name).show_ui(ui, |ui| {
|
||||
for (id, name) in &items {
|
||||
if ui.selectable_label(*id == cur, name).clicked() {
|
||||
actions.push(("essential.set".into(), json!({"layer": layer.id.0, "control": c.id, "item": id.0})));
|
||||
|
||||
@@ -349,7 +349,7 @@ fn flow_keys(
|
||||
rects: &[Rect],
|
||||
cmds: &mut Vec<(String, Value)>,
|
||||
) {
|
||||
let focused = ctx.memory(|m| m.focused());
|
||||
let focused = crate::framework::focused_widget(ctx);
|
||||
let on_node = focused.is_some_and(|f| g.nodes.iter().any(|n| node_id(&n.id) == f));
|
||||
let by_mouse = focused.is_none() && app.ui.focused == crate::dock::PanelKind::Flowchart;
|
||||
if (on_node || by_mouse) && app.dialog.is_none() && !widgets::any_menu_open(ctx) {
|
||||
|
||||
@@ -905,7 +905,7 @@ fn form_grid(ui: &mut egui::Ui, f: &mut Form, regs: &mut Vec<(String, egui::Rect
|
||||
let cur = options.get(*sel).map(|o| o.0.clone()).unwrap_or_default();
|
||||
// The column keeps its width: a long choice (a GPU adapter's name) ends in an
|
||||
// ellipsis instead of widening the form past the dialog (#978).
|
||||
craft_ui::ComboBox::from_id_salt(("form", fl.key.as_str()))
|
||||
egui::ComboBox::from_id_salt(("form", fl.key.as_str()))
|
||||
.selected_text(tr(&cur))
|
||||
.width(240.0)
|
||||
.truncate()
|
||||
@@ -1090,6 +1090,7 @@ mod tests {
|
||||
for (import_as, background) in [("footage", false), ("composition", true), ("compositionLayerSizes", true)] {
|
||||
let mut app = EffectcraftApp::new(effectcraft_host::session());
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
crate::theme::install(&ctx, &app.tokens, crate::i18n::language(&app));
|
||||
app.dialog_state.form = Form {
|
||||
title: "Import".into(),
|
||||
@@ -1118,6 +1119,7 @@ mod tests {
|
||||
fn a_numeric_form_opens_with_its_first_number_selected() {
|
||||
let mut app = EffectcraftApp::new(effectcraft_engine::Session::default());
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
crate::theme::install(&ctx, &app.tokens, crate::i18n::language(&app));
|
||||
app.dialog_state.form = Form {
|
||||
title: "Position".into(),
|
||||
@@ -1185,6 +1187,7 @@ mod tests {
|
||||
fn premiere_export_dialog() {
|
||||
let mut app = EffectcraftApp::new(effectcraft_engine::Session::default());
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
crate::theme::install(&ctx, &app.tokens, crate::i18n::language(&app));
|
||||
app.session.execute("comp.new", json!({"name": "Spot", "width": 64, "height": 36, "frameRate": 25, "duration": 1})).unwrap();
|
||||
app.session.execute("layer.newSolid", json!({"color": "#ff0000"})).unwrap();
|
||||
|
||||
@@ -583,6 +583,7 @@ mod tests {
|
||||
s.prefs.push_recent("/projects/Alpha.ecproj");
|
||||
let mut app = EffectcraftApp::new(s);
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
crate::theme::install(&ctx, &app.tokens, crate::i18n::language(&app));
|
||||
ctx.run_ui(Default::default(), |_| {}).textures_delta.clear();
|
||||
ctx.run_ui(Default::default(), |ui| {
|
||||
@@ -616,6 +617,7 @@ mod tests {
|
||||
app.ui.start_screen = true;
|
||||
app.ui.home_learn = true;
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
crate::theme::install(&ctx, &app.tokens, crate::i18n::language(&app));
|
||||
let frame = |app: &mut EffectcraftApp| {
|
||||
ctx.run_ui(Default::default(), |ui| {
|
||||
|
||||
@@ -199,7 +199,7 @@ pub fn velocity(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
|
||||
fn combo(ui: &mut egui::Ui, app: &mut EffectcraftApp, id: &str, sel: &mut usize, opts: &[&str], enabled: bool) {
|
||||
ui.add_enabled_ui(enabled, |ui| {
|
||||
// The options are the English source strings; the automation id and label stay English.
|
||||
let r = craft_ui::ComboBox::from_id_salt(id).width(200.0).selected_text(tr(opts[*sel])).show_ui(ui, |ui| {
|
||||
let r = egui::ComboBox::from_id_salt(id).width(200.0).selected_text(tr(opts[*sel])).show_ui(ui, |ui| {
|
||||
for (i, o) in opts.iter().enumerate() {
|
||||
ui.selectable_value(sel, i, tr(o));
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ fn control(ui: &mut egui::Ui, p: &Property, v: &KV) -> Option<Value> {
|
||||
}
|
||||
(KV::Enum(i), ParamUi::Popup { options }) => {
|
||||
let mut sel = *i as usize;
|
||||
craft_ui::ComboBox::from_id_salt(("ls-popup", p.uid)).selected_text(options.get(sel).cloned().unwrap_or_default()).show_ui(ui, |ui| {
|
||||
egui::ComboBox::from_id_salt(("ls-popup", p.uid)).selected_text(options.get(sel).cloned().unwrap_or_default()).show_ui(ui, |ui| {
|
||||
for (k, o) in options.iter().enumerate() {
|
||||
ui.selectable_value(&mut sel, k, o);
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ pub fn dialog(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
|
||||
ui.label(tr("Label:"));
|
||||
let labels = effectcraft_engine::color::Label::ALL;
|
||||
let cur = labels.get(d.label).copied().unwrap_or_default();
|
||||
let r = craft_ui::ComboBox::from_id_salt("dialog.marker.label").selected_text(app.session.prefs.label_name(cur)).show_ui(ui, |ui| {
|
||||
let r = egui::ComboBox::from_id_salt("dialog.marker.label").selected_text(app.session.prefs.label_name(cur)).show_ui(ui, |ui| {
|
||||
for (i, l) in labels.into_iter().enumerate() {
|
||||
if crate::widgets::label_entry(ui, l, &app.session.prefs.label_name(l), d.label == i, &app.tokens).clicked() {
|
||||
d.label = i;
|
||||
@@ -446,7 +446,16 @@ pub(crate) fn marker_bin(app: &mut EffectcraftApp, ui: &mut egui::Ui, comp: &Com
|
||||
ui.ctx().set_cursor_icon(if resp.dragged() { egui::CursorIcon::Grabbing } else { egui::CursorIcon::Grab });
|
||||
}
|
||||
icons::paint(ui.painter(), bin, Icon::MarkerBin, if hot { t.icon_active } else { t.icon });
|
||||
let at = resp.interact_pointer_pos().filter(|p| p.x >= strip.min.x && p.x < strip.max.x).map(|p| {
|
||||
// A drag ends where its button came up: a later press in the same pass (one press per pass
|
||||
// follows a release) has moved the pointer on.
|
||||
let released_at = ui.input(|i| {
|
||||
i.events.iter().find_map(|e| match e {
|
||||
egui::Event::PointerButton { button: egui::PointerButton::Primary, pressed: false, pos, .. } => Some(*pos),
|
||||
_ => None,
|
||||
})
|
||||
});
|
||||
let pointer = if resp.drag_stopped() { released_at.or(resp.interact_pointer_pos()) } else { resp.interact_pointer_pos() };
|
||||
let at = pointer.filter(|p| p.x >= strip.min.x && p.x < strip.max.x).map(|p| {
|
||||
let snapped = snap(app, comp, tm, tm.t(p.x), MarkerRef { layer: None, index: usize::MAX });
|
||||
snapped.min(comp.duration.seconds())
|
||||
});
|
||||
@@ -629,6 +638,7 @@ mod tests {
|
||||
assert_eq!(app.session.execute("markers.list", json!({})).unwrap()[0]["chapter"], "");
|
||||
// Enter is OK and Cmd+Backspace is Delete.
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
crate::theme::install(&ctx, &app.tokens, crate::i18n::language(&app));
|
||||
// The dialog opens with Comment focused (#922), a multi-line field where Enter types a
|
||||
// new line; with the focus elsewhere, Enter is OK.
|
||||
|
||||
@@ -58,7 +58,7 @@ pub fn dialog(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
|
||||
super::dialogs::modal(ctx, "New 3D Primitive", vec2(420.0, 300.0), t, |ui| {
|
||||
egui::Grid::new("primitive-grid").num_columns(2).spacing([14.0, 9.0]).show(ui, |ui| {
|
||||
ui.label(tr("Type"));
|
||||
let combo = craft_ui::ComboBox::from_id_salt("primitive-type").selected_text(tr(d.kind.label())).show_ui(ui, |ui| {
|
||||
let combo = egui::ComboBox::from_id_salt("primitive-type").selected_text(tr(d.kind.label())).show_ui(ui, |ui| {
|
||||
for (i, k) in PrimitiveKind::ALL.into_iter().enumerate() {
|
||||
let item = ui.selectable_value(&mut d.kind, k, tr(k.label()));
|
||||
app.auto.add(&format!("dialog.primitive.typeItem.{i}"), item.rect, k.label());
|
||||
|
||||
@@ -293,10 +293,10 @@ fn selection_seen_id() -> egui::Id {
|
||||
egui::Id::unique("proj-sel-seen")
|
||||
}
|
||||
|
||||
/// The focused widget is one of the panel's rows, or nothing has keyboard focus: the panel's keys
|
||||
/// The focused widget is one of the panel's rows, or no widget has the keyboard: the panel's keys
|
||||
/// apply. Any other focused widget (a text field, a button reached with Tab) keeps them.
|
||||
fn keys_reach_rows(app: &EffectcraftApp, ctx: &egui::Context) -> bool {
|
||||
match ctx.memory(|m| m.focused()) {
|
||||
match crate::framework::focused_widget(ctx) {
|
||||
None => app.ui.focused == crate::dock::PanelKind::Project,
|
||||
Some(f) => ctx.data(|d| d.get_temp::<ItemId>(focused_row_id())).is_some_and(|row| row_id(row) == f),
|
||||
}
|
||||
@@ -330,7 +330,7 @@ fn keyboard_nav(app: &mut EffectcraftApp, ctx: &egui::Context) -> Option<ItemId>
|
||||
{
|
||||
return None;
|
||||
}
|
||||
let row_focused = ctx.memory(|m| m.focused()).is_some();
|
||||
let row_focused = crate::framework::widget_has_keyboard(ctx);
|
||||
let mut moved = None;
|
||||
for (key, m) in keys {
|
||||
let (plain, shift) = (!m.any(), m.shift_only());
|
||||
@@ -1657,6 +1657,7 @@ mod tests {
|
||||
let long = p.add_item("A rather long composition name for the list", Label::Aqua, Some(folder), ItemKind::Folder);
|
||||
let app = EffectcraftApp::new(s);
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
let mut fit = (0.0, 0.0);
|
||||
ctx.run_ui(Default::default(), |ui| {
|
||||
let painter = ui.painter();
|
||||
|
||||
@@ -746,7 +746,7 @@ fn delete_selected(app: &EffectcraftApp, ui: &egui::Ui, allowed: bool, on_row: b
|
||||
&& !crate::widgets::any_menu_open(ui.ctx())
|
||||
&& ui.input(|i| i.key_pressed(egui::Key::Delete) || i.key_pressed(egui::Key::Backspace))
|
||||
// (A focused queue row is not typing; any other focused widget may be.)
|
||||
&& (on_row || !ui.ctx().egui_wants_keyboard_input())
|
||||
&& (on_row || !crate::framework::widget_has_keyboard(ui.ctx()))
|
||||
{
|
||||
actions.push(("renderQueue.remove", json!({"item": id})));
|
||||
*selected = None;
|
||||
@@ -767,7 +767,7 @@ fn list_keys(
|
||||
tops: &[(u64, f32)],
|
||||
list_h: f32,
|
||||
) -> bool {
|
||||
let focused = ctx.memory(|m| m.focused());
|
||||
let focused = crate::framework::focused_widget(ctx);
|
||||
let on_row = focused.is_some_and(|f| queue.iter().any(|i| row_id(i.id) == f));
|
||||
let by_mouse = focused.is_none() && app.ui.focused == crate::dock::PanelKind::RenderQueue;
|
||||
if (on_row || by_mouse) && can_navigate && app.dialog.is_none() && !widgets::any_menu_open(ctx) {
|
||||
|
||||
@@ -61,7 +61,7 @@ pub fn show(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
|
||||
ui.label(slot.label());
|
||||
let cur = templates.default_name(k, slot);
|
||||
let mut pick = cur.clone();
|
||||
let r = craft_ui::ComboBox::from_id_salt(("tpl-def", slot.label())).selected_text(&cur).width(300.0).show_ui(ui, |ui| {
|
||||
let r = egui::ComboBox::from_id_salt(("tpl-def", slot.label())).selected_text(&cur).width(300.0).show_ui(ui, |ui| {
|
||||
for n in &list {
|
||||
ui.selectable_value(&mut pick, n.clone(), n);
|
||||
}
|
||||
@@ -79,7 +79,7 @@ pub fn show(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
|
||||
ui.label(egui::RichText::new(tr("Settings")).font(Tokens::semibold(12.5)).color(t.text));
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(tr("Settings Name:"));
|
||||
let r = craft_ui::ComboBox::from_id_salt("tpl-select").selected_text(&st.selected).width(300.0).show_ui(ui, |ui| {
|
||||
let r = egui::ComboBox::from_id_salt("tpl-select").selected_text(&st.selected).width(300.0).show_ui(ui, |ui| {
|
||||
for n in &list {
|
||||
ui.selectable_value(&mut st.selected, n.clone(), n);
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ fn draw_widget(app: &mut EffectcraftApp, ui: &mut egui::Ui, origin: egui::Pos2,
|
||||
let mut pick: Option<usize> = None;
|
||||
ui.add_enabled_ui(w.enabled, |ui| {
|
||||
ui.scope_builder(UiBuilder::new().max_rect(rect), |ui| {
|
||||
craft_ui::ComboBox::from_id_salt(id).selected_text(cur).width(rect.width() - 8.0).show_ui(ui, |ui| {
|
||||
egui::ComboBox::from_id_salt(id).selected_text(cur).width(rect.width() - 8.0).show_ui(ui, |ui| {
|
||||
for (i, it) in w.items.iter().enumerate() {
|
||||
if it == "-" {
|
||||
ui.separator();
|
||||
@@ -785,6 +785,7 @@ mod tests {
|
||||
/// frame's scroll output (viewport and content size).
|
||||
fn panel_frames(dock: egui::Vec2, first: egui::Vec2, then: egui::Vec2) -> (Rect, egui::Vec2) {
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
ctx.all_styles_mut(|s| s.spacing.scroll = egui::style::ScrollStyle::solid());
|
||||
let screen = Rect::from_min_size(egui::Pos2::ZERO, vec2(800.0, 600.0));
|
||||
let mut last = (Rect::NOTHING, egui::Vec2::ZERO);
|
||||
|
||||
@@ -83,7 +83,7 @@ fn page_ui(app: &mut EffectcraftApp, ui: &mut egui::Ui, page: &Page, cur: &Value
|
||||
ui.add_sized(vec2(label_w, 18.0), egui::Label::new(tr("Default Output:")));
|
||||
let shown = if sel.is_empty() { tr("System Default").to_string() } else { sel.clone() };
|
||||
let shown_name = shown.clone();
|
||||
let r = craft_ui::ComboBox::from_id_salt(("settings", key)).selected_text(shown).width(260.0).show_ui(ui, |ui| {
|
||||
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(), tr("System Default")).clicked() {
|
||||
acts.push(Act::Set(key.into(), json!("")));
|
||||
}
|
||||
@@ -173,7 +173,7 @@ fn page_ui(app: &mut EffectcraftApp, ui: &mut egui::Ui, page: &Page, cur: &Value
|
||||
let curv = v.as_str().map_or_else(|| v.to_string(), str::to_string);
|
||||
let shown = opts.iter().find(|o| o.1 == curv).map(|o| o.0).unwrap_or(curv.as_str()).to_string();
|
||||
value_text = tr(&shown).to_string();
|
||||
craft_ui::ComboBox::from_id_salt(("settings", key))
|
||||
egui::ComboBox::from_id_salt(("settings", key))
|
||||
.selected_text(tr(&shown))
|
||||
.width(220.0)
|
||||
.show_ui(ui, |ui| {
|
||||
@@ -529,7 +529,7 @@ fn appearance_ui(app: &mut EffectcraftApp, ui: &mut egui::Ui, cur: &Value, t: &T
|
||||
ui.horizontal(|ui| {
|
||||
ui.add_sized(vec2(250.0, 18.0), egui::Label::new(format!("{}:", tr("Appearance Mode"))).truncate());
|
||||
let shown = APPEARANCE_MODES.iter().find(|(_, v)| *v == mode).map_or(mode.as_str(), |(l, _)| *l);
|
||||
let r = craft_ui::ComboBox::from_id_salt(("settings", "appearance.appearanceMode"))
|
||||
let r = egui::ComboBox::from_id_salt(("settings", "appearance.appearanceMode"))
|
||||
.selected_text(tr(shown))
|
||||
.width(220.0)
|
||||
.show_ui(ui, |ui| {
|
||||
@@ -1331,6 +1331,7 @@ mod tests {
|
||||
fn sam2_settings_offer_file_installation_without_downloads() {
|
||||
let mut app = EffectcraftApp::new(effectcraft_engine::Session::default());
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
let tokens = app.tokens;
|
||||
let mut actions = vec![];
|
||||
let mut output = ctx
|
||||
@@ -1356,6 +1357,7 @@ mod tests {
|
||||
app.session.sys_memory = Some(effectcraft_engine::sysinfo::SysMemory { total: 64 << 30, available: 60 << 30 });
|
||||
let page = pages().into_iter().find(|p| p.id == "memory").unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
let tokens = app.tokens;
|
||||
let cur = serde_json::to_value(&app.session.prefs).unwrap();
|
||||
let mut actions = vec![];
|
||||
@@ -1385,6 +1387,7 @@ mod tests {
|
||||
// (one frame's elements: `find` returns the first match)
|
||||
app.auto = Default::default();
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
let (tokens, cur) = (app.tokens, serde_json::to_value(&app.session.prefs).unwrap());
|
||||
let mut actions = vec![];
|
||||
let mut output = ctx
|
||||
|
||||
@@ -268,7 +268,7 @@ pub fn show(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
|
||||
// ---- preset bar
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(tr("Preset:"));
|
||||
let r = craft_ui::ComboBox::from_id_salt("sc-preset").selected_text(&active).width(220.0).show_ui(ui, |ui| {
|
||||
let r = egui::ComboBox::from_id_salt("sc-preset").selected_text(&active).width(220.0).show_ui(ui, |ui| {
|
||||
for n in &presets {
|
||||
if ui.selectable_label(*n == active, n).clicked() {
|
||||
run.push(("shortcuts.preset".into(), json!({"op": "select", "name": n})));
|
||||
@@ -676,6 +676,7 @@ mod tests {
|
||||
fn the_ok_button_stays_inside_the_dialog_in_a_small_window() {
|
||||
let mut app = EffectcraftApp::new(effectcraft_engine::Session::default());
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
crate::theme::install(&ctx, &app.tokens, crate::i18n::language(&app));
|
||||
open(&mut app);
|
||||
for size in [vec2(1680.0, 1020.0), vec2(1280.0, 720.0)] {
|
||||
|
||||
@@ -795,11 +795,6 @@ pub(super) fn font_picker(app: &mut EffectcraftApp, ui: &mut egui::Ui, id: egui:
|
||||
let changed = search.changed();
|
||||
let mut open = true;
|
||||
// The search lives in the field; the menu's header is the filter row, its list the fonts.
|
||||
let menu = craft_ui::combo::Menu::new(ui, &search)
|
||||
.open(&mut open)
|
||||
.height(380.0)
|
||||
.close_behavior(egui::PopupCloseBehavior::CloseOnClickOutside)
|
||||
.style(egui::style::StyleModifier::default());
|
||||
let app_ref = &mut *app;
|
||||
let header = |ui: &mut egui::Ui| {
|
||||
ui.set_width(rect.width().max(180.0));
|
||||
@@ -922,7 +917,7 @@ pub(super) fn font_picker(app: &mut EffectcraftApp, ui: &mut egui::Ui, id: egui:
|
||||
}
|
||||
chosen
|
||||
};
|
||||
let chosen = menu.show_ui_with_header(header, list).flatten();
|
||||
let chosen = header_menu(&search, &mut open, FONT_MENU_HEIGHT, header, list).flatten();
|
||||
if chosen.is_some() || !open || escape {
|
||||
ui.data_mut(|d| {
|
||||
d.insert_temp(id.with("open"), false);
|
||||
@@ -1095,6 +1090,34 @@ fn fit_preview(lines: &[Vec<[f32; 2]>], room: Rect, baseline: f32) -> Option<(f3
|
||||
Some((k, o))
|
||||
}
|
||||
|
||||
/// The tallest the font menu gets, its header included.
|
||||
const FONT_MENU_HEIGHT: f32 = 380.0;
|
||||
|
||||
/// A menu under `field` while `open` is true: `header` stays at the top and the list it hands its result to scrolls
|
||||
/// under it, the whole menu up to `height` tall and at least as wide as the field. A click outside closes it (`open`
|
||||
/// turns false). Returns what `list` returned, or `None` while the menu is closed.
|
||||
fn header_menu<H, R>(
|
||||
field: &egui::Response,
|
||||
open: &mut bool,
|
||||
height: f32,
|
||||
header: impl FnOnce(&mut egui::Ui) -> H,
|
||||
list: impl FnOnce(&mut egui::Ui, H) -> R,
|
||||
) -> Option<R> {
|
||||
egui::Popup::from_response(field)
|
||||
.open_bool(open)
|
||||
.max_height_from_constrain(true)
|
||||
.align_alternatives(&[egui::RectAlign::TOP_START])
|
||||
.width(field.rect.width())
|
||||
.close_behavior(egui::PopupCloseBehavior::CloseOnClickOutside)
|
||||
.show(|ui| {
|
||||
ui.set_min_width(ui.available_width());
|
||||
ui.set_max_height(height.min(ui.available_height()));
|
||||
let header = header(ui);
|
||||
egui::ScrollArea::vertical().max_height(ui.available_height().max(0.0)).show(ui, |ui| list(ui, header)).inner
|
||||
})
|
||||
.map(|shown| shown.inner)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -1135,6 +1158,7 @@ mod tests {
|
||||
#[test]
|
||||
fn font_menu_rows_draw_a_name_the_interface_fonts_have() {
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
crate::theme::install(&ctx, &Tokens::for_kind(Default::default()), "en");
|
||||
ctx.run_ui(Default::default(), |_| {}).textures_delta.clear();
|
||||
let row = |display: &str| effectcraft_engine::FontRow { family: "Menu Name Test".into(), display: display.into(), recent: false, variable: false };
|
||||
|
||||
@@ -472,6 +472,7 @@ fn drawn_text(mut draw: impl FnMut(&mut egui::Ui)) -> Vec<String> {
|
||||
}
|
||||
}
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
ctx.run_ui(Default::default(), |ui| draw(ui)).textures_delta.clear();
|
||||
let mut frame = ctx.run_ui(Default::default(), |ui| draw(ui));
|
||||
frame.textures_delta.clear();
|
||||
|
||||
@@ -541,7 +541,7 @@ pub fn options_dialog(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens)
|
||||
(LowConfidence::Adapt, "Adapt Feature"),
|
||||
];
|
||||
let cur = actions.iter().find(|(a, _)| *a == d.opts.action).map(|(_, l)| *l).unwrap_or("Adapt Feature");
|
||||
let r = craft_ui::ComboBox::from_id_salt("track-action")
|
||||
let r = egui::ComboBox::from_id_salt("track-action")
|
||||
.selected_text(cur)
|
||||
.show_ui(ui, |ui| {
|
||||
for (a, l) in actions {
|
||||
@@ -594,7 +594,7 @@ pub fn target_dialog(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens)
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(crate::i18n::tr("Layer:"));
|
||||
let cur = d.target.and_then(|id| layers.iter().find(|(l, _)| *l == id)).map(|(_, n)| n.clone()).unwrap_or_else(|| "None".into());
|
||||
let r = craft_ui::ComboBox::from_id_salt("track-target")
|
||||
let r = egui::ComboBox::from_id_salt("track-target")
|
||||
.selected_text(cur)
|
||||
.width(240.0)
|
||||
.show_ui(ui, |ui| {
|
||||
@@ -627,7 +627,7 @@ pub fn apply_dialog(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(crate::i18n::tr("Apply Dimensions:"));
|
||||
let labels = [crate::i18n::tr("X and Y"), crate::i18n::tr("X only"), crate::i18n::tr("Y only")];
|
||||
let r = craft_ui::ComboBox::from_id_salt("track-apply-dims")
|
||||
let r = egui::ComboBox::from_id_salt("track-apply-dims")
|
||||
.selected_text(labels[d.dims.min(2)])
|
||||
.show_ui(ui, |ui| {
|
||||
for (i, l) in labels.iter().enumerate() {
|
||||
|
||||
@@ -55,25 +55,24 @@ fn ask(app: &mut EffectcraftApp, id: &str, params: &Value) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
/// The window's close button (and Quit, which closes it): keep the window open and ask.
|
||||
pub fn on_close_requested(app: &mut EffectcraftApp, ctx: &egui::Context) {
|
||||
if !ctx.input(|i| i.viewport().close_requested()) || app.dialog_state.unsaved.quitting {
|
||||
return;
|
||||
/// The root window's close decision, which the runtime's close path (`crate::framework`, `close_path`) asks when the
|
||||
/// window's close button, Quit or `app.quit` closes the window. A lost graphics device and an answered Quit prompt
|
||||
/// close; a running script render holds the window (a close is no permission to abandon the script, and once Stop
|
||||
/// finishes it a new close is asked about as usual); a modified project holds it while the Unsaved Changes prompt
|
||||
/// asks. On macOS a close that nothing holds quits through the platform (the runtime's close path).
|
||||
pub fn close_decision(app: &mut EffectcraftApp) -> craft_ui::shell::embed::CloseDecision {
|
||||
if app.device_lost_close.is_some() {
|
||||
return crate::framework::decide(true);
|
||||
}
|
||||
if app.session.script_ui.render_host.is_some() {
|
||||
return crate::framework::decide(false);
|
||||
}
|
||||
if app.dialog_state.unsaved.quitting {
|
||||
return crate::framework::decide(true);
|
||||
}
|
||||
// Logged, so a window that closes on its own shows it (#234).
|
||||
log::info!("the window was asked to close");
|
||||
if ask(app, "app.quit", &json!({})) {
|
||||
ctx.send_viewport_cmd(egui::ViewportCommand::CancelClose);
|
||||
}
|
||||
}
|
||||
|
||||
/// On macOS a close that nothing held open quits through `-[NSApplication terminate:]` instead:
|
||||
/// closing the window while AppKit's run loop is running crashes on a Mac with a Touch Bar
|
||||
/// (#341). `on_exit` still runs. A desktop host calls it last in `logic`, after
|
||||
/// `EffectcraftApp::tick` (which runs [`on_close_requested`]) and its own work. Returns whether
|
||||
/// that quit was scheduled; other platforms close the window as before.
|
||||
pub fn quit_on_close(ctx: &egui::Context) -> bool {
|
||||
craft_quit::on_close_request(ctx)
|
||||
crate::framework::decide(!ask(app, "app.quit", &json!({})))
|
||||
}
|
||||
|
||||
/// The project's display name: its file name, or `Untitled Project.ecproj`.
|
||||
@@ -211,6 +210,7 @@ mod tests {
|
||||
|
||||
fn app() -> (EffectcraftApp, egui::Context) {
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
let app = EffectcraftApp::new(effectcraft_engine::Session::default());
|
||||
crate::theme::install(&ctx, &app.tokens, crate::i18n::language(&app));
|
||||
(app, ctx)
|
||||
@@ -225,29 +225,17 @@ mod tests {
|
||||
}
|
||||
let mut out = ctx.run_ui(raw, |ui| {
|
||||
app.auto.begin_frame();
|
||||
on_close_requested(app, ui.ctx());
|
||||
app.close_path(ui.ctx());
|
||||
crate::panels::dialogs::show(app, ui.ctx());
|
||||
});
|
||||
out.textures_delta.clear();
|
||||
out.viewport_output.get(&egui::ViewportId::ROOT).is_some_and(|v| v.commands.contains(&egui::ViewportCommand::CancelClose))
|
||||
}
|
||||
|
||||
/// One frame of the dialogs with the window's close button pressed, through
|
||||
/// [`on_close_requested`] and then [`quit_on_close`] as the app runs them; returns whether the
|
||||
/// close was canceled and whether the platform quit was scheduled.
|
||||
fn close_frame(app: &mut EffectcraftApp, ctx: &egui::Context) -> (bool, bool) {
|
||||
let mut raw = egui::RawInput::default();
|
||||
raw.viewports.entry(egui::ViewportId::ROOT).or_default().events.push(egui::ViewportEvent::Close);
|
||||
let mut quits = false;
|
||||
let mut out = ctx.run_ui(raw, |ui| {
|
||||
app.auto.begin_frame();
|
||||
on_close_requested(app, ui.ctx());
|
||||
quits = quit_on_close(ui.ctx());
|
||||
crate::panels::dialogs::show(app, ui.ctx());
|
||||
});
|
||||
out.textures_delta.clear();
|
||||
let canceled = out.viewport_output.get(&egui::ViewportId::ROOT).is_some_and(|v| v.commands.contains(&egui::ViewportCommand::CancelClose));
|
||||
(canceled, quits)
|
||||
/// One frame of the dialogs with the window's close button pressed, through the runtime's close path as the app
|
||||
/// runs it; returns whether the close was canceled (held, or taken by the platform quit on macOS).
|
||||
fn close_frame(app: &mut EffectcraftApp, ctx: &egui::Context) -> bool {
|
||||
frame(app, ctx, true)
|
||||
}
|
||||
|
||||
fn modified(app: &mut EffectcraftApp) {
|
||||
@@ -412,7 +400,7 @@ mod tests {
|
||||
fn closing_a_saved_project_quits_through_the_platform_on_macos() {
|
||||
let (mut app, ctx) = app();
|
||||
let macos = cfg!(target_os = "macos");
|
||||
assert_eq!(close_frame(&mut app, &ctx), (macos, macos));
|
||||
assert_eq!(close_frame(&mut app, &ctx), macos);
|
||||
assert!(app.dialog.is_none(), "nothing to ask");
|
||||
}
|
||||
|
||||
@@ -420,14 +408,14 @@ mod tests {
|
||||
fn closing_a_modified_project_asks_before_the_platform_quit() {
|
||||
let (mut app, ctx) = app();
|
||||
modified(&mut app);
|
||||
assert_eq!(close_frame(&mut app, &ctx), (true, false), "the prompt holds the window and nothing quits");
|
||||
assert!(close_frame(&mut app, &ctx), "the prompt holds the window");
|
||||
assert_eq!(app.dialog, Some(Dialog::UnsavedChanges));
|
||||
answer_with(&mut app, &ctx, Answer::Cancel);
|
||||
assert!(app.session.is_dirty() && !app.dialog_state.unsaved.quitting);
|
||||
assert_eq!(close_frame(&mut app, &ctx), (true, false), "asked again after Cancel");
|
||||
assert!(close_frame(&mut app, &ctx), "asked again after Cancel");
|
||||
answer_with(&mut app, &ctx, Answer::Discard);
|
||||
let macos = cfg!(target_os = "macos");
|
||||
assert_eq!(close_frame(&mut app, &ctx), (macos, macos), "Don't Save quits");
|
||||
assert_eq!(close_frame(&mut app, &ctx), macos, "Don't Save closes");
|
||||
}
|
||||
|
||||
/// While the window is minimized or hidden, eframe runs `App::logic` without `App::ui` and
|
||||
|
||||
@@ -547,7 +547,7 @@ fn phase_layers(app: &mut EffectcraftApp, ui: &mut egui::Ui, ectx: &EvalCtx, v:
|
||||
let sel_vertices = app.session.state.selected_vertices.clone();
|
||||
// Pen path in progress ends when the tool changes or its mask is gone; Esc / Enter also end
|
||||
// free transform.
|
||||
let finish = ui.input(|i| i.key_pressed(egui::Key::Escape) || i.key_pressed(egui::Key::Enter)) && !ctx.egui_wants_keyboard_input();
|
||||
let finish = ui.input(|i| i.key_pressed(egui::Key::Escape) || i.key_pressed(egui::Key::Enter)) && !crate::framework::widget_has_keyboard(&ctx);
|
||||
if app.ui.tool != Tool::Pen || finish {
|
||||
ui.data_mut(|d| d.remove::<(LayerId, u64)>(pen_id()));
|
||||
}
|
||||
@@ -884,7 +884,8 @@ fn phase_menu(app: &mut EffectcraftApp, ui: &mut egui::Ui, ectx: &EvalCtx, v: &m
|
||||
super::viewer_drop::show(app, ui, &painter, &map, ectx);
|
||||
|
||||
// Interaction.
|
||||
let resp = ui.interact(area, egui::Id::unique("viewer-interact"), Sense::click_and_drag());
|
||||
let resp = ui.interact(area, crate::framework::viewer_id(), Sense::click_and_drag());
|
||||
crate::framework::host_canvas(ui.ctx());
|
||||
let menu_hits_id = egui::Id::unique(("viewer-menu-hits", cid.0));
|
||||
// A right-click an overlay took (the Cryptomatte eyedropper's) opens the menu too.
|
||||
let forwarded = ui.data_mut(|d| d.remove_temp::<egui::Pos2>(egui::Id::unique(FORWARDED_SECONDARY)));
|
||||
|
||||
@@ -1075,6 +1075,29 @@ pub fn hook(
|
||||
owns
|
||||
}
|
||||
|
||||
/// Answers an IME reset that the integration completed or retired, while `custom_mutations` is on: whether `event` is
|
||||
/// one.
|
||||
fn reset_ended(app: &EffectcraftApp, ui: &egui::Ui, event: &egui::Event, custom_mutations: bool) -> bool {
|
||||
match event {
|
||||
egui::Event::ImeResetCompleted { request_id } => {
|
||||
if custom_mutations {
|
||||
complete_reset(app, ui, *request_id);
|
||||
}
|
||||
true
|
||||
}
|
||||
egui::Event::ImeResetRetired { request_id } => {
|
||||
// The integration dropped the request and no completion will follow: ask again, or the
|
||||
// composition stays stale forever.
|
||||
let ctx = ui.ctx();
|
||||
if custom_mutations && read_reset(ctx).is_some_and(|guard| !guard.suspended && guard.request == Some(*request_id)) {
|
||||
request_reset(app, ctx);
|
||||
}
|
||||
true
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// This frame's keys, in order, into the edited text, up to a press outside the `viewer`: the
|
||||
/// panel it lands in decides (after this frame's panels) whether the edit ends, so the keys after
|
||||
/// it in this frame are neither typed nor run as shortcuts (#831).
|
||||
@@ -1106,10 +1129,7 @@ fn keyboard(app: &mut EffectcraftApp, ui: &mut egui::Ui, viewer: Rect) {
|
||||
ctx.input_mut(|input| input.events.retain(|event| !matches!(event, egui::Event::ImeResetCompleted { .. })));
|
||||
let mut custom_mutations = app.session.state.text_edit.is_some();
|
||||
for ev in events {
|
||||
if let egui::Event::ImeResetCompleted { request_id } = &ev {
|
||||
if custom_mutations {
|
||||
complete_reset(app, ui, *request_id);
|
||||
}
|
||||
if reset_ended(app, ui, &ev, custom_mutations) {
|
||||
continue;
|
||||
}
|
||||
sync_ime_target(ui, app);
|
||||
|
||||
@@ -22,6 +22,7 @@ fn doc_text(app: &EffectcraftApp, lid: LayerId) -> String {
|
||||
|
||||
fn feed(app: &mut EffectcraftApp, events: Vec<egui::Event>) {
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
let raw = egui::RawInput { screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(320.0, 180.0))), events, ..Default::default() };
|
||||
let mut out = ctx.run_ui(raw, |ui| keyboard(app, ui, egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(320.0, 180.0))));
|
||||
out.textures_delta.clear();
|
||||
@@ -44,6 +45,7 @@ fn ending_an_edit_from_another_panel_clears_the_preedit() {
|
||||
let (mut app, lid) = editor("abc", 0, 0);
|
||||
let session = app.session.state.text_edit.as_ref().map_or(1, |e| e.session);
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
let mut out = ctx.run_ui(egui::RawInput::default(), |ui| {
|
||||
let viewport = ui.ctx().viewport_id();
|
||||
let preedit = Preedit { owner: ImeOwner { layer: lid, session }, text: "x".into() };
|
||||
@@ -143,9 +145,9 @@ impl ImePass {
|
||||
}
|
||||
|
||||
/// One native floating window holding the Timeline's group and then the Viewer's.
|
||||
fn two_group_window() -> craft_ui::docking::Floating<PanelKind> {
|
||||
let groups = vec![craft_ui::docking::Group::new(vec![PanelKind::Timeline], 0), craft_ui::docking::Group::new(vec![PanelKind::Viewer(1)], 0)];
|
||||
craft_ui::docking::Floating::stack(groups, [0.0, 0.0, 320.0, 360.0]).expect("two groups make a window")
|
||||
fn two_group_window() -> craft_behavior::dock::Floating<PanelKind> {
|
||||
let groups = vec![craft_behavior::dock::Group::new(vec![PanelKind::Timeline], 0), craft_behavior::dock::Group::new(vec![PanelKind::Viewer(1)], 0)];
|
||||
craft_behavior::dock::Floating::stack(1, groups, egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(320.0, 360.0))).expect("two groups make a window")
|
||||
}
|
||||
|
||||
impl ImePass {
|
||||
@@ -155,7 +157,7 @@ impl ImePass {
|
||||
fn window(
|
||||
&mut self,
|
||||
app: &mut EffectcraftApp,
|
||||
window: &craft_ui::docking::Floating<PanelKind>,
|
||||
window: &craft_behavior::dock::Floating<PanelKind>,
|
||||
events: Vec<egui::Event>,
|
||||
viewer_first: bool,
|
||||
every: bool,
|
||||
@@ -167,7 +169,7 @@ impl ImePass {
|
||||
let raw = egui::RawInput { viewport_id: viewport, viewports, screen_rect: Some(rect), events, ..Default::default() };
|
||||
let mut preedit = None;
|
||||
let mut out = ctx.run_ui(raw, |ui| {
|
||||
let mut ime = crate::dock_ui::NativeIme::new(std::slice::from_ref(window), &[]);
|
||||
let mut ime = crate::dock_ui::NativeIme::new(std::slice::from_ref(window), &[(PanelKind::Timeline, viewport)], &[]);
|
||||
let order = if viewer_first { [true, false] } else { [false, true] };
|
||||
for viewer in order {
|
||||
if ime.begin_body(viewport) {
|
||||
@@ -196,7 +198,7 @@ impl ImePass {
|
||||
#[test]
|
||||
fn native_window_with_a_group_before_the_viewer_keeps_the_composition() {
|
||||
let window = two_group_window();
|
||||
let viewport = craft_ui::docking::DockArea::<PanelKind>::window_viewport(crate::dock_ui::area_id(), window.id);
|
||||
let viewport = egui::ViewportId::from_hash_of(("native panel window", window.id));
|
||||
let preview = || egui::Event::Ime(egui::ImeEvent::Preedit { text: "é".into(), active_range_chars: None });
|
||||
for viewer_first in [false, true] {
|
||||
let (mut app, _) = editor("abcd", 4, 4);
|
||||
@@ -221,12 +223,12 @@ fn native_window_with_a_group_before_the_viewer_keeps_the_composition() {
|
||||
assert_eq!(preedit, None);
|
||||
// A window that drew fewer bodies than its layout counts publishes after every body in
|
||||
// its next pass.
|
||||
let mut ime = crate::dock_ui::NativeIme::new(std::slice::from_ref(&window), &[]);
|
||||
let mut ime = crate::dock_ui::NativeIme::new(std::slice::from_ref(&window), &[(PanelKind::Timeline, viewport)], &[]);
|
||||
ime.begin_body(viewport);
|
||||
assert!(!ime.publishes(viewport, false));
|
||||
let unpublished = ime.unpublished();
|
||||
assert_eq!(unpublished, vec![viewport]);
|
||||
let mut ime = crate::dock_ui::NativeIme::new(std::slice::from_ref(&window), &unpublished);
|
||||
let mut ime = crate::dock_ui::NativeIme::new(std::slice::from_ref(&window), &[(PanelKind::Timeline, viewport)], &unpublished);
|
||||
ime.begin_body(viewport);
|
||||
assert!(ime.publishes(viewport, false));
|
||||
}
|
||||
@@ -243,6 +245,7 @@ fn discarded_custom_request_then_home_rearms_the_identical_caret() {
|
||||
app.ui.tool = Tool::Type;
|
||||
app.ui.focused = PanelKind::Composition;
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
install_hooks(&ctx);
|
||||
let mut frame = eframe::Frame::_new_kittest();
|
||||
let raw = || egui::RawInput { screen_rect: Some(Rect::from_min_size(Pos2::ZERO, vec2(1200.0, 800.0))), ..Default::default() };
|
||||
@@ -315,6 +318,18 @@ fn discarded_custom_request_then_home_rearms_the_identical_caret() {
|
||||
assert_eq!(doc_text(&app, lid), "aがbcd");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_retired_reset_request_is_asked_again() {
|
||||
let (mut app, _) = editor("abcd", 4, 4);
|
||||
let mut pass = ImePass::new(egui::ViewportId::ROOT);
|
||||
let preview = || egui::Event::Ime(egui::ImeEvent::Preedit { text: "é".into(), active_range_chars: None });
|
||||
pass.frame(&mut app, vec![preview()], true, false);
|
||||
app.session.execute("text.setSelection", json!({"caret": 1})).unwrap();
|
||||
let first = pass.frame(&mut app, vec![], true, false).unwrap().reset_request.unwrap();
|
||||
let again = pass.frame(&mut app, vec![egui::Event::ImeResetRetired { request_id: first }], true, false).unwrap().reset_request;
|
||||
assert!(again.is_some_and(|id| id != first), "a retired request is replaced by a new one");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn viewport_fences_and_duplicate_completion_keep_their_exact_lifetime() {
|
||||
let (mut app, lid) = editor("abcd", 4, 4);
|
||||
@@ -752,6 +767,7 @@ fn fonts_and_device_loss_all_exit_finalizers_suspend_without_allocating() {
|
||||
app.ui.focused = PanelKind::Composition;
|
||||
app.show_panel(PanelKind::Composition);
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
install_hooks(&ctx);
|
||||
let frame = eframe::Frame::_new_kittest();
|
||||
let preview = || egui::Event::Ime(egui::ImeEvent::Preedit { text: "é".into(), active_range_chars: None });
|
||||
@@ -768,19 +784,13 @@ fn fonts_and_device_loss_all_exit_finalizers_suspend_without_allocating() {
|
||||
.reset_request
|
||||
.expect("one request for the caret interruption");
|
||||
|
||||
// A real font-install pass draws nothing, but `draw` still reaches the finalizer.
|
||||
// A font install asks egui for a discard pass in the same frame. The install pass draws nothing, and its
|
||||
// all-exit finalizer retires the waiting guard without allocating; the discard pass draws with the fonts and
|
||||
// publishes the one deferred request.
|
||||
app.styled = false;
|
||||
let fonts = draw_app_pass(&mut app, &ctx, &frame, vec![]);
|
||||
assert!(!app.is_ready(), "the font-install pass cannot draw");
|
||||
assert!(fonts.platform_output.ime.is_none(), "no custom descriptor is published");
|
||||
let guard = ctx.data(|d| d.get_temp::<ResetGuard>(reset_id(egui::ViewportId::ROOT))).expect("the waiting guard");
|
||||
assert!(guard.suspended && guard.request.is_none(), "the all-exit finalizer retired it without allocating");
|
||||
let second = draw_app_pass(&mut app, &ctx, &frame, vec![])
|
||||
.platform_output
|
||||
.ime
|
||||
.expect("returning to a drawing pass publishes the custom descriptor")
|
||||
.reset_request
|
||||
.expect("the deferred request");
|
||||
assert!(app.is_ready(), "the discard pass after the font install draws");
|
||||
let second = fonts.platform_output.ime.expect("the drawing discard pass publishes the custom descriptor").reset_request.expect("the deferred request");
|
||||
assert_ne!(first, second);
|
||||
|
||||
// The device-loss early return is the other all-exit path. Preset the close bookkeeping
|
||||
|
||||
@@ -346,7 +346,7 @@ pub(crate) fn shown_region(ctx: &egui::Context, comp: [f32; 2]) -> [f64; 4] {
|
||||
|
||||
/// Show Snapshot: the stored snapshot is on screen (button or F5 held).
|
||||
pub(crate) fn showing_snapshot(app: &EffectcraftApp, ctx: &egui::Context) -> bool {
|
||||
let f5 = ctx.input(|i| i.key_down(egui::Key::F5)) && !ctx.egui_wants_keyboard_input();
|
||||
let f5 = ctx.input(|i| i.key_down(egui::Key::F5)) && !crate::framework::widget_has_keyboard(ctx);
|
||||
app.session.snapshot.is_some() && (app.session.state.viewer.show_snapshot || f5)
|
||||
}
|
||||
|
||||
@@ -943,7 +943,8 @@ fn bottom_bar_contents(app: &mut EffectcraftApp, ui: &mut egui::Ui, bar: Rect, z
|
||||
let renderers = [(Renderer::Classic3D, "Classic 3D", "classic3D"), (Renderer::Advanced3D, "Advanced 3D", "advanced3D")];
|
||||
let current = renderers.iter().find(|(r, ..)| *r == comp.renderer).map_or("Classic 3D", |(_, label, _)| *label);
|
||||
let r = Rect::from_min_size(pos2(x, cy - 10.0), vec2(96.0, 20.0));
|
||||
if widgets::dropdown(ui, r, crate::i18n::tr(current), &t, egui::Id::unique("vw-3d")).clicked() {
|
||||
let renderer_resp = widgets::dropdown(ui, r, crate::i18n::tr(current), &t, egui::Id::unique("vw-3d"));
|
||||
if renderer_resp.clicked() {
|
||||
toggle_popup(ui, "vw-3d-pop");
|
||||
}
|
||||
app.auto.add("viewer.renderer3d", r, current);
|
||||
|
||||
@@ -327,7 +327,7 @@ fn add_viewer(app: &mut EffectcraftApp, near: u32) -> u32 {
|
||||
app.ui.viewers.insert(id, None);
|
||||
let p = panel(id);
|
||||
let anchor = [panel(near), PanelKind::Composition].into_iter().find(|q| app.ui.dock.is_open(*q));
|
||||
let _ = app.ui.dock.apply(craft_ui::docking::Action::Open { panel: p, anchor }, crate::dock::permissions);
|
||||
let _ = app.ui.dock.apply(craft_behavior::dock::Action::open(p, anchor), app.ui.dock_locked, crate::dock::permissions);
|
||||
id
|
||||
}
|
||||
|
||||
|
||||
@@ -288,6 +288,7 @@ fn real_properties_and_angle_drags_keep_each_gesture_in_one_undo_step() {
|
||||
app.show_panel(panel);
|
||||
app.toggle_maximize(panel);
|
||||
let ctx = Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
let bounds = Rect::from_min_size(Pos2::ZERO, vec2(1600.0, 1000.0));
|
||||
let mut frame = eframe::Frame::_new_kittest();
|
||||
let mut time = 0.0;
|
||||
|
||||
@@ -653,11 +653,9 @@ pub struct UiState {
|
||||
/// The panel maximized to fill the dock area (`~`), if any.
|
||||
#[serde(default)]
|
||||
pub maximized: Option<PanelKind>,
|
||||
/// Floating windows of [`Self::dock`] whose native rect holds the OS window's outer
|
||||
/// position, from a workspace file of an earlier version (see
|
||||
/// `crate::dock_ui::native_outer_to_content`). Workspaces are not saved while any remain.
|
||||
#[serde(skip)]
|
||||
pub native_outer: Vec<u64>,
|
||||
/// Lock Workspace: no panel of [`Self::dock`] moves, floats or closes.
|
||||
#[serde(default)]
|
||||
pub dock_locked: bool,
|
||||
/// Locked Composition / Timeline tabs (panel ids): opening another composition does not
|
||||
/// bring a locked panel forward (the tab's lock icon, as After Effects' viewer lock).
|
||||
#[serde(default)]
|
||||
@@ -792,7 +790,7 @@ impl Default for UiState {
|
||||
workspace: "Default".into(),
|
||||
dock: crate::dock::Workspace::new(crate::dock::workspace("Default")),
|
||||
saved_workspaces: Default::default(),
|
||||
native_outer: Vec::new(),
|
||||
dock_locked: false,
|
||||
maximized: None,
|
||||
locked_tabs: BTreeSet::new(),
|
||||
effect_controls_lock: None,
|
||||
|
||||
@@ -393,7 +393,7 @@ pub fn install(ctx: &egui::Context, t: &Tokens, language: &str) {
|
||||
stack.push("noto-symbols2".into());
|
||||
}
|
||||
install_script_fallbacks(&mut fonts, language);
|
||||
ctx.set_fonts(fonts);
|
||||
craft_ui::fonts::load(ctx, fonts);
|
||||
apply_visuals(ctx, t);
|
||||
}
|
||||
|
||||
@@ -682,6 +682,7 @@ mod script_font_tests {
|
||||
/// interface's fonts installed.
|
||||
fn assert_drawn(language: &str, text: &str) {
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
super::install(&ctx, &super::Tokens::for_kind(super::ThemeKind::Dark), language);
|
||||
let mut out = ctx.run_ui(egui::RawInput::default(), |_| {});
|
||||
// No renderer here: drop the frame's texture uploads (egui asserts on unhandled ones in debug).
|
||||
@@ -767,6 +768,7 @@ mod script_font_tests {
|
||||
#[test]
|
||||
fn simplified_chinese_interface_draws_simplified_hanzi_after_another_language() {
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
let tokens = super::Tokens::for_kind(super::ThemeKind::Dark);
|
||||
super::install(&ctx, &tokens, "en");
|
||||
super::install(&ctx, &tokens, "zh-hans");
|
||||
@@ -798,6 +800,7 @@ mod script_font_tests {
|
||||
return;
|
||||
}
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
super::install(&ctx, &super::Tokens::for_kind(super::ThemeKind::Dark), "en");
|
||||
let mut out = ctx.run_ui(egui::RawInput::default(), |_| {});
|
||||
out.textures_delta.clear();
|
||||
@@ -839,6 +842,7 @@ mod script_font_tests {
|
||||
return;
|
||||
}
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
ctx.set_pixels_per_point(2.0);
|
||||
super::install(&ctx, &super::Tokens::for_kind(super::ThemeKind::Dark), "ja");
|
||||
let mut out = ctx.run_ui(egui::RawInput::default(), |_| {});
|
||||
@@ -923,6 +927,7 @@ mod tests {
|
||||
#[test]
|
||||
fn every_family_reaches_the_symbol_fallback() {
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
install(&ctx, &Tokens::for_kind(Default::default()), "en");
|
||||
ctx.run_ui(Default::default(), |_| {}).textures_delta.clear();
|
||||
for family in [FontFamily::Proportional, FontFamily::Monospace, FontFamily::Name("medium".into()), FontFamily::Name("semibold".into())] {
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
//! Software updates, background check at startup, and startup prompt modal.
|
||||
//! Software updates, background check at startup, and startup prompt modal, as craft-update's
|
||||
//! dialogs on the app's [`DialogHost`](craft_ui::dialog::DialogHost).
|
||||
|
||||
use crate::EffectcraftApp;
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
use craft_update::dialog::{CheckResultDialog, CheckResultResponse};
|
||||
use craft_ui::dialog::DialogResult;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
use craft_update::stack_dialogs::{CheckChoice, UpdateCheckDialog};
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
use craft_update::updater::{Action, Status, Updater};
|
||||
|
||||
@@ -60,7 +63,7 @@ pub(crate) fn restart_to_update(rt: &mut Runtime, ctx: &egui::Context, clean: bo
|
||||
}
|
||||
// Without a prompt this only takes the close a finished installation queued, so a save after
|
||||
// Cancel does not close the app.
|
||||
let _ = rt.updater.show_if(ctx, true);
|
||||
let _ = rt.updater.take_close(true);
|
||||
ctx.send_viewport_cmd(egui::ViewportCommand::Close);
|
||||
}
|
||||
|
||||
@@ -88,9 +91,9 @@ pub(crate) fn tick(app: &mut EffectcraftApp, ctx: &egui::Context) {
|
||||
{
|
||||
let rt = &mut app.updates_rt;
|
||||
if std::mem::take(&mut rt.check_requested) {
|
||||
rt.updater.check_now(ctx);
|
||||
rt.updater.check_now();
|
||||
} else if rt.startup_check {
|
||||
rt.updater.check_at_start(ctx);
|
||||
rt.updater.check_at_start();
|
||||
}
|
||||
rt.updater.tick(ctx);
|
||||
}
|
||||
@@ -107,28 +110,48 @@ pub(crate) fn result_window_open(open: bool, status: &Status, check_requested: b
|
||||
!matches!(status, Status::Idle) || (open && check_requested)
|
||||
}
|
||||
|
||||
/// One pass of the update flow, before the dialog host runs: answers the result dialog closed in
|
||||
/// the last pass, drives the update prompt, and keeps the result dialog open and current while it
|
||||
/// answers Help ▸ Check for Updates or the updater has something to report.
|
||||
pub(crate) fn show(app: &mut EffectcraftApp, ctx: &egui::Context) {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
// The restart helper is scheduled before the app closes, so no update starts over unsaved work.
|
||||
let clean = !app.session.is_dirty();
|
||||
match app.updates_rt.updater.show_if(ctx, clean) {
|
||||
// Answered before the dialog is kept open below, so a dismissed outcome does not open again at once.
|
||||
match app.framework_dialogs.take::<UpdateCheckDialog>() {
|
||||
Some(DialogResult::Ok(CheckChoice::CheckNow | CheckChoice::CheckAgain)) => app.updates_rt.updater.check_now(),
|
||||
Some(DialogResult::Ok(CheckChoice::RestartToUpdate)) => restart_to_update(&mut app.updates_rt, ctx, clean),
|
||||
Some(DialogResult::Ok(CheckChoice::Update)) => {
|
||||
app.updates_rt.updater.request_install(clean);
|
||||
}
|
||||
Some(DialogResult::Ok(CheckChoice::Download)) => ctx.open_url(egui::OpenUrl::new_tab(crate::UPDATE_APP.releases_url())),
|
||||
// Closing the dialog dismisses the outcome it showed.
|
||||
Some(_) => {
|
||||
app.updates_rt.manual_window_open = false;
|
||||
app.updates_rt.updater.dismiss_status();
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
match app.updates_rt.updater.run(&mut app.framework_dialogs, clean) {
|
||||
Action::OpenUrl(url) => ctx.open_url(egui::OpenUrl::new_tab(url)),
|
||||
Action::Close => ctx.send_viewport_cmd(egui::ViewportCommand::Close),
|
||||
Action::None => {}
|
||||
_ => {}
|
||||
}
|
||||
let rt = &mut app.updates_rt;
|
||||
rt.manual_window_open = result_window_open(rt.manual_window_open, rt.updater.status(), rt.check_requested);
|
||||
if rt.manual_window_open {
|
||||
match CheckResultDialog::new(&crate::UPDATE_APP, env!("CARGO_PKG_VERSION")).show(ctx, rt.updater.status()) {
|
||||
CheckResultResponse::None => {}
|
||||
CheckResultResponse::Close => {
|
||||
rt.manual_window_open = false;
|
||||
rt.updater.dismiss_status();
|
||||
}
|
||||
CheckResultResponse::CheckAgain => rt.updater.check_now(ctx),
|
||||
CheckResultResponse::RestartToUpdate => restart_to_update(rt, ctx, clean),
|
||||
}
|
||||
let shows = rt.manual_window_open;
|
||||
let (status, installing, message) = (rt.updater.status().clone(), rt.updater.is_installing(), rt.updater.status_message());
|
||||
let dialogs = &mut app.framework_dialogs;
|
||||
if shows && !dialogs.is_open::<UpdateCheckDialog>() {
|
||||
dialogs.open(UpdateCheckDialog::new(env!("CARGO_PKG_VERSION")));
|
||||
} else if !shows && dialogs.is_open::<UpdateCheckDialog>() {
|
||||
dialogs.cancel::<UpdateCheckDialog>(ctx);
|
||||
}
|
||||
if let Some(dialog) = dialogs.get_mut::<UpdateCheckDialog>() {
|
||||
dialog.set_status(status);
|
||||
dialog.set_installing(installing);
|
||||
dialog.set_message(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1399,6 +1399,7 @@ mod tests {
|
||||
#[test]
|
||||
fn inline_editors_select_all_only_as_they_open() {
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
let mut text = String::from("Comp 1");
|
||||
let mut id = egui::Id::NULL;
|
||||
let frame = |ctx: &egui::Context, text: &mut String, id: &mut egui::Id| {
|
||||
@@ -1438,6 +1439,7 @@ mod tests {
|
||||
#[test]
|
||||
fn field_text_is_vertically_centred() {
|
||||
let ctx = egui::Context::default();
|
||||
crate::framework::install_headless(&ctx);
|
||||
let t = Tokens::for_kind(Default::default());
|
||||
for h in [22.0, 26.0, 30.0] {
|
||||
let field = Rect::from_min_size(pos2(20.0, 40.0), vec2(220.0, h));
|
||||
|
||||
@@ -28,6 +28,10 @@ struct Snapshot {
|
||||
focused: PanelKind,
|
||||
maximized: Option<PanelKind>,
|
||||
saved_workspaces: BTreeMap<String, Workspace>,
|
||||
/// Lock Workspace. A file without it loads unlocked, unless its workspace carries the
|
||||
/// earlier format's own `locked` ([`WorkspaceStore::load`]).
|
||||
#[serde(default)]
|
||||
locked: bool,
|
||||
}
|
||||
|
||||
impl Snapshot {
|
||||
@@ -39,6 +43,7 @@ impl Snapshot {
|
||||
focused: ui.focused,
|
||||
maximized: ui.maximized,
|
||||
saved_workspaces: ui.saved_workspaces.clone(),
|
||||
locked: ui.dock_locked,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,12 +53,7 @@ impl Snapshot {
|
||||
ui.focused = self.focused;
|
||||
ui.maximized = self.maximized;
|
||||
ui.saved_workspaces = self.saved_workspaces;
|
||||
// A native window's place is made safe to hand to the windowing system.
|
||||
for workspace in std::iter::once(&mut ui.dock).chain(ui.saved_workspaces.values_mut()) {
|
||||
for window in &mut workspace.layout.floating {
|
||||
window.native = window.native.map(crate::dock_ui::sanitized_window_rect);
|
||||
}
|
||||
}
|
||||
ui.dock_locked = self.locked;
|
||||
// Reserve restored viewer slots without restoring any project-specific composition
|
||||
// links. New Viewer allocates from this map, including after switching named layouts.
|
||||
for workspace in std::iter::once(&ui.dock).chain(ui.saved_workspaces.values()) {
|
||||
@@ -107,19 +107,23 @@ pub(crate) struct WorkspaceStore {
|
||||
impl WorkspaceStore {
|
||||
pub(crate) fn load(config: Option<&dyn ConfigStore>, ui: &mut UiState) -> Self {
|
||||
let mut original = None;
|
||||
let mut outer = Vec::new();
|
||||
let loaded = config.map_or(Ok(None), |c| c.read_bounded(FILE, MAX_BYTES)).map_err(|e| e.to_string()).and_then(|text| {
|
||||
text.map(|text| {
|
||||
let value: serde_json::Value = serde_json::from_str(&text).map_err(|e| e.to_string())?;
|
||||
let snapshot = if legacy::is_legacy(&value) {
|
||||
let (snapshot, windows) = legacy::migrate(value, ui)?;
|
||||
let snapshot = legacy::migrate(value, ui)?;
|
||||
original = Some(text);
|
||||
outer = windows;
|
||||
snapshot
|
||||
} else if value.get("version").is_none() {
|
||||
return Err("not a workspace file".to_string());
|
||||
} else {
|
||||
serde_json::from_value::<Snapshot>(value).map_err(|e| e.to_string())?
|
||||
// A file written before the lock moved out of the workspace keeps its lock once.
|
||||
let earlier_lock = value.get("locked").is_none().then(|| value.pointer("/dock/locked").and_then(serde_json::Value::as_bool)).flatten();
|
||||
let mut snapshot = serde_json::from_value::<Snapshot>(value).map_err(|e| e.to_string())?;
|
||||
if let Some(locked) = earlier_lock {
|
||||
snapshot.locked = locked;
|
||||
}
|
||||
snapshot
|
||||
};
|
||||
snapshot.validate()?;
|
||||
Ok(snapshot)
|
||||
@@ -129,7 +133,6 @@ impl WorkspaceStore {
|
||||
let error = match loaded {
|
||||
Ok(Some(snapshot)) => {
|
||||
snapshot.apply(ui);
|
||||
ui.native_outer = outer;
|
||||
None
|
||||
}
|
||||
Ok(None) => None,
|
||||
@@ -163,12 +166,12 @@ impl WorkspaceStore {
|
||||
|| self.saved.focused != ui.focused
|
||||
|| self.saved.maximized != ui.maximized
|
||||
|| self.saved.saved_workspaces != ui.saved_workspaces
|
||||
|| self.saved.locked != ui.dock_locked
|
||||
}
|
||||
|
||||
pub(crate) fn save(&mut self, config: Option<&dyn ConfigStore>, ui: &UiState) -> Result<bool, String> {
|
||||
let Some(config) = config else { return Ok(false) };
|
||||
// A window still at its outer position would be saved as if that were its content's.
|
||||
if !self.has_changes(ui) || !ui.native_outer.is_empty() {
|
||||
if !self.has_changes(ui) {
|
||||
return Ok(false);
|
||||
}
|
||||
let snapshot = Snapshot::capture(ui);
|
||||
@@ -197,20 +200,9 @@ impl WorkspaceStore {
|
||||
let path = config.dir().map_or_else(|| FILE.to_string(), |dir| dir.join(FILE).display().to_string());
|
||||
return Err(format!("{path} couldn't be loaded at startup, so it is left untouched; fix or move it and restart"));
|
||||
}
|
||||
ensure_positions_ready(ui)?;
|
||||
self.save(Some(config), ui).map(|_| ())
|
||||
}
|
||||
}
|
||||
|
||||
/// Explicit saves must wait until migrated native-window positions refer to their content.
|
||||
/// Check before capturing a named layout too, so a later background save cannot persist
|
||||
/// a snapshot made with the old outer-window positions.
|
||||
pub(crate) fn ensure_positions_ready(ui: &UiState) -> Result<(), String> {
|
||||
if !ui.native_outer.is_empty() {
|
||||
return Err("workspace window positions are still being restored; try saving again in a moment".into());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
@@ -9,16 +9,16 @@
|
||||
//! group with all its tabs; a frame with a height keeps it as a fixed size (its tab strip
|
||||
//! added), and the others share the rest. A closed frame's tabs join the open frame above it
|
||||
//! (below it, at the top of the column), as a split has no collapsed frames.
|
||||
//! - A floating group in its own native window (`panel_windows`) keeps that place as the
|
||||
//! window's native rect. The earlier version stored the OS window's outer position, so the
|
||||
//! window's id is returned for [`crate::dock_ui::native_outer_to_content`] to move it to its
|
||||
//! content position once the main window reports its frame.
|
||||
//! - A floating group in its own native window (`panel_windows`) floats where it was in the
|
||||
//! main window; the dock places its OS window again.
|
||||
//! - Closed panels had no recorded place: they stay closed and reopen at their default place.
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use craft_ui::docking::{Floating, Node};
|
||||
use craft_ui::layout::{SplitAxis, SplitSize};
|
||||
use craft_behavior::dock::SplitSize;
|
||||
use craft_behavior::dock::{Floating, Node};
|
||||
use craft_behavior::flow::Axis;
|
||||
use egui::{Rect, pos2, vec2};
|
||||
use serde::Deserialize;
|
||||
|
||||
use super::{Snapshot, VERSION};
|
||||
@@ -63,13 +63,6 @@ struct OldFloating {
|
||||
rect: [f32; 4],
|
||||
}
|
||||
|
||||
/// The floating group holding `panel` shows in its own native window at `rect`.
|
||||
#[derive(Deserialize)]
|
||||
struct OldPanelWindow {
|
||||
panel: PanelKind,
|
||||
rect: [f32; 4],
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct OldSnapshot {
|
||||
workspace: String,
|
||||
@@ -79,8 +72,6 @@ struct OldSnapshot {
|
||||
maximized: Option<PanelKind>,
|
||||
saved_workspaces: BTreeMap<String, OldNode>,
|
||||
saved_floating: BTreeMap<String, Vec<OldFloating>>,
|
||||
#[serde(default)]
|
||||
panel_windows: Vec<OldPanelWindow>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
@@ -99,28 +90,25 @@ pub(super) fn is_legacy(value: &serde_json::Value) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
/// The snapshot an earlier version's file describes, and the ids of its floating windows whose
|
||||
/// native rect holds the OS window's outer position. `ui` supplies what an unversioned record
|
||||
/// The snapshot an earlier version's file describes. `ui` supplies what an unversioned record
|
||||
/// leaves out (the current arrangement). The caller validates the result.
|
||||
pub(super) fn migrate(value: serde_json::Value, ui: &UiState) -> Result<(Snapshot, Vec<u64>), String> {
|
||||
pub(super) fn migrate(value: serde_json::Value, ui: &UiState) -> Result<Snapshot, String> {
|
||||
if value.get("version").is_none() {
|
||||
let record: OldRecord = serde_json::from_value(value).map_err(|e| e.to_string())?;
|
||||
let mut snapshot = Snapshot::capture(ui);
|
||||
snapshot.saved_workspaces = named(record.workspaces, record.floating)?;
|
||||
return Ok((snapshot, Vec::new()));
|
||||
return Ok(snapshot);
|
||||
}
|
||||
let old: OldSnapshot = serde_json::from_value(value).map_err(|e| e.to_string())?;
|
||||
let dock = workspace(old.dock, old.floating, &old.panel_windows)?;
|
||||
let outer = dock.layout.floating.iter().filter(|window| window.native.is_some()).map(|window| window.id).collect();
|
||||
let snapshot = Snapshot {
|
||||
Ok(Snapshot {
|
||||
version: VERSION,
|
||||
workspace: old.workspace,
|
||||
dock,
|
||||
dock: workspace(old.dock, old.floating)?,
|
||||
focused: old.focused,
|
||||
maximized: old.maximized,
|
||||
saved_workspaces: named(old.saved_workspaces, old.saved_floating)?,
|
||||
};
|
||||
Ok((snapshot, outer))
|
||||
locked: false,
|
||||
})
|
||||
}
|
||||
|
||||
/// Named workspaces with their floating groups; floating groups of no named workspace are
|
||||
@@ -130,12 +118,12 @@ fn named(roots: BTreeMap<String, OldNode>, mut floating: BTreeMap<String, Vec<Ol
|
||||
.into_iter()
|
||||
.map(|(name, root)| {
|
||||
let groups = floating.remove(&name).unwrap_or_default();
|
||||
workspace(root, groups, &[]).map(|workspace| (name, workspace))
|
||||
workspace(root, groups).map(|workspace| (name, workspace))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn workspace(root: OldNode, floating: Vec<OldFloating>, windows: &[OldPanelWindow]) -> Result<Workspace, String> {
|
||||
fn workspace(root: OldNode, floating: Vec<OldFloating>) -> Result<Workspace, String> {
|
||||
// Closing the last docked panel left an empty tab group as the root.
|
||||
let root = match root {
|
||||
OldNode::Tabs { panels, .. } if panels.is_empty() => None,
|
||||
@@ -143,32 +131,31 @@ fn workspace(root: OldNode, floating: Vec<OldFloating>, windows: &[OldPanelWindo
|
||||
};
|
||||
let floating = floating
|
||||
.into_iter()
|
||||
.map(|group| {
|
||||
let native = windows.iter().find(|window| group.panels.contains(&window.panel)).map(|window| window.rect);
|
||||
let mut window = Floating::single(group.panels, group.active, group.rect);
|
||||
window.native = native.map(crate::dock_ui::sanitized_window_rect);
|
||||
window
|
||||
.zip(1_u64..)
|
||||
.map(|(group, id)| {
|
||||
let [x, y, w, h] = group.rect;
|
||||
Floating::single(id, group.panels, group.active, Rect::from_min_size(pos2(x, y), vec2(w, h)))
|
||||
})
|
||||
.collect();
|
||||
Ok(Workspace::new(Layout { root, floating }))
|
||||
Ok(Workspace::new(Layout::new(root, floating)))
|
||||
}
|
||||
|
||||
fn node(old: OldNode, depth: usize) -> Result<Node<PanelKind>, String> {
|
||||
if depth > craft_ui::docking::MAX_DEPTH {
|
||||
if depth > craft_behavior::dock::MAX_DEPTH {
|
||||
return Err("workspace dock tree exceeds supported limits".into());
|
||||
}
|
||||
Ok(match old {
|
||||
OldNode::Tabs { panels, active } => Node::Tabs { panels, active },
|
||||
OldNode::Split { vertical, size, a, b } => Node::Split {
|
||||
axis: if vertical { SplitAxis::Vertical } else { SplitAxis::Horizontal },
|
||||
size: match size {
|
||||
OldNode::Tabs { panels, active } => Node::tabs(panels, active),
|
||||
OldNode::Split { vertical, size, a, b } => Node::split(
|
||||
if vertical { Axis::Y } else { Axis::X },
|
||||
match size {
|
||||
OldSplitSize::Ratio(value) => SplitSize::Ratio(value),
|
||||
OldSplitSize::FixedA(value) => SplitSize::FixedFirst(value),
|
||||
OldSplitSize::FixedB(value) => SplitSize::FixedSecond(value),
|
||||
},
|
||||
first: Box::new(node(*a, depth.saturating_add(1))?),
|
||||
second: Box::new(node(*b, depth.saturating_add(1))?),
|
||||
},
|
||||
node(*a, depth.saturating_add(1))?,
|
||||
node(*b, depth.saturating_add(1))?,
|
||||
),
|
||||
OldNode::Stack { entries } => column(entries, depth)?,
|
||||
})
|
||||
}
|
||||
@@ -202,7 +189,7 @@ fn column(entries: Vec<OldStackEntry>, depth: usize) -> Result<Node<PanelKind>,
|
||||
}
|
||||
let active = entry.active.min(panels.len().saturating_sub(1));
|
||||
if entry.open {
|
||||
if depth.saturating_add(frames.len()) > craft_ui::docking::MAX_DEPTH {
|
||||
if depth.saturating_add(frames.len()) > craft_behavior::dock::MAX_DEPTH {
|
||||
return Err("workspace dock tree exceeds supported limits".into());
|
||||
}
|
||||
let height = entry.height.filter(|h| h.is_finite() && *h > 0.0).map(|h| h.min(MAX_FRAME));
|
||||
@@ -226,7 +213,7 @@ fn column(entries: Vec<OldStackEntry>, depth: usize) -> Result<Node<PanelKind>,
|
||||
for frame in frames.into_iter().rev() {
|
||||
let own = frame_size(&frame);
|
||||
let gap = if node.is_some() { FRAME_GAP } else { 0.0 };
|
||||
let tabs = Node::Tabs { panels: frame.panels, active: frame.active };
|
||||
let tabs = Node::tabs(frame.panels, frame.active);
|
||||
node = Some(match node {
|
||||
None => tabs,
|
||||
Some(rest) => {
|
||||
@@ -236,7 +223,7 @@ fn column(entries: Vec<OldStackEntry>, depth: usize) -> Result<Node<PanelKind>,
|
||||
// Shares the rest with the flexible frames below.
|
||||
(None, None) => SplitSize::Ratio(1.0 / (below_flexible as f32 + 1.0)),
|
||||
};
|
||||
Node::Split { axis: SplitAxis::Vertical, size, first: Box::new(tabs), second: Box::new(rest) }
|
||||
Node::split(Axis::Y, size, tabs, rest)
|
||||
}
|
||||
});
|
||||
below_fixed = match (own, below_fixed) {
|
||||
|
||||
@@ -8,7 +8,7 @@ fn stack(count: usize) -> OldNode {
|
||||
|
||||
#[test]
|
||||
fn stacked_frames_respect_the_remaining_tree_depth() {
|
||||
let limit = craft_ui::docking::MAX_DEPTH;
|
||||
let limit = craft_behavior::dock::MAX_DEPTH;
|
||||
assert!(node(stack(limit + 1), 0).is_ok());
|
||||
assert!(node(stack(limit + 2), 0).is_err());
|
||||
assert!(node(stack(1), limit).is_ok());
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
use super::*;
|
||||
use crate::dock::{Floating, Layout, Node, StackEntry, WorkspaceExt as _};
|
||||
use craft_ui::docking::Action;
|
||||
use craft_ui::layout::{SplitAxis, SplitSize};
|
||||
use craft_behavior::dock::Action;
|
||||
use craft_behavior::dock::SplitSize;
|
||||
use craft_behavior::flow::Axis;
|
||||
use effectcraft_engine::config::MemoryConfig;
|
||||
|
||||
fn minimal() -> Workspace {
|
||||
@@ -9,7 +10,11 @@ fn minimal() -> Workspace {
|
||||
}
|
||||
|
||||
fn tabs(panels: &[PanelKind]) -> Node<PanelKind> {
|
||||
Node::Tabs { panels: panels.to_vec(), active: 0 }
|
||||
Node::tabs(panels.to_vec(), 0)
|
||||
}
|
||||
|
||||
fn rect(x: f32, y: f32, w: f32, h: f32) -> egui::Rect {
|
||||
egui::Rect::from_min_size(egui::pos2(x, y), egui::vec2(w, h))
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -23,7 +28,7 @@ fn corrupt_future_or_unknown_workspace_keeps_defaults_and_original_file() {
|
||||
)
|
||||
};
|
||||
let mut deep = r#"{"Tabs":{"panels":["Composition"],"active":0}}"#.to_string();
|
||||
for _ in 0..=craft_ui::docking::MAX_DEPTH {
|
||||
for _ in 0..=craft_behavior::dock::MAX_DEPTH {
|
||||
deep = format!(r#"{{"Split":{{"vertical":true,"size":{{"Ratio":0.5}},"a":{deep},"b":{{"Tabs":{{"panels":[],"active":0}}}}}}}}"#);
|
||||
}
|
||||
let twice =
|
||||
@@ -66,20 +71,12 @@ fn corrupt_future_or_unknown_workspace_keeps_defaults_and_original_file() {
|
||||
const V1: &str = include_str!("../../tests/fixtures/workspaces-v1.json");
|
||||
|
||||
#[test]
|
||||
fn explicit_save_reports_pending_migration_and_can_be_retried() {
|
||||
fn explicit_save_rewrites_an_earlier_file_and_keeps_a_backup() {
|
||||
let config = MemoryConfig::default();
|
||||
config.write(FILE, V1).unwrap();
|
||||
let mut ui = UiState::default();
|
||||
let mut store = WorkspaceStore::load(Some(&config), &mut ui);
|
||||
assert!(!ui.native_outer.is_empty());
|
||||
assert!(!store.save(Some(&config), &ui).unwrap(), "background saves defer quietly");
|
||||
let error = store.save_now(Some(&config), &ui).unwrap_err();
|
||||
assert!(error.contains("positions") && error.contains("try saving again"), "{error}");
|
||||
assert_eq!(config.read(FILE).as_deref(), Some(V1));
|
||||
assert_eq!(config.read(BACKUP), None);
|
||||
assert!(store.has_changes(&ui));
|
||||
|
||||
crate::dock_ui::native_outer_to_content(&mut ui, None, None, 3.0);
|
||||
store.save_now(Some(&config), &ui).unwrap();
|
||||
assert_eq!(config.read(BACKUP).as_deref(), Some(V1));
|
||||
let mut restored = UiState::default();
|
||||
@@ -107,34 +104,26 @@ fn version_one_file_loads_with_every_panel_in_place() {
|
||||
),
|
||||
tabs(&[Properties]),
|
||||
);
|
||||
assert_eq!(ui.dock.layout.root, Some(root));
|
||||
let floating: Vec<_> = ui.dock.layout.floating.iter().map(|w| (w.panels().copied().collect::<Vec<_>>(), w.rect, w.native)).collect();
|
||||
assert_eq!(ui.dock.layout().root, Some(root));
|
||||
let floating: Vec<_> = ui.dock.layout().floating.iter().map(|w| (w.panels().copied().collect::<Vec<_>>(), w.rect, w.native.clone())).collect();
|
||||
assert_eq!(
|
||||
floating,
|
||||
[
|
||||
(vec![Preview], [900.0, 120.0, 300.0, 260.0], None),
|
||||
(vec![RenderQueue], [200.0, 500.0, 520.0, 240.0], Some(crate::dock_ui::sanitized_window_rect([200.0, 500.0, 520.0, 240.0]))),
|
||||
(vec![Preview], rect(900.0, 120.0, 300.0, 260.0), None),
|
||||
// Its native window's place goes: the dock places the OS window again.
|
||||
(vec![RenderQueue], rect(200.0, 500.0, 520.0, 240.0), None),
|
||||
]
|
||||
);
|
||||
// Closed panels stay closed.
|
||||
for panel in [Align, Layer] {
|
||||
assert!(!ui.dock.is_open(panel), "{panel:?}");
|
||||
}
|
||||
// The native window's place is its outer position until the main window reports its
|
||||
// frame (here a 28-point title bar); the file is not rewritten before.
|
||||
let id = ui.dock.layout.floating[1].id;
|
||||
assert_eq!(ui.native_outer, [id]);
|
||||
let mut store = store;
|
||||
assert!(!store.save(Some(&config), &ui).unwrap());
|
||||
let outer = egui::Rect::from_min_size(egui::pos2(10.0, 20.0), egui::vec2(1600.0, 1000.0));
|
||||
crate::dock_ui::native_outer_to_content(&mut ui, Some(outer), Some(outer.translate(egui::vec2(0.0, 28.0))), 0.1);
|
||||
assert_eq!(ui.dock.layout.floating[1].native, Some([200.0, 528.0, 520.0, 240.0]));
|
||||
assert!(ui.native_outer.is_empty());
|
||||
assert!(store.save(Some(&config), &ui).unwrap());
|
||||
// The named workspace still has Layer, closed only after it was saved.
|
||||
let saved = ui.saved_workspaces.get("My Layout").unwrap();
|
||||
assert!(saved.is_docked(Layer) && saved.is_floating(Preview) && !saved.is_open(Align));
|
||||
assert_eq!(saved.layout.floating.iter().filter_map(|w| w.native).count(), 0);
|
||||
assert_eq!(saved.layout().floating.iter().filter(|w| w.native.is_some()).count(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -143,13 +132,6 @@ fn version_one_file_is_rewritten_once_in_the_current_format_and_kept_as_a_backup
|
||||
config.write(FILE, V1).unwrap();
|
||||
let mut ui = UiState::default();
|
||||
let mut store = WorkspaceStore::load(Some(&config), &mut ui);
|
||||
// A backend that reports no window positions: the native place stays as it was.
|
||||
let native = ui.dock.layout.floating[1].native;
|
||||
crate::dock_ui::native_outer_to_content(&mut ui, None, None, 1.0);
|
||||
assert!(!ui.native_outer.is_empty(), "waits for a report");
|
||||
crate::dock_ui::native_outer_to_content(&mut ui, None, None, 5.0);
|
||||
assert!(ui.native_outer.is_empty());
|
||||
assert_eq!(ui.dock.layout.floating[1].native, native);
|
||||
let migrated = Snapshot::capture(&ui);
|
||||
assert!(store.has_changes(&ui), "the migrated layout is written without waiting for an edit");
|
||||
assert!(store.save(Some(&config), &ui).unwrap());
|
||||
@@ -177,16 +159,16 @@ fn stacked_frames_with_tabs_and_an_empty_root_migrate() {
|
||||
let mut ui = UiState::default();
|
||||
let store = WorkspaceStore::load(Some(&config), &mut ui);
|
||||
assert_eq!(store.error, None);
|
||||
assert_eq!(ui.dock.layout.root, None);
|
||||
assert_eq!(ui.dock.layout().root, None);
|
||||
assert!(ui.dock.is_floating(PanelKind::Project));
|
||||
use PanelKind::*;
|
||||
// Each open frame is a tab group with all its tabs; a frame's height is a fixed size
|
||||
// (with its tab strip), and the frame without one takes the rest.
|
||||
let column = crate::dock::vsplit(SplitSize::FixedSecond(80.0 + crate::dock::TAB_STRIP), tabs(&[Info]), crate::dock::tabs(&[Audio, Preview], 1));
|
||||
assert_eq!(ui.saved_workspaces.get("Mine").and_then(|w| w.layout.root.clone()), Some(column));
|
||||
assert_eq!(ui.saved_workspaces.get("Mine").and_then(|w| w.layout().root.clone()), Some(column));
|
||||
// Closed frames' tabs join the open frame above them, or below at the top.
|
||||
let column = crate::dock::vsplit(SplitSize::FixedFirst(46.0 + crate::dock::TAB_STRIP), tabs(&[Preview, Properties, Paint, Align]), tabs(&[Info]));
|
||||
assert_eq!(ui.saved_workspaces.get("Column").and_then(|w| w.layout.root.clone()), Some(column));
|
||||
assert_eq!(ui.saved_workspaces.get("Column").and_then(|w| w.layout().root.clone()), Some(column));
|
||||
assert_eq!(ui.saved_workspaces.len(), 2, "floating groups of no named workspace are dropped");
|
||||
}
|
||||
|
||||
@@ -213,25 +195,21 @@ fn explicit_save_with_nothing_new_succeeds() {
|
||||
#[test]
|
||||
fn invalid_tabs_split_and_deep_tree_are_rejected() {
|
||||
let mut snapshot = Snapshot::capture(&UiState::default());
|
||||
snapshot.dock = Workspace::new(Layout { root: Some(Node::Tabs { panels: vec![PanelKind::Project], active: usize::MAX }), floating: vec![] });
|
||||
snapshot.dock = Workspace::new(Layout::new(Some(Node::tabs(vec![PanelKind::Project], usize::MAX)), vec![]));
|
||||
assert!(snapshot.validate().is_err());
|
||||
let split = |size, first, second| Node::Split { axis: SplitAxis::Horizontal, size, first: Box::new(first), second: Box::new(second) };
|
||||
snapshot.dock = Workspace::new(Layout {
|
||||
root: Some(split(SplitSize::FixedFirst(f32::NAN), tabs(&[PanelKind::Project]), tabs(&[PanelKind::Timeline]))),
|
||||
floating: vec![],
|
||||
});
|
||||
let split = |size, first, second| Node::split(Axis::X, size, first, second);
|
||||
snapshot.dock =
|
||||
Workspace::new(Layout::new(Some(split(SplitSize::FixedFirst(f32::NAN), tabs(&[PanelKind::Project]), tabs(&[PanelKind::Timeline]))), vec![]));
|
||||
assert!(snapshot.validate().is_err());
|
||||
let mut root = tabs(&[PanelKind::Composition]);
|
||||
for _ in 0..=craft_ui::docking::MAX_DEPTH {
|
||||
for _ in 0..=craft_behavior::dock::MAX_DEPTH {
|
||||
root = split(SplitSize::Ratio(0.5), root, tabs(&[]));
|
||||
}
|
||||
snapshot.dock = Workspace::new(Layout { root: Some(root), floating: vec![] });
|
||||
snapshot.dock = Workspace::new(Layout::new(Some(root), vec![]));
|
||||
assert!(snapshot.validate().is_err());
|
||||
// A panel in two places.
|
||||
snapshot.dock = Workspace::new(Layout {
|
||||
root: Some(tabs(&[PanelKind::Project])),
|
||||
floating: vec![Floating::single(vec![PanelKind::Project], 0, [0.0, 0.0, 200.0, 100.0])],
|
||||
});
|
||||
snapshot.dock =
|
||||
Workspace::new(Layout::new(Some(tabs(&[PanelKind::Project])), vec![Floating::single(1, vec![PanelKind::Project], 0, rect(0.0, 0.0, 200.0, 100.0))]));
|
||||
assert!(snapshot.validate().is_err());
|
||||
}
|
||||
|
||||
@@ -241,9 +219,9 @@ fn closing_all_docked_panels_remains_a_persistable_layout() {
|
||||
let mut ui = UiState::default();
|
||||
let mut store = WorkspaceStore::load(Some(&config), &mut ui);
|
||||
for panel in ui.dock.panels() {
|
||||
ui.dock.apply(Action::Close { panel }, crate::dock::permissions).unwrap();
|
||||
ui.dock.apply(Action::close(panel), false, crate::dock::permissions).unwrap();
|
||||
}
|
||||
assert!(ui.dock.layout.root.is_none());
|
||||
assert!(ui.dock.layout().root.is_none());
|
||||
assert!(store.save(Some(&config), &ui).unwrap());
|
||||
let mut restored = UiState::default();
|
||||
let loaded = WorkspaceStore::load(Some(&config), &mut restored);
|
||||
@@ -257,8 +235,8 @@ fn floating_groups_and_named_snapshots_roundtrip_without_document_state() {
|
||||
let mut ui = UiState::default();
|
||||
let mut store = WorkspaceStore::load(Some(&config), &mut ui);
|
||||
ui.workspace = "Floating".into();
|
||||
ui.dock.apply(Action::Float { panel: PanelKind::Preview, rect: [50.0, 80.0, 200.0, 160.0] }, crate::dock::permissions).unwrap();
|
||||
ui.dock.apply(Action::Close { panel: PanelKind::Align }, crate::dock::permissions).unwrap();
|
||||
ui.dock.apply(Action::float(PanelKind::Preview, crate::dock_command::rect_of([50.0, 80.0, 200.0, 160.0])), false, crate::dock::permissions).unwrap();
|
||||
ui.dock.apply(Action::close(PanelKind::Align), false, crate::dock::permissions).unwrap();
|
||||
ui.saved_workspaces.insert(ui.workspace.clone(), ui.dock.clone());
|
||||
ui.maximized = Some(PanelKind::Composition);
|
||||
ui.project_search = "do not persist".into();
|
||||
@@ -267,7 +245,7 @@ fn floating_groups_and_named_snapshots_roundtrip_without_document_state() {
|
||||
WorkspaceStore::load(Some(&config), &mut restored);
|
||||
assert_eq!(Snapshot::capture(&restored), Snapshot::capture(&ui));
|
||||
// The closed panel's place comes back with it.
|
||||
assert!(restored.dock.hidden.iter().any(|(p, _)| *p == PanelKind::Align));
|
||||
assert!(restored.dock.hidden().iter().any(|(p, _)| *p == PanelKind::Align));
|
||||
assert!(restored.project_search.is_empty());
|
||||
}
|
||||
|
||||
@@ -276,7 +254,7 @@ fn restored_viewer_slots_do_not_reuse_ids_or_restore_document_links() {
|
||||
let config = MemoryConfig::default();
|
||||
let mut ui = UiState::default();
|
||||
let mut store = WorkspaceStore::load(Some(&config), &mut ui);
|
||||
let two = |viewer| Workspace::new(Layout { root: Some(tabs(&[PanelKind::Composition, PanelKind::Viewer(viewer)])), floating: vec![] });
|
||||
let two = |viewer| Workspace::new(Layout::new(Some(tabs(&[PanelKind::Composition, PanelKind::Viewer(viewer)])), vec![]));
|
||||
ui.dock = two(2);
|
||||
ui.saved_workspaces.insert("Two views".into(), two(5));
|
||||
ui.viewers.insert(2, Some(42));
|
||||
@@ -295,15 +273,12 @@ fn invalid_viewer_ids_are_rejected_in_every_workspace_reference() {
|
||||
for location in 0..8 {
|
||||
let mut snapshot = Snapshot::capture(&UiState::default());
|
||||
let panel = PanelKind::Viewer(id);
|
||||
let docked = Workspace::new(Layout { root: Some(tabs(&[panel])), floating: vec![] });
|
||||
let stacked =
|
||||
Workspace::new(Layout { root: Some(Node::Stack { entries: vec![StackEntry { panel, open: true, height: None }] }), floating: vec![] });
|
||||
let floating = Workspace::new(Layout {
|
||||
root: Some(tabs(&[PanelKind::Composition])),
|
||||
floating: vec![Floating::single(vec![panel], 0, [0.0, 0.0, 200.0, 100.0])],
|
||||
});
|
||||
let mut hidden = Workspace::new(Layout { root: Some(tabs(&[PanelKind::Composition, panel])), floating: vec![] });
|
||||
hidden.apply(Action::Close { panel }, crate::dock::permissions).unwrap();
|
||||
let docked = Workspace::new(Layout::new(Some(tabs(&[panel])), vec![]));
|
||||
let stacked = Workspace::new(Layout::new(Some(Node::stack(vec![StackEntry::new(panel)])), vec![]));
|
||||
let floating =
|
||||
Workspace::new(Layout::new(Some(tabs(&[PanelKind::Composition])), vec![Floating::single(1, vec![panel], 0, rect(0.0, 0.0, 200.0, 100.0))]));
|
||||
let mut hidden = Workspace::new(Layout::new(Some(tabs(&[PanelKind::Composition, panel])), vec![]));
|
||||
hidden.apply(Action::close(panel), false, crate::dock::permissions).unwrap();
|
||||
match location {
|
||||
0 => snapshot.focused = panel,
|
||||
1 => snapshot.maximized = Some(panel),
|
||||
@@ -323,19 +298,32 @@ fn invalid_viewer_ids_are_rejected_in_every_workspace_reference() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Lock Workspace persists with the workspaces; a file without it loads unlocked, and a file
|
||||
/// whose workspace carries the earlier format's own lock keeps it once.
|
||||
#[test]
|
||||
fn hostile_native_window_places_are_made_safe_on_load() {
|
||||
fn the_workspace_lock_survives_a_save_and_an_earlier_files_lock_carries_over() {
|
||||
let config = MemoryConfig::default();
|
||||
let mut ui = UiState::default();
|
||||
let mut store = WorkspaceStore::load(Some(&config), &mut ui);
|
||||
ui.dock.apply(Action::Float { panel: PanelKind::Project, rect: [10.0, 10.0, 300.0, 200.0] }, crate::dock::permissions).unwrap();
|
||||
ui.dock.apply(Action::SetNative { panel: PanelKind::Project, rect: Some([90_000.0, -90_000.0, 1.0e5, 0.5]) }, crate::dock::permissions).unwrap();
|
||||
ui.dock_locked = true;
|
||||
assert!(store.save(Some(&config), &ui).unwrap());
|
||||
let mut restored = UiState::default();
|
||||
WorkspaceStore::load(Some(&config), &mut restored);
|
||||
let native = restored.dock.layout.floating.iter().find(|w| w.contains(&PanelKind::Project)).and_then(|w| w.native).unwrap();
|
||||
assert_eq!(native, crate::dock_ui::sanitized_window_rect(native));
|
||||
assert!(native[2] <= crate::dock_ui::PANEL_WINDOW_MAX && native[3] >= crate::dock_ui::PANEL_WINDOW_MIN[1]);
|
||||
assert!(restored.dock_locked);
|
||||
|
||||
let mut saved: serde_json::Value = serde_json::from_str(&config.read(FILE).unwrap()).unwrap();
|
||||
saved.as_object_mut().unwrap().remove("locked");
|
||||
config.write(FILE, &saved.to_string()).unwrap();
|
||||
let mut unlocked = UiState::default();
|
||||
WorkspaceStore::load(Some(&config), &mut unlocked);
|
||||
assert!(!unlocked.dock_locked, "a file without the lock loads unlocked");
|
||||
|
||||
saved["dock"]["locked"] = serde_json::json!(true);
|
||||
config.write(FILE, &saved.to_string()).unwrap();
|
||||
let mut earlier = UiState::default();
|
||||
let loaded = WorkspaceStore::load(Some(&config), &mut earlier);
|
||||
assert_eq!(loaded.error, None);
|
||||
assert!(earlier.dock_locked, "the earlier workspace's own lock carries over");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -29,7 +29,6 @@ mod ui_crypto_pick;
|
||||
mod ui_crypto_pick_undo;
|
||||
mod ui_crypto_select;
|
||||
mod ui_dialog_preview;
|
||||
mod ui_dock_resize;
|
||||
mod ui_drag_drop;
|
||||
mod ui_effect_controls;
|
||||
mod ui_effect_drop_highlight;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//! The macOS menu bar takes the Edit menu's key equivalents before any window sees them: while a
|
||||
//! text field has the keyboard, in a docked panel or a floating panel's own OS window, they edit
|
||||
//! the field and leave the project alone, and the items stay enabled.
|
||||
//! the field and leave the project alone, and the items stay enabled. The keys a floating panel's
|
||||
//! window hands to the main window.
|
||||
|
||||
use effectcraft_engine::Session;
|
||||
use effectcraft_ui_egui::EffectcraftApp;
|
||||
@@ -136,7 +137,7 @@ fn native_windows(h: &mut Harness<'_, EffectcraftApp>) -> Host {
|
||||
fn edit_menu_keys_edit_a_text_field_in_a_panel_window() {
|
||||
let mut app = app();
|
||||
menus::invoke(&mut app, &egui::Context::default(), "window.panelWindow", json!({"panel": "Project", "window": true})).unwrap();
|
||||
let mut h = Harness::builder().with_size(vec2(1600.0, 1000.0)).build_eframe(|_| app);
|
||||
let mut h = Harness::builder().with_size(vec2(1600.0, 1000.0)).with_context_setup(effectcraft_ui_egui::framework::install_headless).build_eframe(|_| app);
|
||||
h.ctx.set_os(egui::os::OperatingSystem::Mac);
|
||||
let host = native_windows(&mut h);
|
||||
let at = center(&h, "project.search");
|
||||
@@ -163,7 +164,7 @@ fn edit_menu_keys_edit_a_text_field_in_a_panel_window() {
|
||||
|
||||
#[test]
|
||||
fn edit_menu_keys_edit_a_docked_text_field() {
|
||||
let mut h = Harness::builder().with_size(vec2(1600.0, 1000.0)).build_eframe(|_| app());
|
||||
let mut h = Harness::builder().with_size(vec2(1600.0, 1000.0)).with_context_setup(effectcraft_ui_egui::framework::install_headless).build_eframe(|_| app());
|
||||
h.ctx.set_os(egui::os::OperatingSystem::Mac);
|
||||
h.run_steps(3);
|
||||
let at = center(&h, "project.search");
|
||||
@@ -189,3 +190,46 @@ fn edit_menu_keys_edit_a_docked_text_field() {
|
||||
menu(&mut h, "edit.copy");
|
||||
assert_eq!(project(h.state()), before, "the project is untouched");
|
||||
}
|
||||
|
||||
/// Only the keys go from a floating panel's window to the main window, and only while no widget
|
||||
/// there has the keyboard: its pointer, wheel and typed text are its own.
|
||||
#[test]
|
||||
fn a_panel_window_hands_over_only_the_keys_no_widget_has() {
|
||||
use egui::Key;
|
||||
let mut app = app();
|
||||
menus::invoke(&mut app, &egui::Context::default(), "window.panelWindow", json!({"panel": "Project", "window": true})).unwrap();
|
||||
let mut h = Harness::builder().with_size(vec2(1600.0, 1000.0)).with_context_setup(effectcraft_ui_egui::framework::install_headless).build_eframe(|_| app);
|
||||
let host = native_windows(&mut h);
|
||||
let handed = |h: &mut Harness<'_, EffectcraftApp>, events: &[Event]| {
|
||||
let hook = |h: &mut Harness<'_, EffectcraftApp>| {
|
||||
let ctx = h.ctx.clone();
|
||||
let mut raw = egui::RawInput::default();
|
||||
eframe::App::raw_input_hook(h.state_mut(), &ctx, &mut raw);
|
||||
raw.events
|
||||
};
|
||||
hook(h);
|
||||
for event in events {
|
||||
to_window(&host, event.clone());
|
||||
}
|
||||
h.step();
|
||||
hook(h)
|
||||
};
|
||||
let key = |key| Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::NONE };
|
||||
let at = center(&h, "project.search");
|
||||
let wheel = Event::MouseWheel {
|
||||
unit: egui::MouseWheelUnit::Point,
|
||||
delta: vec2(0.0, 10.0),
|
||||
modifiers: Modifiers::NONE,
|
||||
phase: egui::TouchPhase::Move,
|
||||
source: egui::MouseWheelSource::Wheel,
|
||||
};
|
||||
let typed = [Event::PointerMoved(at), wheel, key(Key::J), Event::Text("j".into())];
|
||||
assert_eq!(handed(&mut h, &typed), vec![key(Key::J)], "the key alone");
|
||||
click(&mut h, at, Some(&host));
|
||||
h.run_steps(2);
|
||||
assert_eq!(handed(&mut h, &typed), Vec::new(), "the search field has the keyboard");
|
||||
to_window(&host, key(Key::Tab));
|
||||
h.run_steps(3);
|
||||
assert_ne!(native_menu::text_field_window(&h.ctx), host.borrow().window, "Tab moved on from the field");
|
||||
assert_eq!(handed(&mut h, &typed), Vec::new(), "another widget has the keyboard");
|
||||
}
|
||||
@@ -31,7 +31,10 @@ fn render_queue_panel_snapshot() {
|
||||
}
|
||||
let ids: Vec<u64> = s.project.render_queue.iter().take(3).map(|i| i.id).collect();
|
||||
let mut app = Some(EffectcraftApp::new(s));
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).build_eframe(|_| app.take().expect("app"));
|
||||
let mut h = Harness::builder()
|
||||
.with_size(egui::vec2(1600.0, 1000.0))
|
||||
.with_context_setup(effectcraft_ui_egui::framework::install_headless)
|
||||
.build_eframe(|_| app.take().expect("app"));
|
||||
h.ctx.data_mut(|d| d.insert_temp(egui::Id::unique("rq-ui"), (ids, None::<u64>)));
|
||||
h.state_mut().show_panel(effectcraft_ui_egui::dock::PanelKind::RenderQueue);
|
||||
h.run_steps(4);
|
||||
@@ -55,7 +58,10 @@ fn templates_dialog_snapshot() {
|
||||
let kind = std::env::var("RQ_TEMPLATES_KIND").unwrap_or_else(|_| "outputModule".into());
|
||||
s.execute("app.templates", json!({"kind": kind})).unwrap();
|
||||
let mut app = Some(EffectcraftApp::new(s));
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(|_| app.take().expect("app"));
|
||||
let mut h = Harness::builder()
|
||||
.with_size(egui::vec2(1400.0, 900.0))
|
||||
.with_context_setup(effectcraft_ui_egui::framework::install_headless)
|
||||
.build_eframe(|_| app.take().expect("app"));
|
||||
h.run_steps(4);
|
||||
assert!(h.state().dialog.is_some(), "the Templates dialog is open");
|
||||
let img = h.render_serialized().expect("render");
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! EffectCraft's workspaces in craft-ui's shared docking: transactions, the command path, pointer
|
||||
//! gestures and persistence.
|
||||
use craft_ui::docking::{Action, Node, Placement, StackEntry, Zone};
|
||||
use craft_behavior::dock::{Action, DockPlacement, Node};
|
||||
use effectcraft_engine::Session;
|
||||
use effectcraft_ui_egui::{
|
||||
EffectcraftApp,
|
||||
@@ -8,7 +8,6 @@ use effectcraft_ui_egui::{
|
||||
};
|
||||
use egui::{Event, Modifiers, PointerButton, Rect, pos2, vec2};
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::{NodeT, Queryable};
|
||||
use serde_json::json;
|
||||
|
||||
fn invoke(app: &mut EffectcraftApp, id: &str, params: serde_json::Value) -> Result<serde_json::Value, String> {
|
||||
@@ -16,7 +15,12 @@ fn invoke(app: &mut EffectcraftApp, id: &str, params: serde_json::Value) -> Resu
|
||||
}
|
||||
|
||||
fn floating(app: &EffectcraftApp) -> &[dock::Floating<PanelKind>] {
|
||||
&app.ui.dock.layout.floating
|
||||
&app.ui.dock.layout().floating
|
||||
}
|
||||
|
||||
/// A rect as `[x, y, width, height]`.
|
||||
fn rect4(r: Rect) -> [f32; 4] {
|
||||
[r.min.x, r.min.y, r.width(), r.height()]
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -26,28 +30,28 @@ fn shared_move_preserves_accordion_metadata_and_unrelated_active_tabs() {
|
||||
dock::tabs(&[PanelKind::Project, PanelKind::Composition, PanelKind::Layer], 1),
|
||||
dock::stack(&[(PanelKind::Preview, false, Some(73.0)), (PanelKind::Properties, true, Some(211.0)), (PanelKind::Align, false, None)]),
|
||||
));
|
||||
workspace.apply(Action::Close { panel: PanelKind::Project }, dock::permissions).unwrap();
|
||||
workspace.apply(Action::close(PanelKind::Project), false, dock::permissions).unwrap();
|
||||
assert!(workspace.is_visible(PanelKind::Composition));
|
||||
workspace
|
||||
.apply(Action::Move { panel: PanelKind::Preview, anchor: PanelKind::Layer, placement: Placement::Tab { before: None } }, dock::permissions)
|
||||
.unwrap();
|
||||
let Some(Node::Split { second, size, .. }) = &workspace.layout.root else { panic!("split was lost") };
|
||||
workspace.apply(Action::move_beside(PanelKind::Preview, PanelKind::Layer, DockPlacement::tab(None)), false, dock::permissions).unwrap();
|
||||
let Some(Node::Split { second, size, .. }) = &workspace.layout().root else { panic!("split was lost") };
|
||||
assert_eq!(*size, SplitSize::FixedSecond(300.0));
|
||||
let Node::Stack { entries } = second.as_ref() else { panic!("stack was lost") };
|
||||
let Node::Stack { entries, .. } = second.as_ref() else { panic!("stack was lost") };
|
||||
// The unrelated stacked panels keep their exact state.
|
||||
assert_eq!(
|
||||
entries,
|
||||
&vec![StackEntry { panel: PanelKind::Properties, open: true, height: Some(211.0) }, StackEntry { panel: PanelKind::Align, open: false, height: None }]
|
||||
);
|
||||
let entries: Vec<_> = entries.iter().map(|entry| (entry.panel, entry.open, entry.height)).collect();
|
||||
assert_eq!(entries, [(PanelKind::Properties, true, Some(211.0)), (PanelKind::Align, false, None)]);
|
||||
assert_eq!(workspace.group_of(PanelKind::Preview), vec![PanelKind::Composition, PanelKind::Layer, PanelKind::Preview]);
|
||||
// Rejected moves and geometry change nothing.
|
||||
let before = workspace.clone();
|
||||
assert!(
|
||||
workspace
|
||||
.apply(Action::Move { panel: PanelKind::Preview, anchor: PanelKind::Audio, placement: Placement::Split(Zone::Left) }, dock::permissions)
|
||||
.apply(Action::move_beside(PanelKind::Preview, PanelKind::Audio, DockPlacement::Split(craft_behavior::DockSide::Start)), false, dock::permissions)
|
||||
.is_err()
|
||||
);
|
||||
assert!(
|
||||
workspace
|
||||
.apply(Action::float(PanelKind::Preview, effectcraft_ui_egui::dock_command::rect_of([0.0, 0.0, f32::INFINITY, 200.0])), false, dock::permissions)
|
||||
.is_err()
|
||||
);
|
||||
assert!(workspace.apply(Action::Float { panel: PanelKind::Preview, rect: [0.0, 0.0, f32::INFINITY, 200.0] }, dock::permissions).is_err());
|
||||
assert_eq!(workspace, before);
|
||||
}
|
||||
|
||||
@@ -65,14 +69,14 @@ fn every_builtin_workspace_validates_and_roundtrips_with_dynamic_identities() {
|
||||
let ids = |layout: &Layout| layout.floating.iter().map(|w| w.id).collect::<Vec<_>>();
|
||||
assert_eq!(ids(&dock::workspace("Undocked Panels")), ids(&dock::workspace("Undocked Panels")));
|
||||
let mut workspace = dock::docked(dock::tabs(&[PanelKind::Composition, PanelKind::Viewer(42), PanelKind::ScriptPanel(77)], 1));
|
||||
workspace.apply(Action::Float { panel: PanelKind::ScriptPanel(77), rect: [20.0, 30.0, 400.0, 300.0] }, dock::permissions).unwrap();
|
||||
workspace
|
||||
.apply(Action::float(PanelKind::ScriptPanel(77), effectcraft_ui_egui::dock_command::rect_of([20.0, 30.0, 400.0, 300.0])), false, dock::permissions)
|
||||
.unwrap();
|
||||
let text = serde_json::to_string(&workspace).unwrap();
|
||||
assert!(text.contains("\"ScriptPanel\":77") && text.contains("\"Viewer\":42"), "{text}");
|
||||
assert_eq!(serde_json::from_str::<Workspace>(&text).unwrap(), workspace);
|
||||
workspace
|
||||
.apply(Action::Move { panel: PanelKind::ScriptPanel(77), anchor: PanelKind::Viewer(42), placement: Placement::Tab { before: None } }, dock::permissions)
|
||||
.unwrap();
|
||||
assert!(workspace.layout.floating.is_empty());
|
||||
workspace.apply(Action::move_beside(PanelKind::ScriptPanel(77), PanelKind::Viewer(42), DockPlacement::tab(None)), false, dock::permissions).unwrap();
|
||||
assert!(workspace.layout().floating.is_empty());
|
||||
assert!(workspace.is_visible(PanelKind::ScriptPanel(77)));
|
||||
}
|
||||
|
||||
@@ -113,7 +117,8 @@ fn pointer_drop_merges_floats_and_redocks_without_project_changes() {
|
||||
),
|
||||
dock::tabs(&[PanelKind::Timeline], 0),
|
||||
));
|
||||
let mut h = Harness::builder().with_size(vec2(1200.0, 760.0)).build_eframe(move |_| app);
|
||||
let mut h =
|
||||
Harness::builder().with_size(vec2(1200.0, 760.0)).with_context_setup(effectcraft_ui_egui::framework::install_headless).build_eframe(move |_| app);
|
||||
h.run_steps(4);
|
||||
let project = h.state().session.project.clone();
|
||||
let times = h.state().session.state.times.clone();
|
||||
@@ -128,17 +133,15 @@ fn pointer_drop_merges_floats_and_redocks_without_project_changes() {
|
||||
drag(&mut h, from, pos2(700.0, 400.0), Modifiers::COMMAND);
|
||||
assert_eq!(floating(h.state()).len(), 1);
|
||||
assert!(h.state().ui.dock.is_floating(PanelKind::Info));
|
||||
let grips: Vec<_> = h.query_all_by_label("Resize panel window").collect();
|
||||
assert!(!grips.is_empty() && grips.iter().all(|grip| grip.accesskit_node().role() == egui::accesskit::Role::Button));
|
||||
// Its corner resizes it and its title bar moves it.
|
||||
let original = floating(h.state())[0].rect;
|
||||
let original = rect4(floating(h.state())[0].rect);
|
||||
let grip = rect(&h, "panel.float.0.resize").center();
|
||||
drag(&mut h, grip, grip - vec2(36.0, 24.0), Modifiers::NONE);
|
||||
let resized = floating(h.state())[0].rect;
|
||||
let resized = rect4(floating(h.state())[0].rect);
|
||||
assert!(resized[2] < original[2] - 25.0 && resized[3] < original[3] - 15.0, "{original:?} -> {resized:?}");
|
||||
let bar = rect(&h, "panel.float.0.move");
|
||||
drag(&mut h, bar.center(), bar.center() - vec2(24.0, 18.0), Modifiers::NONE);
|
||||
let moved = floating(h.state())[0].rect;
|
||||
let moved = rect4(floating(h.state())[0].rect);
|
||||
assert!(moved[0] < resized[0] - 15.0 && moved[1] < resized[1] - 10.0, "{resized:?} -> {moved:?}");
|
||||
// Its tab dropped on a docked tab strip docks it again.
|
||||
let from = rect(&h, "panel.tab.Info").center();
|
||||
@@ -156,10 +159,10 @@ fn current_and_named_floating_layouts_survive_restart() {
|
||||
use std::sync::Arc;
|
||||
let store = Arc::new(MemoryConfig::default());
|
||||
let mut app = EffectcraftApp::new(Session { config: Some(store.clone()), ..Default::default() });
|
||||
app.apply_dock(Action::Float { panel: PanelKind::Project, rect: [45.0, 65.0, 430.0, 310.0] }).unwrap();
|
||||
app.apply_dock(Action::float(PanelKind::Project, effectcraft_ui_egui::dock_command::rect_of([45.0, 65.0, 430.0, 310.0]))).unwrap();
|
||||
invoke(&mut app, "window.saveWorkspaceAs", json!({"name": "Shared float"})).unwrap();
|
||||
let saved = app.ui.dock.clone();
|
||||
app.apply_dock(Action::MoveFloating { panel: PanelKind::Project, rect: [75.0, 95.0, 480.0, 360.0] }).unwrap();
|
||||
app.apply_dock(Action::move_floating(PanelKind::Project, effectcraft_ui_egui::dock_command::rect_of([75.0, 95.0, 480.0, 360.0]))).unwrap();
|
||||
let current = app.ui.dock.clone();
|
||||
eframe::App::on_exit(&mut app);
|
||||
let mut restarted = EffectcraftApp::new(Session { config: Some(store), ..Default::default() });
|
||||
@@ -180,19 +183,19 @@ fn float_command_rejects_malformed_rectangles_and_keeps_one_docked_panel() {
|
||||
// The last docked panel stays docked, whether it moves alone, with its group or by command.
|
||||
app.ui.dock = dock::docked(dock::tabs(&[PanelKind::Project], 0));
|
||||
let before = app.ui.dock.clone();
|
||||
assert!(app.apply_dock(Action::Float { panel: PanelKind::Project, rect: [1.0, 2.0, 300.0, 200.0] }).is_err());
|
||||
assert!(app.apply_dock(Action::float(PanelKind::Project, effectcraft_ui_egui::dock_command::rect_of([1.0, 2.0, 300.0, 200.0]))).is_err());
|
||||
assert!(invoke(&mut app, "window.panel.float", json!({"panel": "Project", "group": true})).is_err());
|
||||
assert_eq!(app.ui.dock, before);
|
||||
// Closing it is allowed.
|
||||
invoke(&mut app, "window.closePanel", json!({"panel": "Project"})).unwrap();
|
||||
assert!(app.ui.dock.layout.root.is_none());
|
||||
assert!(app.ui.dock.layout().root.is_none());
|
||||
}
|
||||
|
||||
/// A floating panel dragged towards the window's bottom edge moves there, and its title bar
|
||||
/// still moves it from there.
|
||||
#[test]
|
||||
fn floating_panel_dragged_towards_the_window_edge_keeps_moving() {
|
||||
let mut h = Harness::builder().with_size(vec2(1600.0, 1000.0)).build_eframe(|_| {
|
||||
let mut h = Harness::builder().with_size(vec2(1600.0, 1000.0)).with_context_setup(effectcraft_ui_egui::framework::install_headless).build_eframe(|_| {
|
||||
let mut app = EffectcraftApp::new(Session::default());
|
||||
app.ui.start_screen = false;
|
||||
app
|
||||
@@ -203,11 +206,11 @@ fn floating_panel_dragged_towards_the_window_edge_keeps_moving() {
|
||||
h.run_steps(3);
|
||||
let bar = rect(&h, "panel.float.0.move");
|
||||
drag(&mut h, bar.center(), bar.center() + vec2(40.0, 420.0), Modifiers::NONE);
|
||||
let moved = floating(h.state())[0].rect;
|
||||
let moved = rect4(floating(h.state())[0].rect);
|
||||
assert!(moved[1] > 550.0, "the panel moved down: {moved:?}");
|
||||
let bar = rect(&h, "panel.float.0.move");
|
||||
drag(&mut h, bar.center(), bar.center() - vec2(30.0, 200.0), Modifiers::NONE);
|
||||
let back = floating(h.state())[0].rect;
|
||||
let back = rect4(floating(h.state())[0].rect);
|
||||
assert!(back[1] < moved[1] - 150.0, "{moved:?} -> {back:?}");
|
||||
}
|
||||
|
||||
@@ -220,15 +223,15 @@ fn catalog_docking_action_supports_resize_reorder_and_floating_geometry() {
|
||||
dock::tabs(&[PanelKind::Composition], 0),
|
||||
));
|
||||
for action in [
|
||||
Action::ResizeSplit { path: vec![], size: SplitSize::FixedFirst(360.0) },
|
||||
Action::Move { panel: PanelKind::Info, anchor: PanelKind::Project, placement: Placement::Tab { before: Some(PanelKind::Project) } },
|
||||
Action::Float { panel: PanelKind::Info, rect: [20.0, 40.0, 300.0, 200.0] },
|
||||
Action::MoveFloating { panel: PanelKind::Info, rect: [45.0, 65.0, 330.0, 240.0] },
|
||||
Action::resize_split(vec![], SplitSize::FixedFirst(360.0)),
|
||||
Action::move_beside(PanelKind::Info, PanelKind::Project, DockPlacement::tab(Some(PanelKind::Project))),
|
||||
Action::float(PanelKind::Info, effectcraft_ui_egui::dock_command::rect_of([20.0, 40.0, 300.0, 200.0])),
|
||||
Action::move_floating(PanelKind::Info, effectcraft_ui_egui::dock_command::rect_of([45.0, 65.0, 330.0, 240.0])),
|
||||
] {
|
||||
invoke(&mut app, "window.dockAction", json!({"action": action})).unwrap();
|
||||
}
|
||||
assert_eq!(floating(&app)[0].rect, [45.0, 65.0, 330.0, 240.0]);
|
||||
let Some(Node::Split { size, .. }) = &app.ui.dock.layout.root else { panic!("split lost") };
|
||||
assert_eq!(rect4(floating(&app)[0].rect), [45.0, 65.0, 330.0, 240.0]);
|
||||
let Some(Node::Split { size, .. }) = &app.ui.dock.layout().root else { panic!("split lost") };
|
||||
assert_eq!(*size, SplitSize::FixedFirst(360.0));
|
||||
let before = app.ui.dock.clone();
|
||||
assert!(invoke(&mut app, "window.dockAction", json!({"action": {"ResizeSplit": {"path": [true, true], "size": {"Ratio": 0.5}}}})).is_err());
|
||||
@@ -251,7 +254,7 @@ fn ui_dock_and_window_panel_commands_parse_craft_ui_commands() {
|
||||
invoke(&mut app, "ui.dock", json!({"action": {"Activate": {"panel": "Layer"}}})).unwrap();
|
||||
assert!(app.ui.dock.is_visible(PanelKind::Layer));
|
||||
invoke(&mut app, "ui.dock", json!({"operation": "float", "panel": "Info", "rect": [100, 100, 300, 200]})).unwrap();
|
||||
assert_eq!(floating(&app)[0].rect, [100.0, 100.0, 300.0, 200.0]);
|
||||
assert_eq!(rect4(floating(&app)[0].rect), [100.0, 100.0, 300.0, 200.0]);
|
||||
// `window.panel.*` takes EffectCraft's panel names too.
|
||||
invoke(&mut app, "window.panel.dock", json!({"panel": "Info", "anchor": "Project", "zone": "right"})).unwrap();
|
||||
assert!(floating(&app).is_empty() && app.ui.dock.is_docked(PanelKind::Info));
|
||||
@@ -283,10 +286,7 @@ fn raw_open_actions_are_rejected_through_every_docking_route() {
|
||||
let mut app = EffectcraftApp::new(Session::default());
|
||||
let before = app.ui.dock.clone();
|
||||
for panel in [PanelKind::ScriptPanel(77), PanelKind::Viewer(42)] {
|
||||
for action in [
|
||||
Action::Open { panel, anchor: Some(PanelKind::Project) },
|
||||
Action::OpenAt { panel, anchor: PanelKind::Project, placement: Placement::Tab { before: None } },
|
||||
] {
|
||||
for action in [Action::open(panel, Some(PanelKind::Project)), Action::open_at(panel, PanelKind::Project, DockPlacement::tab(None))] {
|
||||
for id in ["ui.dock", "window.panel.layout", "window.dockAction"] {
|
||||
let error = invoke(&mut app, id, json!({"action": action})).unwrap_err();
|
||||
assert!(error.contains("panel open commands"), "{id}: {error}");
|
||||
@@ -310,44 +310,21 @@ fn catalog_close_keeps_dynamic_panel_identity_and_releases_viewers() {
|
||||
app.ui.viewers.insert(42, Some(7));
|
||||
app.ui.maximized = Some(PanelKind::Viewer(42));
|
||||
for panel in [PanelKind::Viewer(42), PanelKind::ScriptPanel(77)] {
|
||||
invoke(&mut app, "window.dockAction", json!({"action": Action::Close { panel }})).unwrap();
|
||||
invoke(&mut app, "window.dockAction", json!({"action": Action::close(panel)})).unwrap();
|
||||
assert!(!app.ui.dock.is_open(panel));
|
||||
assert!(app.ui.dock.hidden.iter().any(|(p, _)| *p == panel), "{panel:?} keeps its place");
|
||||
assert!(app.ui.dock.hidden().iter().any(|(p, _)| *p == panel), "{panel:?} keeps its place");
|
||||
}
|
||||
assert!(app.ui.dock.is_docked(PanelKind::Composition));
|
||||
assert_eq!(app.ui.maximized, None);
|
||||
assert!(!app.ui.viewers.get(&42).is_some_and(Option::is_some), "the closed viewer forgets its comp");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stacked_panels_resize_by_pointer_without_changing_closed_entries() {
|
||||
let mut session = Session::default();
|
||||
session.execute("comp.new", json!({"width": 160, "height": 90, "duration": 1})).unwrap();
|
||||
let mut app = EffectcraftApp::new(session);
|
||||
app.ui.start_screen = false;
|
||||
let mut h = Harness::builder().with_size(vec2(1000.0, 720.0)).build_eframe(move |_| app);
|
||||
h.run_steps(4);
|
||||
h.state_mut().ui.dock =
|
||||
dock::docked(dock::stack(&[(PanelKind::Preview, true, Some(100.0)), (PanelKind::Properties, true, None), (PanelKind::Align, false, Some(77.0))]));
|
||||
h.run_steps(3);
|
||||
let project = h.state().session.project.clone();
|
||||
let before = rect(&h, "panel.Preview").height();
|
||||
let from = rect(&h, "dock.gutter.s0").center();
|
||||
drag(&mut h, from, from + vec2(0.0, 16.0), Modifiers::NONE);
|
||||
let after = rect(&h, "panel.Preview").height();
|
||||
assert!((after - before - 16.0).abs() < 2.0, "{before} -> {after}");
|
||||
let Some(Node::Stack { entries }) = &h.state().ui.dock.layout.root else { panic!("stack lost") };
|
||||
assert!(entries[0].height.unwrap_or_default() > 100.0, "{entries:?}");
|
||||
assert_eq!(entries[2], StackEntry { panel: PanelKind::Align, open: false, height: Some(77.0) });
|
||||
assert!(std::sync::Arc::ptr_eq(&project, &h.state().session.project));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn failed_close_preserves_viewer_lifecycle_and_maximize_state() {
|
||||
let mut app = EffectcraftApp::new(Session::default());
|
||||
// A locked workspace refuses the close.
|
||||
app.ui.dock = dock::docked(dock::tabs(&[PanelKind::Composition, PanelKind::Viewer(42)], 1));
|
||||
app.ui.dock.locked = true;
|
||||
app.ui.dock_locked = true;
|
||||
app.ui.maximized = Some(PanelKind::Viewer(42));
|
||||
app.ui.viewers.insert(42, Some(3));
|
||||
app.ui.active_viewer = 42;
|
||||
|
||||
@@ -33,7 +33,8 @@ fn settle(h: &mut Harness<'_, EffectcraftApp>) {
|
||||
|
||||
#[test]
|
||||
fn viewer_registers_3d_controls() {
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).build_eframe(|_| app());
|
||||
let mut h =
|
||||
Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).with_context_setup(effectcraft_ui_egui::framework::install_headless).build_eframe(|_| app());
|
||||
settle(&mut h);
|
||||
h.step();
|
||||
let ids: Vec<String> = h.state().auto.previous.iter().chain(h.state().auto.elements.iter()).map(|e| e.id.clone()).collect();
|
||||
@@ -64,7 +65,8 @@ fn click_id(h: &mut Harness<'_, EffectcraftApp>, id: &str) {
|
||||
/// and switches it, as After Effects' Composition panel does.
|
||||
#[test]
|
||||
fn renderer_menu_shows_and_switches_the_comp_renderer() {
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).build_eframe(|_| app());
|
||||
let mut h =
|
||||
Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).with_context_setup(effectcraft_ui_egui::framework::install_headless).build_eframe(|_| app());
|
||||
h.state_mut().session.execute("comp.settings", json!({"renderer": "classic3D"})).unwrap();
|
||||
h.run_steps(3);
|
||||
let label = |h: &Harness<'_, EffectcraftApp>| h.state().auto.find("viewer.renderer3d").map(|e| e.label.clone());
|
||||
@@ -82,7 +84,8 @@ fn renderer_menu_shows_and_switches_the_comp_renderer() {
|
||||
|
||||
#[test]
|
||||
fn camera_and_light_dialogs_create_layers() {
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).build_eframe(|_| app());
|
||||
let mut h =
|
||||
Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).with_context_setup(effectcraft_ui_egui::framework::install_headless).build_eframe(|_| app());
|
||||
h.step();
|
||||
let ctx = h.ctx.clone();
|
||||
let n0 = h.state().session.active_comp().unwrap().layers.len();
|
||||
@@ -112,7 +115,12 @@ fn camera_and_light_dialogs_create_layers() {
|
||||
fn snapshot() {
|
||||
let _device = crate::gpu_test::lock();
|
||||
let dir = std::env::var("EC_SNAPSHOT_DIR").ok();
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).with_pixels_per_point(1.0).wgpu().build_eframe(|_| app());
|
||||
let mut h = Harness::builder()
|
||||
.with_size(egui::vec2(1600.0, 1000.0))
|
||||
.with_pixels_per_point(1.0)
|
||||
.wgpu()
|
||||
.with_context_setup(effectcraft_ui_egui::framework::install_headless)
|
||||
.build_eframe(|_| app());
|
||||
let shots: [(&str, Option<&str>); 4] =
|
||||
[("active", None), ("custom1", Some("view.3d.custom1")), ("top", Some("view.3d.top")), ("left", Some("view.3d.left"))];
|
||||
for (name, cmd) in shots {
|
||||
@@ -155,7 +163,8 @@ fn snapshot() {
|
||||
/// frame, and 3D layers reaching past the frame draw pixels there.
|
||||
#[test]
|
||||
fn extended_viewer_renders_past_the_comp_frame() {
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).build_eframe(|_| app());
|
||||
let mut h =
|
||||
Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).with_context_setup(effectcraft_ui_egui::framework::install_headless).build_eframe(|_| app());
|
||||
h.state_mut().session.execute("view.3d.custom1", json!({})).unwrap();
|
||||
// Zoom out so the viewer shows plenty of pasteboard.
|
||||
h.state_mut().ui.viewer.zoom = Some(0.15);
|
||||
@@ -209,7 +218,10 @@ fn layout_views_draw_the_camera_and_follow_its_position() {
|
||||
s.execute("layer.setSwitch", json!({"layer": solid, "switch": "threeD", "value": true})).unwrap();
|
||||
let cam = s.execute("layer.newCamera", json!({"position": [320, 180, -300], "poi": [320, 180, 0]})).unwrap()["layer"].as_u64().unwrap();
|
||||
s.execute("view.layout", json!({"views": 4})).unwrap();
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).build_eframe(|_| EffectcraftApp::new(s));
|
||||
let mut h = Harness::builder()
|
||||
.with_size(egui::vec2(1600.0, 1000.0))
|
||||
.with_context_setup(effectcraft_ui_egui::framework::install_headless)
|
||||
.build_eframe(|_| EffectcraftApp::new(s));
|
||||
settle(&mut h);
|
||||
let centre = |h: &Harness<'_, EffectcraftApp>, view: &str| {
|
||||
let id = format!("viewer.view.{view}.camera.{cam}");
|
||||
@@ -235,7 +247,10 @@ fn four_views() -> Harness<'static, EffectcraftApp> {
|
||||
s.execute("layer.setSwitch", json!({"layer": solid, "switch": "threeD", "value": true})).unwrap();
|
||||
s.execute("layer.newCamera", json!({"position": [320, 180, -300], "poi": [320, 180, 0]})).unwrap();
|
||||
s.execute("view.layout", json!({"views": 4})).unwrap();
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).build_eframe(|_| EffectcraftApp::new(s));
|
||||
let mut h = Harness::builder()
|
||||
.with_size(egui::vec2(1600.0, 1000.0))
|
||||
.with_context_setup(effectcraft_ui_egui::framework::install_headless)
|
||||
.build_eframe(|_| EffectcraftApp::new(s));
|
||||
settle(&mut h);
|
||||
h
|
||||
}
|
||||
@@ -288,7 +303,10 @@ fn gizmo_harness(w: u32, h: u32) -> (Harness<'static, EffectcraftApp>, u64) {
|
||||
let solid = s.execute("layer.newSolid", json!({"color": "#ff0000", "width": w, "height": h})).unwrap()["layer"].as_u64().unwrap();
|
||||
s.execute("layer.setSwitch", json!({"layer": solid, "switch": "threeD", "value": true})).unwrap();
|
||||
s.execute("layer.select", json!({"layers": [solid]})).unwrap();
|
||||
let mut harness = Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).build_eframe(|_| EffectcraftApp::new(s));
|
||||
let mut harness = Harness::builder()
|
||||
.with_size(egui::vec2(1600.0, 1000.0))
|
||||
.with_context_setup(effectcraft_ui_egui::framework::install_headless)
|
||||
.build_eframe(|_| EffectcraftApp::new(s));
|
||||
settle(&mut harness);
|
||||
(harness, solid)
|
||||
}
|
||||
|
||||
@@ -22,7 +22,10 @@ fn harness() -> Harness<'static, EffectcraftApp> {
|
||||
s.execute("file.openDemoProject", json!({})).unwrap();
|
||||
// A text layer under edit gives the Character / Paragraph panels their controls.
|
||||
let _ = s.execute("layer.select", json!({"layers": ["EFFECTCRAFT"]}));
|
||||
Harness::builder().with_size(egui::vec2(1680.0, 1020.0)).build_eframe(|_| EffectcraftApp::new(s))
|
||||
Harness::builder()
|
||||
.with_size(egui::vec2(1680.0, 1020.0))
|
||||
.with_context_setup(effectcraft_ui_egui::framework::install_headless)
|
||||
.build_eframe(|_| EffectcraftApp::new(s))
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -142,7 +142,10 @@ fn app_session() -> Session {
|
||||
}
|
||||
|
||||
fn harness() -> Harness<'static, EffectcraftApp> {
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).build_eframe(|_| EffectcraftApp::new(app_session()));
|
||||
let mut h = Harness::builder()
|
||||
.with_size(egui::vec2(1600.0, 1000.0))
|
||||
.with_context_setup(effectcraft_ui_egui::framework::install_headless)
|
||||
.build_eframe(|_| EffectcraftApp::new(app_session()));
|
||||
// The default workspace gives Preview a short frame at the top of the right column; its
|
||||
// controls below that frame stay in the tree and would be counted against the panel under it.
|
||||
// The per-panel pass opens Preview again for its own scenario.
|
||||
|
||||
@@ -21,7 +21,10 @@ fn session() -> Session {
|
||||
}
|
||||
|
||||
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));
|
||||
let mut h = Harness::builder()
|
||||
.with_size(egui::vec2(1680.0, 1020.0))
|
||||
.with_context_setup(effectcraft_ui_egui::framework::install_headless)
|
||||
.build_eframe(|_| EffectcraftApp::new(s));
|
||||
h.run_steps(3);
|
||||
h
|
||||
}
|
||||
|
||||
@@ -18,7 +18,10 @@ fn harness() -> (Harness<'static, EffectcraftApp>, u64, u64) {
|
||||
s.execute("prop.set", json!({"layer": a, "path": "transform/position", "value": [150.0, 180.0]})).unwrap();
|
||||
s.execute("prop.set", json!({"layer": b, "path": "transform/position", "value": [450.0, 180.0]})).unwrap();
|
||||
s.execute("layer.select", json!({"layers": [a, b]})).unwrap();
|
||||
let mut h = Harness::builder().with_size(vec2(1600.0, 1000.0)).build_eframe(|_| EffectcraftApp::new(s));
|
||||
let mut h = Harness::builder()
|
||||
.with_size(vec2(1600.0, 1000.0))
|
||||
.with_context_setup(effectcraft_ui_egui::framework::install_headless)
|
||||
.build_eframe(|_| EffectcraftApp::new(s));
|
||||
h.run_steps(4);
|
||||
(h, a, b)
|
||||
}
|
||||
@@ -139,7 +142,10 @@ fn alt_dragging_a_gizmo_arrow_moves_a_copy() {
|
||||
let solid = s.execute("layer.newSolid", json!({"color": "#ff0000", "width": 200, "height": 200})).unwrap()["layer"].as_u64().unwrap();
|
||||
s.execute("layer.setSwitch", json!({"layer": solid, "switch": "threeD", "value": true})).unwrap();
|
||||
s.execute("layer.select", json!({"layers": [solid]})).unwrap();
|
||||
let mut h = Harness::builder().with_size(vec2(1600.0, 1000.0)).build_eframe(|_| EffectcraftApp::new(s));
|
||||
let mut h = Harness::builder()
|
||||
.with_size(vec2(1600.0, 1000.0))
|
||||
.with_context_setup(effectcraft_ui_egui::framework::install_headless)
|
||||
.build_eframe(|_| EffectcraftApp::new(s));
|
||||
h.run_steps(6);
|
||||
let p0 = pos(&h, LayerId(solid));
|
||||
let [x, y, w, hh] = h.state().auto.find(&format!("viewer.gizmo.{solid}.x")).expect("x arrow registered").rect;
|
||||
|
||||
@@ -49,7 +49,7 @@ fn harness(panel: Panel, angle: f64) -> (Harness<'static, EffectcraftApp>, u64,
|
||||
app.toggle_maximize(panel.kind());
|
||||
app.ui.timeline.layer_reveal.insert(layer, vec!["rotation".into()]);
|
||||
app.ui.timeline.open_layers.insert(layer);
|
||||
let mut h = Harness::builder().with_size(vec2(1600.0, 1000.0)).build_eframe(|_| app);
|
||||
let mut h = Harness::builder().with_size(vec2(1600.0, 1000.0)).with_context_setup(effectcraft_ui_egui::framework::install_headless).build_eframe(|_| app);
|
||||
h.run_steps(4);
|
||||
(h, layer, uid)
|
||||
}
|
||||
|
||||
@@ -54,7 +54,10 @@ fn sound_layer(s: &mut Session, levels: [f64; 2]) -> u64 {
|
||||
/// The harness with layer `l` selected and the Audio panel up.
|
||||
fn harness(mut s: Session, l: u64) -> Harness<'static, EffectcraftApp> {
|
||||
s.execute("layer.select", json!({"layers": [l]})).unwrap();
|
||||
let mut h = Harness::builder().with_size(vec2(1600.0, 1000.0)).build_eframe(|_| EffectcraftApp::new(s));
|
||||
let mut h = Harness::builder()
|
||||
.with_size(vec2(1600.0, 1000.0))
|
||||
.with_context_setup(effectcraft_ui_egui::framework::install_headless)
|
||||
.build_eframe(|_| EffectcraftApp::new(s));
|
||||
h.state_mut().show_panel(PanelKind::Audio);
|
||||
h.run_steps(4);
|
||||
h
|
||||
|
||||
@@ -135,7 +135,8 @@ fn scrubbing_plays_one_frame_per_new_frame() {
|
||||
fn cmd_dragging_the_current_time_scrubs_and_an_idle_scrub_closes() {
|
||||
let fake = Fake::default();
|
||||
let (app, _) = setup(true, &fake);
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(|_| app);
|
||||
let mut h =
|
||||
Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_context_setup(effectcraft_ui_egui::framework::install_headless).build_eframe(|_| app);
|
||||
h.run_steps(3);
|
||||
let cti = h.state().auto.find("timeline.cti").expect("current time indicator").clone();
|
||||
let from = pos2(cti.rect[0] + cti.rect[2] / 2.0, cti.rect[1] + cti.rect[3] / 2.0);
|
||||
@@ -217,7 +218,11 @@ fn preview_with_audio_holds_the_first_frame_and_sounds_from_it() {
|
||||
app.frames.set_remote(Some(renderer));
|
||||
let ahead = (app.frames.lanes() * 2).max(4) as i64;
|
||||
app.session.execute("comp.settings", json!({"comp": cid.0, "duration": (4 * ahead) as f64 / 30.0})).unwrap();
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_step_dt(1.0 / 30.0).build_eframe(|_| app);
|
||||
let mut h = Harness::builder()
|
||||
.with_size(egui::vec2(1400.0, 900.0))
|
||||
.with_step_dt(1.0 / 30.0)
|
||||
.with_context_setup(effectcraft_ui_egui::framework::install_headless)
|
||||
.build_eframe(|_| app);
|
||||
h.state_mut().use_manual_clock();
|
||||
h.run_steps(2);
|
||||
gate.discard(&mut h);
|
||||
@@ -254,7 +259,11 @@ fn preview_with_audio_sounds_without_caching_the_work_area() {
|
||||
let gate = GatedFrames::default();
|
||||
let renderer: Arc<dyn RemoteFrames> = Arc::new(gate.clone());
|
||||
app.frames.set_remote(Some(renderer));
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_step_dt(1.0 / 30.0).build_eframe(|_| app);
|
||||
let mut h = Harness::builder()
|
||||
.with_size(egui::vec2(1400.0, 900.0))
|
||||
.with_step_dt(1.0 / 30.0)
|
||||
.with_context_setup(effectcraft_ui_egui::framework::install_headless)
|
||||
.build_eframe(|_| app);
|
||||
h.state_mut().use_manual_clock();
|
||||
h.run_steps(2);
|
||||
gate.discard(&mut h);
|
||||
@@ -281,7 +290,11 @@ fn a_preview_behind_its_sound_drops_frames_and_keeps_the_sound() {
|
||||
let gate = GatedFrames::default();
|
||||
let renderer: Arc<dyn RemoteFrames> = Arc::new(gate.clone());
|
||||
app.frames.set_remote(Some(renderer));
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_step_dt(1.0 / 30.0).build_eframe(|_| app);
|
||||
let mut h = Harness::builder()
|
||||
.with_size(egui::vec2(1400.0, 900.0))
|
||||
.with_step_dt(1.0 / 30.0)
|
||||
.with_context_setup(effectcraft_ui_egui::framework::install_headless)
|
||||
.build_eframe(|_| app);
|
||||
h.state_mut().use_manual_clock();
|
||||
h.run_steps(2);
|
||||
gate.discard(&mut h);
|
||||
@@ -346,7 +359,11 @@ fn a_sound_in_the_first_100_ms_is_heard() {
|
||||
app.session.execute("layer.timing", json!({"layers": [l], "in": start, "out": start + 0.1})).unwrap();
|
||||
app.session.execute("time.set", json!({"time": start})).unwrap();
|
||||
let first = (start * 30.0) as i64;
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_step_dt(1.0 / 30.0).build_eframe(|_| app);
|
||||
let mut h = Harness::builder()
|
||||
.with_size(egui::vec2(1400.0, 900.0))
|
||||
.with_step_dt(1.0 / 30.0)
|
||||
.with_context_setup(effectcraft_ui_egui::framework::install_headless)
|
||||
.build_eframe(|_| app);
|
||||
h.state_mut().use_manual_clock();
|
||||
h.run_steps(2);
|
||||
let now = h.state().now();
|
||||
@@ -366,7 +383,8 @@ fn a_sound_in_the_first_100_ms_is_heard() {
|
||||
fn audio_only_previews_start_at_once() {
|
||||
let fake = Fake::default();
|
||||
let (app, cid) = setup(true, &fake);
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(|_| app);
|
||||
let mut h =
|
||||
Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_context_setup(effectcraft_ui_egui::framework::install_headless).build_eframe(|_| app);
|
||||
h.state_mut().use_manual_clock();
|
||||
h.run_steps(2);
|
||||
let now = h.state().now();
|
||||
@@ -382,7 +400,11 @@ fn no_device_plays_the_picture_and_stop_ends_the_wait() {
|
||||
let fake = Fake::default();
|
||||
let (mut app, cid) = setup_long(true, &fake, 10.0);
|
||||
app.hooks.audio_device = Some(Box::new(|_| None));
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_step_dt(1.0 / 30.0).build_eframe(|_| app);
|
||||
let mut h = Harness::builder()
|
||||
.with_size(egui::vec2(1400.0, 900.0))
|
||||
.with_step_dt(1.0 / 30.0)
|
||||
.with_context_setup(effectcraft_ui_egui::framework::install_headless)
|
||||
.build_eframe(|_| app);
|
||||
h.state_mut().use_manual_clock();
|
||||
h.run_steps(2);
|
||||
let now = h.state().now();
|
||||
@@ -451,7 +473,11 @@ fn startup_finishes_at_any_ram_preview_budget() {
|
||||
if !device {
|
||||
app.hooks.audio_device = Some(Box::new(|_| None));
|
||||
}
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_step_dt(1.0 / 30.0).build_eframe(|_| app);
|
||||
let mut h = Harness::builder()
|
||||
.with_size(egui::vec2(1400.0, 900.0))
|
||||
.with_step_dt(1.0 / 30.0)
|
||||
.with_context_setup(effectcraft_ui_egui::framework::install_headless)
|
||||
.build_eframe(|_| app);
|
||||
h.state_mut().use_manual_clock();
|
||||
h.run_steps(2);
|
||||
let budget = ((fit as f64 + 0.5) * 9216.0 / 0.9) as usize;
|
||||
@@ -482,7 +508,11 @@ fn extended_viewer(fake: &Fake) -> (Harness<'static, EffectcraftApp>, ItemId, [u
|
||||
let mut app = EffectcraftApp::new(s);
|
||||
let f = fake.clone();
|
||||
app.hooks.audio_device = Some(Box::new(move |_| Some(Box::new(f.clone()) as Box<dyn AudioDevice>)));
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_step_dt(1.0 / 30.0).build_eframe(|_| app);
|
||||
let mut h = Harness::builder()
|
||||
.with_size(egui::vec2(1400.0, 900.0))
|
||||
.with_step_dt(1.0 / 30.0)
|
||||
.with_context_setup(effectcraft_ui_egui::framework::install_headless)
|
||||
.build_eframe(|_| app);
|
||||
h.state_mut().use_manual_clock();
|
||||
// The viewer shows the pasteboard: frames render the extended region.
|
||||
let deadline = std::time::Instant::now() + std::time::Duration::from_secs(30);
|
||||
@@ -591,7 +621,11 @@ fn a_device_that_fails_to_start_plays_the_picture() {
|
||||
let fake = Fake::default();
|
||||
let (mut app, cid) = setup_long(true, &fake, 8.0);
|
||||
app.hooks.audio_device = Some(Box::new(|_| Some(Box::new(Broken) as Box<dyn AudioDevice>)));
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_step_dt(1.0 / 30.0).build_eframe(|_| app);
|
||||
let mut h = Harness::builder()
|
||||
.with_size(egui::vec2(1400.0, 900.0))
|
||||
.with_step_dt(1.0 / 30.0)
|
||||
.with_context_setup(effectcraft_ui_egui::framework::install_headless)
|
||||
.build_eframe(|_| app);
|
||||
h.state_mut().use_manual_clock();
|
||||
h.run_steps(2);
|
||||
assert!(until_started(&mut h), "it left its startup");
|
||||
@@ -644,7 +678,11 @@ fn a_started_preview_follows_its_sound() {
|
||||
let device = Playing::default();
|
||||
let d = device.clone();
|
||||
app.hooks.audio_device = Some(Box::new(move |_| Some(Box::new(d.clone()) as Box<dyn AudioDevice>)));
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_step_dt(1.0 / 30.0).build_eframe(|_| app);
|
||||
let mut h = Harness::builder()
|
||||
.with_size(egui::vec2(1400.0, 900.0))
|
||||
.with_step_dt(1.0 / 30.0)
|
||||
.with_context_setup(effectcraft_ui_egui::framework::install_headless)
|
||||
.build_eframe(|_| app);
|
||||
h.state_mut().use_manual_clock();
|
||||
h.run_steps(2);
|
||||
assert!(until_started(&mut h) && h.state().audio.is_some(), "the sound started");
|
||||
@@ -671,7 +709,11 @@ fn startup_does_not_wait_when_the_ram_preview_holds_no_frame() {
|
||||
for budget in [0, 9216 / 2] {
|
||||
let fake = Fake::default();
|
||||
let (app, _) = setup_long(true, &fake, 8.0);
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_step_dt(1.0 / 30.0).build_eframe(|_| app);
|
||||
let mut h = Harness::builder()
|
||||
.with_size(egui::vec2(1400.0, 900.0))
|
||||
.with_step_dt(1.0 / 30.0)
|
||||
.with_context_setup(effectcraft_ui_egui::framework::install_headless)
|
||||
.build_eframe(|_| app);
|
||||
h.state_mut().use_manual_clock();
|
||||
h.run_steps(2);
|
||||
h.state().frames.set_budget(budget);
|
||||
@@ -720,7 +762,11 @@ fn adding_markers_does_not_stop_the_sound() {
|
||||
let fake = Fake::default();
|
||||
let (app, cid) = setup(true, &fake);
|
||||
// Everything is cached before the preview starts, so the sound starts at once.
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_step_dt(1.0 / 31.0).build_eframe(|_| app);
|
||||
let mut h = Harness::builder()
|
||||
.with_size(egui::vec2(1400.0, 900.0))
|
||||
.with_step_dt(1.0 / 31.0)
|
||||
.with_context_setup(effectcraft_ui_egui::framework::install_headless)
|
||||
.build_eframe(|_| app);
|
||||
h.run_steps(2);
|
||||
let deadline = std::time::Instant::now() + std::time::Duration::from_secs(60);
|
||||
let now = h.ctx.input(|i| i.time);
|
||||
@@ -751,7 +797,11 @@ fn unmuting_a_silent_preview_starts_audio_at_its_current_frame() {
|
||||
app.session.execute("layer.setSwitch", json!({"layers": [layer], "switch": "audio", "value": false})).unwrap();
|
||||
let gate = GatedFrames::default();
|
||||
app.frames.set_remote(Some(Arc::new(gate.clone())));
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_step_dt(1.0 / 30.0).build_eframe(|_| app);
|
||||
let mut h = Harness::builder()
|
||||
.with_size(egui::vec2(1400.0, 900.0))
|
||||
.with_step_dt(1.0 / 30.0)
|
||||
.with_context_setup(effectcraft_ui_egui::framework::install_headless)
|
||||
.build_eframe(|_| app);
|
||||
h.state_mut().use_manual_clock();
|
||||
h.run_steps(2);
|
||||
gate.render(&mut h, cid, &(0..60).collect::<Vec<_>>());
|
||||
@@ -871,7 +921,8 @@ fn preview_rate_audio_drives_video_at_half_speed_and_loops() {
|
||||
let gate = GatedFrames::default();
|
||||
app.frames.set_remote(Some(Arc::new(gate.clone())));
|
||||
let ahead = (app.frames.parallelism() * 2).max(4) as i64;
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(|_| app);
|
||||
let mut h =
|
||||
Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_context_setup(effectcraft_ui_egui::framework::install_headless).build_eframe(|_| app);
|
||||
h.state_mut().use_manual_clock();
|
||||
h.run_steps(2);
|
||||
gate.discard(&mut h);
|
||||
|
||||
@@ -14,7 +14,7 @@ fn physical_shortcuts_distinguish_azerty_zoom_keys() {
|
||||
for (command, keys) in [("timeline.zoomIn", "Physical+6"), ("timeline.zoomOut", "Physical+Minus")] {
|
||||
app.session.execute("shortcuts.set", json!({"command": command, "keys": keys})).unwrap();
|
||||
}
|
||||
let mut h = Harness::builder().with_size(vec2(1200.0, 800.0)).build_eframe(|_| app);
|
||||
let mut h = Harness::builder().with_size(vec2(1200.0, 800.0)).with_context_setup(effectcraft_ui_egui::framework::install_headless).build_eframe(|_| app);
|
||||
h.run_steps(3);
|
||||
h.state_mut().ui.timeline.pps = Some(100.0);
|
||||
for (physical, expected) in [(Key::Num6, 150.0), (Key::Minus, 100.0)] {
|
||||
@@ -49,7 +49,7 @@ fn shifted_one_toggles_only_selected_video_and_iso_key_maximizes() {
|
||||
let mut app = EffectcraftApp::new(s);
|
||||
app.session.execute("shortcuts.set", json!({"command": "layer.setSwitch", "params": {"switch": "video"}, "keys": "Shift+1"})).unwrap();
|
||||
app.session.execute("shortcuts.set", json!({"command": "window.maximizePanel", "keys": "IntlBackslash"})).unwrap();
|
||||
let mut h = Harness::builder().with_size(vec2(1200.0, 800.0)).build_eframe(|_| app);
|
||||
let mut h = Harness::builder().with_size(vec2(1200.0, 800.0)).with_context_setup(effectcraft_ui_egui::framework::install_headless).build_eframe(|_| app);
|
||||
h.run_steps(3);
|
||||
for visible in [false, true] {
|
||||
h.event(Event::Key { key: Key::Num1, physical_key: Some(Key::Num1), pressed: true, repeat: false, modifiers: Modifiers::SHIFT });
|
||||
@@ -72,7 +72,7 @@ fn timeline_shift_p_reveals_instead_of_adding_a_text_animator() {
|
||||
s.execute("layer.newSolid", json!({"name": "Box"})).unwrap();
|
||||
let mut app = EffectcraftApp::new(s);
|
||||
app.session.execute("shortcuts.set", json!({"command": "layer.addTextAnimator", "params": {"properties": ["position"]}, "keys": "Shift+P"})).unwrap();
|
||||
let mut h = Harness::builder().with_size(vec2(1200.0, 800.0)).build_eframe(|_| app);
|
||||
let mut h = Harness::builder().with_size(vec2(1200.0, 800.0)).with_context_setup(effectcraft_ui_egui::framework::install_headless).build_eframe(|_| app);
|
||||
h.run_steps(3);
|
||||
h.state_mut().ui.focused = effectcraft_ui_egui::dock::PanelKind::Timeline;
|
||||
h.event(Event::Key { key: Key::P, physical_key: Some(Key::P), pressed: true, repeat: false, modifiers: Modifiers::SHIFT });
|
||||
|
||||
@@ -20,7 +20,10 @@ fn harness() -> (Harness<'static, EffectcraftApp>, [u64; 6]) {
|
||||
s.execute("prop.set", json!({"layer": ids[3], "path": "transform/position", "value": [60, 40]})).unwrap();
|
||||
s.execute("prop.set", json!({"layer": ids[3], "path": "transform/scale", "value": [50, 50]})).unwrap();
|
||||
s.history.undo.clear();
|
||||
let mut h = Harness::builder().with_size(vec2(1600.0, 1000.0)).build_eframe(|_| EffectcraftApp::new(s));
|
||||
let mut h = Harness::builder()
|
||||
.with_size(vec2(1600.0, 1000.0))
|
||||
.with_context_setup(effectcraft_ui_egui::framework::install_headless)
|
||||
.build_eframe(|_| EffectcraftApp::new(s));
|
||||
h.state_mut().ui.timeline.show_modes = true;
|
||||
h.state_mut().ui.timeline.columns_w = 900.0;
|
||||
h.run_steps(3);
|
||||
|
||||
@@ -22,7 +22,10 @@ fn harness() -> (Harness<'static, EffectcraftApp>, Vec<u64>) {
|
||||
.collect();
|
||||
ids.reverse();
|
||||
s.execute("edit.deselectAll", json!({})).unwrap();
|
||||
let mut h = Harness::builder().with_size(vec2(1600.0, 1000.0)).build_eframe(|_| EffectcraftApp::new(s));
|
||||
let mut h = Harness::builder()
|
||||
.with_size(vec2(1600.0, 1000.0))
|
||||
.with_context_setup(effectcraft_ui_egui::framework::install_headless)
|
||||
.build_eframe(|_| EffectcraftApp::new(s));
|
||||
h.run_steps(3);
|
||||
(h, ids)
|
||||
}
|
||||
@@ -165,7 +168,10 @@ fn switch_targets_skip_the_layers_the_switch_does_not_apply_to() {
|
||||
let cam = s.execute("layer.newCamera", json!({})).unwrap()["layer"].as_u64().unwrap();
|
||||
s.execute("effect.apply", json!({"effect": "ec.blur.gaussian", "layers": [solid]})).unwrap();
|
||||
s.execute("edit.deselectAll", json!({})).unwrap();
|
||||
let mut h = Harness::builder().with_size(vec2(1600.0, 1000.0)).build_eframe(|_| EffectcraftApp::new(s));
|
||||
let mut h = Harness::builder()
|
||||
.with_size(vec2(1600.0, 1000.0))
|
||||
.with_context_setup(effectcraft_ui_egui::framework::install_headless)
|
||||
.build_eframe(|_| EffectcraftApp::new(s));
|
||||
h.run_steps(3);
|
||||
select(&mut h, &[solid, null, cam]);
|
||||
|
||||
|
||||
@@ -12,7 +12,10 @@ use serde_json::json;
|
||||
fn harness() -> Harness<'static, EffectcraftApp> {
|
||||
let mut session = Session::default();
|
||||
session.execute("comp.new", json!({"name":"Empty", "width":640,"height":360,"duration":4})).unwrap();
|
||||
let mut h = Harness::builder().with_size(vec2(1600.0, 1000.0)).build_eframe(|_| EffectcraftApp::new(session));
|
||||
let mut h = Harness::builder()
|
||||
.with_size(vec2(1600.0, 1000.0))
|
||||
.with_context_setup(effectcraft_ui_egui::framework::install_headless)
|
||||
.build_eframe(|_| EffectcraftApp::new(session));
|
||||
// English whatever the system language: the menu items found below by label are translated.
|
||||
h.state_mut().session.prefs.general.language = "en".into();
|
||||
h.run_steps(3);
|
||||
|
||||
@@ -75,7 +75,8 @@ fn click(h: &mut Harness<'_, EffectcraftApp>, at: egui::Pos2, modifiers: egui::M
|
||||
#[test]
|
||||
fn deleting_viewer_track_points_preserves_the_effect_and_layer() {
|
||||
let (a, plate, uid) = app();
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).build_eframe(|_| a);
|
||||
let mut h =
|
||||
Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).with_context_setup(effectcraft_ui_egui::framework::install_headless).build_eframe(|_| a);
|
||||
h.state_mut().show_panel(PanelKind::Composition);
|
||||
h.run_steps(4);
|
||||
let point = rect(&h, "viewer.cameraTracker.point.7").center();
|
||||
@@ -92,7 +93,8 @@ fn deleting_viewer_track_points_preserves_the_effect_and_layer() {
|
||||
#[test]
|
||||
fn viewer_points_selection_and_effect_controls() {
|
||||
let (a, plate, uid) = app();
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).build_eframe(|_| a);
|
||||
let mut h =
|
||||
Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).with_context_setup(effectcraft_ui_egui::framework::install_headless).build_eframe(|_| a);
|
||||
h.state_mut().show_panel(PanelKind::Composition);
|
||||
h.run_steps(4);
|
||||
let all = ids(&h);
|
||||
@@ -188,7 +190,7 @@ fn blender_export_button_opens_python_dialog_and_writes_scene() {
|
||||
let builder = Harness::builder().with_size(egui::vec2(1600.0, 1000.0));
|
||||
let builder = if shot.is_some() { builder.wgpu() } else { builder };
|
||||
let _device = shot.is_some().then(crate::gpu_test::lock);
|
||||
let mut h = builder.build_eframe(|_| a);
|
||||
let mut h = builder.with_context_setup(effectcraft_ui_egui::framework::install_headless).build_eframe(|_| a);
|
||||
h.state_mut().show_panel(PanelKind::EffectControls);
|
||||
h.run_steps(5);
|
||||
let button = rect(&h, &format!("effectControls.cameraTracker.{uid}.exportBlender"));
|
||||
@@ -207,7 +209,8 @@ fn blender_export_button_opens_python_dialog_and_writes_scene() {
|
||||
#[test]
|
||||
fn effect_controls_show_how_many_frames_a_partial_solve_solved() {
|
||||
let (a, plate, uid) = app();
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).build_eframe(|_| a);
|
||||
let mut h =
|
||||
Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).with_context_setup(effectcraft_ui_egui::framework::install_headless).build_eframe(|_| a);
|
||||
h.state_mut().show_panel(PanelKind::EffectControls);
|
||||
h.run_steps(4);
|
||||
let line = format!("effectControls.cameraTracker.{uid}.partialSolve");
|
||||
@@ -247,7 +250,8 @@ fn drag_with(h: &mut Harness<'_, EffectcraftApp>, button: egui::PointerButton, f
|
||||
#[test]
|
||||
fn viewer_zooms_and_pans_over_the_track_points() {
|
||||
let (a, ..) = app();
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).build_eframe(|_| a);
|
||||
let mut h =
|
||||
Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).with_context_setup(effectcraft_ui_egui::framework::install_headless).build_eframe(|_| a);
|
||||
h.state_mut().show_panel(PanelKind::Composition);
|
||||
h.run_steps(4);
|
||||
// Wheel over a point: zooms.
|
||||
@@ -310,7 +314,12 @@ fn snapshot_showcase_track() {
|
||||
s.execute("layer.select", json!({"layers": ["#1"]})).unwrap();
|
||||
s.execute("track.camera", json!({"layer": "#1", "wait": true})).unwrap();
|
||||
s.execute("time.set", json!({"time": 2.0})).unwrap();
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).with_pixels_per_point(1.0).wgpu().build_eframe(|_| EffectcraftApp::new(s));
|
||||
let mut h = Harness::builder()
|
||||
.with_size(egui::vec2(1600.0, 1000.0))
|
||||
.with_pixels_per_point(1.0)
|
||||
.wgpu()
|
||||
.with_context_setup(effectcraft_ui_egui::framework::install_headless)
|
||||
.build_eframe(|_| EffectcraftApp::new(s));
|
||||
h.state_mut().show_panel(PanelKind::Composition);
|
||||
settle(&mut h);
|
||||
let pts: Vec<String> = ids(&h).into_iter().filter(|i| i.starts_with("viewer.cameraTracker.point.")).collect();
|
||||
|
||||
@@ -48,7 +48,11 @@ fn character_fill_eyedropper_samples_viewer_and_keeps_text_selection() {
|
||||
let mut app = EffectcraftApp::new(s);
|
||||
app.set_workspace("Text");
|
||||
let builder = Harness::builder().with_size(vec2(1600.0, 1400.0));
|
||||
let mut h = if std::env::var_os("EC_SNAPSHOT_DIR").is_some() { builder.wgpu().build_eframe(|_| app) } else { builder.build_eframe(|_| app) };
|
||||
let mut h = if std::env::var_os("EC_SNAPSHOT_DIR").is_some() {
|
||||
builder.wgpu().with_context_setup(effectcraft_ui_egui::framework::install_headless).build_eframe(|_| app)
|
||||
} else {
|
||||
builder.with_context_setup(effectcraft_ui_egui::framework::install_headless).build_eframe(|_| app)
|
||||
};
|
||||
h.state_mut().show_panel(PanelKind::Character);
|
||||
settle(&mut h);
|
||||
click_auto(&mut h, "character.fill.eyedropper");
|
||||
@@ -76,7 +80,11 @@ fn character_stroke_eyedropper_samples_viewer() {
|
||||
app.ui.viewer.show_layer_controls = false;
|
||||
app.ui.dock = dock::docked(dock::hsplit(SplitSize::FixedSecond(360.0), dock::tabs(&[PanelKind::Composition], 0), dock::tabs(&[PanelKind::Character], 0)));
|
||||
let builder = Harness::builder().with_size(vec2(1200.0, 760.0));
|
||||
let mut h = if std::env::var_os("EC_SNAPSHOT_DIR").is_some() { builder.wgpu().build_eframe(|_| app) } else { builder.build_eframe(|_| app) };
|
||||
let mut h = if std::env::var_os("EC_SNAPSHOT_DIR").is_some() {
|
||||
builder.wgpu().with_context_setup(effectcraft_ui_egui::framework::install_headless).build_eframe(|_| app)
|
||||
} else {
|
||||
builder.with_context_setup(effectcraft_ui_egui::framework::install_headless).build_eframe(|_| app)
|
||||
};
|
||||
h.state_mut().show_panel(PanelKind::Character);
|
||||
h.state_mut().show_panel(PanelKind::Composition);
|
||||
settle(&mut h);
|
||||
|
||||
@@ -49,7 +49,11 @@ fn character_stroke_order_menu_sets_layer_fill_and_stroke() {
|
||||
let mut app = EffectcraftApp::new(s);
|
||||
app.set_workspace("Text");
|
||||
let builder = Harness::builder().with_size(vec2(1600.0, 1400.0));
|
||||
let mut h = if std::env::var_os("EC_SNAPSHOT_DIR").is_some() { builder.wgpu().build_eframe(|_| app) } else { builder.build_eframe(|_| app) };
|
||||
let mut h = if std::env::var_os("EC_SNAPSHOT_DIR").is_some() {
|
||||
builder.wgpu().with_context_setup(effectcraft_ui_egui::framework::install_headless).build_eframe(|_| app)
|
||||
} else {
|
||||
builder.with_context_setup(effectcraft_ui_egui::framework::install_headless).build_eframe(|_| app)
|
||||
};
|
||||
h.state_mut().show_panel(PanelKind::Character);
|
||||
h.run_steps(4);
|
||||
|
||||
|
||||
@@ -20,7 +20,10 @@ fn view_options_drag_checks_and_unchecks_neighbours() {
|
||||
let mut session = Session::default();
|
||||
session.prefs.disk.disk_cache_enabled = false;
|
||||
session.execute("comp.new", json!({"width":32,"height":32,"duration":1})).unwrap();
|
||||
let mut h = Harness::builder().with_size(vec2(1200.0, 900.0)).build_eframe(|_| EffectcraftApp::new(session));
|
||||
let mut h = Harness::builder()
|
||||
.with_size(vec2(1200.0, 900.0))
|
||||
.with_context_setup(effectcraft_ui_egui::framework::install_headless)
|
||||
.build_eframe(|_| EffectcraftApp::new(session));
|
||||
h.state_mut().ui.viewer.rulers = false;
|
||||
h.state_mut().ui.viewer.guides = true;
|
||||
h.state_mut().ui.viewer.grid = false;
|
||||
|
||||
@@ -51,7 +51,7 @@ fn hex_code_sets_an_effect_colour() {
|
||||
let mut app = EffectcraftApp::new(s);
|
||||
app.show_panel(PanelKind::EffectControls);
|
||||
app.toggle_maximize(PanelKind::EffectControls);
|
||||
let mut h = Harness::builder().with_size(vec2(1600.0, 1000.0)).build_eframe(|_| app);
|
||||
let mut h = Harness::builder().with_size(vec2(1600.0, 1000.0)).with_context_setup(effectcraft_ui_egui::framework::install_headless).build_eframe(|_| app);
|
||||
h.run_steps(4);
|
||||
let midtones = |h: &Harness<'_, EffectcraftApp>| {
|
||||
let c = h.state().session.active_comp().unwrap().layer(LayerId(layer)).unwrap().props.find(uid).unwrap().value.as_color();
|
||||
|
||||
@@ -9,7 +9,11 @@ use serde_json::json;
|
||||
fn harness() -> Harness<'static, EffectcraftApp> {
|
||||
let mut s = Session::default();
|
||||
s.execute("comp.new", json!({"name": "Edit", "width": 2560, "height": 1440, "frameRate": 60, "duration": 4})).unwrap();
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).with_step_dt(1.0 / 60.0).build_eframe(|_| EffectcraftApp::new(s));
|
||||
let mut h = Harness::builder()
|
||||
.with_size(egui::vec2(1600.0, 1000.0))
|
||||
.with_step_dt(1.0 / 60.0)
|
||||
.with_context_setup(effectcraft_ui_egui::framework::install_headless)
|
||||
.build_eframe(|_| EffectcraftApp::new(s));
|
||||
h.run_steps(3);
|
||||
h
|
||||
}
|
||||
@@ -114,8 +118,12 @@ fn composition_settings_buttons_fit_every_language() {
|
||||
let mut s = Session::default();
|
||||
s.execute("comp.new", json!({"name": "Edit", "width": 2560, "height": 1440, "frameRate": 60, "duration": 4})).unwrap();
|
||||
s.prefs.general.language = language.into();
|
||||
let mut h =
|
||||
Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).with_step_dt(1.0 / 60.0).allow_missing_glyphs().build_eframe(|_| EffectcraftApp::new(s));
|
||||
let mut h = Harness::builder()
|
||||
.with_size(egui::vec2(1600.0, 1000.0))
|
||||
.with_step_dt(1.0 / 60.0)
|
||||
.allow_missing_glyphs()
|
||||
.with_context_setup(effectcraft_ui_egui::framework::install_headless)
|
||||
.build_eframe(|_| EffectcraftApp::new(s));
|
||||
h.run_steps(3);
|
||||
open_settings(&mut h);
|
||||
let mut oks = vec![];
|
||||
@@ -148,7 +156,11 @@ fn rect_of(h: &Harness<'_, EffectcraftApp>, id: &str) -> egui::Rect {
|
||||
fn composition_settings_view_stays_put_when_it_scrolls() {
|
||||
let mut s = Session::default();
|
||||
s.execute("comp.new", json!({"name": "Edit", "width": 2560, "height": 1440, "frameRate": 60, "duration": 4})).unwrap();
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1600.0, 520.0)).with_step_dt(1.0 / 60.0).build_eframe(|_| EffectcraftApp::new(s));
|
||||
let mut h = Harness::builder()
|
||||
.with_size(egui::vec2(1600.0, 520.0))
|
||||
.with_step_dt(1.0 / 60.0)
|
||||
.with_context_setup(effectcraft_ui_egui::framework::install_headless)
|
||||
.build_eframe(|_| EffectcraftApp::new(s));
|
||||
h.run_steps(3);
|
||||
open_settings(&mut h);
|
||||
let (view, ok) = (rect_of(&h, "dialog.comp.view"), rect_of(&h, "dialog.comp.ok"));
|
||||
@@ -183,6 +195,7 @@ fn composition_settings_refits_when_the_language_changes() {
|
||||
.with_max_steps(30)
|
||||
// `run` checks accessibility after settling; that is not what this test is about.
|
||||
.with_accessibility_check(false)
|
||||
.with_context_setup(effectcraft_ui_egui::framework::install_headless)
|
||||
.build_eframe(|_| EffectcraftApp::new(s));
|
||||
h.run_steps(3);
|
||||
open_settings(&mut h);
|
||||
@@ -203,7 +216,11 @@ fn composition_settings_refits_when_the_language_changes() {
|
||||
/// leaves the Home screen for the new composition; Cancel keeps it.
|
||||
#[test]
|
||||
fn new_composition_dialog_ok_leaves_the_home_screen() {
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).with_step_dt(1.0 / 60.0).build_eframe(|_| EffectcraftApp::new(Session::default()));
|
||||
let mut h = Harness::builder()
|
||||
.with_size(egui::vec2(1600.0, 1000.0))
|
||||
.with_step_dt(1.0 / 60.0)
|
||||
.with_context_setup(effectcraft_ui_egui::framework::install_headless)
|
||||
.build_eframe(|_| EffectcraftApp::new(Session::default()));
|
||||
h.run_steps(3);
|
||||
h.state_mut().ui.start_screen = true;
|
||||
h.state_mut().dialog = Some(Dialog::NewComp);
|
||||
|
||||
@@ -92,7 +92,12 @@ fn harness(s: Session, size: egui::Vec2, ppp: f32, ec: f32) -> Harness<'static,
|
||||
/// [`harness`] whose steps advance the clock by `dt` seconds.
|
||||
fn harness_dt(s: Session, size: egui::Vec2, ppp: f32, ec: f32, dt: f32) -> Harness<'static, EffectcraftApp> {
|
||||
let app = app(s, ec);
|
||||
let mut h = Harness::builder().with_size(size).with_pixels_per_point(ppp).with_step_dt(dt).build_eframe(|_| app);
|
||||
let mut h = Harness::builder()
|
||||
.with_size(size)
|
||||
.with_pixels_per_point(ppp)
|
||||
.with_step_dt(dt)
|
||||
.with_context_setup(effectcraft_ui_egui::framework::install_headless)
|
||||
.build_eframe(|_| app);
|
||||
settle(&mut h);
|
||||
h
|
||||
}
|
||||
@@ -651,7 +656,12 @@ fn picks_on_the_gpu_viewer() {
|
||||
}
|
||||
let (s, ids) = crypto_session("gpu", 1919, 1079, false);
|
||||
let app = app(s, 420.0);
|
||||
let mut h = Harness::builder().with_size(vec2(1400.0, 900.0)).with_pixels_per_point(1.0).wgpu_setup(setup).build_eframe(|_| app);
|
||||
let mut h = Harness::builder()
|
||||
.with_size(vec2(1400.0, 900.0))
|
||||
.with_pixels_per_point(1.0)
|
||||
.wgpu_setup(setup)
|
||||
.with_context_setup(effectcraft_ui_egui::framework::install_headless)
|
||||
.build_eframe(|_| app);
|
||||
settle(&mut h);
|
||||
if h.state().gpu_adapter().is_none() {
|
||||
eprintln!("the viewer stayed on the CPU ({adapter}): skipping");
|
||||
@@ -1923,10 +1933,11 @@ fn the_same_status_set_again_while_shown_gets_its_own_5_s() {
|
||||
let _ = std::fs::remove_dir_all(&ids.dir);
|
||||
}
|
||||
|
||||
/// A press, a PageDown and the release in one slow pass: the click is the frame on screen at the
|
||||
/// press, so it is dropped and says so, not made on the next frame (Windows round 6, R-i pd8).
|
||||
/// A press, then a PageDown and the release in one slow pass (the runtime takes the press in its
|
||||
/// own pass): the click is the frame on screen at the press, so it is dropped and says so, not
|
||||
/// made on the next frame (Windows round 6, R-i pd8).
|
||||
#[test]
|
||||
fn a_frame_step_between_press_and_release_in_one_pass_drops_the_click() {
|
||||
fn a_frame_step_between_press_and_release_drops_the_click() {
|
||||
let (mut h, ids, a, _) = ready_at_two_ids("key-one-pass");
|
||||
let key = |pressed| Event::Key { key: egui::Key::PageDown, physical_key: None, pressed, repeat: false, modifiers: Modifiers::NONE };
|
||||
let ev = &mut h.input_mut().events;
|
||||
@@ -1935,6 +1946,7 @@ fn a_frame_step_between_press_and_release_in_one_pass_drops_the_click() {
|
||||
ev.push(key(false));
|
||||
ev.push(Event::PointerButton { pos: a, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE });
|
||||
h.step();
|
||||
h.step();
|
||||
assert!(h.state().session.time().seconds() > 0.0, "the PageDown stepped");
|
||||
assert!(h.state().ui.status.starts_with("Pick not made"), "{:?}", h.state().ui.status);
|
||||
for _ in 0..40 {
|
||||
|
||||
@@ -94,7 +94,12 @@ fn harness(s: Session, size: egui::Vec2) -> Harness<'static, EffectcraftApp> {
|
||||
dock::hsplit(SplitSize::FixedSecond(420.0), dock::tabs(&[PanelKind::Composition], 0), dock::tabs(&[PanelKind::EffectControls], 0)),
|
||||
dock::hsplit(SplitSize::FixedSecond(300.0), dock::tabs(&[PanelKind::Timeline], 0), dock::tabs(&[PanelKind::History], 0)),
|
||||
));
|
||||
let mut h = Harness::builder().with_size(size).with_pixels_per_point(1.0).with_step_dt(0.25).build_eframe(|_| app);
|
||||
let mut h = Harness::builder()
|
||||
.with_size(size)
|
||||
.with_pixels_per_point(1.0)
|
||||
.with_step_dt(0.25)
|
||||
.with_context_setup(effectcraft_ui_egui::framework::install_headless)
|
||||
.build_eframe(|_| app);
|
||||
settle(&mut h);
|
||||
h
|
||||
}
|
||||
|
||||
Loaded 100 of 198 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user