diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index e78fe1ea3..8f1aa5ad5 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -16,6 +16,9 @@ concurrency: jobs: sonarcloud: - # Tracked at @main so org-wide CI improvements propagate without PR churn. + # Track shared CI improvements on main. uses: storytold/craft-common-actions/.github/workflows/sonarcloud.yml@main + with: + timeout-minutes: 120 + fonts-ref: b076417b5880bd4154bd22f00695b1d28c6bea83 secrets: inherit diff --git a/Cargo.lock b/Cargo.lock index 70fa5a612..247142a45 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -209,14 +209,14 @@ dependencies = [ "clipboard-win", "image", "log", - "objc2 0.6.4", + "objc2 0.6.5", "objc2-app-kit 0.3.2", "objc2-core-foundation", "objc2-core-graphics", "objc2-foundation 0.3.2", "parking_lot", "percent-encoding", - "windows-sys 0.60.2", + "windows-sys 0.59.0", "wl-clipboard-rs", "x11rb", ] @@ -432,13 +432,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" [[package]] -name = "bit-set" -version = "0.8.0" +name = "base64" +version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08807e080ed7f9d5433fa9b275196cfc35414f66a0c79d864dc51a0d825231a3" -dependencies = [ - "bit-vec 0.8.0", -] +checksum = "ac07cdecf99051d9a5238b80f35af32cdeba5b336e55d957b318b50137e18da5" [[package]] name = "bit-set" @@ -450,10 +447,13 @@ dependencies = [ ] [[package]] -name = "bit-vec" -version = "0.8.0" +name = "bit-set" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e764a1d40d510daf35e07be9eb06e75770908c27d411ee6c92109c9840eaaf7" +checksum = "56d87354e4229f54a44f7bf2435906a4656dba36026ab6eaca629a2c436a691c" +dependencies = [ + "bit-vec 0.10.1", +] [[package]] name = "bit-vec" @@ -461,6 +461,16 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b71798fca2c1fe1086445a7258a4bc81e6e49dcd24c8d0dd9a1e57395b603f51" +[[package]] +name = "bit-vec" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5727b15fa97d4f4fee0a3b7c3d550ed0269f54329207b86388de918604e31269" +dependencies = [ + "borsh", + "serde", +] + [[package]] name = "bit_field" version = "0.10.3" @@ -479,6 +489,15 @@ version = "2.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + [[package]] name = "block2" version = "0.5.1" @@ -494,7 +513,7 @@ version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdeb9d870516001442e364c5220d3574d2da8dc765554b4a617230d33fa58ef5" dependencies = [ - "objc2 0.6.4", + "objc2 0.6.5", ] [[package]] @@ -563,7 +582,7 @@ dependencies = [ "oneshot", "pastey", "portable-atomic", - "rand 0.10.3", + "rand", "regress", "rustc-hash 2.1.3", "ryu-js", @@ -654,6 +673,30 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "borsh" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "553c5d846a6ba5150c65e3b1b8ec073bcf1abc20f9b7220de384a4443ea4e20a" +dependencies = [ + "borsh-derive", + "bytes", + "cfg_aliases", +] + +[[package]] +name = "borsh-derive" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12cdfe656708a01f89b451a7d36466e6fe6c414de0aa18fc54f864f6f9ca9f56" +dependencies = [ + "once_cell", + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 3.0.6", +] + [[package]] name = "bumpalo" version = "3.20.3" @@ -795,8 +838,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "65c35e4b699c7e15ccbe7ee35c005e4fc0a278d22238a2857e6ce2dadeda1b06" dependencies = [ "cfg-if", - "cpufeatures", - "rand_core 0.10.1", + "cpufeatures 0.3.1", + "rand_core", ] [[package]] @@ -872,6 +915,16 @@ dependencies = [ "libc", ] +[[package]] +name = "core-foundation" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2a6cd9ae233e7f62ba4e9353e81a88df7fc8a5987b8d445b4d90c879bd156f6" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "core-foundation-sys" version = "0.8.7" @@ -885,7 +938,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c07782be35f9e1140080c6b96f0d44b739e2278479f64e02fdab4e32dfd8b081" dependencies = [ "bitflags 1.3.2", - "core-foundation", + "core-foundation 0.9.4", "core-graphics-types", "foreign-types", "libc", @@ -898,7 +951,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "45390e6114f68f718cc7a830514a96f903cccd70d02a8f6d9f643ac4ba45afaf" dependencies = [ "bitflags 1.3.2", - "core-foundation", + "core-foundation 0.9.4", "libc", ] @@ -964,6 +1017,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + [[package]] name = "cpufeatures" version = "0.3.1" @@ -976,12 +1038,12 @@ dependencies = [ [[package]] name = "craft-docpath" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=82a24b006eefa036b43c09a67fb9a3fbd17ffe63#82a24b006eefa036b43c09a67fb9a3fbd17ffe63" +source = "git+https://github.com/storytold/craft-libs?rev=512b54355cd1418f4e8c56a3fbd7483c3c274bf3#512b54355cd1418f4e8c56a3fbd7483c3c274bf3" [[package]] name = "craft-pdf" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=9f75d3dc19b4b514c4f3d4847ed1ec1b0e86b4ef#9f75d3dc19b4b514c4f3d4847ed1ec1b0e86b4ef" +source = "git+https://github.com/storytold/craft-libs?rev=512b54355cd1418f4e8c56a3fbd7483c3c274bf3#512b54355cd1418f4e8c56a3fbd7483c3c274bf3" dependencies = [ "hayro-syntax", "thiserror 2.0.21", @@ -990,12 +1052,41 @@ dependencies = [ [[package]] name = "craft-ui" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=25da1314d443171b4adeaad2cd9454b273f35c6f#25da1314d443171b4adeaad2cd9454b273f35c6f" +source = "git+https://github.com/storytold/craft-libs?rev=512b54355cd1418f4e8c56a3fbd7483c3c274bf3#512b54355cd1418f4e8c56a3fbd7483c3c274bf3" dependencies = [ "egui", + "log", + "objc2 0.6.5", + "objc2-app-kit 0.3.2", + "objc2-foundation 0.3.2", "serde", ] +[[package]] +name = "craft-update" +version = "0.1.0" +source = "git+https://github.com/storytold/craft-libs?rev=512b54355cd1418f4e8c56a3fbd7483c3c274bf3#512b54355cd1418f4e8c56a3fbd7483c3c274bf3" +dependencies = [ + "chrono", + "dunce", + "egui", + "flate2", + "getrandom 0.3.4", + "log", + "plist", + "semver", + "serde", + "serde_json", + "sha2", + "tar", + "tempfile", + "ureq", + "verifysign", + "winreg", + "winsafe", + "zip", +] + [[package]] name = "crc32fast" version = "1.5.2" @@ -1045,6 +1136,16 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" +[[package]] +name = "crypto-common" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" +dependencies = [ + "generic-array", + "typenum", +] + [[package]] name = "cursor-icon" version = "1.2.0" @@ -1077,6 +1178,16 @@ version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c" +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + [[package]] name = "dispatch" version = "0.2.0" @@ -1092,7 +1203,7 @@ dependencies = [ "bitflags 2.13.2", "block2 0.6.2", "libc", - "objc2 0.6.4", + "objc2 0.6.5", ] [[package]] @@ -1136,6 +1247,12 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8b14ccef22fc6f5a8f4d7d768562a182c04ce9a3b3157b91390b52ddfdf1a76" +[[package]] +name = "dunce" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" + [[package]] name = "dynify" version = "0.1.2" @@ -1170,6 +1287,7 @@ name = "effectcraft" version = "0.17.0" dependencies = [ "cpal", + "craft-update", "effectcraft-engine", "effectcraft-host", "effectcraft-ui-egui", @@ -1178,10 +1296,10 @@ dependencies = [ "fmv-macos-events", "log", "muda", - "objc2 0.6.4", + "objc2 0.6.5", "objc2-app-kit 0.3.2", "objc2-foundation 0.3.2", - "pollster 0.4.0", + "pollster 1.0.1", "rfd", "serde", "serde_json", @@ -1357,7 +1475,7 @@ dependencies = [ "effectcraft-time", "js-sys", "log", - "pollster 0.4.0", + "pollster 1.0.1", "wasm-bindgen", "web-time", "wgpu", @@ -1479,7 +1597,7 @@ version = "0.17.0" dependencies = [ "effectcraft-geom", "image", - "miniz_oxide 0.8.9", + "miniz_oxide 0.9.1", "serde", "serde_json", "thiserror 2.0.21", @@ -1514,7 +1632,7 @@ dependencies = [ "effectcraft-text", "image", "kurbo", - "miniz_oxide 0.8.9", + "miniz_oxide 0.9.1", "skrifa", "wasm-bindgen-test", "zune-jpeg", @@ -1549,7 +1667,7 @@ dependencies = [ name = "effectcraft-psd" version = "0.17.0" dependencies = [ - "miniz_oxide 0.8.9", + "miniz_oxide 0.9.1", ] [[package]] @@ -1605,7 +1723,7 @@ dependencies = [ name = "effectcraft-segment" version = "0.17.0" dependencies = [ - "miniz_oxide 0.8.9", + "miniz_oxide 0.9.1", "ndarray", "rayon", ] @@ -1660,6 +1778,7 @@ version = "0.17.0" dependencies = [ "chrono", "craft-ui", + "craft-update", "effectcraft-color", "effectcraft-engine", "effectcraft-geom", @@ -1678,7 +1797,7 @@ dependencies = [ "image", "kurbo", "log", - "pollster 0.4.0", + "pollster 1.0.1", "rayon", "serde", "serde_json", @@ -1731,7 +1850,7 @@ dependencies = [ "image", "js-sys", "log", - "objc2 0.6.4", + "objc2 0.6.5", "objc2-app-kit 0.3.2", "objc2-foundation 0.3.2", "parking_lot", @@ -1799,7 +1918,7 @@ dependencies = [ "egui", "image", "log", - "objc2 0.6.4", + "objc2 0.6.5", "objc2-app-kit 0.3.2", "objc2-foundation 0.3.2", "objc2-ui-kit 0.3.2", @@ -2056,6 +2175,16 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b97b65636e5b9ef369943878ac74335ba1c55c1cb6adbf1e2c293c624248d693" +[[package]] +name = "filetime" +version = "0.2.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c287a33c7f0a620c38e641e7f60827713987b3c0f26e8ddc9462cc69cf75759" +dependencies = [ + "cfg-if", + "libc", +] + [[package]] name = "filmcraft-aac" version = "0.1.1" @@ -2340,7 +2469,7 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90642cf66dde7f205dc8b42dfe57b47d0f3a29f571b832742883ef512e23fe55" dependencies = [ - "objc2 0.6.4", + "objc2 0.6.5", "objc2-app-kit 0.3.2", "objc2-foundation 0.3.2", ] @@ -2476,6 +2605,16 @@ dependencies = [ "slab", ] +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + [[package]] name = "gethostname" version = "1.1.0" @@ -2486,6 +2625,17 @@ dependencies = [ "windows-link", ] +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "getrandom" version = "0.3.4" @@ -2508,7 +2658,7 @@ dependencies = [ "js-sys", "libc", "r-efi 6.0.0", - "rand_core 0.10.1", + "rand_core", "wasm-bindgen", ] @@ -2575,7 +2725,7 @@ dependencies = [ "glutin_glx_sys", "glutin_wgl_sys", "libloading", - "objc2 0.6.4", + "objc2 0.6.5", "objc2-app-kit 0.3.2", "objc2-core-foundation", "objc2-foundation 0.3.2", @@ -2720,7 +2870,7 @@ checksum = "9f4d0e94ddd48749f06bbe4e5389fb9799a0c45bcaf00495042076ef05e3241a" [[package]] name = "hayro-jbig2" version = "0.3.0" -source = "git+https://github.com/storytold/craft-libs?rev=9f75d3dc19b4b514c4f3d4847ed1ec1b0e86b4ef#9f75d3dc19b4b514c4f3d4847ed1ec1b0e86b4ef" +source = "git+https://github.com/storytold/craft-libs?rev=512b54355cd1418f4e8c56a3fbd7483c3c274bf3#512b54355cd1418f4e8c56a3fbd7483c3c274bf3" dependencies = [ "hayro-ccitt", ] @@ -2734,7 +2884,7 @@ checksum = "c75ab947623ef4ccaa7acf0579edf7cbb5a73838e3839a7be73335e522f433a1" [[package]] name = "hayro-syntax" version = "0.7.2" -source = "git+https://github.com/storytold/craft-libs?rev=9f75d3dc19b4b514c4f3d4847ed1ec1b0e86b4ef#9f75d3dc19b4b514c4f3d4847ed1ec1b0e86b4ef" +source = "git+https://github.com/storytold/craft-libs?rev=512b54355cd1418f4e8c56a3fbd7483c3c274bf3#512b54355cd1418f4e8c56a3fbd7483c3c274bf3" dependencies = [ "hayro-jbig2", "hayro-jpeg2000", @@ -2762,6 +2912,22 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "http" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "918d3568bebf352712bc2ef3d46a8bcf1a75b373be6539de198e9105cbbf9ce0" +dependencies = [ + "bytes", + "itoa", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + [[package]] name = "icu_collections" version = "2.3.0" @@ -3134,9 +3300,9 @@ checksum = "d4a5ff6bcca6c4867b1c4fd4ef63e4db7436ef363e0ad7531d1558856bae64f4" [[package]] name = "linesweeper" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c19728333c060c6569a53c9a0e56c4be0df52cb4e6e07a8fbe16084cecce769" +checksum = "a25df1b0c5432893f41bba817150e323703ee5f6d974f3a6808ac7fd7f046d18" dependencies = [ "arrayvec", "kurbo", @@ -3186,9 +3352,9 @@ checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6" [[package]] name = "lz4_flex" -version = "0.11.6" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "373f5eceeeab7925e0c1098212f2fbc4d416adec9d35051a6ab251e824c1854a" +checksum = "ecbdfe44b1bd960b68170b417450a628c43f7cf56bb3c5317e61cb230ee7f226" [[package]] name = "mach2" @@ -3275,18 +3441,17 @@ dependencies = [ [[package]] name = "muda" -version = "0.21.0" +version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6744ab645ebe79f9c428455c7cb9dfa4275fa3b50a25408e08f927da8dc618c" +checksum = "4340e89c178916e62879c5c36b7f699019369be413e496178a6983ce91b8bc03" dependencies = [ "crossbeam-channel", "dpi", "keyboard-types", - "objc2 0.6.4", + "objc2 0.6.5", "objc2-app-kit 0.3.2", "objc2-core-foundation", "objc2-foundation 0.3.2", - "once_cell", "png", "thiserror 2.0.21", "windows-sys 0.61.2", @@ -3381,6 +3546,18 @@ dependencies = [ "jni-sys 0.3.1", ] +[[package]] +name = "nix" +version = "0.31.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf20d2fde8ff38632c426f1165ed7436270b44f199fc55284c38276f9db47c3d" +dependencies = [ + "bitflags 2.13.2", + "cfg-if", + "cfg_aliases", + "libc", +] + [[package]] name = "nohash-hasher" version = "0.2.0" @@ -3511,9 +3688,9 @@ dependencies = [ [[package]] name = "objc2" -version = "0.6.4" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a12a8ed07aefc768292f076dc3ac8c48f3781c8f2d5851dd3d98950e8c5a89f" +checksum = "08849bbd4767dfae9457696856ae1c84fe4e0281bbe4a7abff2d0e06fb7981f8" dependencies = [ "objc2-encode", ] @@ -3542,7 +3719,7 @@ checksum = "d49e936b501e5c5bf01fda3a9452ff86dc3ea98ad5f283e1455153142d97518c" dependencies = [ "bitflags 2.13.2", "block2 0.6.2", - "objc2 0.6.4", + "objc2 0.6.5", "objc2-core-foundation", "objc2-core-graphics", "objc2-foundation 0.3.2", @@ -3556,7 +3733,7 @@ checksum = "6948501a91121d6399b79abaa33a8aa4ea7857fe019f341b8c23ad6e81b79b08" dependencies = [ "bitflags 2.13.2", "libc", - "objc2 0.6.4", + "objc2 0.6.5", "objc2-core-audio", "objc2-core-audio-types", "objc2-core-foundation", @@ -3594,7 +3771,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e1eebcea8b0dbff5f7c8504f3107c68fc061a3eb44932051c8cf8a68d969c3b2" dependencies = [ "dispatch2", - "objc2 0.6.4", + "objc2 0.6.5", "objc2-core-audio-types", "objc2-core-foundation", ] @@ -3606,7 +3783,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a89f2ec274a0cf4a32642b2991e8b351a404d290da87bb6a9a9d8632490bd1c" dependencies = [ "bitflags 2.13.2", - "objc2 0.6.4", + "objc2 0.6.5", ] [[package]] @@ -3629,7 +3806,7 @@ checksum = "2a180dd8642fa45cdb7dd721cd4c11b1cadd4929ce112ebd8b9f5803cc79d536" dependencies = [ "bitflags 2.13.2", "dispatch2", - "objc2 0.6.4", + "objc2 0.6.5", ] [[package]] @@ -3640,7 +3817,7 @@ checksum = "e022c9d066895efa1345f8e33e584b9f958da2fd4cd116792e15e07e4720a807" dependencies = [ "bitflags 2.13.2", "dispatch2", - "objc2 0.6.4", + "objc2 0.6.5", "objc2-core-foundation", "objc2-io-surface", ] @@ -3696,7 +3873,7 @@ checksum = "e3e0adef53c21f888deb4fa59fc59f7eb17404926ee8a6f59f5df0fd7f9f3272" dependencies = [ "bitflags 2.13.2", "block2 0.6.2", - "objc2 0.6.4", + "objc2 0.6.5", "objc2-core-foundation", ] @@ -3707,7 +3884,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "180788110936d59bab6bd83b6060ffdfffb3b922ba1396b312ae795e1de9d81d" dependencies = [ "bitflags 2.13.2", - "objc2 0.6.4", + "objc2 0.6.5", "objc2-core-foundation", ] @@ -3743,7 +3920,7 @@ checksum = "a0125f776a10d00af4152d74616409f0d4a2053a6f57fa5b7d6aa2854ac04794" dependencies = [ "bitflags 2.13.2", "block2 0.6.2", - "objc2 0.6.4", + "objc2 0.6.5", "objc2-foundation 0.3.2", ] @@ -3767,7 +3944,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96c1358452b371bf9f104e21ec536d37a650eb10f7ee379fff67d2e08d537f1f" dependencies = [ "bitflags 2.13.2", - "objc2 0.6.4", + "objc2 0.6.5", "objc2-core-foundation", "objc2-core-graphics", "objc2-foundation 0.3.2", @@ -3812,7 +3989,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d87d638e33c06f577498cbcc50491496a3ed4246998a7fbba7ccb98b1e7eab22" dependencies = [ "bitflags 2.13.2", - "objc2 0.6.4", + "objc2 0.6.5", "objc2-core-foundation", "objc2-foundation 0.3.2", ] @@ -3859,6 +4036,12 @@ version = "11.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6790f58c7ff633d8771f42965289203411a5e5c68388703c06e14f24770b41e" +[[package]] +name = "openssl-probe" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe" + [[package]] name = "orbclient" version = "0.3.55" @@ -3895,7 +4078,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d8fae84b431384b68627d0f9b3b1245fcf9f46f6c0e3dc902e9dce64edd1967" dependencies = [ "libc", - "windows-sys 0.61.2", + "windows-sys 0.45.0", ] [[package]] @@ -4061,6 +4244,19 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" +[[package]] +name = "plist" +version = "1.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327a4cb2ad49dc48adfdc9da89e22c64d488b508c67a044d71ba729e4521a285" +dependencies = [ + "base64", + "indexmap", + "quick-xml 0.42.0", + "serde", + "time", +] + [[package]] name = "png" version = "0.18.1" @@ -4139,15 +4335,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" -[[package]] -name = "ppv-lite86" -version = "0.2.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" -dependencies = [ - "zerocopy", -] - [[package]] name = "presser" version = "0.3.1" @@ -4180,16 +4367,17 @@ checksum = "3d595e54a326bc53c1c197b32d295e14b169e3cfeaa8dc82b529f947fba6bcf5" [[package]] name = "proptest" -version = "1.11.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b45fcc2344c680f5025fe57779faef368840d0bd1f42f216291f0dc4ace4744" +checksum = "b8530004ccb15eae51c7e40009fbe317f341f804db54dc033eec1c50be28cfa0" dependencies = [ - "bit-set 0.8.0", - "bit-vec 0.8.0", + "bit-set 0.11.1", + "bit-vec 0.10.1", "bitflags 2.13.2", + "chacha20", + "core_detect", "num-traits", - "rand 0.9.5", - "rand_chacha", + "rand", "rand_xorshift", "regex-syntax", "rusty-fork", @@ -4247,6 +4435,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "quick-xml" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41b1177fdf999d2321d3fb46ff47159d9c1fb9ad66a4879f8c50a0b504615e9b" +dependencies = [ + "memchr", +] + [[package]] name = "quote" version = "1.0.47" @@ -4268,16 +4465,6 @@ version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" -[[package]] -name = "rand" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9ef1d0d795eb7d84685bca4f72f3649f064e6641543d3a8c415898726a57b41" -dependencies = [ - "rand_chacha", - "rand_core 0.9.5", -] - [[package]] name = "rand" version = "0.10.3" @@ -4286,26 +4473,7 @@ checksum = "65c9fb96cbc91e3478eaae79a69fcd3f1ae4ad052e471fe6732fff548984b4af" dependencies = [ "chacha20", "getrandom 0.4.3", - "rand_core 0.10.1", -] - -[[package]] -name = "rand_chacha" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" -dependencies = [ - "ppv-lite86", - "rand_core 0.9.5", -] - -[[package]] -name = "rand_core" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c" -dependencies = [ - "getrandom 0.3.4", + "rand_core", ] [[package]] @@ -4316,11 +4484,11 @@ checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69" [[package]] name = "rand_xorshift" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "513962919efc330f829edb2535844d1b912b0fbe2ca165d613e4e8788bb05a5a" +checksum = "60aa6af80be32871323012e02e6e65f8a7cc7890931ae421d217ad8fe0df2ccf" dependencies = [ - "rand_core 0.9.5", + "rand_core", ] [[package]] @@ -4350,7 +4518,7 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40d213455a5f1dc59214213c7330e074ddf8114c9a42411eb890c767357ce135" dependencies = [ - "objc2 0.6.4", + "objc2 0.6.5", "objc2-core-foundation", "objc2-foundation 0.3.2", "objc2-quartz-core 0.3.2", @@ -4458,7 +4626,7 @@ dependencies = [ "js-sys", "libc", "log", - "objc2 0.6.4", + "objc2 0.6.5", "objc2-app-kit 0.3.2", "objc2-core-foundation", "objc2-foundation 0.3.2", @@ -4474,6 +4642,20 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.17", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + [[package]] name = "roxmltree" version = "0.21.1" @@ -4530,6 +4712,80 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "rustls" +version = "0.23.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e13bd8c0e9365c43cfa5c9e8f9ad49d3c8444926c9aac819e0e4dc503c8fdf" +dependencies = [ + "log", + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-native-certs" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a073f5dc7469f984c52ad2752b63b0807745133b6de880b7b64c1ac4c48aec4" +dependencies = [ + "openssl-probe", + "rustls-pki-types", + "schannel", + "security-framework", +] + +[[package]] +name = "rustls-pki-types" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f4925028c7eb5d1fcdaf196971378ed9d2c1c4efc7dc5d011256f76c99c0a96" +dependencies = [ + "zeroize", +] + +[[package]] +name = "rustls-platform-verifier" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1167586491e2b18b8bfbb293e8180ec17c201c4f076d7cb3070ca964e7598f98" +dependencies = [ + "core-foundation 0.10.1", + "core-foundation-sys", + "jni 0.22.4", + "log", + "once_cell", + "rustls", + "rustls-native-certs", + "rustls-platform-verifier-android", + "rustls-webpki", + "security-framework", + "security-framework-sys", + "webpki-root-certs", + "windows-sys 0.61.2", +] + +[[package]] +name = "rustls-platform-verifier-android" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eec689c0bc40ff2458a5977b6619cb718087084a18e02a131c599b62d05e1a5f" + +[[package]] +name = "rustls-webpki" +version = "0.103.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4443b1b6d39d7c663139942cc4558262562d2c84123bb6282ef177009ca8b281" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + [[package]] name = "rustversion" version = "1.0.23" @@ -4563,6 +4819,15 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "schannel" +version = "0.1.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9cb23c424d8ee841bb4d813677ca237e2a610067d594fec130f87d6093495ab5" +dependencies = [ + "windows-sys 0.61.2", +] + [[package]] name = "scoped-tls" version = "1.0.1" @@ -4575,6 +4840,29 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "security-framework" +version = "3.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7f4bc775c73d9a02cde8bf7b2ec4c9d12743edf609006c7facc23998404cd1d" +dependencies = [ + "bitflags 2.13.2", + "core-foundation 0.10.1", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2691df843ecc5d231c0b14ece2acc3efb62c0a398c7e1d875f3983ce020e3" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "self_cell" version = "1.3.0" @@ -4586,6 +4874,10 @@ name = "semver" version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" +dependencies = [ + "serde", + "serde_core", +] [[package]] name = "send_wrapper" @@ -4625,9 +4917,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.151" +version = "1.0.154" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c841b55ecdae098c80dcae9cf767f6f8a0c2cdb3416bbef72181df4d0fe73f14" +checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6" dependencies = [ "itoa", "memchr", @@ -4656,6 +4948,17 @@ dependencies = [ "serde_core", ] +[[package]] +name = "sha2" +version = "0.10.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" +dependencies = [ + "cfg-if", + "cpufeatures 0.2.17", + "digest", +] + [[package]] name = "shlex" version = "2.0.1" @@ -4900,6 +5203,12 @@ dependencies = [ "syn 2.0.119", ] +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + [[package]] name = "symphonia" version = "0.5.5" @@ -5112,6 +5421,16 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" +[[package]] +name = "tar" +version = "0.4.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f6221d9a6003c78398e3b239969f352578258df48c8eb051caadae0015bc840" +dependencies = [ + "filetime", + "libc", +] + [[package]] name = "tempfile" version = "3.27.0" @@ -5380,6 +5699,18 @@ dependencies = [ "rustc-hash 2.1.3", ] +[[package]] +name = "typed-path" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce898823d8cd0f028662d2f349694b1af0a5cc9be83f1d213a00d3147445e1e" + +[[package]] +name = "typenum" +version = "1.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" + [[package]] name = "uds_windows" version = "1.2.1" @@ -5448,6 +5779,41 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254" +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "ureq" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cde93ff05758a36a851a398a772b0b79a82fbe3c186a46f2696baaeaf84c966b" +dependencies = [ + "base64", + "flate2", + "log", + "percent-encoding", + "rustls", + "rustls-pki-types", + "rustls-platform-verifier", + "ureq-proto", + "utf8-zero", +] + +[[package]] +name = "ureq-proto" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841583fc36089d7d59419568ae157f43a5a03a2e5a81ba87c77d1596ef46e922" +dependencies = [ + "base64", + "http", + "httparse", + "log", +] + [[package]] name = "url" version = "2.5.8" @@ -5466,6 +5832,12 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246" +[[package]] +name = "utf8-zero" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8c0a043c9540bae7c578c88f91dda8bd82e59ae27c21baca69c8b191aaf5a6e" + [[package]] name = "utf8_iter" version = "1.0.4" @@ -5510,6 +5882,16 @@ dependencies = [ "vello_common", ] +[[package]] +name = "verifysign" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6acfcc42a8d44f340d001193d97ef56bf33210b51ad760ae8308c97d5241ca51" +dependencies = [ + "core-foundation 0.10.1", + "windows-sys 0.61.2", +] + [[package]] name = "version_check" version = "0.9.5" @@ -5535,6 +5917,12 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + [[package]] name = "wasip2" version = "1.0.4+wasi-0.2.12" @@ -5851,7 +6239,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "338e30461b3a2b67d70eb30a6d89f8e0c93a833e07d2ae89085cd070c4a00ac0" dependencies = [ "proc-macro2", - "quick-xml", + "quick-xml 0.41.0", "quote", ] @@ -5896,13 +6284,22 @@ dependencies = [ "jni 0.22.4", "log", "ndk-context", - "objc2 0.6.4", + "objc2 0.6.5", "objc2-app-kit 0.3.2", "objc2-foundation 0.3.2", "url", "web-sys", ] +[[package]] +name = "webpki-root-certs" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e49d0e65abc00c142e8f9428da991da9f1a250c39be97459901eb12b9b49f62a" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "weezl" version = "0.1.12" @@ -6037,7 +6434,7 @@ dependencies = [ "naga", "naga-types", "ndk-sys", - "objc2 0.6.4", + "objc2 0.6.5", "objc2-core-foundation", "objc2-core-graphics", "objc2-foundation 0.3.2", @@ -6280,15 +6677,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.60.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" -dependencies = [ - "windows-targets 0.53.5", -] - [[package]] name = "windows-sys" version = "0.61.2" @@ -6322,30 +6710,13 @@ dependencies = [ "windows_aarch64_gnullvm 0.52.6", "windows_aarch64_msvc 0.52.6", "windows_i686_gnu 0.52.6", - "windows_i686_gnullvm 0.52.6", + "windows_i686_gnullvm", "windows_i686_msvc 0.52.6", "windows_x86_64_gnu 0.52.6", "windows_x86_64_gnullvm 0.52.6", "windows_x86_64_msvc 0.52.6", ] -[[package]] -name = "windows-targets" -version = "0.53.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" -dependencies = [ - "windows-link", - "windows_aarch64_gnullvm 0.53.1", - "windows_aarch64_msvc 0.53.1", - "windows_i686_gnu 0.53.1", - "windows_i686_gnullvm 0.53.1", - "windows_i686_msvc 0.53.1", - "windows_x86_64_gnu 0.53.1", - "windows_x86_64_gnullvm 0.53.1", - "windows_x86_64_msvc 0.53.1", -] - [[package]] name = "windows-threading" version = "0.2.1" @@ -6367,12 +6738,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" - [[package]] name = "windows_aarch64_msvc" version = "0.42.2" @@ -6385,12 +6750,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" -[[package]] -name = "windows_aarch64_msvc" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" - [[package]] name = "windows_i686_gnu" version = "0.42.2" @@ -6403,24 +6762,12 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" -[[package]] -name = "windows_i686_gnu" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" - [[package]] name = "windows_i686_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" -[[package]] -name = "windows_i686_gnullvm" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" - [[package]] name = "windows_i686_msvc" version = "0.42.2" @@ -6433,12 +6780,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" -[[package]] -name = "windows_i686_msvc" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" - [[package]] name = "windows_x86_64_gnu" version = "0.42.2" @@ -6451,12 +6792,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" -[[package]] -name = "windows_x86_64_gnu" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" - [[package]] name = "windows_x86_64_gnullvm" version = "0.42.2" @@ -6469,12 +6804,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" - [[package]] name = "windows_x86_64_msvc" version = "0.42.2" @@ -6487,12 +6816,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" -[[package]] -name = "windows_x86_64_msvc" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" - [[package]] name = "winit" version = "0.30.13" @@ -6507,7 +6830,7 @@ dependencies = [ "calloop 0.13.0", "cfg_aliases", "concurrent-queue", - "core-foundation", + "core-foundation 0.9.4", "core-graphics", "cursor-icon", "dpi", @@ -6553,15 +6876,31 @@ dependencies = [ ] [[package]] -name = "winresource" -version = "0.1.31" +name = "winreg" +version = "0.55.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0986a8b1d586b7d3e4fe3d9ea39fb451ae22869dcea4aa109d287a374d866087" +checksum = "cb5a765337c50e9ec252c2069be9bf91c7df47afb103b642ba3a53bf8101be97" +dependencies = [ + "cfg-if", + "windows-sys 0.59.0", +] + +[[package]] +name = "winresource" +version = "0.1.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2bc6d36480b829272a5bdabf08e6dca8004761c1da7e35efef800540c66221b" dependencies = [ "toml", "version_check", ] +[[package]] +name = "winsafe" +version = "0.0.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ef0ffc427f045c0cc9ebffd6f4f91153dcd2a1547b5c3c29ee3f541e16e95c6" + [[package]] name = "wit-bindgen" version = "0.57.1" @@ -6840,6 +7179,12 @@ dependencies = [ "synstructure", ] +[[package]] +name = "zeroize" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13084392c5e4bc371903e2935a5eaeed24905a7511356b883835e18a78f6879" + [[package]] name = "zerotrie" version = "0.2.5" @@ -6873,6 +7218,23 @@ dependencies = [ "syn 3.0.6", ] +[[package]] +name = "zip" +version = "9.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2886b00003a72c4ccee3f42cfc34908d33b2508a74d827dc2a4244706475c704" +dependencies = [ + "crc32fast", + "flate2", + "getrandom 0.4.3", + "indexmap", + "memchr", + "nix", + "typed-path", + "windows-sys 0.61.2", + "zopfli", +] + [[package]] name = "zlib-rs" version = "0.6.8" @@ -6885,6 +7247,18 @@ version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" +[[package]] +name = "zopfli" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aaf7fc5d30c28483d93805c4a5e12b05bbb52407fa67c5f8bd552374cd01fb11" +dependencies = [ + "bumpalo", + "crc32fast", + "log", + "simd-adler32", +] + [[package]] name = "zune-core" version = "0.5.3" diff --git a/Cargo.toml b/Cargo.toml index 598a156a8..fe6d2ddcc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,8 +11,9 @@ rust-version = "1.95" repository = "https://github.com/storytold/effectcraft" [workspace.dependencies] -craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "9f75d3dc19b4b514c4f3d4847ed1ec1b0e86b4ef", version = "=0.1.0", default-features = false, features = ["read"] } -craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "82a24b006eefa036b43c09a67fb9a3fbd17ffe63" } +craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "512b54355cd1418f4e8c56a3fbd7483c3c274bf3", version = "=0.1.0", default-features = false, features = ["read"] } +craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "512b54355cd1418f4e8c56a3fbd7483c3c274bf3" } +craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "512b54355cd1418f4e8c56a3fbd7483c3c274bf3", features = ["egui"] } # internal effectcraft-time = { path = "crates/time" } effectcraft-geom = { path = "crates/geom" } @@ -102,12 +103,12 @@ symphonia = { version = "0.5.5", default-features = false, features = ["aiff"] } # gpu (the same wgpu eframe / egui-wgpu use) wgpu = { version = "30.0.1", features = ["fragile-send-sync-non-atomic-wasm"] } bytemuck = "1" -pollster = "0.4" +pollster = "1" # 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 = "25da1314d443171b4adeaad2cd9454b273f35c6f", features = ["serde"] } +craft-ui = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "512b54355cd1418f4e8c56a3fbd7483c3c274bf3", features = ["serde"] } # `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"] } @@ -219,8 +220,8 @@ lto = "thin" codegen-units = 1 [patch.crates-io] -hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "9f75d3dc19b4b514c4f3d4847ed1ec1b0e86b4ef", version = "=0.7.2" } -hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "9f75d3dc19b4b514c4f3d4847ed1ec1b0e86b4ef", version = "=0.3.0" } +hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "512b54355cd1418f4e8c56a3fbd7483c3c274bf3", version = "=0.7.2" } +hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "512b54355cd1418f4e8c56a3fbd7483c3c274bf3", 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" } diff --git a/apps/effectcraft-web/js/host.js b/apps/effectcraft-web/js/host.js index 12cb90bfa..9346acc29 100644 --- a/apps/effectcraft-web/js/host.js +++ b/apps/effectcraft-web/js/host.js @@ -19,7 +19,7 @@ const enc = (k) => encodeURIComponent(k); const dec = (n) => decodeURIComponent(n); async function opfs() { - if (!navigator.storage || !navigator.storage.getDirectory) throw new Error("no OPFS"); + if (!navigator.storage?.getDirectory) throw new Error("no OPFS"); const root = await navigator.storage.getDirectory(); const dir = await root.getDirectoryHandle(DIR, { create: true }); // Probe a write: some browsers expose OPFS but only write it from workers. @@ -116,7 +116,7 @@ export async function storeOpen(prefer) { try { backend = await make(); break; } catch (e) { console.info(`storage: ${make.name}: ${e.message ?? e}`); } } // Ask the browser not to evict the store under storage pressure (granted for installed apps). - try { if (navigator.storage && navigator.storage.persist) await navigator.storage.persist(); } catch {} + try { if (navigator.storage?.persist) await navigator.storage.persist(); } catch {} return backend.name; } @@ -128,7 +128,7 @@ export async function storeDelete(key) { return backend.del(key); } /// Ask the browser to keep the origin's storage under pressure; resolves with whether it is. export async function storePersist() { try { - if (navigator.storage && navigator.storage.persist) return await navigator.storage.persist(); + if (navigator.storage?.persist) return await navigator.storage.persist(); } catch {} return false; } @@ -227,7 +227,7 @@ export async function audioStart(workletUrl) { } if (gen !== generation) return; node = new AudioWorkletNode(c, "effectcraft-output", { numberOfInputs: 0, outputChannelCount: [2] }); - node.port.onmessage = (e) => { if (e.data && e.data.underrun) underruns += e.data.underrun; }; + node.port.onmessage = (e) => { if (e.data?.underrun) underruns += e.data.underrun; }; kind = "worklet"; } catch (e) { console.warn("audio: AudioWorklet unavailable, using ScriptProcessorNode", e); @@ -318,11 +318,11 @@ function spawn(base) { const w = { worker, files: new Map(), ready: null, gpu: null }; w.ready = new Promise((res, rej) => { worker.onmessage = (e) => { - if (e.data && e.data.type === "gpu") { + if (e.data?.type === "gpu") { w.gpu = e.data.gpu ? { adapter: e.data.gpu } : { cpu: e.data.error || "no GPU" }; jobGpu = w.gpu; } - if (e.data && e.data.type === "ready") res(); + if (e.data?.type === "ready") res(); }; worker.onerror = (e) => rej(new Error(e.message || "worker failed to start")); }); @@ -341,7 +341,7 @@ export function workerRun(id, json, files, base, onMessage) { } catch (e) { // `new Worker` throws at once when the page's origin is opaque (a sandboxed iframe): the job // fails like one whose worker didn't start. - setTimeout(() => onMessage("error", String((e && e.message) || e), null, null)); + setTimeout(() => onMessage("error", String(e?.message || e), null, null)); return; } running.set(id, w); @@ -416,12 +416,12 @@ export function frameWorkerStart(base, onMessage, gpu) { // slot stays, and the failure is reported like a worker that died, after the caller has // recorded the index: frames then render on the page's thread (as with `?noworkers`). frameWorkers.push(null); - setTimeout(() => onMessage(index, undefined, undefined, String((e && e.message) || e || "frame worker failed"))); + setTimeout(() => onMessage(index, undefined, undefined, String(e?.message || e || "frame worker failed"))); return index; } worker.onmessage = (e) => { const m = e.data; - if (m && m.type === "frameReply") onMessage(index, m.json, m.bytes ? new Uint8Array(m.bytes) : null, undefined); + if (m?.type === "frameReply") onMessage(index, m.json, m.bytes ? new Uint8Array(m.bytes) : null, undefined); }; worker.onerror = (e) => { onMessage(index, undefined, undefined, String(e.message || "frame worker failed")); @@ -447,7 +447,7 @@ const cacheDirHandles = {}; async function cacheDir(kind = "frames") { if (cacheDirHandles[kind]) return cacheDirHandles[kind]; - if (!navigator.storage || !navigator.storage.getDirectory) throw new Error("no Origin Private File System"); + if (!navigator.storage?.getDirectory) throw new Error("no Origin Private File System"); let d = await navigator.storage.getDirectory(); for (const n of [CACHE_ROOT, "v1", kind]) d = await d.getDirectoryHandle(n, { create: true }); cacheDirHandles[kind] = d; @@ -544,7 +544,7 @@ export async function cacheClear() { /// Whether this thread has WebGPU (`navigator.gpu`). export function hasWebGpu() { - return !!(self.navigator && self.navigator.gpu); + return !!self.navigator?.gpu; } /// Post a message ({type: "frame", json} or {type: "file", path, bytes}) to frame worker `index`. @@ -652,7 +652,7 @@ export async function browseForget(name) { export async function browseRead(path) { const rel = path.replace(/^\/Folders\//, ""); const folder = folders.get(rel.split("/")[0]); - const h = folder && folder.files.get(rel); + const h = folder?.files.get(rel); if (!h) throw new Error(`${path}: its folder is not open (reconnect it)`); return new Uint8Array(await (await h.getFile()).arrayBuffer()); } @@ -706,7 +706,7 @@ export function showDeviceLost(message, kept) { self.effectcraft .execute("file.save", {}) .catch(() => self.effectcraft.execute("file.saveAs", { path: "/Untitled Project.ecproj" })) - .catch((e) => (text.textContent = `Saving failed: ${(e && e.message) || e}`)); + .catch((e) => (text.textContent = `Saving failed: ${e?.message || e}`)); const reload = document.createElement("button"); reload.textContent = "Reload"; reload.onclick = async () => { @@ -714,7 +714,7 @@ export function showDeviceLost(message, kept) { try { await self.effectcraft.flush(); } catch (e) { - text.textContent = `Writing to browser storage failed (${(e && e.message) || e}). Save the project, or reload anyway and lose the changes.`; + text.textContent = `Writing to browser storage failed (${e?.message || e}). Save the project, or reload anyway and lose the changes.`; reload.textContent = "Reload Anyway"; reload.disabled = false; reload.onclick = () => location.reload(); diff --git a/apps/effectcraft-web/src/browse.rs b/apps/effectcraft-web/src/browse.rs index ad7500fea..2fd680dcb 100644 --- a/apps/effectcraft-web/src/browse.rs +++ b/apps/effectcraft-web/src/browse.rs @@ -52,7 +52,7 @@ struct State { static STATE: LazyLock> = LazyLock::new(Mutex::default); fn state() -> std::sync::MutexGuard<'static, State> { - STATE.lock().unwrap_or_else(|e| e.into_inner()) + STATE.lock().unwrap_or_else(std::sync::PoisonError::into_inner) } /// The web app's Media Browser. diff --git a/apps/effectcraft-web/src/files.rs b/apps/effectcraft-web/src/files.rs index 3f3f3a99f..206314e4b 100644 --- a/apps/effectcraft-web/src/files.rs +++ b/apps/effectcraft-web/src/files.rs @@ -48,14 +48,14 @@ pub fn list() -> Vec<(String, usize)> { /// The next write of `path` goes to browser storage only (no download). pub fn save_quietly(path: &str) { - QUIET.lock().unwrap_or_else(|e| e.into_inner()).push(path.to_string()); + QUIET.lock().unwrap_or_else(std::sync::PoisonError::into_inner).push(path.to_string()); } /// A rendered file (from the page's exporter or a worker): kept in the table unpersisted and /// downloaded at the next [`flush_downloads`]. pub fn add_output(path: &str, data: Arc<[u8]>) { STORE.put_file(path, data, false); - OUTPUTS.lock().unwrap_or_else(|e| e.into_inner()).push(path.to_string()); + OUTPUTS.lock().unwrap_or_else(std::sync::PoisonError::into_inner).push(path.to_string()); } /// The table path for a picked/dropped file name. @@ -120,7 +120,7 @@ impl Services for WebServices { fn write_file(&self, path: &str, data: &[u8]) -> std::io::Result<()> { put(path, data.into()); let quiet = { - let mut q = QUIET.lock().unwrap_or_else(|e| e.into_inner()); + let mut q = QUIET.lock().unwrap_or_else(std::sync::PoisonError::into_inner); let n = q.len(); q.retain(|p| p != path); q.len() != n @@ -184,7 +184,7 @@ pub fn export_sink() -> Arc { /// Download the render outputs written since the last call. pub fn flush_downloads() { - let paths = std::mem::take(&mut *OUTPUTS.lock().unwrap_or_else(|e| e.into_inner())); + let paths = std::mem::take(&mut *OUTPUTS.lock().unwrap_or_else(std::sync::PoisonError::into_inner)); let mut out: Vec<(String, Arc<[u8]>)> = paths.into_iter().filter_map(|p| get(&p).map(|d| (file_name(&p).to_string(), d))).collect(); out.sort_by(|a, b| a.0.cmp(&b.0)); out.dedup_by(|a, b| a.0 == b.0); diff --git a/apps/effectcraft-web/src/lib.rs b/apps/effectcraft-web/src/lib.rs index 0d59906f2..97d2e887f 100644 --- a/apps/effectcraft-web/src/lib.rs +++ b/apps/effectcraft-web/src/lib.rs @@ -6,17 +6,17 @@ //! //! | Desktop | Web | //! |---|---| -//! | file system (`FsServices`, media reads, export writes) | a virtual file table ([`files`]) persisted to the Origin Private File System / IndexedDB ([`persist`], [`store`]) | +//! | file system (`FsServices`, media reads, export writes) | a virtual file table (`files`) persisted to the Origin Private File System / IndexedDB (`persist`, [`store`]) | //! | config directory (settings, shortcuts, recent projects, auto-saves) | the same store ([`store::WebConfig`]) | //! | rfd file dialogs | `` pickers; drop files on the page | -//! | Media Browser on the file system | browser storage and folders opened with the File System Access API ([`browse`]) | +//! | Media Browser on the file system | browser storage and folders opened with the File System Access API (`browse`) | //! | written files (Save, Render Queue) | browser downloads (several render files as one `.zip`) | -//! | frame render threads | frame workers, each with a project replica fed by diffs and its own WebGPU device ([`frames`]); `Frames::pump` on the UI thread without workers | -//! | disk cache folder | frames in the Origin Private File System, written by the frame workers ([`diskcache`]) | -//! | (none) | the storage manager: usage, quota, persistence, clearing ([`storage`]) | -//! | Render Queue / analysis threads | Web Workers running their own engine instance ([`worker`]) | -//! | cpal audio output | Web Audio: an AudioWorklet fed from the preview mixdown ([`audio`]) | -//! | TCP control channel / MCP | `window.effectcraft` JavaScript API ([`api`]) | +//! | frame render threads | frame workers, each with a project replica fed by diffs and its own WebGPU device (`frames`); `Frames::pump` on the UI thread without workers | +//! | disk cache folder | frames in the Origin Private File System, written by the frame workers (`diskcache`) | +//! | (none) | the storage manager: usage, quota, persistence, clearing (`storage`) | +//! | Render Queue / analysis threads | Web Workers running their own engine instance (`worker`) | +//! | cpal audio output | Web Audio: an AudioWorklet fed from the preview mixdown (`audio`) | +//! | TCP control channel / MCP | `window.effectcraft` JavaScript API (`api`) | //! //! [`store`] is portable (unit-tested natively); everything else is `wasm32`-only. diff --git a/apps/effectcraft-web/src/store.rs b/apps/effectcraft-web/src/store.rs index a44a2eac7..8aafdac1c 100644 --- a/apps/effectcraft-web/src/store.rs +++ b/apps/effectcraft-web/src/store.rs @@ -181,7 +181,7 @@ impl Default for Store { impl Store { pub fn lock(&self) -> std::sync::MutexGuard<'_, Mirror> { - self.mirror.lock().unwrap_or_else(|e| e.into_inner()) + self.mirror.lock().unwrap_or_else(std::sync::PoisonError::into_inner) } fn now(&self) -> f64 { diff --git a/apps/effectcraft-web/tests/smoke.mjs b/apps/effectcraft-web/tests/smoke.mjs index 3a6c1337c..83091a72a 100644 --- a/apps/effectcraft-web/tests/smoke.mjs +++ b/apps/effectcraft-web/tests/smoke.mjs @@ -162,7 +162,7 @@ try { const info = await js("effectcraft.info()"); report.steps.gpu = { webgpu: info.webgpu, backend: info.backend, ...info.gpu }; if (info.webgpu && info.backend === "BrowserWebGpu") { - check(info.gpu && info.gpu.compositor, "GPU compositor on WebGPU"); + check(info.gpu?.compositor, "GPU compositor on WebGPU"); check(info.gpu.viewerOnGpu, "viewer frames on the GPU"); } @@ -250,7 +250,7 @@ try { const st = await js(`(async () => { await new Promise((r) => setTimeout(r, 1200)); return effectcraft.execute("storage.info", {}); })()`); report.steps.storage = st; check(st.available && st.quota > 0 && st.usage > 0, `storage.info: ${JSON.stringify(st)}`); - check(st.diskCache && st.diskCache.enabled && st.diskCache.writes > 0, `disk cache in OPFS: ${JSON.stringify(st.diskCache)}`); + check(st.diskCache?.enabled && st.diskCache.writes > 0, `disk cache in OPFS: ${JSON.stringify(st.diskCache)}`); await js(`effectcraft.execute("prefs.open", {page: "disk"})`); await sleep(800); report.steps.storage.screenshot = await shot("01c-storage-manager"); @@ -378,14 +378,14 @@ try { const jobs = gj.workers.jobs || []; const rj = jobs.filter((j) => j.kind === "Render").pop(); const wj = jobs.filter((j) => j.kind === "Warp").pop(); - check(gj.workers.gpu && gj.workers.gpu.adapter, `job workers have a GPU: ${JSON.stringify(gj.workers)}`); + check(gj.workers.gpu?.adapter, `job workers have a GPU: ${JSON.stringify(gj.workers)}`); check(gj.status.every((st) => st === "Done"), `GPU job render: ${JSON.stringify(gj.status)}`); - check(rj && rj.gpu && rj.readbacks >= 3 && rj.passes >= 6, `Render Queue frames on the job worker's GPU, in passes: ${JSON.stringify(rj)}`); + check(rj?.gpu && rj.readbacks >= 3 && rj.passes >= 6, `Render Queue frames on the job worker's GPU, in passes: ${JSON.stringify(rj)}`); check(gj.warp.analyzed, `Warp Stabilizer analysed in a job worker: ${JSON.stringify(gj.warp)}`); - check(wj && wj.gpu && wj.readbacks > 0, `Warp Stabilizer input frames on the job worker's GPU: ${JSON.stringify(wj)}`); + check(wj?.gpu && wj.readbacks > 0, `Warp Stabilizer input frames on the job worker's GPU: ${JSON.stringify(wj)}`); const fj = jobs.filter((j) => j.kind === "ContentFill").pop(); check(!gj.fill.error && gj.fillLayers.length > 0, `Content-Aware Fill in a job worker: ${JSON.stringify(gj.fill)} ${JSON.stringify(gj.fillLayers)}`); - check(fj && fj.gpu && fj.readbacks > 0, `Content-Aware Fill frames on the job worker's GPU: ${JSON.stringify(fj)}`); + check(fj?.gpu && fj.readbacks > 0, `Content-Aware Fill frames on the job worker's GPU: ${JSON.stringify(fj)}`); check(gj.maxGapMs < 400, `event loop blocked ${gj.maxGapMs} ms during the GPU jobs: ${JSON.stringify(gj.gaps)}`); check(gj.gaps.prepareFill < 50, `event loop blocked ${gj.gaps.prepareFill} ms while editing after the analysis (pre-compose, mask): ${JSON.stringify(gj.gaps)}`); } else { @@ -418,7 +418,7 @@ try { check(mb.path === "/Browser Storage" && mb.entries.some((e) => e.name === "tone.wav" && e.kind === "audio"), `Media Browser: ${JSON.stringify(report.steps.mediaBrowser)}`); check(mb.actions.some((a) => a.id === "addFiles"), "Media Browser: Add Files…"); const mbImport = await js(`effectcraft.execute("mediaBrowser.import", {paths: [${JSON.stringify(mb.entries.find((e) => e.name === "tone.wav")?.path ?? "/tone.wav")}]})`); - check(!mbImport.pending && mbImport.items && mbImport.items.length === 1, `Media Browser import: ${JSON.stringify(mbImport)}`); + check(!mbImport.pending && mbImport.items?.length === 1, `Media Browser import: ${JSON.stringify(mbImport)}`); await js(`effectcraft.request("ui.playback", {action: "stop"})`); await js(`effectcraft.execute("time.set", {time: 0})`); await js(`effectcraft.request("ui.playback", {action: "play"})`); @@ -579,7 +579,7 @@ try { report.steps.final2 = { screenshot: await shot("03-offline") }; } catch (e) { failed = true; - report.error = String(e && e.stack || e); + report.error = String(e?.stack || e); try { report.errorShot = await shot("error"); } catch {} } report.console = logs.slice(-40); diff --git a/apps/effectcraft/Cargo.toml b/apps/effectcraft/Cargo.toml index 8a1ea3ae3..e09e7d8b2 100644 --- a/apps/effectcraft/Cargo.toml +++ b/apps/effectcraft/Cargo.toml @@ -48,3 +48,6 @@ objc2-app-kit = { version = "0.3", default-features = false, features = ["std", # PhotoCraft and PdfCraft) registers the handler (Objective-C interop needs unsafe, which our # workspace forbids) behind a safe API. Pinned exactly: review the diff before bumping. fmv-macos-events = "=0.1.0" + +[target.'cfg(windows)'.dependencies] +craft-update = { workspace = true } diff --git a/apps/effectcraft/src/main.rs b/apps/effectcraft/src/main.rs index ccd46951a..6df015290 100644 --- a/apps/effectcraft/src/main.rs +++ b/apps/effectcraft/src/main.rs @@ -50,7 +50,7 @@ fn app_icon() -> egui::IconData { fn is_project_file(path: &str) -> bool { std::path::Path::new(path) .extension() - .and_then(|ext| ext.to_str()) + .and_then(std::ffi::OsStr::to_str) .is_some_and(|ext| ext.eq_ignore_ascii_case("ecproj") || ext.eq_ignore_ascii_case("ecprojx")) } @@ -128,14 +128,24 @@ fn control_port(name: &str, value: Option<&str>) -> Result { /// answer without pumping events, so the window stops answering the compositor and the desktop /// offers to force-quit it while the Open dialog is up (#1275). Windows' blocking dialog pumps /// its own messages, so it keeps [`effectcraft_ui_egui::Hooks::pick_files`] and friends. -fn install_file_dialogs(app: &mut EffectcraftApp, ctx: &egui::Context) { +/// The dialogs asked for in a frame show at its end ([`sheet_dialogs::show_asked`]), where the +/// main window's handle is at hand. +fn install_file_dialogs(app: &mut EffectcraftApp) -> Option> { #[cfg(any(target_os = "macos", target_os = "linux"))] { - let ctx = ctx.clone(); - app.hooks.file_dialog_async = Some(Box::new(move |dialog, done| sheet_dialogs::show(dialog, done, ctx.clone()))); + let (tx, rx) = std::sync::mpsc::channel::(); + app.hooks.file_dialog_async = Some(Box::new(move |dialog, done| { + if tx.send((dialog, done)).is_err() { + log::error!("file dialog: the window is gone"); + } + })); + Some(rx) } #[cfg(not(any(target_os = "macos", target_os = "linux")))] - let _ = (app, ctx); + { + let _ = app; + None + } } /// Run a normal desktop launch: install logging and the panic hook, parse arguments (`--version` exits before the @@ -143,6 +153,11 @@ fn install_file_dialogs(app: &mut EffectcraftApp, ctx: &egui::Context) { /// Builds the session, loads settings, plugins, the requested project/media and the optional control server, then /// reports startup failure through `startup_failed`. Returns the event loop's result. fn main() -> eframe::Result { + // Windows: the update helper is a copy of this program started with `--finish-update`. + #[cfg(windows)] + if let Some(result) = craft_update::self_update::finish(&craft_update::suite::EFFECTCRAFT, &std::env::args_os().skip(1).collect::>()) { + std::process::exit(i32::from(result.is_err())); + } // First, so the panic hook and every start-up warning are recorded. Records go to stderr // and the session log; Help ▸ Enable Logging writes through this logger too, and warnings // feed the compatibility report. @@ -268,6 +283,7 @@ fn main() -> eframe::Result { // reported in a toast and forgotten). let _ = session.execute("window.restoreScriptPanels", json!({})); let mut app = EffectcraftApp::new(session); + app.set_startup_update_check(true); app.set_gpu_failure_bridge(gpu_failures); app.ui.start_screen = show_home; if let Some(n) = notice { @@ -324,7 +340,7 @@ fn main() -> eframe::Result { })); // The commands' file dialogs don't block the frame where the platform's backend // would (#511, #1275); see [`install_file_dialogs`]. - install_file_dialogs(&mut app, &cc.egui_ctx); + let file_dialogs = install_file_dialogs(&mut app); #[cfg(target_os = "macos")] { app.hooks.app_action = Some(Box::new(native_menu::app_action)); @@ -342,6 +358,7 @@ fn main() -> eframe::Result { #[cfg(target_os = "macos")] apple_events: apple_events.connect(&cc.egui_ctx), app, + file_dialogs, window: window::Tracker::new(opened, saved_window, control_port.is_none()), launch, drawn: false, @@ -423,6 +440,8 @@ fn startup_failed(e: &eframe::Error, gl_next: bool) { /// The desktop app: the egui app plus, on macOS, the system menu bar. struct Desktop { app: EffectcraftApp, + /// The commands' file dialogs, shown at the end of the frame that asked for them. + file_dialogs: Option>, #[cfg(target_os = "macos")] menu: native_menu::NativeBar, /// Documents opened from Finder, the Dock or `open` (macOS). @@ -442,10 +461,16 @@ impl eframe::App for Desktop { self.menu.update(&mut self.app, ctx); self.app.tick(ctx, frame); self.app.finish_ime_logic(ctx); + if let Some(asked) = &self.file_dialogs { + sheet_dialogs::show_asked(asked, frame, ctx); + } } fn ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame) { self.app.ui(ui, frame); + if let Some(asked) = &self.file_dialogs { + sheet_dialogs::show_asked(asked, frame, ui.ctx()); + } self.window.frame(ui.ctx(), self.app.session.config.as_deref()); if !self.drawn { self.drawn = true; @@ -645,10 +670,10 @@ mod tests { #[test] fn commands_file_dialogs_do_not_block_the_frame() { let mut app = effectcraft_ui_egui::EffectcraftApp::new(effectcraft_engine::Session::default()); - super::install_file_dialogs(&mut app, &egui::Context::default()); + let asked = super::install_file_dialogs(&mut app); #[cfg(any(target_os = "macos", target_os = "linux"))] - assert!(app.hooks.file_dialog_async.is_some(), "the commands' file dialogs must not block the frame"); + assert!(app.hooks.file_dialog_async.is_some() && asked.is_some(), "the commands' file dialogs must not block the frame"); #[cfg(not(any(target_os = "macos", target_os = "linux")))] - assert!(app.hooks.file_dialog_async.is_none(), "the blocking dialog pumps its own messages here"); + assert!(app.hooks.file_dialog_async.is_none() && asked.is_none(), "the blocking dialog pumps its own messages here"); } } diff --git a/apps/effectcraft/src/native_menu.rs b/apps/effectcraft/src/native_menu.rs index 9db2ffe76..c3b142c5f 100644 --- a/apps/effectcraft/src/native_menu.rs +++ b/apps/effectcraft/src/native_menu.rs @@ -2,10 +2,10 @@ //! [`effectcraft_ui_egui::native_menu`]'s spec of the engine's After Effects menu tree. //! //! Each frame [`NativeBar::update`] runs menu activations (the same command ids as the in-window -//! bar), and when [`native_menu::state_key`] changed it rebuilds the spec and pushes labels, -//! enabled and check state into the existing items; a structural change (Open Recent, a new -//! shortcut preset) rebuilds the menu. Settings ▸ Appearance ▸ Use In-Window Menu Bar on macOS -//! swaps back to the in-window bar. +//! bar), and when [`native_menu::state_key`] or whether a text field has the keyboard changed it +//! rebuilds the spec and pushes labels, enabled and check state into the existing items; a +//! structural change (Open Recent, a new shortcut preset) rebuilds the menu. Settings ▸ +//! Appearance ▸ Use In-Window Menu Bar on macOS swaps back to the in-window bar. use std::collections::HashMap; use std::sync::mpsc::{Receiver, channel}; @@ -24,7 +24,7 @@ pub struct NativeBar { items: HashMap, spec: NativeMenu, structure: u64, - state: Option, + state: Option<(u64, bool)>, events: Receiver, /// The in-window-bar setting last applied (None: not yet). in_window: Option, @@ -67,12 +67,13 @@ impl NativeBar { if in_window { return; } - let key = native_menu::state_key(app); + // While a text field has the keyboard, the Edit items it takes stay enabled. + let key = (native_menu::state_key(app), native_menu::text_field_window(ctx).is_some()); if self.state == Some(key) && self.menu.is_some() { return; } self.state = Some(key); - let spec = native_menu::build(app); + let spec = native_menu::build_now(app, ctx); let structure = spec.structure(); if self.menu.is_none() || structure != self.structure { self.install(&spec); diff --git a/apps/effectcraft/src/sheet_dialogs.rs b/apps/effectcraft/src/sheet_dialogs.rs index 7a75ef2a7..911870190 100644 --- a/apps/effectcraft/src/sheet_dialogs.rs +++ b/apps/effectcraft/src/sheet_dialogs.rs @@ -17,10 +17,24 @@ use std::pin::Pin; type Answer = Pin> + Send>>; -/// Show `dialog` (on the main thread: the sheet opens here) and hand its paths to `done` once it -/// closes, then wake the UI. -pub fn show(dialog: FileDialog, done: DialogDone, ctx: egui::Context) { - let answer = open(dialog); +/// A command's dialog waiting for [`show_asked`]. +pub type Asked = (FileDialog, DialogDone); + +/// Show the dialogs the commands asked for in this frame (on the main thread: a sheet opens +/// here) and hand each one's paths to its `done` once it closes, then wake the UI. +/// +/// On macOS the sheet goes on the main window (`frame`'s). Without a parent rfd puts it on +/// AppKit's main window, which is a floating panel's OS window after a click in one; that +/// window hides while the app has no focused window, and a sheet whose window goes away ends +/// without answering, with later sheets queued behind it on the same window. +pub fn show_asked(asked: &std::sync::mpsc::Receiver, frame: &eframe::Frame, ctx: &egui::Context) { + while let Ok((dialog, done)) = asked.try_recv() { + show(dialog, done, frame, ctx.clone()); + } +} + +fn show(dialog: FileDialog, done: DialogDone, frame: &eframe::Frame, ctx: egui::Context) { + let answer = open(dialog, frame); let spawned = std::thread::Builder::new().name("ec-file-dialog".into()).spawn(move || { done(pollster::block_on(answer)); ctx.request_repaint(); @@ -30,6 +44,13 @@ pub fn show(dialog: FileDialog, done: DialogDone, ctx: egui::Context) { } } +/// A dialog on the main window. Linux keeps the portal's dialog unparented: rfd exports the +/// window for the portal from the dialog's worker thread there. +fn parented(frame: &eframe::Frame) -> AsyncFileDialog { + let d = AsyncFileDialog::new(); + if cfg!(target_os = "macos") { d.set_parent(frame) } else { d } +} + fn paths(files: Option>) -> Vec { files.unwrap_or_default().into_iter().map(|f| f.path().to_string_lossy().to_string()).collect() } @@ -39,10 +60,10 @@ fn path(file: Option) -> Vec { } /// The dialog, as the blocking hooks in `main.rs` show it. -fn open(dialog: FileDialog) -> Answer { +fn open(dialog: FileDialog, frame: &eframe::Frame) -> Answer { match dialog { FileDialog::Open { exts, many } => { - let d = AsyncFileDialog::new().add_filter("Media", &exts); + let d = parented(frame).add_filter("Media", &exts); if many { let f = d.pick_files(); Box::pin(async move { paths(f.await) }) @@ -52,22 +73,22 @@ fn open(dialog: FileDialog) -> Answer { } } FileDialog::OpenProject => { - let f = AsyncFileDialog::new().add_filter("EffectCraft Project", &["ecproj", "ecprojx"]).pick_file(); + let f = parented(frame).add_filter("EffectCraft Project", &["ecproj", "ecprojx"]).pick_file(); Box::pin(async move { path(f.await) }) } FileDialog::Folder => { - let f = AsyncFileDialog::new().pick_folder(); + let f = parented(frame).pick_folder(); Box::pin(async move { path(f.await) }) } FileDialog::Save { default, ext, project } => { let at = std::path::Path::new(&default); let name = at.file_name().map(|n| n.to_string_lossy().to_string()).unwrap_or_default(); let mut d = if project { - AsyncFileDialog::new().add_filter("EffectCraft Project", &["ecproj"]) + parented(frame).add_filter("EffectCraft Project", &["ecproj"]) } else if ext.is_empty() { - AsyncFileDialog::new() + parented(frame) } else { - AsyncFileDialog::new().add_filter(&ext, &[ext.as_str()]) + parented(frame).add_filter(&ext, &[ext.as_str()]) }; // A default with a folder that exists opens the dialog there. if let Some(dir) = at.parent().filter(|d| d.is_dir()) { diff --git a/crates/color/src/space.rs b/crates/color/src/space.rs index ee7590eca..b570975aa 100644 --- a/crates/color/src/space.rs +++ b/crates/color/src/space.rs @@ -177,7 +177,7 @@ impl ColorSpace { /// Parse an id or label (case-insensitive, loose). pub fn parse(s: &str) -> Option { - let k: String = s.chars().filter(|c| c.is_ascii_alphanumeric()).collect::().to_ascii_lowercase(); + let k: String = s.chars().filter(char::is_ascii_alphanumeric).collect::().to_ascii_lowercase(); match k.as_str() { "srgb" | "srgbiec6196621" | "srgbiec61966" | "iec6196621" => Some(ColorSpace::Srgb), "rec709" | "bt709" | "hdtvrec709" | "hdtv" | "709" => Some(ColorSpace::Rec709), diff --git a/crates/effects/src/camera_tracker.rs b/crates/effects/src/camera_tracker.rs index ff4e51fe4..ba7878abf 100644 --- a/crates/effects/src/camera_tracker.rs +++ b/crates/effects/src/camera_tracker.rs @@ -136,11 +136,11 @@ type Cache = Mutex>>; fn cached(c: &'static OnceLock>, json: &str, parse: impl Fn(&str) -> Option) -> Option> { let key = fnv(json.as_bytes()); let c = c.get_or_init(Default::default); - if let Some(a) = c.lock().unwrap_or_else(|e| e.into_inner()).get(&key) { + if let Some(a) = c.lock().unwrap_or_else(std::sync::PoisonError::into_inner).get(&key) { return Some(a.clone()); } let a = Arc::new(parse(json)?); - let mut m = c.lock().unwrap_or_else(|e| e.into_inner()); + let mut m = c.lock().unwrap_or_else(std::sync::PoisonError::into_inner); if m.len() > 8 { m.clear(); } diff --git a/crates/effects/src/catalog.rs b/crates/effects/src/catalog.rs index 0be2b04f5..80a937b22 100644 --- a/crates/effects/src/catalog.rs +++ b/crates/effects/src/catalog.rs @@ -92,7 +92,7 @@ const CPU_ONLY_CONTROLS: &[(&str, &[&str])] = &[ ]; /// Whether the GPU kernel of effect `id` covers the instance's current settings (see -/// [`CPU_ONLY_CONTROLS`]; plus Cell Pattern's HQ variants and Turbulent Displace's locked +/// `CPU_ONLY_CONTROLS`; plus Cell Pattern's HQ variants and Turbulent Displace's locked /// pinning). pub fn gpu_supported(id: &str, ctx: &crate::EffectCtx) -> bool { match id { diff --git a/crates/effects/src/channel3d.rs b/crates/effects/src/channel3d.rs index 39a1c49b1..ea194f6da 100644 --- a/crates/effects/src/channel3d.rs +++ b/crates/effects/src/channel3d.rs @@ -359,7 +359,7 @@ pub(crate) fn selection_names(sel: &str) -> Vec { out } -/// Parse a selection: comma-separated names (optionally quoted, see [`selection_names`]) or +/// Parse a selection: comma-separated names (optionally quoted, see `selection_names`) or /// `` hashes / wildcards. pub fn selection_hashes(sel: &str, manifest: Option<&[(String, u32)]>) -> Vec { let mut out = vec![]; diff --git a/crates/effects/src/color_fx.rs b/crates/effects/src/color_fx.rs index 402d0ebe2..06884017c 100644 --- a/crates/effects/src/color_fx.rs +++ b/crates/effects/src/color_fx.rs @@ -25,7 +25,7 @@ pub(crate) fn luma_601(c: [f32; 3]) -> f32 { LUMA_601[0] * c[0] + LUMA_601[1] * c[1] + LUMA_601[2] * c[2] } -/// The Rec. 601 luma weights of [`luma_601`]. The WGSL kernels repeat them as literals; the GPU +/// The Rec. 601 luma weights of `luma_601`. The WGSL kernels repeat them as literals; the GPU /// test `shader_constants_match_the_cpu` checks that they are these. pub const LUMA_601: [f32; 3] = [0.299, 0.587, 0.114]; @@ -384,7 +384,7 @@ pub fn mirror_pow(v: f32, p: f32) -> f32 { /// back toward the gray). After Effects 2026 with Tint Color [1, 0.5, 0]: gray 0.1 (a red solid /// at Reds 10, case 717) → (43, 21, 0), gray 0.6 (yellow at defaults, case 825) → (255, 129, 2), /// white → white; the old hue / saturation / lightness mix gave (51, 26, 0) for the first. -/// The luminosity weights of [`bw_tint`] (a Color blend's). `fx_color.wgsl` repeats them; the GPU +/// The luminosity weights of `bw_tint` (a Color blend's). `fx_color.wgsl` repeats them; the GPU /// test `shader_constants_match_the_cpu` checks that they are these. pub const BW_TINT_LUMA: [f32; 3] = [0.3, 0.59, 0.11]; @@ -755,7 +755,7 @@ impl ColoramaPalette { } } - /// Parse "pos:r,g,b[,a] pos:r,g,b …" (positions 0..1, channels 0..1). `None` without stops. + /// Parse "pos:r,g,b\[,a\] pos:r,g,b …" (positions 0..1, channels 0..1). `None` without stops. pub fn parse(s: &str) -> Option { let mut stops: Vec<(f32, [f32; 4])> = s .split_whitespace() diff --git a/crates/effects/src/generate2.rs b/crates/effects/src/generate2.rs index 80d32ce0e..fcb05d6e2 100644 --- a/crates/effects/src/generate2.rs +++ b/crates/effects/src/generate2.rs @@ -61,7 +61,7 @@ const CELL_PATTERNS: [&str; 12] = [ "Tubular", ]; -/// Shaping used for Cell Pattern option `i` (see [`cell_value`]). +/// Shaping used for Cell Pattern option `i` (see `cell_value`). pub fn pattern_kind(i: u32) -> u32 { match i { 0..=5 => i, diff --git a/crates/effects/src/generate3.rs b/crates/effects/src/generate3.rs index 6beec4cb7..9e22ac8ae 100644 --- a/crates/effects/src/generate3.rs +++ b/crates/effects/src/generate3.rs @@ -147,8 +147,8 @@ pub(crate) fn paint(img: &mut Image, cov: &Plane, color: [f32; 4], opacity: f32, }); } -/// Coverage of a plan-drawn generator: round-capped segments rasterised by [`raster_segs`] -/// with `hardness`, or the union of convex polygons ([`raster_convex`]). +/// Coverage of a plan-drawn generator: round-capped segments rasterised by `raster_segs` +/// with `hardness`, or the union of convex polygons (`raster_convex`). #[derive(Clone, Debug)] pub enum Coverage { Segs { segs: Vec, hardness: f64 }, @@ -165,7 +165,7 @@ impl Coverage { } /// Stroke, Scribble, Vegas and Write-on, shared with the GPU compositor (effectcraft-gpu -/// `fx_gen2`): the coverage and how it is painted. `style` 0–2 as [`paint`] (On Original +/// `fx_gen2`): the coverage and how it is painted. `style` 0–2 as `paint` (On Original /// Image, On Transparent, Reveal Original Image), 3 = under the layer (Vegas' Composite Under). #[derive(Clone, Debug)] pub struct PaintPlan { @@ -213,7 +213,7 @@ pub fn paint_plan(id: &str, ctx: &EffectCtx, b: &Buf) -> Option { } } -/// Scribble's Composite as a [`paint`] style. +/// Scribble's Composite as a `paint` style. pub fn scribble_style(ctx: &EffectCtx) -> u32 { match ctx.params.e("composite") { 0 => 0, @@ -1596,7 +1596,7 @@ fn draw_marks(b: &mut Buf, segs_core: &[Seg], thickness: f64, softness: f64, ins } /// Audio Spectrum / Audio Waveform, shared with the GPU compositor (effectcraft-gpu `fx_gen2`): -/// the marks (the audio analysis runs on the CPU) and how [`draw_marks`] colours them. +/// the marks (the audio analysis runs on the CPU) and how `draw_marks` colours them. #[derive(Clone, Debug)] pub struct MarksPlan { pub segs: Vec, diff --git a/crates/effects/src/noise3.rs b/crates/effects/src/noise3.rs index baa5fb50a..bf1f05ed6 100644 --- a/crates/effects/src/noise3.rs +++ b/crates/effects/src/noise3.rs @@ -333,7 +333,7 @@ impl Fractal { } /// Fractal / Turbulent Noise resolved for the GPU kernel (effectcraft-gpu `fx_noise`): the -/// per-pixel constants and, per octave, the terms [`Fractal::raw`] computes before touching the +/// per-pixel constants and, per octave, the terms `Fractal::raw` computes before touching the /// pixel, in the same f32 order. pub struct FractalGpu { pub kind: u32, diff --git a/crates/effects/src/ocio.rs b/crates/effects/src/ocio.rs index 74816b110..df579964f 100644 --- a/crates/effects/src/ocio.rs +++ b/crates/effects/src/ocio.rs @@ -617,7 +617,7 @@ pub fn load_file(src: &str) -> Option> { let parsed = if inline { parse_file(src, "") } else { - let ext = std::path::Path::new(src_t).extension().and_then(|e| e.to_str()).unwrap_or(""); + let ext = std::path::Path::new(src_t).extension().and_then(std::ffi::OsStr::to_str).unwrap_or(""); std::fs::read_to_string(src_t).ok().and_then(|t| parse_file(&t, ext)) } .map(Arc::new); @@ -1055,7 +1055,7 @@ pub enum ColorOp { /// Negative channels to 0 (the saturation intent). Max0, /// A LUT (0 nearest, 1 trilinear, 2 tetrahedral) with an optional per-channel shaper, forward - /// or inverse (as [`FileXform::apply`]). + /// or inverse (as `FileXform::apply`). Lut { lut: Arc, shaper: Option; 3]>>, interp: u32, inverse: bool }, /// `m × (c + pre) + post` (a custom config's MatrixTransform and RangeTransform). Affine { m: [[f32; 3]; 3], pre: [f32; 3], post: [f32; 3] }, @@ -1322,7 +1322,7 @@ fn curve3(xs: [f64; 3], ys: [f64; 3], v: f64) -> f64 { } /// Color Stabilizer's correction of buffer `b` as one piecewise-linear map per channel (points -/// with increasing x; the end segments extend), the same maps [`color_stabilizer`] applies. +/// with increasing x; the end segments extend), the same maps `color_stabilizer` applies. /// `None` without a host or reference frame (the layer passes through). (The GPU effect.) pub fn color_stabilizer_maps(ctx: &EffectCtx, b: &Buf) -> Option<[Vec<(f64, f64)>; 3]> { let reference = ctx.env.host?.self_at(ctx.params.f("referenceFrame"), ctx.env.effect_index)?; diff --git a/crates/effects/src/ocio_config.rs b/crates/effects/src/ocio_config.rs index 5ea844414..41c74b4e4 100644 --- a/crates/effects/src/ocio_config.rs +++ b/crates/effects/src/ocio_config.rs @@ -20,7 +20,7 @@ //! * `looks` (`name`, `process_space`, `transform`, `inverse_transform`) and look strings //! (`+A, -B`, `A | B` = the first one the config has); //! * transforms: `MatrixTransform` (`matrix` 4×4 row-major, `offset`), `FileTransform` (the LUT, -//! CDL and matrix files [`super::ocio::parse_file`] reads; `interpolation`, `ccc_id`), +//! CDL and matrix files `super::ocio::parse_file` reads; `interpolation`, `ccc_id`), //! `ExponentTransform` (`value`), `ExponentWithLinearTransform` (`gamma`, `offset`, `style: //! mirror`; the power curve with a linear toe that the Academy CLF specification calls //! "moncurve"), `LogTransform` (`base`), `LogAffineTransform` (`base`, `logSideSlope`, diff --git a/crates/effects/src/sim.rs b/crates/effects/src/sim.rs index 14146a9f4..1bb82f46e 100644 --- a/crates/effects/src/sim.rs +++ b/crates/effects/src/sim.rs @@ -186,7 +186,7 @@ pub enum Tint { /// How a sprite layer meets the original layer. #[derive(Clone, Copy, Debug, PartialEq)] pub enum Post { - /// [`combine`] with this mode (0 Composite … 5 sprites only). + /// `combine` with this mode (0 Composite … 5 sprites only). Combine(u32), /// The sprites alone. Replace, diff --git a/crates/effects/src/sim2.rs b/crates/effects/src/sim2.rs index cf7322bda..939c36757 100644 --- a/crates/effects/src/sim2.rs +++ b/crates/effects/src/sim2.rs @@ -1586,7 +1586,7 @@ pub struct FoamEnv { /// What Foam draws this frame over a transparent frame of the layer's size: the bubble sprites, /// then the User Defined texture's discs, the Environment Map's reflections and (Draft + Flow -/// Map) the flow map under it all, each [`foam_disc`]-composited in bubble order. +/// Map) the flow map under it all, each `foam_disc`-composited in bubble order. pub struct FoamPlan { pub sprites: crate::sim::SpritePlan, pub user: Option<(crate::LayerPixels, Vec)>, diff --git a/crates/effects/src/util.rs b/crates/effects/src/util.rs index 1527e221f..ae55d095d 100644 --- a/crates/effects/src/util.rs +++ b/crates/effects/src/util.rs @@ -537,7 +537,7 @@ impl SimCache { pub fn run(&self, key: u64, target: u64, init: impl FnOnce() -> S, mut step: impl FnMut(&mut S, u64)) -> std::sync::Arc { use std::sync::Arc; let start = { - let mut g = self.inner.lock().unwrap_or_else(|e| e.into_inner()); + let mut g = self.inner.lock().unwrap_or_else(std::sync::PoisonError::into_inner); let tick = g.iter().map(|e| e.used).max().unwrap_or(0) + 1; g.iter_mut().find(|e| e.key == key).and_then(|e| { e.used = tick; @@ -563,7 +563,7 @@ impl SimCache { } let out = Arc::new(st); fresh.push((target, out.clone())); - let mut g = self.inner.lock().unwrap_or_else(|e| e.into_inner()); + let mut g = self.inner.lock().unwrap_or_else(std::sync::PoisonError::into_inner); let tick = g.iter().map(|e| e.used).max().unwrap_or(0) + 1; let idx = match g.iter().position(|e| e.key == key) { Some(ix) => ix, diff --git a/crates/effects/src/warp_stab.rs b/crates/effects/src/warp_stab.rs index 595cb5200..f850bdcf3 100644 --- a/crates/effects/src/warp_stab.rs +++ b/crates/effects/src/warp_stab.rs @@ -191,11 +191,11 @@ fn analysis_cached(json: &str) -> Option<(u64, Arc)> { static C: OnceLock = OnceLock::new(); let key = fnv(json.as_bytes()); let c = C.get_or_init(Default::default); - if let Some(a) = c.lock().unwrap_or_else(|e| e.into_inner()).get(&key) { + if let Some(a) = c.lock().unwrap_or_else(std::sync::PoisonError::into_inner).get(&key) { return Some((key, a.clone())); } let a = Arc::new(WarpAnalysis::from_json(json)?); - let mut m = c.lock().unwrap_or_else(|e| e.into_inner()); + let mut m = c.lock().unwrap_or_else(std::sync::PoisonError::into_inner); if m.len() > 8 { m.clear(); } @@ -294,7 +294,7 @@ pub fn store_summary(key: [u64; 2], summary: PlanSummary) { } fn keep_summary(key: (u64, u64), summary: Arc) { - let mut m = summaries().lock().unwrap_or_else(|e| e.into_inner()); + let mut m = summaries().lock().unwrap_or_else(std::sync::PoisonError::into_inner); if m.len() > 32 { m.clear(); } @@ -305,7 +305,7 @@ fn keep_summary(key: (u64, u64), summary: Arc) { /// cached (seconds for a long Subspace Warp clip). `None` when not analysed. pub fn summary(params: &Params) -> Option<([u64; 2], Arc)> { let (key, a, st) = plan_key(params)?; - let cached = summaries().lock().unwrap_or_else(|e| e.into_inner()).get(&key).cloned(); + let cached = summaries().lock().unwrap_or_else(std::sync::PoisonError::into_inner).get(&key).cloned(); let sum = match cached { Some(s) => s, None => { @@ -333,7 +333,7 @@ pub fn summary_at(params: &Params, time: f64) -> Option<(usize, Arc pub fn cached_summary_at(params: &Params, time: f64) -> Option<(usize, Arc)> { let (key, a, _) = plan_key(params)?; let k = a.frame_at(time)?; - let sum = summaries().lock().unwrap_or_else(|e| e.into_inner()).get(&key).cloned(); + let sum = summaries().lock().unwrap_or_else(std::sync::PoisonError::into_inner).get(&key).cloned(); let sum = match sum { Some(s) => s, None => { @@ -445,13 +445,13 @@ fn render(ctx: &EffectCtx, buf: Buf) -> Buf { } } if !local.is_empty() { - let mut n = need_m.lock().unwrap_or_else(|e| e.into_inner()); + let mut n = need_m.lock().unwrap_or_else(std::sync::PoisonError::into_inner); for (x, w) in local { n[y * ow as usize + x] = w; } } }); - let need = need_m.into_inner().unwrap_or_else(|e| e.into_inner()); + let need = need_m.into_inner().unwrap_or_else(std::sync::PoisonError::into_inner); if synth && need.iter().any(|w| *w > 0.0) { synthesize(ctx, &a, k, &src_of, &crop, sc, &mut out, &need); } diff --git a/crates/engine/src/commands/edit.rs b/crates/engine/src/commands/edit.rs index a7de48652..4f79e5271 100644 --- a/crates/engine/src/commands/edit.rs +++ b/crates/engine/src/commands/edit.rs @@ -860,7 +860,7 @@ fn original_path(s: &Session) -> Option { /// importer takes. Anything else (a folder or app bundle, a script, a shortcut) is refused. pub(crate) fn openable_original(path: &str) -> std::result::Result<(), String> { let media = |p: &std::path::Path| { - let ext = p.extension().and_then(|e| e.to_str()).map(str::to_ascii_lowercase).unwrap_or_default(); + let ext = p.extension().and_then(std::ffi::OsStr::to_str).map(str::to_ascii_lowercase).unwrap_or_default(); crate::media_browser::kind_of(&p.to_string_lossy()).is_some_and(|k| k != "project") || matches!(ext.as_str(), "pdf" | "ai" | "eps") }; let name = std::path::Path::new(path).file_name().map(|n| n.to_string_lossy().into_owned()).unwrap_or_else(|| path.to_string()); diff --git a/crates/engine/src/commands/file.rs b/crates/engine/src/commands/file.rs index 0fea452dc..b3922c7d6 100644 --- a/crates/engine/src/commands/file.rs +++ b/crates/engine/src/commands/file.rs @@ -560,7 +560,7 @@ pub const DATA_EXTENSIONS: &[&str] = &["json", "csv", "tsv"]; /// A data footage item for `path` (JSON / CSV / TSV), `None` for other files. pub(crate) fn data_footage(services: &dyn crate::Services, path: &str) -> Option> { - let ext = std::path::Path::new(path).extension().and_then(|e| e.to_str()).unwrap_or("").to_ascii_lowercase(); + let ext = std::path::Path::new(path).extension().and_then(std::ffi::OsStr::to_str).unwrap_or("").to_ascii_lowercase(); if !DATA_EXTENSIONS.contains(&ext.as_str()) { return None; } diff --git a/crates/engine/src/commands/layer_menu.rs b/crates/engine/src/commands/layer_menu.rs index 0a0449376..33d17bb4f 100644 --- a/crates/engine/src/commands/layer_menu.rs +++ b/crates/engine/src/commands/layer_menu.rs @@ -708,7 +708,7 @@ const BUNDLE_EXTENSIONS: &[&str] = &[ /// Whether the system file manager would open folder `dir` as something other than a folder: a /// bundle (`Tool.app`), or a Windows folder with a `{CLSID}` extension. fn opens_as_bundle(dir: &std::path::Path) -> bool { - let ext = dir.extension().and_then(|e| e.to_str()).unwrap_or_default().to_ascii_lowercase(); + let ext = dir.extension().and_then(std::ffi::OsStr::to_str).unwrap_or_default().to_ascii_lowercase(); ext.starts_with('{') || BUNDLE_EXTENSIONS.contains(&ext.as_str()) } diff --git a/crates/engine/src/commands/paint.rs b/crates/engine/src/commands/paint.rs index 73f600b56..c02a1849d 100644 --- a/crates/engine/src/commands/paint.rs +++ b/crates/engine/src/commands/paint.rs @@ -107,7 +107,7 @@ impl Default for PaintOptions { } fn norm(s: &str) -> String { - s.chars().filter(|c| c.is_ascii_alphanumeric()).collect::().to_ascii_lowercase() + s.chars().filter(char::is_ascii_alphanumeric).collect::().to_ascii_lowercase() } /// Index of `v` in `names` (by number or case/space-insensitive name). diff --git a/crates/engine/src/commands/relink.rs b/crates/engine/src/commands/relink.rs index 2d7c2ea13..d899decbe 100644 --- a/crates/engine/src/commands/relink.rs +++ b/crates/engine/src/commands/relink.rs @@ -103,7 +103,7 @@ fn run(s: &mut Session, p: &Value) -> Result { } let supported = matches!(old.kind, FootageKind::Still | FootageKind::Sequence | FootageKind::Video | FootageKind::Audio) && old.layer.is_none() && old.page == 0; - let name = Path::new(&old.path).file_name().and_then(|n| n.to_str()).unwrap_or(""); + let name = Path::new(&old.path).file_name().and_then(std::ffi::OsStr::to_str).unwrap_or(""); let paths = index.get(name).cloned().unwrap_or_default(); let mut candidates = vec![]; let mut accepted = vec![]; diff --git a/crates/engine/src/mask_track.rs b/crates/engine/src/mask_track.rs index f85ba6b70..79c2b4643 100644 --- a/crates/engine/src/mask_track.rs +++ b/crates/engine/src/mask_track.rs @@ -80,10 +80,10 @@ impl MaskMethod { } } pub fn from_name(s: &str) -> Option { - let n: String = s.chars().filter(|c| c.is_ascii_alphanumeric()).collect::().to_ascii_lowercase(); + let n: String = s.chars().filter(char::is_ascii_alphanumeric).collect::().to_ascii_lowercase(); MaskMethod::ALL .into_iter() - .find(|m| m.id().to_ascii_lowercase() == n || m.label().chars().filter(|c| c.is_ascii_alphanumeric()).collect::().to_ascii_lowercase() == n) + .find(|m| m.id().to_ascii_lowercase() == n || m.label().chars().filter(char::is_ascii_alphanumeric).collect::().to_ascii_lowercase() == n) } pub fn model(self) -> Model { match self { diff --git a/crates/engine/src/offload.rs b/crates/engine/src/offload.rs index ad2c0cde0..135822d57 100644 --- a/crates/engine/src/offload.rs +++ b/crates/engine/src/offload.rs @@ -289,10 +289,10 @@ pub struct Inbox(Mutex>); impl Inbox { pub fn push(&self, r: WorkerReply) { - self.0.lock().unwrap_or_else(|e| e.into_inner()).push(r); + self.0.lock().unwrap_or_else(std::sync::PoisonError::into_inner).push(r); } pub fn take(&self) -> Vec { - std::mem::take(&mut *self.0.lock().unwrap_or_else(|e| e.into_inner())) + std::mem::take(&mut *self.0.lock().unwrap_or_else(std::sync::PoisonError::into_inner)) } } diff --git a/crates/engine/src/render_queue.rs b/crates/engine/src/render_queue.rs index 74b333151..27e9a7dce 100644 --- a/crates/engine/src/render_queue.rs +++ b/crates/engine/src/render_queue.rs @@ -110,7 +110,7 @@ pub struct JobShared { } pub(crate) fn lock(m: &Mutex) -> std::sync::MutexGuard<'_, T> { - m.lock().unwrap_or_else(|e| e.into_inner()) + m.lock().unwrap_or_else(std::sync::PoisonError::into_inner) } impl JobShared { diff --git a/crates/engine/src/tests_proxy.rs b/crates/engine/src/tests_proxy.rs index 82cd1dcfd..16e0cb00c 100644 --- a/crates/engine/src/tests_proxy.rs +++ b/crates/engine/src/tests_proxy.rs @@ -20,7 +20,7 @@ use crate::render::{FootageSource, RenderOpts}; struct Synthetic; fn file_px(path: &str, x: u32, y: u32) -> [f32; 4] { - let name = std::path::Path::new(path).file_name().and_then(|n| n.to_str()).unwrap_or(""); + let name = std::path::Path::new(path).file_name().and_then(std::ffi::OsStr::to_str).unwrap_or(""); match name { "red16.png" => [1.0, 0.0, 0.0, 1.0], "blue8.png" => [0.0, 0.0, 1.0, 1.0], @@ -43,7 +43,7 @@ fn file_px(path: &str, x: u32, y: u32) -> [f32; 4] { } fn size_of(path: &str) -> (u32, u32) { - match std::path::Path::new(path).file_name().and_then(|n| n.to_str()).unwrap_or("") { + match std::path::Path::new(path).file_name().and_then(std::ffi::OsStr::to_str).unwrap_or("") { "red16.png" => (16, 16), "blue8.png" => (8, 8), "lines.mov" | "matte_black.png" | "matte_white.png" | "half.png" => (4, 4), diff --git a/crates/engine/src/tracking.rs b/crates/engine/src/tracking.rs index cfdd12441..434cdd8af 100644 --- a/crates/engine/src/tracking.rs +++ b/crates/engine/src/tracking.rs @@ -157,7 +157,7 @@ pub struct TrackShared { } pub(crate) fn lock(m: &Mutex) -> std::sync::MutexGuard<'_, T> { - m.lock().unwrap_or_else(|e| e.into_inner()) + m.lock().unwrap_or_else(std::sync::PoisonError::into_inner) } /// A running (or finished, not yet polled) analysis. diff --git a/crates/engine/src/viewer.rs b/crates/engine/src/viewer.rs index 997c2023b..6b6e5ce99 100644 --- a/crates/engine/src/viewer.rs +++ b/crates/engine/src/viewer.rs @@ -663,10 +663,10 @@ impl SimProfile { } pub fn parse(s: &str) -> Option { - let k: String = s.chars().filter(|c| c.is_ascii_alphanumeric()).collect::().to_ascii_lowercase(); + let k: String = s.chars().filter(char::is_ascii_alphanumeric).collect::().to_ascii_lowercase(); SimProfile::ALL .into_iter() - .find(|p| p.id().to_ascii_lowercase() == k || p.label().chars().filter(|c| c.is_ascii_alphanumeric()).collect::().to_ascii_lowercase() == k) + .find(|p| p.id().to_ascii_lowercase() == k || p.label().chars().filter(char::is_ascii_alphanumeric).collect::().to_ascii_lowercase() == k) .or(match k.as_str() { "off" => Some(SimProfile::None), "hdtv" | "bt709" => Some(SimProfile::Rec709), diff --git a/crates/export/src/lib.rs b/crates/export/src/lib.rs index eda979958..9af195204 100644 --- a/crates/export/src/lib.rs +++ b/crates/export/src/lib.rs @@ -13,7 +13,7 @@ //! | AV1 | MP4 (`av01`) | `effectcraft-av1enc` Main 8/10-bit 4:2:0, key + inter frames | no | AAC-LC (FilmCraft) | //! | WAV / AIFF | RIFF WAVE / AIFF (AIFF-C for float) | — | — | PCM 16/24-bit or 32-bit float, mono/stereo (audio only) | //! -//! Every frame goes through [`pipeline`]: the Render Settings overrides (Effects, Solo Switches, +//! Every frame goes through the internal `pipeline` module: the Render Settings overrides (Effects, Solo Switches, //! Guide Layers, Frame Blending, Motion Blur, Color Depth), field rendering (two fields half a //! frame apart woven line by line, with optional 3:2 pulldown from film frames at 4/5 of the //! rate), then the Output Module's Crop (edges or the region of interest) and Resize. Channels diff --git a/crates/export/src/pipeline.rs b/crates/export/src/pipeline.rs index 8dcee03e4..9fd131474 100644 --- a/crates/export/src/pipeline.rs +++ b/crates/export/src/pipeline.rs @@ -247,7 +247,7 @@ impl<'a> Cx<'a> { } let img = self.crop_resize(img); if let Some(ft) = &self.frame_times { - ft.lock().unwrap_or_else(|e| e.into_inner()).push((i, t0.elapsed().as_secs_f64())); + ft.lock().unwrap_or_else(std::sync::PoisonError::into_inner).push((i, t0.elapsed().as_secs_f64())); } img } @@ -327,7 +327,7 @@ impl<'a> Cx<'a> { for dir in &self.job.options.overflow { let p = std::path::Path::new(dir).join(&name).to_string_lossy().to_string(); if q.has_room(&p, bytes) { - self.overflowed.lock().unwrap_or_else(|e| e.into_inner()).push(p.clone()); + self.overflowed.lock().unwrap_or_else(std::sync::PoisonError::into_inner).push(p.clone()); return p; } } @@ -351,7 +351,7 @@ impl<'a> Cx<'a> { Ok(r) => s.push_str(&format!("Result: Done ({} frames, {}×{}, {} bytes) in {seconds:.2} s\n", r.frames, r.width, r.height, r.bytes)), Err(e) => s.push_str(&format!("Result: Failed\nError: {e}\n")), } - let over = self.overflowed.lock().unwrap_or_else(|e| e.into_inner()); + let over = self.overflowed.lock().unwrap_or_else(std::sync::PoisonError::into_inner); if !over.is_empty() { s.push_str(&format!("Storage overflow: {} file(s) written to overflow folders (first: {})\n", over.len(), over[0])); } @@ -366,7 +366,7 @@ impl<'a> Cx<'a> { } } if let (RenderLog::PlusPerFrameInfo, Some(ft), Some(c)) = (level, &self.frame_times, comp) { - let mut v = ft.lock().unwrap_or_else(|e| e.into_inner()).clone(); + let mut v = ft.lock().unwrap_or_else(std::sync::PoisonError::into_inner).clone(); v.sort_by_key(|(i, _)| *i); s.push_str("\nFrames:\n"); let f0 = self.job.settings.first_frame(c); diff --git a/crates/expr/src/prelude.js b/crates/expr/src/prelude.js index df6ed3ff4..6611d36aa 100644 --- a/crates/expr/src/prelude.js +++ b/crates/expr/src/prelude.js @@ -840,14 +840,14 @@ var __propHandler = { // A layer-valued property (a Layer Control's Layer) is named as its layer (#809). if (k === 'name' && t.__info[2] === 'layer') { var lv = t.value; - if (lv !== null && lv !== undefined && lv.__isLayer) return lv.name; + if (lv?.__isLayer) return lv.name; } if (k in t) return t[k]; var v = t.value; if (v === null || v === undefined) return undefined; var x = v[k]; // Property groups are callable proxies: hand them over as they are, not bound like methods (#809). - if (x !== null && x !== undefined && x.__isGroup) return x; + if (x?.__isGroup) return x; return typeof x === 'function' ? x.bind(v) : x; }, }; @@ -904,8 +904,8 @@ __TextStyle.prototype = { }, get text() { var t = this.__d.text; - for (var k = 0; k < this.__ops.length; k++) { - var o = this.__ops[k]; + for (const elem of this.__ops) { + var o = elem; if (o[0] !== 'text') continue; if (o[2] < 0) t = String(o[1]); else t = t.slice(0, o[2]) + String(o[1]) + (o[3] < 0 ? '' : t.slice(o[2] + o[3])); diff --git a/crates/expr/src/rewrite.rs b/crates/expr/src/rewrite.rs index 6b0ea539f..35c373bb4 100644 --- a/crates/expr/src/rewrite.rs +++ b/crates/expr/src/rewrite.rs @@ -581,7 +581,7 @@ fn push_piece(out: &mut String, p: Piece) { /// rewrite (which nests a call per arithmetic operator). The JavaScript parser and compiler /// recurse per level and a 2 MiB thread overflows its stack (aborting the app) at about 75 /// nested brackets, so deeper expressions are rejected with an error instead. Constructs that -/// nest without brackets count as part of a level ([`too_nested`]). +/// nest without brackets count as part of a level (`too_nested`). pub const MAX_NESTING: usize = 32; /// Hard limit on bytes emitted by the array-math source rewrite. pub const MAX_REWRITTEN_BYTES: usize = 4 * 1024 * 1024; @@ -608,7 +608,7 @@ const HEAVY: usize = 32; /// about 3 800 links). const LIGHT: usize = 6; -/// One bracket level of [`too_nested`]'s walk. +/// One bracket level of `too_nested`'s walk. #[derive(Default)] struct Level { /// `[`: commas separate elements (a loop in the parser), not operands. @@ -710,7 +710,7 @@ fn too_nested(toks: &[Tok]) -> bool { too_nested_from(toks, 0) } -/// [`too_nested`] for code that already sits `base` deep (a template substitution). +/// `too_nested` for code that already sits `base` deep (a template substitution). fn too_nested_from(toks: &[Tok], base: usize) -> bool { let mut levels = vec![Level::default()]; let mut prefix = 0usize; diff --git a/crates/gpu/src/tests_deferred.rs b/crates/gpu/src/tests_deferred.rs index b6e43b55f..e8778b628 100644 --- a/crates/gpu/src/tests_deferred.rs +++ b/crates/gpu/src/tests_deferred.rs @@ -30,7 +30,7 @@ pub(crate) fn deferred_gpu() -> Option<(&'static Gpu, std::sync::MutexGuard<'sta g }); let g = crate::tests::require_gpu("deferred gpu tests", g.as_ref())?; - Some((g, LOCK.lock().unwrap_or_else(|e| e.into_inner()))) + Some((g, LOCK.lock().unwrap_or_else(std::sync::PoisonError::into_inner))) } /// Footage with GPU effects around a CPU-only one, a solid with Glow, and a precomp whose diff --git a/crates/media/src/exr_channels.rs b/crates/media/src/exr_channels.rs index 8c4cb1339..795da99e5 100644 --- a/crates/media/src/exr_channels.rs +++ b/crates/media/src/exr_channels.rs @@ -183,7 +183,7 @@ fn picture_layer<'a>(aux: &AuxChannels, layers: &[&'a str]) -> Option<&'a str> { /// The picture of a multi-layer OpenEXR file without an unnamed RGB layer (Blender's /// `ViewLayer.Combined.R`, the compositor's `Image.R`, Nuke's `beauty.R`, …), which the image /// decoder rejects. After Effects shows a file's main RGBA channels and leaves the other layers -/// to EXtractoR; here that is the beauty pass by name ([`BEAUTY`]), else the first colour layer +/// to EXtractoR; here that is the beauty pass by name (`BEAUTY`), else the first colour layer /// that is not a data pass (never Cryptomatte, depth or normals, #412), else the first channel /// as grey. Linear, straight RGBA as the file stores it. `None` when it is not a readable EXR. pub fn layered_image(bytes: &[u8]) -> Option { diff --git a/crates/media/src/layered.rs b/crates/media/src/layered.rs index 0a70d1f7f..055c3feb0 100644 --- a/crates/media/src/layered.rs +++ b/crates/media/src/layered.rs @@ -36,7 +36,7 @@ pub fn vector_doc( } fn is_pdf_like(path: &str, bytes: &[u8]) -> bool { - let ext = std::path::Path::new(path).extension().and_then(|e| e.to_str()).unwrap_or("").to_ascii_lowercase(); + let ext = std::path::Path::new(path).extension().and_then(std::ffi::OsStr::to_str).unwrap_or("").to_ascii_lowercase(); effectcraft_pdf::sniff(bytes).is_some() && (effectcraft_pdf::EXTENSIONS.contains(&ext.as_str()) || bytes.starts_with(b"%PDF")) } diff --git a/crates/media/src/lib.rs b/crates/media/src/lib.rs index 04a9d95e3..9b5b491ab 100644 --- a/crates/media/src/lib.rs +++ b/crates/media/src/lib.rs @@ -80,7 +80,7 @@ pub fn is_importable(path: &std::path::Path) -> bool { } pub(crate) fn ext_of(path: &std::path::Path) -> String { - path.extension().and_then(|e| e.to_str()).unwrap_or("").to_ascii_lowercase() + path.extension().and_then(std::ffi::OsStr::to_str).unwrap_or("").to_ascii_lowercase() } /// The `image` crate format of a still: from its signature, else from its extension (Targa has diff --git a/crates/media/src/pool.rs b/crates/media/src/pool.rs index 4deefed35..4820efa35 100644 --- a/crates/media/src/pool.rs +++ b/crates/media/src/pool.rs @@ -388,7 +388,7 @@ impl MediaPool { } /// The conformed-audio file of `path` at `rate` (named by a hash of the path, size and - /// modification time, so an edited file conforms again, and of [`CONFORM_VERSION`]). + /// modification time, so an edited file conforms again, and of `CONFORM_VERSION`). pub fn conformed_path(&self, path: &str, rate: u32) -> Option { use std::hash::{Hash, Hasher}; let folder = lock(&self.inner.conform).clone()?; @@ -756,7 +756,7 @@ impl Inner { drop(c); return Ok(Arc::new(self.decode(&loc, footage)?)); } - c = self.done.wait(c).unwrap_or_else(|e| e.into_inner()); + c = self.done.wait(c).unwrap_or_else(std::sync::PoisonError::into_inner); } self.misses.fetch_add(1, Ordering::Relaxed); c.inflight.insert(loc.key.clone()); @@ -972,7 +972,7 @@ fn describe_problem(codec: &str, e: &MediaError) -> String { } fn lock(m: &Mutex) -> std::sync::MutexGuard<'_, T> { - m.lock().unwrap_or_else(|e| e.into_inner()) + m.lock().unwrap_or_else(std::sync::PoisonError::into_inner) } #[cfg(test)] diff --git a/crates/model/Cargo.toml b/crates/model/Cargo.toml index 25397921a..33ee26726 100644 --- a/crates/model/Cargo.toml +++ b/crates/model/Cargo.toml @@ -15,4 +15,4 @@ serde = { workspace = true } serde_json = { workspace = true } thiserror = { workspace = true } image = { workspace = true } -miniz_oxide = "0.8" +miniz_oxide = "0.9" diff --git a/crates/path/Cargo.toml b/crates/path/Cargo.toml index 46cf0a832..2e9bc85d9 100644 --- a/crates/path/Cargo.toml +++ b/crates/path/Cargo.toml @@ -15,4 +15,4 @@ effectcraft-keyframe = { workspace = true } effectcraft-raster = { workspace = true } kurbo = { workspace = true } tiny-skia = { workspace = true } -linesweeper = "0.4" +linesweeper = "0.5" diff --git a/crates/path/src/boolean.rs b/crates/path/src/boolean.rs index 5a81b3e19..bcd395566 100644 --- a/crates/path/src/boolean.rs +++ b/crates/path/src/boolean.rs @@ -5,7 +5,7 @@ //! MIT OR Apache-2.0), reworked to take and return kurbo paths directly. //! //! Inputs are closed implicitly (a filled open path is painted as if closed). The sweep splits -//! curves at intersections and y-extrema; [`tidy_segments`] re-joins pieces that came from one +//! curves at intersections and y-extrema; `tidy_segments` re-joins pieces that came from one //! input curve (exactly) or one smooth run (by least-squares refit), so results carry roughly as //! few vertices as the inputs. Output contours are simple and consistently oriented (holes wind //! opposite to their outer contour), so they fill the same under either fill rule. diff --git a/crates/path/src/trace.rs b/crates/path/src/trace.rs index 429738032..01508bcaf 100644 --- a/crates/path/src/trace.rs +++ b/crates/path/src/trace.rs @@ -6,7 +6,7 @@ //! with "outside" so every contour closes. //! 2. **Douglas–Peucker** simplification of each closed loop to the Tolerance (pixels). //! 3. **Bezier fitting**: each simplified span is fitted with one cubic (least squares with fixed -//! end tangents, Newton reparameterisation; [`crate::fit`]). The tangent at each vertex is the +//! end tangents, Newton reparameterisation; `crate::fit`). The tangent at each vertex is the //! chord direction at Corner Roundness 0 (straight segments, sharp corners) and the smooth //! (Catmull–Rom) direction at 100 %, blended between. //! diff --git a/crates/pdf/Cargo.toml b/crates/pdf/Cargo.toml index b37dff50f..bf6148569 100644 --- a/crates/pdf/Cargo.toml +++ b/crates/pdf/Cargo.toml @@ -14,7 +14,7 @@ craft-pdf.workspace = true effectcraft-svg = { workspace = true } kurbo = { workspace = true } effectcraft-text = { workspace = true } -miniz_oxide = "0.8" +miniz_oxide = "0.9" # Embedded TrueType / OpenType font programs (MIT OR Apache-2.0). skrifa = { workspace = true } # DCT (JPEG) images (MIT OR Apache-2.0 OR Zlib; pure Rust). diff --git a/crates/pdf/README.md b/crates/pdf/README.md index e4970edc9..7389b00c8 100644 --- a/crates/pdf/README.md +++ b/crates/pdf/README.md @@ -138,7 +138,7 @@ ffmpeg elsewhere) to check the code tables against an independent implementation ## Shared parser setup and bounds The workspace pins `craft-pdf` to `craft-libs` Git revision -`9f75d3dc19b4b514c4f3d4847ed1ec1b0e86b4ef`, with `default-features = false` and only the explicit `read` +`512b54355cd1418f4e8c56a3fbd7483c3c274bf3`, with `default-features = false` and only the explicit `read` feature. This excludes the backend's bundled fonts and Adobe CMaps and preserves EffectCraft's font and asset policies. The shared parser does not change the supported drawing operators, image codecs, continuously rasterized SVG tree, editable shapes, or EPS interpreter. diff --git a/crates/project/src/lib.rs b/crates/project/src/lib.rs index 8a4bbeb3c..822fc7f75 100644 --- a/crates/project/src/lib.rs +++ b/crates/project/src/lib.rs @@ -201,7 +201,7 @@ impl TimeDisplayStyle { } } pub fn parse(s: &str) -> Option { - let k: String = s.chars().filter(|c| c.is_ascii_alphanumeric()).collect::().to_ascii_lowercase(); + let k: String = s.chars().filter(char::is_ascii_alphanumeric).collect::().to_ascii_lowercase(); match k.as_str() { "timecode" => Some(TimeDisplayStyle::Timecode), "frames" => Some(TimeDisplayStyle::Frames), @@ -1292,7 +1292,7 @@ impl Footage { if self.kind != FootageKind::Data { return None; } - let ext = std::path::Path::new(&self.path).extension().and_then(|e| e.to_str()).unwrap_or("").to_ascii_lowercase(); + let ext = std::path::Path::new(&self.path).extension().and_then(std::ffi::OsStr::to_str).unwrap_or("").to_ascii_lowercase(); Some(match ext.as_str() { "csv" => "csv", "tsv" | "tab" => "tsv", diff --git a/crates/psd/Cargo.toml b/crates/psd/Cargo.toml index 49dda6a3b..b6849041b 100644 --- a/crates/psd/Cargo.toml +++ b/crates/psd/Cargo.toml @@ -10,4 +10,4 @@ rust-version.workspace = true workspace = true [dependencies] -miniz_oxide = "0.8" +miniz_oxide = "0.9" diff --git a/crates/psd/src/lib.rs b/crates/psd/src/lib.rs index 5ae32126a..60a9ab806 100644 --- a/crates/psd/src/lib.rs +++ b/crates/psd/src/lib.rs @@ -1,5 +1,5 @@ //! Photoshop document (PSD / PSB) reader, implemented from Adobe's public *Photoshop File Formats -//! Specification* (see README.md), and a minimal writer ([`write`]) for fixtures. +//! Specification* (see README.md), and a minimal writer ([`mod@write`]) for fixtures. //! //! [`Psd::parse`] reads the structure (header, layer records and their additional information, //! the layer tree) without decoding pixels; [`Psd::composite`] decodes the merged image and diff --git a/crates/render/Cargo.toml b/crates/render/Cargo.toml index db2fa9dd0..efbd1fc19 100644 --- a/crates/render/Cargo.toml +++ b/crates/render/Cargo.toml @@ -19,7 +19,7 @@ effectcraft-raster = { workspace = true } effectcraft-path = { workspace = true } effectcraft-text = { workspace = true } effectcraft-effects = { workspace = true } -lz4_flex = { version = "0.11", default-features = false, features = ["std", "safe-encode", "safe-decode", "checked-decode"] } +lz4_flex = { version = "0.14", default-features = false, features = ["std", "safe-encode", "safe-decode", "checked-decode"] } effectcraft-model = { workspace = true } kurbo = { workspace = true } rayon = { workspace = true } diff --git a/crates/render/src/disk_cache.rs b/crates/render/src/disk_cache.rs index f867a614a..4fa2e1cb3 100644 --- a/crates/render/src/disk_cache.rs +++ b/crates/render/src/disk_cache.rs @@ -331,7 +331,7 @@ impl DiskCache { let Ok(files) = std::fs::read_dir(shard.path()) else { continue }; for f in files.flatten() { let p = f.path(); - let name = p.file_name().and_then(|n| n.to_str()).unwrap_or(""); + let name = p.file_name().and_then(std::ffi::OsStr::to_str).unwrap_or(""); if name.contains(".tmp") { // A writer that died mid-write; old temporaries are removed. if f.metadata().and_then(|m| m.modified()).is_ok_and(|t| t.elapsed().is_ok_and(|e| e.as_secs() > 600)) { diff --git a/crates/render/src/lib.rs b/crates/render/src/lib.rs index bf3aa42ee..e4fc8e6e5 100644 --- a/crates/render/src/lib.rs +++ b/crates/render/src/lib.rs @@ -521,7 +521,7 @@ pub struct RenderOpts { pub motion_blur: bool, /// Render guide layers (viewer only). Only the top-level comp's own guide layers: nested /// comps (precomps, collapsed precomps, comps read by effects) never draw theirs, as in - /// After Effects (see [`Renderer::nested_opts`]). + /// After Effects (see `Renderer::nested_opts`). pub guides: bool, /// Draft quality: fewer motion-blur samples, bilinear only. pub draft: bool, diff --git a/crates/render/src/three_d/adv/shade.rs b/crates/render/src/three_d/adv/shade.rs index c7c1a40f1..9acc852fe 100644 --- a/crates/render/src/three_d/adv/shade.rs +++ b/crates/render/src/three_d/adv/shade.rs @@ -230,7 +230,7 @@ const PLANE_SLOPE_MAX: f32 = 64.0; /// Fraction of light reaching `p` through shadow map `m` (1 = lit). `ng` is the /// receiver's geometric (not normal-mapped) normal facing the viewer. /// -/// PCF over an N×N tap grid (5 ≤ N ≤ [`PCF_MAX_TAPS`]) spread over a reach derived +/// PCF over an N×N tap grid (5 ≤ N ≤ `PCF_MAX_TAPS`) spread over a reach derived /// from `radius` (the wanted penumbra in output pixels) divided by the receiver's /// texel footprint, each tap jittered by an integer hash of the receiver's /// sub-texel cell and the tap index, and each tap comparing against the four diff --git a/crates/render/src/three_d/camera.rs b/crates/render/src/three_d/camera.rs index 5e1f983b2..30873b6a9 100644 --- a/crates/render/src/three_d/camera.rs +++ b/crates/render/src/three_d/camera.rs @@ -408,7 +408,7 @@ impl View3D { } } pub fn from_id(s: &str) -> Option { - let k: String = s.chars().filter(|c| c.is_ascii_alphanumeric()).collect::().to_ascii_lowercase(); + let k: String = s.chars().filter(char::is_ascii_alphanumeric).collect::().to_ascii_lowercase(); View3D::ALL.into_iter().find(|v| v.id().eq_ignore_ascii_case(&k) || v.label().replace(' ', "").eq_ignore_ascii_case(&k)) } pub fn is_ortho(self) -> bool { diff --git a/crates/render/src/three_d/compose.rs b/crates/render/src/three_d/compose.rs index 20061f756..929b48d45 100644 --- a/crates/render/src/three_d/compose.rs +++ b/crates/render/src/three_d/compose.rs @@ -703,7 +703,7 @@ fn occlusion(c: &Item, p: Vec3, l: &LightState) -> [f32; 3] { /// A Classic 3D run prepared for an accelerator ([`Renderer::prepare_3d_run`]): every plane /// with its geometry, material and buffer, ready for the per-pixel depth sort, lighting and -/// ray-cast shadows of [`draw_run`] on another device. +/// ray-cast shadows of `draw_run` on another device. #[derive(Clone, Debug)] pub struct Run3d { /// Drawn planes in stack order, then shadow casters from outside the run (`draw` false). @@ -971,7 +971,7 @@ pub(crate) fn environment_rotation(ctx: &EvalCtx) -> f32 { .to_radians() as f32 } -/// An Environment Light Background layer ready to draw (see [`draw_sky`]): the layer's +/// An Environment Light Background layer ready to draw (see `draw_sky`): the layer's /// buffer in the blending space, its opacity and the camera's view rays. Also handed to an /// accelerator's compositor (`Renderer::sky_draw`). #[derive(Clone)] diff --git a/crates/render/src/three_d/mod.rs b/crates/render/src/three_d/mod.rs index bccfc3e05..f2cc1c70a 100644 --- a/crates/render/src/three_d/mod.rs +++ b/crates/render/src/three_d/mod.rs @@ -2,7 +2,7 @@ //! compositor for runs of 3D layers. //! //! The 2D compositor (`Renderer::comp_frame`) walks the layer stack bottom-to-top; each run of -//! consecutive 3D layers is handed to [`compose::draw_run`] as a group (2D layers break 3D +//! consecutive 3D layers is handed to `compose::draw_run` as a group (2D layers break 3D //! groups, as in After Effects). pub mod adv; diff --git a/crates/script/src/prelude.js b/crates/script/src/prelude.js index 5216db341..ce64e221b 100644 --- a/crates/script/src/prelude.js +++ b/crates/script/src/prelude.js @@ -420,7 +420,7 @@ function __callable(o) { delete f.length; Object.setPrototypeOf(f, Object.getPrototypeOf(o)); var keys = Object.keys(o); - for (var i = 0; i < keys.length; i++) f[keys[i]] = o[keys[i]]; + for (const elem of keys) f[elem] = o[elem]; var self = new Proxy(f, { get: __attr.get, apply: function (t, thisArg, args) { return self.property(args[0]); }, @@ -473,7 +473,7 @@ function MarkerValue(comment, chapter, url, frameTarget, cuePointName, params) { } MarkerValue.prototype.getParameters = function () { var o = {}; - for (var i = 0; i < this.__params.length; i++) o[this.__params[i][0]] = this.__params[i][1]; + for (const elem of this.__params) o[elem[0]] = elem[1]; return o; }; MarkerValue.prototype.setParameters = function (o) { @@ -513,8 +513,8 @@ TextDocument.prototype = { set text(v) { this.__text = String(v); this.__textSet = true; }, __style: function (k, d) { if (k in this.__changed) return this.__changed[k]; - if (this.__base && this.__base.first && k in this.__base.first) return this.__base.first[k]; - if (this.__base && this.__base.para && k in this.__base.para) return this.__base.para[k]; + if (this.__base?.first && k in this.__base.first) return this.__base.first[k]; + if (this.__base?.para && k in this.__base.para) return this.__base.para[k]; return d; }, __set: function (k, v) { this.__changed[k] = v; }, @@ -580,14 +580,14 @@ TextDocument.prototype = { }, get tsume() { return this.__style("tsume", 0); }, set tsume(v) { this.__set("tsume", __num(v)); }, - get boxText() { return !!(this.__base && this.__base.box_size); }, + get boxText() { return !!this.__base?.box_size; }, get pointText() { return !this.boxText; }, - get boxTextSize() { return this.__base && this.__base.box_size ? this.__base.box_size.slice() : undefined; }, + get boxTextSize() { return this.__base?.box_size ? this.__base.box_size.slice() : undefined; }, set boxTextSize(v) { var p = this.boxTextPos || [0, 0]; this.__set("box", [p[0], p[1], v[0], v[1]]); }, - get boxTextPos() { return this.__base && this.__base.box_size ? this.__base.box_pos.slice() : undefined; }, + get boxTextPos() { return this.__base?.box_size ? this.__base.box_pos.slice() : undefined; }, get startIndent() { return this.__style("indentLeft", 0); }, set startIndent(v) { this.__set("indentLeft", __num(v)); }, get endIndent() { return this.__style("indentRight", 0); }, @@ -665,7 +665,7 @@ PropertyBase.prototype = { get isMask() { return !!this.__info().isMask; }, get selected() { var c = __get("item", { id: this.__layer.__comp }).selectedProperties; - for (var i = 0; i < c.length; i++) if (c[i][0] === this.__layer.__id && c[i][1] === this.__uid) return true; + for (const elem of c) if (elem[0] === this.__layer.__id && elem[1] === this.__uid) return true; return false; }, set selected(v) { @@ -842,7 +842,7 @@ Property.prototype.property = function () { return null; }; i = __num(i, "keyIndex"); // Only the key asked for: fetching the whole list made every key call linear (#814). var r = i >= 1 && Math.floor(i) === i ? __get("keys", { comp: this.__layer.__comp, layer: this.__layer.__id, uid: this.__uid, index: i - 1 }) : null; - if (!r || !r.key) throw __err("keyIndex " + i + " is out of range 1.." + (r ? r.count : this.numKeys)); + if (!r?.key) throw __err("keyIndex " + i + " is out of range 1.." + (r ? r.count : this.numKeys)); return r.key; }; // Script value → engine JSON for `prop.set` / `prop.addKey`. @@ -853,13 +853,13 @@ Property.prototype.property = function () { return null; }; return __get("textdoc", { comp: this.__layer.__comp, layer: this.__layer.__id, uid: this.__uid, time: time, attrs: td.__attrs() }); } if (t === "SHAPE") { - if (!v || !v.vertices) throw __err("value must be a Shape"); + if (!v?.vertices) throw __err("value must be a Shape"); var n = v.vertices.length; - function fit(a) { var o = []; for (var i = 0; i < n; i++) o.push(a && a[i] ? [a[i][0], a[i][1]] : [0, 0]); return o; } + function fit(a) { var o = []; for (var i = 0; i < n; i++) o.push(a?.[i] ? [a[i][0], a[i][1]] : [0, 0]); return o; } return { vertices: fit(v.vertices), in_tangents: fit(v.inTangents), out_tangents: fit(v.outTangents), closed: v.closed !== false }; } if (t === "LAYER_INDEX") { - var idx = v && v.__id !== undefined ? v.index : __num(v); + var idx = v?.__id !== undefined ? v.index : __num(v); if (!idx) return null; return this.__layer.containingComp.layer(idx).__id; } @@ -1177,7 +1177,7 @@ Layer.prototype = { }, get selectedProperties() { var c = this.containingComp.__info().selectedProperties, out = []; - for (var i = 0; i < c.length; i++) if (c[i][0] === this.__id) out.push(__propOf(this, __get("node", { comp: this.__comp, layer: this.__id, uid: c[i][1] }))); + for (const elem of c) if (elem[0] === this.__id) out.push(__propOf(this, __get("node", { comp: this.__comp, layer: this.__id, uid: elem[1] }))); return out; }, get parent() { var p = this.__info().parent; return p === null ? null : __layer(this.__comp, p); }, @@ -1205,7 +1205,7 @@ Layer.prototype = { var before = this.containingComp.__info().layers; __call("edit.duplicate", this.__p()); var after = this.containingComp.__info().layers; - for (var i = 0; i < after.length; i++) if (before.indexOf(after[i]) < 0) return __layer(this.__comp, after[i]); + for (const elem of after) if (before.indexOf(elem) < 0) return __layer(this.__comp, elem); return null; }, copyToComp: function (comp) { @@ -1310,7 +1310,7 @@ AVLayer.prototype.constructor = AVLayer; // AVLayer.replaceSource). `fixExpressions` is accepted for compatibility: only AV sources are // replaced, so the property tree and the layer's name stay and expressions keep resolving. P.replaceSource = function (newSource, fixExpressions) { - if (!newSource || newSource.__id === undefined) throw __err("replaceSource needs a project item"); + if (newSource?.__id === undefined) throw __err("replaceSource needs a project item"); __call("layer.replaceSource", { comp: this.__comp, layers: [this.__id], item: newSource.__id, fixExpressions: !!fixExpressions }); return null; }; @@ -1371,7 +1371,7 @@ LayerCollection.prototype = { return layer; }, add: function (item, duration) { - if (!item || item.id === undefined) throw __err("add(): expected an item"); + if (item?.id === undefined) throw __err("add(): expected an item"); var l = this.__new(__call("layer.addItem", { comp: this.__comp, item: item.id, time: 0 })); return this.__dur(l, duration); }, @@ -1414,15 +1414,15 @@ LayerCollection.prototype = { }, precompose: function (indices, name, moveAllAttributes) { var ids = this.__ids(), sel = []; - for (var i = 0; i < indices.length; i++) sel.push(ids[indices[i] - 1]); + for (const elem of indices) sel.push(ids[elem - 1]); var r = __call("layer.precompose", { comp: this.__comp, layers: sel, name: String(name), mode: moveAllAttributes === false ? "leave" : "move" }); return __item(r.comp); }, byName: function (name) { var ids = this.__ids(); - for (var i = 0; i < ids.length; i++) { - var l = __get("layer", { comp: this.__comp, layer: ids[i] }); - if (l.name === name) return __layer(this.__comp, ids[i]); + for (const elem of ids) { + var l = __get("layer", { comp: this.__comp, layer: elem }); + if (l.name === name) return __layer(this.__comp, elem); } return null; }, @@ -1493,7 +1493,7 @@ Item.prototype = { get label() { return this.__info().label; }, set label(v) { __call("project.setLabel", { items: [this.__id], label: __num(v, "label") }); }, get parentFolder() { return __item(this.__info().parent); }, - set parentFolder(f) { __call("project.move", { items: [this.__id], folder: f && f.__id ? f.__id : null }); }, + set parentFolder(f) { __call("project.move", { items: [this.__id], folder: f?.__id ? f.__id : null }); }, get selected() { return this.__info().selected; }, set selected(v) { var selection = __get("project").selection; @@ -1527,7 +1527,7 @@ AVItem.prototype = Object.create(Item.prototype); def("hasVideo", function () { return this.__info().hasVideo; }); def("hasAudio", function () { return this.__info().hasAudio; }); def("footageMissing", function () { return !!this.__info().footageMissing; }); - def("useProxy", function () { var p = this.__info().proxy; return !!(p && p.enabled); }, function (v) { + def("useProxy", function () { var p = this.__info().proxy; return !!p?.enabled; }, function (v) { if (!this.__info().proxy) throw __err("\"" + this.name + "\" has no proxy"); __call("file.useProxy", { item: this.__id, on: !!v }); }); @@ -1564,9 +1564,9 @@ CompItem.prototype.constructor = CompItem; }); def("activeCamera", function () { var ids = this.__info().layers; - for (var i = 0; i < ids.length; i++) { - var l = __get("layer", { comp: this.__id, layer: ids[i] }); - if (l.kind === "camera" && l.enabled && l.active) return __layer(this.__id, ids[i]); + for (const elem of ids) { + var l = __get("layer", { comp: this.__id, layer: elem }); + if (l.kind === "camera" && l.enabled && l.active) return __layer(this.__id, elem); } return null; }); @@ -1606,7 +1606,7 @@ CompItem.prototype.constructor = CompItem; if (a < 1 || a > ids.length || Math.floor(a) !== a) throw __err("layer index " + a + " is out of range 1.." + ids.length); return __layer(this.__id, ids[a - 1]); } - if (a && a.__id !== undefined && typeof b === "number") { + if (a?.__id !== undefined && typeof b === "number") { var j = a.index + b; return j >= 1 && j <= ids.length ? __layer(this.__id, ids[j - 1]) : null; } @@ -1619,9 +1619,9 @@ CompItem.prototype.constructor = CompItem; P.__controllers = function () { var out = []; (function walk(list) { - for (var i = 0; i < list.length; i++) { - if (list[i].kind === "property" || list[i].kind === "mirror" || list[i].kind === "media") out.push(list[i]); - if (list[i].children) walk(list[i].children); + for (const elem of list) { + if (elem.kind === "property" || elem.kind === "mirror" || elem.kind === "media") out.push(elem); + if (elem.children) walk(elem.children); } })(this.__eg().controls); return out; @@ -1732,7 +1732,7 @@ FolderItem.prototype.constructor = FolderItem; Object.defineProperty(P, "numItems", { get: function () { return new ItemCollection(this.__id).length; } }); Object.defineProperty(P, "parentFolder", { get: function () { return this.__id === 0 ? null : __item(this.__info().parent); }, - set: function (f) { __call("project.move", { items: [this.__id], folder: f && f.__id ? f.__id : null }); }, + set: function (f) { __call("project.move", { items: [this.__id], folder: f?.__id ? f.__id : null }); }, }); P.item = function (i) { var v = new ItemCollection(this.__id).__at(__num(i, "index")); @@ -1776,7 +1776,7 @@ RenderQueueItem.prototype = { constructor: RenderQueueItem, __info: function () { var l = __call("renderQueue.list", {}).items; - for (var i = 0; i < l.length; i++) if (l[i].id === this.__id) return l[i]; + for (const elem of l) if (elem.id === this.__id) return elem; throw __err("the render queue item no longer exists"); }, get comp() { return __item(this.__info().comp); }, @@ -1812,7 +1812,7 @@ RenderQueueItem.prototype = { var before = __call("renderQueue.list", {}).items.map(function (i) { return i.id; }); __call("renderQueue.duplicate", { item: this.__id }); var after = __call("renderQueue.list", {}).items; - for (var i = 0; i < after.length; i++) if (before.indexOf(after[i].id) < 0) return new RenderQueueItem(after[i].id); + for (const elem of after) if (before.indexOf(elem.id) < 0) return new RenderQueueItem(elem.id); return null; }, applyTemplate: function () {}, @@ -1945,9 +1945,9 @@ Project.prototype = { } } var r = __call("file.import", args); - if (r.errors && r.errors.length) throw __err(r.errors.join("; ")); + if (r.errors?.length) throw __err(r.errors.join("; ")); // Composition imports create several footage items, but callers need the comp. - return __item(r.comps && r.comps.length ? r.comps[0] : r.items[0]); + return __item(r.comps?.length ? r.comps[0] : r.items[0]); }, importFileWithDialog: function () { return null; }, importPlaceholder: function (name, w, h, rate, dur) { diff --git a/crates/script/src/runtime.rs b/crates/script/src/runtime.rs index 192da5740..608c83d0e 100644 --- a/crates/script/src/runtime.rs +++ b/crates/script/src/runtime.rs @@ -710,7 +710,7 @@ pub(crate) fn outcome(output: Vec, result: Result) -> Ou /// don't block. /// /// ExtendScript's `#include` / `#includepath` are inlined first, and errors point at the file -/// and line they came from ([`crate::include`]). +/// and line they came from (`crate::include`). pub fn run(session: &mut Session, req: &ScriptRequest) -> Outcome { let expanded = match crate::include::expand(session, req.code, req.name) { Ok(x) => x, diff --git a/crates/script/src/scriptui.js b/crates/script/src/scriptui.js index 52c65efb6..4760d058b 100644 --- a/crates/script/src/scriptui.js +++ b/crates/script/src/scriptui.js @@ -213,7 +213,7 @@ function __uiResPlain(v) { if (v instanceof Array) return v.map(__uiResPlain); if (v && typeof v === "object" && v.__object) { var o = {}; - for (var k = 0; k < v.__object.length; k++) o[v.__object[k][0]] = __uiResPlain(v.__object[k][1]); + for (const elem of v.__object) o[elem[0]] = __uiResPlain(elem[1]); return o; } return v; @@ -222,8 +222,8 @@ function __uiResPlain(v) { // A resource's own properties and its child elements (in source order). function __uiResProps(res) { var props = {}, kids = []; - for (var k = 0; k < res.list.length; k++) { - var e = res.list[k]; + for (const elem2 of res.list) { + var e = elem2; if (e[1] && typeof e[1] === "object" && e[1].__element) kids.push([e[0], { type: e[1].__element, list: e[1].list }]); else props[e[0]] = __uiResPlain(e[1]); } @@ -239,17 +239,17 @@ function __uiApplyRes(c, res) { // Ranges before values, items before selections. if (props.minvalue !== undefined) c.minvalue = __num(props.minvalue); if (props.maxvalue !== undefined) c.maxvalue = __num(props.maxvalue); - if (props.items instanceof Array && c.items) for (var n = 0; n < props.items.length; n++) c.add("item", props.items[n]); + if (props.items instanceof Array && c.items) for (const elem of props.items) c.add("item", elem); for (var k in props) { if (__uiResSkip[k]) continue; var v = props[k]; if (__uiSizes[k] && v instanceof Array) v = __dim(v[0], v[1]); c[k] = v; } - for (var j = 0; j < pk.kids.length; j++) { - var child = __uiAddRes(c, pk.kids[j][1]); - child.__key = pk.kids[j][0]; - c[pk.kids[j][0]] = child; + for (const elem of pk.kids) { + var child = __uiAddRes(c, elem[1]); + child.__key = elem[0]; + c[elem[0]] = child; } return c; } @@ -268,7 +268,7 @@ Window.alert = function (s) { alert(s); }; Window.confirm = function (s) { return confirm(s); }; Window.prompt = function (m, d) { return prompt(m, d); }; Window.find = function (type, title) { - for (var i = 0; i < __uiWins.length; i++) if (__uiWins[i].text === title) return __uiWins[i]; + for (const elem of __uiWins) if (elem.text === title) return elem; return null; }; @@ -335,7 +335,7 @@ function __uiColor(c) { return null; } function __uiFontSize(f, g) { - var x = f && f.size !== undefined ? Number(f.size) : g && g.font && g.font.size !== undefined ? Number(g.font.size) : 12; + var x = f?.size !== undefined ? Number(f.size) : g?.font && g.font.size !== undefined ? Number(g.font.size) : 12; return x > 0 ? x : 12; } @@ -371,11 +371,11 @@ function __uiGraphics() { this.__push({ op: "fill", color: brush ? brush.color : null, path: (path || this.currentPath).slice() }); }, strokePath: function (pen, path) { - this.__push({ op: "stroke", color: pen ? pen.color : null, width: pen && pen.lineWidth !== undefined ? pen.lineWidth : 1, path: (path || this.currentPath).slice() }); + this.__push({ op: "stroke", color: pen ? pen.color : null, width: pen?.lineWidth !== undefined ? pen.lineWidth : 1, path: (path || this.currentPath).slice() }); }, drawString: function (text, pen, x, y, font) { var f = font || this.font; - this.__push({ op: "text", text: String(text), color: pen ? pen.color : null, x: __num(x || 0), y: __num(y || 0), size: __uiFontSize(f, this), style: String(f && f.style !== undefined ? f.style : "") }); + this.__push({ op: "text", text: String(text), color: pen ? pen.color : null, x: __num(x || 0), y: __num(y || 0), size: __uiFontSize(f, this), style: String(f?.style !== undefined ? f.style : "") }); }, drawOSControl: function () { this.__push({ op: "os" }); }, drawImage: function (img, x, y, w, h) { this.__push({ op: "image", image: __uiImageJson(img), x: __num(x || 0), y: __num(y || 0), w: w === undefined ? 0 : __num(w), h: h === undefined ? 0 : __num(h) }); }, @@ -384,7 +384,7 @@ function __uiGraphics() { var size = __uiFontSize(font, this); var lines = String(s).split("\n"); var cw = size * 0.58, w = 0; - for (var i = 0; i < lines.length; i++) w = Math.max(w, Math.ceil(lines[i].length * cw)); + for (const elem of lines) w = Math.max(w, Math.ceil(elem.length * cw)); var n = lines.length; if (boundaryWidth > 0 && w > boundaryWidth) { n = Math.ceil(w / boundaryWidth) + lines.length - 1; @@ -405,14 +405,14 @@ function __uiRunDraws(win) { })(win); if (!drawn.length) return; __uiLayout(win); - for (var k = 0; k < drawn.length; k++) { - var c = drawn[k]; + for (const elem of drawn) { + var c = elem; c.__draw = []; c.graphics.__rec = c.__draw; try { c.onDraw.call(c, { type: "draw", target: c }); } catch (e) { - try { writeLn("onDraw: " + (e && e.message ? e.message : e)); } catch (e2) {} + try { writeLn("onDraw: " + (e?.message ? e.message : e)); } catch (e2) {} } c.graphics.__rec = null; } @@ -498,7 +498,7 @@ function __uiProto() { var arg = t === "image" || t === "iconbutton" ? text : typeof text === "object" && text !== null && !(text instanceof Array) ? "" : text; __uiInit(c, t, this.window, this, bounds, arg, props); if ((t === "dropdownlist" || t === "listbox") && text instanceof Array) { - for (var i = 0; i < text.length; i++) c.add("item", text[i]); + for (const elem of text) c.add("item", elem); c.text = ""; } if (t === "slider" || t === "scrollbar") { @@ -521,7 +521,7 @@ function __uiProto() { if (t === "checkbox" || t === "radiobutton") c.value = false; if (t === "edittext" && c.properties.multiline) c.__multiline = true; if (t === "edittext" && c.properties.readonly) c.__readonly = true; - if (c.properties && c.properties.name) c.name = c.properties.name; + if (c.properties?.name) c.name = c.properties.name; this.children.push(c); if (t === "tab" && this.type === "tabbedpanel" && this.__sel.length === 0) this.__sel = [this.children.length - 1]; return c; @@ -608,21 +608,21 @@ function __uiProto() { removeEventListener: function (name, fn, capture) { var k = String(name).toLowerCase(); var m = capture ? this.__capture : this.__listeners; - if (m && m[k]) m[k] = m[k].filter(function (f) { return f !== fn; }); + if (m?.[k]) m[k] = m[k].filter(function (f) { return f !== fn; }); }, dispatchEvent: function (e) { this.__fire("on" + String(e.type || e).charAt(0).toUpperCase() + String(e.type || e).slice(1)); }, __fire: function (name) { var r; if (typeof this[name] === "function") r = this[name].call(this); var l = this.__listeners[name.slice(2).toLowerCase()]; - if (l) for (var i = 0; i < l.length; i++) l[i].call(this, { type: name.slice(2).toLowerCase(), target: this }); + if (l) for (const elem of l) elem.call(this, { type: name.slice(2).toLowerCase(), target: this }); return r; }, __handlers: function () { var out = []; var names = ["onClick", "onChange", "onChanging", "onDoubleClick", "onClose", "onShow", "onActivate", "onDeactivate", "onResize", "onDraw"]; - for (var i = 0; i < names.length; i++) { - var n = names[i]; + for (const elem of names) { + var n = elem; if (typeof this[n] === "function" || (this.__listeners[n.slice(2).toLowerCase()] || []).length) out.push(n); } return out; @@ -634,8 +634,8 @@ function __uiProto() { (function () { var all = ["Window", "Panel", "Group", "Button", "IconButton", "StaticText", "EditText", "Checkbox", "RadioButton", "Slider", "Scrollbar", "Progressbar", "DropDownList", "ListBox", "TabbedPanel", "Tab", "ScriptUIImage"]; - for (var i = 0; i < all.length; i++) { - var C = __ecGlobal[all[i]]; + for (const elem of all) { + var C = __ecGlobal[elem]; var p = __uiProto(); for (var k in p) C.prototype[k] = p[k]; Object.defineProperty(C.prototype, "bounds", { @@ -737,8 +737,8 @@ function __uiMouseListeners(c, type, capture) { // The mouse events that reach a listener at `c`: its own, and its containers' (`inherited`). function __uiMouseWanted(c, inherited) { var out = inherited.slice(); - for (var i = 0; i < __uiMouseKinds.length; i++) { - var t = __uiMouseKinds[i]; + for (const elem of __uiMouseKinds) { + var t = elem; if (out.indexOf(t) < 0 && (__uiMouseListeners(c, t, false).length || __uiMouseListeners(c, t, true).length)) out.push(t); } return out; @@ -793,7 +793,7 @@ function __uiMouseFire(target, type, v) { var l = __uiMouseListeners(c, type, capture); e.currentTarget = c; e.eventPhase = phase; - for (var i = 0; i < l.length; i++) if (typeof l[i] === "function") l[i].call(c, e); + for (const elem of l) if (typeof elem === "function") elem.call(c, e); }; var n = path.length - 1; for (var i = 0; i < n; i++) { @@ -832,7 +832,7 @@ function __uiJson(c, inherited) { if (m) o.margins = m; if (typeof c.spacing === "number") o.spacing = c.spacing; var kids = c.children; - for (var i = 0; i < kids.length; i++) o.children.push(__uiJson(kids[i], mouse)); + for (const elem of kids) o.children.push(__uiJson(elem, mouse)); } if (c.alignment !== null && c.alignment !== undefined) o.alignment = __uiAlign(c.alignment); if (c.type === "checkbox" || c.type === "radiobutton") o.checked = !!c.value; @@ -859,8 +859,8 @@ function __uiJson(c, inherited) { // The open windows of this script, for the host. function __uiSnapshot() { var out = []; - for (var i = 0; i < __uiWins.length; i++) { - var w = __uiWins[i]; + for (const elem of __uiWins) { + var w = elem; if (w.__shown && !w.__closed) __uiRunDraws(w); out.push({ id: w.__wid, kind: w.__kind, title: String(w.text || ""), visible: !!w.__shown && !w.__closed, modal: !!w.__modal, root: __uiJson(w) }); } @@ -871,12 +871,12 @@ function __uiSnapshot() { function __uiOpenCount() { var n = 0; - for (var i = 0; i < __uiWins.length; i++) if (__uiWins[i].__shown && !__uiWins[i].__closed) n++; + for (const elem of __uiWins) if (elem.__shown && !elem.__closed) n++; return n; } function __uiWin(id) { - for (var i = 0; i < __uiWins.length; i++) if (__uiWins[i].__wid === id) return __uiWins[i]; + for (const elem of __uiWins) if (elem.__wid === id) return elem; return null; } function __uiFind(c, id) { @@ -914,7 +914,7 @@ function __uiDispatch(winId, id, kind, valueJson) { if (!c || c.enabled === false) return; var radio = function () { var sib = c.parent ? c.parent.children : []; - for (var i = 0; i < sib.length; i++) if (sib[i] !== c && sib[i].type === "radiobutton") sib[i].value = false; + for (const elem of sib) if (elem !== c && elem.type === "radiobutton") elem.value = false; c.value = true; }; // A mouse click carries the pointer's details ({x, y, button, detail, …keys}). diff --git a/crates/script/src/socket.rs b/crates/script/src/socket.rs index 9d1f87989..6b2976dc1 100644 --- a/crates/script/src/socket.rs +++ b/crates/script/src/socket.rs @@ -89,7 +89,7 @@ mod imp { Sock::Listener(_) => None, }; let entry = Arc::new(Entry { sock: Mutex::new(s), wake, closed: AtomicBool::new(false) }); - let mut t = table().lock().unwrap_or_else(|e| e.into_inner()); + let mut t = table().lock().unwrap_or_else(std::sync::PoisonError::into_inner); let id = t.next; t.next += 1; t.socks.insert(id, entry); @@ -98,12 +98,12 @@ mod imp { /// The socket `id`, if open. The table is locked only for the lookup. fn get(id: u32) -> Option> { - table().lock().unwrap_or_else(|e| e.into_inner()).socks.get(&id).cloned() + table().lock().unwrap_or_else(std::sync::PoisonError::into_inner).socks.get(&id).cloned() } /// Forget socket `id`; a call blocked on it fails at once. fn close(id: u32) { - let entry = table().lock().unwrap_or_else(|e| e.into_inner()).socks.remove(&id); + let entry = table().lock().unwrap_or_else(std::sync::PoisonError::into_inner).socks.remove(&id); if let Some(entry) = entry { entry.closed.store(true, Ordering::Release); if let Some(w) = &entry.wake { @@ -261,7 +261,7 @@ mod imp { _ => err("the socket is not open"), }; }; - let mut sock = entry.sock.lock().unwrap_or_else(|e| e.into_inner()); + let mut sock = entry.sock.lock().unwrap_or_else(std::sync::PoisonError::into_inner); // Recheck after locking: close or a failed mode transition may have retired it // while this caller waited with an Arc obtained from the table. if entry.closed.load(Ordering::Acquire) { diff --git a/crates/segment/Cargo.toml b/crates/segment/Cargo.toml index 98f3d1a14..515635db5 100644 --- a/crates/segment/Cargo.toml +++ b/crates/segment/Cargo.toml @@ -10,6 +10,6 @@ rust-version.workspace = true workspace = true [dependencies] -miniz_oxide = "0.8" +miniz_oxide = "0.9" ndarray = { version = "0.17", default-features = false, features = ["std"] } rayon = { workspace = true } diff --git a/crates/text/src/font_dirs.rs b/crates/text/src/font_dirs.rs index 0561d8f84..30694946b 100644 --- a/crates/text/src/font_dirs.rs +++ b/crates/text/src/font_dirs.rs @@ -150,7 +150,9 @@ impl Reader<'_> { let mut files: Vec = rd .flatten() .map(|e| e.path()) - .filter(|p| p.file_name().and_then(|n| n.to_str()).is_some_and(|n| n.ends_with(".conf") && n.starts_with(|c: char| c.is_ascii_digit()))) + .filter(|p| { + p.file_name().and_then(std::ffi::OsStr::to_str).is_some_and(|n| n.ends_with(".conf") && n.starts_with(|c: char| c.is_ascii_digit())) + }) .collect(); files.sort(); for f in files { diff --git a/crates/text/src/fonts.rs b/crates/text/src/fonts.rs index 724fc4aaf..e20ffcbd1 100644 --- a/crates/text/src/fonts.rs +++ b/crates/text/src/fonts.rs @@ -116,7 +116,7 @@ fn walk(dir: &std::path::Path, depth: u32, out: &mut Vec) { if depth < 8 { walk(&p, depth + 1, out); } - } else if p.extension().and_then(|x| x.to_str()).is_some_and(|x| matches!(x.to_ascii_lowercase().as_str(), "ttf" | "otf" | "ttc" | "otc")) { + } else if p.extension().and_then(std::ffi::OsStr::to_str).is_some_and(|x| matches!(x.to_ascii_lowercase().as_str(), "ttf" | "otf" | "ttc" | "otc")) { out.push(p); } } @@ -319,7 +319,7 @@ fn push(db: &mut Db, info: FaceInfo) -> FaceId { /// added. pub fn add_source(src: &dyn FontSource) -> usize { let faces = src.faces(); - let mut d = db().write().unwrap_or_else(|e| e.into_inner()); + let mut d = db().write().unwrap_or_else(std::sync::PoisonError::into_inner); let mut n = 0; for f in faces { let dup = d.faces.iter().any(|g| g.info.family.eq_ignore_ascii_case(&f.family) && g.info.style.eq_ignore_ascii_case(&f.style)); @@ -329,7 +329,7 @@ pub fn add_source(src: &dyn FontSource) -> usize { } } // A new face can belong to one of a script's usual families. - family_faces_cache().write().unwrap_or_else(|e| e.into_inner()).clear(); + family_faces_cache().write().unwrap_or_else(std::sync::PoisonError::into_inner).clear(); n } @@ -337,9 +337,9 @@ pub fn add_source(src: &dyn FontSource) -> usize { pub fn add_font_data(data: Vec) -> Vec { let data = Arc::new(data); let names = read_faces_bytes(&data); - let mut d = db().write().unwrap_or_else(|e| e.into_inner()); + let mut d = db().write().unwrap_or_else(std::sync::PoisonError::into_inner); let ids = names.into_iter().map(|n| push(&mut d, info_from(n, FaceData::Shared(data.clone()), "user"))).collect(); - family_faces_cache().write().unwrap_or_else(|e| e.into_inner()).clear(); + family_faces_cache().write().unwrap_or_else(std::sync::PoisonError::into_inner).clear(); ids } @@ -353,21 +353,21 @@ pub fn scan_system() -> usize { if system_scanned() { return 0; } - let _scan = SCAN.lock().unwrap_or_else(|e| e.into_inner()); + let _scan = SCAN.lock().unwrap_or_else(std::sync::PoisonError::into_inner); if system_scanned() { return 0; } let n = if cfg!(target_arch = "wasm32") { 0 } else { add_source(&DirectorySource::system()) }; - db().write().unwrap_or_else(|e| e.into_inner()).scanned = true; + db().write().unwrap_or_else(std::sync::PoisonError::into_inner).scanned = true; n } /// Scan the system font folders again, adding fonts installed since the last scan (faces already /// known are kept, so font ids stay valid). Returns the number of faces added. pub fn rescan_system() -> usize { - let _scan = SCAN.lock().unwrap_or_else(|e| e.into_inner()); + let _scan = SCAN.lock().unwrap_or_else(std::sync::PoisonError::into_inner); let n = if cfg!(target_arch = "wasm32") { 0 } else { add_source(&DirectorySource::system()) }; - db().write().unwrap_or_else(|e| e.into_inner()).scanned = true; + db().write().unwrap_or_else(std::sync::PoisonError::into_inner).scanned = true; n } @@ -388,12 +388,12 @@ pub fn scan_system_in_background() { } pub fn system_scanned() -> bool { - db().read().unwrap_or_else(|e| e.into_inner()).scanned + db().read().unwrap_or_else(std::sync::PoisonError::into_inner).scanned } /// A face by id (panics never: unknown ids give the default face). pub fn face(id: FaceId) -> Arc { - let d = db().read().unwrap_or_else(|e| e.into_inner()); + let d = db().read().unwrap_or_else(std::sync::PoisonError::into_inner); // The bundled fonts are compiled in and always parse (`tests::bundled_families_and_resolution` checks them), so // the database is never empty. #[allow(clippy::expect_used)] @@ -402,7 +402,7 @@ pub fn face(id: FaceId) -> Arc { /// All faces (bundled first). pub fn all_faces() -> Vec> { - db().read().unwrap_or_else(|e| e.into_inner()).faces.clone() + db().read().unwrap_or_else(std::sync::PoisonError::into_inner).faces.clone() } /// Family names in the fonts' own languages: English family → native family (only families @@ -743,15 +743,15 @@ static REQUESTED_CJK_LOCALE: RwLock> = RwLock::new(None); pub fn set_cjk_locale(tag: &str) { let tag = tag.trim().to_ascii_lowercase(); let requested = if tag.is_empty() || tag == "c" || tag == "posix" { None } else { Some(tag) }; - *REQUESTED_CJK_LOCALE.write().unwrap_or_else(|e| e.into_inner()) = requested; + *REQUESTED_CJK_LOCALE.write().unwrap_or_else(std::sync::PoisonError::into_inner) = requested; // The order of the CJK families follows the language, so a change of language drops the cached // fallbacks. - fallback_cache().write().unwrap_or_else(|e| e.into_inner()).clear(); - family_faces_cache().write().unwrap_or_else(|e| e.into_inner()).clear(); + fallback_cache().write().unwrap_or_else(std::sync::PoisonError::into_inner).clear(); + family_faces_cache().write().unwrap_or_else(std::sync::PoisonError::into_inner).clear(); } fn requested_cjk_locale() -> Option { - REQUESTED_CJK_LOCALE.read().unwrap_or_else(|e| e.into_inner()).clone() + REQUESTED_CJK_LOCALE.read().unwrap_or_else(std::sync::PoisonError::into_inner).clone() } /// The CJK locale to use: [`set_cjk_locale`] when the host asked for one, otherwise the locale @@ -981,7 +981,7 @@ fn fallback_with_locale(c: char, prefer: FaceId, locale: impl FnOnce() -> CjkLoc } } let key = (c as u32 >> 8, prefer); - if let Some(cached) = fallback_cache().read().unwrap_or_else(|e| e.into_inner()).get(&key).copied() { + if let Some(cached) = fallback_cache().read().unwrap_or_else(std::sync::PoisonError::into_inner).get(&key).copied() { match cached { Some(id) if face(id).has_char(c) => return id, Some(_) => {} @@ -992,7 +992,7 @@ fn fallback_with_locale(c: char, prefer: FaceId, locale: impl FnOnce() -> CjkLoc scan_system(); } let found = system_fallback(c, &p.info.style); - fallback_cache().write().unwrap_or_else(|e| e.into_inner()).insert(key, found); + fallback_cache().write().unwrap_or_else(std::sync::PoisonError::into_inner).insert(key, found); found.unwrap_or(prefer) } @@ -1000,7 +1000,7 @@ fn fallback_with_locale(c: char, prefer: FaceId, locale: impl FnOnce() -> CjkLoc /// for `script`, in the order they are tried, each in the style of `prefer`. For CJK, the other CJK /// languages' families follow in the locale's order. fn family_faces(script: FallbackScript, prefer: &Face, locale: CjkLocale) -> Arc> { - if let Some(faces) = family_faces_cache().read().unwrap_or_else(|e| e.into_inner()).get(&(script, prefer.id, locale)) { + if let Some(faces) = family_faces_cache().read().unwrap_or_else(std::sync::PoisonError::into_inner).get(&(script, prefer.id, locale)) { return faces.clone(); } let order: Vec = match script { @@ -1016,7 +1016,7 @@ fn family_faces(script: FallbackScript, prefer: &Face, locale: CjkLocale) -> Arc let style = &prefer.info.style; let faces: Arc> = Arc::new(order.into_iter().flat_map(|s| families_for(s, locale)).filter_map(|fam| resolve_in(fam, style)).map(|r| r.face).collect()); - family_faces_cache().write().unwrap_or_else(|e| e.into_inner()).insert((script, prefer.id, locale), faces.clone()); + family_faces_cache().write().unwrap_or_else(std::sync::PoisonError::into_inner).insert((script, prefer.id, locale), faces.clone()); faces } diff --git a/crates/text/src/layout.rs b/crates/text/src/layout.rs index 7ca5bd13a..0730e4442 100644 --- a/crates/text/src/layout.rs +++ b/crates/text/src/layout.rs @@ -399,7 +399,7 @@ enum Form { pub fn feature_substitutes(face: FaceId, tag: &[u8; 4], c: char) -> bool { static C: OnceLock>> = OnceLock::new(); let cache = C.get_or_init(Default::default); - if let Some(v) = cache.lock().unwrap_or_else(|e| e.into_inner()).get(&(face, *tag, c)) { + if let Some(v) = cache.lock().unwrap_or_else(std::sync::PoisonError::into_inner).get(&(face, *tag, c)) { return *v; } let f = fonts::face(face); @@ -419,7 +419,7 @@ pub fn feature_substitutes(face: FaceId, tag: &[u8; 4], c: char) -> bool { } _ => false, }; - let mut m = cache.lock().unwrap_or_else(|e| e.into_inner()); + let mut m = cache.lock().unwrap_or_else(std::sync::PoisonError::into_inner); if m.len() > 100_000 { m.clear(); } @@ -1123,12 +1123,12 @@ pub fn layout_rich(text: &str, runs: &[(Range, TextStyle)], paras: &[Para let key = h.finish(); static CLOCK: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0); let now = CLOCK.fetch_add(1, std::sync::atomic::Ordering::Relaxed); - if let Some(e) = cache().lock().unwrap_or_else(|e| e.into_inner()).get_mut(&key) { + if let Some(e) = cache().lock().unwrap_or_else(std::sync::PoisonError::into_inner).get_mut(&key) { e.0 = now; return e.1.clone(); } let l = Arc::new(layout_rich_uncached(text, runs, paras)); - let mut c = cache().lock().unwrap_or_else(|e| e.into_inner()); + let mut c = cache().lock().unwrap_or_else(std::sync::PoisonError::into_inner); if c.len() >= 512 { // evict the oldest quarter let mut ages: Vec = c.values().map(|v| v.0).collect(); diff --git a/crates/text/src/lib.rs b/crates/text/src/lib.rs index 187167527..35e7ecc06 100644 --- a/crates/text/src/lib.rs +++ b/crates/text/src/lib.rs @@ -54,7 +54,7 @@ impl OutlinePen for Pen { pub(crate) fn outline_units(face: FaceId, gid: u32) -> Option> { static C: OnceLock>>>> = OnceLock::new(); let c = C.get_or_init(Default::default); - if let Some(v) = c.lock().unwrap_or_else(|e| e.into_inner()).get(&(face, gid)) { + if let Some(v) = c.lock().unwrap_or_else(std::sync::PoisonError::into_inner).get(&(face, gid)) { return v.clone(); } let f = fonts::face(face); @@ -64,7 +64,7 @@ pub(crate) fn outline_units(face: FaceId, gid: u32) -> Option> { g.draw(DrawSettings::unhinted(Size::unscaled(), LocationRef::default()), &mut pen).ok()?; Some(Arc::new(pen.0)) }); - let mut m = c.lock().unwrap_or_else(|e| e.into_inner()); + let mut m = c.lock().unwrap_or_else(std::sync::PoisonError::into_inner); if m.len() > 50_000 { m.clear(); } diff --git a/crates/text/src/variable.rs b/crates/text/src/variable.rs index bf4fde39e..559343352 100644 --- a/crates/text/src/variable.rs +++ b/crates/text/src/variable.rs @@ -36,7 +36,7 @@ pub fn intern(coords: &[(String, f32)]) -> u32 { if key.windows(2).any(|w| w[0].0 == w[1].0) { return 0; } - let mut t = table().lock().unwrap_or_else(|e| e.into_inner()); + let mut t = table().lock().unwrap_or_else(std::sync::PoisonError::into_inner); if let Some(id) = t.by_coords.get(&key) { return *id; } @@ -55,7 +55,7 @@ pub fn coords(id: u32) -> Arc> { if id == 0 { return Arc::new(Vec::new()); } - table().lock().unwrap_or_else(|e| e.into_inner()).values.get(id as usize - 1).cloned().unwrap_or_default() + table().lock().unwrap_or_else(std::sync::PoisonError::into_inner).values.get(id as usize - 1).cloned().unwrap_or_default() } fn table() -> &'static Mutex { @@ -109,7 +109,7 @@ pub fn outline_units_at(face: FaceId, gid: u32, coords: &[(String, f32)]) -> Opt let c = C.get_or_init(Default::default); // Quantise to 1/100 of a unit so animation frames reuse outlines. let key: Key = (face, gid, coords.iter().map(|(t, v)| (t.clone(), (v * 100.0).round() as i32)).collect()); - if let Some(v) = c.lock().unwrap_or_else(|e| e.into_inner()).get(&key) { + if let Some(v) = c.lock().unwrap_or_else(std::sync::PoisonError::into_inner).get(&key) { return v.clone(); } let f = fonts::face(face); @@ -120,7 +120,7 @@ pub fn outline_units_at(face: FaceId, gid: u32, coords: &[(String, f32)]) -> Opt g.draw(DrawSettings::unhinted(Size::unscaled(), LocationRef::from(&loc)), &mut pen).ok()?; Some(Arc::new(pen.0)) }); - let mut m = c.lock().unwrap_or_else(|e| e.into_inner()); + let mut m = c.lock().unwrap_or_else(std::sync::PoisonError::into_inner); if m.len() > 20_000 { m.clear(); } diff --git a/crates/ui-egui/Cargo.toml b/crates/ui-egui/Cargo.toml index 009a2c6e6..ede0196e2 100644 --- a/crates/ui-egui/Cargo.toml +++ b/crates/ui-egui/Cargo.toml @@ -33,6 +33,9 @@ kurbo = { workspace = true } image = { 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-update = { workspace = true } sys-locale = { workspace = true } [dev-dependencies] @@ -40,7 +43,7 @@ sys-locale = { workspace = true } # here documents the requirement (kittest's own dev-dependencies do not propagate to consumers). egui = { workspace = true, features = ["default_fonts", "monochrome_emoji_fonts"] } egui_kittest = { workspace = true, features = ["eframe", "wgpu"] } -pollster = "0.4" +pollster = "1" effectcraft-host = { workspace = true } exr = { workspace = true } diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rs index 29fe4e661..e535cc723 100644 --- a/crates/ui-egui/src/control.rs +++ b/crates/ui-egui/src/control.rs @@ -404,7 +404,7 @@ fn panel(app: &mut EffectcraftApp, method: &str, p: &Value) -> Outcome { if method == "ui.panel.show" { app.show_panel(panel); } else { - app.ui.dock.close(panel); + app.close_panel(panel); } ok(Value::Null) } diff --git a/crates/ui-egui/src/dock.rs b/crates/ui-egui/src/dock.rs index 268ed9416..054aa3598 100644 --- a/crates/ui-egui/src/dock.rs +++ b/crates/ui-egui/src/dock.rs @@ -1,11 +1,14 @@ -//! Docking: a tree of splits and tab groups. Panels are rounded frames separated by -//! thin gutters; each group has a tab strip (active tab bright, with a panel menu "≡"); the focused -//! panel gets a blue outline. Gutters drag to resize; workspaces are serialized trees. +//! 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). use egui::{Align2, Rect, Sense, Stroke, pos2, vec2}; use serde::{Deserialize, Serialize}; -use craft_ui::layout::{ResizeHandle, ResizeHandleStyle, SplitAxis, SplitSize as SharedSplitSize, split_rect}; +pub use craft_ui::docking::{Floating, Node, PanelState, Permissions, StackEntry}; +pub use craft_ui::layout::{SplitAxis, SplitSize}; use crate::icons::{self, Icon}; use crate::theme::Tokens; @@ -161,117 +164,39 @@ impl PanelKind { } } -#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)] -pub enum SplitSize { - Ratio(f32), - /// First child has a fixed size in points. - FixedA(f32), - /// Second child has a fixed size in points. - FixedB(f32), +/// The docked tree plus floating windows. +pub type Layout = craft_ui::docking::Layout; +/// What a workspace saves: the layout, closed panels with where each goes back, and the lock. +pub type Workspace = craft_ui::docking::Workspace; + +/// 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 +/// docked is checked per transaction ([`crate::dock_ui`]). +pub fn permissions(_panel: &PanelKind) -> Permissions { + Permissions::default() } -impl SplitSize { - fn shared(self) -> SharedSplitSize { - match self { - Self::Ratio(value) => SharedSplitSize::Ratio(value), - Self::FixedA(value) => SharedSplitSize::FixedFirst(value), - Self::FixedB(value) => SharedSplitSize::FixedSecond(value), - } - } +/// A tab group. +pub fn tabs(p: &[PanelKind], active: usize) -> Node { + Node::Tabs { panels: 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). +pub fn stack(e: &[(PanelKind, bool, Option)]) -> Node { + Node::Stack { entries: e.iter().map(|&(panel, open, height)| StackEntry { panel, open, height }).collect() } +} +/// Two frames side by side. +pub fn hsplit(size: SplitSize, a: Node, b: Node) -> Node { + Node::Split { axis: SplitAxis::Horizontal, size, first: Box::new(a), second: Box::new(b) } +} +/// Two frames one above the other. +pub fn vsplit(size: SplitSize, a: Node, b: Node) -> Node { + Node::Split { axis: SplitAxis::Vertical, size, first: Box::new(a), second: Box::new(b) } } -/// One frame in a [`DockNode::Stack`]: a header with one tab per panel (a panel dropped onto a -/// stacked panel joins its frame as a tab, as in After Effects). -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] -#[serde(from = "StackEntryRepr")] -pub struct StackEntry { - pub panels: Vec, - /// The shown tab. - pub active: usize, - pub open: bool, - /// Content height when open (set by dragging the gaps); `None` = share the remaining height. - pub height: Option, -} - -/// A saved [`StackEntry`]: workspaces saved before stacked frames held tabs name one `panel`. -#[derive(Deserialize)] -struct StackEntryRepr { - #[serde(default)] - panel: Option, - #[serde(default)] - panels: Vec, - #[serde(default)] - active: usize, - open: bool, - #[serde(default)] - height: Option, -} - -impl From for StackEntry { - fn from(r: StackEntryRepr) -> StackEntry { - let mut panels = r.panels; - if let Some(p) = r.panel - && !panels.contains(&p) - { - panels.insert(0, p); - } - let active = r.active.min(panels.len().saturating_sub(1)); - StackEntry { panels, active, open: r.open, height: r.height } - } -} - -impl StackEntry { - /// A frame showing just `panel`. - pub fn new(panel: PanelKind, open: bool, height: Option) -> StackEntry { - StackEntry { panels: vec![panel], active: 0, open, height } - } - pub fn contains(&self, p: PanelKind) -> bool { - self.panels.contains(&p) - } - /// The frame's shown panel. - pub fn shown(&self) -> Option { - self.panels.get(self.active).or(self.panels.first()).copied() - } - /// Show `p` (one of its tabs). - fn show(&mut self, p: PanelKind) { - if let Some(i) = self.panels.iter().position(|x| *x == p) { - self.active = i; - } - } -} - -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] -pub enum DockNode { - /// `vertical`: children stacked top/bottom; else side by side. - Split { - vertical: bool, - size: SplitSize, - a: Box, - b: Box, - }, - Tabs { - panels: Vec, - active: usize, - }, - /// After Effects' stacked panels (e.g. the Default workspace's right column): each panel has - /// a header row; clicking it expands or collapses the panel in place, and dragging the gap - /// between two open panels resizes them. - Stack { - entries: Vec, - }, -} - -fn tabs(p: &[PanelKind], active: usize) -> DockNode { - DockNode::Tabs { panels: p.to_vec(), active } -} -fn stack(e: &[(PanelKind, bool, Option)]) -> DockNode { - DockNode::Stack { entries: e.iter().map(|&(panel, open, height)| StackEntry::new(panel, open, height)).collect() } -} -fn hsplit(size: SplitSize, a: DockNode, b: DockNode) -> DockNode { - DockNode::Split { vertical: false, size, a: Box::new(a), b: Box::new(b) } -} -fn vsplit(size: SplitSize, a: DockNode, b: DockNode) -> DockNode { - DockNode::Split { vertical: true, size, a: Box::new(a), b: Box::new(b) } +/// A workspace of just `root`, with no floating windows. +pub fn docked(root: Node) -> Workspace { + Workspace::new(Layout { root: Some(root), floating: Vec::new() }) } /// The built-in workspaces: After Effects 2026's (Window ▸ Workspace), less Libraries (an Adobe @@ -296,24 +221,36 @@ pub const WORKSPACES: &[&str] = &[ "Undocked Panels", ]; -/// The floating panels a workspace starts with (Undocked Panels), in points for a window of -/// about 1680×1020 (they are kept inside the window when drawn). -pub fn workspace_floating(name: &str) -> Vec { +/// The floating windows a workspace starts with (Undocked Panels), in points for a window of +/// about 1680×1020 (craft-ui keeps them inside the window when drawn). Each window has a fixed +/// id, so a built-in layout built again is the same set of windows. +fn workspace_floating(name: &str) -> Vec> { use PanelKind::*; - let f = |panels: &[PanelKind], rect: [f32; 4]| Floating { panels: panels.to_vec(), active: 0, rect }; + let f = |id: u64, panels: &[PanelKind], rect: [f32; 4]| Floating::single(panels.to_vec(), 0, rect).with_id(id); match name { "Undocked Panels" => vec![ - f(&[Project, EffectControls], [24.0, 110.0, 320.0, 420.0]), - f(&[Preview, Info, Audio], [1330.0, 110.0, 320.0, 300.0]), - f(&[EffectsPresets, Properties, Character, Paragraph], [1330.0, 430.0, 320.0, 360.0]), - f(&[Timeline, RenderQueue], [24.0, 640.0, 1280.0, 340.0]), + f(1, &[Project, EffectControls], [24.0, 110.0, 320.0, 420.0]), + f(2, &[Preview, Info, Audio], [1330.0, 110.0, 320.0, 300.0]), + f(3, &[EffectsPresets, Properties, Character, Paragraph], [1330.0, 430.0, 320.0, 360.0]), + f(4, &[Timeline, RenderQueue], [24.0, 640.0, 1280.0, 340.0]), ], _ => vec![], } } -/// The default layout of a named workspace. -pub fn workspace(name: &str) -> DockNode { +/// The height of a frame's tab strip ([`Tokens::tab_h`]). +pub const TAB_STRIP: f32 = 30.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) } +} + +/// The docked tree of a named workspace. +fn workspace_root(name: &str) -> Node { use PanelKind::*; use SplitSize::*; let right = |p: &[PanelKind], q: &[PanelKind]| vsplit(Ratio(0.45), tabs(p, 0), tabs(q, 0)); @@ -321,45 +258,45 @@ pub fn workspace(name: &str) -> DockNode { "Animation" => vsplit( Ratio(0.55), hsplit( - FixedA(300.0), + FixedFirst(300.0), tabs(&[Project, EffectControls], 1), - hsplit(FixedB(300.0), tabs(&[Composition, Layer], 0), right(&[Info, Preview, Audio], &[EffectsPresets, Smoother, Wiggler, MotionSketch])), + hsplit(FixedSecond(300.0), tabs(&[Composition, Layer], 0), right(&[Info, Preview, Audio], &[EffectsPresets, Smoother, Wiggler, MotionSketch])), ), tabs(&[Timeline, RenderQueue], 0), ), "Effects" => vsplit( Ratio(0.58), hsplit( - FixedA(340.0), + FixedFirst(340.0), tabs(&[EffectControls, Project], 0), - hsplit(FixedB(300.0), tabs(&[Composition, Layer], 0), right(&[Info, Preview], &[EffectsPresets])), + hsplit(FixedSecond(300.0), tabs(&[Composition, Layer], 0), right(&[Info, Preview], &[EffectsPresets])), ), tabs(&[Timeline, RenderQueue], 0), ), "Motion Tracking" => vsplit( Ratio(0.6), hsplit( - FixedA(300.0), + FixedFirst(300.0), tabs(&[Project, EffectControls], 0), - hsplit(FixedB(300.0), tabs(&[Layer, Composition], 0), right(&[Info, Preview], &[Tracker])), + hsplit(FixedSecond(300.0), tabs(&[Layer, Composition], 0), right(&[Info, Preview], &[Tracker])), ), tabs(&[Timeline], 0), ), "Paint" => vsplit( Ratio(0.6), hsplit( - FixedA(300.0), + FixedFirst(300.0), tabs(&[Project, EffectControls], 0), - hsplit(FixedB(300.0), tabs(&[Layer, Composition], 0), right(&[Paint, Info], &[Brushes, Preview])), + hsplit(FixedSecond(300.0), tabs(&[Layer, Composition], 0), right(&[Paint, Info], &[Brushes, Preview])), ), tabs(&[Timeline], 0), ), "Text" => vsplit( Ratio(0.58), hsplit( - FixedA(300.0), + FixedFirst(300.0), tabs(&[Project, EffectControls], 0), - hsplit(FixedB(300.0), tabs(&[Composition], 0), right(&[Character, Paragraph], &[Align, Preview, EffectsPresets])), + hsplit(FixedSecond(300.0), tabs(&[Composition], 0), right(&[Character, Paragraph], &[Align, Preview, EffectsPresets])), ), tabs(&[Timeline], 0), ), @@ -367,31 +304,35 @@ pub fn workspace(name: &str) -> DockNode { // Review: a large viewer with the markers and the project beside it. "Review" => vsplit( Ratio(0.66), - hsplit(FixedA(280.0), tabs(&[Project, Markers], 0), hsplit(FixedB(260.0), tabs(&[Composition, Layer], 0), right(&[Preview, Info], &[Audio]))), + hsplit( + FixedFirst(280.0), + tabs(&[Project, Markers], 0), + hsplit(FixedSecond(260.0), tabs(&[Composition, Layer], 0), right(&[Preview, Info], &[Audio])), + ), tabs(&[Timeline, RenderQueue], 0), ), // Essential Graphics: the Properties panel (After Effects' successor to the Essential // Graphics panel) full height on the right, type panels beside the viewer. "Essential Graphics" => hsplit( - FixedB(320.0), + FixedSecond(320.0), vsplit( Ratio(0.58), hsplit( - FixedA(280.0), + FixedFirst(280.0), tabs(&[Project, EffectControls], 0), - hsplit(FixedB(260.0), tabs(&[Composition, Layer], 0), right(&[Character, Paragraph], &[Align, Preview])), + hsplit(FixedSecond(260.0), tabs(&[Composition, Layer], 0), right(&[Character, Paragraph], &[Align, Preview])), ), tabs(&[Timeline], 0), ), - stack(&[(Properties, true, None), (EffectsPresets, false, None)]), + tabs(&[Properties, EffectsPresets], 0), ), // Color: wide Effect Controls for grading effects, Info for colour readouts. "Color" => vsplit( Ratio(0.6), hsplit( - FixedA(360.0), + FixedFirst(360.0), tabs(&[EffectControls, Project], 0), - hsplit(FixedB(340.0), tabs(&[Composition, Layer], 0), right(&[LumetriScopes, Info, Preview], &[EffectsPresets])), + hsplit(FixedSecond(340.0), tabs(&[Composition, Layer], 0), right(&[LumetriScopes, Info, Preview], &[EffectsPresets])), ), tabs(&[Timeline], 0), ), @@ -401,19 +342,19 @@ pub fn workspace(name: &str) -> DockNode { "Small Screen" => vsplit( Ratio(0.55), hsplit( - FixedA(240.0), + FixedFirst(240.0), tabs(&[Project, EffectControls], 0), - hsplit(FixedB(240.0), tabs(&[Composition], 0), tabs(&[Info, Preview, EffectsPresets], 1)), + hsplit(FixedSecond(240.0), tabs(&[Composition], 0), tabs(&[Info, Preview, EffectsPresets], 1)), ), tabs(&[Timeline], 0), ), "All Panels" => vsplit( Ratio(0.55), hsplit( - FixedA(300.0), + FixedFirst(300.0), tabs(&[Project, EffectControls, Flowchart, History, MediaBrowser, Metadata], 0), hsplit( - FixedB(300.0), + FixedSecond(300.0), tabs(&[Composition, Layer, Footage], 0), right( &[Info, Preview, Audio, Align, Character, Paragraph, LumetriScopes], @@ -439,475 +380,130 @@ pub fn workspace(name: &str) -> DockNode { "Standard" => vsplit( Ratio(0.56), hsplit( - FixedA(300.0), + FixedFirst(300.0), tabs(&[Project, EffectControls], 0), - hsplit(FixedB(290.0), tabs(&[Composition, Layer], 0), right(&[Info, Audio], &[Preview, EffectsPresets])), + hsplit(FixedSecond(290.0), tabs(&[Composition, Layer], 0), right(&[Info, Audio], &[Preview, EffectsPresets])), ), tabs(&[Timeline, RenderQueue], 0), ), // Default (as in After Effects): Project/Effect Controls | Composition over the Timeline, - // and a full-height right column with Preview above the Properties panel. + // and a full-height right column: a short Preview frame above the Properties frame. _ => hsplit( - FixedB(300.0), - vsplit(Ratio(0.56), hsplit(FixedA(300.0), tabs(&[Project, EffectControls], 0), tabs(&[Composition, Layer], 0)), tabs(&[Timeline, RenderQueue], 0)), - stack(&[(Preview, true, Some(46.0)), (Properties, true, None), (Align, false, None), (Audio, false, None), (EffectsPresets, false, None)]), + FixedSecond(300.0), + vsplit( + Ratio(0.56), + hsplit(FixedFirst(300.0), tabs(&[Project, EffectControls], 0), tabs(&[Composition, Layer], 0)), + tabs(&[Timeline, RenderQueue], 0), + ), + vsplit(FixedFirst(PREVIEW_FRAME), tabs(&[Preview], 0), tabs(&[Properties, Align, Audio, EffectsPresets], 0)), ), } } -impl DockNode { - /// Every panel in the tree. - pub fn panels(&self, out: &mut Vec) { - match self { - DockNode::Split { a, b, .. } => { - a.panels(out); - b.panels(out); - } - DockNode::Tabs { panels, .. } => out.extend(panels.iter().copied()), - DockNode::Stack { entries } => out.extend(entries.iter().flat_map(|e| e.panels.iter().copied())), - } - } - pub fn contains(&self, p: PanelKind) -> bool { - let mut v = Vec::new(); - self.panels(&mut v); - v.contains(&p) - } - /// The tabs of the group `p` is in, in order. - pub fn group_of(&self, p: PanelKind) -> Option<&[PanelKind]> { - match self { - DockNode::Split { a, b, .. } => a.group_of(p).or_else(|| b.group_of(p)), - DockNode::Tabs { panels, .. } => panels.contains(&p).then_some(panels.as_slice()), - DockNode::Stack { entries } => entries.iter().find(|e| e.contains(p)).map(|e| e.panels.as_slice()), - } - } - /// Make `p` the active tab of its group. Returns false if not present. - pub fn activate(&mut self, p: PanelKind) -> bool { - if !crate::dock_shared::valid_tree(self) { - return false; - } - match self { - DockNode::Split { a, b, .. } => a.activate(p) || b.activate(p), - DockNode::Tabs { panels, active } => { - if let Some(i) = panels.iter().position(|x| *x == p) { - *active = i; - true - } else { - false - } - } - DockNode::Stack { entries } => match entries.iter_mut().find(|e| e.contains(p)) { - Some(e) => { - e.show(p); - e.open = true; - true - } - None => false, - }, - } - } - /// Expand or collapse a stacked panel's frame (showing `p`). Returns false if `p` is not in - /// a stack. - pub fn toggle_stacked(&mut self, p: PanelKind) -> bool { - if !crate::dock_shared::valid_tree(self) { - return false; - } - match self { - DockNode::Split { a, b, .. } => a.toggle_stacked(p) || b.toggle_stacked(p), - DockNode::Tabs { .. } => false, - DockNode::Stack { entries } => match entries.iter_mut().find(|e| e.contains(p)) { - Some(e) => { - e.show(p); - e.open = !e.open; - true - } - None => false, - }, - } - } +/// Queries on a workspace that EffectCraft's menus, commands and panels ask. +pub trait WorkspaceExt { + /// `p` is in the docked tree. + fn is_docked(&self, p: PanelKind) -> bool; + /// `p` is in a floating window. + fn is_floating(&self, p: PanelKind) -> bool; + /// `p` is open, docked or floating. + fn is_open(&self, p: PanelKind) -> bool; + /// `p` shows: the front tab of its group, an open stacked panel, not in a minimized window. + fn is_visible(&self, p: PanelKind) -> bool; + /// The panels of the tab group holding `p` (a stacked panel is a group of its own). + fn group_of(&self, p: PanelKind) -> Vec; + /// Every open panel, docked first. + fn panels(&self) -> Vec; +} - pub fn is_visible(&self, p: PanelKind) -> bool { - match self { - DockNode::Split { a, b, .. } => a.is_visible(p) || b.is_visible(p), - DockNode::Tabs { panels, active } => panels.get(*active) == Some(&p), - DockNode::Stack { entries } => entries.iter().any(|e| e.open && e.shown() == Some(p)), +pub(crate) fn node_panels(node: &Node, out: &mut Vec) { + match node { + Node::Split { first, second, .. } => { + node_panels(first, out); + node_panels(second, out); } - } - /// Close a panel (remove its tab; empty groups collapse their split). - pub fn close(&mut self, p: PanelKind) { - if !crate::dock_shared::valid_for_close(self) { - return; - } - if let DockNode::Split { a, b, .. } = self { - a.close(p); - b.close(p); - let empty = |n: &DockNode| match n { - DockNode::Tabs { panels, .. } => panels.is_empty(), - DockNode::Stack { entries } => entries.is_empty(), - DockNode::Split { .. } => false, - }; - if empty(a) { - *self = (**b).clone(); - } else if empty(b) { - *self = (**a).clone(); - } - } else if let DockNode::Tabs { panels, active } = self { - let shown = panels.get(*active).copied(); - panels.retain(|x| *x != p); - *active = shown.and_then(|shown| panels.iter().position(|x| *x == shown)).unwrap_or((*active).min(panels.len().saturating_sub(1))); - } else if let DockNode::Stack { entries } = self { - for e in entries.iter_mut() { - let shown = e.shown(); - e.panels.retain(|x| *x != p); - e.active = shown.and_then(|shown| e.panels.iter().position(|x| *x == shown)).unwrap_or(e.active.min(e.panels.len().saturating_sub(1))); - } - entries.retain(|e| !e.panels.is_empty()); - } - } - /// Add a panel as a tab next to `near` (or into the first group). - pub fn open_near(&mut self, p: PanelKind, near: PanelKind) { - if !crate::dock_shared::valid_tree(self) { - return; - } - if self.contains(p) { - self.activate(p); - return; - } - fn add(n: &mut DockNode, p: PanelKind, near: PanelKind) -> bool { - match n { - DockNode::Split { a, b, .. } => add(a, p, near) || add(b, p, near), - DockNode::Tabs { panels, active } => { - if panels.contains(&near) { - panels.push(p); - *active = panels.len() - 1; - true - } else { - false - } - } - DockNode::Stack { entries } => match entries.iter().position(|e| e.contains(near)) { - Some(i) => { - entries.insert(i + 1, StackEntry::new(p, true, None)); - true - } - None => false, - }, + Node::Tabs { panels, .. } => out.extend(panels.iter().copied()), + 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()); } } - fn add_first(n: &mut DockNode, p: PanelKind) -> bool { - match n { - DockNode::Split { a, b, .. } => add_first(a, p) || add_first(b, p), - DockNode::Tabs { panels, active } if !panels.is_empty() => { - panels.push(p); - *active = panels.len() - 1; - true - } - DockNode::Stack { entries } if !entries.is_empty() => { - entries.push(StackEntry::new(p, true, None)); - true - } - _ => false, - } - } - if self.panel_count() == 0 { - // Every panel was closed: there is no anchor, so the panel becomes the whole dock. - *self = tabs(&[p], 0); - } else if !add(self, p, near) && !add(self, p, PanelKind::EffectsPresets) && !add(self, p, PanelKind::Project) { - // None of the anchors is docked (e.g. Minimal with Timeline closed): use the first group. - add_first(self, p); - } + _ => {} } } -/// Where a dragged panel tab lands on a group: as a tab (center) or split off to one side. -#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] -pub enum Zone { - Center, - Left, - Right, - Top, - Bottom, +fn node_group(node: &Node, p: PanelKind) -> Option> { + 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::Dock { columns, .. } => columns.iter().flat_map(|c| c.groups.iter()).find(|g| g.panels.contains(&p)).map(|g| g.panels.clone()), + _ => None, + } } -impl Zone { - pub(crate) fn shared(self) -> craft_ui::docking::Zone { - match self { - Self::Center => craft_ui::docking::Zone::Center, - Self::Left => craft_ui::docking::Zone::Left, - Self::Right => craft_ui::docking::Zone::Right, - Self::Top => craft_ui::docking::Zone::Top, - Self::Bottom => craft_ui::docking::Zone::Bottom, +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()) + } + fn is_floating(&self, p: PanelKind) -> bool { + self.layout.floating.iter().any(|w| w.contains(&p)) + } + fn is_open(&self, p: PanelKind) -> bool { + self.layout.contains(&p) + } + fn is_visible(&self, p: PanelKind) -> bool { + self.layout.panel_state(&p) == PanelState::Front + } + fn group_of(&self, p: PanelKind) -> Vec { + self.layout.root.iter().chain(self.layout.floating.iter().map(|w| &w.root)).find_map(|node| node_group(node, p)).unwrap_or_default() + } + fn panels(&self) -> Vec { + 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); + } + out + } +} + +/// Every panel a workspace names: open, or closed with a recorded place. +pub fn referenced_panels(workspace: &Workspace) -> Vec { + 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); } } - - pub fn from_name(s: &str) -> Option { - Some(match s.to_ascii_lowercase().as_str() { - "center" | "tab" => Zone::Center, - "left" => Zone::Left, - "right" => Zone::Right, - "top" => Zone::Top, - "bottom" => Zone::Bottom, - _ => return None, - }) - } + out } -/// The drop zone for a pointer at `pos` over a group `rect` (with a `tab_h` tab strip): the tab -/// strip and the middle of the group are Center; within a quarter of the size from an edge, -/// the nearest edge. -pub fn drop_zone(rect: Rect, tab_h: f32, pos: egui::Pos2) -> Zone { - match craft_ui::docking::drop_zone(rect, tab_h, pos) { - Some(craft_ui::docking::Zone::Left) => Zone::Left, - Some(craft_ui::docking::Zone::Right) => Zone::Right, - Some(craft_ui::docking::Zone::Top) => Zone::Top, - Some(craft_ui::docking::Zone::Bottom) => Zone::Bottom, - _ => Zone::Center, - } -} - -/// The shared preview region, or an empty rectangle for invalid geometry. -pub fn zone_rect(rect: Rect, zone: Zone) -> Rect { - craft_ui::docking::zone_rect(rect, zone.shared()).unwrap_or(Rect::NOTHING) -} - -/// A panel group floating over the dock (undocked). -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] -pub struct Floating { - pub panels: Vec, - pub active: usize, - /// [x, y, w, h] in points. - pub rect: [f32; 4], -} - -/// A floating group moved out of the main window into its own native window (which can sit on -/// another monitor): the group holding `panel` shows there. -#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)] -pub struct PanelWindow { - pub panel: PanelKind, - /// The window's [x, y] outer position and [w, h] inner size, in desktop points. - pub rect: [f32; 4], -} - -/// The smallest and largest native panel window, in points. -pub const PANEL_WINDOW_MIN: [f32; 2] = [160.0, 100.0]; -pub const PANEL_WINDOW_MAX: f32 = 16_384.0; -/// The farthest a native panel window may sit from the desktop origin, in points. -pub const PANEL_WINDOW_MAX_POS: f32 = 100_000.0; - -impl PanelWindow { - /// The rect made safe to hand to the windowing system: finite, with a size within - /// [`PANEL_WINDOW_MIN`]..=[`PANEL_WINDOW_MAX`] and a position within - /// ±[`PANEL_WINDOW_MAX_POS`] (hostile workspace files and bad monitor reports included). - pub fn sanitized(rect: [f32; 4]) -> [f32; 4] { - let finite = |v: f32, fallback: f32| if v.is_finite() { v } else { fallback }; - let [x, y, w, h] = rect; - [ - finite(x, 0.0).clamp(-PANEL_WINDOW_MAX_POS, PANEL_WINDOW_MAX_POS), - finite(y, 0.0).clamp(-PANEL_WINDOW_MAX_POS, PANEL_WINDOW_MAX_POS), - finite(w, 420.0).clamp(PANEL_WINDOW_MIN[0], PANEL_WINDOW_MAX), - finite(h, 320.0).clamp(PANEL_WINDOW_MIN[1], PANEL_WINDOW_MAX), - ] - } -} - -impl DockNode { - /// Insert panel `p` relative to the group that holds `anchor`: as a tab next to it - /// (Center) or in a new group split off to one side. In a stack, the group is `anchor`'s - /// frame: Center adds a tab to that frame and Top / Bottom add a frame above or below it - /// (#302); Left / Right split the column. `p` is removed from its old place first. Returns - /// false (tree unchanged) if `anchor` isn't docked or is `p` itself alone. - pub fn dock_panel(&mut self, p: PanelKind, anchor: PanelKind, zone: Zone) -> bool { - if !crate::dock_shared::valid_tree(self) || p == anchor || !self.contains(anchor) { - return false; +/// The automation id of the gap below stacked panel `p`: `dock.gutter.s`, 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 { + fn rec(node: &Node, p: PanelKind, path: &mut String, depth: usize) -> Option { + if depth > craft_ui::docking::MAX_DEPTH { + return None; } - let before = self.clone(); - self.close(p); - fn rec(n: &mut DockNode, p: PanelKind, anchor: PanelKind, zone: Zone) -> bool { - let here = match n { - DockNode::Split { a, b, .. } => return rec(a, p, anchor, zone) || rec(b, p, anchor, zone), - DockNode::Tabs { panels, .. } => panels.contains(&anchor), - DockNode::Stack { entries } => entries.iter().any(|e| e.contains(anchor)), - }; - if !here { - return false; + 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 } - match (zone, &mut *n) { - (Zone::Center, DockNode::Tabs { panels, active }) => { - let i = panels.iter().position(|x| *x == anchor).map_or(panels.len(), |i| i + 1); - panels.insert(i, p); - *active = i; - } - (Zone::Center, DockNode::Stack { entries }) => { - let Some(e) = entries.iter_mut().find(|e| e.contains(anchor)) else { return false }; - let i = e.panels.iter().position(|x| *x == anchor).map_or(e.panels.len(), |i| i + 1); - e.panels.insert(i, p); - e.active = i; - e.open = true; - } - (Zone::Top | Zone::Bottom, DockNode::Stack { entries }) => { - let Some(i) = entries.iter().position(|e| e.contains(anchor)) else { return false }; - let at = if zone == Zone::Top { i } else { i + 1 }; - entries.insert(at, StackEntry::new(p, true, None)); - } - (z, node) => { - let new = tabs(&[p], 0); - let old = std::mem::replace(node, tabs(&[], 0)); - let vertical = matches!(z, Zone::Top | Zone::Bottom); - let (a, b) = if matches!(z, Zone::Left | Zone::Top) { (new, old) } else { (old, new) }; - *node = DockNode::Split { vertical, size: SplitSize::Ratio(0.5), a: Box::new(a), b: Box::new(b) }; - } - } - true - } - if rec(self, p, anchor, zone) { - true - } else { - *self = before; - false - } - } - - /// Move panel `p` into the group that holds `anchor` as a tab before `before` (one of that - /// group's panels) or last, and show it. False (tree unchanged) if `anchor` isn't docked. - pub fn insert_tab(&mut self, p: PanelKind, anchor: PanelKind, before: Option) -> bool { - if !crate::dock_shared::valid_tree(self) { - return false; - } - if p == anchor || !self.contains(anchor) { - return false; - } - let saved = self.clone(); - self.close(p); - fn rec(n: &mut DockNode, p: PanelKind, anchor: PanelKind, before: Option) -> bool { - match n { - DockNode::Split { a, b, .. } => rec(a, p, anchor, before) || rec(b, p, anchor, before), - DockNode::Tabs { panels, active } if panels.contains(&anchor) => { - let i = before.and_then(|b| panels.iter().position(|x| *x == b)).unwrap_or(panels.len()); - panels.insert(i, p); - *active = i; - true - } - DockNode::Stack { entries } => { - // A tab of the anchor's frame. - let Some(e) = entries.iter_mut().find(|e| e.contains(anchor)) else { return false }; - let i = before.and_then(|b| e.panels.iter().position(|x| *x == b)).unwrap_or(e.panels.len()); - e.panels.insert(i, p); - e.active = i; - e.open = true; - true - } - _ => false, - } - } - if rec(self, p, anchor, before) { - true - } else { - *self = saved; - false - } - } - - /// Path of the group containing `p` (as in [`Group::path`]; stacks add `sN`). - pub fn path_of(&self, p: PanelKind) -> Option { - fn rec(n: &DockNode, p: PanelKind, path: &str) -> Option { - match n { - DockNode::Split { a, b, .. } => rec(a, p, &format!("{path}a")).or_else(|| rec(b, p, &format!("{path}b"))), - DockNode::Tabs { panels, .. } => panels.contains(&p).then(|| path.to_string()), - DockNode::Stack { entries } => entries.iter().position(|e| e.contains(p)).map(|i| format!("{path}s{i}")), - } - } - rec(self, p, "") - } - - /// Number of panels in the tree. - pub fn panel_count(&self) -> usize { - let mut v = vec![]; - self.panels(&mut v); - v.len() - } -} - -/// A full layout: the docked tree plus floating panels (what a workspace saves). -#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] -pub struct Layout { - pub root: DockNode, - #[serde(default)] - pub floating: Vec, -} - -impl Layout { - /// Apply a shared transaction without replacing the persisted app schema. - pub fn apply(&mut self, action: craft_ui::docking::Action) -> Result<(), String> { - crate::dock_shared::encode(&self.root, &self.floating)?.validate().map_err(|error| error.to_string())?; - let moving_to_float = match &action { - craft_ui::docking::Action::Float { panel, .. } => Some(*panel), - craft_ui::docking::Action::Move { panel, anchor, .. } if self.floating.iter().any(|group| group.panels.contains(anchor)) => Some(*panel), + Node::Stack { entries } => entries.iter().position(|e| e.panel == p).map(|i| format!("dock.gutter.{path}s{i}")), _ => None, - }; - if moving_to_float.is_some_and(|panel| self.root.contains(panel) && self.root.panel_count() <= 1) { - return Err("the last docked panel must remain in the workspace".into()); } - crate::dock_shared::apply(self, action) } - - /// Undock an existing panel; the final docked panel stays in the workspace. - pub fn float(&mut self, p: PanelKind, rect: [f32; 4]) -> bool { - self.apply(craft_ui::docking::Action::Float { panel: p, rect }).is_ok() - } - - /// Close an existing floating panel and collapse its empty group. - pub fn unfloat(&mut self, p: PanelKind) -> bool { - crate::dock_shared::unfloat(self, p) - } - - /// Move or reorder a docked/floating tab through the shared transaction. - pub fn insert_tab(&mut self, p: PanelKind, anchor: PanelKind, before: Option) -> bool { - if !crate::dock_shared::valid_tree(&self.root) { - return false; - } - self.apply(craft_ui::docking::Action::Move { panel: p, anchor, placement: craft_ui::docking::Placement::Tab { before } }).is_ok() - } - - /// Dock a panel beside an anchor; floating destinations accept tabs only. - pub fn dock(&mut self, p: PanelKind, anchor: PanelKind, zone: Zone) -> bool { - if !crate::dock_shared::valid_tree(&self.root) { - return false; - } - self.apply(craft_ui::docking::Action::Move { panel: p, anchor, placement: craft_ui::docking::Placement::Split(zone.shared()) }).is_ok() - } - - pub fn contains(&self, p: PanelKind) -> bool { - self.root.contains(p) || self.floating.iter().any(|group| group.panels.contains(&p)) - } -} - -/// One laid-out tab group. -pub struct Group { - pub path: String, - pub rect: Rect, - pub content: Rect, - pub panels: Vec, - pub active: usize, - /// In a [`DockNode::Stack`]: whether the panel is expanded. - pub stacked: Option, -} - -/// Actions produced by interacting with the dock chrome. -#[derive(Debug, Clone, PartialEq)] -pub enum DockAction { - Activate(PanelKind), - /// Expand/collapse a stacked panel. - ToggleStacked(PanelKind), - Focus(PanelKind), - Close(PanelKind), - PanelMenu(PanelKind, egui::Pos2), - /// A tab started being dragged (re-dock or undock). - BeginDrag(PanelKind), - /// The tab's lock was toggled (Composition / Timeline viewer lock). - ToggleLock(PanelKind), - /// A document tab of a panel was clicked (the Timeline's tab of comp `id`). - ActivateDoc(PanelKind, u64), - /// A document tab's close button (or middle click): close that document (comp `id`). - CloseDoc(PanelKind, u64), + 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 @@ -916,449 +512,165 @@ pub enum DockAction { pub struct DocTab { pub id: u64, pub title: String, - pub deco: Option, + /// The comp's label colour. + pub swatch: egui::Color32, /// The document the panel shows now. pub active: bool, } -/// What a group's tabs show: labels, the comp swatch / close / lock decorations and the panels -/// that show one tab per document. -pub struct TabInfo<'a> { - pub title: &'a dyn Fn(PanelKind) -> String, - pub decos: &'a [(PanelKind, TabDeco)], - pub docs: &'a [(PanelKind, Vec)], +/// 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), } -/// What drawing a group's chrome produced: actions and where each panel's tabs are (a panel with -/// document tabs spans all of them; tabs hidden behind the overflow chevron are left out). -#[derive(Default)] -pub struct Chrome { - pub actions: Vec, - pub tabs: Vec<(PanelKind, Rect)>, +/// 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 the shown comp's name. +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 } -/// After Effects-style extras on a tab that shows a composition (Composition, Timeline): a close -/// button (×), the item's label colour as a small square and the viewer lock. -#[derive(Debug, Clone, Copy, PartialEq)] -pub struct TabDeco { - pub swatch: egui::Color32, - pub locked: bool, - /// Close button and lock (Composition, Timeline); Effect Controls shows just the swatch. - pub viewer: bool, +/// 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 } -/// Lay out the tree into group rects (with `gap` gutters) and handle gutter dragging. -pub fn layout(ui: &mut egui::Ui, node: &mut DockNode, rect: Rect, t: &Tokens, path: &str, out: &mut Vec, reg: &mut crate::automation::Registry) { - let mut actions = Vec::new(); - layout_with_actions(ui, node, rect, t, path, out, reg, &mut actions); - for action in actions { - crate::dock_shared::apply_tree(node, action); - } +/// Whether comp tab `doc` carries the ×: the comp the Timeline shows, while it is the group's +/// shown panel. +fn has_close(doc: &DocTab, selected: bool) -> bool { + selected && doc.active } -/// Lay out chrome while returning mutations for the application's UI command route. -pub fn layout_with_actions( +/// The width each comp tab asks for in the Timeline group's tab row. +pub fn doc_widths(ctx: &egui::Context, docs: &[DocTab], selected: bool, font: &egui::FontId) -> Vec { + docs.iter().map(|d| text_width(ctx, doc_job(d, font, egui::Color32::WHITE)) + TAB_PADDING + if has_close(d, selected) { DOC_CLOSE } else { 0.0 }).collect() +} + +/// 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, and × on the +/// shown comp while the Timeline is the group's shown panel (`selected`). 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.`, `panel.tab.Timeline.close` +/// for the shown comp's ×, `panel.tab.Timeline.more` for », and `panel.tab.Timeline.more.` +/// for its items. +pub fn doc_tabs( ui: &mut egui::Ui, - node: &mut DockNode, - rect: Rect, - t: &Tokens, - path: &str, - out: &mut Vec, + strip: Rect, + docs: &[DocTab], + selected: bool, + style: &craft_ui::docking::DockStyle, reg: &mut crate::automation::Registry, - actions: &mut Vec>, -) { - layout_inner(ui, node, rect, t, path, &[], out, reg, actions); -} - -fn layout_inner( - ui: &mut egui::Ui, - node: &mut DockNode, - rect: Rect, - t: &Tokens, - path: &str, - tree_path: &[bool], - out: &mut Vec, - reg: &mut crate::automation::Registry, - actions: &mut Vec>, -) { - match node { - DockNode::Tabs { panels, active } => { - let tab_h = if panels.len() == 1 && panels[0].compact() { 8.0 } else { t.tab_h }; - let content = Rect::from_min_max(pos2(rect.min.x, rect.min.y + tab_h), rect.max); - out.push(Group { path: path.to_string(), rect, content, panels: panels.clone(), active: *active, stacked: None }); - } - DockNode::Stack { entries } => { - // A header for every entry; the open panels' bodies share the rest. - let head = t.tab_h; - let g = t.gap; - let n = entries.len() as f32; - let avail = rect.height() - n * head - (n - 1.0).max(0.0) * g; - let bodies = stack_bodies(entries, avail); - let mut y = rect.min.y; - let mut drag = None; - for (i, e) in entries.iter().enumerate() { - let body = bodies.get(i).copied().unwrap_or(0.0); - let r = Rect::from_min_max(pos2(rect.min.x, y), pos2(rect.max.x, (y + head + body).min(rect.max.y))); - let content = Rect::from_min_max(pos2(r.min.x, r.min.y + head), r.max); - let group = format!("{path}s{i}"); - // The gap below a panel resizes the open panels on either side of it. - let above = entries.get(..=i).and_then(|s| s.iter().rposition(|x| x.open)); - let below = entries.get(i + 1..).and_then(|s| s.iter().position(|x| x.open)).map(|k| i + 1 + k); - if let (Some(above), Some(below)) = (above, below) { - let gap = Rect::from_min_max(pos2(rect.min.x, r.max.y), pos2(rect.max.x, r.max.y + g)); - if let Some(d) = gutter(ui, gap, true, &group, t, reg) { - drag = Some((above, below, d)); - } - } - out.push(Group { path: group, rect: r, content, panels: e.panels.clone(), active: e.active, stacked: Some(e.open) }); - y = r.max.y + g; - } - if let Some((above, below, d)) = drag { - let mut proposed = entries.clone(); - resize_stacked(&mut proposed, &bodies, above, below, d); - for (before, after) in entries.iter().zip(proposed) { - if before.height != after.height - && let Some(panel) = after.shown() - { - actions.push(craft_ui::docking::Action::ResizeStack { panel, height: after.height }); - } - } - } - } - DockNode::Split { vertical, size, a, b } => { - let axis = if *vertical { SplitAxis::Vertical } else { SplitAxis::Horizontal }; - let Some(split) = split_rect(rect, axis, size.shared(), t.gap, 20.0) else { return }; - let response = resize_handle(split.divider, *vertical, path, t).value(split.first_size(), 0.0..=split.available()).show(ui); - reg.add(&format!("dock.gutter.{path}"), response.response.rect, "gutter"); - if response.delta != 0.0 - && let Some(resized) = split.resized(size.shared(), response.delta, 40.0) - { - actions.push(craft_ui::docking::Action::ResizeSplit { path: tree_path.to_vec(), size: resized }); - } - let mut first_path = tree_path.to_vec(); - first_path.push(false); - let mut second_path = tree_path.to_vec(); - second_path.push(true); - layout_inner(ui, a, split.first, t, &format!("{path}a"), &first_path, out, reg, actions); - layout_inner(ui, b, split.second, t, &format!("{path}b"), &second_path, out, reg, actions); - } - } -} - -/// A gap between dock areas that drags to resize them (`vertical`: up and down), with a slightly -/// larger hit area than the gap. Returns the drag this frame. -fn gutter(ui: &mut egui::Ui, gap: Rect, vertical: bool, path: &str, t: &Tokens, reg: &mut crate::automation::Registry) -> Option { - let response = resize_handle(gap, vertical, path, t).show(ui); - reg.add(&format!("dock.gutter.{path}"), response.response.rect, "gutter"); - (response.delta != 0.0).then_some(response.delta) -} - -/// Build the split-divider handle for `gap`: `vertical` selects the axis, `path` gives its stable id, and the theme -/// supplies hover/drag/focus colours and the localized size label. Returns the handle for the caller to show. -fn resize_handle(gap: Rect, vertical: bool, path: &str, t: &Tokens) -> ResizeHandle<'static> { - let axis = if vertical { SplitAxis::Vertical } else { SplitAxis::Horizontal }; - let style = ResizeHandleStyle { hovered: t.focus.gamma_multiply(0.4), dragged: t.focus.gamma_multiply(0.9), focused: t.focus }; - let label = if vertical { crate::i18n::tr("Height:") } else { crate::i18n::tr("Width:") }; - ResizeHandle::new(egui::Id::unique(("dock-gutter", path.to_string())), axis, gap, label, style) -} - -/// The least body height of an open stacked panel (when the stack has room for it). -const STACK_MIN: f32 = 40.0; - -/// An open stacked panel without a height of its own: it shares the room the others leave. -fn flexible(e: &StackEntry) -> bool { - e.open && !e.height.is_some_and(f32::is_finite) -} - -/// The body heights of a stack's panels in `avail` points (headers and gaps taken out). Open -/// panels with a height keep it and the others share the rest; when no panel takes the rest, or -/// there is too little room, the heights grow or shrink in proportion (down to [`STACK_MIN`]) so -/// the open panels fill the stack. -fn stack_bodies(entries: &[StackEntry], avail: f32) -> Vec { - let avail = if avail.is_finite() { avail.max(0.0) } else { 0.0 }; - let open = entries.iter().filter(|e| e.open).count(); - let min = STACK_MIN.min(avail / open.max(1) as f32); - let fixed: Vec = entries.iter().filter(|e| e.open && !flexible(e)).filter_map(|e| e.height).map(|h| h.max(min)).collect(); - let flex = open.saturating_sub(fixed.len()); - let k = fixed.len() as f32; - // What the panels with a height may take, and how much of it lies above their minimum. - let room = avail - flex as f32 * min; - let sum: f32 = fixed.iter().sum(); - let (excess, target) = (sum - k * min, (room - k * min).max(0.0)); - let fit = flex == 0 || sum > room; - let size = |h: f32| match (fit, excess > 0.0) { - (false, _) => h, - (true, true) => min + (h - min) / excess * target, - (true, false) => min + target / k.max(1.0), - }; - let used: f32 = fixed.iter().map(|&h| size(h)).sum(); - let share = (avail - used).max(0.0) / flex.max(1) as f32; - entries - .iter() - .map(|e| match (e.open, flexible(e)) { - (false, _) => 0.0, - (true, true) => share, - (true, false) => size(e.height.unwrap_or(min).max(min)), - }) - .collect() -} - -/// `v` held to `lo..=hi`, never panicking: when the room is too small for both minimums -/// (`hi < lo`), `lo` wins; a non-finite `v` gives `lo`. -#[cfg(test)] -fn clamp_ordered(v: f32, lo: f32, hi: f32) -> f32 { - let lo = if lo.is_finite() { lo } else { 0.0 }; - let hi = if hi.is_finite() { hi.max(lo) } else { lo }; - if v.is_finite() { v.max(lo).min(hi) } else { lo } -} - -/// The size of a split's first side in `avail` points (both sides keep 20 pt when there is room). -/// `f32::clamp` panics when its bounds cross, which a split shorter than 40 pt did (#306). -#[cfg(test)] -fn split_first(size: SplitSize, avail: f32) -> f32 { - let avail = if avail.is_finite() { avail.max(0.0) } else { 0.0 }; - let first = match size { - SplitSize::Ratio(r) => avail * r, - SplitSize::FixedA(px) => px.min(avail - 20.0), - SplitSize::FixedB(px) => avail - px.min(avail - 20.0), - }; - let lo = 20.0_f32.min(avail); - clamp_ordered(first, lo, avail - 20.0).min(avail) -} - -/// Drag the gap between the open stacked panels `above` and `below` (laid out at `bodies`) by -/// `d` points: one grows as much as the other shrinks, neither below [`STACK_MIN`]. The new sizes -/// become the panels' heights, except that the last panel without one keeps sharing the rest -/// (so the stack still fills its column when the window is resized). -fn resize_stacked(entries: &mut [StackEntry], bodies: &[f32], above: usize, below: usize, d: f32) { - let (Some(&a), Some(&b)) = (bodies.get(above), bodies.get(below)) else { return }; - let pair = a + b; - let lo = STACK_MIN.min(pair / 2.0); - let na = (a + d).max(lo).min(pair - lo); - for (i, h) in [(above, na), (below, pair - na)] { - let last_flexible = entries.iter().filter(|e| flexible(e)).count() == 1; - if let Some(e) = entries.get_mut(i) - && !(last_flexible && flexible(e)) - { - e.height = Some(h); - } - } -} - -/// Draw a group's frame + tab strip: one tab per panel, or per document for panels that show -/// several (the Timeline's comps). Tab labels may name the comp or layer they show (After -/// Effects style). -pub fn draw_group_chrome(ui: &mut egui::Ui, g: &Group, t: &Tokens, reg: &mut crate::automation::Registry, info: &TabInfo) -> Chrome { - struct Entry { - panel: PanelKind, - doc: Option, - label: String, - deco: Option, - /// The group's shown tab. - active: bool, - /// The document its panel shows (even behind another tab). - shown_doc: bool, - } - let mut out = Chrome::default(); - let painter = ui.painter().clone(); - painter.rect_filled(g.rect, t.radius, t.panel_bg); - let active_panel = g.panels.get(g.active).copied(); - let compact = g.panels.len() == 1 && g.panels[0].compact(); - if compact { - // grip dots - let c = pos2(g.rect.center().x, g.rect.min.y + 4.0); - for dx in [-4.0, 0.0, 4.0] { - painter.circle_filled(c + vec2(dx, 0.0), 1.0, t.text_faint); - } - } else { - let mut entries: Vec = vec![]; - for (pi, p) in g.panels.iter().enumerate() { - let shown = pi == g.active; - match info.docs.iter().find(|(k, d)| k == p && !d.is_empty()) { - Some((_, docs)) => entries.extend(docs.iter().map(|d| Entry { - panel: *p, - doc: Some(d.id), - label: d.title.clone(), - deco: d.deco, - active: shown && d.active, - shown_doc: d.active, - })), - None => entries.push(Entry { - panel: *p, - doc: None, - label: (info.title)(*p), - deco: info.decos.iter().find(|(k, _)| k == p).map(|(_, d)| *d), - active: shown, - shown_doc: false, - }), - } - } - let ai = entries.iter().position(|e| e.active).unwrap_or(0); - let strip = Rect::from_min_size(g.rect.min, vec2(g.rect.width(), t.tab_h)); - if t.gradients { - // Settings ▸ Appearance ▸ Use Gradients. - crate::theme::gradient_rect(&painter, strip.shrink2(vec2(t.radius, 0.0)), t.grad_top(t.panel_bg), t.panel_bg); - } - let activate = |e: &Entry| match e.doc { - Some(id) => DockAction::ActivateDoc(e.panel, id), - None => DockAction::Activate(e.panel), +) -> Vec { + let mut out = Vec::new(); + let timeline = PanelKind::Timeline.id(); + let widths = doc_widths(ui.ctx(), docs, selected, &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 close = has_close(doc, selected); + let mut job = doc_job(doc, &style.font, color); + job.wrap = egui::text::TextWrapping { + max_width: (tab.width() - TAB_PADDING - if close { DOC_CLOSE } else { 0.0 }).max(0.0), + max_rows: 1, + break_anywhere: true, + overflow_character: Some('\u{2026}'), }; - let close = |e: &Entry| match e.doc { - Some(id) => DockAction::CloseDoc(e.panel, id), - None => DockAction::Close(e.panel), - }; - let mut x = strip.min.x + 12.0; - let text_y = strip.min.y + 16.0; - for (k, e) in entries.iter().enumerate() { - let p = &e.panel; - // A collapsed stacked panel's header is plain text (no underline or panel menu). - let is_active = k == ai && g.stacked != Some(false); - let galley = painter.layout_no_wrap(e.label.clone(), Tokens::ui(12.0), if is_active { t.tab_text_active } else { t.tab_text }); - let menu_w = if is_active { 20.0 } else { 0.0 }; - // The lock belongs to the panel: on its shown document's tab only. - let lock = e.deco.is_some_and(|d| d.viewer) && (e.doc.is_none() || is_active); - // × (active tab only), swatch and lock before the label. - let deco_w = match e.deco { - Some(d) if d.viewer => (if is_active { 16.0 } else { 0.0 }) + 14.0 + if lock { 16.0 } else { 0.0 }, - Some(_) => 14.0, - None => 0.0, - }; - let w = galley.size().x + 16.0 + menu_w + deco_w; - if x + w > strip.max.x - 20.0 && k > ai { - let r = Rect::from_min_size(pos2(strip.max.x - 22.0, strip.min.y + 6.0), vec2(18.0, 20.0)); - let resp = ui.interact(r, egui::Id::unique(("tab-overflow", g.path.clone())), Sense::click()); - icons::paint(&painter, r.shrink(4.0).translate(vec2(-2.0, 0.0)), Icon::ChevronRight, t.tab_text); - icons::paint(&painter, r.shrink(4.0).translate(vec2(2.0, 0.0)), Icon::ChevronRight, t.tab_text); - crate::widgets::focus_outline(ui, &resp, t); - reg.add_response(&format!("panel.overflow.{}", g.path), &resp, "More tabs"); - if resp.clicked() - && let Some(next) = entries.get((ai + 1) % entries.len()) - { - out.actions.push(activate(next)); - } - break; + 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); + if close { + let cr = Rect::from_center_size(pos2(label_end + DOC_CLOSE / 2.0, mid), vec2(10.0, 10.0)); + let hit = ui.interact(cr.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(tab.intersect(clip)); + painter.line_segment([cr.center() + vec2(-k, -k), cr.center() + vec2(k, k)], Stroke::new(1.2, cc)); + painter.line_segment([cr.center() + vec2(-k, k), cr.center() + vec2(k, -k)], Stroke::new(1.2, cc)); + reg.add_response(&format!("panel.tab.{timeline}.close"), &hit, "Close"); + if hit.clicked() { + out.push(DocAction::Close(doc.id)); } - let tab = Rect::from_min_size(pos2(x, strip.min.y), vec2(w, t.tab_h)); - match out.tabs.iter_mut().find(|(q, _)| q == p) { - Some((_, r)) => *r = r.union(tab), - None => out.tabs.push((*p, tab)), - } - let resp = ui.interact(tab, egui::Id::unique(("tab", g.path.clone(), k)), Sense::click_and_drag()); - if resp.drag_started() { - out.actions.push(DockAction::BeginDrag(*p)); - } - // A document tab also answers to the panel's id while it is the shown one. - let auto_id = match e.doc { - Some(id) => format!("panel.tab.{}.{id}", p.id()), - None => format!("panel.tab.{}", p.id()), - }; - reg.add_response(&auto_id, &resp, &e.label); - if e.shown_doc { - reg.add_response(&format!("panel.tab.{}", p.id()), &resp, &e.label); - } - let mut label_x = tab.min.x + 8.0; - if let Some(d) = e.deco { - let mut dx = tab.min.x + 6.0; - if is_active && d.viewer { - let cr = Rect::from_center_size(pos2(dx + 5.0, text_y), vec2(10.0, 10.0)); - let cresp = ui.interact(cr.expand(2.0), egui::Id::unique(("tab-close", g.path.clone(), k)), Sense::click()); - let cc = if cresp.hovered() { t.tab_text_active } else { t.tab_text }; - let kk = 3.5; - painter.line_segment([cr.center() + vec2(-kk, -kk), cr.center() + vec2(kk, kk)], Stroke::new(1.2, cc)); - painter.line_segment([cr.center() + vec2(-kk, kk), cr.center() + vec2(kk, -kk)], Stroke::new(1.2, cc)); - reg.add_response(&format!("panel.tab.{}.close", p.id()), &cresp, "Close"); - crate::widgets::focus_outline(ui, &cresp, t); - if cresp.clicked() { - out.actions.push(close(e)); - } - dx += 16.0; - } - let sw = Rect::from_center_size(pos2(dx + 5.0, text_y), vec2(9.0, 9.0)); - painter.rect_filled(sw, 1.0, d.swatch); - dx += 14.0; - label_x = dx; - if lock { - let lr = Rect::from_center_size(pos2(dx + 6.0, text_y), vec2(12.0, 12.0)); - let lresp = ui.interact(lr.expand(2.0), egui::Id::unique(("tab-lock", g.path.clone(), k)), Sense::click()); - let lc = if d.locked { - t.tab_text_active - } else if lresp.hovered() { - t.tab_text - } else { - t.text_faint - }; - icons::paint(&painter, lr, Icon::Lock, lc); - reg.add_response(&format!("panel.tab.{}.lock", p.id()), &lresp, if d.locked { "Unlock" } else { "Lock" }); - crate::widgets::focus_outline(ui, &lresp, t); - if lresp.clicked() { - out.actions.push(DockAction::ToggleLock(*p)); - } - label_x = dx + 16.0; - } - } - let label_w = galley.size().x; - let col = if is_active || resp.hovered() { t.tab_text_active } else { t.tab_text }; - painter.galley_with_override_text_color(pos2(label_x, text_y - galley.size().y / 2.0), galley, col); - if is_active { - let mr = Rect::from_center_size(pos2(label_x + label_w + 12.0, text_y), vec2(12.0, 10.0)); - let mresp = ui.interact(mr.expand(3.0), egui::Id::unique(("tab-menu", g.path.clone())), Sense::click()); - reg.add_response(&format!("panel.menu.{}", p.id()), &mresp, "panel menu"); - let mc = if mresp.hovered() { t.tab_text_active } else { t.tab_text }; - for dy in [-3.5, 0.0, 3.5] { - painter.line_segment([pos2(mr.min.x, mr.center().y + dy), pos2(mr.max.x, mr.center().y + dy)], Stroke::new(1.5, mc)); - } - let uy = strip.min.y + 23.0; - painter.line_segment([pos2(label_x, uy), pos2(mr.max.x, uy)], Stroke::new(1.0, t.tab_text_active)); - crate::widgets::focus_outline(ui, &mresp, t); - if mresp.clicked() { - out.actions.push(DockAction::PanelMenu(*p, mr.left_bottom())); - } - } - crate::widgets::focus_outline(ui, &resp, t); - if resp.clicked() { - // A stacked frame's shown tab expands / collapses it; another tab shows that - // panel (expanding the frame). - if g.stacked.is_some() && (k == ai || entries.len() == 1) { - out.actions.push(DockAction::ToggleStacked(*p)); - } else { - out.actions.push(activate(e)); - } - out.actions.push(DockAction::Focus(*p)); - } - if resp.middle_clicked() { - out.actions.push(close(e)); - } - x += w + 8.0; } - // A stacked panel's whole header bar expands/collapses it, not just its name (as in After - // Effects): the frame with its shown tab. - if g.stacked.is_some() - && let Some(e) = entries.get(ai).or(entries.first()) - { - let rest = Rect::from_min_max(pos2((x - 8.0).max(strip.min.x), strip.min.y), strip.max); - if rest.width() > 0.0 { - let resp = ui.interact(rest, egui::Id::unique(("tab-rest", g.path.clone())), Sense::click()); - reg.add(&format!("panel.header.{}", e.panel.id()), rest, &e.label); - if resp.clicked() { - out.actions.push(DockAction::ToggleStacked(e.panel)); - out.actions.push(DockAction::Focus(e.panel)); - } - } + if resp.clicked() { + out.push(DocAction::Activate(doc.id)); + } + if resp.middle_clicked() { + out.push(DocAction::Close(doc.id)); } } - // clicking anywhere in the panel focuses it; a press on another of its tabs waits for that - // tab's click, which focuses the panel actually chosen (a text edit stays open in Character) - let at = ui.input(|i| i.pointer.interact_pos()); - if let Some(p) = active_panel - && ui.rect_contains_pointer(g.rect) - && ui.input(|i| i.pointer.any_pressed()) - && !out.tabs.iter().any(|(q, r)| *q != p && at.is_some_and(|a| r.contains(a))) - { - out.actions.push(DockAction::Focus(p)); + 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 } +/// A viewer lock button (Composition viewers and the Timeline keep their comp while locked). +/// Returns true when clicked. Automation: `panel.tab..lock`. +pub fn lock_button(ui: &mut egui::Ui, rect: Rect, panel: PanelKind, locked: bool, t: &Tokens, reg: &mut crate::automation::Registry) -> bool { + let resp = ui.interact(rect, egui::Id::unique(("tab-lock", panel.id())), Sense::click()); + let color = if locked { + t.tab_text_active + } else if resp.hovered() { + t.tab_text + } else { + t.text_faint + }; + icons::paint(ui.painter(), rect.shrink(2.0), Icon::Lock, color); + reg.add_response(&format!("panel.tab.{}.lock", panel.id()), &resp, if locked { "Unlock" } else { "Lock" }); + crate::widgets::focus_outline(ui, &resp, t); + resp.clicked() +} + /// Placeholder body for panels that are not implemented yet. pub fn placeholder(ui: &mut egui::Ui, rect: Rect, t: &Tokens, text: &str) { ui.painter().text(rect.center(), Align2::CENTER_CENTER, text, Tokens::ui(12.0), t.text_faint); @@ -1367,438 +679,91 @@ pub fn placeholder(ui: &mut egui::Ui, rect: Rect, t: &Tokens, text: &str) { #[cfg(test)] mod tests { use super::*; + use PanelKind::*; + use craft_ui::docking::{Action, Placement, Zone}; + + fn apply(w: &mut Workspace, action: Action) { + w.apply(action, permissions).unwrap(); + } - /// The original split clamp panicked whenever 0 < available < 40. Run the actual dock - /// layout without the app's last-resort panic guard so that regression cannot be hidden. #[test] - fn tiny_split_layouts_stay_inside_their_parent() { - let ctx = egui::Context::default(); - let tokens = Tokens::for_kind(crate::theme::ThemeKind::Dark); - for extent in [20.0, 0.0, 1.0, 5.0, 15.0, 35.0, 39.9, 40.0, 80.0] { - for vertical in [false, true] { - for size in [SplitSize::Ratio(0.5), SplitSize::FixedA(300.0), SplitSize::FixedB(300.0)] { - let rect = Rect::from_min_size(egui::Pos2::ZERO, egui::Vec2::splat(extent)); - let mut node = - DockNode::Split { vertical, size, a: Box::new(tabs(&[PanelKind::Project], 0)), b: Box::new(tabs(&[PanelKind::Composition], 0)) }; - let mut groups = vec![]; - let mut registry = crate::automation::Registry::default(); - let mut output = ctx.run_ui(egui::RawInput::default(), |ui| layout(ui, &mut node, rect, &tokens, "", &mut groups, &mut registry)); - output.textures_delta.clear(); - assert_eq!(groups.len(), 2); - for group in groups { - assert!(rect.contains_rect(group.rect), "{extent}, {vertical}: {:?}", group.rect); - assert!(group.rect.width() >= 0.0 && group.rect.height() >= 0.0); - } - } + fn after_effects_workspaces_exist_with_their_core_panels() { + for name in WORKSPACES { + let w = Workspace::new(workspace(name)); + w.validate().unwrap_or_else(|e| panic!("{name}: {e}")); + assert!(w.is_docked(Composition), "{name}"); + if *name != "Undocked Panels" { + assert!(w.is_docked(Timeline), "{name}"); } } - } - - #[test] - fn open_near_in_an_empty_dock_makes_the_panel_the_dock() { - for p in [PanelKind::Composition, PanelKind::Timeline, PanelKind::Project] { - let mut d = tabs(&[], 0); - d.open_near(p, PanelKind::EffectsPresets); - assert!(d.is_visible(p)); - assert_eq!(d.panel_count(), 1); + let all = Workspace::new(workspace("All Panels")); + for p in PanelKind::ALL.iter().filter(|p| !matches!(p, ScriptConsole | EssentialGraphics | MaskInterpolation)) { + assert!(all.is_open(*p), "All Panels lacks {p:?}"); } - } - - #[test] - fn open_near_without_any_anchor_uses_the_first_group() { - let mut d = tabs(&[PanelKind::Composition], 0); - d.open_near(PanelKind::Timeline, PanelKind::EffectsPresets); - assert!(d.is_visible(PanelKind::Timeline)); - assert_eq!(d.panel_count(), 2); - } - - #[test] - fn stacked_panels_toggle_open_close() { - use PanelKind::*; - let mut d = stack(&[(Preview, true, Some(46.0)), (Properties, true, None), (Align, false, None)]); - assert!(d.is_visible(Properties) && !d.is_visible(Align)); - assert!(d.toggle_stacked(Align)); - assert!(d.is_visible(Align)); - assert!(d.toggle_stacked(Align) && !d.is_visible(Align)); - // Showing a collapsed panel expands it; opening a new panel near one inserts after it. - assert!(d.activate(Align) && d.is_visible(Align)); - d.open_near(Info, Properties); - let mut v = vec![]; - d.panels(&mut v); - assert_eq!(v, [Preview, Properties, Info, Align]); - d.close(Preview); - assert!(!d.contains(Preview)); - assert!(!d.toggle_stacked(Timeline)); - } - - fn entry(panel: PanelKind, open: bool, height: Option) -> StackEntry { - StackEntry::new(panel, open, height) - } - - fn close_to(a: &[f32], b: &[f32]) -> bool { - a.len() == b.len() && a.iter().zip(b).all(|(x, y)| (x - y).abs() < 1e-3) - } - - #[test] - fn stacked_panels_fill_their_column() { - use PanelKind::*; - // A panel with a height keeps it; the open ones without share the rest. - let s = [entry(Preview, true, Some(100.0)), entry(Properties, true, None), entry(Align, false, None), entry(Audio, true, None)]; - assert!(close_to(&stack_bodies(&s, 500.0), &[100.0, 200.0, 0.0, 200.0])); - // Too little room: the heights shrink so the others keep their minimum. - let s = [entry(Preview, true, Some(500.0)), entry(Properties, true, None)]; - assert!(close_to(&stack_bodies(&s, 300.0), &[260.0, STACK_MIN])); - // Nothing to take the rest: the heights grow in proportion (above the minimum) to fill. - let s = [entry(Preview, true, Some(100.0)), entry(Properties, true, Some(300.0)), entry(Align, false, Some(80.0))]; - assert!(close_to(&stack_bodies(&s, 600.0), &[137.5, 462.5, 0.0])); - let s = [entry(Preview, true, Some(46.0)), entry(Properties, false, None)]; - assert!(close_to(&stack_bodies(&s, 600.0), &[600.0, 0.0])); - // Hostile sizes never make a body negative or non-finite. - for avail in [-50.0, 0.0, 10.0, f32::NAN, f32::INFINITY] { - for h in [None, Some(-5.0), Some(f32::NAN), Some(f32::INFINITY), Some(1e30), Some(f32::MAX)] { - let s = [entry(Preview, true, h), entry(Properties, true, Some(60.0)), entry(Align, false, h)]; - let b = stack_bodies(&s, avail); - assert!(b.iter().all(|x| x.is_finite() && *x >= 0.0), "{avail} {h:?}: {b:?}"); + // No built-in workspace uses accordions: right columns are frames split vertically. + fn no_stack(node: &Node) -> bool { + match node { + Node::Split { first, second, .. } => no_stack(first) && no_stack(second), + Node::Stack { .. } => false, + _ => true, } } - assert!(stack_bodies(&[], 100.0).is_empty()); - } - - #[test] - fn dragging_a_stack_gap_trades_height_between_its_neighbours() { - use PanelKind::*; - let mut s = vec![entry(Preview, true, Some(46.0)), entry(Properties, true, None), entry(Align, false, None)]; - let bodies = stack_bodies(&s, 800.0); - resize_stacked(&mut s, &bodies, 0, 1, 100.0); - // Preview keeps its new height; Properties, the only panel without one, takes the rest. - assert_eq!(s[0].height, Some(146.0)); - assert_eq!(s[1].height, None); - assert!(close_to(&stack_bodies(&s, 800.0), &[146.0, 654.0, 0.0])); - // Neither side goes below the minimum. - for (d, want) in [(-1000.0, STACK_MIN), (1000.0, 800.0 - STACK_MIN)] { - let bodies = stack_bodies(&s, 800.0); - resize_stacked(&mut s, &bodies, 0, 1, d); - assert!(close_to(&stack_bodies(&s, 800.0)[..1], &[want]), "{d}"); - } - // Two sharing panels: the upper one gets a height, the lower one keeps sharing. - let mut s = vec![entry(Preview, true, None), entry(Align, false, None), entry(Properties, true, None)]; - let bodies = stack_bodies(&s, 400.0); - resize_stacked(&mut s, &bodies, 0, 2, 50.0); - assert_eq!((s[0].height, s[2].height), (Some(250.0), None)); - assert!(close_to(&stack_bodies(&s, 400.0), &[250.0, 0.0, 150.0])); - // Out-of-range indices change nothing. - let before = s.clone(); - resize_stacked(&mut s, &bodies, 0, 9, 50.0); - assert_eq!(s, before); - } - - #[test] - fn default_workspace_has_ae_right_column_stack() { - let d = workspace("Default"); - assert!(d.is_visible(PanelKind::Properties) && d.is_visible(PanelKind::Preview)); - assert!(d.contains(PanelKind::EffectsPresets) && !d.is_visible(PanelKind::EffectsPresets)); - } - - #[test] - fn workspaces_contain_core_panels() { - for w in WORKSPACES { - let d = workspace(w); - let floating: Vec = workspace_floating(w).into_iter().flat_map(|f| f.panels).collect(); - assert!(d.contains(PanelKind::Timeline) || floating.contains(&PanelKind::Timeline), "{w}"); - assert!(d.contains(PanelKind::Composition) || d.contains(PanelKind::Layer), "{w}"); - // A panel is in one place only. - let mut all = vec![]; - d.panels(&mut all); - all.extend(floating); - let n = all.len(); - all.sort_by_key(|p| p.id()); - all.dedup(); - assert_eq!(all.len(), n, "{w} has a panel twice"); + for name in WORKSPACES { + let layout = workspace(name); + assert!(layout.root.iter().chain(layout.floating.iter().map(|f| &f.root)).all(no_stack), "{name}"); } } #[test] - fn after_effects_workspaces_exist() { - // Window ▸ Workspace in After Effects 2026, less Libraries (an Adobe service). - for w in [ - "Default", - "Review", - "Learn", - "Small Screen", - "Standard", - "All Panels", - "Animation", - "Essential Graphics", - "Color", - "Effects", - "Minimal", - "Motion Tracking", - "Paint", - "Text", - "Undocked Panels", - ] { - assert!(WORKSPACES.contains(&w), "{w}"); - } - assert!(!WORKSPACES.contains(&"Libraries")); - // Layouts differ from Default (except Learn, which is Default plus the Home screen). - let def = workspace("Default"); - for w in WORKSPACES.iter().filter(|w| !matches!(**w, "Default" | "Learn")) { - assert_ne!(workspace(w), def, "{w} falls back to Default"); - } - assert!(workspace("Essential Graphics").contains(PanelKind::Properties)); - assert!(workspace("Color").contains(PanelKind::EffectControls)); - assert!(!workspace_floating("Undocked Panels").is_empty()); - // Every built-in workspace is in Window ▸ Workspace. - let menu: Vec = effectcraft_engine::menus::entries() - .into_iter() - .filter(|(_, e)| e.command == "window.workspace") - .filter_map(|(_, e)| e.params.get("name").and_then(|v| v.as_str()).map(str::to_string)) - .collect(); - for w in WORKSPACES { - assert!(menu.iter().any(|m| m == w), "{w} missing from Window > Workspace"); - } - } - - #[test] - fn short_splits_lay_out_without_panicking() { - // #306: a split 0 < avail < 40 pt tall made `f32::clamp` panic (its bounds crossed). - for avail in [0.0, 5.0, 19.0, 20.0, 30.0, 39.0, 40.0, 41.0, -10.0, f32::NAN, f32::INFINITY] { - for size in [SplitSize::Ratio(0.5), SplitSize::Ratio(f32::NAN), SplitSize::FixedA(300.0), SplitSize::FixedB(300.0), SplitSize::FixedA(-5.0)] { - let f = split_first(size, avail); - assert!(f.is_finite() && f >= 0.0, "{size:?} {avail}: {f}"); - if avail.is_finite() && avail > 0.0 { - assert!(f <= avail, "{size:?} {avail}: {f}"); - } - } - } - assert_eq!(split_first(SplitSize::FixedA(300.0), 30.0), 20.0); - assert_eq!(split_first(SplitSize::Ratio(0.5), 200.0), 100.0); - assert_eq!(clamp_ordered(5.0, 40.0, -4.0), 40.0); - // Every workspace, laid out in rects too short and too narrow for its minimums. - let ctx = egui::Context::default(); - let t = Tokens::for_kind(crate::theme::ThemeKind::Dark); - for w in WORKSPACES { - for (wd, ht) in [(30.0, 30.0), (800.0, 36.0), (800.0, 45.0), (36.0, 600.0), (1.0, 1.0), (0.0, 0.0)] { - let mut node = workspace(w); - let mut frame = ctx.run_ui(egui::RawInput::default(), |ui| { - let mut out = vec![]; - let mut reg = crate::automation::Registry::default(); - layout(ui, &mut node, Rect::from_min_size(pos2(0.0, 0.0), vec2(wd, ht)), &t, "", &mut out, &mut reg); - assert!(!out.is_empty(), "{w}"); - }); - frame.textures_delta.clear(); - } - } - } - - #[test] - fn drop_zone_math() { - let r = Rect::from_min_size(pos2(100.0, 100.0), vec2(400.0, 300.0)); - let tab = 28.0; - assert_eq!(drop_zone(r, tab, pos2(300.0, 110.0)), Zone::Center, "tab strip"); - assert_eq!(drop_zone(r, tab, r.center()), Zone::Center); - assert_eq!(drop_zone(r, tab, pos2(120.0, 250.0)), Zone::Left); - assert_eq!(drop_zone(r, tab, pos2(490.0, 250.0)), Zone::Right); - assert_eq!(drop_zone(r, tab, pos2(300.0, 140.0)), Zone::Top); - assert_eq!(drop_zone(r, tab, pos2(300.0, 390.0)), Zone::Bottom); - // Corners go to the nearer edge. - assert_eq!(drop_zone(r, tab, pos2(105.0, 395.0)), Zone::Left); - assert_eq!(zone_rect(r, Zone::Right), Rect::from_min_max(pos2(300.0, 100.0), r.max)); - assert_eq!(zone_rect(r, Zone::Top).height(), 150.0); - assert_eq!(zone_rect(r, Zone::Center), r); - } - - #[test] - fn dock_panel_splits_and_inserts_tabs() { - use PanelKind::*; - let mut d = workspace("Standard"); - let n = d.panel_count(); - // Tab next to an anchor. - assert!(d.dock_panel(Info, Timeline, Zone::Center)); - assert_eq!(d.panel_count(), n); - let p = d.path_of(Timeline).unwrap(); - assert_eq!(d.path_of(Info).unwrap(), p); - assert!(d.is_visible(Info)); - // Split to the right of the Composition group: a new single-tab group beside it. - assert!(d.dock_panel(Info, Composition, Zone::Right)); - let comp_path = d.path_of(Composition).unwrap(); - let info_path = d.path_of(Info).unwrap(); - assert_eq!(comp_path.len(), info_path.len()); - assert!(comp_path.ends_with('a') && info_path.ends_with('b')); - assert!(d.is_visible(Info)); - // Top: the new group comes first in a vertical split. - assert!(d.dock_panel(Audio, Timeline, Zone::Top)); - assert!(d.path_of(Audio).unwrap().ends_with('a')); - // Dropping a panel on itself or an undocked anchor changes nothing. - let before = d.clone(); - assert!(!d.dock_panel(Audio, Audio, Zone::Left)); - assert!(!d.dock_panel(Audio, Tracker, Zone::Left)); - assert_eq!(d, before); - // Into a stack: a tab of the anchor's frame (#302). - let mut s = workspace("Default"); - let props = s.path_of(Properties).unwrap(); - assert!(s.dock_panel(Tracker, Properties, Zone::Center)); - assert_eq!(s.path_of(Tracker), Some(props.clone())); - assert!(s.is_visible(Tracker) && !s.is_visible(Properties)); - assert!(s.activate(Properties) && s.is_visible(Properties)); - // Top / Bottom: a frame of its own above / below the anchor's, not a split column. - assert!(s.dock_panel(Info, Properties, Zone::Bottom)); - let below = s.path_of(Info).unwrap(); - assert_ne!(below, props); - assert_eq!(s.path_of(Properties), Some(props.clone())); - assert!(s.dock_panel(Info, Properties, Zone::Top)); - assert_eq!(s.path_of(Info), Some(props.clone()), "above Properties: its frame's index"); - // Closing a tab keeps the frame; closing the frame's last tab removes it. - s.close(Tracker); - assert!(s.contains(Properties) && !s.contains(Tracker)); - // A tab dragged onto a stacked frame's tab strip joins that frame. - let mut t = workspace("Default"); - assert!(t.insert_tab(Info, Preview, None)); - assert_eq!(t.path_of(Info), t.path_of(Preview)); - // Moving the only panel of a group collapses its split. - let mut m = hsplit(SplitSize::Ratio(0.5), tabs(&[Project], 0), tabs(&[Composition], 0)); - assert!(m.dock_panel(Project, Composition, Zone::Center)); - assert_eq!(m, tabs(&[Composition, Project], 1)); - } - - /// #302: workspaces saved when each stacked frame held one `panel` still load. - #[test] - fn old_stack_entries_load() { - let e: StackEntry = serde_json::from_str(r#"{"panel":"Preview","open":true,"height":46.0}"#).unwrap(); - assert_eq!(e, StackEntry::new(PanelKind::Preview, true, Some(46.0))); - let s = serde_json::to_string(&workspace("Default")).unwrap(); - assert_eq!(serde_json::from_str::(&s).unwrap(), workspace("Default")); - } - - #[test] - fn floating_layout_round_trips() { - use PanelKind::*; - let mut l = Layout { root: workspace("Standard"), floating: vec![] }; - assert!(l.float(Info, [200.0, 150.0, 320.0, 240.0])); - assert!(!l.root.contains(Info) && l.contains(Info)); - // Tab another panel into the floating group, then dock it back. - assert!(l.dock(Audio, Info, Zone::Center)); - assert_eq!(l.floating[0].panels, [Info, Audio]); - assert!(!l.dock(Audio, Info, Zone::Left), "floating groups only take tabs"); - assert!(l.dock(Info, Timeline, Zone::Bottom)); - assert_eq!(l.floating[0].panels, [Audio]); - assert!(l.root.contains(Info)); - let s = serde_json::to_string(&l).unwrap(); - let back: Layout = serde_json::from_str(&s).unwrap(); - assert_eq!(back, l); - // A workspace saved before floating panels existed still loads. - let old: Layout = serde_json::from_str(&format!("{{\"root\": {}}}", serde_json::to_string(&l.root).unwrap())).unwrap(); - assert!(old.floating.is_empty()); - // The last docked panel can't float. - let mut one = Layout { root: tabs(&[Timeline], 0), floating: vec![] }; - assert!(!one.float(Timeline, [0.0; 4])); - assert!(l.unfloat(Audio) && l.floating.is_empty()); - } - - #[test] - fn close_and_open() { - let mut d = workspace("Default"); - d.close(PanelKind::Paragraph); - assert!(!d.contains(PanelKind::Paragraph)); - d.open_near(PanelKind::Tracker, PanelKind::EffectsPresets); - assert!(d.is_visible(PanelKind::Tracker)); - let s = serde_json::to_string(&d).unwrap(); - let back: DockNode = serde_json::from_str(&s).unwrap(); - assert_eq!(back, d); - assert_eq!(PanelKind::from_name("effects & presets"), Some(PanelKind::EffectsPresets)); - } - - /// Ported from #630 (Ni-zav): the reporter's reproduction on the Minimal workspace. - #[test] - fn window_panels_reopen_after_last_panel_is_closed() { - use PanelKind::*; - for reopen in [Composition, Timeline, Project] { - let mut d = workspace("Minimal"); - d.close(Composition); - d.close(Timeline); - assert_eq!(d.panel_count(), 0); - d.open_near(reopen, EffectsPresets); - assert_eq!(d.panel_count(), 1); - assert!(d.is_visible(reopen), "{reopen:?} must be visible"); - } - let mut d = tabs(&[Audio], 0); - d.open_near(History, Project); - assert_eq!(d, tabs(&[Audio, History], 1)); - let mut d = workspace("Minimal"); - d.open_near(EffectsPresets, Timeline); - assert_eq!(d.path_of(EffectsPresets), d.path_of(Timeline)); - } - - #[test] - fn closing_earlier_inactive_tab_keeps_the_shown_panel() { - use PanelKind::*; - let mut d = tabs(&[Properties, Align, EffectsPresets], 1); - d.close(Properties); - assert!(d.is_visible(Align), "closing an inactive tab keeps the shown panel"); - assert!(!d.is_visible(EffectsPresets)); - assert_eq!(d.panel_count(), 2); - } - - #[test] - fn closing_active_tab_keeps_existing_neighbor_choice() { - use PanelKind::*; - for (active, closed, shown) in [(0, Properties, Align), (1, Align, EffectsPresets), (2, EffectsPresets, Align)] { - let mut d = tabs(&[Properties, Align, EffectsPresets], active); - d.close(closed); - assert!(d.is_visible(shown), "active {active}: {closed:?} -> {shown:?}"); - } - } - - #[test] - fn close_normalizes_invalid_active_and_collapses_empty_splits() { - use PanelKind::*; - let mut d = tabs(&[Properties, Align, EffectsPresets], usize::MAX); - d.close(History); - assert!(d.is_visible(EffectsPresets)); - d.close(Properties); - assert!(d.is_visible(EffectsPresets)); - d.close(EffectsPresets); - assert!(d.is_visible(Align)); - d.close(Align); - assert_eq!(d, tabs(&[], 0)); - let mut d = DockNode::Split { vertical: true, size: SplitSize::Ratio(0.5), a: Box::new(tabs(&[Properties], 0)), b: Box::new(tabs(&[Align], 0)) }; - d.close(Properties); - assert_eq!(d, tabs(&[Align], 0)); - d.close(Align); - assert_eq!(d, tabs(&[], 0)); - } - - #[test] - fn removing_earlier_inactive_floating_tab_keeps_the_shown_panel() { - use PanelKind::*; - let mut layout = Layout { - root: tabs(&[Composition], 0), - floating: vec![Floating { panels: vec![Properties, Align, EffectsPresets], active: 1, rect: [0.0, 0.0, 300.0, 200.0] }], + 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:?}") }; - assert!(layout.unfloat(Properties)); - let f = &layout.floating[0]; - assert_eq!(f.panels.get(f.active), Some(&Align)); - assert!(layout.root.is_visible(Composition)); + 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 } }); + assert_eq!(w.group_of(Project), vec![Properties, Align, Audio, EffectsPresets, Project]); + assert_eq!(w.group_of(Preview), vec![Preview]); } #[test] - fn floating_removal_keeps_active_neighbor_and_handles_invalid_index() { - use PanelKind::*; - for (active, closed, shown) in - [(0, Properties, Align), (1, Align, EffectsPresets), (2, EffectsPresets, Align), (usize::MAX, Properties, EffectsPresets)] - { - let mut layout = Layout { - root: tabs(&[Composition], 0), - floating: vec![Floating { panels: vec![Properties, Align, EffectsPresets], active, rect: [0.0, 0.0, 300.0, 200.0] }], - }; - assert!(layout.unfloat(closed)); - let f = &layout.floating[0]; - assert_eq!(f.panels.get(f.active), Some(&shown)); - for p in [Properties, Align, EffectsPresets] { - layout.unfloat(p); - } - assert!(layout.floating.is_empty()); - assert!(!layout.unfloat(History)); - } + 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) }); + 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) } }); + 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_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 }); + assert!(!w.is_open(Info)); + w.set_visible(Info, true, None, 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(); + 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 }); + assert!(w.is_visible(EffectsPresets)); + // A panel never laid out opens beside its anchor. + apply(&mut w, Action::Open { panel: History, anchor: 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"); } } diff --git a/crates/ui-egui/src/dock_shared.rs b/crates/ui-egui/src/dock_shared.rs deleted file mode 100644 index 4f090e219..000000000 --- a/crates/ui-egui/src/dock_shared.rs +++ /dev/null @@ -1,312 +0,0 @@ -//! Convert the persisted workspace schema to shared docking transactions. - -use craft_ui::docking::{Action, Floating as SharedFloating, Layout as SharedLayout, Node, Placement, StackEntry as SharedStackEntry}; -use craft_ui::layout::{SplitAxis, SplitSize as SharedSplitSize}; - -use crate::dock::{DockNode, Floating, Layout, PanelKind, SplitSize, StackEntry}; - -const MAX_DEPTH: usize = 32; -const MAX_NODES: usize = 4096; -const MAX_PANELS: usize = 128; - -fn encode_node(node: &DockNode, depth: usize, count: &mut usize) -> Result, String> { - *count = count.saturating_add(1); - if depth > MAX_DEPTH || *count > MAX_NODES { - return Err("workspace dock tree exceeds supported limits".into()); - } - Ok(match node { - DockNode::Tabs { panels, active } => { - if panels.len() > MAX_PANELS { - return Err("too many workspace tabs".into()); - } - Node::Tabs { panels: panels.clone(), active: *active } - } - DockNode::Stack { entries } => { - if entries.len() > MAX_PANELS { - return Err("too many workspace stack entries".into()); - } - if entries.iter().any(|entry| entry.panels.is_empty() || entry.active >= entry.panels.len() || entry.panels.len() > MAX_PANELS) { - return Err("invalid stacked tab selection".into()); - } - Node::Stack { - entries: entries - .iter() - .flat_map(|entry| entry.panels.iter().map(move |panel| SharedStackEntry { panel: *panel, open: entry.open, height: entry.height })) - .collect(), - } - } - DockNode::Split { vertical, size, a, b } => Node::Split { - axis: if *vertical { SplitAxis::Vertical } else { SplitAxis::Horizontal }, - size: match *size { - SplitSize::Ratio(value) => SharedSplitSize::Ratio(value), - SplitSize::FixedA(value) => SharedSplitSize::FixedFirst(value), - SplitSize::FixedB(value) => SharedSplitSize::FixedSecond(value), - }, - first: Box::new(encode_node(a, depth.saturating_add(1), count)?), - second: Box::new(encode_node(b, depth.saturating_add(1), count)?), - }, - }) -} - -fn decode_node(node: Node) -> DockNode { - match node { - Node::Tabs { panels, active } => DockNode::Tabs { panels, active }, - Node::Stack { entries } => { - DockNode::Stack { entries: entries.into_iter().map(|entry| StackEntry::new(entry.panel, entry.open, entry.height)).collect() } - } - Node::Split { axis, size, first, second } => DockNode::Split { - vertical: axis == SplitAxis::Vertical, - size: match size { - SharedSplitSize::Ratio(value) => SplitSize::Ratio(value), - SharedSplitSize::FixedFirst(value) => SplitSize::FixedA(value), - SharedSplitSize::FixedSecond(value) => SplitSize::FixedB(value), - }, - a: Box::new(decode_node(*first)), - b: Box::new(decode_node(*second)), - }, - } -} - -pub(crate) fn encode(root: &DockNode, floating: &[Floating]) -> Result, String> { - if floating.len() > MAX_PANELS || floating.iter().any(|group| group.panels.len() > MAX_PANELS) { - return Err("too many floating workspace panels".into()); - } - let root = if matches!(root, DockNode::Tabs { panels, active: 0 } if panels.is_empty()) { None } else { Some(encode_node(root, 0, &mut 0)?) }; - Ok(SharedLayout { - root, - floating: floating.iter().map(|group| SharedFloating { panels: group.panels.clone(), active: group.active, rect: group.rect }).collect(), - }) -} - -pub(crate) fn decode(layout: SharedLayout) -> Layout { - Layout { - root: layout.root.map(decode_node).unwrap_or_else(|| DockNode::Tabs { panels: vec![], active: 0 }), - floating: layout.floating.into_iter().map(|group| Floating { panels: group.panels, active: group.active, rect: group.rect }).collect(), - } -} - -/// Restore app-owned accordion tab frames after shared validation/transactions. -/// The shared model represents individual stack panels; grouping stays in the persisted app schema. -fn restore_frames(node: &mut DockNode, original: &DockNode) { - fn collect(node: &DockNode, out: &mut Vec) { - match node { - DockNode::Split { a, b, .. } => { - collect(a, out); - collect(b, out); - } - DockNode::Stack { entries } => out.extend(entries.iter().cloned()), - DockNode::Tabs { .. } => {} - } - } - fn restore(node: &mut DockNode, frames: &[StackEntry]) { - match node { - DockNode::Split { a, b, .. } => { - restore(a, frames); - restore(b, frames); - } - DockNode::Stack { entries } => { - let mut result: Vec = Vec::new(); - for entry in std::mem::take(entries) { - let Some(panel) = entry.shown() else { continue }; - let old = frames.iter().find(|frame| frame.contains(panel)); - if let Some(last) = result.last_mut() - && old.is_some_and(|frame| last.panels.iter().all(|p| frame.contains(*p))) - { - last.panels.push(panel); - if old.and_then(StackEntry::shown) == Some(panel) { - last.active = last.panels.len().saturating_sub(1); - } - } else { - result.push(entry); - } - } - for entry in &mut result { - if let Some(old) = frames.iter().find(|frame| entry.panels.iter().all(|panel| frame.contains(*panel))) { - entry.active = old - .shown() - .and_then(|shown| entry.panels.iter().position(|panel| *panel == shown)) - .unwrap_or(old.active.min(entry.panels.len().saturating_sub(1))); - } - } - *entries = result; - } - DockNode::Tabs { .. } => {} - } - } - let mut frames = Vec::new(); - collect(original, &mut frames); - restore(node, &frames); -} - -pub(crate) fn apply(layout: &mut Layout, action: Action) -> Result<(), String> { - let mut shared = encode(&layout.root, &layout.floating)?; - // Validate the same shared command first. Native stack insertion then retains tabs inside - // their accordion frame, including the existing before/after insertion policy. - shared.apply(action.clone()).map_err(|error| error.to_string())?; - let mut proposed = decode(shared); - restore_frames(&mut proposed.root, &layout.root); - match action { - Action::Move { panel, anchor, placement } | Action::OpenAt { panel, anchor, placement } if layout.root.contains(anchor) => { - fn stacked(node: &DockNode, p: PanelKind) -> bool { - match node { - DockNode::Split { a, b, .. } => stacked(a, p) || stacked(b, p), - DockNode::Stack { entries } => entries.iter().any(|e| e.contains(p)), - _ => false, - } - } - if stacked(&layout.root, anchor) { - let mut native = layout.clone(); - native.unfloat(panel); - let applied = match placement { - Placement::Tab { before } => native.root.insert_tab(panel, anchor, before), - Placement::Split(zone) => native.root.dock_panel( - panel, - anchor, - match zone { - craft_ui::docking::Zone::Left => crate::dock::Zone::Left, - craft_ui::docking::Zone::Right => crate::dock::Zone::Right, - craft_ui::docking::Zone::Top => crate::dock::Zone::Top, - craft_ui::docking::Zone::Bottom => crate::dock::Zone::Bottom, - craft_ui::docking::Zone::Center => crate::dock::Zone::Center, - }, - ), - }; - if !applied { - return Err("stacked panel move failed".into()); - } - proposed = native; - } - } - Action::Activate { panel } => { - proposed.root.activate(panel); - } - Action::SetStackOpen { panel, open } => { - fn set(node: &mut DockNode, p: PanelKind, open: bool) { - match node { - DockNode::Split { a, b, .. } => { - set(a, p, open); - set(b, p, open); - } - DockNode::Stack { entries } => { - if let Some(e) = entries.iter_mut().find(|e| e.contains(p)) { - e.open = open; - } - } - _ => {} - } - } - set(&mut proposed.root, panel, open); - } - Action::ResizeStack { panel, height } => { - fn set(node: &mut DockNode, p: PanelKind, h: Option) { - match node { - DockNode::Split { a, b, .. } => { - set(a, p, h); - set(b, p, h); - } - DockNode::Stack { entries } => { - if let Some(e) = entries.iter_mut().find(|e| e.contains(p)) { - e.height = h; - } - } - _ => {} - } - } - set(&mut proposed.root, panel, height); - } - _ => {} - } - encode(&proposed.root, &proposed.floating)?.validate().map_err(|error| error.to_string())?; - *layout = proposed; - Ok(()) -} - -pub(crate) fn apply_tree(root: &mut DockNode, action: Action) -> bool { - if !valid_tree(root) { - return false; - } - let mut layout = Layout { root: root.clone(), floating: vec![] }; - if apply(&mut layout, action).is_err() { - return false; - } - *root = layout.root; - true -} - -pub(crate) fn valid_tree(root: &DockNode) -> bool { - encode(root, &[]).is_ok_and(|shared| shared.validate().is_ok()) -} - -pub(crate) fn valid_for_close(root: &DockNode) -> bool { - fn normalize(node: &mut Node) { - match node { - Node::Tabs { panels, active } => *active = (*active).min(panels.len().saturating_sub(1)), - Node::Split { first, second, .. } => { - normalize(first); - normalize(second); - } - Node::Stack { .. } => {} - } - } - let Ok(mut shared) = encode(root, &[]) else { return false }; - if let Some(root) = &mut shared.root { - normalize(root); - } - shared.validate().is_ok() -} - -pub(crate) fn unfloat(layout: &mut Layout, panel: PanelKind) -> bool { - let Ok(mut shared) = encode(&layout.root, &layout.floating) else { return false }; - let mut found = false; - for group in &mut shared.floating { - if group.panels.contains(&panel) { - group.active = group.active.min(group.panels.len().saturating_sub(1)); - found = true; - } - } - if !found || shared.apply(Action::Close { panel }).is_err() { - return false; - } - let mut proposed = decode(shared); - restore_frames(&mut proposed.root, &layout.root); - *layout = proposed; - true -} - -#[cfg(test)] -mod stacked_frame_tests { - use super::*; - use crate::dock::Zone; - #[test] - fn stacked_tabs_survive_shared_resize_activate_float_and_close() { - let mut root = crate::dock::workspace("Default"); - assert!(root.dock_panel(PanelKind::Info, PanelKind::Properties, Zone::Center)); - fn group(node: &DockNode) -> Option<&StackEntry> { - match node { - DockNode::Split { a, b, .. } => group(a).or_else(|| group(b)), - DockNode::Stack { entries } => entries.iter().find(|e| e.contains(PanelKind::Properties)), - _ => None, - } - } - let before = group(&root).unwrap().clone(); - assert!(before.contains(PanelKind::Info)); - let mut layout = Layout { root, floating: vec![] }; - layout.apply(Action::ResizeSplit { path: vec![], size: SharedSplitSize::Ratio(0.6) }).unwrap(); - assert_eq!(group(&layout.root).unwrap(), &before); - layout.apply(Action::Activate { panel: PanelKind::Properties }).unwrap(); - assert_eq!(group(&layout.root).unwrap().shown(), Some(PanelKind::Properties)); - let original_frame = group(&layout.root).unwrap().clone(); - layout.apply(Action::OpenAt { panel: PanelKind::History, anchor: PanelKind::Properties, placement: Placement::Tab { before: None } }).unwrap(); - let opened = group(&layout.root).unwrap(); - assert!(opened.contains(PanelKind::History)); - assert!(opened.contains(PanelKind::Info)); - assert_eq!(opened.shown(), Some(PanelKind::History)); - assert_eq!(opened.height, original_frame.height); - layout.apply(Action::Close { panel: PanelKind::History }).unwrap(); - layout.apply(Action::Float { panel: PanelKind::Info, rect: [20.0, 20.0, 300.0, 300.0] }).unwrap(); - assert_eq!(group(&layout.root).unwrap().panels, vec![PanelKind::Properties]); - layout.apply(Action::Close { panel: PanelKind::Info }).unwrap(); - assert!(layout.floating.is_empty()); - assert_eq!(group(&layout.root).unwrap().panels, vec![PanelKind::Properties]); - } -} diff --git a/crates/ui-egui/src/dock_ui.rs b/crates/ui-egui/src/dock_ui.rs index 05bcd1c8e..30710392a 100644 --- a/crates/ui-egui/src/dock_ui.rs +++ b/crates/ui-egui/src/dock_ui.rs @@ -1,26 +1,310 @@ -//! The dock area: lays out the docked tree (or the maximized panel), draws each group's chrome -//! and body, floating (undocked) panel groups over it, and tab drag-and-drop: drag a tab onto a -//! group to tab it there (center) or split it off to a side (After Effects' drop zones, with a -//! highlight of where it will land); hold Cmd/Ctrl when releasing, or drop outside every group, -//! to float it. `` ` `` maximizes the panel under the pointer. A floating group can also move -//! out of the main window into its own native window ([`EffectcraftApp::set_panel_window`]), -//! which can sit on another monitor. +//! EffectCraft's panels in craft-ui's shared docking. craft-ui draws the frames, tab strips, +//! stacked panels, floating windows, dividers and drop previews and owns the gestures (drag a tab +//! onto a group to tab it there or split it off to a side; hold Cmd/Ctrl at the release, or drop +//! outside every group, to float it). EffectCraft draws the panel bodies, the ≡ panel menu, the +//! Timeline's comp tabs and the viewer locks in each group header, and runs every layout change +//! through its command path (`window.dockAction`), so pointer, menu and control-channel changes +//! share one route. -use egui::{Color32, Rect, Sense, Stroke, StrokeKind, pos2, vec2}; +use crate::state::UiState; +use craft_ui::docking::{ + Action, Divider, DockArea, DockCommand, DockContent, DockError, DockEvent, DockStyle, FloatSpace, Floating, Hit, Node, ResizeEdge, UiDock, +}; +use egui::{Rect, Sense, Stroke, StrokeKind, pos2, vec2}; +use serde_json::{Value, json}; -use crate::dock::{self, DockAction, DockNode, Group, Layout, PanelKind, PanelWindow}; +use crate::dock::{self, DocAction, DocTab, PanelKind, Workspace, WorkspaceExt as _}; +use crate::icons::{self, Icon}; +use crate::theme::Tokens; use crate::{EffectcraftApp, panels}; -use craft_ui::docking::{Action, DropTarget, resolve_drop}; -/// The `egui::Id` under which the panel whose tab is being dragged is stored. -fn drag_id() -> egui::Id { - egui::Id::unique("dock-tab-drag") +/// The dock area's egui id; `DockArea::hit_rects` and `float_space` read by it. +pub fn area_id() -> egui::Id { + egui::Id::unique("effectcraft-docking") +} + +/// Width of the ≡ panel menu button at the end of each tab strip. +const MENU_W: f32 = 26.0; +/// Width of the viewer lock before it. +const LOCK_W: f32 = 18.0; + +/// The smallest and largest native panel window, in points. +pub const PANEL_WINDOW_MIN: [f32; 2] = [160.0, 100.0]; +pub const PANEL_WINDOW_MAX: f32 = 16_384.0; +/// The farthest a native panel window may sit from the desktop origin, in points. +pub const PANEL_WINDOW_MAX_POS: f32 = 100_000.0; + +/// A native panel window's desktop rect made safe to hand to the windowing system: finite, with +/// a size within [`PANEL_WINDOW_MIN`]..=[`PANEL_WINDOW_MAX`] and a position within +/// ±[`PANEL_WINDOW_MAX_POS`] (hostile workspace files and bad monitor reports included). +pub fn sanitized_window_rect(rect: [f32; 4]) -> [f32; 4] { + let finite = |v: f32, fallback: f32| if v.is_finite() { v } else { fallback }; + let [x, y, w, h] = rect; + [ + finite(x, 0.0).clamp(-PANEL_WINDOW_MAX_POS, PANEL_WINDOW_MAX_POS), + finite(y, 0.0).clamp(-PANEL_WINDOW_MAX_POS, PANEL_WINDOW_MAX_POS), + finite(w, 420.0).clamp(PANEL_WINDOW_MIN[0], PANEL_WINDOW_MAX), + finite(h, 320.0).clamp(PANEL_WINDOW_MIN[1], PANEL_WINDOW_MAX), + ] +} + +/// How long to wait for the main window to report its frame before migrated native windows +/// keep their places as they are, in seconds. +const FRAME_REPORT_WAIT: f64 = 2.0; + +/// Moves the native rects of [`UiState::native_outer`]'s windows from the OS window's outer +/// position to its content position, by the main window's frame offset (`inner` less `outer`, +/// the main window's desktop rects): the earlier version's windows had the same OS title bar. +/// Without a report by [`FRAME_REPORT_WAIT`] (a backend without window positions), the places +/// stay as they are. +pub(crate) fn native_outer_to_content(ui: &mut UiState, outer: Option, inner: Option, now: f64) { + let offset = match (outer, inner) { + (Some(outer), Some(inner)) if outer.min.is_finite() && inner.min.is_finite() => inner.min - outer.min, + _ if now < FRAME_REPORT_WAIT => return, + _ => egui::Vec2::ZERO, + }; + let ids = std::mem::take(&mut ui.native_outer); + for window in ui.dock.layout.floating.iter_mut().filter(|w| ids.contains(&w.id)) { + if let Some([x, y, w, h]) = window.native { + window.native = Some(sanitized_window_rect([x + offset.x, y + offset.y, w, h])); + } + } +} + +/// A new floating group's default rect near the centre of `screen`. +pub fn default_float_rect(screen: Rect) -> [f32; 4] { + let c = screen.center(); + [c.x - 210.0, c.y - 160.0, 420.0, 320.0] +} + +/// A panel named by its title or id ("Effect Controls", "EffectControls") or its serialized +/// form (`{"Viewer": 2}`). +fn panel_param(value: &Value) -> Result { + match value.as_str() { + Some(name) => PanelKind::from_name(name).ok_or(format!("unknown panel `{name}`")), + None => serde_json::from_value::(value.clone()).map_err(|_| "unknown `panel`".to_string()), + } +} + +/// The docking commands: `window.dockAction {action}`, craft-ui's `window.panel.*` commands, +/// `ui.dock` and `ui.dock.reset`. `None` for any other id. +pub(crate) fn route(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, params: &Value) -> Option> { + match id { + "window.dockAction" => Some((|| { + let value = params.get("action").cloned().ok_or("missing docking action")?; + let action: Action = serde_json::from_value(value).map_err(|error| format!("invalid docking action: {error}"))?; + if matches!(&action, Action::Open { .. } | Action::OpenAt { .. }) { + return Err("use the panel open commands to preserve viewer and ScriptUI lifecycle callbacks".into()); + } + app.apply_dock(action)?; + Ok(Value::Null) + })()), + "ui.dock.reset" => { + let name = app.ui.workspace.clone(); + app.set_workspace(&name); + Some(Ok(json!({"docking": app.ui.dock}))) + } + "ui.dock" => Some((|| { + let mut tagged = if params.is_object() { params.clone() } else { json!({}) }; + if let Some(fields) = tagged.as_object_mut() { + fields.insert("command".into(), json!("ui.dock")); + } + let command: DockCommand = serde_json::from_value(tagged).map_err(|error| format!("invalid ui.dock params: {error}"))?; + app.run_dock_command(ctx, command)?; + Ok(json!({"docking": app.ui.dock})) + })()), + _ if id.starts_with("window.panel.") && DockCommand::::IDS.contains(&id) => Some((|| { + let mut tagged = if params.is_object() { params.clone() } else { json!({}) }; + if let Some(fields) = tagged.as_object_mut() { + fields.insert("command".into(), json!(id)); + // EffectCraft's panel names ("Effect Controls") as well as craft-ui's ids. + for key in ["panel", "anchor", "before"] { + if let Some(name) = fields.get(key).and_then(Value::as_str) { + let panel = PanelKind::from_name(name).ok_or(format!("unknown panel `{name}`"))?; + fields.insert(key.into(), json!(panel)); + } + } + } + let command: DockCommand = serde_json::from_value(tagged).map_err(|error| format!("invalid docking command: {error}"))?; + app.run_dock_command(ctx, command)?; + Ok(Value::Null) + })()), + "window.panelWindow" => Some((|| { + let panel = panel_param(params.get("panel").ok_or("panelWindow: need `panel`")?).map_err(|e| format!("panelWindow: {e}"))?; + let window = match params.get("window") { + None | Some(Value::Null) => None, + Some(value) => Some(value.as_bool().ok_or("panelWindow: `window` must be true or false")?), + }; + let window = app.set_panel_window(ctx, panel, window)?; + Ok(json!({"window": window})) + })()), + _ => None, + } } impl EffectcraftApp { + /// A layout action from the dock area or a menu, through the command path the control + /// channel uses. pub(crate) fn dock_command(&mut self, ctx: &egui::Context, action: Action) -> Result<(), String> { let value = serde_json::to_value(action).map_err(|error| error.to_string())?; - crate::menus::invoke(self, ctx, "window.dockAction", serde_json::json!({"action": value})).map(|_| ()) + crate::menus::invoke(self, ctx, "window.dockAction", json!({"action": value})).map(|_| ()) + } + + /// Run a craft-ui docking command on the current workspace, all or nothing. Named + /// workspaces and Reset are EffectCraft's own (`window.workspace`, `window.resetWorkspace`). + pub(crate) fn run_dock_command(&mut self, ctx: &egui::Context, command: DockCommand) -> Result<(), String> { + if command.is_app_owned() { + if matches!(command, DockCommand::ResetWorkspace {}) { + let name = self.ui.workspace.clone(); + self.set_workspace(&name); + return Ok(()); + } + return Err("use the window.workspace commands for named workspaces".into()); + } + // A closed panel opens through EffectCraft's own path, which puts it in its usual place + // and runs the viewer and ScriptUI lifecycles. + let shown = match &command { + DockCommand::Activate { panel } | DockCommand::UiDock(UiDock::Operation(craft_ui::docking::DockOperation::Open { panel })) => Some(*panel), + DockCommand::UiDock(UiDock::Operation(craft_ui::docking::DockOperation::Activate { panel })) => Some(*panel), + _ => None, + }; + if let Some(panel) = shown.filter(|panel| !self.ui.dock.is_open(*panel)) { + self.show_panel(panel); + return Ok(()); + } + let space = craft_ui::docking::float_space(ctx, area_id()).unwrap_or_else(|| FloatSpace::new(ctx.content_rect())); + match command.to_actions(&self.ui.dock, false, &space) { + Ok(actions) => self.apply_dock_all(actions), + // Showing a hidden panel at an edge, and Lock, change more than the layout. + Err(DockError::NotAllowed) => { + let mut workspace = self.ui.dock.clone(); + let closed = command.apply(&mut workspace, false, &space, dock::permissions).map_err(|error| error.to_string())?; + self.commit_workspace(workspace, &closed, true); + Ok(()) + } + Err(error) => Err(error.to_string()), + } + } + + pub fn apply_dock(&mut self, action: Action) -> Result<(), String> { + self.apply_dock_all(vec![action]) + } + + /// Apply `actions` all or none. No move or float may empty the docked tree, so a floating + /// panel always has somewhere to dock back to; closing the last docked panel stays allowed. + pub(crate) fn apply_dock_all(&mut self, actions: Vec>) -> Result<(), String> { + let mut workspace = self.ui.dock.clone(); + let mut relocating = false; + let mut closed = Vec::new(); + for action in actions { + relocating |= matches!( + &action, + Action::Move { .. } + | Action::Float { .. } + | Action::MoveGroup { .. } + | Action::MoveWindow { .. } + | Action::MovePanel { .. } + | Action::MoveColumn { .. } + ); + let closing = matches!(&action, Action::Close { .. } | Action::CloseGroup { .. } | Action::CloseWindow { .. } | Action::CloseOthers { .. }); + let docked = workspace.layout.root.is_some(); + closed.extend(workspace.apply(action, dock::permissions).map_err(|error| error.to_string())?); + if !closing && docked && workspace.layout.root.is_none() { + return Err("the last docked panel must remain in the workspace".into()); + } + } + self.commit_workspace(workspace, &closed, relocating); + Ok(()) + } + + /// Take a changed workspace and release the state of the panels it closed: a ScriptUI + /// panel's script window closes (its onClose runs), a viewer forgets its comp. + fn commit_workspace(&mut self, workspace: Workspace, closed: &[PanelKind], relocating: bool) { + self.ui.dock = workspace; + for &p in closed { + if let PanelKind::ScriptPanel(id) = p + && self.session.script_ui.window(id).is_some() + && let Err(e) = self.session.execute("scriptui.close", json!({"window": id})) + { + self.ui.status = e.to_string(); + } + panels::viewers::on_close(self, p); + } + if relocating || self.ui.maximized.is_some_and(|m| !self.ui.dock.is_docked(m)) { + self.ui.maximized = None; + } + } + + /// Close a panel wherever it is (docked or floating). A rejected close changes nothing. + pub fn close_panel(&mut self, p: PanelKind) { + if self.ui.dock.is_open(p) { + let _ = self.apply_dock(Action::Close { panel: p }); + } + } + + /// Toggle the maximized panel (`p`, or none). Only a docked frame maximizes. + pub fn toggle_maximize(&mut self, p: PanelKind) { + self.ui.maximized = if self.ui.maximized == Some(p) || !self.ui.dock.is_docked(p) { None } else { Some(p) }; + } + + /// The panel whose body is under `pos` (from the last frame), else the focused one. + pub fn panel_at(&self, pos: Option) -> PanelKind { + pos.and_then(|p| self.dock_rects.iter().rev().find(|(_, r)| r.contains(p)).map(|(k, _)| *k)).unwrap_or(self.ui.focused) + } + + /// Whether panel `p` is in a floating window with a desktop place: its own OS window on + /// desktop (craft-ui `native-windows`); on the web and in embedded viewports the window + /// stays in the page and the place is kept for a desktop session. + pub fn in_panel_window(&self, p: PanelKind) -> bool { + self.ui.dock.layout.floating.iter().any(|w| w.contains(&p) && w.native.is_some()) + } + + /// Move panel `p` into a floating window of its own, which on desktop is an OS window that + /// can go on another monitor, or back into the main window (`window` false), where it joins + /// the first docked group. `None` toggles. A docked panel is undocked first, and its window + /// opens over the panel's place in the main window. Returns whether `p` is now in a window + /// of its own. + pub fn set_panel_window(&mut self, ctx: &egui::Context, p: PanelKind, window: Option) -> Result { + let current = self.in_panel_window(p); + let window = window.unwrap_or(!current); + if window == current { + return Ok(current); + } + if !window { + // On desktop every floating window is an OS window, so the way back is docking. + let anchor = self.ui.dock.layout.root.as_ref().and_then(|root| { + let mut panels = Vec::new(); + dock::node_panels(root, &mut panels); + panels.into_iter().find(|panel| *panel != p) + }); + let actions = match anchor { + Some(anchor) => vec![Action::Move { panel: p, anchor, placement: craft_ui::docking::Placement::Tab { before: None } }], + // Nothing is docked: the panel becomes the docked layout. + None => vec![Action::Close { panel: p }, Action::Open { panel: p, anchor: None }], + }; + let mut workspace = self.ui.dock.clone(); + // One transaction, so the panel is never reported closed and keeps its state. + let closed = workspace.apply_all(actions, dock::permissions).map_err(|_| format!("can't dock {}", p.title()))?; + self.commit_workspace(workspace, &closed, true); + return Ok(false); + } + if !self.ui.dock.is_floating(p) { + if !self.ui.dock.is_docked(p) { + return Err(format!("{} is not open", p.title())); + } + let rect = default_float_rect(ctx.input_for(egui::ViewportId::ROOT, |i| i.content_rect())); + self.apply_dock(Action::Float { panel: p, rect }).map_err(|_| format!("can't undock {}", p.title()))?; + } + let Some([x, y, w, h]) = self.ui.dock.layout.floating.iter().find(|f| f.contains(&p)).map(|f| f.rect) else { + return Err(format!("can't undock {}", p.title())); + }; + let origin = ctx.input_for(egui::ViewportId::ROOT, |i| i.viewport().inner_rect.map(|r| r.min)).unwrap_or(pos2(0.0, 0.0)); + let rect = sanitized_window_rect([origin.x + x, origin.y + y, w, h]); + self.apply_dock(Action::SetNative { panel: p, rect: Some(rect) })?; + if self.ui.maximized == Some(p) { + self.ui.maximized = None; + } + Ok(true) } /// Tab labels that name what the panel shows, as After Effects does: "Composition Intro", @@ -49,119 +333,45 @@ impl EffectcraftApp { } /// A comp's label colour as a tab swatch (faint without a label). - fn comp_swatch(&self, cid: effectcraft_engine::project::ItemId) -> Color32 { + fn comp_swatch(&self, cid: effectcraft_engine::project::ItemId) -> egui::Color32 { match self.session.project.item(cid).map(|i| i.label) { Some(l) if l != effectcraft_engine::color::Label::None => self.tokens.label(l), _ => self.tokens.text_faint, } } - /// The Timeline's tabs: one per open comp, as in After Effects (opening a precomp adds a tab - /// next to its parent's instead of replacing it). - fn tab_docs(&self) -> Vec<(PanelKind, Vec)> { + /// The Timeline's comp tabs: one per open comp, as in After Effects (opening a precomp adds a + /// tab next to its parent's instead of replacing it). + fn tab_docs(&self) -> Vec { let st = &self.session.state; - let locked = self.ui.locked_tabs.contains(&PanelKind::Timeline.id()); - let docs = st - .open_comps + st.open_comps .iter() .filter_map(|id| { let it = self.session.project.item(*id).filter(|i| i.as_comp().is_some())?; - let deco = dock::TabDeco { swatch: self.comp_swatch(*id), locked, viewer: true }; - Some(dock::DocTab { id: id.0, title: it.name.clone(), deco: Some(deco), active: st.active_comp == Some(*id) }) + Some(DocTab { id: id.0, title: it.name.clone(), swatch: self.comp_swatch(*id), active: st.active_comp == Some(*id) }) }) - .collect(); - vec![(PanelKind::Timeline, docs)] + .collect() } - /// The Composition and Timeline tabs' close button, label-colour swatch and viewer lock. - fn tab_decos(&self) -> Vec<(PanelKind, dock::TabDeco)> { - let Some(cid) = self.session.active_comp_id() else { return vec![] }; - let swatch = self.comp_swatch(cid); - let mut v: Vec<(PanelKind, dock::TabDeco)> = - vec![(PanelKind::Timeline, dock::TabDeco { swatch, locked: self.ui.locked_tabs.contains(&PanelKind::Timeline.id()), viewer: true })]; - // Every Composition viewer: its comp's swatch and its own lock. + /// The label-colour swatch before a tab's name: each Composition viewer's comp, and Effect + /// Controls' (and with Use Label Color for Related Tabs, Properties') selected layer. + fn tab_swatches(&self) -> Vec<(PanelKind, egui::Color32)> { + let mut v = Vec::new(); for id in std::iter::once(0).chain(self.ui.viewers.keys().copied().filter(|v| *v != 0)) { - let p = panels::viewers::panel(id); let swatch = panels::viewers::comp_of(self, id).map_or(self.tokens.text_faint, |c| self.comp_swatch(c)); - v.push((p, dock::TabDeco { swatch, locked: self.ui.locked_tabs.contains(&p.id()), viewer: true })); + v.push((panels::viewers::panel(id), swatch)); } - // Effect Controls carries the selected layer's label colour. if let Some(l) = self.session.active_comp().and_then(|c| self.session.state.selected_layers.first().and_then(|id| c.layer(*id))) && l.label != effectcraft_engine::color::Label::None { - v.push((PanelKind::EffectControls, dock::TabDeco { swatch: self.tokens.label(l.label), locked: false, viewer: false })); + v.push((PanelKind::EffectControls, self.tokens.label(l.label))); + if self.session.prefs.appearance.use_label_color_for_tabs { + v.push((PanelKind::Properties, self.tokens.label(l.label))); + } } v } - /// Settings ▸ Appearance ▸ Use Label Color for Related Tabs: the Composition and Timeline - /// tabs carry their comp's label colour, Effect Controls and Properties the layer's. - fn label_tab_marks(&self, ui: &egui::Ui) { - if !self.session.prefs.appearance.use_label_color_for_tabs { - return; - } - let Some(cid) = self.session.active_comp_id() else { return }; - let comp_label = self.session.project.item(cid).map(|i| i.label); - let layer_label = self.session.active_comp().and_then(|c| self.session.state.selected_layers.first().and_then(|l| c.layer(*l))).map(|l| l.label); - // (the Composition, Timeline and Effect Controls tabs carry their swatch already) - let _ = comp_label; - for (p, label) in [(PanelKind::Properties, layer_label)] { - let (Some(label), Some(e)) = (label, self.auto.find(&format!("panel.tab.{}", p.id()))) else { continue }; - if label == effectcraft_engine::color::Label::None { - continue; - } - let r = Rect::from_min_size(pos2(e.rect[0] + 2.0, e.rect[1] + 9.0), vec2(4.0, (e.rect[3] - 16.0).max(6.0))); - ui.painter().rect_filled(r, 1.0, self.tokens.label(label)); - } - } - - /// Edit the full layout (docked tree + floating groups) with a [`Layout`] operation. - pub fn edit_layout(&mut self, f: impl FnOnce(&mut Layout) -> bool) -> bool { - let Ok(shared) = crate::dock_shared::encode(&self.ui.dock, &self.ui.floating) else { return false }; - if shared.validate().is_err() { - return false; - } - let mut l = Layout { root: self.ui.dock.clone(), floating: self.ui.floating.clone() }; - if !f(&mut l) { - return false; - } - self.ui.dock = l.root; - self.ui.floating = l.floating; - if self.ui.maximized.is_some_and(|m| !self.ui.dock.contains(m)) { - self.ui.maximized = None; - } - true - } - - /// Close a panel wherever it is (docked or floating). - pub fn close_panel(&mut self, p: PanelKind) { - // Commit the layout first: rejected closes must not release viewer or script state. - if !self.edit_layout(|layout| layout.apply(Action::Close { panel: p }).is_ok()) { - return; - } - // Closing a ScriptUI panel closes its script window (its script's onClose runs). - if let PanelKind::ScriptPanel(id) = p - && self.session.script_ui.window(id).is_some() - && let Err(e) = self.session.execute("scriptui.close", serde_json::json!({"window": id})) - { - self.ui.status = e.to_string(); - } - panels::viewers::on_close(self, p); - if self.ui.maximized == Some(p) { - self.ui.maximized = None; - } - } - - /// Toggle the maximized panel (`p`, or none). - pub fn toggle_maximize(&mut self, p: PanelKind) { - self.ui.maximized = if self.ui.maximized == Some(p) || !self.ui.dock.contains(p) { None } else { Some(p) }; - } - - /// The docked panel whose group is under `pos` (from the last frame), else the focused one. - pub fn panel_at(&self, pos: Option) -> PanelKind { - pos.and_then(|p| self.dock_rects.iter().rev().find(|(_, r)| r.contains(p)).map(|(k, _)| *k)).unwrap_or(self.ui.focused) - } - /// Draw panel `p`'s body in `rect`: register its automation region, put the Composition Navigator above an active /// viewer when a nested-comp flow exists, then call the panel's `show` and (for a viewer) the sketch overlay. fn panel_body(&mut self, ui: &mut egui::Ui, p: PanelKind, rect: Rect) { @@ -186,57 +396,34 @@ impl EffectcraftApp { } } - /// Apply one action after the panel bodies have drawn. A panel-window pass runs this at - /// its own pass end so the final IME descriptor sees the post-action state. - fn handle_dock_action(&mut self, ctx: &egui::Context, action: DockAction) { - match action { - DockAction::Activate(p) => { - let _ = self.dock_command(ctx, Action::Activate { panel: p }); - } - DockAction::ToggleStacked(p) => { - let _ = self.dock_command(ctx, Action::SetStackOpen { panel: p, open: !self.ui.dock.is_visible(p) }); - } - DockAction::Focus(p) => { - self.ui.focused = p; - panels::viewer_text::panel_clicked(self, ctx, p); - // A click in (or on the tab of) another Composition viewer makes it active. - if let Some(id) = panels::viewers::id_of(p) { - panels::viewers::activate(self, ctx, id); - } - } - DockAction::Close(p) => { - let _ = self.dock_command(ctx, Action::Close { panel: p }); - } - DockAction::PanelMenu(p, pos) => { - ctx.data_mut(|d| d.insert_temp(egui::Id::unique("panel-menu"), (p, pos))); - } - DockAction::BeginDrag(p) => ctx.data_mut(|d| { - d.insert_temp(drag_id(), p); - }), - DockAction::ToggleLock(p) => { - if !self.ui.locked_tabs.remove(&p.id()) { - self.ui.locked_tabs.insert(p.id().to_string()); - } - } - // The Timeline's comp tabs: show that comp / close its Timeline. - DockAction::ActivateDoc(p, id) => { - let _ = self.dock_command(ctx, Action::Activate { panel: p }); - if self.session.state.active_comp.map(|c| c.0) != Some(id) { - let _ = crate::menus::invoke(self, ctx, "comp.open", serde_json::json!({"comp": id})); - } - } - DockAction::CloseDoc(_, id) => { - let _ = crate::menus::invoke(self, ctx, "comp.close", serde_json::json!({"comp": id})); - } + /// A press in a panel (its body, tab or group header) focuses it; another Composition viewer + /// also becomes the active one. + fn focus_panel(&mut self, ctx: &egui::Context, p: PanelKind) { + self.ui.focused = p; + panels::viewer_text::panel_clicked(self, ctx, p); + if let Some(id) = panels::viewers::id_of(p) { + panels::viewers::activate(self, ctx, id); } } - /// Lay out and draw the workspace in `body`: the maximized panel or the dock tree, group chrome, active bodies - /// and focus outline; then floating groups, their native panel windows, layout/action commands, tab drag-and-drop - /// and the panel menu. Draws the Home screen instead when it is showing. + /// Whether floating panels' OS windows take no input: a dialog of the app's own or a + /// command's OS file dialog is up. egui's `Modal` blocks only the window it is in. + pub(crate) fn floats_blocked(&mut self, ctx: &egui::Context) -> bool { + let (focused, now) = ctx.input(|i| (i.focused || i.raw.viewports.values().any(|v| v.focused == Some(true)), i.time)); + let file_dialog = self.file_dialogs.up(focused, now); + self.dialog.is_some() || panels::dialogs::modal_open(ctx) || file_dialog + } + + /// Draw the Home screen or workspace in `body`. Shared craft-ui docking owns the dock tree, + /// group chrome, tab dragging and floating native windows; this adapter draws panel bodies, + /// applies the returned events/actions and shows the panel menu. pub(crate) fn dock_area(&mut self, ui: &mut egui::Ui, body: Rect) { let t = self.tokens; let ctx = ui.ctx().clone(); + if !self.ui.native_outer.is_empty() { + let (outer, inner, now) = ctx.input_for(egui::ViewportId::ROOT, |i| (i.viewport().outer_rect, i.viewport().inner_rect, i.time)); + native_outer_to_content(&mut self.ui, outer, inner, now); + } if self.ui.start_screen { // Home covers the whole workspace, as in After Effects (the panels wait behind it). let mut child = ui.new_child(egui::UiBuilder::new().max_rect(body).id_salt("home")); @@ -244,443 +431,422 @@ impl EffectcraftApp { panels::home::show(self, &mut child, body); return; } - // The maximized panel fills the area; the tree is kept as it is. - let maximized = self.ui.maximized.filter(|m| self.ui.dock.contains(*m)); - let mut dock = match maximized { - Some(m) => DockNode::Tabs { panels: vec![m], active: 0 }, - None => std::mem::replace(&mut self.ui.dock, DockNode::Tabs { panels: vec![], active: 0 }), - }; - let mut groups = Vec::new(); - let mut layout_actions = Vec::new(); - dock::layout_with_actions(ui, &mut dock, body, &t, "", &mut groups, &mut self.auto, &mut layout_actions); - let mut actions = Vec::new(); - let titles = self.tab_titles(); - let decos = self.tab_decos(); + let style = dock_style(ui, &t); + let maximized = self.ui.maximized.filter(|m| self.ui.dock.is_docked(*m)); + let mut area = DockArea::new(area_id()).float_bounds(body).maximized(maximized).locked(self.ui.dock.locked).input_blocked(self.floats_blocked(&ctx)); + if let Some(panel) = self.pending_panel_raise.take() { + area = area.raise_panel(panel); + } + let layout = self.ui.dock.layout.clone(); + let mut child = ui.new_child(egui::UiBuilder::new().max_rect(body).id_salt("effectcraft-dock-area")); + child.set_clip_rect(body.intersect(ui.clip_rect())); let docs = self.tab_docs(); - let title = |p: PanelKind| { - titles.iter().find(|(k, _)| *k == p).map(|(_, s)| s.clone()).unwrap_or_else(|| crate::i18n::command_label("window.panel", p.title()).to_string()) + let ime = NativeIme::new(&layout.floating, &self.unpublished_viewports); + let mut content = EffectContent { + titles: self.tab_titles(), + swatches: self.tab_swatches(), + docs, + ctx: ctx.clone(), + style: style.clone(), + app: self, + tokens: t, + doc_actions: Vec::new(), + locks: Vec::new(), + menu: None, + bodies: Vec::new(), + ime, }; - let info = dock::TabInfo { title: &title, decos: &decos, docs: &docs }; - // Where each group's tabs are (tab drags show where a tab will land between them). - let mut tab_rects: Vec<(String, Vec<(PanelKind, Rect)>)> = vec![]; - for g in &groups { - let c = dock::draw_group_chrome(ui, g, &t, &mut self.auto, &info); - actions.extend(c.actions); - tab_rects.push((g.path.clone(), c.tabs)); - } - self.label_tab_marks(ui); - if maximized.is_none() { - self.ui.dock = dock; - } - self.dock_rects = groups.iter().filter_map(|g| Some((*g.panels.get(g.active)?, g.rect))).collect(); - for g in &groups { - let Some(p) = g.panels.get(g.active).copied() else { continue }; - if g.content.height() < 2.0 { - continue; // a collapsed stacked panel: header only - } - self.panel_body(ui, p, g.content); - } - for g in &groups { - if g.panels.get(g.active) == Some(&self.ui.focused) { - ui.painter().rect_stroke(g.rect, 0.0, Stroke::new(1.0, t.focus), StrokeKind::Inside); - } - } - // Floating groups over the dock. - let mut float_groups: Vec = vec![]; - let layers = ctx.memory(|memory| memory.layer_ids().collect::>()); - let mut floating_order: Vec<_> = (0..self.ui.floating.len()).collect(); - floating_order.sort_by_key(|index| { - self.ui - .floating - .get(*index) - .and_then(|group| group.panels.first()) - .and_then(|panel| { - let id = egui::Id::unique(("floating-panel", panel.id())); - layers.iter().position(|layer| layer.id == id) - }) - .unwrap_or(usize::MAX) - }); - // A native window is kept only for a panel that still floats. A native viewport that - // goes away releases its IME context: its composition must not reappear elsewhere. - let ui_state = &mut self.ui; - let gone: Vec = ui_state - .panel_windows - .iter() - .filter(|w| !ui_state.floating.iter().any(|group| group.panels.contains(&w.panel))) - .map(|w| panel_window_id(w.panel)) - .collect(); - ui_state.panel_windows.retain(|w| ui_state.floating.iter().any(|group| group.panels.contains(&w.panel))); + let mut output = area.show_content(&mut child, &layout, &style, &mut content); + let EffectContent { doc_actions, locks, menu, bodies, ime, .. } = content; + self.dock_rects = bodies; + self.unpublished_viewports = ime.unpublished(); + // A window that closed or docked takes its composition with it. + let previous = std::mem::replace(&mut self.native_viewports, ime.begun()); + let gone: Vec<_> = previous.into_iter().filter(|v| !self.native_viewports.contains(v)).collect(); for viewport in gone { panels::viewer_text::end_viewport(self, &ctx, viewport); } - for i in floating_order { - // Groups in their own native window take no tab drops from the main window. - if let Some(window) = self.ui.floating.get(i).and_then(|group| self.panel_window_of(&group.panels)) { - self.panel_window(&ctx, i, window, &info); - continue; - } - if let Some((g, tabs)) = self.floating_window(&ctx, i, &info, &mut actions) { - tab_rects.push((g.path.clone(), tabs)); - float_groups.push(g); + self.forward_window_input(&ctx, std::mem::take(&mut output.forwarded_events), std::mem::take(&mut output.window_files)); + if let Some(panel) = output.focused { + self.focus_panel(&ctx, panel); + } + if let Some(error) = output.error { + self.ui.status = error.to_string(); + } + for event in output.events { + if let DockEvent::ToggleMaximize { panel } = event { + self.toggle_maximize(panel); } } - for action in layout_actions { - let _ = self.dock_command(&ctx, action); + for action in output.actions { + if let Err(error) = self.dock_command(&ctx, action) { + self.ui.status = error; + } } - for a in actions { - self.handle_dock_action(&ctx, a); + for p in locks { + if !self.ui.locked_tabs.remove(&p.id()) { + self.ui.locked_tabs.insert(p.id().to_string()); + } } - self.tab_drag(&ctx, &groups, &float_groups, &tab_rects); + for action in doc_actions { + let result = match action { + // The Timeline's comp tabs: show that comp / close its Timeline. + DocAction::Activate(id) => { + let _ = self.apply_dock(Action::Activate { panel: PanelKind::Timeline }); + self.focus_panel(&ctx, PanelKind::Timeline); + if self.session.state.active_comp.map(|c| c.0) == Some(id) { + Ok(Value::Null) + } else { + crate::menus::invoke(self, &ctx, "comp.open", json!({"comp": id})) + } + } + DocAction::Close(id) => crate::menus::invoke(self, &ctx, "comp.close", json!({"comp": id})), + }; + if let Err(error) = result { + self.ui.status = error; + } + } + if let Some((panel, pos)) = menu { + ctx.data_mut(|d| d.insert_temp(egui::Id::unique("panel-menu"), (panel, pos))); + } + let hits = DockArea::::hit_rects(&ctx, area_id()); + self.register_dock_hits(&hits); panels::panel_menu_popup(self, ui); } - /// One floating group: a window with a tab strip (drag the empty strip to move it, the - /// corner to resize it) and the active panel's body. - fn floating_window( - &mut self, - ctx: &egui::Context, - i: usize, - info: &dock::TabInfo, - actions: &mut Vec, - ) -> Option<(Group, Vec<(PanelKind, Rect)>)> { - let t = self.tokens; - let f = self.ui.floating.get(i)?.clone(); - let screen = ctx.content_rect(); - let mut rect = Rect::from_min_size(pos2(f.rect[0], f.rect[1]), vec2(f.rect[2].max(160.0), f.rect[3].max(100.0))); - // Keep the strip reachable. - rect = rect.translate(vec2( - (screen.min.x - rect.min.x).max(0.0) + (screen.max.x - 40.0 - rect.min.x).min(0.0), - (screen.min.y - rect.min.y).max(0.0) + (screen.max.y - 30.0 - rect.min.y).min(0.0), - )); - let id = egui::Id::unique(("floating-panel", f.panels.first().map(|p| p.id()).unwrap_or_default())); - let mut group = None; - // Not constrained to the window: the group is drawn where its rect says (the clamp above - // keeps its strip reachable), so it follows the pointer past the window's edges. - egui::Area::new(id).order(egui::Order::Middle).fixed_pos(rect.min).constrain(false).interactable(true).show(ctx, |ui| { - let (r, _) = ui.allocate_exact_size(rect.size(), Sense::hover()); - ui.painter().rect_filled(r.expand(1.0), t.radius, Color32::from_black_alpha(90)); - let strip = Rect::from_min_size(r.min, vec2(r.width(), t.tab_h)); - // Move by the strip (tabs, registered later, take precedence over it). - // (`id.with("move")` is the id of the `Area`'s own background widget.) - let mv = ui.interact(strip, id.with("strip"), Sense::drag()); - self.auto.add(&format!("panel.float.{i}.move"), strip, "Move floating panel"); - let mut nr = r; - if mv.dragged() { - nr = nr.translate(mv.drag_delta()); - } - let g = Group { - path: format!("f{i}"), - rect: r, - content: Rect::from_min_max(pos2(r.min.x, r.min.y + t.tab_h), r.max), - panels: f.panels.clone(), - active: f.active.min(f.panels.len().saturating_sub(1)), - stacked: None, + /// Keys and dropped files that reach a floating panel's own OS window go to the main + /// window's next frame ([`crate::EffectcraftApp::raw_input_hook`]), so its shortcuts and + /// file import handle them. Text is not forwarded, and nothing is while a text field in + /// the main window has the keyboard. + fn forward_window_input(&mut self, ctx: &egui::Context, events: Vec, files: Vec>) { + let typing = ctx.egui_wants_keyboard_input(); + let events = events.into_iter().filter(|event| !typing && !matches!(event, egui::Event::Text(_) | egui::Event::Ime(_))); + self.forwarded.events.extend(events); + self.forwarded.files.extend(files.into_iter().flat_map(|window| window.dropped)); + if !self.forwarded.events.is_empty() || !self.forwarded.files.is_empty() { + ctx.request_repaint(); + } + } + + /// Automation ids for craft-ui's gesture sources: `panel.tab.`, `panel.drag.` + /// (the group's drag bar), `panel.border.` (the top border above its tabs), + /// `panel.tabs.more.`, `panel.header.` (a stacked panel's open/close button), + /// `panel.float..move`, `.close`, `.resize` (bottom-right + /// corner) and `.resize.`, `dock.gutter.` (`a`/`b` per split level; a stack's gap + /// below entry `i` adds `s`), `dock.corner..` where two dividers meet, and + /// the same inside floating window `n` as `panel.float..gutter.…` and `.corner.…`. + fn register_dock_hits(&mut self, hits: &[(Hit, Rect)]) { + let window = |panel: &PanelKind| self.ui.dock.layout.floating.iter().position(|window| window.contains(panel)); + // Tabs are labelled as drawn: "Composition Intro", not "Composition". + let titles = self.tab_titles(); + let title = |panel: &PanelKind| titles.iter().find(|(p, _)| p == panel).map_or_else(|| panel.title().to_string(), |(_, t)| t.clone()); + let mut found = Vec::new(); + for (hit, rect) in hits { + let entry = match hit { + Hit::Tab(panel) => (format!("panel.tab.{}", panel.id()), title(panel)), + Hit::DragBar(panel) => (format!("panel.drag.{}", panel.id()), "Move panel group".into()), + Hit::Border(panel) => (format!("panel.border.{}", panel.id()), "Move panel group".into()), + Hit::Overflow(panel) => (format!("panel.tabs.more.{}", panel.id()), "More tabs".into()), + Hit::StackToggle(panel) => (format!("panel.header.{}", panel.id()), title(panel)), + Hit::Title(panel) => match window(panel) { + Some(index) => (format!("panel.float.{index}.move"), "Move floating panel".into()), + None => continue, + }, + Hit::Close(panel) => match window(panel) { + Some(index) => (format!("panel.float.{index}.close"), "Close floating panel".into()), + None => continue, + }, + Hit::Resize(panel, edge) => match window(panel) { + Some(index) if *edge == ResizeEdge::BottomRight => (format!("panel.float.{index}.resize"), "Resize floating panel".into()), + Some(index) => (format!("panel.float.{index}.resize.{edge:?}"), "Resize floating panel".into()), + None => continue, + }, + Hit::Divider(Divider::Split(path)) => (format!("dock.gutter.{}", path_id(path)), "gutter".into()), + Hit::Divider(Divider::Stack(panel)) => match dock::stack_gutter_id(&self.ui.dock.layout, *panel) { + Some(id) => (id, "gutter".into()), + None => continue, + }, + Hit::Divider(Divider::Intersection(outer, inner)) => (format!("dock.corner.{}.{}", path_id(outer), path_id(inner)), "gutter corner".into()), + Hit::Divider(Divider::WindowSplit(panel, path)) => match window(panel) { + Some(index) => (format!("panel.float.{index}.gutter.{}", path_id(path)), "gutter".into()), + None => continue, + }, + Hit::Divider(Divider::WindowIntersection(panel, outer, inner)) => match window(panel) { + Some(index) => (format!("panel.float.{index}.corner.{}.{}", path_id(outer), path_id(inner)), "gutter corner".into()), + None => continue, + }, + _ => continue, }; - let c = dock::draw_group_chrome(ui, &g, &t, &mut self.auto, info); - actions.extend(c.actions); - if let Some(p) = g.panels.get(g.active).copied() { - self.panel_body(ui, p, g.content); - } - ui.painter().rect_stroke(r, t.radius, Stroke::new(1.0, t.field_border), StrokeKind::Outside); - if g.panels.get(g.active) == Some(&self.ui.focused) { - ui.painter().rect_stroke(r, t.radius, Stroke::new(1.0, t.focus), StrokeKind::Inside); - } - // Resize from the corner. - let grip = Rect::from_min_max(r.max - vec2(14.0, 14.0), r.max); - let rs = ui.interact(grip, id.with("resize"), Sense::click_and_drag()); - rs.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Splitter, rs.enabled(), crate::i18n::tr("Resize floating panel"))); - self.auto.add_response(&format!("panel.float.{i}.resize"), &rs, "Resize floating panel"); - for k in 0..3 { - let o = 4.0 + k as f32 * 4.0; - ui.painter().line_segment([pos2(r.max.x - o, r.max.y - 2.0), pos2(r.max.x - 2.0, r.max.y - o)], Stroke::new(1.0, t.text_faint)); - } - if rs.hovered() || rs.dragged() { - ui.ctx().set_cursor_icon(egui::CursorIcon::ResizeNwSe); - } - let delta = floating_resize_delta(ui, &rs); - if rs.has_focus() { - ui.painter().rect_stroke(grip, 2.0, Stroke::new(1.5, t.focus), StrokeKind::Inside); - } - if delta != egui::Vec2::ZERO { - nr = Rect::from_min_size(nr.min, (nr.size() + delta).max(vec2(160.0, 100.0))); - } - if nr != r - && let Some(panel) = f.panels.first().copied() - { - let _ = self.dock_command(ctx, Action::MoveFloating { panel, rect: [nr.min.x, nr.min.y, nr.width(), nr.height()] }); - } - group = Some((g, c.tabs)); - }); - group - } - - /// The native window a floating group (its `panels`) shows in, if any. - pub(crate) fn panel_window_of(&self, panels: &[PanelKind]) -> Option { - self.ui.panel_windows.iter().find(|w| panels.contains(&w.panel)).copied() - } - - /// Whether panel `p` shows in its own native window. - pub fn in_panel_window(&self, p: PanelKind) -> bool { - self.ui.floating.iter().any(|group| group.panels.contains(&p) && self.panel_window_of(&group.panels).is_some()) - } - - /// The viewport panel `p` is drawn in: its native window's, or the main window's (also when - /// the platform embeds viewports, as the browser build does). - pub(crate) fn panel_viewport(&self, ctx: &egui::Context, p: PanelKind) -> egui::ViewportId { - if ctx.embed_viewports() { - return egui::ViewportId::ROOT; + found.push((entry, *rect, DockArea::hit_id(area_id(), hit))); } - self.ui - .floating + // The widget id lets keyboard focus on a divider or grip map to its element. + for ((id, label), rect, widget) in found { + self.auto.add(&id, rect, &label); + if let Some(element) = self.auto.elements.last_mut() { + element.response_id = Some(widget); + } + } + } +} + +/// A split path as `a`/`b` per level (first/second child). +fn path_id(path: &[bool]) -> String { + path.iter().map(|second| if *second { 'b' } else { 'a' }).collect() +} + +/// After Effects' window is all frames: drops on all four window edges, Ctrl/Cmd-drag undocks, +/// a release over no target floats, and a floating window's title bar only moves it. +fn dock_style(ui: &egui::Ui, t: &Tokens) -> DockStyle { + let mut style = DockStyle::from_ui(ui); + style.side_edge_zones = true; + style.new_dock_zones = false; + style.maximize_item = true; + style.close_others_item = true; + style.command_press_floats = true; + style.float_on_empty_drop = true; + style.title_bar_docks = false; + style.float_hint = true; + style.wheel_selects_tabs = true; + style.middle_click_closes_tabs = true; + style.float_label = "Undock Panel".into(); + style.float_group_label = "Undock Frame".into(); + style.close_group_label = "Close Frame".into(); + style.tab_height = t.tab_h; + style.gap = t.gap; + style.background = t.panel_bg; + style.tab_background = t.panel_bg; + style.active_background = t.panel_bg; + style.floating_background = t.panel_bg; + style.text = t.tab_text_active; + style.inactive_text = t.tab_text; + style.accent = t.focus; + style.font = Tokens::ui(12.0); + style +} + +/// Panels with a viewer lock: the Composition viewers and the Timeline keep their comp while +/// locked. +fn has_lock(panel: PanelKind) -> bool { + matches!(panel, PanelKind::Composition | PanelKind::Viewer(_) | PanelKind::Timeline) +} + +/// EffectCraft's side of the dock area for one frame. +struct EffectContent<'a> { + app: &'a mut EffectcraftApp, + tokens: Tokens, + titles: Vec<(PanelKind, String)>, + swatches: Vec<(PanelKind, egui::Color32)>, + docs: Vec, + /// Measures the comp tabs for their width in the tab row. + ctx: egui::Context, + style: DockStyle, + doc_actions: Vec, + /// Viewer locks clicked. + locks: Vec, + /// The ≡ button clicked: its panel and where its menu opens. + menu: Option<(PanelKind, egui::Pos2)>, + /// Where each panel body was drawn, in drawing order (floating windows last). + bodies: Vec<(PanelKind, Rect)>, + /// Where each native window's IME descriptor is set up and published. + ime: NativeIme, +} + +/// Which body of a native floating window publishes its IME descriptor. +/// +/// Each OS window is an egui pass of its own. `viewer_text::finish_ime` publishes what the pass's +/// text editor recorded, and with nothing recorded it clears the composition and the preedit. A +/// window with another group before the Viewer that published after every body would clear the +/// preedit before the Viewer drew, and the Viewer's publication would then be a new context that +/// interrupts the composition, every pass. So a window publishes after the body in which its +/// editor has recorded its geometry and after its last body. +pub(crate) struct NativeIme { + /// The bodies each native window draws this pass, as its layout says. + expected: Vec<(egui::ViewportId, usize)>, + /// The bodies each native window has drawn so far, in the order the windows began. + drawn: Vec<(egui::ViewportId, usize)>, + /// Windows that published this pass. + published: Vec, +} + +impl NativeIme { + /// `unpublished` are the windows that drew last pass but never published: the layout's count + /// was too high for them, so they publish after every body this pass. + pub(crate) fn new(floating: &[Floating], unpublished: &[egui::ViewportId]) -> Self { + let expected = floating .iter() - .find(|group| group.panels.contains(&p)) - .and_then(|group| self.panel_window_of(&group.panels)) - .map_or(egui::ViewportId::ROOT, |w| panel_window_id(w.panel)) - } - - /// Move panel `p` (and the floating group it is in) into its own native window, which can be - /// placed on another monitor, or back into the main window (`window` false; it floats there - /// where it was before). `None` toggles. A docked panel is undocked first. The window opens - /// over the place the panel had in the main window. Returns whether `p` is now in a window. - pub fn set_panel_window(&mut self, ctx: &egui::Context, p: PanelKind, window: Option) -> Result { - let group_of = |app: &Self| app.ui.floating.iter().find(|group| group.panels.contains(&p)).map(|group| (group.panels.clone(), group.rect)); - let current = self.in_panel_window(p); - let window = window.unwrap_or(!current); - if window == current { - return Ok(current); - } - if !window { - if let Some((panels, _)) = group_of(self) { - self.ui.panel_windows.retain(|w| !panels.contains(&w.panel)); - } - return Ok(false); - } - if group_of(self).is_none() { - if !self.ui.dock.contains(p) { - return Err(format!("{} is not open", p.title())); - } - let rect = default_float_rect(ctx.input_for(egui::ViewportId::ROOT, |i| i.content_rect())); - if !self.edit_layout(|layout| layout.float(p, rect)) { - return Err(format!("can't undock {}", p.title())); - } - } - let Some((_, [x, y, w, h])) = group_of(self) else { return Err(format!("can't undock {}", p.title())) }; - // Over the panel's place in the main window (its content's position on the desktop). - let origin = ctx.input_for(egui::ViewportId::ROOT, |i| i.viewport().inner_rect.map(|r| r.min)).unwrap_or(pos2(0.0, 0.0)); - let rect = PanelWindow::sanitized([origin.x + x, origin.y + y, w, h]); - ctx.data_mut(|d| d.remove::<[f32; 4]>(panel_window_spawn_id(p))); - self.ui.panel_windows.push(PanelWindow { panel: p, rect }); - if self.ui.maximized == Some(p) { - self.ui.maximized = None; - } - Ok(true) - } - - /// One floating group in its own native window: the group's tab strip and active panel fill - /// the window. Closing the window brings the group back into the main window. - fn panel_window(&mut self, ctx: &egui::Context, i: usize, window: PanelWindow, info: &dock::TabInfo) { - let t = self.tokens; - let Some(f) = self.ui.floating.get(i).cloned() else { return }; - let active = f.active.min(f.panels.len().saturating_sub(1)); - let Some(shown) = f.panels.get(active).copied() else { return }; - // The window opens at its saved place; after that the window system owns its position and - // size (handing them back every frame would fight the user dragging it). - let spawn_id = panel_window_spawn_id(window.panel); - let spawn = ctx.data_mut(|d| *d.get_temp_mut_or_insert_with(spawn_id, || PanelWindow::sanitized(window.rect))); - let builder = egui::ViewportBuilder::default() - .with_title((info.title)(shown)) - .with_position([spawn[0], spawn[1]]) - .with_inner_size([spawn[2], spawn[3]]) - .with_min_inner_size(dock::PANEL_WINDOW_MIN); - let mut closed = false; - let mut placed = None; - let mut pass_viewport = None; - let mut actions = Vec::new(); - ctx.show_viewport_immediate(panel_window_id(window.panel), builder, |ui, class| { - pass_viewport = Some(ui.ctx().viewport_id()); - let native = matches!(class, egui::ViewportClass::Immediate | egui::ViewportClass::Deferred); - if native { - panels::viewer_text::begin_ui(ui.ctx()); - } - egui::CentralPanel::default().frame(egui::Frame::NONE.fill(t.panel_bg)).show(ui, |ui| { - let r = ui.max_rect(); - let g = Group { - path: format!("w{i}"), - rect: r, - content: Rect::from_min_max(pos2(r.min.x, (r.min.y + t.tab_h).min(r.max.y)), r.max), - panels: f.panels.clone(), - active, - stacked: None, - }; - let c = dock::draw_group_chrome(ui, &g, &t, &mut self.auto, info); - // Tabs can't be dragged between native windows yet. - actions.extend(c.actions.into_iter().filter(|a| !matches!(a, DockAction::BeginDrag(_)))); - self.panel_body(ui, shown, g.content); - if shown == self.ui.focused { - ui.painter().rect_stroke(r, 0.0, Stroke::new(1.0, t.focus), StrokeKind::Inside); - } - if native { - panels::panel_menu_popup(self, ui); - } - }); - // Apply this window's panel/tab actions before publishing its IME descriptor: a - // click-away or close in the floating panel must own the pass's final output. - for action in actions.drain(..) { - self.handle_dock_action(ui.ctx(), action); - } - panels::viewer_text::finish_ime(self, ui); - // An embedded window (no native windows on this platform) reads the main window's - // input: its close request and place aren't this window's. - if native { - closed = ui.input(|i| i.viewport().close_requested()); - placed = ui.input(|i| { - let v = i.viewport(); - let inner = v.inner_rect?; - let min = v.outer_rect.map_or(pos2(window.rect[0], window.rect[1]), |outer| outer.min); - Some([min.x, min.y, inner.width(), inner.height()]) - }); - } - }); - if closed { - self.ui.panel_windows.retain(|w| !f.panels.contains(&w.panel)); - if let Some(viewport) = pass_viewport { - panels::viewer_text::end_viewport(self, ctx, viewport); - } - panels::viewer_text::end_viewport(self, ctx, panel_window_id(window.panel)); - ctx.data_mut(|d| d.remove::<[f32; 4]>(spawn_id)); - return; - } - // Remember where the window is, so the workspace reopens it there. - if let Some(rect) = placed.map(PanelWindow::sanitized) - && rect != window.rect - && let Some(w) = self.ui.panel_windows.iter_mut().find(|w| w.panel == window.panel) - { - w.rect = rect; - } - } - - /// A tab being dragged. Over a tab strip (or the middle of a group) it shows where the tab - /// will land: an insertion mark between two tabs (a drop there reorders a group's own tabs - /// too); near a group's edge, the half it will split off. On release it lands there (or - /// floats with Cmd/Ctrl or outside every group). - fn tab_drag(&mut self, ctx: &egui::Context, groups: &[Group], floats: &[Group], tab_rects: &[(String, Vec<(PanelKind, Rect)>)]) { - let Some(p) = ctx.data(|d| d.get_temp::(drag_id())) else { return }; - let t = self.tokens; - let canceled = - ctx.input(|input| input.key_pressed(egui::Key::Escape) || !input.focused || (!input.pointer.primary_down() && !input.pointer.primary_released())); - if canceled || (!self.ui.dock.contains(p) && !self.ui.floating.iter().any(|group| group.panels.contains(&p))) { - ctx.data_mut(|data| data.remove::(drag_id())); - return; - } - let Some(pos) = ctx.pointer_latest_pos() else { return }; - // The shared resolver receives groups in paint order; a floating group occludes the dock. - let targets: Vec<_> = groups - .iter() - .map(|g| (g, false)) - .chain(floats.iter().map(|g| (g, true))) - .filter_map(|(g, floating)| { - Some(DropTarget { - anchor: *g.panels.get(g.active)?, - rect: g.rect, - tab_strip: Some(Rect::from_min_max(g.rect.min, pos2(g.rect.max.x, g.content.min.y))), - tabs: { - let mut tabs = tab_rects.iter().find(|(path, _)| *path == g.path).map(|(_, tabs)| tabs.clone()).unwrap_or_default(); - for panel in &g.panels { - if !tabs.iter().any(|(candidate, _)| candidate == panel) { - tabs.push((*panel, Rect::NOTHING)); - } - } - tabs - }, - allow_splits: !floating, - accepts_tabs: true, - }) + .filter_map(|window| { + let viewport = window_viewport(window.id)?; + let count = if unpublished.contains(&viewport) { 0 } else { window_bodies(window) }; + Some((viewport, count)) }) .collect(); - let over_group = targets.iter().any(|target| target.rect.contains(pos)); - let float_drop = ctx.input(|i| i.modifiers.command); - let plan = (!float_drop).then(|| resolve_drop(&p, pos, &targets)).flatten(); - let painter = ctx.layer_painter(egui::LayerId::new(egui::Order::Foreground, egui::Id::unique("dock-drop"))); - if let Some(proposal) = &plan { - let preview = proposal.preview.shrink(2.0); - painter.rect_filled(preview, t.radius, t.focus.gamma_multiply(0.18)); - painter.rect_stroke(preview, t.radius, Stroke::new(2.0, t.focus), StrokeKind::Inside); - if let Some(mark) = proposal.insertion { - insertion_mark(&painter, mark.center().x, mark, t.focus); + Self { expected, drawn: Vec::new(), published: Vec::new() } + } + + /// Count a body of `viewport` that starts drawing. True for the window's first body: its + /// pass sets up the IME before it. + pub(crate) fn begin_body(&mut self, viewport: egui::ViewportId) -> bool { + match self.drawn.iter_mut().find(|(v, _)| *v == viewport) { + Some((_, n)) => { + *n = n.saturating_add(1); + false } - } - // Ghost of the dragged tab. - let g = painter.layout_no_wrap(crate::i18n::command_label("window.panel", p.title()).to_string(), crate::theme::Tokens::ui(12.0), Color32::WHITE); - let gr = Rect::from_min_size(pos + vec2(12.0, 10.0), g.size() + vec2(16.0, 8.0)); - painter.rect_filled(gr, 4.0, t.focus.gamma_multiply(0.85)); - painter.galley(gr.min + vec2(8.0, 4.0), g, Color32::WHITE); - ctx.set_cursor_icon(egui::CursorIcon::Grabbing); - ctx.request_repaint(); - if ctx.input(|i| i.pointer.primary_released()) { - ctx.data_mut(|d| d.remove::(drag_id())); - let ok = match plan { - Some(proposal) => self.dock_command(ctx, Action::Move { panel: p, anchor: proposal.anchor, placement: proposal.placement }).is_ok(), - None if float_drop || !over_group => { - let r = [pos.x - 40.0, pos.y - 12.0, 420.0, 320.0]; - self.dock_command(ctx, Action::Float { panel: p, rect: r }).is_ok() - } - None => false, - }; - if ok { - self.ui.focused = p; - self.show_panel(p); + None => { + self.drawn.push((viewport, 1)); + true } } } -} -/// The insertion mark of a tab drag: a bar between two tabs at `x`, with caps. -fn insertion_mark(painter: &egui::Painter, x: f32, strip: Rect, col: Color32) { - let (y0, y1) = (strip.min.y + 3.0, strip.max.y - 2.0); - painter.line_segment([pos2(x, y0), pos2(x, y1)], Stroke::new(2.5, col)); - for (y, d) in [(y0, 1.0), (y1, -1.0)] { - painter.add(egui::Shape::convex_polygon(vec![pos2(x - 4.5, y), pos2(x + 4.5, y), pos2(x, y + 5.0 * d)], col, Stroke::NONE)); + /// Whether the body of `viewport` that just drew publishes the IME descriptor: once the + /// window's editor has `recorded` its geometry this pass, and after the window's last body. + /// A window the layout does not name publishes after every body. + pub(crate) fn publishes(&mut self, viewport: egui::ViewportId, recorded: bool) -> bool { + let drawn = self.drawn.iter().find(|(v, _)| *v == viewport).map_or(0, |(_, n)| *n); + let expected = self.expected.iter().find(|(v, _)| *v == viewport).map_or(0, |(_, n)| *n); + let publishes = recorded || drawn >= expected; + if publishes && !self.published.contains(&viewport) { + self.published.push(viewport); + } + publishes + } + + /// The native windows whose pass began. + pub(crate) fn begun(&self) -> Vec { + self.drawn.iter().map(|(v, _)| *v).collect() + } + + /// The native windows that drew bodies but did not publish. + pub(crate) fn unpublished(&self) -> Vec { + self.drawn.iter().map(|(v, _)| *v).filter(|v| !self.published.contains(v)).collect() } } -/// The native window of the floating group whose window entry names `panel`. -pub fn panel_window_id(panel: PanelKind) -> egui::ViewportId { - egui::ViewportId::from_hash_of(("effectcraft-panel-window", panel.id())) +/// The OS window craft-ui opens for the floating window `id`. +#[cfg(not(target_arch = "wasm32"))] +fn window_viewport(id: u64) -> Option { + Some(DockArea::::window_viewport(area_id(), id)) } -/// Where a native panel window was told to open (kept for as long as it stays open). -fn panel_window_spawn_id(panel: PanelKind) -> egui::Id { - egui::Id::unique(("panel-window-spawn", panel.id())) +/// The web keeps floating windows in the page. +#[cfg(target_arch = "wasm32")] +fn window_viewport(_id: u64) -> Option { + None } -/// A new floating group's default rect near the centre of `screen`. -pub fn default_float_rect(screen: Rect) -> [f32; 4] { - let c = screen.center(); - [c.x - 210.0, c.y - 160.0, 420.0, 320.0] -} - -/// A corner is a two-axis resize control; focused arrows belong to it and Tab moves on. -fn floating_resize_delta(ui: &mut egui::Ui, response: &egui::Response) -> egui::Vec2 { - if response.drag_started() { - response.request_focus(); +/// The panel bodies craft-ui draws in a floating window: the active panel of each group and each +/// open stack entry. A minimized window shows its bar only. +fn window_bodies(window: &Floating) -> usize { + if window.minimized { + return 0; } - let mut delta = if response.dragged() { response.drag_delta() } else { egui::Vec2::ZERO }; - if response.has_focus() { - ui.memory_mut(|memory| { - memory.set_focus_lock_filter(response.id, egui::EventFilter { horizontal_arrows: true, vertical_arrows: true, ..Default::default() }) - }); - ui.input_mut(|input| { - for (key, amount) in [ - (egui::Key::ArrowLeft, vec2(-8.0, 0.0)), - (egui::Key::ArrowRight, vec2(8.0, 0.0)), - (egui::Key::ArrowUp, vec2(0.0, -8.0)), - (egui::Key::ArrowDown, vec2(0.0, 8.0)), - ] { - if input.consume_key(egui::Modifiers::NONE, key) { - delta += amount; - } + let mut count = 0usize; + let mut nodes = vec![&window.root]; + while let Some(node) = nodes.pop() { + match node { + Node::Split { first, second, .. } => nodes.extend([&**first, &**second]), + Node::Tabs { panels, active } => count = count.saturating_add(usize::from(panels.get(*active).is_some())), + Node::Stack { entries } => count = count.saturating_add(entries.iter().filter(|e| e.open).count()), + _ => {} + } + } + count +} + +impl EffectContent<'_> { + fn header_width(&self, active: PanelKind, strip_width: f32) -> f32 { + let lock = if has_lock(active) { LOCK_W } else { 0.0 }; + (lock + MENU_W).min(strip_width * 2.0 / 3.0).max(MENU_W) + } + + /// Whether the group of `panels` shows comp tabs: it holds the Timeline and comps are open. + fn has_doc_tabs(&self, panels: &[PanelKind]) -> bool { + panels.contains(&PanelKind::Timeline) && !self.docs.is_empty() + } +} + +impl DockContent for EffectContent<'_> { + fn body(&mut self, ui: &mut egui::Ui, panel: &PanelKind) { + let t = self.tokens; + let rect = ui.max_rect(); + self.bodies.push((*panel, rect)); + // A floating panel's OS window is a pass of its own: its text IME descriptor is set up + // before its first body and published after its bodies (the main window does both in + // `draw`). + let viewport = ui.ctx().viewport_id(); + let native = viewport != egui::ViewportId::ROOT && !ui.ctx().embed_viewports(); + if native && self.ime.begin_body(viewport) { + panels::viewer_text::begin_ui(ui.ctx()); + } + self.app.panel_body(ui, *panel, rect); + if native && self.ime.publishes(viewport, panels::viewer_text::ime_recorded(ui.ctx())) { + panels::viewer_text::finish_ime(self.app, ui); + } + // The body fills its frame; allocating it lets a floated panel keep its full size. + ui.allocate_rect(rect, Sense::hover()); + // Painted after the body so child backgrounds cannot hide the focus outline. + if self.app.ui.focused == *panel { + ui.painter().rect_stroke(rect, 0.0, Stroke::new(1.0, t.focus), StrokeKind::Inside); + } + } + + fn logical_label(&self, panel: &PanelKind) -> String { + crate::i18n::command_label("window.panel", panel.title()).to_string() + } + + /// The tab names what the panel shows ("Composition Intro"), after the label swatch of its + /// comp or layer. With comps open, the Timeline's own tab is just "Timeline"; each comp has a + /// tab of its own after the group's panel tabs. + fn label(&mut self, _ui: &egui::Ui, panel: &PanelKind, logical: &str, font: &egui::FontId, color: egui::Color32) -> egui::WidgetText { + let title = self.titles.iter().find(|(p, _)| p == panel).map_or(logical, |(_, s)| s.as_str()); + let Some((_, swatch)) = self.swatches.iter().find(|(p, _)| p == panel) else { return title.into() }; + let mut job = egui::text::LayoutJob::default(); + job.append("■ ", 0.0, egui::TextFormat::simple(font.clone(), *swatch)); + job.append(title, 0.0, egui::TextFormat::simple(font.clone(), color)); + job.into() + } + + fn group_header_width(&self, _panels: &[PanelKind], active: &PanelKind, _floating: bool, strip_width: f32) -> f32 { + self.header_width(*active, strip_width) + } + + /// The viewer lock and the ≡ panel menu of the shown panel. + fn group_header(&mut self, ui: &mut egui::Ui, _panels: &[PanelKind], active: &PanelKind, _floating: bool) { + let t = self.tokens; + let header = ui.max_rect(); + let menu = Rect::from_min_max(pos2((header.max.x - MENU_W).max(header.min.x), header.min.y), header.max); + if has_lock(*active) { + let lock = Rect::from_center_size(pos2(menu.min.x - LOCK_W / 2.0, header.center().y), vec2(14.0, 14.0)); + let locked = self.app.ui.locked_tabs.contains(&active.id()); + if dock::lock_button(ui, lock, *active, locked, &t, &mut self.app.auto) { + self.locks.push(*active); } - }); + } + let rect = Rect::from_center_size(menu.center(), vec2(18.0, 18.0)); + let response = ui.interact(rect, egui::Id::unique(("panel-menu-button", active.id())), Sense::click()); + response.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, response.enabled(), "panel menu")); + self.app.auto.add_response(&format!("panel.menu.{}", active.id()), &response, "panel menu"); + let color = if response.hovered() { t.tab_text_active } else { t.tab_text }; + icons::paint(ui.painter(), Rect::from_center_size(rect.center(), vec2(16.0, 16.0)), Icon::Hamburger, color); + crate::widgets::focus_outline(ui, &response, &t); + if response.clicked() { + self.app.ui.focused = *active; + self.menu = Some((*active, rect.left_bottom())); + } + } + + fn group_extra_tabs_width(&self, panels: &[PanelKind], active: &PanelKind, _floating: bool) -> f32 { + if !self.has_doc_tabs(panels) { + return 0.0; + } + dock::doc_widths(&self.ctx, &self.docs, *active == PanelKind::Timeline, &self.style.font).iter().sum() + } + + /// The Timeline's comp tabs, after its group's panel tabs whichever panel is shown. + fn group_extra_tabs(&mut self, ui: &mut egui::Ui, panels: &[PanelKind], active: &PanelKind, _floating: bool) { + if self.has_doc_tabs(panels) { + let selected = *active == PanelKind::Timeline; + self.doc_actions.extend(dock::doc_tabs(ui, ui.max_rect(), &self.docs, selected, &self.style, &mut self.app.auto)); + } } - if response.enabled() { delta } else { egui::Vec2::ZERO } } diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 2a39ea8ed..8e9c69fbf 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -14,7 +14,6 @@ pub mod color_picker; pub mod control; pub mod credits; pub mod dock; -mod dock_shared; pub mod dock_ui; mod expression_diagnostics; pub mod frames; @@ -30,6 +29,7 @@ mod pointer_wrap; pub mod prefs_live; pub mod state; pub mod theme; +pub mod updates_ui; pub mod widgets; mod workspace_state; @@ -37,7 +37,7 @@ use std::sync::Arc; use std::sync::mpsc::{Receiver, Sender}; pub use control::ControlRequest; -use dock::PanelKind; +use dock::{PanelKind, WorkspaceExt as _}; use effectcraft_engine::Session; use effectcraft_engine::project::ItemId; use effectcraft_engine::render::RenderOpts; @@ -441,6 +441,8 @@ pub struct EffectcraftApp { pub(crate) control_rx: Option>, pub(crate) deferred: Vec<(ControlRequest, f64)>, pub(crate) synthetic: Vec, + /// Input from floating panels' own OS windows for the main window's next frame. + pub(crate) forwarded: ForwardedInput, pub(crate) input_waiters: Vec>, /// Control requests waiting for an offloaded job (`wait: true` in the browser). pub(crate) job_waiters: Vec<(control::JobWaiter, Sender)>, @@ -479,6 +481,8 @@ pub struct EffectcraftApp { device_lost_close: Option, /// Answers of file dialogs shown without blocking ([`Hooks::file_dialog_async`]). pub(crate) dialog_answers: (Sender, Receiver), + /// Those dialogs that are up, for blocking floating panels' OS windows meanwhile. + pub(crate) file_dialogs: FileDialogsUp, /// Commands from the native menu bar. pub command_inbox: Option>, /// Pointer position in comp pixels (Info panel). @@ -489,6 +493,7 @@ pub struct EffectcraftApp { pub audio: Option, /// Audio scrubbing's open output (Ctrl/Cmd-drag the current time, `playback.scrubAudio`). pub scrub: Option, + pub(crate) updates_rt: updates_ui::Runtime, /// Audio panel VU meters. pub meter: audio::Meter, /// Waveform peak summaries per footage item (see `panels::waveform`). @@ -504,6 +509,13 @@ pub struct EffectcraftApp { /// Docked groups laid out last frame: (active panel, group rect) — `~` maximizes the one /// under the pointer. pub(crate) dock_rects: Vec<(PanelKind, egui::Rect)>, + /// The floating panels' OS windows that drew a panel last frame; one that is gone releases + /// its IME state. + pub(crate) native_viewports: Vec, + /// The native windows that drew a panel last frame without publishing their IME descriptor. + pub(crate) unpublished_viewports: Vec, + /// A floating panel shown by a command: its window comes to the front next frame. + pub(crate) pending_panel_raise: Option, /// Home screen: recent-project thumbnail textures by path (None = no thumbnail). pub(crate) home_thumbs: std::collections::HashMap>, /// The (project path, saved revision) whose thumbnail was stored last. @@ -519,14 +531,6 @@ pub struct EffectcraftApp { /// The saved workspaces in the settings store ([`effectcraft_engine::config::ConfigStore`]). pub const WORKSPACES_FILE: &str = "workspaces.json"; -#[derive(serde::Serialize, serde::Deserialize)] -struct SavedWorkspaces { - #[serde(default)] - workspaces: std::collections::BTreeMap, - #[serde(default)] - floating: std::collections::BTreeMap>, -} - /// The comp frames a playback pass covers (`first..=last`). #[derive(Clone, Copy, Debug)] struct FrameWindow { @@ -594,6 +598,7 @@ impl EffectcraftApp { control_rx: None, deferred: vec![], synthetic: vec![], + forwarded: ForwardedInput::default(), input_waiters: vec![], job_waiters: vec![], pending_screenshots: vec![], @@ -614,6 +619,7 @@ impl EffectcraftApp { gpu_failure_applied: None, device_lost_close: None, dialog_answers: std::sync::mpsc::channel(), + file_dialogs: FileDialogsUp::default(), command_inbox: None, pointer_comp: None, dialog_state: Default::default(), @@ -627,11 +633,15 @@ impl EffectcraftApp { applied_prefs: None, recovery: None, dock_rects: vec![], + native_viewports: vec![], + unpublished_viewports: vec![], + pending_panel_raise: None, 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(), } .with_ui_commands() } @@ -748,8 +758,7 @@ impl EffectcraftApp { self.ui.home_learn = false; } self.ui.workspace = name.to_string(); - self.ui.dock = self.ui.saved_workspaces.get(name).cloned().unwrap_or_else(|| dock::workspace(name)); - self.ui.floating = self.ui.saved_floating.get(name).cloned().unwrap_or_else(|| dock::workspace_floating(name)); + self.ui.dock = self.ui.saved_workspaces.get(name).cloned().unwrap_or_else(|| dock::Workspace::new(dock::workspace(name))); self.ui.maximized = None; } @@ -855,46 +864,65 @@ impl EffectcraftApp { /// Show panel `p` (opening it in its usual place if it is closed), bring it to the front and /// give it the focus: Window ▸ ``. pub fn show_panel(&mut self, p: PanelKind) { - if !self.ui.floating.iter().any(|f| f.panels.contains(&p)) && self.ui.maximized.is_some_and(|m| m != p) { + if !self.ui.dock.is_floating(p) && self.ui.maximized.is_some_and(|m| m != p) { self.ui.maximized = None; } self.raise_panel(p); self.ui.focused = p; } - /// Bring panel `p` to the front of its group, opening it in its usual place if it is closed, - /// without moving the focus (a comp opening brings up its viewer, an effect applied brings up - /// Effect Controls). + /// Bring panel `p` to the front of its group, opening it if it is closed, without moving the + /// focus (a comp opening brings up its viewer, an effect applied brings up Effect Controls). + /// A closed panel goes back where it was; one never laid out goes to its usual place: the + /// Composition panel in the centre with the Layer panel and other viewers (with none of + /// those left, above the Timeline), Layer and the viewers beside the Composition panel, and + /// so on. pub fn raise_panel(&mut self, p: PanelKind) { - if self.ui.floating.iter().any(|group| group.panels.contains(&p)) { - self.edit_layout(|layout| layout.apply(craft_ui::docking::Action::Activate { panel: p }).is_ok()); - return; - } - if !self.ui.dock.contains(p) { - // The Composition panel lives in the centre, with the Layer panel and other viewers; - // with none of those left, above the Timeline. - let centre = |d: &dock::DockNode| { - let mut v = Vec::new(); - d.panels(&mut v); - v.into_iter().find(|q| matches!(q, PanelKind::Layer | PanelKind::Viewer(_) | PanelKind::Flowchart | PanelKind::Footage)) - }; + if !self.ui.dock.is_open(p) { + let docked = |q: &PanelKind| self.ui.dock.is_docked(*q); let near = match p { - PanelKind::Composition => match centre(&self.ui.dock) { - Some(q) => q, - None if self.ui.dock.dock_panel(p, PanelKind::Timeline, dock::Zone::Top) => { - self.ui.dock.activate(p); - return; - } - None => PanelKind::EffectsPresets, - }, - PanelKind::Layer | PanelKind::Flowchart | PanelKind::Viewer(_) => PanelKind::Composition, - PanelKind::RenderQueue => PanelKind::Timeline, - PanelKind::EffectControls | PanelKind::History => PanelKind::Project, - _ => PanelKind::EffectsPresets, + PanelKind::Composition => self + .ui + .dock + .panels() + .into_iter() + .find(|q| matches!(q, PanelKind::Layer | PanelKind::Viewer(_) | PanelKind::Flowchart | PanelKind::Footage) && docked(q)), + PanelKind::Layer | PanelKind::Flowchart | PanelKind::Viewer(_) => Some(PanelKind::Composition), + PanelKind::RenderQueue => Some(PanelKind::Timeline), + PanelKind::EffectControls | PanelKind::History => Some(PanelKind::Project), + _ => Some(PanelKind::EffectsPresets), + } + .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 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), + }, + dock::permissions, + ) + .map(|_| ()) + } else if known { + workspace.set_visible(p, true, near, dock::permissions) + } else { + workspace.apply(craft_ui::docking::Action::Open { panel: p, anchor: near }, dock::permissions).map(|_| ()) }; - self.ui.dock.open_near(p, near); + match opened { + Ok(()) => self.ui.dock = workspace, + Err(e) => { + self.ui.status = format!("can't open {}: {e}", p.title()); + return; + } + } + } + let _ = self.ui.dock.apply(craft_ui::docking::Action::Activate { panel: p }, dock::permissions); + if self.ui.dock.is_floating(p) { + self.pending_panel_raise = Some(p); } - self.ui.dock.activate(p); } pub fn render_source(&self) -> RenderSource { @@ -1013,6 +1041,7 @@ impl EffectcraftApp { /// Run the commands whose non-blocking file dialogs have been answered. pub(crate) fn run_dialog_answers(&mut self) { while let Ok(answer) = self.dialog_answers.1.try_recv() { + self.file_dialogs.answered(); menus::dialog_answered(self, answer); } } @@ -1257,7 +1286,7 @@ impl EffectcraftApp { } let restore_max = preset.full_screen.then_some(self.ui.maximized); let viewer = panels::viewers::active_panel(self); - if preset.full_screen && self.ui.dock.contains(viewer) { + if preset.full_screen && self.ui.dock.is_docked(viewer) { self.ui.maximized = Some(viewer); } self.playback = Playback { @@ -2218,6 +2247,7 @@ impl EffectcraftApp { } // Frames and worker completions wake the app even while it is hidden. self.frames.set_context(ctx); + updates_ui::tick(self, ctx); if self.session.render_job.is_some() { self.session.poll_render(); ctx.request_repaint_after(std::time::Duration::from_millis(100)); @@ -2300,7 +2330,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.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() @@ -2473,6 +2503,7 @@ impl EffectcraftApp { panels::precomp::mini_flowchart(self, &ctx); panels::home::capture_thumbnail(self); panels::dialogs::show(self, &ctx); + updates_ui::show(self, &ctx); panels::scriptui_view::sync_panels(self); panels::scriptui_view::show_windows(self, &ctx); panels::learn::coach(self, &ctx); @@ -2626,6 +2657,62 @@ impl EffectcraftApp { } } +/// Non-blocking file dialogs ([`Hooks::file_dialog_async`]) that are up. While one is, the dock +/// area blocks floating panels' OS windows, as it does for a modal dialog; otherwise craft-ui +/// takes the app for inactive while the dialog has the keyboard, and hides floating palettes. +/// +/// A dialog can end without answering: on macOS a sheet whose window goes away ends without its +/// completion handler. A dialog is taken for gone, so floating windows never stay blocked, once +/// one of the app's windows has the keyboard again after none had it, or when one has kept it +/// for [`FileDialogsUp::UNSEEN`] since the dialog was asked for, so the dialog never showed. +#[derive(Default)] +pub(crate) struct FileDialogsUp { + count: usize, + /// When the oldest dialog up was first checked ([`FileDialogsUp::up`]). + since: Option, + /// None of the app's windows had the keyboard since then. + left: bool, +} + +impl FileDialogsUp { + /// Seconds a dialog has to take the keyboard from the app's windows. The desktop portal can + /// take a moment to show the first dialog on Linux. + const UNSEEN: f64 = 2.0; + + pub(crate) fn opened(&mut self) { + if self.count == 0 { + *self = Self::default(); + } + self.count = self.count.saturating_add(1); + } + + pub(crate) fn answered(&mut self) { + self.count = self.count.saturating_sub(1); + } + + /// Whether a dialog is up at `now`, `focused`: whether one of the app's windows has the + /// keyboard. + pub(crate) fn up(&mut self, focused: bool, now: f64) -> bool { + if self.count == 0 { + return false; + } + let since = *self.since.get_or_insert(now); + if !focused { + self.left = true; + } else if self.left || now - since >= Self::UNSEEN { + *self = Self::default(); + } + self.count > 0 + } +} + +/// Keys and dropped files from floating panels' OS windows (craft-ui `DockOutput`). +#[derive(Default)] +pub(crate) struct ForwardedInput { + pub(crate) events: Vec, + pub(crate) files: Vec, +} + impl eframe::App for EffectcraftApp { fn on_exit(&mut self) { self.save_workspace_state(); @@ -2640,6 +2727,8 @@ impl eframe::App for EffectcraftApp { /// 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) { + 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(); // Only a pass that can draw may receive synthetic input: `Context::run_ui` applies // everything the hook feeds to its input state, so a pass that cannot draw (fonts still diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rs index 9364630af..4f6bacbc3 100644 --- a/crates/ui-egui/src/menus.rs +++ b/crates/ui-egui/src/menus.rs @@ -8,7 +8,7 @@ use serde_json::{Value, json}; use crate::EffectcraftApp; -use crate::dock::PanelKind; +use crate::dock::{PanelKind, WorkspaceExt as _}; use crate::state::{Resolution, Tool}; use effectcraft_engine::menus::{MenuEntry, MenuNode}; @@ -415,6 +415,11 @@ pub fn invoke(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, params: V if crate::panels::layer_styles_dialog::route(app, id, ¶ms)? { return Ok(Value::Null); } + // Shared docking: `window.dockAction`, craft-ui's `window.panel.*` commands, `ui.dock`, + // `ui.dock.reset` and `window.panelWindow`. + if let Some(result) = crate::dock_ui::route(app, ctx, id, ¶ms) { + return result; + } // Legacy per-panel / per-workspace ids (`window.panel.Project`, `window.workspace.default`). if let Some(rest) = id.strip_prefix("window.panel.") { return frontend(app, ctx, "window.panel", json!({"panel": rest})); @@ -502,46 +507,6 @@ pub fn invoke(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, params: V _ => {} } } - if id == "window.dockAction" { - let value = params.get("action").cloned().ok_or("missing docking action")?; - let action: craft_ui::docking::Action = serde_json::from_value(value).map_err(|error| format!("invalid docking action: {error}"))?; - if matches!(&action, craft_ui::docking::Action::Open { .. } | craft_ui::docking::Action::OpenAt { .. }) { - return Err("use the panel open commands to preserve viewer and ScriptUI lifecycle callbacks".into()); - } - if let craft_ui::docking::Action::Close { panel } = &action { - let mut layout = crate::dock_shared::encode(&app.ui.dock, &app.ui.floating)?; - layout.apply(action.clone()).map_err(|error| error.to_string())?; - app.close_panel(*panel); - return Ok(Value::Null); - } - let mut error = None; - if !app.edit_layout(|layout| match layout.apply(action) { - Ok(()) => true, - Err(reason) => { - error = Some(reason); - false - } - }) { - return Err(error.unwrap_or_else(|| "invalid docking layout".into())); - } - return Ok(Value::Null); - } - // Multiple monitors: {panel, window?: bool} moves a panel into its own native window (or - // back into the main window; no `window` toggles). - if id == "window.panelWindow" { - // A panel name ("Info", "Effect Controls") or its serialized form ({"Viewer": 2}). - let value = params.get("panel").ok_or("panelWindow: need `panel`")?; - let panel = match value.as_str() { - Some(name) => PanelKind::from_name(name).ok_or(format!("unknown panel `{name}`"))?, - None => serde_json::from_value::(value.clone()).map_err(|_| "panelWindow: unknown `panel`".to_string())?, - }; - let window = match params.get("window") { - None | Some(Value::Null) => None, - Some(value) => Some(value.as_bool().ok_or("panelWindow: `window` must be true or false")?), - }; - let window = app.set_panel_window(ctx, panel, window)?; - return Ok(json!({"window": window})); - } // A UI-only command (not in the engine's menus), so `frontend` gets it from here. if id == "window.maximizeApp" { return frontend(app, ctx, id, params); @@ -560,7 +525,9 @@ pub fn invoke(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, params: V } "closePanel" => { let p = panel_of("panel").ok_or("closePanel: need `panel`")??; - app.close_panel(p); + if app.ui.dock.is_open(p) { + app.apply_dock(craft_ui::docking::Action::Close { panel: p })?; + } return Ok(Value::Null); } "floatPanel" => { @@ -569,22 +536,31 @@ pub fn invoke(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, params: V Some(value) => serde_json::from_value::<[f32; 4]>(value.clone()).map_err(|_| "rect must contain four finite numbers")?, None => crate::dock_ui::default_float_rect(ctx.content_rect()), }; - if !app.edit_layout(|l| l.float(p, r)) { - return Err(format!("can't undock {}", p.title())); - } + app.apply_dock(craft_ui::docking::Action::Float { panel: p, rect: r }).map_err(|e| format!("can't undock {}: {e}", p.title()))?; return Ok(Value::Null); } _ => { + // craft-ui's `window.panel.dock`: zones center/tab, left/right/top/bottom (a split + // beside the anchor), above/below; without an anchor a side zone docks along that + // edge of the whole workspace. let p = panel_of("panel").ok_or("dockPanel: need `panel`")??; - let anchor = panel_of("anchor").ok_or("dockPanel: need `anchor` (a docked panel)")??; - let zone = params - .get("zone") - .and_then(Value::as_str) - .map_or(Some(crate::dock::Zone::Center), crate::dock::Zone::from_name) - .ok_or("zone: center|left|right|top|bottom")?; - if !app.edit_layout(|l| l.dock(p, anchor, zone)) { - return Err(format!("can't dock {} at {} ({zone:?})", p.title(), anchor.title())); + let mut command = json!({"command": "window.panel.dock", "panel": p}); + if let Some(anchor) = panel_of("anchor") { + command["anchor"] = json!(anchor?); + command["zone"] = json!("center"); } + if let Some(zone) = params.get("zone") { + let zone = zone.as_str().ok_or("zone: center|tab|left|right|top|bottom|above|below")?.to_ascii_lowercase(); + if command.get("anchor").is_some() || zone != "center" { + command["zone"] = json!(zone); + } + } + if let Some(before) = panel_of("before") { + command["before"] = json!(before?); + } + let command: craft_ui::docking::DockCommand = + serde_json::from_value(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); } @@ -666,10 +642,7 @@ pub fn invoke(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, params: V // Alt+Shift+, / Alt+Shift+.: the previous / next tab of the focused panel's group. "window.nextPanel" | "window.previousPanel" => { let focused = app.ui.focused; - let group: Vec = match app.ui.floating.iter().find(|f| f.panels.contains(&focused)) { - Some(f) => f.panels.clone(), - None => app.ui.dock.group_of(focused).map(<[PanelKind]>::to_vec).unwrap_or_default(), - }; + let group = app.ui.dock.group_of(focused); let Some(i) = group.iter().position(|p| *p == focused) else { return Ok(Value::Null) }; let step = if id == "window.nextPanel" { 1 } else { group.len().saturating_sub(1) }; if let Some(next) = group.get((i + step) % group.len().max(1)).copied() { @@ -933,6 +906,10 @@ pub fn frontend(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, p: Valu ctx.copy_text(path.to_string()); json!({"path": path}) } + "app.checkForUpdates" | "help.checkForUpdates" => { + crate::updates_ui::check(app); + Value::Null + } "app.about" => { app.dialog = Some(crate::Dialog::About); Value::Null @@ -1174,7 +1151,6 @@ pub fn frontend(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, p: Valu "window.saveWorkspace" => { let name = app.ui.workspace.clone(); app.ui.saved_workspaces.insert(name.clone(), app.ui.dock.clone()); - app.ui.saved_floating.insert(name.clone(), app.ui.floating.clone()); app.store_saved_workspaces()?; json!({"workspace": name}) } @@ -1190,7 +1166,6 @@ pub fn frontend(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, p: Valu return Ok(Value::Null); }; app.ui.saved_workspaces.insert(name.clone(), app.ui.dock.clone()); - app.ui.saved_floating.insert(name.clone(), app.ui.floating.clone()); app.ui.workspace = name.clone(); app.store_saved_workspaces()?; json!({"workspace": name}) @@ -1213,7 +1188,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) { - app.ui.saved_floating.remove(&name); if app.ui.saved_workspaces.remove(&name).is_none() && !builtin { return Err(format!("no workspace `{name}`")); } @@ -1230,9 +1204,6 @@ pub fn frontend(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, p: Valu } 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 let Some(f) = app.ui.saved_floating.remove(&name) { - app.ui.saved_floating.insert(new.to_string(), f); - } if app.ui.workspace == name { app.ui.workspace = new.to_string(); } @@ -1448,6 +1419,7 @@ fn file_dialog(app: &mut EffectcraftApp, id: &str, params: &Value) -> Option Option bool { - if app.ui.floating.iter().any(|f| f.panels.get(f.active) == Some(&p)) { - return true; + if app.ui.dock.is_floating(p) { + return app.ui.dock.is_visible(p); } - match app.ui.maximized.filter(|m| app.ui.dock.contains(*m)) { + match app.ui.maximized.filter(|m| app.ui.dock.is_docked(*m)) { Some(m) => m == p, None => app.ui.dock.is_visible(p), } @@ -2569,7 +2541,7 @@ mod tests { run(&mut app, "window.toggleCompTimeline"); assert_eq!(app.ui.focused, PanelKind::Timeline); // Alt+Shift+. / Alt+Shift+,: the tabs of the focused panel's group, wrapping. - let group = app.ui.dock.group_of(PanelKind::Timeline).unwrap().to_vec(); + let group = app.ui.dock.group_of(PanelKind::Timeline); assert!(group.len() > 1, "{group:?}"); run(&mut app, "window.nextPanel"); assert_eq!(app.ui.focused, group[(group.iter().position(|p| *p == PanelKind::Timeline).unwrap() + 1) % group.len()]); @@ -2581,7 +2553,7 @@ mod tests { // With another panel active it closes that panel. app.show_panel(PanelKind::Project); run(&mut app, "window.closeAll"); - assert!(!app.ui.dock.contains(PanelKind::Project)); + assert!(!app.ui.dock.is_open(PanelKind::Project)); } #[test] @@ -2703,6 +2675,56 @@ mod tests { let _ = std::fs::remove_dir_all(&dir); } + /// While a command's OS file dialog is up, floating panels' OS windows are blocked, as for + /// a modal dialog; a dialog that ends, answered or not, unblocks them, and Save As opens a + /// dialog again. A macOS sheet can end without answering (its window went away): once one of + /// the app's windows has the keyboard again, or keeps it as if no dialog showed, floating + /// windows are not left blocked. + #[test] + 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(); + let pending: Arc>> = Arc::default(); + let queue = pending.clone(); + app.hooks.file_dialog_async = Some(Box::new(move |_dialog, done| queue.lock().unwrap().push(done))); + let blocked = |app: &mut EffectcraftApp, focused: bool, time: f64| { + let input = egui::RawInput { focused, time: Some(time), ..Default::default() }; + let mut out = false; + ctx.run_ui(input, |ui| out = app.floats_blocked(ui.ctx())).textures_delta.clear(); + out + }; + assert!(!blocked(&mut app, true, 0.0)); + // Cancelled. + invoke(&mut app, &ctx, "file.saveAs", json!({})).unwrap(); + assert!(blocked(&mut app, true, 0.1), "blocked while the dialog takes the keyboard"); + assert!(blocked(&mut app, false, 0.2)); + let done = pending.lock().unwrap().pop().expect("a dialog was shown"); + done(Vec::new()); + app.run_dialog_answers(); + assert!(!blocked(&mut app, false, 0.3)); + // Save As asks again; the sheet ends without answering. + invoke(&mut app, &ctx, "file.saveAs", json!({})).unwrap(); + assert_eq!(pending.lock().unwrap().len(), 1, "Save As opens a dialog again"); + assert!(blocked(&mut app, true, 1.0)); + assert!(blocked(&mut app, false, 1.1)); + assert!(blocked(&mut app, false, 9.0), "a dialog may stay up for long"); + assert!(!blocked(&mut app, true, 9.1), "an app window has the keyboard again"); + // A dialog that never takes the keyboard. + invoke(&mut app, &ctx, "file.saveAs", json!({})).unwrap(); + assert!(blocked(&mut app, true, 10.0)); + assert!(blocked(&mut app, true, 11.0)); + assert!(!blocked(&mut app, true, 12.5)); + // Answers of dialogs taken for gone arrive late: nothing stays blocked. + for done in pending.lock().unwrap().drain(..) { + done(Vec::new()); + } + app.run_dialog_answers(); + assert!(!blocked(&mut app, false, 13.0)); + invoke(&mut app, &ctx, "file.saveAs", json!({})).unwrap(); + assert!(blocked(&mut app, false, 13.1), "a later dialog blocks again"); + } + #[test] fn tga_is_available_in_import_replace_and_proxy_dialogs() { use std::sync::{Arc, Mutex}; diff --git a/crates/ui-egui/src/native_menu.rs b/crates/ui-egui/src/native_menu.rs index 7d7046ed3..9288ec4e1 100644 --- a/crates/ui-egui/src/native_menu.rs +++ b/crates/ui-egui/src/native_menu.rs @@ -126,6 +126,27 @@ impl NativeMenu { } } +/// The native menu spec as the menu bar shows it now: [`build`], with the Edit items a text field +/// takes ([`edits_text`]) enabled while one has the keyboard ([`text_field_window`]). Paste +/// otherwise follows the project clipboard and would be greyed out with nothing copied there, +/// while the field can paste. +pub fn build_now(app: &EffectcraftApp, ctx: &egui::Context) -> NativeMenu { + fn enable(nodes: &mut [NativeNode]) { + for node in nodes { + match node { + NativeNode::Item(item) if edits_text(&item.command) => item.enabled = true, + NativeNode::Submenu { children, .. } => enable(children), + _ => {} + } + } + } + let mut menu = build(app); + if text_field_window(ctx).is_some() { + enable(&mut menu.menus); + } + menu +} + /// Build the native menu spec for the app's current state. pub fn build(app: &EffectcraftApp) -> NativeMenu { fn rec(app: &EffectcraftApp, nodes: &[MenuNode], path: &str, out: &mut Vec) { @@ -332,9 +353,23 @@ pub fn state_key(app: &EffectcraftApp) -> u64 { h.finish() } -/// Commands that act on a focused text field instead (Edit menu while typing): the egui event to -/// send in their place. -fn text_field_event(command: &str, clipboard: Option) -> Option> { +/// 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). +pub fn text_field_window(ctx: &egui::Context) -> Option { + craft_ui::docking::typing_window(ctx).or_else(|| ctx.egui_wants_keyboard_input().then_some(egui::ViewportId::ROOT)) +} + +/// Whether a focused text field takes the menu command `command` ([`activate`]): the native menu +/// keeps such items enabled while one has the keyboard, whatever the project allows. +pub fn edits_text(command: &str) -> bool { + text_field_event(command).is_some() +} + +/// Commands that act on a focused text field instead (Edit menu while typing): the egui events +/// to send in their place. Paste is a Cmd+V press, which the field's window turns into a request +/// for the clipboard text. +fn text_field_event(command: &str) -> Option> { let key = |k: egui::Key, shift: bool| egui::Event::Key { key: k, physical_key: None, @@ -345,7 +380,7 @@ fn text_field_event(command: &str, clipboard: Option) -> Option vec![egui::Event::Copy], "edit.cut" => vec![egui::Event::Cut], - "edit.paste" => vec![egui::Event::Paste(clipboard?)], + "edit.paste" => vec![key(egui::Key::V, false)], "edit.selectAll" => vec![key(egui::Key::A, false)], "edit.undo" => vec![key(egui::Key::Z, false)], "edit.redo" => vec![key(egui::Key::Z, true)], @@ -353,8 +388,43 @@ fn text_field_event(command: &str, clipboard: Option) -> Option) { + if window == egui::ViewportId::ROOT { + for event in events { + match event { + egui::Event::Key { key: egui::Key::V, .. } => { + if let Some(text) = app.hooks.clipboard_text.as_ref().and_then(|f| f()) { + app.synthetic.push(egui::Event::Paste(text)); + } + } + event => app.synthetic.push(event), + } + } + 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 }) + } + _ => None, + }; + std::iter::once(event).chain(release) + }) + .collect(); + craft_ui::docking::send_keys(ctx, window, events); +} + /// Run a native menu item (by id) the way the in-window menu bar does. While a text field has -/// the keyboard, Edit ▸ Cut/Copy/Paste/Select All/Undo/Redo edit the text instead. +/// the keyboard ([`text_field_window`]), Edit ▸ Cut/Copy/Paste/Select All/Undo/Redo edit the +/// text instead. pub fn activate(app: &mut EffectcraftApp, ctx: &egui::Context, menu: &NativeMenu, id: &str) -> Result { let item = menu.find(id).ok_or_else(|| format!("no native menu item `{id}`"))?; let (command, params) = (item.command.clone(), item.params.clone()); @@ -369,13 +439,12 @@ pub fn activate(app: &mut EffectcraftApp, ctx: &egui::Context, menu: &NativeMenu ctx.request_repaint(); return Ok(Value::Null); } - if ctx.egui_wants_keyboard_input() { - let clip = if command == "edit.paste" { app.hooks.clipboard_text.as_ref().and_then(|f| f()) } else { None }; - if let Some(events) = text_field_event(&command, clip) { - app.synthetic.extend(events); - ctx.request_repaint(); - return Ok(Value::Null); - } + // The menu bar takes the Edit menu's key equivalents before any window sees them: while a + // text field has the keyboard, in the main window or a floating panel's own window, the + // field gets the key and the project command does not run. + if let (Some(window), Some(events)) = (text_field_window(ctx), text_field_event(&command)) { + send_to_text_field(app, ctx, window, events); + return Ok(Value::Null); } let params = if params.is_null() { json!({}) } else { params }; let (command, params) = crate::menus::menu_choice(app, command, params); @@ -605,7 +674,7 @@ mod tests { assert_ne!(state_key(&app), k0); // A tab behind another one, a closed panel and panels under a maximized one are not shown. assert_eq!((checked(&app, "renderQueue"), checked(&app, "timeline")), (Some(true), Some(false))); - app.ui.dock.close(PanelKind::RenderQueue); + app.close_panel(PanelKind::RenderQueue); assert_eq!((checked(&app, "renderQueue"), checked(&app, "timeline")), (Some(false), Some(true))); app.ui.maximized = Some(PanelKind::Timeline); assert_eq!((checked(&app, "timeline"), checked(&app, "project")), (Some(true), Some(false))); @@ -648,9 +717,9 @@ mod tests { activate(app, &ctx, &spec, &id).unwrap(); }; choose(&mut app); - assert!(app.ui.dock.contains(PanelKind::Align)); + assert!(crate::dock::WorkspaceExt::is_open(&app.ui.dock, PanelKind::Align)); choose(&mut app); - assert!(!app.ui.dock.contains(PanelKind::Align)); + assert!(!crate::dock::WorkspaceExt::is_open(&app.ui.dock, PanelKind::Align)); } #[test] @@ -663,8 +732,7 @@ mod tests { activate(&mut app, &ctx, &spec, &id).unwrap(); assert_eq!(app.session.active_comp().unwrap().layers.len(), n + 1); assert!(activate(&mut app, &ctx, &spec, "m.999").is_err()); - assert!(text_field_event("edit.copy", None).is_some()); - assert!(text_field_event("edit.paste", None).is_none()); - assert!(text_field_event("layer.newNull", None).is_none()); + assert!(edits_text("edit.copy") && edits_text("edit.paste")); + assert!(!edits_text("layer.newNull")); } } diff --git a/crates/ui-egui/src/panels/dialogs.rs b/crates/ui-egui/src/panels/dialogs.rs index b59af5721..47de23d59 100644 --- a/crates/ui-egui/src/panels/dialogs.rs +++ b/crates/ui-egui/src/panels/dialogs.rs @@ -170,6 +170,18 @@ pub(crate) fn modal_space(ctx: &egui::Context) -> egui::Vec2 { (ctx.content_rect().size() - vec2(48.0, 48.0)).max(vec2(120.0, 80.0)) } +fn modal_pass_id() -> egui::Id { + egui::Id::unique("effectcraft-modal-pass") +} + +/// Whether a modal dialog showed in this pass or the one before: egui's `Modal` blocks input +/// only in its own window, so floating panels in OS windows of their own are blocked by the +/// dock area while this holds. Dialogs draw after the dock, so the previous pass counts. +pub(crate) fn modal_open(ctx: &egui::Context) -> bool { + let shown = ctx.data(|d| d.get_temp::(modal_pass_id())); + shown.is_some_and(|pass| pass.saturating_add(1) >= ctx.cumulative_pass_nr_for(egui::ViewportId::ROOT)) +} + pub(crate) fn modal(ctx: &egui::Context, title: &str, size: egui::Vec2, t: &Tokens, body: impl FnOnce(&mut egui::Ui)) { modal_with_scroll(ctx, title, size, t, false, body); } @@ -190,6 +202,8 @@ fn modal_with_scroll(ctx: &egui::Context, title: &str, size: egui::Vec2, t: &Tok /// only its content: `body` gets the height left under the title, with `size` kept within the /// window. pub(crate) fn modal_fit(ctx: &egui::Context, title: &str, size: egui::Vec2, t: &Tokens, body: impl FnOnce(&mut egui::Ui, f32)) { + let pass = ctx.cumulative_pass_nr_for(egui::ViewportId::ROOT); + ctx.data_mut(|d| d.insert_temp(modal_pass_id(), pass)); let size = size.min(modal_space(ctx)); let id = egui::Id::unique(("modal", title)); // Dragging the title row moves the dialog off what it edits. The offset is kept within the @@ -693,6 +707,29 @@ fn palette(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) { mod tests { use super::*; + #[test] + fn modal_open_holds_from_a_shown_dialog_until_the_pass_after_it_closes() { + let (app, ctx) = app(); + let t = app.tokens; + // Asked as the dock asks it: during the pass, before the dialogs draw. + let pass = |show: bool| { + let mut open = false; + let mut output = ctx.run_ui(egui::RawInput::default(), |ui| { + open = modal_open(ui.ctx()); + if show { + modal(ui.ctx(), "Test", vec2(200.0, 100.0), &t, |_| {}); + } + }); + output.textures_delta.clear(); + open + }; + assert!(!pass(false)); + assert!(!pass(true), "the first pass of a dialog finds none shown yet"); + assert!(pass(true)); + assert!(pass(false), "the pass after the last one shown still counts"); + assert!(!pass(false)); + } + fn app() -> (EffectcraftApp, egui::Context) { let ctx = egui::Context::default(); let mut app = EffectcraftApp::new(effectcraft_engine::Session::default()); diff --git a/crates/ui-egui/src/panels/home.rs b/crates/ui-egui/src/panels/home.rs index 5522548eb..3b735e47e 100644 --- a/crates/ui-egui/src/panels/home.rs +++ b/crates/ui-egui/src/panels/home.rs @@ -127,7 +127,7 @@ pub fn format_size(bytes: u64) -> String { /// The Kind column: what a recent file is, by its extension, in the interface language. fn kind_of(path: &str) -> &'static str { - tr(match std::path::Path::new(path).extension().and_then(|e| e.to_str()).map(str::to_ascii_lowercase).as_deref() { + tr(match std::path::Path::new(path).extension().and_then(std::ffi::OsStr::to_str).map(str::to_ascii_lowercase).as_deref() { Some("ecproj") => "EffectCraft project", Some("aep" | "aepx") => "After Effects project", Some("json" | "lottie") => "Lottie animation", diff --git a/crates/ui-egui/src/panels/mod.rs b/crates/ui-egui/src/panels/mod.rs index 5327ab170..9a8fd2a54 100644 --- a/crates/ui-egui/src/panels/mod.rs +++ b/crates/ui-egui/src/panels/mod.rs @@ -220,10 +220,6 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, p: PanelKind, rect: Rec pub fn panel_menu_popup(app: &mut EffectcraftApp, ui: &mut egui::Ui) { let id = egui::Id::unique("panel-menu"); let Some((panel, pos)) = ui.ctx().data(|d| d.get_temp::<(PanelKind, egui::Pos2)>(id)) else { return }; - // The menu opens in the window that shows the panel (a panel can have its own window). - if app.panel_viewport(ui.ctx(), panel) != ui.ctx().viewport_id() { - return; - } let mut close = false; let area = egui::Area::new(id.with("area")).order(egui::Order::Foreground).fixed_pos(pos).show(ui.ctx(), |ui| { egui::Frame::popup(ui.style()).show(ui, |ui| { @@ -232,13 +228,14 @@ pub fn panel_menu_popup(app: &mut EffectcraftApp, ui: &mut egui::Ui) { let _ = app.dock_command(ui.ctx(), craft_ui::docking::Action::Close { panel }); close = true; } - let floating = app.ui.floating.iter().any(|f| f.panels.contains(&panel)); + 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 }); close = true; } - // Multiple monitors: a native window of its own, which can go on another screen. + // Multiple monitors: an OS window of its own, which can go on another screen. Where + // egui embeds viewports (the web), floating windows stay in the page. if !ui.ctx().embed_viewports() { let windowed = app.in_panel_window(panel); if ui.button(if windowed { tr("Move Panel to Main Window") } else { tr("Move Panel to New Window") }).clicked() { diff --git a/crates/ui-egui/src/panels/scriptui_view.rs b/crates/ui-egui/src/panels/scriptui_view.rs index df1b85fab..40096c8c9 100644 --- a/crates/ui-egui/src/panels/scriptui_view.rs +++ b/crates/ui-egui/src/panels/scriptui_view.rs @@ -15,7 +15,7 @@ use egui::{Align2, Color32, Rect, Sense, Stroke, StrokeKind, UiBuilder, pos2, ve use serde_json::{Value, json}; use crate::EffectcraftApp; -use crate::dock::PanelKind; +use crate::dock::{PanelKind, WorkspaceExt as _}; use crate::theme::Tokens; enum Act { @@ -587,12 +587,7 @@ pub fn panel_title(app: &EffectcraftApp, id: u32) -> Option { /// Close the dock panels whose script window has gone (the script closed it, or a saved /// workspace from an earlier run). pub fn sync_panels(app: &mut EffectcraftApp) { - let mut all = vec![]; - app.ui.dock.panels(&mut all); - for f in &app.ui.floating { - all.extend(f.panels.iter().copied()); - } - for p in all { + for p in app.ui.dock.panels() { if let PanelKind::ScriptPanel(id) = p && app.session.script_ui.window(id).is_none() { diff --git a/crates/ui-egui/src/panels/timeline.rs b/crates/ui-egui/src/panels/timeline.rs index cf8a8d80d..f1d107d5e 100644 --- a/crates/ui-egui/src/panels/timeline.rs +++ b/crates/ui-egui/src/panels/timeline.rs @@ -1776,6 +1776,9 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) { p.rect_filled(handle, 2.0, t.accent); let resp = ui.interact(hr, egui::Id::unique(("wa", set)), Sense::drag()); app.auto.add(&format!("timeline.workArea.{set}"), hr, set); + if resp.dragged() || resp.hovered() { + ctx.set_cursor_icon(egui::CursorIcon::ResizeHorizontal); + } if resp.dragged() && let Some(pt) = resp.interact_pointer_pos() { diff --git a/crates/ui-egui/src/panels/viewer_text.rs b/crates/ui-egui/src/panels/viewer_text.rs index 3c5c04f9e..5fe55638e 100644 --- a/crates/ui-egui/src/panels/viewer_text.rs +++ b/crates/ui-egui/src/panels/viewer_text.rs @@ -269,6 +269,13 @@ pub(crate) fn begin_ui(ctx: &egui::Context) { ctx.data_mut(|data| data.remove::(id)); } +/// Whether the text editor recorded its IME geometry in this pass of the current viewport. +pub(crate) fn ime_recorded(ctx: &egui::Context) -> bool { + let viewport = ctx.viewport_id(); + let pass = ctx.cumulative_pass_nr_for(viewport); + ctx.data(|d| d.get_temp::(ime_geometry_id(viewport))).is_some_and(|(p, _, _)| p == pass) +} + /// Close a logic-only tick: when no full UI pass ran, revoke admission and resync and suspend the reset guard so a /// hidden tick never publishes IME state. pub(crate) fn finish_logic(app: &EffectcraftApp, ctx: &egui::Context) { @@ -298,7 +305,7 @@ fn ime_composition_id(viewport: egui::ViewportId) -> egui::Id { egui::Id::unique(("viewer-text-ime-composition", viewport)) } /// The `egui::Id` under which the current pass number, text region and caret rectangle are stored for the -/// pass-end finalizer. +/// viewport IME publisher. fn ime_geometry_id(viewport: egui::ViewportId) -> egui::Id { egui::Id::unique(("viewer-text-ime-geometry", viewport)) } @@ -553,11 +560,12 @@ fn visible_preedit(ui: &egui::Ui, app: &EffectcraftApp) -> Option { (p.owner == owner && !p.text.is_empty()).then_some(p.text) } -/// Publish the settled descriptor for one completed viewport pass. +/// Publish the descriptor from this viewport's current text state and recorded geometry. /// -/// This runs at the very end of a root pass (after dock actions, ScriptUI, learn and dialogs) -/// and at the end of each panel-window pass after that window's actions. The overlay only -/// records geometry; it never publishes early with a snapshot that a later action can replace. +/// The root viewport publishes after dock actions, ScriptUI, learn and dialogs. Native panel +/// windows publish after the IME-owning body records geometry and again after their last body; +/// publication can therefore precede later bodies in that window. The overlay only records +/// geometry; this function resolves the current owner and availability when it publishes. pub(crate) fn finish_ime(app: &mut EffectcraftApp, ui: &egui::Ui) { let ctx = ui.ctx(); let viewport = ctx.viewport_id(); @@ -1407,7 +1415,7 @@ fn draw(app: &mut EffectcraftApp, ui: &mut egui::Ui, painter: &egui::Painter, ma let rect = Rect::from_points(&quad); app.auto.add("viewer.textEdit", rect, &format!("Editing {}", e.layer.name)); let cursor_rect = Rect::from_two_pos(sa, sb).expand2(vec2(1.0, 0.0)); - // The outgoing IME descriptor is published by the pass-end finalizer, with this actual + // The viewport IME publisher uses this actual // caret geometry and the edited layer's committed `TextDoc` (never the bidi or pre-edit // display text). An available-empty document stays distinct from unavailable. let viewport = ui.ctx().viewport_id(); @@ -1564,6 +1572,95 @@ mod tests { } } + /// One native floating window holding the Timeline's group and then the Viewer's. + fn two_group_window() -> craft_ui::docking::Floating { + 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") + } + + impl ImePass { + /// One pass of a native window with a body that edits no text and the Viewer's editor, + /// in the order given, publishing as `NativeIme` decides or, with `every`, after each + /// body. Returns the descriptor and the preedit the pass ended with. + fn window( + &mut self, + app: &mut EffectcraftApp, + window: &craft_ui::docking::Floating, + events: Vec, + viewer_first: bool, + every: bool, + ) -> (Option, Option) { + let ctx = self.ctx.clone(); + let (rect, viewport) = (self.rect, self.viewport); + let mut viewports = egui::ViewportIdMap::default(); + viewports.insert(viewport, egui::ViewportInfo::default()); + 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 order = if viewer_first { [true, false] } else { [false, true] }; + for viewer in order { + if ime.begin_body(viewport) { + begin_ui(ui.ctx()); + } + if viewer { + ui.interact(rect, focus_id(), egui::Sense::focusable_noninteractive()); + ui.memory_mut(|m| m.request_focus(focus_id())); + sync_ime_target(ui, app); + keyboard(app, ui, rect); + let pass = ui.ctx().cumulative_pass_nr_for(viewport); + ui.data_mut(|d| d.insert_temp(ime_geometry_id(viewport), (pass, rect, rect))); + } + if ime.publishes(viewport, ime_recorded(ui.ctx())) || every { + finish_ime(app, ui); + } + } + assert!(ime.unpublished().is_empty(), "the window published"); + preedit = read_preedit(ui).map(|p| p.text); + }); + out.textures_delta.clear(); + (out.platform_output.ime, preedit) + } + } + + #[test] + fn native_window_with_a_group_before_the_viewer_keeps_the_composition() { + let window = two_group_window(); + let viewport = craft_ui::docking::DockArea::::window_viewport(crate::dock_ui::area_id(), 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); + let mut pass = ImePass::new(viewport); + let (first, preedit) = pass.window(&mut app, &window, vec![preview()], viewer_first, false); + let first = first.expect("the editor publishes"); + assert_eq!(preedit.as_deref(), Some("é")); + for _ in 0..2 { + let (ime, preedit) = pass.window(&mut app, &window, vec![], viewer_first, false); + let ime = ime.expect("the editor keeps publishing"); + assert!(!ime.should_interrupt_composition, "viewer first: {viewer_first}"); + assert_eq!((ime.owner, ime.context_generation), (first.owner, first.context_generation), "the same IME context"); + assert_eq!(preedit.as_deref(), Some("é"), "the preedit survives the other body"); + } + } + // Publishing after the body drawn before the Viewer clears the preedit and interrupts. + let (mut app, _) = editor("abcd", 4, 4); + let mut pass = ImePass::new(viewport); + pass.window(&mut app, &window, vec![preview()], false, true); + let (ime, preedit) = pass.window(&mut app, &window, vec![], false, true); + assert!(ime.expect("the editor publishes").should_interrupt_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), &[]); + 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); + ime.begin_body(viewport); + assert!(ime.publishes(viewport, false)); + } + fn ime_text(ime: &egui::output::IMEOutput) -> (&str, usize, usize) { let p = ime.surrounding_text.available().expect("committed surrounding text"); (p.text.as_str(), p.cursor, p.anchor) diff --git a/crates/ui-egui/src/panels/viewers.rs b/crates/ui-egui/src/panels/viewers.rs index 097cbeced..e8be901b9 100644 --- a/crates/ui-egui/src/panels/viewers.rs +++ b/crates/ui-egui/src/panels/viewers.rs @@ -14,7 +14,7 @@ use egui::{Align2, Color32, Rect, Sense, pos2, vec2}; use serde_json::json; use crate::EffectcraftApp; -use crate::dock::PanelKind; +use crate::dock::{PanelKind, WorkspaceExt as _}; use crate::frames::{FrameImage, FrameKey}; use crate::theme::Tokens; @@ -59,7 +59,7 @@ pub fn locked(app: &EffectcraftApp, id: u32) -> bool { /// Viewer `id`'s panel is docked or floating. fn open(app: &EffectcraftApp, id: u32) -> bool { let p = panel(id); - app.ui.dock.contains(p) || app.ui.floating.iter().any(|f| f.panels.contains(&p)) + app.ui.dock.is_open(p) } /// The comp viewer `id` shows: the active comp in the active viewer, else its own. @@ -241,7 +241,7 @@ pub fn on_open_comp(app: &mut EffectcraftApp, comp: ItemId) { // The comp's viewer and its Timeline tab come to the front (unless locked), reopened if they // were closed (as in After Effects). for p in [active_panel(app), PanelKind::Timeline] { - let closed = !app.ui.dock.contains(p) && !app.ui.floating.iter().any(|f| f.panels.contains(&p)); + let closed = !app.ui.dock.is_open(p); if closed || !app.ui.locked_tabs.contains(&p.id()) { app.raise_panel(p); } @@ -267,8 +267,8 @@ fn add_viewer(app: &mut EffectcraftApp, near: u32) -> u32 { let id = app.ui.viewers.keys().copied().max().unwrap_or(0).saturating_add(1).max(1); app.ui.viewers.insert(id, None); let p = panel(id); - let anchor = if app.ui.dock.contains(panel(near)) { panel(near) } else { PanelKind::Composition }; - app.ui.dock.open_near(p, anchor); + 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); id } diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs index 1e2f57204..88b8e7fa4 100644 --- a/crates/ui-egui/src/state.rs +++ b/crates/ui-egui/src/state.rs @@ -4,7 +4,7 @@ use std::collections::{BTreeMap, BTreeSet}; use serde::{Deserialize, Serialize}; -use crate::dock::{DockNode, PanelKind}; +use crate::dock::PanelKind; use crate::icons::Icon; #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)] @@ -568,23 +568,20 @@ pub struct UiState { /// Tool shown in each toolbar slot. pub slot_tools: Vec, pub workspace: String, - pub dock: DockNode, + /// The current layout: docked frames, floating windows (one can be recorded as its own + /// native window, Move Panel to New Window) and the places of closed panels. + pub dock: crate::dock::Workspace, /// Saved workspace layouts (Save Changes to this Workspace / Save as New Workspace). #[serde(default)] - pub saved_workspaces: std::collections::BTreeMap, - /// Undocked (floating) panel groups. - #[serde(default)] - pub floating: Vec, - /// Floating panels of the saved workspaces. - #[serde(default)] - pub saved_floating: std::collections::BTreeMap>, - /// Floating groups shown in their own native window instead of over the dock (Move Panel - /// to New Window), so they can be placed on another monitor. - #[serde(default)] - pub panel_windows: Vec, + pub saved_workspaces: std::collections::BTreeMap, /// The panel maximized to fill the dock area (`~`), if any. #[serde(default)] pub maximized: Option, + /// 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, /// 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)] @@ -700,11 +697,9 @@ impl Default for UiState { script_console: Default::default(), slot_tools: Tool::SLOTS.iter().map(|s| s[0]).collect(), workspace: "Default".into(), - dock: crate::dock::workspace("Default"), + dock: crate::dock::Workspace::new(crate::dock::workspace("Default")), saved_workspaces: Default::default(), - floating: vec![], - saved_floating: Default::default(), - panel_windows: vec![], + native_outer: Vec::new(), maximized: None, locked_tabs: BTreeSet::new(), viewers: Default::default(), diff --git a/crates/ui-egui/src/updates_ui.rs b/crates/ui-egui/src/updates_ui.rs new file mode 100644 index 000000000..0101e16ae --- /dev/null +++ b/crates/ui-egui/src/updates_ui.rs @@ -0,0 +1,125 @@ +//! Software updates, background check at startup, and startup prompt modal. + +use crate::EffectcraftApp; + +#[cfg(not(target_arch = "wasm32"))] +use craft_update::updater::{Action, Status, Updater}; + +pub(crate) struct Runtime { + #[cfg(not(target_arch = "wasm32"))] + updater: Updater, + /// The desktop app turns the check at start on; tests and the web build leave it off. + #[cfg(not(target_arch = "wasm32"))] + startup_check: bool, + #[cfg(not(target_arch = "wasm32"))] + check_requested: bool, + pub(crate) manual_window_open: bool, + pub(crate) status_message: Option, +} + +impl Default for Runtime { + fn default() -> Self { + Self { + #[cfg(not(target_arch = "wasm32"))] + updater: Updater::new(&craft_update::suite::EFFECTCRAFT, env!("CARGO_PKG_VERSION")), + #[cfg(not(target_arch = "wasm32"))] + startup_check: false, + #[cfg(not(target_arch = "wasm32"))] + check_requested: false, + manual_window_open: false, + status_message: None, + } + } +} + +impl EffectcraftApp { + /// Whether the app asks for a newer release when it starts (off until the desktop app turns it on). + #[cfg(not(target_arch = "wasm32"))] + pub fn set_startup_update_check(&mut self, on: bool) { + self.updates_rt.startup_check = on; + } +} + +pub(crate) fn check(app: &mut EffectcraftApp) { + #[cfg(not(target_arch = "wasm32"))] + { + app.updates_rt.check_requested = true; + } + #[cfg(target_arch = "wasm32")] + { + app.updates_rt.manual_window_open = true; + app.updates_rt.status_message = Some(crate::i18n::tr("Update check is not supported in the web browser.").to_string()); + } +} + +pub(crate) fn tick(app: &mut EffectcraftApp, ctx: &egui::Context) { + #[cfg(not(target_arch = "wasm32"))] + { + let rt = &mut app.updates_rt; + if std::mem::take(&mut rt.check_requested) { + rt.updater.check_now(ctx); + } else if rt.startup_check { + rt.updater.check_at_start(ctx); + } + rt.updater.tick(ctx); + } + #[cfg(target_arch = "wasm32")] + let _ = (app, ctx); +} + +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) { + Action::OpenUrl(url) => ctx.open_url(egui::OpenUrl::new_tab(url)), + Action::Close => ctx.send_viewport_cmd(egui::ViewportCommand::Close), + Action::None => {} + } + // The window answers Help ▸ Check for Updates, so it follows the updater's status. + let rt = &mut app.updates_rt; + (rt.manual_window_open, rt.status_message) = match rt.updater.status() { + Status::Idle => (false, None), + Status::Checking => (true, None), + Status::UpToDate => ( + true, + Some(crate::i18n::tr("EffectCraft {version} is currently the newest version available.").replace("{version}", env!("CARGO_PKG_VERSION"))), + ), + Status::Failed(e) => (true, Some(crate::i18n::tr("Could not check for updates:\n{error}").replace("{error}", e))), + }; + } + + if app.updates_rt.manual_window_open { + let mut open = true; + let mut close = false; + egui::Window::new(crate::i18n::tr("Check for Updates")) + .open(&mut open) + .resizable(false) + .collapsible(false) + .anchor(egui::Align2::CENTER_CENTER, egui::vec2(0.0, 0.0)) + .show(ctx, |ui| { + if let Some(msg) = &app.updates_rt.status_message { + ui.label(msg); + } else { + ui.label(crate::i18n::tr("Checking for updates…")); + } + ui.add_space(8.0); + ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { + if ui.button(crate::i18n::tr("Close")).clicked() { + close = true; + } + }); + }); + if !open || close { + app.updates_rt.manual_window_open = false; + app.updates_rt.status_message = None; + } + } + + // Closing the window dismisses the outcome it showed. + #[cfg(not(target_arch = "wasm32"))] + if !app.updates_rt.manual_window_open { + app.updates_rt.updater.dismiss_status(); + } +} diff --git a/crates/ui-egui/src/workspace_state.rs b/crates/ui-egui/src/workspace_state.rs index c2ac9e373..92e41fde5 100644 --- a/crates/ui-egui/src/workspace_state.rs +++ b/crates/ui-egui/src/workspace_state.rs @@ -5,93 +5,72 @@ use std::collections::BTreeMap; use effectcraft_engine::config::ConfigStore; use serde::{Deserialize, Serialize}; -use crate::dock::{DockNode, Floating, PanelKind, PanelWindow, SplitSize}; +use crate::dock::{PanelKind, Workspace}; use crate::state::UiState; +mod legacy; + const FILE: &str = "workspaces.json"; +/// An earlier version's file, kept when it is first rewritten in the current format. +const BACKUP: &str = "workspaces.old.json"; const MAX_BYTES: usize = 1024 * 1024; const MAX_WORKSPACES: usize = 64; -const MAX_NODES: usize = 4096; -const MAX_DEPTH: usize = 32; -const MAX_PANELS: usize = 128; /// Leave room for new viewers without approaching the u32 allocator limit. const MAX_VIEWER_ID: u32 = 65_535; -const MAX_COORD: f32 = 1_000_000.0; +/// The snapshot version: 2 holds craft-ui docking workspaces. +const VERSION: u32 = 2; #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] struct Snapshot { version: u32, workspace: String, - dock: DockNode, - floating: Vec, + dock: Workspace, focused: PanelKind, maximized: Option, - saved_workspaces: BTreeMap, - saved_floating: BTreeMap>, - /// Floating groups in their own native window (absent from files of earlier versions). - #[serde(default)] - panel_windows: Vec, + saved_workspaces: BTreeMap, } impl Snapshot { fn capture(ui: &UiState) -> Self { Self { - version: 1, + version: VERSION, workspace: ui.workspace.clone(), dock: ui.dock.clone(), - floating: ui.floating.clone(), focused: ui.focused, maximized: ui.maximized, saved_workspaces: ui.saved_workspaces.clone(), - saved_floating: ui.saved_floating.clone(), - panel_windows: ui.panel_windows.clone(), } } fn apply(self, ui: &mut UiState) { ui.workspace = self.workspace; ui.dock = self.dock; - ui.floating = self.floating; ui.focused = self.focused; ui.maximized = self.maximized; ui.saved_workspaces = self.saved_workspaces; - ui.saved_floating = self.saved_floating; - // A window is only kept for a panel that still floats, and only where a window can be. - let floating = |panel: PanelKind| ui.floating.iter().any(|group| group.panels.contains(&panel)); - ui.panel_windows = self - .panel_windows - .into_iter() - .filter(|window| floating(window.panel)) - .map(|window| PanelWindow { panel: window.panel, rect: PanelWindow::sanitized(window.rect) }) - .collect(); - // Reserve restored viewer slots without restoring any project-specific composition - // links. New Viewer allocates from this map, including after switching named layouts. - let mut panels = Vec::new(); - for root in std::iter::once(&ui.dock).chain(ui.saved_workspaces.values()) { - root.panels(&mut panels); - } - for groups in std::iter::once(&ui.floating).chain(ui.saved_floating.values()) { - for group in groups { - panels.extend(group.panels.iter().copied()); + // 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); } } - for panel in panels { - if let PanelKind::Viewer(id) = panel { - ui.viewers.entry(id).or_insert(None); + // 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()) { + for panel in crate::dock::referenced_panels(workspace) { + if let PanelKind::Viewer(id) = panel { + ui.viewers.entry(id).or_insert(None); + } } } } fn validate(&self) -> Result<(), String> { - if self.version != 1 { + if self.version != VERSION { return Err(format!("unsupported workspace version {}", self.version)); } let name_ok = |name: &str| !name.trim().is_empty() && name.len() <= 256; - if !name_ok(&self.workspace) - || self.saved_workspaces.len() > MAX_WORKSPACES - || self.saved_floating.len() > MAX_WORKSPACES - || self.saved_workspaces.keys().chain(self.saved_floating.keys()).any(|name| !name_ok(name)) - { + if !name_ok(&self.workspace) || self.saved_workspaces.len() > MAX_WORKSPACES || self.saved_workspaces.keys().any(|name| !name_ok(name)) { return Err("workspace names or count exceed supported limits".into()); } if !crate::dock::WORKSPACES.contains(&self.workspace.as_str()) && !self.saved_workspaces.contains_key(&self.workspace) { @@ -101,79 +80,16 @@ impl Snapshot { PanelKind::Viewer(id) => (1..=MAX_VIEWER_ID).contains(&id), _ => true, }; - if !panel_ok(self.focused) || self.maximized.is_some_and(|panel| !panel_ok(panel)) || self.panel_windows.iter().any(|w| !panel_ok(w.panel)) { + if !panel_ok(self.focused) || self.maximized.is_some_and(|panel| !panel_ok(panel)) { return Err("workspace viewer ID is outside the supported range 1–65535".into()); } - let mut nodes = 0usize; - for root in std::iter::once(&self.dock).chain(self.saved_workspaces.values()) { - let mut pending = vec![(root, 0usize)]; - while let Some((node, depth)) = pending.pop() { - nodes = nodes.saturating_add(1); - if depth > MAX_DEPTH || nodes > MAX_NODES { - return Err("workspace dock tree exceeds supported limits".into()); - } - match node { - DockNode::Split { size, a, b, .. } => { - let valid = match *size { - SplitSize::Ratio(v) => v.is_finite() && (0.0..=1.0).contains(&v), - SplitSize::FixedA(v) | SplitSize::FixedB(v) => v.is_finite() && (0.0..=MAX_COORD).contains(&v), - }; - if !valid { - return Err("invalid workspace split size".into()); - } - pending.push((a, depth.saturating_add(1))); - pending.push((b, depth.saturating_add(1))); - } - DockNode::Tabs { panels, active } => { - // Closing the last docked panel leaves an empty group with active=0. - if panels.len() > MAX_PANELS || *active >= panels.len().max(1) || panels.iter().any(|panel| !panel_ok(*panel)) { - return Err("invalid workspace tab group".into()); - } - } - DockNode::Stack { entries } => { - if entries.len() > MAX_PANELS - || entries.iter().any(|e| { - e.panels.is_empty() - || e.panels.len() > MAX_PANELS - || e.active >= e.panels.len() - || e.panels.iter().any(|p| !panel_ok(*p)) - || e.height.is_some_and(|v| !v.is_finite() || !(0.0..=MAX_COORD).contains(&v)) - }) - { - return Err("invalid workspace panel stack".into()); - } - } - } + for workspace in std::iter::once(&self.dock).chain(self.saved_workspaces.values()) { + // craft-ui checks the trees, selections, sizes, rects and limits. + workspace.validate().map_err(|error| error.to_string())?; + if crate::dock::referenced_panels(workspace).into_iter().any(|panel| !panel_ok(panel)) { + return Err("workspace viewer ID is outside the supported range 1–65535".into()); } } - if self.panel_windows.len() > MAX_PANELS || self.panel_windows.iter().any(|w| !w.rect.iter().all(|v| v.is_finite())) { - return Err("invalid workspace panel windows".into()); - } - for groups in std::iter::once(&self.floating).chain(self.saved_floating.values()) { - if groups.len() > MAX_PANELS { - return Err("too many floating workspace groups".into()); - } - for group in groups { - let [x, y, width, height] = group.rect; - if group.panels.is_empty() - || group.panels.len() > MAX_PANELS - || group.panels.iter().any(|panel| !panel_ok(*panel)) - || group.active >= group.panels.len() - || !group.rect.iter().all(|v| v.is_finite()) - || x.abs() > MAX_COORD - || y.abs() > MAX_COORD - || !(1.0..=MAX_COORD).contains(&width) - || !(1.0..=MAX_COORD).contains(&height) - { - return Err("invalid floating workspace group".into()); - } - } - } - crate::dock_shared::encode(&self.dock, &self.floating)?.validate().map_err(|error| error.to_string())?; - for (name, root) in &self.saved_workspaces { - let floating = self.saved_floating.get(name).map(Vec::as_slice).unwrap_or(&[]); - crate::dock_shared::encode(root, floating)?.validate().map_err(|error| error.to_string())?; - } Ok(()) } } @@ -182,24 +98,26 @@ pub(crate) struct WorkspaceStore { saved: Snapshot, last_attempt: f64, writable: bool, + /// The text of an earlier version's file that loaded: the first save copies it to + /// [`BACKUP`] and writes the file in the current format. + migrated_from: Option, pub(crate) error: Option, } 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())?; - // Only an explicitly legacy-shaped record can migrate. A versioned future - // snapshot must never deserialize as an empty defaulted legacy record. - let snapshot = if value.get("version").is_none() - && value.as_object().is_some_and(|fields| fields.contains_key("workspaces") || fields.contains_key("floating")) - { - let legacy: crate::SavedWorkspaces = serde_json::from_value(value).map_err(|e| e.to_string())?; - let mut snapshot = Snapshot::capture(ui); - snapshot.saved_workspaces = legacy.workspaces; - snapshot.saved_floating = legacy.floating; + let snapshot = if legacy::is_legacy(&value) { + let (snapshot, windows) = 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::(value).map_err(|e| e.to_string())? }; @@ -211,6 +129,7 @@ impl WorkspaceStore { let error = match loaded { Ok(Some(snapshot)) => { snapshot.apply(ui); + ui.native_outer = outer; None } Ok(None) => None, @@ -219,10 +138,11 @@ impl WorkspaceStore { if let Some(error) = &error { log::warn!("{error}"); ui.status = error.clone(); + original = None; } // An unreadable or newer file is never replaced by this session, even after a later // layout edit. Ordinary failed writes remain dirty and retryable. - Self { saved: Snapshot::capture(ui), last_attempt: f64::NEG_INFINITY, writable: error.is_none(), error } + Self { saved: Snapshot::capture(ui), last_attempt: f64::NEG_INFINITY, writable: error.is_none(), migrated_from: original, error } } pub(crate) fn due(&mut self, now: f64) -> bool { @@ -237,19 +157,18 @@ impl WorkspaceStore { if !self.writable { return false; } - self.saved.workspace != ui.workspace + self.migrated_from.is_some() + || self.saved.workspace != ui.workspace || self.saved.dock != ui.dock - || self.saved.floating != ui.floating || self.saved.focused != ui.focused || self.saved.maximized != ui.maximized || self.saved.saved_workspaces != ui.saved_workspaces - || self.saved.saved_floating != ui.saved_floating - || self.saved.panel_windows != ui.panel_windows } pub(crate) fn save(&mut self, config: Option<&dyn ConfigStore>, ui: &UiState) -> Result { let Some(config) = config else { return Ok(false) }; - if !self.has_changes(ui) { + // 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() { return Ok(false); } let snapshot = Snapshot::capture(ui); @@ -258,7 +177,11 @@ impl WorkspaceStore { if text.len() > MAX_BYTES { return Err("workspace file exceeds 1 MiB".into()); } + if let Some(original) = &self.migrated_from { + config.write(BACKUP, original).map_err(|e| format!("keep the earlier workspace file: {e}"))?; + } config.write(FILE, &text).map_err(|e| format!("save workspaces: {e}"))?; + self.migrated_from = None; self.saved = snapshot; self.error = None; Ok(true) @@ -281,26 +204,173 @@ impl WorkspaceStore { #[cfg(test)] mod tests { use super::*; + use crate::dock::{Floating, Layout, Node, StackEntry, WorkspaceExt as _}; + use craft_ui::docking::Action; + use craft_ui::layout::{SplitAxis, SplitSize}; use effectcraft_engine::config::MemoryConfig; + fn minimal() -> Workspace { + Workspace::new(crate::dock::workspace("Minimal")) + } + + fn tabs(panels: &[PanelKind]) -> Node { + Node::Tabs { panels: panels.to_vec(), active: 0 } + } + #[test] - fn corrupt_or_future_workspace_keeps_defaults_and_original_file() { + fn corrupt_future_or_unknown_workspace_keeps_defaults_and_original_file() { let valid = Snapshot::capture(&UiState::default()); - for text in ["{".into(), serde_json::to_string(&Snapshot { version: 2, ..valid }).unwrap(), " ".repeat(MAX_BYTES + 1)] { + // Damaged files of the earlier version: a panel in two places, a bad split, an unknown + // panel, a tree deeper than craft-ui allows, a missing field. + let earlier = |dock: &str| { + format!( + r#"{{"version":1,"workspace":"Default","dock":{dock},"floating":[],"focused":"Composition","maximized":null,"saved_workspaces":{{}},"saved_floating":{{}}}}"# + ) + }; + let mut deep = r#"{"Tabs":{"panels":["Composition"],"active":0}}"#.to_string(); + for _ in 0..=craft_ui::docking::MAX_DEPTH { + deep = format!(r#"{{"Split":{{"vertical":true,"size":{{"Ratio":0.5}},"a":{deep},"b":{{"Tabs":{{"panels":[],"active":0}}}}}}}}"#); + } + let twice = + r#"{"Split":{"vertical":true,"size":{"Ratio":0.5},"a":{"Tabs":{"panels":["Project"],"active":0}},"b":{"Tabs":{"panels":["Project"],"active":0}}}}"#; + let bad_split = r#"{"Split":{"vertical":true,"size":{"Ratio":7.0},"a":{"Tabs":{"panels":["Project"],"active":0}},"b":{"Tabs":{"panels":["Timeline"],"active":0}}}}"#; + for text in [ + "{".into(), + "{}".into(), + "[1, 2]".into(), + serde_json::to_string(&Snapshot { version: VERSION + 1, ..valid }).unwrap(), + " ".repeat(MAX_BYTES + 1), + earlier(twice), + earlier(bad_split), + earlier(r#"{"Tabs":{"panels":["NoSuchPanel"],"active":0}}"#), + earlier(&deep), + r#"{"version":1,"workspace":"Default"}"#.into(), + r#"{"workspaces":{"Mine":{"Tabs":{"panels":["Composition"],"active":3}}}}"#.into(), + ] { let config = MemoryConfig::default(); config.write(FILE, &text).unwrap(); let mut ui = UiState::default(); let mut store = WorkspaceStore::load(Some(&config), &mut ui); assert!(store.error.is_some()); assert_eq!(ui.workspace, "Default"); + assert_eq!(ui.dock, UiState::default().dock); ui.focused = PanelKind::Project; - ui.dock = crate::dock::workspace("Minimal"); + ui.dock = minimal(); assert!(!store.save(Some(&config), &ui).unwrap()); assert!(store.save_now(Some(&config), &ui).unwrap_err().contains("couldn't be loaded")); assert_eq!(config.read(FILE).as_deref(), Some(text.as_str())); + assert_eq!(config.read(BACKUP), None); } } + /// A file written by EffectCraft 0.10 (craft-libs 5c874d51): the Default workspace with + /// Preview floating, Render Queue floating in its own native window, Align closed, + /// Effects & Presets moved into the Project group and Audio split beside the Timeline, + /// saved as "My Layout"; then Layer closed. + const V1: &str = include_str!("../tests/fixtures/workspaces-v1.json"); + + #[test] + fn version_one_file_loads_with_every_panel_in_place() { + let config = MemoryConfig::default(); + config.write(FILE, V1).unwrap(); + let mut ui = UiState::default(); + let store = WorkspaceStore::load(Some(&config), &mut ui); + assert_eq!(store.error, None); + assert_eq!(ui.workspace, "My Layout"); + assert_eq!(ui.focused, PanelKind::Composition); + use PanelKind::*; + let root = crate::dock::hsplit( + SplitSize::FixedSecond(300.0), + crate::dock::vsplit( + SplitSize::Ratio(0.56), + crate::dock::hsplit(SplitSize::FixedFirst(300.0), crate::dock::tabs(&[Project, EffectControls, EffectsPresets], 2), tabs(&[Composition])), + crate::dock::hsplit(SplitSize::Ratio(0.5), tabs(&[Timeline]), tabs(&[Audio])), + ), + tabs(&[Properties]), + ); + assert_eq!(ui.dock.layout.root, Some(root)); + let floating: Vec<_> = ui.dock.layout.floating.iter().map(|w| (w.panels().copied().collect::>(), w.rect, w.native)).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]))), + ] + ); + // 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); + } + + #[test] + fn version_one_file_is_rewritten_once_in_the_current_format_and_kept_as_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); + // 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()); + assert_eq!(config.read(BACKUP).as_deref(), Some(V1)); + let text = config.read(FILE).unwrap(); + assert_eq!(serde_json::from_str::(&text).unwrap()["version"], VERSION); + assert!(!store.has_changes(&ui)); + let mut restored = UiState::default(); + let reloaded = WorkspaceStore::load(Some(&config), &mut restored); + assert_eq!(reloaded.error, None); + assert!(!reloaded.has_changes(&restored)); + assert_eq!(Snapshot::capture(&restored), migrated); + } + + #[test] + fn stacked_frames_with_tabs_and_an_empty_root_migrate() { + let text = r#"{"version":1,"workspace":"Mine","dock":{"Tabs":{"panels":[],"active":0}}, + "floating":[{"panels":["Project"],"active":0,"rect":[10.0,10.0,300.0,200.0]}], + "focused":"Project","maximized":null, + "saved_workspaces":{"Mine":{"Stack":{"entries":[{"panel":"Info","open":true},{"panels":["Audio","Preview"],"active":1,"open":true,"height":80.0}]}}, + "Column":{"Stack":{"entries":[{"panel":"Align","open":false},{"panel":"Preview","open":true,"height":46.0},{"panels":["Properties","Paint"],"active":1,"open":false,"height":300.0},{"panel":"Info","open":true}]}}}, + "saved_floating":{"Gone":[{"panels":["Align"],"active":0,"rect":[0.0,0.0,100.0,100.0]}]}}"#; + let config = MemoryConfig::default(); + config.write(FILE, text).unwrap(); + 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!(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)); + // 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.len(), 2, "floating groups of no named workspace are dropped"); + } + #[test] fn explicit_save_without_a_settings_folder_is_an_error() { let mut ui = UiState::default(); @@ -324,24 +394,25 @@ mod tests { #[test] fn invalid_tabs_split_and_deep_tree_are_rejected() { let mut snapshot = Snapshot::capture(&UiState::default()); - snapshot.dock = DockNode::Tabs { panels: vec![], active: usize::MAX }; + snapshot.dock = Workspace::new(Layout { root: Some(Node::Tabs { panels: vec![PanelKind::Project], active: usize::MAX }), floating: vec![] }); assert!(snapshot.validate().is_err()); - snapshot.dock = DockNode::Split { - vertical: false, - size: SplitSize::FixedA(f32::NAN), - a: Box::new(crate::dock::workspace("Minimal")), - b: Box::new(crate::dock::workspace("Minimal")), - }; + 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![], + }); assert!(snapshot.validate().is_err()); - snapshot.dock = crate::dock::workspace("Minimal"); - for _ in 0..=MAX_DEPTH { - snapshot.dock = DockNode::Split { - vertical: false, - size: SplitSize::Ratio(0.5), - a: Box::new(snapshot.dock), - b: Box::new(DockNode::Tabs { panels: vec![PanelKind::Project], active: 0 }), - }; + let mut root = tabs(&[PanelKind::Composition]); + for _ in 0..=craft_ui::docking::MAX_DEPTH { + root = split(SplitSize::Ratio(0.5), root, tabs(&[])); } + snapshot.dock = Workspace::new(Layout { root: Some(root), floating: 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])], + }); assert!(snapshot.validate().is_err()); } @@ -350,11 +421,10 @@ mod tests { let config = MemoryConfig::default(); let mut ui = UiState::default(); let mut store = WorkspaceStore::load(Some(&config), &mut ui); - let mut panels = Vec::new(); - ui.dock.panels(&mut panels); - for panel in panels { - ui.dock.close(panel); + for panel in ui.dock.panels() { + ui.dock.apply(Action::Close { panel }, crate::dock::permissions).unwrap(); } + 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); @@ -368,16 +438,17 @@ mod tests { let mut ui = UiState::default(); let mut store = WorkspaceStore::load(Some(&config), &mut ui); ui.workspace = "Floating".into(); - ui.dock.close(PanelKind::Preview); - ui.floating = vec![Floating { panels: vec![PanelKind::Preview], active: 0, rect: [50.0, 80.0, 200.0, 160.0] }]; + 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.saved_workspaces.insert(ui.workspace.clone(), ui.dock.clone()); - ui.saved_floating.insert(ui.workspace.clone(), ui.floating.clone()); ui.maximized = Some(PanelKind::Composition); ui.project_search = "do not persist".into(); assert!(store.save(Some(&config), &ui).unwrap()); let mut restored = UiState::default(); 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.project_search.is_empty()); } @@ -386,8 +457,9 @@ mod tests { let config = MemoryConfig::default(); let mut ui = UiState::default(); let mut store = WorkspaceStore::load(Some(&config), &mut ui); - ui.dock = DockNode::Tabs { panels: vec![PanelKind::Composition, PanelKind::Viewer(2)], active: 0 }; - ui.saved_workspaces.insert("Two views".into(), DockNode::Tabs { panels: vec![PanelKind::Composition, PanelKind::Viewer(5)], active: 0 }); + let two = |viewer| Workspace::new(Layout { root: Some(tabs(&[PanelKind::Composition, PanelKind::Viewer(viewer)])), floating: vec![] }); + ui.dock = two(2); + ui.saved_workspaces.insert("Two views".into(), two(5)); ui.viewers.insert(2, Some(42)); assert!(store.save(Some(&config), &ui).unwrap()); let mut app = crate::EffectcraftApp::new(effectcraft_engine::Session::default()); @@ -395,7 +467,7 @@ mod tests { assert_eq!(app.ui.viewers.get(&2), Some(&None)); assert_eq!(app.ui.viewers.get(&5), Some(&None)); assert_eq!(crate::panels::viewers::new_viewer(&mut app), 6); - assert!(app.ui.dock.contains(PanelKind::Viewer(2))); + assert!(app.ui.dock.is_docked(PanelKind::Viewer(2))); } #[test] @@ -404,23 +476,27 @@ mod tests { for location in 0..8 { let mut snapshot = Snapshot::capture(&UiState::default()); let panel = PanelKind::Viewer(id); - let dock = DockNode::Tabs { panels: vec![panel], active: 0 }; - let stack = DockNode::Stack { entries: vec![crate::dock::StackEntry::new(panel, true, None)] }; - let floating = vec![Floating { panels: vec![panel], active: 0, rect: [0.0, 0.0, 200.0, 100.0] }]; + 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(); match location { 0 => snapshot.focused = panel, 1 => snapshot.maximized = Some(panel), - 2 => snapshot.dock = dock, - 3 => snapshot.dock = stack, - 4 => snapshot.floating = floating, - 5 => { - snapshot.saved_workspaces.insert("Saved".into(), dock); - } + 2 => snapshot.dock = docked, + 3 => snapshot.dock = stacked, + 4 => snapshot.dock = floating, + 5 => snapshot.dock = hidden, 6 => { - snapshot.saved_workspaces.insert("Saved".into(), stack); + snapshot.saved_workspaces.insert("Saved".into(), stacked); } _ => { - snapshot.saved_floating.insert("Saved".into(), floating); + snapshot.saved_workspaces.insert("Saved".into(), floating); } } assert!(snapshot.validate().is_err(), "viewer {id} at location {location} must be rejected"); @@ -428,6 +504,21 @@ mod tests { } } + #[test] + fn hostile_native_window_places_are_made_safe_on_load() { + 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(); + 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]); + } + #[test] fn failed_write_keeps_previous_snapshot_and_retries() { struct Fails<'a>(&'a MemoryConfig); diff --git a/crates/ui-egui/src/workspace_state/legacy.rs b/crates/ui-egui/src/workspace_state/legacy.rs new file mode 100644 index 000000000..93d71fd75 --- /dev/null +++ b/crates/ui-egui/src/workspace_state/legacy.rs @@ -0,0 +1,245 @@ +//! Workspace files of earlier versions: EffectCraft's own dock tree (craft-libs 5c874d51 and +//! before), read into private copies of its types and turned into craft-ui workspaces. +//! +//! - Version 1 (`{version: 1, workspace, dock, floating, …, panel_windows}`) keeps the current +//! arrangement, the named workspaces, focus and the maximized panel. +//! - The unversioned record (`{workspaces, floating}`) holds only named workspaces; the +//! current arrangement stays the default. +//! - A column of stacked frames becomes tab groups split top to bottom. Each open frame is a +//! 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. +//! - 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 serde::Deserialize; + +use super::{Snapshot, VERSION}; +use crate::dock::{Layout, PanelKind, Workspace}; +use crate::state::UiState; + +#[derive(Deserialize)] +enum OldSplitSize { + Ratio(f32), + FixedA(f32), + FixedB(f32), +} + +/// A stacked frame; files from before stacked frames held tabs name one `panel`. +#[derive(Deserialize)] +struct OldStackEntry { + #[serde(default)] + panel: Option, + #[serde(default)] + panels: Vec, + #[serde(default)] + active: usize, + open: bool, + #[serde(default)] + height: Option, +} + +#[derive(Deserialize)] +enum OldNode { + Split { vertical: bool, size: OldSplitSize, a: Box, b: Box }, + Tabs { panels: Vec, active: usize }, + Stack { entries: Vec }, +} + +#[derive(Deserialize)] +struct OldFloating { + panels: Vec, + active: usize, + 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, + dock: OldNode, + floating: Vec, + focused: PanelKind, + maximized: Option, + saved_workspaces: BTreeMap, + saved_floating: BTreeMap>, + #[serde(default)] + panel_windows: Vec, +} + +#[derive(Deserialize)] +struct OldRecord { + #[serde(default)] + workspaces: BTreeMap, + #[serde(default)] + floating: BTreeMap>, +} + +/// Whether `value` is a file of an earlier version that [`migrate`] reads. +pub(super) fn is_legacy(value: &serde_json::Value) -> bool { + match value.get("version") { + Some(version) => version.as_u64() == Some(1), + None => value.as_object().is_some_and(|fields| fields.contains_key("workspaces") || fields.contains_key("floating")), + } +} + +/// 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 +/// leaves out (the current arrangement). The caller validates the result. +pub(super) fn migrate(value: serde_json::Value, ui: &UiState) -> Result<(Snapshot, Vec), 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())); + } + 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 { + version: VERSION, + workspace: old.workspace, + dock, + focused: old.focused, + maximized: old.maximized, + saved_workspaces: named(old.saved_workspaces, old.saved_floating)?, + }; + Ok((snapshot, outer)) +} + +/// Named workspaces with their floating groups; floating groups of no named workspace are +/// dropped, as the earlier version never showed them. +fn named(roots: BTreeMap, mut floating: BTreeMap>) -> Result, String> { + roots + .into_iter() + .map(|(name, root)| { + let groups = floating.remove(&name).unwrap_or_default(); + workspace(root, groups, &[]).map(|workspace| (name, workspace)) + }) + .collect() +} + +fn workspace(root: OldNode, floating: Vec, windows: &[OldPanelWindow]) -> Result { + // 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, + root => Some(node(root, 0)?), + }; + 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 + }) + .collect(); + Ok(Workspace::new(Layout { root, floating })) +} + +fn node(old: OldNode, depth: usize) -> Result, String> { + if depth > craft_ui::docking::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 { + 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))?), + }, + OldNode::Stack { entries } => column(entries)?, + }) +} + +/// The space between two frames of a column, in points ([`crate::theme::Tokens::gap`]). +const FRAME_GAP: f32 = 4.0; +/// The largest frame height a migrated column keeps, in points. +const MAX_FRAME: f32 = 10_000.0; + +/// A tab group of a column: its panels, shown tab, and body height when it has one. +struct Frame { + panels: Vec, + active: usize, + height: Option, +} + +/// A column of stacked frames as tab groups split top to bottom (see the module docs). +fn column(entries: Vec) -> Result, String> { + let mut frames: Vec = Vec::new(); + // Tabs of closed frames above the first open one. + let mut waiting: Vec = Vec::new(); + for entry in entries { + let mut panels = entry.panels; + if let Some(panel) = entry.panel + && !panels.contains(&panel) + { + panels.insert(0, panel); + } + if panels.is_empty() { + continue; + } + let active = entry.active.min(panels.len().saturating_sub(1)); + if entry.open { + let height = entry.height.filter(|h| h.is_finite() && *h > 0.0).map(|h| h.min(MAX_FRAME)); + frames.push(Frame { panels, active, height }); + } else if let Some(above) = frames.last_mut() { + above.panels.extend(panels); + } else { + waiting.extend(panels); + } + } + match frames.first_mut() { + Some(top) => top.panels.extend(waiting), + None if !waiting.is_empty() => frames.push(Frame { panels: waiting, active: 0, height: None }), + None => return Err("a stacked frame holds no panels".into()), + } + let frame_size = |frame: &Frame| frame.height.map(|h| h + crate::dock::TAB_STRIP); + let mut node: Option> = None; + // Below the frame being added: the frames' fixed sizes and gaps, or None when one shares. + let mut below_fixed = Some(0.0_f32); + let mut below_flexible = 0_usize; + 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 }; + node = Some(match node { + None => tabs, + Some(rest) => { + let size = match (own, below_fixed) { + (Some(own), _) => SplitSize::FixedFirst(own), + (None, Some(below)) => SplitSize::FixedSecond(below), + // 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) } + } + }); + below_fixed = match (own, below_fixed) { + (Some(own), Some(below)) => Some(below + gap + own), + _ => None, + }; + if own.is_none() { + below_flexible = below_flexible.saturating_add(1); + } + } + node.ok_or_else(|| "a stacked frame holds no panels".into()) +} diff --git a/crates/ui-egui/tests/fixtures/workspaces-v1.json b/crates/ui-egui/tests/fixtures/workspaces-v1.json new file mode 100644 index 000000000..164bf37f0 --- /dev/null +++ b/crates/ui-egui/tests/fixtures/workspaces-v1.json @@ -0,0 +1,234 @@ +{ + "version": 1, + "workspace": "My Layout", + "dock": { + "Split": { + "vertical": false, + "size": { + "FixedB": 300.0 + }, + "a": { + "Split": { + "vertical": true, + "size": { + "Ratio": 0.56 + }, + "a": { + "Split": { + "vertical": false, + "size": { + "FixedA": 300.0 + }, + "a": { + "Tabs": { + "panels": [ + "Project", + "EffectControls", + "EffectsPresets" + ], + "active": 2 + } + }, + "b": { + "Tabs": { + "panels": [ + "Composition" + ], + "active": 0 + } + } + } + }, + "b": { + "Split": { + "vertical": false, + "size": { + "Ratio": 0.5 + }, + "a": { + "Tabs": { + "panels": [ + "Timeline" + ], + "active": 0 + } + }, + "b": { + "Tabs": { + "panels": [ + "Audio" + ], + "active": 0 + } + } + } + } + } + }, + "b": { + "Stack": { + "entries": [ + { + "panels": [ + "Properties" + ], + "active": 0, + "open": true, + "height": null + } + ] + } + } + } + }, + "floating": [ + { + "panels": [ + "Preview" + ], + "active": 0, + "rect": [ + 900.0, + 120.0, + 300.0, + 260.0 + ] + }, + { + "panels": [ + "RenderQueue" + ], + "active": 0, + "rect": [ + 200.0, + 500.0, + 520.0, + 240.0 + ] + } + ], + "focused": "Composition", + "maximized": null, + "saved_workspaces": { + "My Layout": { + "Split": { + "vertical": false, + "size": { + "FixedB": 300.0 + }, + "a": { + "Split": { + "vertical": true, + "size": { + "Ratio": 0.56 + }, + "a": { + "Split": { + "vertical": false, + "size": { + "FixedA": 300.0 + }, + "a": { + "Tabs": { + "panels": [ + "Project", + "EffectControls", + "EffectsPresets" + ], + "active": 2 + } + }, + "b": { + "Tabs": { + "panels": [ + "Composition", + "Layer" + ], + "active": 0 + } + } + } + }, + "b": { + "Split": { + "vertical": false, + "size": { + "Ratio": 0.5 + }, + "a": { + "Tabs": { + "panels": [ + "Timeline" + ], + "active": 0 + } + }, + "b": { + "Tabs": { + "panels": [ + "Audio" + ], + "active": 0 + } + } + } + } + } + }, + "b": { + "Stack": { + "entries": [ + { + "panels": [ + "Properties" + ], + "active": 0, + "open": true, + "height": null + } + ] + } + } + } + } + }, + "saved_floating": { + "My Layout": [ + { + "panels": [ + "Preview" + ], + "active": 0, + "rect": [ + 900.0, + 120.0, + 300.0, + 260.0 + ] + }, + { + "panels": [ + "RenderQueue" + ], + "active": 0, + "rect": [ + 200.0, + 500.0, + 520.0, + 240.0 + ] + } + ] + }, + "panel_windows": [ + { + "panel": "RenderQueue", + "rect": [ + 200.0, + 500.0, + 520.0, + 240.0 + ] + } + ] +} \ No newline at end of file diff --git a/crates/ui-egui/tests/it/main.rs b/crates/ui-egui/tests/it/main.rs index b5492c1b5..6b4c08912 100644 --- a/crates/ui-egui/tests/it/main.rs +++ b/crates/ui-egui/tests/it/main.rs @@ -1,5 +1,6 @@ //! The crate's integration tests, one binary (each module is a former `tests/.rs`). +mod native_menu_text_keys; mod render_queue_snapshot; mod shared_docking_ui; mod ui_3d; diff --git a/crates/ui-egui/tests/it/native_menu_text_keys.rs b/crates/ui-egui/tests/it/native_menu_text_keys.rs new file mode 100644 index 000000000..d740c6b46 --- /dev/null +++ b/crates/ui-egui/tests/it/native_menu_text_keys.rs @@ -0,0 +1,191 @@ +//! 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. + +use effectcraft_engine::Session; +use effectcraft_ui_egui::EffectcraftApp; +use effectcraft_ui_egui::{menus, native_menu}; +use egui::{Event, Modifiers, PointerButton, Pos2, ViewportCommand, ViewportId, ViewportInfo, pos2, vec2}; +use egui_kittest::Harness; +use serde_json::json; +use std::cell::RefCell; +use std::collections::HashMap; +use std::rc::Rc; + +fn app() -> EffectcraftApp { + let mut s = Session::default(); + s.execute("comp.new", json!({"name": "Main", "width": 320, "height": 180, "duration": 4})).unwrap(); + s.execute("layer.newSolid", json!({"name": "Solid", "color": "#406080"})).unwrap(); + let mut app = EffectcraftApp::new(s); + app.ui.start_screen = false; + app.hooks.clipboard_text = Some(Box::new(|| Some("pasted".into()))); + app +} + +/// What the Edit commands would change in the project. +fn project(app: &EffectcraftApp) -> (u64, usize, usize, usize) { + let s = &app.session; + (s.revision, s.state.clipboard.len(), s.history.undo.len(), s.history.redo.len()) +} + +/// Choose the native menu item that runs `command`, then deliver what it queued for the main +/// window (kittest does not call `raw_input_hook`). +fn menu(h: &mut Harness<'_, EffectcraftApp>, command: &str) { + let spec = native_menu::build(h.state()); + let id = spec.items().into_iter().find(|i| i.command == command).unwrap().id.clone(); + let ctx = h.ctx.clone(); + native_menu::activate(h.state_mut(), &ctx, &spec, &id).unwrap(); + for _ in 0..3 { + let mut raw = egui::RawInput::default(); + eframe::App::raw_input_hook(h.state_mut(), &ctx, &mut raw); + h.input_mut().events.extend(raw.events); + h.step(); + h.state_mut().mark_synthetic_applied(); + } + h.run_steps(2); +} + +/// Whether the menu bar shows `command`'s item enabled now, and whether the project alone would. +fn enabled(h: &Harness<'_, EffectcraftApp>, command: &str) -> (bool, bool) { + let find = |menu: native_menu::NativeMenu| menu.items().into_iter().find(|i| i.command == command).unwrap().enabled; + (find(native_menu::build_now(h.state(), &h.ctx)), find(native_menu::build(h.state()))) +} + +fn center(h: &Harness<'_, EffectcraftApp>, id: &str) -> Pos2 { + let e = h.state().auto.find(id).unwrap_or_else(|| panic!("no {id}")).clone(); + pos2(e.rect[0] + e.rect[2] / 2.0, e.rect[1] + e.rect[3] / 2.0) +} + +fn click(h: &mut Harness<'_, EffectcraftApp>, at: Pos2, window: Option<&Host>) { + let send = |h: &mut Harness<'_, EffectcraftApp>, event: Event| match window { + Some(host) => to_window(host, event), + None => h.input_mut().events.push(event), + }; + send(h, Event::PointerMoved(at)); + h.step(); + for pressed in [true, false] { + send(h, Event::PointerButton { pos: at, button: PointerButton::Primary, pressed, modifiers: Modifiers::NONE }); + h.step(); + } +} + +/// Stand-in OS windows for floating panels: each runs its own pass with its own input, and +/// asking one for the clipboard text gives it "pasted". +#[derive(Default)] +struct Windows { + window: Option, + events: HashMap>, +} + +type Host = Rc>; + +fn to_window(host: &Host, event: Event) { + let mut host = host.borrow_mut(); + let Some(window) = host.window else { panic!("no floating panel window") }; + host.events.entry(window).or_default().push(event); +} + +fn native_windows(h: &mut Harness<'_, EffectcraftApp>) -> Host { + let host = Host::default(); + let shared = host.clone(); + egui::Context::set_immediate_viewport_renderer(move |ctx, mut viewport| { + let id = viewport.ids.this; + let size = viewport.builder.inner_size.unwrap_or(vec2(400.0, 300.0)); + let time = ctx.input(|i| i.time); + let events = { + let mut host = shared.borrow_mut(); + host.window = Some(id); + host.events.remove(&id).unwrap_or_default() + }; + let viewports = [(ViewportId::ROOT, false), (id, true)] + .into_iter() + .map(|(id, focused)| (id, ViewportInfo { focused: Some(focused), native_pixels_per_point: Some(1.0), ..Default::default() })) + .collect(); + let input = egui::RawInput { + viewport_id: id, + viewports, + screen_rect: Some(egui::Rect::from_min_size(Pos2::ZERO, size)), + events, + focused: true, + time: Some(time), + ..Default::default() + }; + let mut full = ctx.run_ui(input, |ui| (viewport.viewport_ui_cb)(ui)); + full.textures_delta.clear(); + if full.viewport_output.get(&id).is_some_and(|out| out.commands.contains(&ViewportCommand::RequestPaste)) { + shared.borrow_mut().events.entry(id).or_default().push(Event::Paste("pasted".into())); + } + }); + h.ctx.set_embed_viewports(false); + // A main window that reports its place: not Wayland, where floating panels stay in it. + let screen = h.ctx.content_rect(); + h.input_mut().viewports.entry(ViewportId::ROOT).or_default().outer_rect = Some(screen); + h.run_steps(3); + let window = host.borrow().window.expect("the floating panel opens in an OS window of its own"); + // That window has the keyboard. + let input = h.input_mut(); + input.focused = false; + for (id, focused) in [(ViewportId::ROOT, false), (window, true)] { + input.viewports.entry(id).or_default().focused = Some(focused); + } + h.run_steps(2); + host +} + +#[test] +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); + h.ctx.set_os(egui::os::OperatingSystem::Mac); + let host = native_windows(&mut h); + let at = center(&h, "project.search"); + click(&mut h, at, Some(&host)); + to_window(&host, Event::Text("abc".into())); + h.run_steps(3); + let window = host.borrow().window.unwrap(); + assert_eq!(h.state().ui.project_search, "abc"); + assert!(!h.ctx.egui_wants_keyboard_input(), "the main window has no focused widget"); + assert_eq!(native_menu::text_field_window(&h.ctx), Some(window)); + assert_eq!(enabled(&h, "edit.paste"), (true, false), "Paste stays enabled with nothing copied in the project"); + let before = project(h.state()); + menu(&mut h, "edit.selectAll"); + menu(&mut h, "edit.cut"); + assert_eq!(h.state().ui.project_search, "", "Select All and Cut act on the field"); + menu(&mut h, "edit.paste"); + assert_eq!(h.state().ui.project_search, "pasted"); + menu(&mut h, "edit.undo"); + assert_eq!(h.state().ui.project_search, "", "Undo undoes the paste"); + menu(&mut h, "edit.copy"); + assert_eq!(project(h.state()), before, "the project is untouched"); + assert_eq!(h.state().ui.project_search, ""); +} + +#[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()); + h.ctx.set_os(egui::os::OperatingSystem::Mac); + h.run_steps(3); + let at = center(&h, "project.search"); + h.input_mut().events.push(Event::PointerMoved(at)); + h.step(); + for pressed in [true, false] { + h.input_mut().events.push(Event::PointerButton { pos: at, button: PointerButton::Primary, pressed, modifiers: Modifiers::NONE }); + h.step(); + } + h.input_mut().events.push(Event::Text("abc".into())); + h.run_steps(3); + assert_eq!(h.state().ui.project_search, "abc"); + assert_eq!(native_menu::text_field_window(&h.ctx), Some(ViewportId::ROOT)); + assert_eq!(enabled(&h, "edit.paste"), (true, false), "Paste stays enabled with nothing copied in the project"); + let before = project(h.state()); + menu(&mut h, "edit.selectAll"); + menu(&mut h, "edit.cut"); + assert_eq!(h.state().ui.project_search, "", "Select All and Cut act on the field"); + menu(&mut h, "edit.paste"); + assert_eq!(h.state().ui.project_search, "pasted"); + menu(&mut h, "edit.undo"); + assert_eq!(h.state().ui.project_search, "", "Undo undoes the paste"); + menu(&mut h, "edit.copy"); + assert_eq!(project(h.state()), before, "the project is untouched"); +} diff --git a/crates/ui-egui/tests/it/shared_docking_ui.rs b/crates/ui-egui/tests/it/shared_docking_ui.rs index 29d591a1d..c71fadf3c 100644 --- a/crates/ui-egui/tests/it/shared_docking_ui.rs +++ b/crates/ui-egui/tests/it/shared_docking_ui.rs @@ -1,92 +1,86 @@ -//! Existing EffectCraft workspaces use shared transactions without changing their saved schema. -use craft_ui::docking::{Action, Placement, Zone}; +//! 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 effectcraft_engine::Session; use effectcraft_ui_egui::{ EffectcraftApp, - dock::{self, DockNode, Layout, PanelKind, SplitSize, StackEntry}, + dock::{self, Layout, PanelKind, SplitSize, Workspace, WorkspaceExt as _}, }; use egui::{Event, Modifiers, PointerButton, Rect, pos2, vec2}; use egui_kittest::Harness; use egui_kittest::kittest::{NodeT, Queryable}; use serde_json::json; -#[test] -fn shared_move_preserves_accordion_metadata_and_unrelated_active_tabs() { - let mut layout = Layout { - root: DockNode::Split { - vertical: false, - size: SplitSize::FixedB(300.0), - a: Box::new(DockNode::Tabs { panels: vec![PanelKind::Project, PanelKind::Composition, PanelKind::Layer], active: 1 }), - b: Box::new(DockNode::Stack { - entries: vec![ - StackEntry::new(PanelKind::Preview, false, Some(73.0)), - StackEntry::new(PanelKind::Properties, true, Some(211.0)), - StackEntry::new(PanelKind::Align, false, None), - ], - }), - }, - floating: vec![], - }; - layout.apply(Action::Close { panel: PanelKind::Project }).unwrap(); - assert!(layout.root.is_visible(PanelKind::Composition)); - layout.apply(Action::Move { panel: PanelKind::Preview, anchor: PanelKind::Align, placement: Placement::Tab { before: None } }).unwrap(); - let DockNode::Split { b, size, .. } = &layout.root else { panic!("split was lost") }; - assert_eq!(*size, SplitSize::FixedB(300.0)); - let DockNode::Stack { entries } = b.as_ref() else { panic!("stack was lost") }; - // Upstream now makes a tab drop join the anchor's accordion frame. Its height belongs - // to the destination frame; the unrelated Properties frame keeps its exact metadata. - let joined = entries.iter().find(|entry| entry.contains(PanelKind::Preview)).unwrap(); - assert_eq!(joined.panels, vec![PanelKind::Align, PanelKind::Preview]); - assert_eq!(joined.shown(), Some(PanelKind::Preview)); - assert!(joined.open); - assert_eq!(joined.height, None); - assert_eq!(entries.iter().find(|entry| entry.contains(PanelKind::Properties)).unwrap(), &StackEntry::new(PanelKind::Properties, true, Some(211.0))); - let before = layout.clone(); - assert!(layout.apply(Action::Move { panel: PanelKind::Preview, anchor: PanelKind::Audio, placement: Placement::Split(Zone::Left) }).is_err()); - assert_eq!(layout, before); - assert!(layout.apply(Action::Float { panel: PanelKind::Preview, rect: [0.0, 0.0, f32::INFINITY, 200.0] }).is_err()); - assert_eq!(layout, before); +fn invoke(app: &mut EffectcraftApp, id: &str, params: serde_json::Value) -> Result { + effectcraft_ui_egui::menus::invoke(app, &egui::Context::default(), id, params) +} + +fn floating(app: &EffectcraftApp) -> &[dock::Floating] { + &app.ui.dock.layout.floating } #[test] -fn every_builtin_workspace_and_dynamic_identity_roundtrips() { +fn shared_move_preserves_accordion_metadata_and_unrelated_active_tabs() { + let mut workspace = dock::docked(dock::hsplit( + SplitSize::FixedSecond(300.0), + 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(); + 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") }; + assert_eq!(*size, SplitSize::FixedSecond(300.0)); + 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 }] + ); + 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) + .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); +} + +#[test] +fn every_builtin_workspace_validates_and_roundtrips_with_dynamic_identities() { for name in dock::WORKSPACES { - let mut layout = Layout { root: dock::workspace(name), floating: dock::workspace_floating(name) }; - let before = serde_json::to_value(&layout).unwrap(); - // A structural no-op still crosses both adapters and shared validation. The complete - // persisted shape must remain byte-equivalent, including accordion state and heights. - let action = match &layout.root { - DockNode::Split { size, .. } => Action::ResizeSplit { - path: vec![], - size: match *size { - SplitSize::Ratio(v) => craft_ui::layout::SplitSize::Ratio(v), - SplitSize::FixedA(v) => craft_ui::layout::SplitSize::FixedFirst(v), - SplitSize::FixedB(v) => craft_ui::layout::SplitSize::FixedSecond(v), - }, - }, - DockNode::Tabs { panels, .. } => Action::Move { panel: panels[0], anchor: panels[1], placement: Placement::Tab { before: Some(panels[0]) } }, - DockNode::Stack { entries } => Action::SetStackOpen { panel: entries[0].shown().unwrap(), open: entries[0].open }, - }; - layout.apply(action).unwrap(); - assert_eq!(before, serde_json::to_value(&layout).unwrap()); - let back: Layout = serde_json::from_value(before).unwrap(); - assert_eq!(layout, back); + let workspace = Workspace::new(dock::workspace(name)); + workspace.validate().unwrap_or_else(|e| panic!("{name}: {e}")); + assert!(workspace.is_open(PanelKind::Composition), "{name} lacks the Composition panel"); + let text = serde_json::to_string(&workspace).unwrap(); + assert_eq!(serde_json::from_str::(&text).unwrap(), workspace, "{name}"); } - let mut layout = Layout { - root: DockNode::Tabs { panels: vec![PanelKind::Composition, PanelKind::Viewer(42), PanelKind::ScriptPanel(77)], active: 1 }, - floating: vec![], - }; - layout.apply(Action::Float { panel: PanelKind::ScriptPanel(77), rect: [20.0, 30.0, 400.0, 300.0] }).unwrap(); - layout.apply(Action::Move { panel: PanelKind::ScriptPanel(77), anchor: PanelKind::Viewer(42), placement: Placement::Tab { before: None } }).unwrap(); - assert!(layout.floating.is_empty()); - assert!(layout.contains(PanelKind::Viewer(42))); - assert!(layout.root.is_visible(PanelKind::ScriptPanel(77))); + assert_eq!(dock::workspace("Undocked Panels").floating.len(), 4); + // Built again, a built-in layout has the same windows (ids included). + let ids = |layout: &Layout| layout.floating.iter().map(|w| w.id).collect::>(); + 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(); + let text = serde_json::to_string(&workspace).unwrap(); + assert!(text.contains("\"ScriptPanel\":77") && text.contains("\"Viewer\":42"), "{text}"); + assert_eq!(serde_json::from_str::(&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()); + assert!(workspace.is_visible(PanelKind::ScriptPanel(77))); } fn rect(h: &Harness<'_, EffectcraftApp>, id: &str) -> Rect { let element = h.state().auto.find(id).unwrap_or_else(|| panic!("missing {id}")); Rect::from_min_size(pos2(element.rect[0], element.rect[1]), vec2(element.rect[2], element.rect[3])) } + fn drag(h: &mut Harness<'_, EffectcraftApp>, from: egui::Pos2, to: egui::Pos2, modifiers: Modifiers) { h.event(Event::ModifiersChanged(modifiers)); h.event(Event::PointerMoved(from)); @@ -108,126 +102,52 @@ fn pointer_drop_merges_floats_and_redocks_without_project_changes() { let mut session = Session::default(); session.execute("comp.new", json!({"name": "Docking composition", "width": 320, "height": 180, "duration": 4})).unwrap(); session.execute("layer.newSolid", json!({"name": "Teal plate", "width": 320, "height": 180, "color": "#245b68"})).unwrap(); - session.execute("layer.newSolid", json!({"name": "Coral tile", "width": 110, "height": 70, "color": "#ee7859"})).unwrap(); let mut app = EffectcraftApp::new(session); app.ui.start_screen = false; - app.ui.dock = DockNode::Split { - vertical: false, - size: SplitSize::FixedA(400.0), - a: Box::new(DockNode::Tabs { panels: vec![PanelKind::Project, PanelKind::Info, PanelKind::Audio], active: 1 }), - b: Box::new(DockNode::Tabs { panels: vec![PanelKind::Composition, PanelKind::Layer], active: 0 }), - }; - app.ui.dock = DockNode::Split { - vertical: true, - size: SplitSize::Ratio(0.62), - a: Box::new(app.ui.dock), - b: Box::new(DockNode::Tabs { panels: vec![PanelKind::Timeline], active: 0 }), - }; - let snapshots = std::env::var_os("CRAFT_UI_DOCKING_SNAPSHOT_DIR").map(std::path::PathBuf::from); - let mut builder = Harness::builder().with_size(vec2(1200.0, 760.0)); - if snapshots.is_some() { - builder = builder.wgpu(); - } - let mut h = builder.build_eframe(move |_| app); + app.ui.dock = dock::docked(dock::vsplit( + SplitSize::Ratio(0.62), + dock::hsplit( + SplitSize::FixedFirst(400.0), + dock::tabs(&[PanelKind::Project, PanelKind::Info, PanelKind::Audio], 1), + dock::tabs(&[PanelKind::Composition, PanelKind::Layer], 0), + ), + dock::tabs(&[PanelKind::Timeline], 0), + )); + let mut h = Harness::builder().with_size(vec2(1200.0, 760.0)).build_eframe(move |_| app); h.run_steps(4); - let deadline = std::time::Instant::now() + std::time::Duration::from_secs(2); - while h.state().frames.urgent_pending() && std::time::Instant::now() < deadline { - std::thread::sleep(std::time::Duration::from_millis(1)); - } - assert!(!h.state().frames.urgent_pending()); - h.run_steps(3); let project = h.state().session.project.clone(); let times = h.state().session.state.times.clone(); - let mut action_log = vec![action_state(&h, "start")]; + // A tab dropped on another group's tab strip joins it. let from = rect(&h, "panel.tab.Info").center(); - let to = rect(&h, "panel.Composition").center(); + let to = rect(&h, "panel.tab.Layer").center() + vec2(20.0, 0.0); drag(&mut h, from, to, Modifiers::NONE); assert!(h.state().ui.dock.is_visible(PanelKind::Info)); - assert!(same_group(&h.state().ui.dock, PanelKind::Info, PanelKind::Composition)); - action_log.push(action_state(&h, "merged")); - let from = rect(&h, "panel.tab.Info").center(); - let before = rect(&h, "panel.tab.Composition"); - drag(&mut h, from, pos2(before.left() + 2.0, before.center().y), Modifiers::NONE); - assert_eq!(tabs_containing(&h.state().ui.dock, PanelKind::Info).first(), Some(&PanelKind::Info)); - action_log.push(action_state(&h, "reordered")); - + assert!(h.state().ui.dock.group_of(PanelKind::Info).contains(&PanelKind::Composition)); + // Cmd/Ctrl at the release floats it. let from = rect(&h, "panel.tab.Info").center(); drag(&mut h, from, pos2(700.0, 400.0), Modifiers::COMMAND); - assert_eq!(h.state().ui.floating.len(), 1); - // The grip is a resize handle: the migration's role mapping (`ResizeHandle → Splitter`) applies - // to floating panels too, and the widget reports it (`dock_ui.rs`). - assert_eq!(h.get_by_label("Resize floating panel").accesskit_node().role(), egui::accesskit::Role::Splitter); - action_log.push(action_state(&h, "floated")); - let original = h.state().ui.floating[0].rect; + 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 grip = rect(&h, "panel.float.0.resize").center(); - drag(&mut h, grip, grip + vec2(36.0, 24.0), Modifiers::NONE); - assert!(h.state().ui.floating[0].rect[2] > original[2] + 25.0); - assert!(h.state().ui.floating[0].rect[3] > original[3] + 15.0); - action_log.push(action_state(&h, "resized")); - let grip_id = egui::Id::unique(("floating-panel", PanelKind::Info.id())).with("resize"); - assert_eq!(h.ctx.memory(|memory| memory.focused()), Some(grip_id)); - let before_keys = h.state().ui.floating[0].rect; - for key in [egui::Key::ArrowRight, egui::Key::ArrowDown] { - for pressed in [true, false] { - h.event(Event::Key { key, physical_key: None, pressed, repeat: false, modifiers: Modifiers::NONE }); - h.step(); - } - } - assert_eq!(h.state().ui.floating[0].rect[2], before_keys[2] + 8.0); - assert_eq!(h.state().ui.floating[0].rect[3], before_keys[3] + 8.0); - h.event(Event::Key { key: egui::Key::Tab, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::NONE }); - h.step(); - h.event(Event::Key { key: egui::Key::Tab, physical_key: None, pressed: false, repeat: false, modifiers: Modifiers::NONE }); - h.run_steps(3); - assert_ne!(h.ctx.memory(|memory| memory.focused()), Some(grip_id)); - action_log.push(action_state(&h, "keyboard-resized")); - let resized = h.state().ui.floating[0].rect; - let header = rect(&h, "panel.float.0.move"); - let from = pos2(header.right() - 24.0, header.center().y); - drag(&mut h, from, from - vec2(24.0, 18.0), Modifiers::NONE); - assert!(h.state().ui.floating[0].rect[0] < resized[0] - 15.0); - assert!(h.state().ui.floating[0].rect[1] < resized[1] - 10.0); - action_log.push(action_state(&h, "moved")); - - if let Some(directory) = &snapshots { - std::fs::create_dir_all(directory).unwrap(); - h.render().unwrap().save(directory.join("effectcraft-floating.png")).unwrap(); - } + drag(&mut h, grip, grip - vec2(36.0, 24.0), Modifiers::NONE); + let resized = 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; + 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(); - let to = rect(&h, "panel.Audio").center(); + let to = rect(&h, "panel.tab.Project").center() + vec2(20.0, 0.0); drag(&mut h, from, to, Modifiers::NONE); - assert!(h.state().ui.floating.is_empty()); - action_log.push(action_state(&h, "redocked")); + assert!(floating(h.state()).is_empty()); + assert!(h.state().ui.dock.group_of(PanelKind::Info).contains(&PanelKind::Project)); assert!(std::sync::Arc::ptr_eq(&project, &h.state().session.project)); assert_eq!(times, h.state().session.state.times); - assert!(h.state().auto.elements.iter().any(|element| element.id.starts_with("timeline.layer."))); - h.state_mut().session.execute("view.exposure", json!({"stops": 2.0})).unwrap(); - h.run_steps(3); - let pos = rect(&h, "viewer.resetExposure").center(); - h.event(Event::PointerMoved(pos)); - h.step(); - for pressed in [true, false] { - h.event(Event::PointerButton { pos, button: PointerButton::Primary, pressed, modifiers: Modifiers::NONE }); - h.step(); - } - h.run_steps(3); - assert_eq!(h.state().session.state.viewer.exposure, 0.0); - action_log.push(action_state(&h, "viewer-reset-exposure")); - if let Some(directory) = &snapshots { - std::fs::write(directory.join("effectcraft-actions.json"), serde_json::to_vec_pretty(&action_log).unwrap()).unwrap(); - } - if let Some(directory) = &snapshots { - h.render().unwrap().save(directory.join("effectcraft-redocked.png")).unwrap(); - } - assert!(std::sync::Arc::ptr_eq(&project, &h.state().session.project)); -} - -fn same_group(root: &DockNode, first: PanelKind, second: PanelKind) -> bool { - match root { - DockNode::Tabs { panels, .. } => panels.contains(&first) && panels.contains(&second), - DockNode::Split { a, b, .. } => same_group(a, first, second) || same_group(b, first, second), - DockNode::Stack { .. } => false, - } } #[test] @@ -236,186 +156,175 @@ 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() }); - assert!(app.edit_layout(|layout| layout.apply(Action::Float { panel: PanelKind::Project, rect: [45.0, 65.0, 430.0, 310.0] }).is_ok())); - let ctx = egui::Context::default(); - effectcraft_ui_egui::menus::invoke(&mut app, &ctx, "window.saveWorkspaceAs", json!({"name": "Shared float"})).unwrap(); - let saved = app.ui.floating.clone(); - assert!(app.edit_layout(|layout| layout.apply(Action::MoveFloating { panel: PanelKind::Project, rect: [75.0, 95.0, 480.0, 360.0] }).is_ok())); - let current = app.ui.floating.clone(); + app.apply_dock(Action::Float { panel: PanelKind::Project, rect: [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(); + let current = app.ui.dock.clone(); eframe::App::on_exit(&mut app); let mut restarted = EffectcraftApp::new(Session { config: Some(store), ..Default::default() }); - assert_eq!(restarted.ui.floating, current); + assert_eq!(restarted.ui.dock, current); restarted.set_workspace("Default"); restarted.set_workspace("Shared float"); - assert_eq!(restarted.ui.floating, saved); -} - -fn tabs_containing(root: &DockNode, panel: PanelKind) -> Vec { - match root { - DockNode::Tabs { panels, .. } if panels.contains(&panel) => panels.clone(), - DockNode::Split { a, b, .. } => { - let first = tabs_containing(a, panel); - if first.is_empty() { tabs_containing(b, panel) } else { first } - } - _ => vec![], - } + assert_eq!(restarted.ui.dock, saved); } #[test] -fn float_command_rejects_malformed_rectangles_atomically() { +fn float_command_rejects_malformed_rectangles_and_keeps_one_docked_panel() { let mut app = EffectcraftApp::new(Session::default()); let before = app.ui.dock.clone(); - let ctx = egui::Context::default(); for rect in [json!([1, 2, 300]), json!([1, 2, 300, 200, 7]), json!([1, 2, 1e100, 200]), json!("rectangle")] { - assert!(effectcraft_ui_egui::menus::invoke(&mut app, &ctx, "window.floatPanel", json!({"panel": "Project", "rect": rect})).is_err()); + assert!(invoke(&mut app, "window.floatPanel", json!({"panel": "Project", "rect": rect})).is_err()); assert_eq!(app.ui.dock, before); - assert!(app.ui.floating.is_empty()); } - app.ui.dock = DockNode::Tabs { panels: vec![PanelKind::Project], active: 0 }; - assert!(!app.edit_layout(|layout| layout.apply(Action::Float { panel: PanelKind::Project, rect: [1.0, 2.0, 300.0, 200.0] }).is_ok())); + // 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!(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()); } -/// A floating panel dragged past the window's bottom edge is drawn where its rect says: it was -/// shifted back into the window while its rect kept moving, and its strip then clashed with the -/// floating area's own widget ("Double use of widget ID"). +/// 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_past_the_window_edge_is_drawn_at_its_rect() { - let mut h = Harness::builder().with_size(vec2(1600.0, 1000.0)).build_eframe(|_| EffectcraftApp::new(Session::default())); +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 app = EffectcraftApp::new(Session::default()); + app.ui.start_screen = false; + app + }); h.run_steps(3); let ctx = h.ctx.clone(); effectcraft_ui_egui::menus::invoke(h.state_mut(), &ctx, "window.floatPanel", json!({"panel": "Preview", "rect": [600.0, 400.0, 360.0, 300.0]})).unwrap(); h.run_steps(3); - let strip = rect(&h, "panel.float.0.move"); - let from = pos2(strip.right() - 24.0, strip.center().y); - drag(&mut h, from, from + vec2(40.0, 420.0), Modifiers::NONE); - let moved = h.state().ui.floating[0].rect; - assert!(moved[1] + moved[3] > 1000.0, "the panel hangs past the bottom edge: {moved:?}"); - let strip = rect(&h, "panel.float.0.move"); - assert_eq!([strip.min.x, strip.min.y], [moved[0], moved[1]]); - // The strip still moves it from there. - let from = pos2(strip.right() - 24.0, strip.center().y); - drag(&mut h, from, from - vec2(30.0, 200.0), Modifiers::NONE); - assert_eq!(h.state().ui.floating[0].rect[1], moved[1] - 200.0); -} - -fn action_state(h: &Harness<'_, EffectcraftApp>, action: &str) -> serde_json::Value { - json!({"action": action, "dock": h.state().ui.dock, "floating": h.state().ui.floating, "focused": h.state().ui.focused}) + 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; + 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; + assert!(back[1] < moved[1] - 150.0, "{moved:?} -> {back:?}"); } #[test] fn catalog_docking_action_supports_resize_reorder_and_floating_geometry() { let mut app = EffectcraftApp::new(Session::default()); - app.ui.dock = DockNode::Split { - vertical: false, - size: SplitSize::FixedA(300.0), - a: Box::new(DockNode::Tabs { panels: vec![PanelKind::Project, PanelKind::Info], active: 1 }), - b: Box::new(DockNode::Tabs { panels: vec![PanelKind::Composition], active: 0 }), - }; - let ctx = egui::Context::default(); + app.ui.dock = dock::docked(dock::hsplit( + SplitSize::FixedFirst(300.0), + dock::tabs(&[PanelKind::Project, PanelKind::Info], 1), + dock::tabs(&[PanelKind::Composition], 0), + )); for action in [ - Action::ResizeSplit { path: vec![], size: craft_ui::layout::SplitSize::FixedFirst(360.0) }, + 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] }, ] { - effectcraft_ui_egui::menus::invoke(&mut app, &ctx, "window.dockAction", json!({"action": action})).unwrap(); + invoke(&mut app, "window.dockAction", json!({"action": action})).unwrap(); } - assert_eq!(app.ui.floating[0].rect, [45.0, 65.0, 330.0, 240.0]); - let DockNode::Split { size, .. } = &app.ui.dock else { panic!("split lost") }; - assert_eq!(*size, SplitSize::FixedA(360.0)); - let before = json!({"dock": app.ui.dock, "floating": app.ui.floating}); - assert!( - effectcraft_ui_egui::menus::invoke( - &mut app, - &ctx, - "window.dockAction", - json!({"action": { - "ResizeSplit": {"path": [true, true], "size": {"Ratio": 0.5}} - }}) - ) - .is_err() - ); - assert_eq!(json!({"dock": app.ui.dock, "floating": app.ui.floating}), before); + 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!(*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()); + assert!(invoke(&mut app, "window.dockAction", json!({"action": {"Open": {"panel": "Align", "anchor": null}}})).is_err()); + assert_eq!(app.ui.dock, before); } #[test] -fn catalog_close_keeps_dynamic_panel_identity() { +fn ui_dock_and_window_panel_commands_parse_craft_ui_commands() { let mut app = EffectcraftApp::new(Session::default()); - app.ui.dock = DockNode::Tabs { panels: vec![PanelKind::Composition, PanelKind::Viewer(42), PanelKind::ScriptPanel(77)], active: 1 }; - let ctx = egui::Context::default(); - for panel in [PanelKind::Viewer(42), PanelKind::ScriptPanel(77)] { - effectcraft_ui_egui::menus::invoke(&mut app, &ctx, "window.dockAction", json!({"action": Action::Close { panel }})).unwrap(); - assert!(!app.ui.dock.contains(panel)); + app.ui.dock = dock::docked(dock::hsplit( + SplitSize::FixedFirst(300.0), + dock::tabs(&[PanelKind::Project, PanelKind::Info], 0), + dock::tabs(&[PanelKind::Composition, PanelKind::Layer], 0), + )); + // `ui.dock` operations and actions return the workspace. + let reply = invoke(&mut app, "ui.dock", json!({"operation": "move", "panel": "Info", "target": "Composition", "zone": "center"})).unwrap(); + assert!(reply["docking"]["layout"].is_object(), "{reply}"); + assert!(app.ui.dock.group_of(PanelKind::Info).contains(&PanelKind::Composition)); + 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]); + // `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)); + invoke(&mut app, "window.panel.close", json!({"panel": "Info"})).unwrap(); + assert!(!app.ui.dock.is_open(PanelKind::Info)); + // A closed panel reopens where it was. + invoke(&mut app, "window.panel.activate", json!({"panel": "Info"})).unwrap(); + assert!(app.ui.dock.is_docked(PanelKind::Info)); + // The per-panel ids still open a panel. + invoke(&mut app, "window.panel.Align", json!({})).unwrap(); + assert!(app.ui.dock.is_open(PanelKind::Align)); + // Bad commands change nothing; Reset returns to the workspace's layout. + let before = app.ui.dock.clone(); + for (id, params) in [ + ("ui.dock", json!({"operation": "move", "panel": "Info", "target": "Nope"})), + ("ui.dock", json!({"operation": "teleport", "panel": "Info"})), + ("window.panel.move", json!({"panel": "Info"})), + ("window.panel.dock", json!({"panel": "Nope", "anchor": "Project"})), + ] { + assert!(invoke(&mut app, id, params.clone()).is_err(), "{id} {params}"); + assert_eq!(app.ui.dock, before); } - assert!(app.ui.dock.contains(PanelKind::Composition)); + invoke(&mut app, "ui.dock.reset", json!({})).unwrap(); + assert_eq!(app.ui.dock, Workspace::new(dock::workspace("Default"))); } #[test] -fn accordion_resize_routes_pointer_and_keyboard_without_changing_closed_entries() { +fn catalog_close_keeps_dynamic_panel_identity_and_releases_viewers() { + let mut app = EffectcraftApp::new(Session::default()); + app.ui.dock = dock::docked(dock::tabs(&[PanelKind::Composition, PanelKind::Viewer(42), PanelKind::ScriptPanel(77)], 1)); + 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(); + 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.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 = DockNode::Stack { - entries: vec![ - StackEntry::new(PanelKind::Preview, true, Some(100.0)), - StackEntry::new(PanelKind::Properties, true, None), - StackEntry::new(PanelKind::Align, false, Some(77.0)), - ], - }; + 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 id = egui::Id::unique(("dock-gutter", "s0".to_string())); - h.ctx.memory_mut(|memory| memory.request_focus(id)); - h.run_steps(2); - for pressed in [true, false] { - h.event(Event::Key { key: egui::Key::ArrowDown, physical_key: None, pressed, repeat: false, modifiers: Modifiers::NONE }); - h.step(); - } - let DockNode::Stack { entries } = &h.state().ui.dock else { panic!("stack lost") }; - assert_eq!(entries[0].height, Some(108.0)); + 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 DockNode::Stack { entries } = &h.state().ui.dock else { panic!("stack lost") }; - assert_eq!(entries[0].height, Some(124.0)); - assert_eq!(entries[1].height, None); - assert_eq!(entries[2], StackEntry::new(PanelKind::Align, false, Some(77.0))); + 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 legacy_close_repairs_selection_but_transactions_remain_strict() { - use effectcraft_ui_egui::dock::Floating; - let mut root = DockNode::Tabs { panels: vec![PanelKind::Properties, PanelKind::Align, PanelKind::EffectsPresets], active: usize::MAX }; - root.close(PanelKind::History); - assert!(root.is_visible(PanelKind::EffectsPresets)); - let mut layout = Layout { - root: DockNode::Tabs { panels: vec![PanelKind::Composition], active: 0 }, - floating: vec![Floating { - panels: vec![PanelKind::Properties, PanelKind::Align, PanelKind::EffectsPresets], - active: usize::MAX, - rect: [0.0, 0.0, 300.0, 200.0], - }], - }; - let before = layout.clone(); - assert!(layout.apply(Action::Close { panel: PanelKind::Properties }).is_err()); - assert_eq!(layout, before); - assert!(layout.unfloat(PanelKind::Properties)); - assert_eq!(layout.floating[0].panels.get(layout.floating[0].active), Some(&PanelKind::EffectsPresets)); - layout.floating[0].rect = [0.0; 4]; - let before = layout.clone(); - assert!(!layout.unfloat(PanelKind::Align)); - assert_eq!(layout, before); -} - #[test] fn failed_close_preserves_viewer_lifecycle_and_maximize_state() { let mut app = EffectcraftApp::new(Session::default()); - app.ui.dock = DockNode::Tabs { panels: vec![PanelKind::Composition, PanelKind::Viewer(42)], active: usize::MAX }; + // 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.maximized = Some(PanelKind::Viewer(42)); - app.ui.viewers.insert(42, None); + app.ui.viewers.insert(42, Some(3)); app.ui.active_viewer = 42; app.ui.locked_tabs.insert(PanelKind::Viewer(42).id()); let before = app.ui.clone(); @@ -426,3 +335,21 @@ fn failed_close_preserves_viewer_lifecycle_and_maximize_state() { assert_eq!(app.ui.active_viewer, before.active_viewer); assert_eq!(app.ui.locked_tabs, before.locked_tabs); } + +/// A panel never laid out opens at EffectCraft's default place for it (History beside the +/// Project panel, Render Queue with the Timeline), not where craft-ui's fallback puts it; a panel +/// the user closed comes back where it was. +#[test] +fn never_placed_panels_open_at_their_default_place() { + let mut app = EffectcraftApp::new(Session::default()); + assert!(!app.ui.dock.is_open(PanelKind::History)); + invoke(&mut app, "window.panel", json!({"panel": "History"})).unwrap(); + assert!(app.ui.dock.group_of(PanelKind::History).contains(&PanelKind::Project), "{:?}", app.ui.dock.group_of(PanelKind::History)); + invoke(&mut app, "window.panel.activate", json!({"panel": "Tracker"})).unwrap(); + assert!(app.ui.dock.group_of(PanelKind::Tracker).contains(&PanelKind::EffectsPresets) || app.ui.dock.is_open(PanelKind::Tracker)); + // Closed by the user, it reopens at its recorded place. + invoke(&mut app, "window.dockPanel", json!({"panel": "History", "anchor": "Timeline"})).unwrap(); + invoke(&mut app, "window.closePanel", json!({"panel": "History"})).unwrap(); + invoke(&mut app, "window.panel", json!({"panel": "History"})).unwrap(); + assert!(app.ui.dock.group_of(PanelKind::History).contains(&PanelKind::Timeline)); +} diff --git a/crates/ui-egui/tests/it/ui_blank_context_menus.rs b/crates/ui-egui/tests/it/ui_blank_context_menus.rs index a604ef2c2..52417326f 100644 --- a/crates/ui-egui/tests/it/ui_blank_context_menus.rs +++ b/crates/ui-egui/tests/it/ui_blank_context_menus.rs @@ -1,6 +1,7 @@ //! Right-click actions in the blank Project and Timeline areas, and on Timeline property names. use effectcraft_engine::Session; use effectcraft_engine::project::ItemKind; +use effectcraft_ui_egui::dock::WorkspaceExt as _; use effectcraft_ui_egui::{Dialog, EffectcraftApp, dock::PanelKind}; use egui::{Event, Modifiers, PointerButton, Pos2, Rect, pos2, vec2}; use egui_kittest::{Harness, kittest::Queryable as _}; @@ -160,7 +161,7 @@ fn timeline_blank_menu_opens_current_comp_in_essential_graphics() { h.get_by_label("Open in Essential Graphics").click(); h.run_steps(3); assert_eq!(h.state().session.state.essential_primary, Some(comp)); - assert!(h.state().ui.dock.contains(PanelKind::EssentialGraphics)); + assert!(h.state().ui.dock.is_docked(PanelKind::EssentialGraphics)); } } diff --git a/crates/ui-egui/tests/it/ui_character_eyedropper.rs b/crates/ui-egui/tests/it/ui_character_eyedropper.rs index a2c4c6d1f..ea2578a0d 100644 --- a/crates/ui-egui/tests/it/ui_character_eyedropper.rs +++ b/crates/ui-egui/tests/it/ui_character_eyedropper.rs @@ -2,7 +2,7 @@ use effectcraft_engine::{Session, commands::text_edit::layer_doc, project::LayerId}; use effectcraft_ui_egui::{ EffectcraftApp, - dock::{DockNode, PanelKind, SplitSize}, + dock::{self, PanelKind, SplitSize}, panels::viewer::comp_to_screen, }; use egui::{Event, Modifiers, PointerButton, Pos2, pos2, vec2}; @@ -71,12 +71,7 @@ fn character_stroke_eyedropper_samples_viewer() { s.execute("layer.setText", json!({"layer": text, "fill": [0.0, 0.0, 0.0], "size": 32.0})).unwrap(); let mut app = EffectcraftApp::new(s); app.ui.viewer.show_layer_controls = false; - app.ui.dock = DockNode::Split { - vertical: false, - size: SplitSize::FixedB(360.0), - a: Box::new(DockNode::Tabs { panels: vec![PanelKind::Composition], active: 0 }), - b: Box::new(DockNode::Tabs { panels: vec![PanelKind::Character], active: 0 }), - }; + 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) }; h.state_mut().show_panel(PanelKind::Character); diff --git a/crates/ui-egui/tests/it/ui_dock_resize.rs b/crates/ui-egui/tests/it/ui_dock_resize.rs index 3dc44b708..863fe697e 100644 --- a/crates/ui-egui/tests/it/ui_dock_resize.rs +++ b/crates/ui-egui/tests/it/ui_dock_resize.rs @@ -1,10 +1,11 @@ //! Shared pane resizing in the full application, including application shortcut ownership. +use craft_ui::docking::{Divider, DockArea, Hit}; use effectcraft_engine::Session; use effectcraft_ui_egui::EffectcraftApp; -use effectcraft_ui_egui::dock::{DockNode, PanelKind, SplitSize}; +use effectcraft_ui_egui::dock::{self, Node, PanelKind, SplitSize}; use effectcraft_ui_egui::theme::ThemeKind; -use egui::{Event, Id, Key, Modifiers, PointerButton, Rect, pos2, vec2}; +use egui::{Event, Key, Modifiers, PointerButton, Rect, pos2, vec2}; use egui_kittest::Harness; use serde_json::json; @@ -23,8 +24,8 @@ fn snapshots(h: &mut Harness<'_, EffectcraftApp>, directory: Option<&std::path:: } fn first_size(h: &Harness<'_, EffectcraftApp>) -> f32 { - match h.state().ui.dock { - DockNode::Split { size: SplitSize::FixedA(value), .. } => value, + match &h.state().ui.dock.layout.root { + Some(Node::Split { size: SplitSize::FixedFirst(value), .. }) => *value, ref other => panic!("fixed-size mode changed: {other:?}"), } } @@ -45,16 +46,12 @@ fn focused_dock_resize_owns_arrows_and_keeps_pointer_dragging() { h.run_steps(4); snapshots(&mut h, directory.as_deref(), "workspace"); h.state_mut().ui.focused = PanelKind::Composition; - h.state_mut().ui.dock = DockNode::Split { - vertical: false, - size: SplitSize::FixedA(400.0), - a: Box::new(DockNode::Tabs { panels: vec![PanelKind::Project], active: 0 }), - b: Box::new(DockNode::Tabs { panels: vec![PanelKind::Composition], active: 0 }), - }; + h.state_mut().ui.dock = + dock::docked(dock::hsplit(SplitSize::FixedFirst(400.0), dock::tabs(&[PanelKind::Project], 0), dock::tabs(&[PanelKind::Composition], 0))); h.run_steps(3); let before_project = h.state().session.project.clone(); let before_times = h.state().session.state.times.clone(); - let id = Id::unique(("dock-gutter", String::new())); + let id = DockArea::::hit_id(effectcraft_ui_egui::dock_ui::area_id(), &Hit::Divider(Divider::Split(Vec::new()))); h.ctx.memory_mut(|memory| memory.request_focus(id)); h.run_steps(2); assert_eq!(h.ctx.memory(|memory| memory.focused()), Some(id)); diff --git a/crates/ui-egui/tests/it/ui_fx_editors.rs b/crates/ui-egui/tests/it/ui_fx_editors.rs index 90a5af15d..b9530fdf4 100644 --- a/crates/ui-egui/tests/it/ui_fx_editors.rs +++ b/crates/ui-egui/tests/it/ui_fx_editors.rs @@ -8,6 +8,7 @@ use effectcraft_engine::keyframe::Value as KV; use effectcraft_engine::project::{LayerId, Node, PropGroup}; use effectcraft_ui_egui::EffectcraftApp; use effectcraft_ui_egui::dock::PanelKind; +use effectcraft_ui_egui::dock::WorkspaceExt as _; use egui::{Event, Pos2, pos2}; use egui_kittest::Harness; use serde_json::json; @@ -298,5 +299,5 @@ fn composition_tabs_and_scrolling_preview() { let shown = h.state().session.state.active_comp.unwrap(); click_id(&mut h, "panel.tab.Timeline.close"); assert!(!h.state().session.state.open_comps.contains(&shown)); - assert!(h.state().ui.dock.contains(PanelKind::Timeline)); + assert!(h.state().ui.dock.is_docked(PanelKind::Timeline)); } diff --git a/crates/ui-egui/tests/it/ui_menus.rs b/crates/ui-egui/tests/it/ui_menus.rs index 90207b52d..c76f7fafd 100644 --- a/crates/ui-egui/tests/it/ui_menus.rs +++ b/crates/ui-egui/tests/it/ui_menus.rs @@ -318,7 +318,8 @@ fn hold_browse_opens_a_submenu_and_the_release_inside_picks_an_entry() { h.state_mut().session.state.selected_layers = vec![first]; let effect = rect(&h, "menu.Effect"); press(&mut h, effect.center()); - assert!(shown(&h, "Effect Controls"), "the Effect menu opens on the press"); + // (Effect ▸ Remove All: "Effect Controls" also names the panel's tab.) + assert!(shown(&h, "Remove All"), "the Effect menu opens on the press"); // The categories come from the effect registry; the first alphabetically is "3D Channel". let cat = h.query_by_label_contains("3D Channel").expect("the category row is shown").rect(); move_to(&mut h, cat.center()); @@ -326,7 +327,7 @@ fn hold_browse_opens_a_submenu_and_the_release_inside_picks_an_entry() { let entry = h.query_by_label_contains("Cryptomatte").expect("the submenu is open").rect(); move_to(&mut h, entry.center()); release(&mut h, entry.center()); - assert!(!shown(&h, "Effect Controls"), "the release closed the menus"); + assert!(!shown(&h, "Remove All"), "the release closed the menus"); assert!(h.state().session.state.last_effect.is_some(), "and the release chose the entry: it applied its effect"); } diff --git a/crates/ui-egui/tests/it/ui_panel_focus.rs b/crates/ui-egui/tests/it/ui_panel_focus.rs index 8fe2c881f..0d436f702 100644 --- a/crates/ui-egui/tests/it/ui_panel_focus.rs +++ b/crates/ui-egui/tests/it/ui_panel_focus.rs @@ -5,7 +5,8 @@ use effectcraft_engine::Session; use effectcraft_engine::project::ItemId; use effectcraft_ui_egui::EffectcraftApp; -use effectcraft_ui_egui::dock::{DockNode, PanelKind}; +use effectcraft_ui_egui::dock::WorkspaceExt as _; +use effectcraft_ui_egui::dock::{Node, PanelKind, Workspace}; use egui::{Event, Pos2, pos2}; use egui_kittest::Harness; use serde_json::json; @@ -42,15 +43,6 @@ fn click_n(h: &mut Harness<'_, EffectcraftApp>, p: Pos2, n: u32) { h.run_steps(2); } -/// The tabs of the docked group holding `p`, in order. -fn group_of(n: &DockNode, p: PanelKind) -> Option> { - match n { - DockNode::Split { a, b, .. } => group_of(a, p).or_else(|| group_of(b, p)), - DockNode::Tabs { panels, .. } => panels.contains(&p).then(|| panels.clone()), - DockNode::Stack { entries } => entries.iter().find(|e| e.contains(p)).map(|e| e.panels.clone()), - } -} - fn invoke(h: &mut Harness<'_, EffectcraftApp>, id: &str, params: serde_json::Value) { let ctx = h.ctx.clone(); effectcraft_ui_egui::menus::invoke(h.state_mut(), &ctx, id, params).unwrap(); @@ -66,7 +58,7 @@ fn opening_a_comp_brings_up_a_closed_composition_panel() { let (mut h, other, main) = harness(); assert_eq!(group_of(&h.state().ui.dock, PanelKind::Composition), Some(vec![PanelKind::Composition, PanelKind::Layer])); invoke(&mut h, "window.closePanel", json!({"panel": "Composition"})); - assert!(!h.state().ui.dock.contains(PanelKind::Composition)); + assert!(!h.state().ui.dock.is_docked(PanelKind::Composition)); assert!(h.state().ui.dock.is_visible(PanelKind::Layer), "the centre shows the Layer panel"); // Double-click "Other" in the Project panel. @@ -75,7 +67,7 @@ fn opening_a_comp_brings_up_a_closed_composition_panel() { assert_eq!(h.state().session.active_comp_id(), Some(ItemId(other))); let dock = &h.state().ui.dock; assert!(dock.is_visible(PanelKind::Composition), "the Composition panel is back and in front"); - assert_eq!(group_of(dock, PanelKind::Composition), Some(vec![PanelKind::Layer, PanelKind::Composition]), "back in the centre"); + assert_eq!(group_of(dock, PanelKind::Composition), Some(vec![PanelKind::Composition, PanelKind::Layer]), "back in the centre"); assert!(h.state().auto.elements.iter().any(|e| e.id == "panel.Composition"), "the Composition panel is drawn"); // Open Composition (the Project panel's context menu) with the panel closed again. @@ -83,12 +75,12 @@ fn opening_a_comp_brings_up_a_closed_composition_panel() { invoke(&mut h, "comp.open", json!({"comp": main})); assert_eq!(h.state().session.active_comp_id(), Some(ItemId(main))); assert!(h.state().ui.dock.is_visible(PanelKind::Composition)); - assert_eq!(group_of(&h.state().ui.dock, PanelKind::Composition), Some(vec![PanelKind::Layer, PanelKind::Composition])); + assert_eq!(group_of(&h.state().ui.dock, PanelKind::Composition), Some(vec![PanelKind::Composition, PanelKind::Layer])); // Window ▸ Composition reopens it in the centre too (not beside Effects & Presets). invoke(&mut h, "window.closePanel", json!({"panel": "Composition"})); invoke(&mut h, "window.panel", json!({"panel": "Composition"})); - assert_eq!(group_of(&h.state().ui.dock, PanelKind::Composition), Some(vec![PanelKind::Layer, PanelKind::Composition])); + assert_eq!(group_of(&h.state().ui.dock, PanelKind::Composition), Some(vec![PanelKind::Composition, PanelKind::Layer])); assert!(h.state().ui.dock.is_visible(PanelKind::Composition)); } @@ -99,12 +91,12 @@ fn opening_a_comp_in_the_minimal_workspace_docks_the_viewer_above_the_timeline() let (mut h, other, _) = harness(); invoke(&mut h, "window.workspace", json!({"name": "Minimal"})); invoke(&mut h, "window.closePanel", json!({"panel": "Composition"})); - assert!(!h.state().ui.dock.contains(PanelKind::Composition)); + assert!(!h.state().ui.dock.is_docked(PanelKind::Composition)); invoke(&mut h, "comp.open", json!({"comp": other})); - match &h.state().ui.dock { - DockNode::Split { vertical: true, a, b, .. } => { - assert_eq!(group_of(a, PanelKind::Composition), Some(vec![PanelKind::Composition]), "the viewer is on top"); - assert!(b.contains(PanelKind::Timeline)); + match &h.state().ui.dock.layout.root { + Some(Node::Split { axis: effectcraft_ui_egui::dock::SplitAxis::Vertical, first, second, .. }) => { + assert_eq!(**first, Node::Tabs { panels: vec![PanelKind::Composition], active: 0 }, "the viewer is on top"); + assert!(matches!(&**second, Node::Tabs { panels, .. } if panels.contains(&PanelKind::Timeline))); } other => panic!("expected the viewer above the Timeline, got {other:?}"), } @@ -147,7 +139,7 @@ fn applying_an_effect_brings_up_effect_controls_on_that_layer() { // Closed: Effect ▸ Last Effect reopens it. invoke(&mut h, "window.closePanel", json!({"panel": "EffectControls"})); - assert!(!h.state().ui.dock.contains(PanelKind::EffectControls)); + assert!(!h.state().ui.dock.is_docked(PanelKind::EffectControls)); try_invoke(&mut h, "effect.applyLast", json!({})); assert!(ec_up(&h), "Effect Controls reopened"); @@ -177,7 +169,7 @@ fn double_clicking_an_effect_in_the_timeline_opens_effect_controls() { invoke(&mut h, "window.closePanel", json!({"panel": "EffectControls"})); let blue = layer_id(&h, "Blue"); invoke(&mut h, "layer.select", json!({"layers": [blue]})); - assert!(!h.state().ui.dock.contains(PanelKind::EffectControls)); + assert!(!h.state().ui.dock.is_docked(PanelKind::EffectControls)); let name = rect(&h, &format!("timeline.group.{uid}.name")); click_n(&mut h, name.center(), 2); @@ -231,3 +223,8 @@ fn focused_panel_outline_is_painted_over_the_panel_bodies() { } } } + +/// The tabs of the group holding `p`, in order. +fn group_of(w: &Workspace, p: PanelKind) -> Option> { + Some(w.group_of(p)).filter(|g| !g.is_empty()) +} diff --git a/crates/ui-egui/tests/it/ui_panel_windows.rs b/crates/ui-egui/tests/it/ui_panel_windows.rs index 76a9a31c0..d2750bb05 100644 --- a/crates/ui-egui/tests/it/ui_panel_windows.rs +++ b/crates/ui-egui/tests/it/ui_panel_windows.rs @@ -1,67 +1,52 @@ -//! Multiple monitors (#486): a panel moves out of the main window into a native window of its -//! own (Move Panel to New Window), which can be placed on another screen, and back. +//! Multiple monitors (#486): Move Panel to New Window puts a panel in a floating window of its +//! own, which on desktop is an OS window that can go on another screen, and Move Panel to Main +//! Window docks it again. The test harness embeds viewports, so these windows draw in the main +//! window here, as on the web. use effectcraft_engine::Session; use effectcraft_ui_egui::EffectcraftApp; -use effectcraft_ui_egui::dock::{PanelKind, PanelWindow}; -use egui::vec2; -use egui_kittest::Harness; +use effectcraft_ui_egui::dock::{PanelKind, WorkspaceExt as _}; +use effectcraft_ui_egui::dock_ui::sanitized_window_rect; use serde_json::json; fn invoke(app: &mut EffectcraftApp, ctx: &egui::Context, params: serde_json::Value) -> Result { effectcraft_ui_egui::menus::invoke(app, ctx, "window.panelWindow", params) } +fn native(app: &EffectcraftApp, panel: PanelKind) -> Option<[f32; 4]> { + app.ui.dock.layout.floating.iter().find(|w| w.contains(&panel)).and_then(|w| w.native) +} + #[test] fn panel_window_command_moves_a_docked_panel_into_its_own_window_and_back() { let mut app = EffectcraftApp::new(Session::default()); let ctx = egui::Context::default(); - assert!(app.ui.dock.contains(PanelKind::Project)); + assert!(app.ui.dock.is_docked(PanelKind::Project)); assert_eq!(invoke(&mut app, &ctx, json!({"panel": "Project", "window": true})).unwrap(), json!({"window": true})); // Undocked first, then given a window of its own. - assert!(!app.ui.dock.contains(PanelKind::Project)); - assert!(app.ui.floating.iter().any(|group| group.panels == [PanelKind::Project])); + assert!(!app.ui.dock.is_docked(PanelKind::Project)); + assert!(app.ui.dock.layout.floating.iter().any(|w| w.panels().copied().collect::>() == [PanelKind::Project])); assert!(app.in_panel_window(PanelKind::Project)); - let window = app.ui.panel_windows.iter().find(|w| w.panel == PanelKind::Project).copied().unwrap(); - assert_eq!(window.rect, PanelWindow::sanitized(window.rect)); + let rect = native(&app, PanelKind::Project).unwrap(); + assert_eq!(rect, sanitized_window_rect(rect)); // Asking again changes nothing; no `window` toggles. assert_eq!(invoke(&mut app, &ctx, json!({"panel": "Project", "window": true})).unwrap(), json!({"window": true})); - assert_eq!(app.ui.panel_windows.len(), 1); assert_eq!(invoke(&mut app, &ctx, json!({"panel": "Project"})).unwrap(), json!({"window": false})); - // Back in the main window, still floating where it was. + // Back in the main window: docked in the first docked group. assert!(!app.in_panel_window(PanelKind::Project)); - assert!(app.ui.panel_windows.is_empty()); - assert!(app.ui.floating.iter().any(|group| group.panels == [PanelKind::Project])); + assert!(!app.ui.dock.is_floating(PanelKind::Project)); + assert!(app.ui.dock.is_docked(PanelKind::Project)); // The serialized panel form works too. assert_eq!(invoke(&mut app, &ctx, json!({"panel": PanelKind::Project})).unwrap(), json!({"window": true})); // Bad requests are errors and change nothing. - let before = app.ui.panel_windows.clone(); + let before = app.ui.dock.clone(); for params in [json!({}), json!({"panel": "Nope"}), json!({"panel": 7}), json!({"panel": "Project", "window": "yes"}), json!({"panel": {"Viewer": 9}})] { assert!(invoke(&mut app, &ctx, params.clone()).is_err(), "{params} must be rejected"); } - assert_eq!(app.ui.panel_windows, before); -} - -#[test] -fn a_panel_in_its_own_window_leaves_the_main_window() { - let mut app = EffectcraftApp::new(Session::default()); - app.ui.start_screen = false; - let mut h = Harness::builder().with_size(vec2(1200.0, 760.0)).build_eframe(move |_| app); - h.run_steps(3); - let ctx = h.ctx.clone(); - invoke(h.state_mut(), &ctx, json!({"panel": "Project", "window": true})).unwrap(); - h.run_steps(3); - // No in-window floating group is drawn for it (no move strip, no floating area)... - assert!(!h.state().auto.elements.iter().any(|e| e.id.starts_with("panel.float."))); - let area = egui::Id::unique(("floating-panel", PanelKind::Project.id())); - assert!(!h.ctx.memory(|m| m.layer_ids().any(|layer| layer.id == area && m.areas().is_visible(&layer)))); - // ...the window draws it (here embedded: the test harness has no native windows). - assert!(h.state().auto.elements.iter().any(|e| e.id == "panel.Project")); - // Docking it back into the main window closes the window entry. - let ctx = h.ctx.clone(); - effectcraft_ui_egui::menus::invoke(h.state_mut(), &ctx, "window.dockPanel", json!({"panel": "Project", "anchor": "Timeline"})).unwrap(); - h.run_steps(2); - assert!(h.state().ui.panel_windows.is_empty()); - assert!(!h.state().in_panel_window(PanelKind::Project)); + assert_eq!(app.ui.dock, before); + // Docking it back into the main window ends its window. + effectcraft_ui_egui::menus::invoke(&mut app, &ctx, "window.dockPanel", json!({"panel": "Project", "anchor": "Timeline"})).unwrap(); + assert!(!app.in_panel_window(PanelKind::Project)); + assert!(app.ui.dock.is_docked(PanelKind::Project)); } #[test] @@ -72,16 +57,50 @@ fn panel_windows_survive_restart_with_hostile_places_made_safe() { let mut app = EffectcraftApp::new(Session { config: Some(store.clone()), ..Default::default() }); let ctx = egui::Context::default(); invoke(&mut app, &ctx, json!({"panel": "Project", "window": true})).unwrap(); - let hostile = [1.0e9, -3.0e12, 1.0e9, 0.5]; - if let Some(w) = app.ui.panel_windows.first_mut() { - w.rect = hostile; - } - // A window for a panel that doesn't float is dropped on load. - app.ui.panel_windows.push(PanelWindow { panel: PanelKind::Timeline, rect: [10.0, 10.0, 300.0, 200.0] }); + let hostile = [90_000.0, -99_000.0, 99_000.0, 0.5]; + app.apply_dock(craft_ui::docking::Action::SetNative { panel: PanelKind::Project, rect: Some(hostile) }).unwrap(); eframe::App::on_exit(&mut app); let restarted = EffectcraftApp::new(Session { config: Some(store), ..Default::default() }); - assert_eq!(restarted.ui.panel_windows, vec![PanelWindow { panel: PanelKind::Project, rect: PanelWindow::sanitized(hostile) }]); - let [x, y, w, h] = PanelWindow::sanitized(hostile); + assert_eq!(native(&restarted, PanelKind::Project), Some(sanitized_window_rect(hostile))); + let [x, y, w, h] = sanitized_window_rect(hostile); assert!(x <= 100_000.0 && y >= -100_000.0 && (160.0..=16_384.0).contains(&w) && (100.0..=16_384.0).contains(&h)); - assert!(PanelWindow::sanitized([f32::NAN, f32::INFINITY, f32::NAN, f32::NEG_INFINITY]).iter().all(|v| v.is_finite())); + assert!(sanitized_window_rect([f32::NAN, f32::INFINITY, f32::NAN, f32::NEG_INFINITY]).iter().all(|v| v.is_finite())); +} + +#[test] +fn a_click_on_a_floating_panel_does_nothing_while_a_dialog_is_open() { + use egui::{Event, Modifiers, PointerButton, pos2, vec2}; + use egui_kittest::Harness; + let mut app = EffectcraftApp::new(Session::default()); + app.ui.start_screen = false; + app.apply_dock(craft_ui::docking::Action::Float { panel: PanelKind::Project, rect: [80.0, 120.0, 320.0, 240.0] }).unwrap(); + let mut h = Harness::builder().with_size(vec2(1400.0, 900.0)).build_eframe(move |_| app); + h.run_steps(3); + let close = |h: &Harness<'_, EffectcraftApp>| { + let e = h.state().auto.elements.iter().find(|e| e.id.starts_with("panel.float.") && e.id.ends_with(".close")).expect("the floating window's ×"); + pos2(e.rect[0] + e.rect[2] / 2.0, e.rect[1] + e.rect[3] / 2.0) + }; + let click = |h: &mut Harness<'_, EffectcraftApp>, pos| { + h.event(Event::PointerMoved(pos)); + h.step(); + for pressed in [true, false] { + h.event(Event::PointerButton { pos, button: PointerButton::Primary, pressed, modifiers: Modifiers::NONE }); + h.step(); + } + h.run_steps(2); + }; + let at = close(&h); + let ctx = h.ctx.clone(); + effectcraft_ui_egui::menus::invoke(h.state_mut(), &ctx, "app.settings", json!({"page": "general"})).unwrap(); + h.run_steps(3); + let before = h.state().ui.dock.clone(); + click(&mut h, at); + assert_eq!(h.state().ui.dock, before, "the floating panel takes no click while Settings is open"); + assert!(h.state().ui.dock.is_floating(PanelKind::Project)); + // The same click closes the window once the dialog is gone. + h.state_mut().dialog = None; + h.run_steps(3); + let at = close(&h); + click(&mut h, at); + assert!(!h.state().ui.dock.is_open(PanelKind::Project)); } diff --git a/crates/ui-egui/tests/it/ui_panels.rs b/crates/ui-egui/tests/it/ui_panels.rs index f4c11ba0b..db9ef7373 100644 --- a/crates/ui-egui/tests/it/ui_panels.rs +++ b/crates/ui-egui/tests/it/ui_panels.rs @@ -2,6 +2,7 @@ //! registers its automation ids; the Footage panel's buttons edit into the comp; the Progress //! panel lists and cancels a job; Lumetri Scopes switch scope through their dropdown. +use effectcraft_ui_egui::dock::WorkspaceExt as _; use std::sync::Arc; use effectcraft_engine::{Session, config::MemoryConfig}; @@ -60,7 +61,7 @@ fn window_menu_opens_the_new_panels() { ("contentAwareFill", PanelKind::ContentAwareFill, "contentFill.method"), ] { open(&mut h, name); - assert!(h.state().ui.dock.contains(kind) || h.state().ui.floating.iter().any(|f| f.panels.contains(&kind)), "{name} shown"); + assert!(h.state().ui.dock.is_open(kind), "{name} shown"); if !auto.is_empty() { assert!(h.state().auto.find(auto).is_some(), "{name}: {auto}"); } @@ -72,9 +73,7 @@ fn window_menu_opens_the_new_panels() { #[test] fn window_menu_closes_a_checked_panel() { let mut h = harness(); - let shown = |h: &Harness<'_, EffectcraftApp>| { - h.state().ui.dock.contains(PanelKind::Align) || h.state().ui.floating.iter().any(|f| f.panels.contains(&PanelKind::Align)) - }; + let shown = |h: &Harness<'_, EffectcraftApp>| h.state().ui.dock.is_open(PanelKind::Align); open(&mut h, "align"); assert!(shown(&h)); click(&mut h, "menu.Window"); @@ -106,7 +105,7 @@ fn footage_panel_buttons_edit_into_the_comp() { let item = h.state().session.project.items.values().find(|i| matches!(i.kind, effectcraft_engine::project::ItemKind::Solid(_))).unwrap().id.0; h.state_mut().session.execute("footage.open", json!({"item": item})).unwrap(); h.run_steps(4); - assert!(h.state().ui.dock.contains(PanelKind::Footage) || h.state().ui.floating.iter().any(|f| f.panels.contains(&PanelKind::Footage))); + assert!(h.state().ui.dock.is_open(PanelKind::Footage)); assert!(h.state().auto.find("footage.overlayEdit").is_some()); let before = h.state().session.active_comp().unwrap().layers.len(); click(&mut h, "footage.overlayEdit"); diff --git a/crates/ui-egui/tests/it/ui_preview_align.rs b/crates/ui-egui/tests/it/ui_preview_align.rs index 2b2ba1b44..1469a5e9e 100644 --- a/crates/ui-egui/tests/it/ui_preview_align.rs +++ b/crates/ui-egui/tests/it/ui_preview_align.rs @@ -279,21 +279,25 @@ fn playback_prefetches_past_the_cached_frames_ahead() { std::thread::sleep(std::time::Duration::from_millis(2)); } assert_eq!(h.state().frames.cached_frames(&series), (0..120).collect::>()); + // Rendering/instrumentation time must not move the playhead near the end of the + // cached run. Exercise real prefetch workers while holding playback in its first second. + h.state_mut().use_manual_clock(); h.state_mut().session.set_time(Tick::ZERO); invoke(&mut h, "playback.toggle", json!({})); + h.state_mut().clock_mut().advance(0.25); h.run_steps(2); assert!(h.state().playback.playing); let cur = h.state().session.time(); + assert!(cur > Tick::ZERO, "playback advances with the manual clock"); assert!(cur < Tick::from_seconds_f64(1.0), "{cur:?}"); - for _ in 0..4000 { + let deadline = std::time::Instant::now() + std::time::Duration::from_secs(60); + while std::time::Instant::now() < deadline { if h.state().frames.cached_frames(&series).iter().any(|&f| f >= 120) { break; } h.step(); std::thread::sleep(std::time::Duration::from_millis(1)); - if h.state().session.time() >= Tick::from_seconds_f64(1.0) { - break; - } + assert_eq!(h.state().session.time(), cur, "worker waits do not advance playback"); } assert!(h.state().frames.cached_frames(&series).iter().any(|&f| f >= 120), "frames past the cached run render while it plays the first second"); } diff --git a/crates/ui-egui/tests/it/ui_scriptui.rs b/crates/ui-egui/tests/it/ui_scriptui.rs index 31fb555d3..aa439737b 100644 --- a/crates/ui-egui/tests/it/ui_scriptui.rs +++ b/crates/ui-egui/tests/it/ui_scriptui.rs @@ -4,6 +4,7 @@ use effectcraft_ui_egui::EffectcraftApp; use effectcraft_ui_egui::dock::PanelKind; +use effectcraft_ui_egui::dock::WorkspaceExt as _; use egui::{Event, Rect, pos2, vec2}; use egui_kittest::Harness; use serde_json::json; @@ -75,7 +76,7 @@ fn script_windows_are_drawn_and_clickable() { h.state_mut().session.execute("window.scriptPanel", json!({"name": "Layer Tools.jsx"})).unwrap(); h.run_steps(3); let panel = h.state().session.script_ui.windows.iter().find(|w| w.script == "Layer Tools.jsx").unwrap().id; - assert!(h.state().ui.dock.contains(PanelKind::ScriptPanel(panel)), "the panel docks"); + assert!(h.state().ui.dock.is_docked(PanelKind::ScriptPanel(panel)), "the panel docks"); assert!(h.state().auto.find(&format!("scriptui.{panel}")).is_some()); // The menus list scripts and panels. let cx = effectcraft_engine::menus::DynCtx::default(); @@ -104,7 +105,7 @@ fn panels_open_at_quit_dock_again_at_launch() { let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(|_| EffectcraftApp::new(s)); h.run_steps(3); let panel = h.state().session.script_ui.windows.iter().find(|w| w.script == "Hello Panel.jsx").expect("the panel's window").id; - assert!(h.state().ui.dock.contains(PanelKind::ScriptPanel(panel)), "the panel docks"); + assert!(h.state().ui.dock.is_docked(PanelKind::ScriptPanel(panel)), "the panel docks"); assert!(h.state().auto.find(&format!("scriptui.{panel}.hi")).is_some(), "its controls are drawn"); // Closing its tab forgets it for the next launch. h.state_mut().close_panel(PanelKind::ScriptPanel(panel)); @@ -131,7 +132,7 @@ fn ease_presets_panel_eases_the_selected_keys_from_its_list() { s.execute("window.scriptPanel", json!({"name": "Ease Presets.jsx"})).unwrap(); h.run_steps(3); let panel = h.state().session.script_ui.windows.iter().find(|w| w.script == "Ease Presets.jsx").unwrap().id; - assert!(h.state().ui.dock.contains(PanelKind::ScriptPanel(panel)), "the panel docks"); + assert!(h.state().ui.dock.is_docked(PanelKind::ScriptPanel(panel)), "the panel docks"); h.state_mut().ui.maximized = Some(PanelKind::ScriptPanel(panel)); h.run_steps(3); let steps = h.state().session.history.undo.len(); diff --git a/crates/ui-egui/tests/it/ui_scrolling.rs b/crates/ui-egui/tests/it/ui_scrolling.rs index bba415d60..2e0f32ac8 100644 --- a/crates/ui-egui/tests/it/ui_scrolling.rs +++ b/crates/ui-egui/tests/it/ui_scrolling.rs @@ -314,7 +314,8 @@ fn panels_taller_than_their_space_have_a_scroll_bar_to_drag() { click_at(&mut h, pos2(bar.center().x, bar.min.y + 2.0)); assert_eq!(scrolled(&h, id).0, 0.0, "{id}: at the top"); drag(&mut h, pos2(bar.center().x, bar.min.y + 6.0), pos2(bar.center().x, bar.max.y + 40.0)); - assert_eq!(scrolled(&h, id).0, max, "{id}: dragged to the end"); + let end = scrolled(&h, id).0; + assert!((end - max).abs() < 0.01, "{id}: dragged to the end: {end} of {max}"); } } @@ -332,7 +333,7 @@ fn effect_values_stay_clear_of_the_keyframe_navigator() { app.session.execute("prop.toggleAnimation", json!({"layer": lid, "path": path})).unwrap(); app.session.execute("prop.set", json!({"layer": lid, "path": path, "value": [123456.7, 123456.7]})).unwrap(); let uid = app.session.active_comp().unwrap().layer(effectcraft_engine::project::LayerId(lid)).unwrap().props.prop(path).unwrap().uid; - assert!(app.edit_layout(|l| l.float(PanelKind::EffectControls, [300.0, 150.0, 330.0, 500.0]))); + app.apply_dock(craft_ui::docking::Action::Float { panel: PanelKind::EffectControls, rect: [300.0, 150.0, 330.0, 500.0] }).unwrap(); h.run_steps(3); let value = rect(&h, &format!("effectControls.prop.{uid}.value.1")); let nav = rect(&h, &format!("effectControls.prop.{uid}.prevKey")); diff --git a/crates/ui-egui/tests/it/ui_tabs.rs b/crates/ui-egui/tests/it/ui_tabs.rs index fe69d56f9..65b429f44 100644 --- a/crates/ui-egui/tests/it/ui_tabs.rs +++ b/crates/ui-egui/tests/it/ui_tabs.rs @@ -5,7 +5,8 @@ use effectcraft_engine::Session; use effectcraft_engine::project::ItemId; use effectcraft_ui_egui::EffectcraftApp; -use effectcraft_ui_egui::dock::{DockNode, PanelKind}; +use effectcraft_ui_egui::dock::WorkspaceExt as _; +use effectcraft_ui_egui::dock::{Node, PanelKind, SplitSize, Workspace}; use egui::{Event, Pos2, pos2}; use egui_kittest::Harness; use serde_json::json; @@ -59,15 +60,6 @@ fn drag(h: &mut Harness<'_, EffectcraftApp>, from: Pos2, to: Pos2) { h.run_steps(2); } -/// The tabs of the docked group holding `p`, in order. -fn group_of(n: &DockNode, p: PanelKind) -> Option> { - match n { - DockNode::Split { a, b, .. } => group_of(a, p).or_else(|| group_of(b, p)), - DockNode::Tabs { panels, .. } => panels.contains(&p).then(|| panels.clone()), - DockNode::Stack { entries } => entries.iter().find(|e| e.contains(p)).map(|e| e.panels.clone()), - } -} - fn open_comps(h: &Harness<'_, EffectcraftApp>) -> Vec { h.state().session.state.open_comps.iter().map(|c| c.0).collect() } @@ -81,10 +73,11 @@ fn project_double_click_opens_a_comp_as_its_own_timeline_tab() { assert_eq!(open_comps(&h), vec![main, pre]); assert_eq!(h.state().session.state.active_comp, Some(ItemId(pre))); assert_eq!(h.state().session.project.item(ItemId(pre)).map(|i| i.name.clone()), Some("Pre".into())); - // One Timeline tab per comp, the newest last; the shown one answers to the panel's id. + // One comp tab per comp in the Timeline's tab strip, the newest last. let (tm, tp) = (rect(&h, &format!("panel.tab.Timeline.{main}")), rect(&h, &format!("panel.tab.Timeline.{pre}"))); - assert!(tp.min.x > tm.max.x, "{tm:?} {tp:?}"); - assert_eq!(rect(&h, "panel.tab.Timeline"), tp); + assert!(tp.min.x >= tm.max.x - 0.5, "{tm:?} {tp:?}"); + let strip = rect(&h, "panel.tab.Timeline"); + assert!(strip.y_range().contains(tp.center().y) && tp.min.x > strip.max.x, "{strip:?} {tp:?}"); // Clicking Main's tab shows Main again; both stay open. click_n(&mut h, tm.center(), 1); assert_eq!(h.state().session.state.active_comp, Some(ItemId(main))); @@ -94,7 +87,7 @@ fn project_double_click_opens_a_comp_as_its_own_timeline_tab() { click_n(&mut h, close.center(), 1); assert_eq!(open_comps(&h), vec![pre]); assert_eq!(h.state().session.state.active_comp, Some(ItemId(pre))); - assert!(h.state().ui.dock.contains(PanelKind::Timeline)); + assert!(h.state().ui.dock.is_docked(PanelKind::Timeline)); // Double-clicking an open comp again adds no second tab. let name = rect(&h, &format!("project.item.{pre}.name")); click_n(&mut h, name.center(), 2); @@ -179,18 +172,17 @@ fn double_clicking_a_precomp_bar_opens_its_comp() { assert_eq!(h.state().session.active_comp_id(), Some(ItemId(pre))); } -/// Issue #46: a panel dragged by its panel-menu (hamburger) button onto the left edge of another -/// group docks there as its own group; dragging the gap between panels resizes them. +/// Issue #46: a panel dragged onto the left edge of another group docks there as its own group; +/// dragging the gap between panels resizes them. #[test] fn panels_dock_beside_others_and_gutters_resize_them() { let (mut h, _, _) = harness(); let dock = |h: &Harness<'_, EffectcraftApp>| h.state().ui.dock.clone(); - // Show Effect Controls in its group so its menu button is on screen, then drag by it. let tab = rect(&h, "panel.tab.EffectControls"); - click_n(&mut h, tab.center(), 1); - let grip = rect(&h, "panel.menu.EffectControls").center(); let tl = rect(&h, "panel.Timeline"); - drag(&mut h, grip, pos2(tl.min.x + tl.width() * 0.08, tl.center().y)); + // Inside the Timeline body's left drop zone. + let depth = craft_ui::docking::SIDE_EDGE_ZONE_DEPTH.min(tl.width().min(tl.height()) / 4.0); + drag(&mut h, tab.center(), pos2(tl.min.x + depth / 2.0, tl.center().y)); assert_eq!(group_of(&dock(&h), PanelKind::EffectControls), Some(vec![PanelKind::EffectControls])); assert!(!group_of(&dock(&h), PanelKind::Timeline).unwrap().contains(&PanelKind::EffectControls)); let (fx, tl) = (rect(&h, "panel.EffectControls"), rect(&h, "panel.Timeline")); @@ -212,41 +204,83 @@ fn panels_dock_beside_others_and_gutters_resize_them() { assert!((wider.width() - project.width() - 60.0).abs() < 2.0, "{} → {}", project.width(), wider.width()); } -/// Issue #171: the gaps between the right column's stacked panels drag to resize them (Preview -/// was stuck at its default height), not below a minimum; the heights stay in the layout. +/// The divider below the Preview frame: the horizontal gutter between it and the Properties +/// frame. +fn preview_divider(h: &Harness<'_, EffectcraftApp>) -> egui::Rect { + let (preview, props) = (rect(h, "panel.Preview"), rect(h, "panel.Properties")); + h.state() + .auto + .previous + .iter() + .filter(|e| e.id.starts_with("dock.gutter.") && e.rect[2] > e.rect[3]) + .map(|e| egui::Rect::from_min_size(pos2(e.rect[0], e.rect[1]), egui::vec2(e.rect[2], e.rect[3]))) + .find(|g| g.x_range().contains(preview.center().x) && g.center().y >= preview.max.y - 1.0 && g.center().y <= props.min.y + 1.0) + .expect("a gutter between Preview and Properties") +} + +/// Default's right column: a short Preview frame (46 points of body) and the Properties frame +/// below it taking the rest of the column, at any window height. #[test] -fn stacked_panel_gaps_resize_the_panels() { +fn the_default_preview_frame_is_short_and_properties_takes_the_rest() { let (mut h, _, _) = harness(); - fn height(n: &DockNode, p: PanelKind) -> Option> { - match n { - DockNode::Split { a, b, .. } => height(a, p).or_else(|| height(b, p)), - DockNode::Tabs { .. } => None, - DockNode::Stack { entries } => entries.iter().find(|e| e.contains(p)).map(|e| e.height), + let body = |h: &Harness<'_, EffectcraftApp>| rect(h, "panel.Preview").height(); + assert!((body(&h) - 46.0).abs() < 1.5, "Preview {}", body(&h)); + let props = rect(&h, "panel.Properties"); + assert!(props.height() > 300.0, "Properties {props:?}"); + // A taller window gives the room to Properties. + let size = h.ctx.content_rect().size(); + h.set_size(size + egui::vec2(0.0, 200.0)); + h.run_steps(3); + assert!((body(&h) - 46.0).abs() < 1.5, "Preview {}", body(&h)); + assert!((rect(&h, "panel.Properties").height() - props.height() - 200.0).abs() < 2.0); +} + +/// Issue #171: the divider below the Preview frame drags to resize it (Preview was stuck at its +/// default height), not below a minimum; the new height stays in the layout. +#[test] +fn the_preview_frame_divider_resizes_it() { + let (mut h, _, _) = harness(); + fn preview_size(w: &Workspace) -> Option { + fn rec(n: &Node) -> Option { + match n { + Node::Split { first, second, size, .. } => match first.as_ref() { + Node::Tabs { panels, .. } if panels.contains(&PanelKind::Preview) => Some(*size), + _ => rec(first).or_else(|| rec(second)), + }, + _ => None, + } } + rec(w.layout.root.as_ref()?) } let (preview, props) = (rect(&h, "panel.Preview"), rect(&h, "panel.Properties")); - let gap = rect(&h, "dock.gutter.bs0"); - assert!(gap.center().y > preview.max.y && gap.center().y < props.min.y, "the gap below Preview: {gap:?}"); + let gap = preview_divider(&h); drag(&mut h, gap.center(), gap.center() + egui::vec2(0.0, 150.0)); let (p2, q2) = (rect(&h, "panel.Preview"), rect(&h, "panel.Properties")); assert!((p2.height() - preview.height() - 150.0).abs() < 2.0, "Preview {} → {}", preview.height(), p2.height()); assert!((props.height() - q2.height() - 150.0).abs() < 2.0, "Properties {} → {}", props.height(), q2.height()); assert!((q2.max.y - props.max.y).abs() < 1.0, "the column stays filled"); - let saved = height(&h.state().ui.dock, PanelKind::Preview).flatten().expect("Preview's height is in the layout"); - assert!((saved - p2.height()).abs() < 2.0, "{saved} vs {}", p2.height()); - assert_eq!(height(&h.state().ui.dock, PanelKind::Properties), Some(None), "Properties still takes the rest"); - // Collapsing and expanding Preview keeps its height. - let tab = rect(&h, "panel.tab.Preview"); - click_n(&mut h, tab.center(), 1); - assert!(!h.state().ui.dock.is_visible(PanelKind::Preview)); - click_n(&mut h, tab.center(), 1); - assert!((rect(&h, "panel.Preview").height() - p2.height()).abs() < 1.0); - // Not below the minimum. - let gap = rect(&h, "dock.gutter.bs0"); - drag(&mut h, gap.center(), gap.center() - egui::vec2(0.0, 400.0)); + // The frame keeps a fixed height, 150 points more. + let Some(SplitSize::FixedFirst(size)) = preview_size(&h.state().ui.dock) else { panic!("{:?}", preview_size(&h.state().ui.dock)) }; + assert!((size - effectcraft_ui_egui::dock::PREVIEW_FRAME - 150.0).abs() < 2.0, "{size}"); + // Dragged up to Preview's top, it stops at its minimum. + let gap = preview_divider(&h); + let top = rect(&h, "panel.Preview").min.y; + drag(&mut h, gap.center(), pos2(gap.center().x, top)); assert!((rect(&h, "panel.Preview").height() - 40.0).abs() < 1.0, "{}", rect(&h, "panel.Preview").height()); } +/// Maximize acts on one frame: the Preview frame fills the dock area, Properties hides. +#[test] +fn maximizing_preview_maximizes_its_frame_alone() { + let (mut h, _, _) = harness(); + let preview = rect(&h, "panel.Preview"); + h.state_mut().ui.maximized = Some(PanelKind::Preview); + h.run_steps(3); + let big = rect(&h, "panel.Preview"); + assert!(big.height() > preview.height() + 300.0 && big.width() > preview.width() + 300.0, "{preview:?} → {big:?}"); + assert!(h.state().auto.find("panel.Properties").is_none(), "the Properties frame is not shown"); +} + /// Issue #45: the Project panel's details (name, size, duration) stay inside the panel with a /// margin, cut short with "…" when they don't fit; so does the hint shown with nothing selected. #[test] @@ -338,42 +372,97 @@ fn dragging_the_viewer_timeline_divider_far_up_does_not_crash() { h.run_steps(2); } -/// Issue #301: clicking anywhere on a stacked panel's header bar expands/collapses it, not only -/// its name; the panel menu button keeps its own click. +/// Issue #301: a stacked panel's header bar opens it with a click anywhere on it, and its −/+ +/// button at the bar's right end collapses and expands it. #[test] fn a_stacked_panels_whole_header_bar_toggles_it() { let (mut h, _, _) = harness(); + use effectcraft_ui_egui::dock; + let stack = dock::stack(&[(PanelKind::Preview, true, Some(46.0)), (PanelKind::Properties, true, None)]); + h.state_mut().ui.dock = dock::docked(dock::hsplit(SplitSize::FixedSecond(300.0), dock::tabs(&[PanelKind::Composition], 0), stack)); + h.run_steps(3); let open = |h: &Harness<'_, EffectcraftApp>| h.state().ui.dock.is_visible(PanelKind::Preview); assert!(open(&h)); - let bar = rect(&h, "panel.header.Preview"); - let tab = rect(&h, "panel.tab.Preview"); - assert!(bar.min.x >= tab.max.x - 1.0 && bar.width() > 40.0, "{bar:?} {tab:?}"); - click_n(&mut h, pos2(bar.max.x - 6.0, bar.center().y), 1); - assert!(!open(&h), "a click at the bar's right end collapses Preview"); - let bar = rect(&h, "panel.header.Preview"); - click_n(&mut h, bar.center(), 1); + let toggle = rect(&h, "panel.header.Preview"); + let bar = rect(&h, "panel.tab.Preview"); + assert!(toggle.max.x <= bar.max.x + 1.0 && toggle.min.x > bar.center().x, "{toggle:?} {bar:?}"); + click_n(&mut h, toggle.center(), 1); + assert!(!open(&h), "the button collapses Preview"); + let toggle = rect(&h, "panel.header.Preview"); + click_n(&mut h, toggle.center(), 1); assert!(open(&h), "and expands it again"); - let menu = rect(&h, "panel.menu.Preview"); - click_n(&mut h, menu.center(), 1); - assert!(open(&h), "the panel menu button doesn't toggle the panel"); + let toggle = rect(&h, "panel.header.Preview"); + click_n(&mut h, toggle.center(), 1); + assert!(!open(&h)); + click_n(&mut h, pos2(bar.min.x + bar.width() * 0.25, bar.center().y), 1); + assert!(open(&h), "a click on the bar away from the button opens it"); } -/// #302: a panel dropped onto a stacked panel becomes a tab in that panel's frame (it was -/// inserted as a stacked panel of its own below it); its tabs switch the frame's panel. +/// #302: a panel dropped onto the Properties frame becomes a tab in that frame; its tabs switch +/// the frame's panel, and the Preview frame above keeps showing. #[test] -fn a_tab_dropped_on_a_stacked_panel_joins_its_frame() { +fn a_tab_dropped_on_a_frame_joins_it() { let (mut h, _, _) = harness(); let dock = |h: &Harness<'_, EffectcraftApp>| h.state().ui.dock.clone(); let fx = rect(&h, "panel.tab.EffectControls"); let props = rect(&h, "panel.Properties"); drag(&mut h, fx.center(), props.center()); - assert_eq!(group_of(&dock(&h), PanelKind::Properties), Some(vec![PanelKind::Properties, PanelKind::EffectControls])); + let group = group_of(&dock(&h), PanelKind::Properties).unwrap(); + assert!(group.starts_with(&[PanelKind::Properties]) && group.contains(&PanelKind::EffectControls), "{group:?}"); assert!(dock(&h).is_visible(PanelKind::EffectControls) && !dock(&h).is_visible(PanelKind::Properties)); + assert!(dock(&h).is_visible(PanelKind::Preview)); // The frame's other tab shows Properties again, the frame stays open. let tab = rect(&h, "panel.tab.Properties"); click_n(&mut h, tab.center(), 1); assert!(dock(&h).is_visible(PanelKind::Properties) && !dock(&h).is_visible(PanelKind::EffectControls)); // The layout (saved workspaces) round-trips. let s = serde_json::to_string(&dock(&h)).unwrap(); - assert_eq!(serde_json::from_str::(&s).unwrap(), dock(&h)); + assert_eq!(serde_json::from_str::(&s).unwrap(), dock(&h)); +} + +/// The tabs of the group holding `p`, in order. +fn group_of(w: &Workspace, p: PanelKind) -> Option> { + Some(w.group_of(p)).filter(|g| !g.is_empty()) +} + +fn has(h: &Harness<'_, EffectcraftApp>, id: &str) -> bool { + h.state().auto.previous.iter().chain(h.state().auto.elements.iter()).any(|e| e.id == id) +} + +#[test] +fn open_comps_are_tabs_in_the_timeline_row_and_the_rest_are_in_its_overflow_menu() { + let mut s = Session::default(); + let names = ["Opening Titles", "Lower Third Left", "Lower Third Right", "Product Shot", "End Card Wide", "Logo Sting Short"]; + let comps: Vec = names + .iter() + .map(|name| s.execute("comp.new", json!({"name": name, "width": 320, "height": 180, "duration": 4})).unwrap()["comp"].as_u64().unwrap()) + .collect(); + s.state.open_comps = vec![ItemId(comps[0])]; + s.state.active_comp = Some(ItemId(comps[0])); + let mut h = Harness::builder().with_size(egui::vec2(1000.0, 800.0)).build_eframe(|_| EffectcraftApp::new(s)); + h.run_steps(3); + let alone = rect(&h, "panel.tab.RenderQueue"); + h.state_mut().session.state.open_comps = comps.iter().map(|c| ItemId(*c)).collect(); + h.run_steps(3); + // The panel tabs keep their width; the comp tabs follow them in the same row, in order. + let (tl, rq) = (rect(&h, "panel.tab.Timeline"), rect(&h, "panel.tab.RenderQueue")); + assert!((rq.width() - alone.width()).abs() < 0.5, "Render Queue {rq:?} was {alone:?}"); + let shown: Vec = comps.iter().copied().filter(|c| has(&h, &format!("panel.tab.Timeline.{c}"))).collect(); + assert!(shown.contains(&comps[0]) && shown.len() < comps.len(), "{shown:?}"); + let mut x = rq.max.x; + for c in &shown { + let tab = rect(&h, &format!("panel.tab.Timeline.{c}")); + assert!(tl.y_range().contains(tab.center().y) && tab.min.x >= x - 0.5, "comp {c} at {tab:?} after x {x}"); + x = tab.max.x; + } + // A comp with no room is in the » menu; picking it shows it, and its tab joins the row. + let hidden = comps.iter().copied().find(|c| !shown.contains(c)).unwrap(); + let more = rect(&h, "panel.tab.Timeline.more"); + assert!(more.min.x >= x - 0.5 && tl.y_range().contains(more.center().y), "{more:?}"); + click_n(&mut h, more.center(), 1); + let item = rect(&h, &format!("panel.tab.Timeline.more.{hidden}")); + click_n(&mut h, item.center(), 1); + assert_eq!(h.state().session.state.active_comp, Some(ItemId(hidden))); + assert_eq!(open_comps(&h), comps); + assert!(has(&h, &format!("panel.tab.Timeline.{hidden}"))); } diff --git a/crates/ui-egui/tests/it/ui_viewers.rs b/crates/ui-egui/tests/it/ui_viewers.rs index 0019cc9c8..833ab0a60 100644 --- a/crates/ui-egui/tests/it/ui_viewers.rs +++ b/crates/ui-egui/tests/it/ui_viewers.rs @@ -5,7 +5,8 @@ use effectcraft_engine::Session; use effectcraft_engine::project::ItemId; use effectcraft_ui_egui::EffectcraftApp; -use effectcraft_ui_egui::dock::{PanelKind, Zone}; +use effectcraft_ui_egui::dock::PanelKind; +use effectcraft_ui_egui::dock::WorkspaceExt as _; use effectcraft_ui_egui::panels::viewers; use egui::{Event, pos2}; use egui_kittest::Harness; @@ -67,12 +68,18 @@ fn new_viewers_lock_route_comps_and_activate_on_click() { h.run_steps(3); // View ▸ New Viewer: viewer 1 shows A too, viewer 0 (the Composition panel) is locked. invoke(&mut h, "view.newViewer", json!({})); - assert!(h.state().ui.dock.contains(PanelKind::Viewer(1))); + assert!(h.state().ui.dock.is_docked(PanelKind::Viewer(1))); assert!(viewers::locked(h.state(), 0) && !viewers::locked(h.state(), 1)); assert_eq!((h.state().ui.active_viewer, shows(&h, 0), shows(&h, 1)), (1, Some(a), Some(a))); // Side by side, so both draw. - assert!(h.state_mut().edit_layout(|l| l.dock(PanelKind::Viewer(1), PanelKind::Composition, Zone::Right))); - h.state_mut().ui.dock.activate(PanelKind::Composition); + h.state_mut() + .apply_dock(craft_ui::docking::Action::Move { + panel: PanelKind::Viewer(1), + anchor: PanelKind::Composition, + placement: craft_ui::docking::Placement::Split(craft_ui::docking::Zone::Right), + }) + .unwrap(); + h.state_mut().apply_dock(craft_ui::docking::Action::Activate { panel: PanelKind::Composition }).unwrap(); h.run_steps(3); // Opening B shows it in the active (unlocked) viewer; the locked one keeps A. invoke(&mut h, "comp.open", json!({"comp": b})); @@ -90,7 +97,7 @@ fn new_viewers_lock_route_comps_and_activate_on_click() { h.state_mut().ui.locked_tabs.insert(PanelKind::Viewer(1).id()); invoke(&mut h, "comp.open", json!({"comp": b})); assert_eq!(h.state().ui.active_viewer, 2); - assert!(h.state().ui.dock.contains(PanelKind::Viewer(2))); + assert!(h.state().ui.dock.is_docked(PanelKind::Viewer(2))); assert_eq!((shows(&h, 0), shows(&h, 1), shows(&h, 2)), (Some(a), Some(c), Some(b))); // Closing the active viewer forgets it; another open viewer takes over. h.state_mut().close_panel(PanelKind::Viewer(2)); @@ -145,8 +152,14 @@ fn viewers_snapshot() { let mut h = Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).build_eframe(|_| EffectcraftApp::new(s)); h.run_steps(3); invoke(&mut h, "view.newViewer", json!({})); - assert!(h.state_mut().edit_layout(|l| l.dock(PanelKind::Viewer(1), PanelKind::Composition, Zone::Right))); - h.state_mut().ui.dock.activate(PanelKind::Composition); + h.state_mut() + .apply_dock(craft_ui::docking::Action::Move { + panel: PanelKind::Viewer(1), + anchor: PanelKind::Composition, + placement: craft_ui::docking::Placement::Split(craft_ui::docking::Zone::Right), + }) + .unwrap(); + h.state_mut().apply_dock(craft_ui::docking::Action::Activate { panel: PanelKind::Composition }).unwrap(); invoke(&mut h, "comp.open", json!({"comp": other.0})); for _ in 0..300 { h.step(); diff --git a/crates/ui-egui/tests/it/ui_workspace_focus.rs b/crates/ui-egui/tests/it/ui_workspace_focus.rs index fbadb964d..9bd5374bd 100644 --- a/crates/ui-egui/tests/it/ui_workspace_focus.rs +++ b/crates/ui-egui/tests/it/ui_workspace_focus.rs @@ -5,27 +5,31 @@ use std::sync::Arc; use effectcraft_engine::Session; use effectcraft_engine::config::{ConfigStore, DirConfig, MemoryConfig}; use effectcraft_ui_egui::EffectcraftApp; -use effectcraft_ui_egui::dock::{DockNode, PanelKind, SplitSize}; +use effectcraft_ui_egui::dock::{self, Node, PanelKind, SplitSize}; use effectcraft_ui_egui::state::Tool; use egui::{Event, Id, Key, Modifiers, vec2}; use egui_kittest::Harness; use serde_json::json; +/// The egui id of panel `p`'s dock tab. +fn tab_id(p: PanelKind) -> Id { + craft_ui::docking::DockArea::::hit_id(effectcraft_ui_egui::dock_ui::area_id(), &craft_ui::docking::Hit::Tab(p)) +} + #[test] fn named_and_current_workspaces_survive_frontend_restart() { let store = Arc::new(MemoryConfig::default()); let mut app = EffectcraftApp::new(Session { config: Some(store.clone()), ..Default::default() }); - app.ui.dock = DockNode::Split { - vertical: false, - size: SplitSize::FixedA(345.0), - a: Box::new(DockNode::Tabs { panels: vec![PanelKind::Project], active: 0 }), - b: Box::new(DockNode::Tabs { panels: vec![PanelKind::Composition, PanelKind::Layer], active: 1 }), - }; + app.ui.dock = dock::docked(dock::hsplit( + SplitSize::FixedFirst(345.0), + dock::tabs(&[PanelKind::Project], 0), + dock::tabs(&[PanelKind::Composition, PanelKind::Layer], 1), + )); let ctx = egui::Context::default(); effectcraft_ui_egui::menus::invoke(&mut app, &ctx, "window.saveWorkspaceAs", json!({"name": "Restart layout"})).unwrap(); let saved = app.ui.dock.clone(); - if let DockNode::Split { size, .. } = &mut app.ui.dock { - *size = SplitSize::FixedA(390.0); + if let Some(Node::Split { size, .. }) = &mut app.ui.dock.layout.root { + *size = SplitSize::FixedFirst(390.0); } app.ui.focused = PanelKind::Layer; let current = app.ui.dock.clone(); @@ -100,15 +104,18 @@ fn unreadable_native_workspace_is_preserved_after_later_layout_changes() { #[test] fn legacy_named_workspaces_migrate_once_and_survive_actual_app_restart() { let store = Arc::new(MemoryConfig::default()); - let saved = effectcraft_ui_egui::dock::workspace("Minimal"); - store.write("workspaces.json", &json!({"workspaces":{"Legacy":saved},"floating":{}}).to_string()).unwrap(); + // An unversioned record from an earlier EffectCraft: its Minimal layout saved as "Legacy". + let legacy = r#"{"floating":{},"workspaces":{"Legacy":{"Split":{"a":{"Tabs":{"active":0,"panels":["Composition"]}},"b":{"Tabs":{"active":0,"panels":["Timeline"]}},"size":{"Ratio":0.6000000238418579},"vertical":true}}}}"#; + store.write("workspaces.json", legacy).unwrap(); + let saved = effectcraft_ui_egui::dock::Workspace::new(effectcraft_ui_egui::dock::workspace("Minimal")); let mut app = EffectcraftApp::new(Session { config: Some(store.clone()), ..Default::default() }); assert_eq!(app.ui.saved_workspaces.get("Legacy"), Some(&saved)); app.set_workspace("Legacy"); let ctx = egui::Context::default(); effectcraft_ui_egui::menus::invoke(&mut app, &ctx, "window.saveWorkspaceAs", json!({"name":"Migrated"})).unwrap(); let text = store.read("workspaces.json").unwrap(); - assert_eq!(serde_json::from_str::(&text).unwrap()["version"], 1); + assert_eq!(serde_json::from_str::(&text).unwrap()["version"], 2); + assert_eq!(store.read("workspaces.old.json").as_deref(), Some(legacy)); let restarted = EffectcraftApp::new(Session { config: Some(store), ..Default::default() }); assert_eq!(restarted.ui.saved_workspaces.get("Legacy"), Some(&saved)); assert_eq!(restarted.ui.saved_workspaces.get("Migrated"), Some(&saved)); @@ -166,19 +173,19 @@ fn tab_traversal_activates_an_inactive_dock_tab_without_editing_the_project() { app.ui.start_screen = false; app.ui.show_menu_bar = false; // Leave the inactive, layer-named tab visible instead of behind the overflow control. - if let DockNode::Split { a, .. } = &mut app.ui.dock - && let DockNode::Split { a, .. } = a.as_mut() - && let DockNode::Split { size, .. } = a.as_mut() + if let Some(Node::Split { first, .. }) = &mut app.ui.dock.layout.root + && let Node::Split { first, .. } = first.as_mut() + && let Node::Split { size, .. } = first.as_mut() { - *size = SplitSize::FixedA(420.0); + *size = SplitSize::FixedFirst(420.0); } let mut h = Harness::builder().with_size(vec2(1200.0, 760.0)).build_eframe(move |_| app); h.run_steps(3); assert!(h.state().auto.find("panel.tab.EffectControls").is_some(), "the inactive tab must be visible in this fixture"); let before = h.state().ui.dock.clone(); - let target = Id::unique(("tab", "aaa".to_string(), 1usize)); + let target = tab_id(PanelKind::EffectControls); let mut tabs = 0; - for _ in 0..80 { + for _ in 0..200 { key(&mut h, Key::Tab, Modifiers::NONE); tabs += 1; if h.ctx.memory(|m| m.focused()) == Some(target) { @@ -188,24 +195,26 @@ fn tab_traversal_activates_an_inactive_dock_tab_without_editing_the_project() { assert_eq!(h.ctx.memory(|m| m.focused()), Some(target)); println!("Tab presses from no focus to Effect Controls: {tabs}"); assert_eq!(h.state().ui.dock, before, "traversal alone must not activate a tab"); + // craft-ui outlines the keyboard-focused tab, inset 2 pt, in the dock's accent (EffectCraft's + // focus colour). + let response = h.ctx.read_response(target).unwrap(); + assert!( + h.output().shapes.iter().any(|shape| { + matches!(&shape.shape, egui::Shape::Rect(r) if r.rect == response.rect.shrink(2.0) && r.stroke.color == h.state().tokens.focus && r.stroke.width > 0.0) + }), + "the dock tab must visibly show keyboard focus" + ); key(&mut h, Key::Space, Modifiers::NONE); let mut activated = before; - assert!(activated.activate(PanelKind::EffectControls)); + activated.apply(craft_ui::docking::Action::Activate { panel: PanelKind::EffectControls }, dock::permissions).unwrap(); assert_eq!(h.state().ui.dock, activated); assert_eq!(h.state().ui.focused, PanelKind::EffectControls); assert!(!h.state().playback.playing); assert!(Arc::ptr_eq(&h.state().session.project, &project)); - let response = h.ctx.read_response(target).unwrap(); - assert!( - h.output().shapes.iter().any(|shape| { - matches!(&shape.shape, egui::Shape::Rect(r) if r.rect == response.rect.shrink(1.0) && r.stroke.color == h.state().tokens.text && r.stroke.width > 0.0) - }), - "the active dock tab must visibly retain keyboard focus" - ); let inspected = effectcraft_ui_egui::control::inspect(h.state(), &h.ctx); assert_eq!(inspected["keyboardFocus"]["automationId"], "panel.tab.EffectControls"); key(&mut h, Key::Tab, Modifiers::SHIFT); - assert_eq!(h.ctx.memory(|m| m.focused()), Some(Id::unique(("tab", "aaa".to_string(), 0usize)))); + assert_eq!(h.ctx.memory(|m| m.focused()), Some(tab_id(PanelKind::Project))); key(&mut h, Key::Enter, Modifiers::NONE); assert_eq!(h.state().ui.focused, PanelKind::Project); assert!(!h.state().playback.playing); @@ -284,8 +293,8 @@ fn control_root_divider_drag_after_toolbar_and_dock_tab_keyboard_activation() { d.ok("ui.click", json!({"id":"tools.Selection"}), true); // The toolbar can grow as upstream adds controls. Traverse to the actual response // identity rather than assuming a fixed number of focus stops. - let target = Id::unique(("tab", "aaa".to_string(), 1usize)); - for tabs in 1..=100 { + let target = tab_id(PanelKind::EffectControls); + for tabs in 1..=200 { d.ok("ui.key", json!({"key":"Tab"}), true); assert!(d.h.state().ui.mini_flowchart.is_none(), "dock-tab traversal must not open a foreground popup"); if d.h.ctx.memory(|memory| memory.focused()) == Some(target) { @@ -480,7 +489,7 @@ fn failed_save_or_delete_of_a_saved_workspace_keeps_the_file() { let saved = app.ui.dock.clone(); let before = store.read("workspaces.json").unwrap(); store.full.store(true, std::sync::atomic::Ordering::Relaxed); - app.ui.dock.close(PanelKind::Timeline); + app.close_panel(PanelKind::Timeline); let error = invoke(&mut app, "window.saveWorkspace", json!({})).unwrap_err(); assert!(error.contains("synthetic full disk") && error.contains("may be lost after a restart"), "{error}"); assert!(invoke(&mut app, "window.editWorkspaces", json!({"name": "Kept", "delete": true})).is_err()); diff --git a/docs/control-protocol.md b/docs/control-protocol.md index aa5b22f8b..6c7548835 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -186,20 +186,63 @@ including outside the layer's `[in, out)` range. Timing metadata carries outside `prop.get.time` is comp seconds. For these commands, `path` or `prop` identifies a property, not a group. Set a layer's offset with `layer.timing {layer, start}` (comp seconds). -Panel moves, tab ordering, edge splits and floating geometry use shared docking transactions. -`window.floatPanel` requires exactly four finite numbers when `rect` is supplied. Invalid -geometry or missing source/anchor panels leaves the layout unchanged. The persisted workspace -shape is unchanged: accordion open states and explicit heights, floating groups, and dynamic -viewer/ScriptUI identities remain app data. Pointer drops use the same shared placement rules -as commands, with floating groups resolved in their actual window stacking order. +Panels dock in craft-ui's shared docking (`craft_ui::docking`): split frames, tab groups, +stacked panels and floating windows. Every change, by pointer, menu or command, is one +transaction that checks the whole result; an invalid one returns an error and leaves the layout +unchanged. No move or float may leave the docked area empty; closing its last panel is allowed. +Panels name themselves by id (`"EffectControls"`), by title (`"Effect Controls"`) where a command +takes a name, or as `{"Viewer":42}` and `{"ScriptPanel":77}` for viewers and ScriptUI panels. -`window.dockAction` accepts `{action}` using the shared docking action's JSON form. It -covers tab moves and ordering, split and floating geometry, activation, and closing. -For example, `{"action":{"ResizeSplit":{"path":[],"size":{"FixedFirst":360}}}}` -resizes the root split; path entries use `false` for the first child and `true` for -the second. `{"action":{"MoveFloating":{"panel":"Info","rect":[45,65,420,320]}}}` -repositions and resizes the floating group containing Info. Invalid actions leave the -layout unchanged. Pointer gestures dispatch through this same catalog command. -EffectCraft also supports `SetStackOpen` and `ResizeStack`. Dynamic panel identities use -`{"Viewer":42}` or `{"ScriptPanel":77}` in the action. Closing runs the existing viewer -and ScriptUI lifecycle callbacks; opening uses the existing panel creation commands. +- `window.dockAction {action}` applies one craft-ui `Action` in its JSON form. For example, + `{"action":{"ResizeSplit":{"path":[],"size":{"FixedFirst":360}}}}` resizes the root split + (path entries are `false` for the first child and `true` for the second), and + `{"action":{"MoveFloating":{"panel":"Info","rect":[45,65,420,320]}}}` moves and resizes the + floating window holding Info. `Open` and `OpenAt` are refused: panels open through the panel + commands (`window.panel`, `ui.panel.show`), which run the viewer and ScriptUI lifecycles. + Closing runs them too. Pointer gestures dispatch through this command. +- craft-ui's commands: `window.panel.move`, `.float`, `.dock`, `.activate`, `.close`, + `.closeGroup`, `.closeOthers`, `.minimize`, `.iconic`, `.window` and `.layout`, with the params + of craft-ui's `DockCommand` (`docs/ui-docking.md` in craft-libs). `window.panel.` + (`window.panel.Align`) opens and shows that panel. `window.panel.activate` on a closed panel + reopens it where it was. +- `ui.dock {operation, panel, …}` or `ui.dock {action}`: craft-ui's `ui.dock` operations + (`open`, `close`, `activate`, `float {rect}`, `moveFloating {rect}`, + `move {target, zone?, before?}`, `setStackOpen {open}`, `resizeStack {height}`, + `resizeSplit {path, size}`; `rect` is `[x, y, width, height]`). It returns + `{"docking": workspace}`. `ui.dock.reset` returns the current workspace to its saved or + built-in layout and returns the same. +- `window.dockPanel {panel, anchor?, zone?, before?}` docks as `window.panel.dock`: `zone` is + `center`, `tab`, `left`, `right`, `top`, `bottom`, `above` or `below`; without an anchor a + side zone docks along that edge of the whole workspace. `window.floatPanel {panel, rect?}` + requires exactly four finite numbers when `rect` is given and otherwise floats a 420x320 + window in the middle of the app window. `window.closePanel {panel}` closes it. +- `window.panelWindow {panel, window?}` puts a panel in a floating window of its own with a + desktop place over the panel's place in the main window, and returns `{"window": bool}`. A + docked panel floats first. `window` false docks it again, as a tab of the first docked group; + without `window` it toggles. + +On desktop every floating window is an OS window of its own (craft-ui's `native-windows`), which +can go on another monitor; on Wayland, on the web and where egui embeds viewports, floating +windows stay in the main window. Keys pressed in a floating window that none of its widgets uses +run the main window's shortcuts, and files dropped on one import as on the main window. While a +modal dialog is open, floating windows take no input. + +The automation ids of the docking chrome are `panel.tab.`, `panel.drag.` (a +group's drag bar), `panel.tabs.more.`, `panel.menu.` (≡), `panel.header.` +(a stacked panel's open and close button), `panel.tab..lock` (viewer lock), +`panel.tab.Timeline.` and `panel.tab.Timeline.close` (the Timeline's comp tabs), +`panel.float..move`, `.close`, `.resize` and `.resize.` for floating window `n`, +`dock.gutter.` for dividers (`a`/`b` per split level; a stack's gap below entry `i` adds +`s`) and `dock.corner..` where two dividers meet. + +Saved workspaces (`workspaces.json`, version 2) hold craft-ui `Workspace`s: the layout, the +closed panels with where each goes back, the lock, and each floating window's desktop place. A +version 1 file (EffectCraft 0.10 and earlier) and the older unversioned record of +named workspaces load with every panel in place: the current layout, the named workspaces, +floating windows and their native window places. A column of stacked frames becomes tab groups +split top to bottom: each open frame keeps all its tabs and its height (as a fixed size), and a +closed frame's tabs join the open frame above it. A native window's place moves from the OS +window's outer position to its content's, by the main window's title bar, before the first save. +Panels that were closed stay closed and reopen at their default place. The first save writes version 2 and keeps +the earlier file as `workspaces.old.json`. A damaged, unknown or newer file loads as the default +layout and is left unchanged. diff --git a/docs/gaps.md b/docs/gaps.md index f8fcd64c2..3f59b1f99 100644 --- a/docs/gaps.md +++ b/docs/gaps.md @@ -76,7 +76,7 @@ are grouped by area; the issue tracker has the rest. | 17 | **Media Browser lists files import refuses** | `media_browser.rs` lists AVI; `media::is_importable` has none of them (Targa and Radiance HDR import since #745; DPX and Cineon since #756, log shown as stored: no Cineon Settings conversion yet; MXF OP1a / OP-Atom since #767; FilmCraft has no AVI demuxer); #431 and #324 closed | Confusing failures on common VFX formats | 15–30 h | G6 · [file-format-parity.md](file-format-parity.md) | | 18 | **Relative paths and relinking** | Projects store absolute footage paths; no relink when a project moves | Moving or sharing a project breaks it | 6–12 h | G4 · [file-format-parity.md](file-format-parity.md) | | 19 | **Plug-in ecosystem** | No After Effects SDK hosting (#600, #327 OpenFX, #334, #376 plug-in manager); our WebAssembly API has no third-party plug-ins | Many pro projects depend on Trapcode, Element, Saber… | 40–80 h for API growth; SDK hosting needs an owner decision | G8 · [scripting-parity.md](scripting-parity.md) | -| 20 | **Multi-monitor and video output** | #486: any panel can move into a native window of its own (panel menu ▸ Move Panel to New Window, `window.panelWindow`) and so onto another screen, restored with the workspace; still missing: dragging tabs between those windows, app shortcuts while one has the focus, named workspaces remembering them, Mercury Transmit to video hardware (we have a second preview window only) | Two-screen setups are standard for professionals | 10–20 h | G2 · [hardware-parity.md](hardware-parity.md) | +| 20 | **Multi-monitor and video output** | #486: on Windows, macOS and X11 every floating panel is an OS window of its own (Undock Panel, a drag out of the main window, panel menu ▸ Move Panel to New Window, `window.panelWindow`) and so can go onto another screen (on Wayland, the web and in embedded viewports floating panels stay in the app window, since Wayland reports no window positions); tabs and groups drag between windows, shortcuts work in them, and the current and named workspaces restore their places; still missing: Mercury Transmit to video hardware (we have a second preview window only) | Two-screen setups are standard for professionals | 10–20 h | G2 · [hardware-parity.md](hardware-parity.md) | | 21 | **Small 26.x features** | Proportional Scrubbing (26.2), pasting Illustrator's own clipboard data as shapes (26.3; SVG markup on the clipboard pastes as a shape layer, #738), variable-font filter (26.3), the rebuilt Effect Controls (26.5). Percentage guides (View ▸ Add Percentage Guide, Convert Guides to Percentage / Pixels) and effect colour labels (Effect Controls header bar and right-click Label menu, `effect.setLabel`) are in (#1095), built from the release notes' one-line descriptions and never compared with After Effects: the Timeline's effect rows wear the label as a colour bar on the left edge (#1509), but After Effects' exact UI there is unknown | Users of the current version expect them | 10–20 h left | — · [ui-parity.md](ui-parity.md) | | 22 | **Encoder efficiency** | HEVC / AV1 have no B-frames, multi-reference or SAO / CDEF; Opus no FEC / DTX; single-file intermediates are 8-bit uncompressed QuickTime only (#372 closed by #778: no 16-bpc, AVI or lossless-compressed codec); #325 render over existing file | Larger files than After Effects + Media Encoder | 20–40 h | G6 · [file-format-parity.md](file-format-parity.md) | | 23 | **Essential Graphics interchange** | Templates are `.ectemplate`, not `.mogrt`; #338 and #611 closed | Premiere editors can't use our templates | 15–30 h | — · [file-format-parity.md](file-format-parity.md) | diff --git a/docs/ui-parity.md b/docs/ui-parity.md index df4c5e0ea..d4473c266 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -16,7 +16,7 @@ feel and platform differences, and the 26.x interface changes are not in yet. | Area | Status | % | Evidence and gaps | |---|---|---:|---| | Menu bar | After Effects' menus, order, submenus and labels; native on macOS; keyboard-operable in-window bar | 95% | 587 entries in `crates/engine/src/menus.rs`; Adobe-service entries omitted by design; `ui_menus` tests (#279) | -| Panels and workspaces | Every After Effects panel; all standard workspaces; drag-to-dock, tabs, floating panels, maximise | 75% | `ui_tabs`, `ui_panels`; panels move into their own native windows on any screen (#486 open: no dragging tabs between those windows); #302, #301 and #320 (docking, stacked-panel headers, workspace persistence) are closed | +| Panels and workspaces | Every After Effects panel; all standard workspaces; drag-to-dock, tabs, floating panels, maximise | 75% | `ui_tabs`, `ui_panels`; on Windows, macOS and X11 floating panels are OS windows of their own on any screen (on Wayland, the web and in embedded viewports they stay in the app window), with tabs and groups dragging between windows and shortcuts working in them (#486); #302, #301 and #320 (docking, stacked-panel headers, workspace persistence) are closed | | Timeline | Switches, modes, parent & link, twirl-downs, reveal shortcuts (U, UU, P, S, R, T, A, E, M, F, Alt+Shift…), pick whips, graph editor, work area, markers | 75% | `ui_keyframes`, `ui_timeline_*`; expand precomps in place (#601); #456, #457, #569 and #355 (Graph Editor jitter and buttons, negative rotation, bulk keyframing) are closed; Proportional Scrubbing (26.2: Ctrl+Alt / Cmd+Opt scrub of hot text spreads the change over the selected layers by selection order, #770) matched for layers selected as a whole, not yet for individually selected properties; every layer has the Video switch, nulls, cameras and lights included (a hidden null, camera or light has no box or handles in the viewer and isn't picked there; other selected hidden layers keep their layer controls and paths, #1769); a row control (a switch, the label swatch, a Modes cell) clicked on one of several selected layers acts on the whole selection, with the layers the switch doesn't apply to left out (#1849); a shape group's inner Contents (After Effects' elided Vectors group) draws no row — the group's path, fill/stroke and Transform list directly under it | | Composition viewer | Selection, handles with direction-aware cursors, rulers, guides, grids, snapping, channels, exposure, region of interest, snapshots, 3D views, Spacebar hand | 70% | `ui_viewer`, `ui_viewers`; Cmd/Ctrl +/− doesn't zoom (#570); anchor point grab on Linux (#492); #352 (snapping) is closed; no 3D transform gizmos (#392, #347); percentage guides (26.5) exist as View ▸ Add Percentage Guide and Convert Guides to Percentage / Pixels (a guide stores a percent of the comp, so it follows comp-size changes; behaviour inferred from the release note, not compared with After Effects); Copy Frame to Clipboard (26.3) is in the Composition menu and the viewer's context menu | | Tools panel | All After Effects tools; long-press flyouts; Tool Creates Shape / Mask; Fill / Stroke options | 80% | #213, #227 fixed; #553 (pen and vertex tools on motion paths) is closed | @@ -41,9 +41,8 @@ cover shape paths and masks, corner-vertex dragging and undo, and layers without ## Estimate -**≈ 60–120 h**: the open interaction issues above (25–45 h, about 0.2–0.5 h each with a scripted -test), 3D gizmos 8–15 h, multi-monitor panels 10–20 h, the 26.x interface changes 10–20 h, an -accessibility pass 15–30 h. Checking feel against After Effects needs the owner's Mac with After +**≈ 60–110 h**: the open interaction issues above (25–45 h, about 0.2–0.5 h each with a scripted +test), 3D gizmos 8–15 h, the 26.x interface changes 10–20 h, an accessibility pass 15–30 h. Checking feel against After Effects needs the owner's Mac with After Effects running; most of the rest parallelises. ## Revision history diff --git a/packaging/linux/package.sh b/packaging/linux/package.sh index a67a00d4a..a1fc5008a 100755 --- a/packaging/linux/package.sh +++ b/packaging/linux/package.sh @@ -84,6 +84,11 @@ has() { case " $FORMATS " in *" $format "*) return 0 ;; *) return 1 ;; esac } +# Fails unless FILE ($2) has SHA-256 digest $1. +verify_sha256() { + printf '%s %s\n' "$1" "$2" | sha256sum -c - +} + # ---- .tar.gz ------------------------------------------------------------------------------------ if has tar; then mkdir -p "$WORK/tar" @@ -141,21 +146,21 @@ if has appimage; then download="$TOOL.download" curl --proto '=https' -fsSL -o "$download" \ "https://github.com/AppImage/appimagetool/releases/download/$APPIMAGETOOL_VERSION/appimagetool-$ARCH.AppImage" - printf '%s %s\n' "$APPIMAGETOOL_SHA256" "$download" | sha256sum -c - + verify_sha256 "$APPIMAGETOOL_SHA256" "$download" chmod 755 "$download" mv "$download" "$TOOL" fi - printf '%s %s\n' "$APPIMAGETOOL_SHA256" "$TOOL" | sha256sum -c - + verify_sha256 "$APPIMAGETOOL_SHA256" "$TOOL" fi RUNTIME="$CARGO_TARGET_DIR/appimage-runtime-$APPIMAGE_RUNTIME_VERSION-$ARCH" if [[ ! -f "$RUNTIME" ]]; then download="$RUNTIME.download" curl --proto '=https' -fsSL -o "$download" \ "https://github.com/AppImage/type2-runtime/releases/download/$APPIMAGE_RUNTIME_VERSION/runtime-$ARCH" - printf '%s %s\n' "$APPIMAGE_RUNTIME_SHA256" "$download" | sha256sum -c - + verify_sha256 "$APPIMAGE_RUNTIME_SHA256" "$download" mv "$download" "$RUNTIME" fi - printf '%s %s\n' "$APPIMAGE_RUNTIME_SHA256" "$RUNTIME" | sha256sum -c - + verify_sha256 "$APPIMAGE_RUNTIME_SHA256" "$RUNTIME" # Absolute, because appimagetool runs in $DIST below (CARGO_TARGET_DIR or APPIMAGETOOL may be # relative). OUT="$(cd "$DIST" && pwd)/$BASENAME.AppImage" diff --git a/xtask/src/main.rs b/xtask/src/main.rs index e4ddaef77..da8026d78 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -176,7 +176,7 @@ fn repo_files() -> Result, String> { } fn is_asset(path: &str) -> bool { - std::path::Path::new(path).extension().and_then(|e| e.to_str()).is_some_and(|e| ASSET_EXT.contains(&e.to_ascii_lowercase().as_str())) + std::path::Path::new(path).extension().and_then(std::ffi::OsStr::to_str).is_some_and(|e| ASSET_EXT.contains(&e.to_ascii_lowercase().as_str())) } fn assets() -> Result<(), String> { @@ -384,7 +384,7 @@ fn serve_dir(dir: &std::path::Path, port: u16) -> Result<(), String> { Ok(b) => ("200 OK", b), Err(_) => ("404 Not Found", b"not found".to_vec()), }; - let mime = match file.extension().and_then(|e| e.to_str()).unwrap_or("") { + let mime = match file.extension().and_then(std::ffi::OsStr::to_str).unwrap_or("") { "html" => "text/html; charset=utf-8", "js" => "text/javascript", "wasm" => "application/wasm", diff --git a/xtask/src/pdf_deps.rs b/xtask/src/pdf_deps.rs index d0efd830c..c26876897 100644 --- a/xtask/src/pdf_deps.rs +++ b/xtask/src/pdf_deps.rs @@ -5,7 +5,7 @@ use std::process::Command; use serde_json::Value; -const REV: &str = "9f75d3dc19b4b514c4f3d4847ed1ec1b0e86b4ef"; +const REV: &str = "512b54355cd1418f4e8c56a3fbd7483c3c274bf3"; const PACKAGES: &[(&str, &str)] = &[("craft-pdf", "0.1.0"), ("hayro-syntax", "0.7.2"), ("hayro-jbig2", "0.3.0")]; pub fn run(root: &Path) -> Result<(), String> {