diff --git a/Cargo.lock b/Cargo.lock index 2903e7010..f9557dd7d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -189,6 +189,22 @@ dependencies = [ "libc", ] +[[package]] +name = "annotate-snippets" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "710e8eae58854cdc1790fcb56cca04d712a17be849eeb81da2a724bf4bae2bc4" +dependencies = [ + "anstyle", + "unicode-width", +] + +[[package]] +name = "anstyle" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000" + [[package]] name = "anyhow" version = "1.0.104" @@ -220,7 +236,7 @@ dependencies = [ "objc2-foundation 0.3.2", "parking_lot", "percent-encoding", - "windows-sys 0.61.2", + "windows-sys 0.52.0", "wl-clipboard-rs", "x11rb", ] @@ -236,6 +252,9 @@ name = "arrayvec" version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3fb67a6e08acf24fdeccbac2cb6ac4305825bd1f117462e0e6f2f193345ad56" +dependencies = [ + "serde", +] [[package]] name = "as-raw-xcb-connection" @@ -303,7 +322,7 @@ dependencies = [ "futures-lite", "parking", "polling", - "rustix 1.1.5", + "rustix 1.1.6", "slab", "windows-sys 0.61.2", ] @@ -334,7 +353,7 @@ dependencies = [ "cfg-if", "event-listener", "futures-lite", - "rustix 1.1.5", + "rustix 1.1.6", ] [[package]] @@ -360,7 +379,7 @@ dependencies = [ "cfg-if", "futures-core", "futures-io", - "rustix 1.1.5", + "rustix 1.1.6", "signal-hook-registry", "slab", "windows-sys 0.61.2", @@ -474,6 +493,25 @@ version = "1.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2af50177e190e07a26ab74f8b1efbfe2ef87da2116221318cb1c2e82baf7de06" +[[package]] +name = "bindgen" +version = "0.72.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "993776b509cfb49c750f11b8f07a46fa23e0a1386ffc01fb1e7d343efc387895" +dependencies = [ + "annotate-snippets", + "bitflags 2.13.2", + "cexpr", + "clang-sys", + "itertools 0.13.0", + "proc-macro2", + "quote", + "regex", + "rustc-hash 2.1.3", + "shlex 1.3.0", + "syn 2.0.119", +] + [[package]] name = "bit-set" version = "0.8.0" @@ -516,6 +554,12 @@ version = "2.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" +[[package]] +name = "block" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" + [[package]] name = "block-buffer" version = "0.10.4" @@ -603,6 +647,16 @@ version = "1.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04" +[[package]] +name = "calendrical_calculations" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5abbd6eeda6885048d357edc66748eea6e0268e3dd11f326fff5bd248d779c26" +dependencies = [ + "core_maths", + "displaydoc", +] + [[package]] name = "calloop" version = "0.13.0" @@ -625,7 +679,7 @@ checksum = "43b32313e937c8721c9d17ee9bf60699a6402b4b7c2cb6ac1bee0ffcaa4b4e5e" dependencies = [ "bitflags 2.13.2", "polling", - "rustix 1.1.5", + "rustix 1.1.6", "tracing", ] @@ -648,7 +702,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "138efcf0940a02ebf0cc8d1eff41a1682a46b431630f4c52450d6265876021fa" dependencies = [ "calloop 0.14.5", - "rustix 1.1.5", + "rustix 1.1.6", "wayland-backend", "wayland-client", ] @@ -662,7 +716,26 @@ dependencies = [ "find-msvc-tools", "jobserver", "libc", - "shlex", + "shlex 2.0.1", +] + +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom 7.1.3", +] + +[[package]] +name = "cfg-expr" +version = "0.20.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edd44d82755fb9210fb10d9daf8dd7e522da0efe1d5f263cffc5db07725663ff" +dependencies = [ + "smallvec", + "target-lexicon", ] [[package]] @@ -721,6 +794,17 @@ dependencies = [ "inout", ] +[[package]] +name = "clang-sys" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "157a8ba7b480713b56f4c09fd13fc3e0a22a5dfab8097ba61cbc5feef950788a" +dependencies = [ + "glob", + "libc", + "libloading", +] + [[package]] name = "clipboard-win" version = "5.4.1" @@ -839,6 +923,12 @@ version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be95d4a884358a21a199689323c29e9256b4a1b315e22f183d155422041d3a9a" +[[package]] +name = "cookie-factory" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9885fa71e26b8ab7855e2ec7cae6e9b380edff76cd052e07c683a0319d51b3a2" + [[package]] name = "core-foundation" version = "0.9.4" @@ -889,12 +979,34 @@ dependencies = [ "libc", ] +[[package]] +name = "core-graphics2" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b65858d95344d2711161cd92196732f67d6c5fea238cf12f994584828731a5c" +dependencies = [ + "bitflags 2.13.2", + "block", + "cfg-if", + "core-foundation 0.10.1", + "libc", +] + [[package]] name = "core_detect" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f8f80099a98041a3d1622845c271458a2d73e688351bf3cb999266764b81d48" +[[package]] +name = "core_maths" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77745e017f5edba1a9c1d854f6f3a52dac8a12dd5af5d2f54aecf61e43d80d30" +dependencies = [ + "libm", +] + [[package]] name = "cpubits" version = "0.1.1" @@ -920,56 +1032,129 @@ dependencies = [ ] [[package]] -name = "craft-cfb" +name = "craft-atomic" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=3b8e426a260695af840a2cd79a064d40778f939e#3b8e426a260695af840a2cd79a064d40778f939e" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" +dependencies = [ + "rustix 1.1.6", +] + +[[package]] +name = "craft-behavior" +version = "0.1.0" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" +dependencies = [ + "accesskit", + "bitflags 2.13.2", + "craft-host", + "craft-keymap", + "craft-theme", + "craft-tracked", + "craft-ui-macros", + "emath", + "kurbo", + "serde", + "smallvec", +] [[package]] name = "craft-cfb" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=e98299546f5c5c3c22388d16507f8b5e61a5f280#e98299546f5c5c3c22388d16507f8b5e61a5f280" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" + +[[package]] +name = "craft-cloud-ui" +version = "0.1.0" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" +dependencies = [ + "egui", +] + +[[package]] +name = "craft-codepage" +version = "0.1.0" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" [[package]] name = "craft-csv" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=e98299546f5c5c3c22388d16507f8b5e61a5f280#e98299546f5c5c3c22388d16507f8b5e61a5f280" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" dependencies = [ "thiserror 2.0.21", ] +[[package]] +name = "craft-docpath" +version = "0.1.0" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" +dependencies = [ + "serde", +] + [[package]] name = "craft-drawingml" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a20dfd1623709b0bd9830106d3a92a1a443902e3#a20dfd1623709b0bd9830106d3a92a1a443902e3" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" dependencies = [ "chrono", - "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=a20dfd1623709b0bd9830106d3a92a1a443902e3)", + "craft-xml", "kurbo", "log", "serde", ] +[[package]] +name = "craft-font-catalog" +version = "0.1.0" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" +dependencies = [ + "harfrust 0.13.3", + "kurbo", + "skrifa 0.47.0", + "thiserror 2.0.21", + "unicode-bidi", + "unicode-segmentation", + "windows-registry", +] + [[package]] name = "craft-fonts-build" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=aa84415bae3b765fef6b7ef42404f66ad1cff9d9#aa84415bae3b765fef6b7ef42404f66ad1cff9d9" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" [[package]] name = "craft-gridcraft-format" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=9a6d894200221fcfedc274870c30394d404f859d#9a6d894200221fcfedc274870c30394d404f859d" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" dependencies = [ "serde", "serde_json", "thiserror 2.0.21", ] +[[package]] +name = "craft-host" +version = "0.1.0" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" +dependencies = [ + "bitflags 2.13.2", + "craft-i18n", + "egui", + "serde", + "toml", + "web-time", +] + [[package]] name = "craft-i18n" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=aa84415bae3b765fef6b7ef42404f66ad1cff9d9#aa84415bae3b765fef6b7ef42404f66ad1cff9d9" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" dependencies = [ + "chrono", "fixed_decimal", + "icu_calendar", + "icu_collator", + "icu_datetime", "icu_decimal", "icu_locale_core", "icu_locale_fallback", @@ -979,6 +1164,7 @@ dependencies = [ "icu_provider", "icu_provider_adapters", "icu_provider_blob", + "icu_time", "log", "objc2-foundation 0.3.2", "sys-locale", @@ -987,19 +1173,35 @@ dependencies = [ "writeable", ] +[[package]] +name = "craft-keymap" +version = "0.1.0" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" +dependencies = [ + "craft-host", + "craft-i18n", + "craft-tracked", + "craft-ui-macros", + "craft-xml", + "egui", + "serde", + "serde_json", +] + [[package]] name = "craft-math" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=010702ee9b030844c852939095b1da0d0656a890#010702ee9b030844c852939095b1da0d0656a890" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" dependencies = [ - "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=010702ee9b030844c852939095b1da0d0656a890)", + "craft-xml", + "roxmltree", "serde", ] [[package]] name = "craft-mcp-server" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=08da5e1486ee640de1d2cccd8fe8dd32b1d3b62c#08da5e1486ee640de1d2cccd8fe8dd32b1d3b62c" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" dependencies = [ "serde_json", ] @@ -1007,12 +1209,12 @@ dependencies = [ [[package]] name = "craft-odf" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=010702ee9b030844c852939095b1da0d0656a890#010702ee9b030844c852939095b1da0d0656a890" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" dependencies = [ "aes", "base64 0.23.1", - "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=010702ee9b030844c852939095b1da0d0656a890)", - "craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=010702ee9b030844c852939095b1da0d0656a890)", + "craft-xml", + "craft-zip", "flate2", "getrandom 0.3.4", "hmac", @@ -1025,23 +1227,23 @@ dependencies = [ [[package]] name = "craft-ods" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=010702ee9b030844c852939095b1da0d0656a890#010702ee9b030844c852939095b1da0d0656a890" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" dependencies = [ "craft-odf", - "craft-sheet 0.1.0 (git+https://github.com/storytold/craft-libs?rev=010702ee9b030844c852939095b1da0d0656a890)", - "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=010702ee9b030844c852939095b1da0d0656a890)", + "craft-sheet", + "craft-xml", "thiserror 2.0.21", ] [[package]] name = "craft-offcrypto" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=e98299546f5c5c3c22388d16507f8b5e61a5f280#e98299546f5c5c3c22388d16507f8b5e61a5f280" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" dependencies = [ "aes", "base64 0.23.1", - "craft-cfb 0.1.0 (git+https://github.com/storytold/craft-libs?rev=e98299546f5c5c3c22388d16507f8b5e61a5f280)", - "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=e98299546f5c5c3c22388d16507f8b5e61a5f280)", + "craft-cfb", + "craft-xml", "getrandom 0.3.4", "hmac", "sha1 0.11.0", @@ -1053,10 +1255,10 @@ dependencies = [ [[package]] name = "craft-opc" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a20dfd1623709b0bd9830106d3a92a1a443902e3#a20dfd1623709b0bd9830106d3a92a1a443902e3" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" dependencies = [ - "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=a20dfd1623709b0bd9830106d3a92a1a443902e3)", - "craft-zip 0.1.0 (git+https://github.com/storytold/craft-libs?rev=a20dfd1623709b0bd9830106d3a92a1a443902e3)", + "craft-xml", + "craft-zip", "log", "thiserror 2.0.21", ] @@ -1064,41 +1266,104 @@ dependencies = [ [[package]] name = "craft-pdf" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=ff142b3ad58aa7306676749428f4f2f9b277b5dd#ff142b3ad58aa7306676749428f4f2f9b277b5dd" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" +dependencies = [ + "serde", +] + +[[package]] +name = "craft-platform" +version = "0.1.0" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" +dependencies = [ + "async-channel", + "async-io", + "async-process", + "core-graphics2", + "craft-atomic", + "craft-docpath", + "craft-host", + "craft-i18n", + "craft-theme", + "futures-lite", + "js-sys", + "log", + "objc2-app-kit 0.3.2", + "rfd", + "serde", + "serde_json", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "web-time", + "windows", + "x11rb", + "xcap", + "zbus", +] [[package]] name = "craft-print" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=aa84415bae3b765fef6b7ef42404f66ad1cff9d9#aa84415bae3b765fef6b7ef42404f66ad1cff9d9" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" dependencies = [ + "craft-behavior", + "craft-host", + "craft-theme", + "craft-ui", "craft-winprint-gdi", + "egui", + "js-sys", "log", "miniz_oxide 0.9.1", "roxmltree", + "serde", + "serde_json", "tempfile", + "wasm-bindgen", + "web-sys", "winprint", "winsafe", ] [[package]] -name = "craft-sheet" +name = "craft-quit" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=010702ee9b030844c852939095b1da0d0656a890#010702ee9b030844c852939095b1da0d0656a890" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" +dependencies = [ + "dispatch2", + "objc2 0.6.5", + "objc2-app-kit 0.3.2", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "craft-settings" +version = "0.1.0" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" +dependencies = [ + "craft-atomic", + "craft-host", + "dirs", + "log", + "serde", + "serde_json", + "toml", + "toml_edit", + "web-sys", + "web-time", +] [[package]] name = "craft-sheet" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=3b8e426a260695af840a2cd79a064d40778f939e#3b8e426a260695af840a2cd79a064d40778f939e" - -[[package]] -name = "craft-sheet" -version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a20dfd1623709b0bd9830106d3a92a1a443902e3#a20dfd1623709b0bd9830106d3a92a1a443902e3" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" [[package]] name = "craft-stream-codecs" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=f7e0d7fd5577e102b4634bcbe062e649eb68165f#f7e0d7fd5577e102b4634bcbe062e649eb68165f" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" dependencies = [ "fax", "hayro-ccitt", @@ -1106,40 +1371,216 @@ dependencies = [ "thiserror 2.0.21", ] +[[package]] +name = "craft-svg" +version = "0.1.0" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" +dependencies = [ + "craft-xml", + "flate2", + "kurbo", + "quick-xml 0.41.0", + "resvg", + "roxmltree", + "thiserror 2.0.21", + "usvg", + "vectorcraft-geom", + "vectorcraft-pathops", +] + +[[package]] +name = "craft-theme" +version = "0.1.0" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" +dependencies = [ + "bitflags 2.13.2", + "craft-tracked", + "craft-ui-macros", + "ecolor", + "log", + "serde", + "serde_json", + "smallvec", +] + +[[package]] +name = "craft-tracked" +version = "0.1.0" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" + [[package]] name = "craft-ui" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=aa84415bae3b765fef6b7ef42404f66ad1cff9d9#aa84415bae3b765fef6b7ef42404f66ad1cff9d9" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" dependencies = [ - "craft-fonts-build", + "craft-cloud-ui", + "craft-ui-canvas", + "craft-ui-contract", + "craft-ui-panels", + "craft-ui-patterns", + "craft-ui-shell", + "craft-ui-widgets", +] + +[[package]] +name = "craft-ui-canvas" +version = "0.1.0" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" +dependencies = [ + "craft-behavior", "craft-i18n", + "craft-keymap", + "craft-theme", + "craft-ui-macros", + "craft-ui-panels", "egui", - "epaint", - "js-sys", + "serde", + "serde_json", +] + +[[package]] +name = "craft-ui-contract" +version = "0.1.0" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" +dependencies = [ + "accesskit", + "craft-behavior", + "craft-codepage", + "craft-font-catalog", + "craft-fonts-build", + "craft-host", + "craft-i18n", + "craft-keymap", + "craft-platform", + "craft-quit", + "craft-settings", + "craft-svg", + "craft-theme", + "craft-tracked", + "craft-ui-macros", + "craft-window", + "egui", + "epaint_default_fonts", + "flate2", + "inventory", "log", - "objc2 0.6.5", - "objc2-app-kit 0.3.2", - "objc2-foundation 0.3.2", - "skrifa", - "wasm-bindgen", + "scoped-tls", + "serde", + "serde_json", + "siphasher", + "skrifa 0.44.0", + "smallvec", + "toml", + "typeid", "wasm-bindgen-futures", - "web-sys", + "web-time", +] + +[[package]] +name = "craft-ui-macros" +version = "0.1.0" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "craft-ui-panels" +version = "0.1.0" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" +dependencies = [ + "craft-behavior", + "craft-host", + "craft-i18n", + "craft-keymap", + "craft-quit", + "craft-theme", + "craft-ui-macros", + "craft-ui-widgets", + "egui", + "serde", + "serde_json", +] + +[[package]] +name = "craft-ui-patterns" +version = "0.1.0" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" +dependencies = [ + "craft-behavior", + "craft-host", + "craft-i18n", + "craft-keymap", + "craft-pdf", + "craft-theme", + "craft-ui-macros", + "craft-ui-panels", + "egui", + "serde", + "serde_json", + "toml", + "toml_edit", + "zeroize", +] + +[[package]] +name = "craft-ui-shell" +version = "0.1.0" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" +dependencies = [ + "craft-behavior", + "craft-host", + "craft-i18n", + "craft-platform", + "craft-svg", + "craft-theme", + "craft-ui-macros", + "craft-ui-panels", + "craft-window", + "egui", + "raw-window-handle", + "serde", + "web-time", +] + +[[package]] +name = "craft-ui-widgets" +version = "0.1.0" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" +dependencies = [ + "craft-behavior", + "craft-host", + "craft-i18n", + "craft-keymap", + "craft-svg", + "craft-theme", + "craft-ui-contract", + "craft-ui-macros", + "egui", + "log", + "serde", + "smallvec", ] [[package]] name = "craft-update" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=e98299546f5c5c3c22388d16507f8b5e61a5f280#e98299546f5c5c3c22388d16507f8b5e61a5f280" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" dependencies = [ "chrono", + "craft-host", + "craft-theme", + "craft-ui", "dunce", "egui", "flate2", - "getrandom 0.3.4", "image", "log", "plist", - "rustix 1.1.5", + "rustix 1.1.6", "semver", "serde", "serde_json", @@ -1156,7 +1597,7 @@ dependencies = [ [[package]] name = "craft-web-api" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=aa84415bae3b765fef6b7ef42404f66ad1cff9d9#aa84415bae3b765fef6b7ef42404f66ad1cff9d9" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" dependencies = [ "js-sys", "serde_json", @@ -1167,21 +1608,43 @@ dependencies = [ [[package]] name = "craft-web-host" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=aa84415bae3b765fef6b7ef42404f66ad1cff9d9#aa84415bae3b765fef6b7ef42404f66ad1cff9d9" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" dependencies = [ + "craft-host", + "craft-platform", "wasm-bindgen", + "wasm-bindgen-futures", "web-sys", ] +[[package]] +name = "craft-win32" +version = "0.1.0" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" +dependencies = [ + "winsafe", +] + [[package]] name = "craft-window" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=e98299546f5c5c3c22388d16507f8b5e61a5f280#e98299546f5c5c3c22388d16507f8b5e61a5f280" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" dependencies = [ + "craft-atomic", + "craft-behavior", + "craft-host", + "craft-settings", + "craft-win32", "egui", + "muda", "objc2 0.6.5", "objc2-app-kit 0.3.2", + "objc2-foundation 0.3.2", + "raw-window-handle", + "serde", + "serde_json", "wayland-client", + "winsafe", ] [[package]] @@ -1195,10 +1658,10 @@ dependencies = [ [[package]] name = "craft-xls" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=3b8e426a260695af840a2cd79a064d40778f939e#3b8e426a260695af840a2cd79a064d40778f939e" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" dependencies = [ - "craft-cfb 0.1.0 (git+https://github.com/storytold/craft-libs?rev=3b8e426a260695af840a2cd79a064d40778f939e)", - "craft-sheet 0.1.0 (git+https://github.com/storytold/craft-libs?rev=3b8e426a260695af840a2cd79a064d40778f939e)", + "craft-cfb", + "craft-sheet", "md-5", "miniz_oxide 0.9.1", "sha1 0.10.7", @@ -1208,58 +1671,29 @@ dependencies = [ [[package]] name = "craft-xlsx" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a20dfd1623709b0bd9830106d3a92a1a443902e3#a20dfd1623709b0bd9830106d3a92a1a443902e3" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" dependencies = [ "craft-drawingml", "craft-opc", - "craft-sheet 0.1.0 (git+https://github.com/storytold/craft-libs?rev=a20dfd1623709b0bd9830106d3a92a1a443902e3)", - "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=a20dfd1623709b0bd9830106d3a92a1a443902e3)", + "craft-sheet", + "craft-xml", "thiserror 2.0.21", ] [[package]] name = "craft-xml" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=010702ee9b030844c852939095b1da0d0656a890#010702ee9b030844c852939095b1da0d0656a890" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" dependencies = [ "quick-xml 0.41.0", "serde", "thiserror 2.0.21", ] -[[package]] -name = "craft-xml" -version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a20dfd1623709b0bd9830106d3a92a1a443902e3#a20dfd1623709b0bd9830106d3a92a1a443902e3" -dependencies = [ - "quick-xml 0.41.0", - "serde", - "thiserror 2.0.21", -] - -[[package]] -name = "craft-xml" -version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=e98299546f5c5c3c22388d16507f8b5e61a5f280#e98299546f5c5c3c22388d16507f8b5e61a5f280" -dependencies = [ - "quick-xml 0.41.0", - "thiserror 2.0.21", -] - [[package]] name = "craft-zip" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=010702ee9b030844c852939095b1da0d0656a890#010702ee9b030844c852939095b1da0d0656a890" -dependencies = [ - "flate2", - "thiserror 2.0.21", - "zip 9.1.0", -] - -[[package]] -name = "craft-zip" -version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=a20dfd1623709b0bd9830106d3a92a1a443902e3#a20dfd1623709b0bd9830106d3a92a1a443902e3" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" dependencies = [ "flate2", "thiserror 2.0.21", @@ -1361,6 +1795,12 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f27ae1dd37df86211c42e150270f82743308803d90a6f6e6651cd730d5e1732f" +[[package]] +name = "data-url" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be1e0bca6c3637f992fc1cc7cbc52a78c1ef6db076dbf1059c4323d6a2048376" + [[package]] name = "der" version = "0.7.10" @@ -1437,6 +1877,27 @@ dependencies = [ "ctutils", ] +[[package]] +name = "dirs" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d57d423b3c82e89b9a24ca3091fee61f456a26edbd28d26c65906f4bc1dcd8f" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e01a3366d27ee9890022452ee61b2b63a67e6f13f58900b651ff5665f0bb1fab" +dependencies = [ + "libc", + "option-ext", + "redox_users", + "windows-sys 0.59.0", +] + [[package]] name = "dispatch" version = "0.2.0" @@ -1496,6 +1957,61 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8b14ccef22fc6f5a8f4d7d768562a182c04ce9a3b3157b91390b52ddfdf1a76" +[[package]] +name = "drm" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80bc8c5c6c2941f70a55c15f8d9f00f9710ebda3ffda98075f996a0e6c92756f" +dependencies = [ + "bitflags 2.13.2", + "bytemuck", + "drm-ffi", + "drm-fourcc", + "libc", + "rustix 0.38.44", +] + +[[package]] +name = "drm" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a41816e58f47f49acfd956651055ddcf137c4882c2098c30c448817af21183a" +dependencies = [ + "bitflags 2.13.2", + "bytemuck", + "bytemuck_derive", + "drm-ffi", + "drm-fourcc", + "libc", + "rustix 1.1.6", +] + +[[package]] +name = "drm-ffi" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51a91c9b32ac4e8105dec255e849e0d66e27d7c34d184364fb93e469db08f690" +dependencies = [ + "drm-sys", + "rustix 1.1.6", +] + +[[package]] +name = "drm-fourcc" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0aafbcdb8afc29c1a7ee5fbe53b5d62f4565b35a042a662ca9fecd0b54dae6f4" + +[[package]] +name = "drm-sys" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc8e1361066d91f5ffccff060a3c3be9c3ecde15be2959c1937595f7a82a9f8" +dependencies = [ + "libc", + "linux-raw-sys 0.9.4", +] + [[package]] name = "dunce" version = "1.0.5" @@ -1505,7 +2021,7 @@ checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" [[package]] name = "ecolor" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=6d518fc799681571963842f95b55a6b68431b15a#6d518fc799681571963842f95b55a6b68431b15a" +source = "git+https://github.com/storytold/egui.git?rev=f5025284445ea19c35f746d96fc0b75468b3f560#f5025284445ea19c35f746d96fc0b75468b3f560" dependencies = [ "bytemuck", "emath", @@ -1514,7 +2030,7 @@ dependencies = [ [[package]] name = "eframe" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=6d518fc799681571963842f95b55a6b68431b15a#6d518fc799681571963842f95b55a6b68431b15a" +source = "git+https://github.com/storytold/egui.git?rev=f5025284445ea19c35f746d96fc0b75468b3f560#f5025284445ea19c35f746d96fc0b75468b3f560" dependencies = [ "ahash", "bytemuck", @@ -1549,14 +2065,14 @@ dependencies = [ [[package]] name = "egui" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=6d518fc799681571963842f95b55a6b68431b15a#6d518fc799681571963842f95b55a6b68431b15a" +source = "git+https://github.com/storytold/egui.git?rev=f5025284445ea19c35f746d96fc0b75468b3f560#f5025284445ea19c35f746d96fc0b75468b3f560" dependencies = [ "accesskit", "ahash", "bitflags 2.13.2", "emath", "epaint", - "itertools", + "itertools 0.15.0", "log", "nohash-hasher", "profiling", @@ -1568,7 +2084,7 @@ dependencies = [ [[package]] name = "egui-wgpu" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=6d518fc799681571963842f95b55a6b68431b15a#6d518fc799681571963842f95b55a6b68431b15a" +source = "git+https://github.com/storytold/egui.git?rev=f5025284445ea19c35f746d96fc0b75468b3f560#f5025284445ea19c35f746d96fc0b75468b3f560" dependencies = [ "ahash", "bytemuck", @@ -1587,7 +2103,7 @@ dependencies = [ [[package]] name = "egui-winit" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=6d518fc799681571963842f95b55a6b68431b15a#6d518fc799681571963842f95b55a6b68431b15a" +source = "git+https://github.com/storytold/egui.git?rev=f5025284445ea19c35f746d96fc0b75468b3f560#f5025284445ea19c35f746d96fc0b75468b3f560" dependencies = [ "accesskit_winit", "arboard", @@ -1612,12 +2128,12 @@ dependencies = [ [[package]] name = "egui_extras" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=6d518fc799681571963842f95b55a6b68431b15a#6d518fc799681571963842f95b55a6b68431b15a" +source = "git+https://github.com/storytold/egui.git?rev=f5025284445ea19c35f746d96fc0b75468b3f560#f5025284445ea19c35f746d96fc0b75468b3f560" dependencies = [ "ahash", "egui", "enum-map", - "itertools", + "itertools 0.15.0", "log", "profiling", ] @@ -1625,7 +2141,7 @@ dependencies = [ [[package]] name = "egui_glow" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=6d518fc799681571963842f95b55a6b68431b15a#6d518fc799681571963842f95b55a6b68431b15a" +source = "git+https://github.com/storytold/egui.git?rev=f5025284445ea19c35f746d96fc0b75468b3f560#f5025284445ea19c35f746d96fc0b75468b3f560" dependencies = [ "bytemuck", "egui", @@ -1638,7 +2154,7 @@ dependencies = [ [[package]] name = "egui_kittest" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=6d518fc799681571963842f95b55a6b68431b15a#6d518fc799681571963842f95b55a6b68431b15a" +source = "git+https://github.com/storytold/egui.git?rev=f5025284445ea19c35f746d96fc0b75468b3f560#f5025284445ea19c35f746d96fc0b75468b3f560" dependencies = [ "dify", "eframe", @@ -1664,11 +2180,23 @@ checksum = "0e9c71c2167ca323c882b99918929403426e2373ea17242ff5653e0d5e1058be" [[package]] name = "emath" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=6d518fc799681571963842f95b55a6b68431b15a#6d518fc799681571963842f95b55a6b68431b15a" +source = "git+https://github.com/storytold/egui.git?rev=f5025284445ea19c35f746d96fc0b75468b3f560#f5025284445ea19c35f746d96fc0b75468b3f560" dependencies = [ "bytemuck", ] +[[package]] +name = "embedded-io" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef1a6892d9eef45c8fa6b9e0086428a2cca8491aca8f787c534a3d6d0bcb3ced" + +[[package]] +name = "embedded-io" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edd0f118536f44f5ccd48bcb8b111bdc3de888b58c74639dfb034a357d0f206d" + [[package]] name = "encoding_rs" version = "0.8.42" @@ -1733,7 +2261,7 @@ dependencies = [ [[package]] name = "epaint" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=6d518fc799681571963842f95b55a6b68431b15a#6d518fc799681571963842f95b55a6b68431b15a" +source = "git+https://github.com/storytold/egui.git?rev=f5025284445ea19c35f746d96fc0b75468b3f560#f5025284445ea19c35f746d96fc0b75468b3f560" dependencies = [ "ahash", "bytemuck", @@ -1741,13 +2269,13 @@ dependencies = [ "emath", "epaint_default_fonts", "font-types", - "harfrust", + "harfrust 0.12.0", "log", "nohash-hasher", "parking_lot", "profiling", "self_cell", - "skrifa", + "skrifa 0.44.0", "smallvec", "unicode-bidi", "unicode-general-category", @@ -1759,7 +2287,7 @@ dependencies = [ [[package]] name = "epaint_default_fonts" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=6d518fc799681571963842f95b55a6b68431b15a#6d518fc799681571963842f95b55a6b68431b15a" +source = "git+https://github.com/storytold/egui.git?rev=f5025284445ea19c35f746d96fc0b75468b3f560#f5025284445ea19c35f746d96fc0b75468b3f560" [[package]] name = "equivalent" @@ -1774,7 +2302,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -1900,6 +2428,12 @@ dependencies = [ "zlib-rs", ] +[[package]] +name = "float-cmp" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4" + [[package]] name = "fmt-derive" version = "0.1.2" @@ -2076,6 +2610,30 @@ dependencies = [ "slab", ] +[[package]] +name = "gbm" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce852e998d3ca5e4a97014fb31c940dc5ef344ec7d364984525fd11e8a547e6a" +dependencies = [ + "bitflags 2.13.2", + "drm 0.14.1", + "drm-fourcc", + "gbm-sys", + "libc", + "wayland-backend", + "wayland-server", +] + +[[package]] +name = "gbm-sys" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c13a5f2acc785d8fb6bf6b7ab6bfb0ef5dad4f4d97e8e70bb8e470722312f76f" +dependencies = [ + "libc", +] + [[package]] name = "generic-array" version = "0.14.7" @@ -2092,7 +2650,7 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1bd49230192a3797a9a4d6abe9b3eed6f7fa4c8a8a4947977c6f80025f92cbd8" dependencies = [ - "rustix 1.1.5", + "rustix 1.1.6", "windows-link", ] @@ -2146,6 +2704,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "gl" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a94edab108827d67608095e269cf862e60d920f144a5026d3dbcfd8b877fb404" +dependencies = [ + "gl_generator", +] + [[package]] name = "gl_generator" version = "0.14.0" @@ -2168,11 +2735,17 @@ dependencies = [ "hashbrown 0.17.1", "log", "peniko", - "skrifa", + "skrifa 0.44.0", "smallvec", "vello_common", ] +[[package]] +name = "glob" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4eba85ea1d0a966a983acd07deee566e67395d2d96b6fb39e62b5a833f1eb0b" + [[package]] name = "glow" version = "0.17.0" @@ -2429,9 +3002,9 @@ version = "0.19.1" dependencies = [ "craft-pdf", "craft-stream-codecs", - "harfrust", + "harfrust 0.12.0", "sha2 0.11.1", - "skrifa", + "skrifa 0.44.0", "unicode-bidi", ] @@ -2450,6 +3023,11 @@ dependencies = [ name = "gridcraft-ui-egui" version = "0.19.1" dependencies = [ + "craft-behavior", + "craft-host", + "craft-keymap", + "craft-print", + "craft-theme", "craft-ui", "craft-update", "craft-window", @@ -2464,7 +3042,7 @@ dependencies = [ "log", "serde", "serde_json", - "skrifa", + "skrifa 0.44.0", "sys-locale", "toml", "unicode-bidi", @@ -2496,7 +3074,7 @@ dependencies = [ name = "gridcraft-xlsx" version = "0.19.1" dependencies = [ - "craft-cfb 0.1.0 (git+https://github.com/storytold/craft-libs?rev=e98299546f5c5c3c22388d16507f8b5e61a5f280)", + "craft-cfb", "craft-csv", "craft-drawingml", "craft-math", @@ -2505,7 +3083,7 @@ dependencies = [ "craft-opc", "craft-xls", "craft-xlsx", - "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=a20dfd1623709b0bd9830106d3a92a1a443902e3)", + "craft-xml", "gridcraft-core", "gridcraft-formula", "gridcraft-functions", @@ -2565,7 +3143,20 @@ checksum = "c03d949a14aa089bbb282f7dd76a498a7f684428e4257202efc119ec010376f9" dependencies = [ "bitflags 2.13.2", "bytemuck", - "read-fonts", + "read-fonts 0.41.0", + "smallvec", +] + +[[package]] +name = "harfrust" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "948d0741125ba89cd3e1c23e5642415b6ade7e1d29d67ba25fb925b533e989d6" +dependencies = [ + "bitflags 2.13.2", + "bytemuck", + "once_cell", + "read-fonts 0.43.3", "smallvec", ] @@ -2607,7 +3198,7 @@ checksum = "9f4d0e94ddd48749f06bbe4e5389fb9799a0c45bcaf00495042076ef05e3241a" [[package]] name = "hayro-jbig2" version = "0.3.0" -source = "git+https://github.com/storytold/craft-libs?rev=f7e0d7fd5577e102b4634bcbe062e649eb68165f#f7e0d7fd5577e102b4634bcbe062e649eb68165f" +source = "git+https://github.com/aiongg/craft-libs?rev=cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de#cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" dependencies = [ "hayro-ccitt", ] @@ -2773,6 +3364,39 @@ dependencies = [ "cc", ] +[[package]] +name = "icu_calendar" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58655df2f728e46e4eee80bddebefacf52ec3e77cdb925014b47c5a5905eb55c" +dependencies = [ + "calendrical_calculations", + "displaydoc", + "icu_locale_core", + "icu_provider", + "serde", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_collator" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08984ed58ac439ebf3e13d2cf26b0c46a60afcd21721c1d14087c0b240344dda" +dependencies = [ + "icu_collections", + "icu_locale_core", + "icu_normalizer", + "icu_properties", + "icu_provider", + "serde", + "smallvec", + "utf16_iter", + "utf8_iter", + "zerovec", +] + [[package]] name = "icu_collections" version = "2.3.0" @@ -2781,12 +3405,37 @@ checksum = "fa68d21081c4a05d5a901a1c62add574c77048b6a1c67be3b50ce0b60d4ca513" dependencies = [ "displaydoc", "potential_utf", + "serde", "utf8_iter", "yoke", "zerofrom", "zerovec", ] +[[package]] +name = "icu_datetime" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c44df99c4c5297b05653d1a1629f13bdc9fd4044acfbbaf30b15194a1eed4cd6" +dependencies = [ + "displaydoc", + "fixed_decimal", + "icu_calendar", + "icu_decimal", + "icu_locale_core", + "icu_pattern", + "icu_plurals", + "icu_provider", + "icu_time", + "potential_utf", + "serde", + "smallvec", + "tinystr", + "writeable", + "zerotrie", + "zerovec", +] + [[package]] name = "icu_decimal" version = "2.3.0" @@ -2848,6 +3497,7 @@ dependencies = [ "icu_normalizer_data", "icu_properties", "icu_provider", + "serde", "smallvec", "utf16_iter", "utf8_iter", @@ -2898,6 +3548,7 @@ dependencies = [ "icu_locale_core", "icu_properties_data", "icu_provider", + "serde", "zerotrie", "zerovec", ] @@ -2950,6 +3601,22 @@ dependencies = [ "zerovec", ] +[[package]] +name = "icu_time" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af37e1c3b9f3ab564b619fdf4b22de169f6381eb0f7048e3ca454290c438126b" +dependencies = [ + "calendrical_calculations", + "displaydoc", + "icu_calendar", + "icu_locale_core", + "icu_provider", + "serde", + "zerotrie", + "zerovec", +] + [[package]] name = "idna" version = "1.1.0" @@ -2987,6 +3654,12 @@ dependencies = [ "zune-jpeg", ] +[[package]] +name = "imagesize" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65b27460c2c92b037f3f94c538ed9a3342f3fdf923606781629ccb35f82d042a" + [[package]] name = "indexmap" version = "2.14.2" @@ -3006,6 +3679,15 @@ dependencies = [ "hybrid-array", ] +[[package]] +name = "inventory" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6928282826c822ad91bf1c9a1cb90a30ba1c26770749929b4656cd6be829cd7c" +dependencies = [ + "rustversion", +] + [[package]] name = "ipnet" version = "2.12.2" @@ -3031,6 +3713,15 @@ dependencies = [ "once_cell", ] +[[package]] +name = "itertools" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" +dependencies = [ + "either", +] + [[package]] name = "itertools" version = "0.15.0" @@ -3171,6 +3862,7 @@ dependencies = [ "arrayvec", "euclid", "polycool", + "serde", "smallvec", ] @@ -3225,18 +3917,85 @@ dependencies = [ "redox_syscall 0.9.4", ] +[[package]] +name = "libspa" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "882f7427e7989dcc9d388b7f05c4630390a1d7696f9ffa469cd4a7a48f0b4c40" +dependencies = [ + "bitflags 2.13.2", + "cc", + "cookie-factory", + "libc", + "libspa-sys", + "nom 8.0.0", + "rustix 1.1.6", + "system-deps", +] + +[[package]] +name = "libspa-sys" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b6e17bdaf63ed0d5e4144022624032b41fd9733112e8c74ac26fc9bf1291924" +dependencies = [ + "bindgen", + "cc", + "system-deps", +] + +[[package]] +name = "libwayshot-xcap" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea8a46e4d016ef464e386e4970f5415fe0939c2d63abe0c2f539c05ef88c5fe5" +dependencies = [ + "drm 0.15.0", + "gbm", + "gl", + "image", + "khronos-egl", + "memmap2", + "rustix 1.1.6", + "thiserror 2.0.21", + "tracing", + "wayland-backend", + "wayland-client", + "wayland-protocols", + "wayland-protocols-wlr", +] + [[package]] name = "linebender_resource_handle" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4a5ff6bcca6c4867b1c4fd4ef63e4db7436ef363e0ad7531d1558856bae64f4" +[[package]] +name = "linesweeper" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a25df1b0c5432893f41bba817150e323703ee5f6d974f3a6808ac7fd7f046d18" +dependencies = [ + "arrayvec", + "kurbo", + "polycool", + "rustc-hash 2.1.3", + "smallvec", +] + [[package]] name = "linux-raw-sys" version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab" +[[package]] +name = "linux-raw-sys" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12" + [[package]] name = "linux-raw-sys" version = "0.12.1" @@ -3319,6 +4078,12 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + [[package]] name = "miniz_oxide" version = "0.8.9" @@ -3470,6 +4235,16 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451" +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + [[package]] name = "nom" version = "8.0.0" @@ -3552,8 +4327,8 @@ dependencies = [ "block2 0.5.1", "libc", "objc2 0.5.3", - "objc2-core-data", - "objc2-core-image", + "objc2-core-data 0.2.2", + "objc2-core-image 0.2.2", "objc2-foundation 0.2.2", "objc2-quartz-core 0.2.2", ] @@ -3566,9 +4341,48 @@ checksum = "d49e936b501e5c5bf01fda3a9452ff86dc3ea98ad5f283e1455153142d97518c" dependencies = [ "bitflags 2.13.2", "block2 0.6.2", + "libc", "objc2 0.6.5", + "objc2-cloud-kit 0.3.2", + "objc2-core-data 0.3.2", "objc2-core-foundation", "objc2-core-graphics", + "objc2-core-image 0.3.2", + "objc2-core-text", + "objc2-core-video", + "objc2-foundation 0.3.2", + "objc2-quartz-core 0.3.2", +] + +[[package]] +name = "objc2-av-foundation" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "478ae33fcac9df0a18db8302387c666b8ef08a3e2d62b510ca4fc278a384b6c0" +dependencies = [ + "bitflags 2.13.2", + "block2 0.6.2", + "dispatch2", + "objc2 0.6.5", + "objc2-avf-audio", + "objc2-core-audio-types", + "objc2-core-foundation", + "objc2-core-graphics", + "objc2-core-image 0.3.2", + "objc2-core-video", + "objc2-foundation 0.3.2", + "objc2-image-io", + "objc2-media-toolbox", + "objc2-quartz-core 0.3.2", +] + +[[package]] +name = "objc2-avf-audio" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13a380031deed8e99db00065c45937da434ca987c034e13b87e4441f9e4090be" +dependencies = [ + "objc2 0.6.5", "objc2-foundation 0.3.2", ] @@ -3585,6 +4399,17 @@ dependencies = [ "objc2-foundation 0.2.2", ] +[[package]] +name = "objc2-cloud-kit" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73ad74d880bb43877038da939b7427bba67e9dd42004a18b809ba7d87cee241c" +dependencies = [ + "bitflags 2.13.2", + "objc2 0.6.5", + "objc2-foundation 0.3.2", +] + [[package]] name = "objc2-contacts" version = "0.2.2" @@ -3596,6 +4421,28 @@ dependencies = [ "objc2-foundation 0.2.2", ] +[[package]] +name = "objc2-core-audio" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1eebcea8b0dbff5f7c8504f3107c68fc061a3eb44932051c8cf8a68d969c3b2" +dependencies = [ + "dispatch2", + "objc2 0.6.5", + "objc2-core-audio-types", + "objc2-core-foundation", +] + +[[package]] +name = "objc2-core-audio-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a89f2ec274a0cf4a32642b2991e8b351a404d290da87bb6a9a9d8632490bd1c" +dependencies = [ + "bitflags 2.13.2", + "objc2 0.6.5", +] + [[package]] name = "objc2-core-data" version = "0.2.2" @@ -3608,6 +4455,17 @@ dependencies = [ "objc2-foundation 0.2.2", ] +[[package]] +name = "objc2-core-data" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b402a653efbb5e82ce4df10683b6b28027616a2715e90009947d50b8dd298fa" +dependencies = [ + "bitflags 2.13.2", + "objc2 0.6.5", + "objc2-foundation 0.3.2", +] + [[package]] name = "objc2-core-foundation" version = "0.3.2" @@ -3615,7 +4473,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a180dd8642fa45cdb7dd721cd4c11b1cadd4929ce112ebd8b9f5803cc79d536" dependencies = [ "bitflags 2.13.2", + "block2 0.6.2", "dispatch2", + "libc", "objc2 0.6.5", ] @@ -3626,10 +4486,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e022c9d066895efa1345f8e33e584b9f958da2fd4cd116792e15e07e4720a807" dependencies = [ "bitflags 2.13.2", + "block2 0.6.2", "dispatch2", + "libc", "objc2 0.6.5", "objc2-core-foundation", "objc2-io-surface", + "objc2-metal 0.3.2", ] [[package]] @@ -3644,6 +4507,16 @@ dependencies = [ "objc2-metal 0.2.2", ] +[[package]] +name = "objc2-core-image" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5d563b38d2b97209f8e861173de434bd0214cf020e3423a52624cd1d989f006" +dependencies = [ + "objc2 0.6.5", + "objc2-foundation 0.3.2", +] + [[package]] name = "objc2-core-location" version = "0.2.2" @@ -3656,6 +4529,49 @@ dependencies = [ "objc2-foundation 0.2.2", ] +[[package]] +name = "objc2-core-media" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05ec576860167a15dd9fce7fbee7512beb4e31f532159d3482d1f9c6caedf31d" +dependencies = [ + "bitflags 2.13.2", + "block2 0.6.2", + "dispatch2", + "objc2 0.6.5", + "objc2-core-audio", + "objc2-core-audio-types", + "objc2-core-foundation", + "objc2-core-video", +] + +[[package]] +name = "objc2-core-text" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0cde0dfb48d25d2b4862161a4d5fcc0e3c24367869ad306b0c9ec0073bfed92d" +dependencies = [ + "bitflags 2.13.2", + "objc2 0.6.5", + "objc2-core-foundation", + "objc2-core-graphics", +] + +[[package]] +name = "objc2-core-video" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d425caf1df73233f29fd8a5c3e5edbc30d2d4307870f802d18f00d83dc5141a6" +dependencies = [ + "bitflags 2.13.2", + "block2 0.6.2", + "objc2 0.6.5", + "objc2-core-foundation", + "objc2-core-graphics", + "objc2-io-surface", + "objc2-metal 0.3.2", +] + [[package]] name = "objc2-encode" version = "4.1.0" @@ -3683,10 +4599,22 @@ checksum = "e3e0adef53c21f888deb4fa59fc59f7eb17404926ee8a6f59f5df0fd7f9f3272" dependencies = [ "bitflags 2.13.2", "block2 0.6.2", + "libc", "objc2 0.6.5", "objc2-core-foundation", ] +[[package]] +name = "objc2-image-io" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32b0446e98cf4a784cc7a0177715ff317eeaa8463841c616cfc78aa4f953c4ea" +dependencies = [ + "objc2 0.6.5", + "objc2-core-foundation", + "objc2-core-graphics", +] + [[package]] name = "objc2-io-surface" version = "0.3.2" @@ -3710,6 +4638,18 @@ dependencies = [ "objc2-foundation 0.2.2", ] +[[package]] +name = "objc2-media-toolbox" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edd9fdde720df3da7046bb9097811000c1e7ab5cd579fa89d96b27d56781fb30" +dependencies = [ + "objc2 0.6.5", + "objc2-core-audio-types", + "objc2-core-foundation", + "objc2-core-media", +] + [[package]] name = "objc2-metal" version = "0.2.2" @@ -3780,9 +4720,9 @@ dependencies = [ "bitflags 2.13.2", "block2 0.5.1", "objc2 0.5.3", - "objc2-cloud-kit", - "objc2-core-data", - "objc2-core-image", + "objc2-cloud-kit 0.2.2", + "objc2-core-data 0.2.2", + "objc2-core-image 0.2.2", "objc2-core-location", "objc2-foundation 0.2.2", "objc2-link-presentation", @@ -3850,6 +4790,12 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe" +[[package]] +name = "option-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" + [[package]] name = "orbclient" version = "0.3.55" @@ -3886,7 +4832,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d8fae84b431384b68627d0f9b3b1245fcf9f46f6c0e3dc902e9dce64edd1967" dependencies = [ "libc", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -4052,6 +4998,12 @@ dependencies = [ "siphasher", ] +[[package]] +name = "pico-args" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5be167a7af36ee22fe3115051bc51f6e6c7054c9348e28deb4f49bd6f705a315" + [[package]] name = "pin-project" version = "1.1.13" @@ -4089,6 +5041,31 @@ dependencies = [ "futures-io", ] +[[package]] +name = "pipewire" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bde71084c4e25959d68f1ea54daa75e5ecdb338e5caf0b5510143b79baa32d5c" +dependencies = [ + "bitflags 2.13.2", + "libc", + "libspa", + "libspa-sys", + "pipewire-sys", + "rustix 1.1.6", +] + +[[package]] +name = "pipewire-sys" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce653f53e63e5b93853218092ee9a8906a5d082c92f3f1db26316955dd63ce0" +dependencies = [ + "bindgen", + "libspa-sys", + "system-deps", +] + [[package]] name = "pkg-config" version = "0.3.34" @@ -4137,7 +5114,7 @@ dependencies = [ "concurrent-queue", "hermit-abi", "pin-project-lite", - "rustix 1.1.5", + "rustix 1.1.6", "windows-sys 0.61.2", ] @@ -4184,6 +5161,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6764c3b5dd454e283a30e6dfe78e9b31096d9e32036b5d1eaac7a6119ccb9a24" dependencies = [ "cobs", + "embedded-io 0.4.0", + "embedded-io 0.6.1", "serde", ] @@ -4342,7 +5321,7 @@ dependencies = [ "once_cell", "socket2", "tracing", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -4522,6 +5501,28 @@ dependencies = [ "once_cell", ] +[[package]] +name = "read-fonts" +version = "0.43.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "005c8acf251756c478b0bf402885bfd88a1476020c4c7e6060edc1aa68da38ea" +dependencies = [ + "bytemuck", + "font-types", + "once_cell", +] + +[[package]] +name = "read-fonts" +version = "0.44.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5a0cf4bb6cbce4c29756270d189a5e400ac05e91192161d83a0bcb6e68492e8" +dependencies = [ + "bytemuck", + "font-types", + "once_cell", +] + [[package]] name = "redox_syscall" version = "0.4.1" @@ -4549,6 +5550,16 @@ dependencies = [ "bitflags 2.13.2", ] +[[package]] +name = "redox_users" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60dc65c0ff1a7ae1294b0c67b9f14baf70b644404010370171787bfac1038fc0" +dependencies = [ + "libredox", + "thiserror 2.0.21", +] + [[package]] name = "regex" version = "1.13.1" @@ -4633,6 +5644,21 @@ dependencies = [ "web-sys", ] +[[package]] +name = "resvg" +version = "0.48.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67e3803f97b999e80cbf7c6ecdd07a8102204d92e1633cf48783720c521196bd" +dependencies = [ + "bytemuck", + "log", + "pico-args", + "rgb", + "svgtypes", + "tiny-skia 0.12.0", + "usvg", +] + [[package]] name = "rfd" version = "0.17.2" @@ -4660,6 +5686,15 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "rgb" +version = "0.8.53" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47b34b781b31e5d73e9fbc8689c70551fd1ade9a19e3e28cfec8580a79290cc4" +dependencies = [ + "bytemuck", +] + [[package]] name = "ring" version = "0.17.14" @@ -4719,15 +5754,15 @@ dependencies = [ [[package]] name = "rustix" -version = "1.1.5" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "891efababe418670775f199f0d233d84843c227a0949a883ce15b37c78d6629d" +checksum = "e5e76742e5294153d4dde1207dbec5bdd81eef6fabdc0d2118babadabfd858aa" dependencies = [ "bitflags 2.13.2", "errno", "libc", "linux-raw-sys 0.12.1", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -4786,7 +5821,7 @@ dependencies = [ "security-framework", "security-framework-sys", "webpki-root-certs", - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -4863,7 +5898,7 @@ checksum = "b6277f0217056f77f1d8f49f2950ac6c278c0d607c45f5ee99328d792ede24ec" dependencies = [ "log", "smithay-client-toolkit 0.19.2", - "tiny-skia", + "tiny-skia 0.11.4", ] [[package]] @@ -5050,6 +6085,12 @@ dependencies = [ "digest 0.11.3", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "shlex" version = "2.0.1" @@ -5257,6 +6298,15 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e" +[[package]] +name = "simplecss" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a9c6883ca9c3c7c90e888de77b7a5c849c779d25d74a1269b0218b14e8b136c" +dependencies = [ + "log", +] + [[package]] name = "siphasher" version = "1.0.4" @@ -5270,7 +6320,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "819ab7d62b1d3e72d9d9dea5650bac30424f9111364bb94928dbf5ecad1baa68" dependencies = [ "bytemuck", - "read-fonts", + "read-fonts 0.41.0", +] + +[[package]] +name = "skrifa" +version = "0.47.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "526e654b303ff4ad73a5a40b25de2b3ce3d039c5e3b6da5f89ae6e57004cb40f" +dependencies = [ + "bytemuck", + "read-fonts 0.44.0", ] [[package]] @@ -5293,6 +6353,9 @@ name = "smallvec" version = "1.16.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f9395f0f0eee849a9b707b2f06bb92a6a422090e2123bb2ef8e87a0e61892a8e" +dependencies = [ + "serde", +] [[package]] name = "smithay-client-toolkit" @@ -5332,7 +6395,7 @@ dependencies = [ "libc", "log", "memmap2", - "rustix 1.1.5", + "rustix 1.1.6", "thiserror 2.0.21", "wayland-backend", "wayland-client", @@ -5412,6 +6475,9 @@ name = "strict-num" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6637bab7722d379c8b41ba849228d680cc12d0a45ba1fa2b48f2a30577a06731" +dependencies = [ + "float-cmp", +] [[package]] name = "strum" @@ -5440,6 +6506,16 @@ version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" +[[package]] +name = "svgtypes" +version = "0.16.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f12b12995e3638c70618c1facb1ce65302f6a6f706b675f07c58a5d7391120e" +dependencies = [ + "kurbo", + "siphasher", +] + [[package]] name = "syn" version = "1.0.109" @@ -5525,6 +6601,19 @@ dependencies = [ "libc", ] +[[package]] +name = "system-deps" +version = "7.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "396a35feb67335377e0251fcbc1092fc85c484bd4e3a7a54319399da127796e7" +dependencies = [ + "cfg-expr", + "heck", + "pkg-config", + "toml", + "version-compare", +] + [[package]] name = "tar" version = "0.4.46" @@ -5536,6 +6625,12 @@ dependencies = [ "xattr", ] +[[package]] +name = "target-lexicon" +version = "0.13.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adb6935a6f5c20170eeceb1a3835a49e12e19d792f6dd344ccc76a985ca5a6ca" + [[package]] name = "tempfile" version = "3.27.0" @@ -5545,8 +6640,8 @@ dependencies = [ "fastrand", "getrandom 0.4.3", "once_cell", - "rustix 1.1.5", - "windows-sys 0.61.2", + "rustix 1.1.6", + "windows-sys 0.52.0", ] [[package]] @@ -5653,7 +6748,22 @@ dependencies = [ "bytemuck", "cfg-if", "log", - "tiny-skia-path", + "tiny-skia-path 0.11.4", +] + +[[package]] +name = "tiny-skia" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47ffee5eaaf5527f630fb0e356b90ebdec84d5d18d937c5e440350f88c5a91ea" +dependencies = [ + "arrayref", + "arrayvec", + "bytemuck", + "cfg-if", + "log", + "png", + "tiny-skia-path 0.12.0", ] [[package]] @@ -5667,6 +6777,17 @@ dependencies = [ "strict-num", ] +[[package]] +name = "tiny-skia-path" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edca365c3faccca67d06593c5980fa6c57687de727a03131735bb85f01fdeeb9" +dependencies = [ + "arrayref", + "bytemuck", + "strict-num", +] + [[package]] name = "tinystr" version = "0.8.4" @@ -5774,8 +6895,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1340ea94a5856333492c9064b02c778b191dd2c853778d9609debdcdfea3a614" dependencies = [ "indexmap", + "serde_core", + "serde_spanned", "toml_datetime", "toml_parser", + "toml_writer", "winnow", ] @@ -5878,7 +7002,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8765b90061cba6c22b5831f675da109ae5561588290f9fa2317adab2714d5a6" dependencies = [ "memchr", - "nom", + "nom 8.0.0", "petgraph", ] @@ -5903,6 +7027,12 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ce898823d8cd0f028662d2f349694b1af0a5cc9be83f1d213a00d3147445e1e" +[[package]] +name = "typeid" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc7d623258602320d5c55d1bc22793b57daff0ec7efc270ea7d55ce1d5f5471c" + [[package]] name = "typenum" version = "1.20.1" @@ -6018,6 +7148,25 @@ dependencies = [ "serde", ] +[[package]] +name = "usvg" +version = "0.48.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "977d0a4abdef933f424a99fe09f95576e089b90aebc6f016a3bc813762493e91" +dependencies = [ + "data-url", + "imagesize", + "kurbo", + "log", + "pico-args", + "roxmltree", + "simplecss", + "siphasher", + "strict-num", + "svgtypes", + "tiny-skia-path 0.12.0", +] + [[package]] name = "utf16_iter" version = "1.0.5" @@ -6047,6 +7196,27 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "vectorcraft-geom" +version = "0.18.0" +source = "git+https://github.com/storytold/vectorcraft.git?rev=6b3a6b8788ebcb420d69449199cbdf323888d27e#6b3a6b8788ebcb420d69449199cbdf323888d27e" +dependencies = [ + "kurbo", + "serde", + "thiserror 2.0.21", +] + +[[package]] +name = "vectorcraft-pathops" +version = "0.18.0" +source = "git+https://github.com/storytold/vectorcraft.git?rev=6b3a6b8788ebcb420d69449199cbdf323888d27e#6b3a6b8788ebcb420d69449199cbdf323888d27e" +dependencies = [ + "kurbo", + "linesweeper", + "thiserror 2.0.21", + "vectorcraft-geom", +] + [[package]] name = "vello_common" version = "0.2.0" @@ -6084,6 +7254,12 @@ dependencies = [ "windows-sys 0.61.2", ] +[[package]] +name = "version-compare" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03c2856837ef78f57382f06b2b8563a2f512f7185d732608fd9176cb3b8edf0e" + [[package]] name = "version_check" version = "0.9.5" @@ -6188,7 +7364,7 @@ checksum = "38a91b4eaddff87b1cd1074985e3713da4af2c49742d1b356b2c01670a67a078" dependencies = [ "cc", "downcast-rs", - "rustix 1.1.5", + "rustix 1.1.6", "scoped-tls", "smallvec", "wayland-sys", @@ -6201,7 +7377,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3c36a0f861ad76d0901f2800b46321410d9f73f2ea88aac0650d86c32688073" dependencies = [ "bitflags 2.13.2", - "rustix 1.1.5", + "rustix 1.1.6", "wayland-backend", "wayland-scanner", ] @@ -6223,7 +7399,7 @@ version = "0.31.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4a52d18780be9b1314328a3de5f930b73d2200112e3849ca6cb11822793fb34d" dependencies = [ - "rustix 1.1.5", + "rustix 1.1.6", "wayland-client", "xcursor", ] @@ -6303,6 +7479,19 @@ dependencies = [ "quote", ] +[[package]] +name = "wayland-server" +version = "0.31.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dde9c29be0f723a573977de51ee455bf3dfa03652730a74f9dd3b337e374d75" +dependencies = [ + "bitflags 2.13.2", + "downcast-rs", + "rustix 1.1.6", + "wayland-backend", + "wayland-scanner", +] + [[package]] name = "wayland-sys" version = "0.31.11" @@ -6310,7 +7499,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8eab23fefc9e41f8e841df4a9c707e8a8c4ed26e944ef69297184de2785e3be" dependencies = [ "dlib", + "libc", "log", + "memoffset", "once_cell", "pkg-config", ] @@ -6533,13 +7724,19 @@ dependencies = [ "web-sys", ] +[[package]] +name = "widestring" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72069c3113ab32ab29e5584db3c6ec55d416895e60715417b5b883a357c3e471" + [[package]] name = "winapi-util" version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.61.2", + "windows-sys 0.52.0", ] [[package]] @@ -6817,7 +8014,7 @@ dependencies = [ [[package]] name = "winprint" version = "0.2.1" -source = "git+https://github.com/storytold/winprint.rs?rev=bc06a7c48b768eb27a828c7986f6d2868b245ee0#bc06a7c48b768eb27a828c7986f6d2868b245ee0" +source = "git+https://github.com/storytold/winprint.rs?rev=8ae097ef941b432b0e7671b1ec3a506800e65e57#8ae097ef941b432b0e7671b1ec3a506800e65e57" dependencies = [ "flate2", "fmt-derive", @@ -6877,7 +8074,7 @@ dependencies = [ "libc", "log", "os_pipe", - "rustix 1.1.5", + "rustix 1.1.6", "thiserror 2.0.21", "tree_magic_mini", "wayland-backend", @@ -6923,7 +8120,7 @@ dependencies = [ "libc", "libloading", "once_cell", - "rustix 1.1.5", + "rustix 1.1.6", "x11rb-protocol", ] @@ -6965,7 +8162,49 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32e45ad4206f6d2479085147f02bc2ef834ac85886624a23575ae137c8aa8156" dependencies = [ "libc", - "rustix 1.1.5", + "rustix 1.1.6", +] + +[[package]] +name = "xcap" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da270fd7c8581d43d731cb690bcc791fc0a7b3bc96e131a4b6552d0379640a9e" +dependencies = [ + "dispatch2", + "image", + "libwayshot-xcap", + "log", + "objc2 0.6.5", + "objc2-app-kit 0.3.2", + "objc2-av-foundation", + "objc2-core-foundation", + "objc2-core-graphics", + "objc2-core-media", + "objc2-core-video", + "objc2-foundation 0.3.2", + "percent-encoding", + "pipewire", + "rand 0.10.3", + "scopeguard", + "serde", + "thiserror 2.0.21", + "url", + "widestring", + "windows", + "xcb", + "zbus", +] + +[[package]] +name = "xcb" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6c2ad15e0e922856ee89afe862b8992334bbe7953adad56cd1199358cb30566" +dependencies = [ + "bitflags 2.13.2", + "libc", + "quick-xml 0.41.0", ] [[package]] @@ -7058,7 +8297,7 @@ dependencies = [ "hex", "libc", "ordered-stream", - "rustix 1.1.5", + "rustix 1.1.6", "serde", "serde_repr", "tracing", @@ -7353,14 +8592,14 @@ dependencies = [ [[patch.unused]] name = "egui_demo_lib" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=6d518fc799681571963842f95b55a6b68431b15a#6d518fc799681571963842f95b55a6b68431b15a" +source = "git+https://github.com/storytold/egui.git?rev=f5025284445ea19c35f746d96fc0b75468b3f560#f5025284445ea19c35f746d96fc0b75468b3f560" [[patch.unused]] name = "egui_inspection" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=6d518fc799681571963842f95b55a6b68431b15a#6d518fc799681571963842f95b55a6b68431b15a" +source = "git+https://github.com/storytold/egui.git?rev=f5025284445ea19c35f746d96fc0b75468b3f560#f5025284445ea19c35f746d96fc0b75468b3f560" [[patch.unused]] name = "egui_system_font_provider" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=6d518fc799681571963842f95b55a6b68431b15a#6d518fc799681571963842f95b55a6b68431b15a" +source = "git+https://github.com/storytold/egui.git?rev=f5025284445ea19c35f746d96fc0b75468b3f560#f5025284445ea19c35f746d96fc0b75468b3f560" diff --git a/Cargo.toml b/Cargo.toml index 256e8e68e..c9d8e1f84 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -93,6 +93,14 @@ epaint_default_fonts = "0.37" # One native window per workbook: the window list, Window menu titles and the immediate-viewport # driver. Same craft-libs revision as craft-update above. craft-window = { version = "0.1.0", git = "https://github.com/aiongg/craft-libs", rev = "cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de", default-features = false, features = ["ui"] } +# The UI runtime GridCraft's egui UI is hosted by (`crates/ui-egui/src/framework.rs`): who the app is +# to the framework's dialogs, the runtime's key bindings, the theme mode, window placement and the +# printer controls. Same craft-libs revision as above. +craft-behavior = { version = "0.1.0", git = "https://github.com/aiongg/craft-libs", rev = "cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" } +craft-host = { version = "0.1.0", git = "https://github.com/aiongg/craft-libs", rev = "cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" } +craft-keymap = { version = "0.1.0", git = "https://github.com/aiongg/craft-libs", rev = "cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" } +craft-theme = { version = "0.1.0", git = "https://github.com/aiongg/craft-libs", rev = "cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" } +craft-print = { version = "0.1.0", git = "https://github.com/aiongg/craft-libs", rev = "cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de", features = ["ui"] } [workspace.lints.rust] unsafe_code = "forbid" diff --git a/apps/gridcraft-web/src/web.rs b/apps/gridcraft-web/src/web.rs index 1108c4c11..428772f3c 100644 --- a/apps/gridcraft-web/src/web.rs +++ b/apps/gridcraft-web/src/web.rs @@ -49,6 +49,7 @@ pub fn start() { canvas, options, Box::new(move |cc| { + gridcraft_ui_egui::framework::install_headless(&cc.egui_ctx); let inbox: Inbox = Inbox::default(); let mut session = Session::new(); // In host mode the host sends the workbook to edit; no sample meanwhile. @@ -158,6 +159,7 @@ impl eframe::App for WebShell { }); } self.app.logic(ctx); + self.app.close_path(ctx); // Store changed preferences straight away: a reload or closed tab runs no exit code (#1562). let changed = self.prefs.changed(&self.app); if !changed.is_empty() { @@ -177,6 +179,7 @@ impl eframe::App for WebShell { /// Forwards a browser frame's raw input to the shared app before eframe handles it. fn raw_input_hook(&mut self, ctx: &egui::Context, raw: &mut egui::RawInput) { self.app.raw_input_hook(ctx, raw); + self.app.before_input(ctx); } fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) { diff --git a/apps/gridcraft/Cargo.toml b/apps/gridcraft/Cargo.toml index daeb959d0..3dfdb7024 100644 --- a/apps/gridcraft/Cargo.toml +++ b/apps/gridcraft/Cargo.toml @@ -32,7 +32,7 @@ winit = { version = "0.30", default-features = false, features = ["x11", "waylan [target.'cfg(not(target_arch = "wasm32"))'.dependencies] # Same craft-libs revision as the workspace's craft-update and craft-window (see the root # Cargo.toml). -craft-print = { git = "https://github.com/aiongg/craft-libs", rev = "cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" } +craft-print = { workspace = true } craft-update = { workspace = true } rfd = { workspace = true } arboard = { workspace = true, features = ["image-data"] } diff --git a/apps/gridcraft/src/main.rs b/apps/gridcraft/src/main.rs index 858c7f9d1..824d654b1 100644 --- a/apps/gridcraft/src/main.rs +++ b/apps/gridcraft/src/main.rs @@ -45,13 +45,12 @@ impl eframe::App for App { } self.0.logic(ctx); self.1.logic(&mut self.0, ctx); - if ctx.input(|input| input.viewport().close_requested()) && self.0.printing.busy() { - ctx.send_viewport_cmd(egui::ViewportCommand::CancelClose); - } + self.0.close_path(ctx); } /// Forwards raw input to the shared app, then opens every non-empty dropped file path as a workbook. fn raw_input_hook(&mut self, ctx: &egui::Context, raw: &mut egui::RawInput) { self.0.raw_input_hook(ctx, raw); + self.0.before_input(ctx); // Files dropped on the window open as workbooks. for f in std::mem::take(&mut raw.dropped_files) { if let Some(p) = f.path().to_str().map(str::to_string).filter(|p| !p.is_empty()) { @@ -59,7 +58,8 @@ impl eframe::App for App { } } } - fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) { + fn ui(&mut self, ui: &mut egui::Ui, frame: &mut eframe::Frame) { + gridcraft_ui_egui::framework::before_ui(ui.ctx(), &*frame); self.1.show(&mut self.0, ui); } fn on_exit(&mut self) { @@ -393,6 +393,7 @@ fn main() -> eframe::Result<()> { let Some(mut app) = pending.take() else { return Err("the app was already created".into()); }; + gridcraft_ui_egui::framework::install(&cc.egui_ctx)?; SheetApp::setup_context_for_language(&cc.egui_ctx, app.ui.dark, app.ui.language); if let Some(port) = control_port { match control_server::start(port, control_token.clone(), cc.egui_ctx.clone()) { diff --git a/apps/gridcraft/src/print.rs b/apps/gridcraft/src/print.rs index 2132fc601..74d6912c4 100644 --- a/apps/gridcraft/src/print.rs +++ b/apps/gridcraft/src/print.rs @@ -1,5 +1,5 @@ //! Desktop spooler adapter. Discovery and submission never run on the UI thread. -use gridcraft_ui_egui::printing::{Discover, Duplex, Printer, Settings, Submit}; +use gridcraft_ui_egui::printing::{Destination, Discover, Duplex, Printer, Settings, Submit}; /// Returns a printer-discovery closure that enumerates `craft_print::printers()` on a named background thread and sends the mapped list through a channel. pub fn discover() -> Discover { @@ -8,7 +8,7 @@ pub fn discover() -> Discover { let _ = std::thread::Builder::new().name("print-discovery".into()).spawn(move || { let printers = craft_print::printers() .into_iter() - .map(|printer| Printer { name: printer.name, label: printer.description, default: printer.default }) + .map(|printer| Printer::new(printer.name).label(printer.description).is_default(printer.default)) .collect(); let _ = sender.send(printers); }); @@ -34,12 +34,16 @@ pub fn submit() -> Submit { let (sender, receiver) = std::sync::mpsc::channel(); let worker = std::thread::Builder::new().name("print-submit".into()).spawn(move || { let job = craft_print::Job { - printer: Some(settings.printer), + printer: match settings.destination { + Destination::Printer(name) => Some(name), + _ => None, + }, copies: settings.copies.clamp(1, 999), - duplex: settings.duplex.map(|value| match value { - Duplex::LongEdge => craft_print::Duplex::LongEdge, - Duplex::ShortEdge => craft_print::Duplex::ShortEdge, - Duplex::Off => craft_print::Duplex::Off, + duplex: settings.duplex.and_then(|value| match value { + Duplex::LongEdge => Some(craft_print::Duplex::LongEdge), + Duplex::ShortEdge => Some(craft_print::Duplex::ShortEdge), + Duplex::Off => Some(craft_print::Duplex::Off), + _ => None, }), grayscale: settings.grayscale, scaling: craft_print::Scaling::ShrinkToFit, diff --git a/crates/ui-egui/Cargo.toml b/crates/ui-egui/Cargo.toml index 0cdf857a6..86280acab 100644 --- a/crates/ui-egui/Cargo.toml +++ b/crates/ui-egui/Cargo.toml @@ -9,9 +9,15 @@ description = "GridCraft egui frontend (Excel-style UI); swappable — nothing b workspace = true [dependencies] -# The shared capture slot (`craft_ui::capture`) comes from the one craft-libs revision every -# craft-libs dependency uses (see the root Cargo.toml). +# The UI runtime that hosts this egui UI (`src/framework.rs`) and the framework dialogs, from the +# one craft-libs revision every craft-libs dependency uses (see the root Cargo.toml). craft-ui = { git = "https://github.com/aiongg/craft-libs", rev = "cd87dc61f77d8470b2e9e6a1236f9a84ee0a64de" } +craft-behavior = { workspace = true } +craft-host = { workspace = true } +craft-keymap = { workspace = true } +craft-print = { workspace = true } +craft-theme = { workspace = true } +craft-window = { workspace = true } gridcraft-engine = { workspace = true } gridcraft-chart = { workspace = true } # `monochrome_emoji_fonts` restores the Noto Emoji and emoji-icon faces that 0.37 moved behind @@ -42,7 +48,6 @@ gridcraft-xlsx = { workspace = true, features = ["test-support"] } craft-update = { workspace = true } # The desktop's preferred language for the first-run interface language. sys-locale = { workspace = true } -craft-window = { workspace = true } [target.'cfg(target_arch = "wasm32")'.dependencies] # Read the browser's preferred language for the first-run web interface language. diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index 471905fbd..8d020f1e8 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -88,6 +88,8 @@ impl SheetApp { arrange_windows: None, #[cfg(not(target_arch = "wasm32"))] updates_rt: Default::default(), + framework_dialogs: Default::default(), + framework_host: crate::framework::host(), } } @@ -102,7 +104,7 @@ impl SheetApp { /// Sets up fonts and visuals for a specific persisted interface language. pub fn setup_context_for_language(ctx: &egui::Context, dark: bool, language: i18n::Language) { - ctx.set_fonts(theme::font_definitions_for_language(language)); + craft_ui::fonts::load(ctx, theme::font_definitions_for_language(language)); theme::apply(ctx, dark); } @@ -123,7 +125,6 @@ impl SheetApp { self.desktop_dark = Some(answer); } self.sync_theme_preference(ctx); - self.sync_input_options(ctx); // The geometry captures are bound to. Native frames recorded it from their fresh // `RawInput` in `raw_input_hook` (including hidden logic-only ticks); the epoch is // monotonic, so a resize back to the original values is still a new epoch and old pixels @@ -139,7 +140,6 @@ impl SheetApp { // Printing feedback is polled once per frame, here, so hidden windows and logic-only // frames still see worker completion. `ui` and the desktop app no longer poll it. self.poll_printing(ctx); - self.guard_window_close(ctx); #[cfg(not(target_arch = "wasm32"))] updates_ui::tick(self, ctx); // Files read asynchronously (web file picker, dropped files). @@ -212,8 +212,6 @@ impl SheetApp { } // The language the widgets translate with this frame (see `i18n::current`). i18n::set_current(&ctx, self.ui.language); - #[cfg(not(target_arch = "wasm32"))] - updates_ui::show(self, &ctx); let t = theme::Tokens::get(&ctx); // A host can turn the File tab off while Backstage is already open: close it. if !self.chrome.file_tab { @@ -256,6 +254,12 @@ impl SheetApp { widgets::toast(self, &ctx); // Last, so its resize cursors win over the widgets under the window edges. ribbon::window_frame(self, &ctx); + // The update flow and the framework dialogs run once per frame, in the root window. + if ctx.viewport_id() == egui::ViewportId::ROOT { + #[cfg(not(target_arch = "wasm32"))] + updates_ui::show(self, &ctx); + self.run_framework_dialogs(ui); + } self.flush_viewport_commands(&ctx); // Requests are admitted in `logic`, for the root viewport, so only its pass issues them. if ctx.viewport_id() == egui::ViewportId::ROOT { @@ -524,7 +528,7 @@ mod lifecycle_tests { fn a_logic_only_tick_polls_printing_feedback() { let ctx = egui::Context::default(); let mut app = app(); - app.printing.printers.push(crate::printing::Printer { name: "Queue".into(), label: String::new(), default: true }); + app.printing.printers.push(crate::printing::Printer::new("Queue").is_default(true)); app.run("ui.printSettings", serde_json::json!({"printer": "Queue"})).unwrap(); app.services.print_native = Some(Box::new(|_, _| { let (sender, receiver) = std::sync::mpsc::channel(); diff --git a/crates/ui-egui/src/app/fonts.rs b/crates/ui-egui/src/app/fonts.rs index 76a829a9d..6a84a09dc 100644 --- a/crates/ui-egui/src/app/fonts.rs +++ b/crates/ui-egui/src/app/fonts.rs @@ -81,7 +81,7 @@ impl SheetApp { return; } if self.prepared_fonts { - ctx.set_fonts(theme::pinned_font_definitions()); + craft_ui::fonts::load(ctx, theme::pinned_font_definitions()); theme::apply(ctx, self.ui.dark); } else { SheetApp::setup_context_for_language(ctx, self.ui.dark, self.ui.language); @@ -107,7 +107,7 @@ impl SheetApp { if used == self.fonts_bound { return; } - ctx.set_fonts(theme::font_definitions_with(self.ui.language, &used)); + craft_ui::fonts::load(ctx, theme::font_definitions_with(self.ui.language, &used)); self.fonts_bound = used; self.fonts_rebind = true; ctx.request_repaint(); diff --git a/crates/ui-egui/src/app/prefs.rs b/crates/ui-egui/src/app/prefs.rs index 151374e6e..d57a16328 100644 --- a/crates/ui-egui/src/app/prefs.rs +++ b/crates/ui-egui/src/app/prefs.rs @@ -27,27 +27,6 @@ impl SheetApp { self.effective_dark = ctx.theme() == egui::Theme::Dark; } - /// Keeps egui's own keyboard zoom and quit shortcuts off and applies GridCraft's zoom factor. - pub(super) fn sync_input_options(&mut self, ctx: &egui::Context) { - // Interface size: the preference owns the zoom factor, so egui's own Ctrl/Cmd +/-/0 zoom - // keys stay off (they would also swallow GridCraft's shortcuts). - if ctx.options(|o| o.zoom_with_keyboard) { - ctx.options_mut(|o| o.zoom_with_keyboard = false); - } - // egui closes the window on Ctrl+Q (and with Shift or Alt held too) without asking to save - // (#1443). Excel for Windows has no such key (Ctrl+Q is Quick Analysis). With a native - // window per workbook egui's Cmd+Q would close only the window it was typed in: the menu - // bar's Quit item has the key instead (it asks about unsaved workbooks first). - if (ctx.os() != egui::os::OperatingSystem::Mac || self.native_windows) && ctx.options(|o| !o.quit_shortcuts.is_empty()) { - ctx.options_mut(|o| o.quit_shortcuts.clear()); - } - let zoom = self.ui.zoom_factor(); - if (ctx.zoom_factor() - zoom).abs() > 0.001 { - ctx.set_zoom_factor(zoom); - ctx.request_repaint(); - } - } - /// Look for a newer release once, in the background, as the desktop app starts (a no-op on the /// web). A found release opens the update prompt; nothing is shown when GridCraft is current. pub fn start_update_check(&mut self) { diff --git a/crates/ui-egui/src/app/quit.rs b/crates/ui-egui/src/app/quit.rs index 7f364829f..43ec478cd 100644 --- a/crates/ui-egui/src/app/quit.rs +++ b/crates/ui-egui/src/app/quit.rs @@ -1,28 +1,35 @@ +use craft_ui::shell::embed::CloseDecision; + use super::{SaveAnswer, SheetApp, json}; impl SheetApp { - /// Holds back a window close (the close button, Alt+F4, the OS quitting the app) while a - /// workbook has unsaved changes, and asks about them first. - pub(super) fn guard_window_close(&mut self, ctx: &egui::Context) { - if self.native_windows || self.allow_close || !ctx.input(|i| i.viewport().close_requested()) { - return; + /// The root window was asked to close (the close button, Alt+F4, the OS quitting the app): whether it closes + /// now. A running print job holds it. With a native window per workbook the close is that window's + /// ([`crate::doc_windows`]) unless the app is quitting. Otherwise unsaved changes hold it while they are asked + /// about. + pub fn close_decision(&mut self, ctx: &egui::Context) -> CloseDecision { + if self.printing.busy() { + return CloseDecision::Hold; + } + if self.allow_close { + return CloseDecision::Close; + } + if self.native_windows { + return CloseDecision::Hold; } // A cell still being edited is part of the workbook, as for File › Close. if !self.commit_edit(0, 0, false, false) { - ctx.send_viewport_cmd(egui::ViewportCommand::CancelClose); - return; + return CloseDecision::Hold; } // The macro step editor asks about its own unsaved steps and debug run first; once it has // closed, the window close goes on. if self.dialog.as_ref().is_some_and(|d| d.name == "macroEditor") { - ctx.send_viewport_cmd(egui::ViewportCommand::CancelClose); crate::macro_editor::request_close(self, true); - return; + return CloseDecision::Hold; } if !self.session.documents().iter().any(|d| d.is_dirty()) { - return; + return CloseDecision::Close; } - ctx.send_viewport_cmd(egui::ViewportCommand::CancelClose); match self.dialog.as_mut() { // Already asking about a workbook (File › Close): answering it now goes on to quit. Some(d) if d.name() == "saveChanges" => { @@ -30,6 +37,7 @@ impl SheetApp { } _ => self.continue_quit(ctx), } + CloseDecision::Hold } /// Asks about the next unsaved workbook before quitting, in its window, or closes the app diff --git a/crates/ui-egui/src/backstage.rs b/crates/ui-egui/src/backstage.rs index dfd5ccfa9..5ad23932c 100644 --- a/crates/ui-egui/src/backstage.rs +++ b/crates/ui-egui/src/backstage.rs @@ -233,12 +233,7 @@ pub fn show(app: &mut SheetApp, ui: &mut Ui) { }); }); bs.text_edit_focused = ctx.text_edit_focused(); - if !typing - && app.dialog.is_none() - && app.message.is_none() - && !egui::Popup::is_any_open(&ctx) - && ctx.input_mut(|i| i.consume_key(Modifiers::NONE, Key::Escape)) - { + if !typing && app.dialog.is_none() && app.message.is_none() && !egui::Popup::is_any_open(&ctx) && crate::framework::consume_escape(&ctx) { out.close = true; } if let Some(page) = out.page { diff --git a/crates/ui-egui/src/capture.rs b/crates/ui-egui/src/capture.rs new file mode 100644 index 000000000..848469ffb --- /dev/null +++ b/crates/ui-egui/src/capture.rs @@ -0,0 +1,251 @@ +//! One-shot completion slots for screenshot requests. +//! +//! Applications retain request IDs, output paths, deadlines, settling policy, geometry epochs and +//! aggregate admission budgets. This module only correlates one capture with one slot, checks the +//! retained image against a per-image byte bound, and wakes the owning viewport. +//! +//! [`CaptureSlot::new`] does not issue a screenshot command. Send the returned [`egui::ScreenshotCallback`] +//! with [`egui::ViewportCommand::Screenshot`] when the application decides the capture is due, or +//! complete it directly from a headless renderer. The callback holds only a weak reference to the +//! slot, so dropping or cancelling the request releases its image and makes late results inert. +//! +//! Every retry needs a fresh slot and a fresh callback from [`CaptureSlot::new`]; a callback is +//! one-shot, and a slot ignores completions after its result was taken, cancelled or dropped. The +//! slot does not track whether a request is still open: keep that pending/closed distinction in the +//! application's request record. +//! +//! A completion that publishes its result just before a concurrent [`CaptureSlot::cancel`] or drop +//! can still deliver its single wakeup afterwards. That extra repaint is harmless: if the +//! cancellation won, the image is released and a later [`CaptureSlot::take`] returns `None`; if +//! `take` won first, the caller already owns the result and nothing else changes. A completion that +//! observes a cancelled or taken slot stores no image and does not wake. Cancellation and completion +//! are therefore not atomic with respect to the wakeup, and this module never waits for another +//! thread while holding the slot lock. +//! +//! [`CaptureSlot`] holds a strong [`egui::Context`]. Keep it in the application's request record; +//! storing it in `Context`-owned data (`egui::Memory::data` or a registered plugin) forms a +//! `Context` → slot → `Context` cycle that keeps both alive. + +use std::mem::size_of; +use std::sync::{Arc, Mutex, MutexGuard, PoisonError, Weak}; + +use egui::{Color32, ColorImage, Context, ScreenshotCallback, ViewportId}; + +/// Why a completed screenshot was rejected and released. +/// +/// The enum is `#[non_exhaustive]`: consumers should match the known variants and use a wildcard +/// arm for a future rejection reason. +#[non_exhaustive] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum CaptureError { + /// The checked `width * height` pixel count, or its `width * height * size_of::()` + /// byte count, overflowed `usize`. + DimensionsOverflow { width: usize, height: usize }, + /// The pixel buffer does not match the reported image dimensions, or the image has zero width + /// or height. + MalformedImage { width: usize, height: usize, pixels: usize }, + /// The checked image size exceeds the slot's per-image byte bound. + ImageTooLarge { bytes: usize, max_bytes: usize }, +} + +impl core::fmt::Display for CaptureError { + /// Format a human-readable rejection reason. The wording is informative only and is not an + /// API contract; the variants keep checked-overflow, malformed-image and size-cap cases + /// distinguishable. + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + Self::DimensionsOverflow { width, height } => { + write!(f, "screenshot dimensions {width}×{height} overflow the checked pixel or byte count") + } + Self::MalformedImage { width, height, pixels } => write!(f, "screenshot has {pixels} pixels for its {width}×{height} dimensions"), + Self::ImageTooLarge { bytes, max_bytes } => write!(f, "screenshot uses {bytes} bytes, over the {max_bytes}-byte per-image limit"), + } + } +} + +impl std::error::Error for CaptureError {} + +enum SlotState { + Pending, + Ready(Result, CaptureError>), + Taken, + Cancelled, +} + +struct Shared { + state: Mutex, + /// The live request owns the strong context; the callback only upgrades it briefly to wake. + context: Context, + viewport: ViewportId, + max_image_bytes: usize, +} + +/// The live request side of a capture. Keep it alive until the result is taken or the request is +/// cancelled; dropping it cancels the completion and releases any retained image. +/// +/// This type is `Send + Sync`; the application may hold it in its request record and poll +/// [`Self::take`] from its logic pass. Do not store it in `Context`-owned storage: the slot holds a +/// strong [`egui::Context`], so `egui::Memory::data` or a registered plugin would create a cycle. +#[must_use = "the slot must be kept alive to receive and take the screenshot"] +pub struct CaptureSlot { + shared: Arc, +} + +impl CaptureSlot { + /// Create a completion slot and its one-shot callback. + /// + /// `max_image_bytes` bounds the single retained image only. The application must separately + /// reserve its aggregate in-flight/completed budget before issuing the request. + /// + /// This function does not send a viewport command. If the request is issued in a UI pass, send + /// the callback with [`egui::ViewportCommand::Screenshot`]; a pending screenshot command itself + /// requests the paint needed while the window is hidden. Issue that command at most once per + /// slot, after the application has settled the frame it wants; every retry needs a fresh slot + /// and callback. + pub fn new(context: &Context, viewport: ViewportId, max_image_bytes: usize) -> (Self, ScreenshotCallback) { + let shared = Arc::new(Shared { state: Mutex::new(SlotState::Pending), context: context.clone(), viewport, max_image_bytes }); + let weak = Arc::downgrade(&shared); + let callback = ScreenshotCallback::new(move |image| complete(&weak, image)); + (Self { shared }, callback) + } + + /// Take the completed result, at most once. + /// + /// Returns `None` while the capture is pending, after it was cancelled or dropped, and after a + /// previous call already took the image or error. The slot cannot distinguish those states; + /// the application's request record owns the pending/closed distinction. Invalid images are + /// returned as an error so the application can report completion failure with its own request + /// identity. + pub fn take(&self) -> Option, CaptureError>> { + let mut state = lock(&self.shared.state); + if !matches!(&*state, SlotState::Ready(_)) { + return None; + } + match core::mem::replace(&mut *state, SlotState::Taken) { + SlotState::Ready(result) => Some(result), + _ => None, + } + } + + /// Cancel the request and release any completed image. + /// + /// A completion that published its result before this call may still deliver one harmless + /// repaint afterwards; the slot retains no image and a later [`Self::take`] returns `None`. A + /// completion that observes the cancellation stores no image and does not wake. Calling `cancel` + /// after [`Self::take`] is harmless. Any retained image is dropped after the slot mutex is + /// unlocked. + pub fn cancel(&self) { + close(&self.shared); + } + + #[cfg(test)] + /// Nonblocking probe used by the wakeup test to prove that the slot mutex is free while the + /// repaint observer runs. + fn lock_is_free(&self) -> bool { + self.shared.state.try_lock().is_ok() + } + + #[cfg(test)] + /// Count strong references to the shared slot state, proving callbacks retain none. + fn state_strong_count(&self) -> usize { + Arc::strong_count(&self.shared) + } + + #[cfg(test)] + /// A weak handle to the shared state, used to inject a second completion directly when egui has + /// already consumed the public callback. + fn state_weak(&self) -> Weak { + Arc::downgrade(&self.shared) + } +} + +impl Drop for CaptureSlot { + /// Cancel the request as the slot goes away. A later completion upgrades no live state and + /// releases its image, a retained ready image is dropped, and no repaint is requested. Results + /// already taken by the caller are unaffected. + fn drop(&mut self) { + close(&self.shared); + } +} + +impl core::fmt::Debug for CaptureSlot { + /// Format only the viewport and omit the remaining fields. The retained image and error payload + /// are deliberately hidden so logging cannot hold or dump screenshot contents. + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.debug_struct("CaptureSlot").field("viewport", &self.shared.viewport).finish_non_exhaustive() + } +} + +/// Lock the slot state, recovering from poisoning instead of panicking. The guard must be +/// released before entering the egui context or a repaint observer; completion and close do so +/// before waking the viewport. +fn lock(state: &Mutex) -> MutexGuard<'_, SlotState> { + state.lock().unwrap_or_else(PoisonError::into_inner) +} + +/// Mark the slot closed and drop any retained image after releasing the mutex. +fn close(shared: &Shared) { + let previous = { + let mut state = lock(&shared.state); + core::mem::replace(&mut *state, SlotState::Cancelled) + }; + drop(previous); +} + +/// Validate a completed image, store it, and wake the owning viewport. +/// +/// The slot lock is released before calling into the context, so a repaint observer may call +/// [`CaptureSlot::take`] or [`CaptureSlot::cancel`] re-entrantly. Inside an observer, only consume or +/// release that value; any further `Context` access must happen outside the observer. +/// [`egui::Context::request_repaint_of`] takes egui's context lock. Ordinary `Ui` closures and egui +/// 0.37 plugin hooks run outside that lock, as do renderer/worker callbacks. Repaint observers and +/// request-repaint callbacks run under it: completing from either would deadlock when requesting +/// the repaint. This function never waits under the slot lock. +fn complete(weak: &Weak, image: Arc) { + let Some(shared) = weak.upgrade() else { + // The request was dropped; the image is released here without a reply. + return; + }; + let result = checked_image(image, shared.max_image_bytes); + let should_wake = { + let mut state = lock(&shared.state); + if matches!(&*state, SlotState::Pending) { + *state = SlotState::Ready(result); + true + } else { + // Cancelled, already taken, or (defensively) completed twice: drop the image. + false + } + }; + // The slot lock is released before calling into the context, so a repaint observer may take + // the result or cancel the request re-entrantly without deadlocking. + if should_wake { + shared.context.request_repaint_of(shared.viewport); + } +} + +/// Validate `image` against the slot's per-image byte bound before publishing it. +/// +/// Zero width or height is malformed before any arithmetic; the pixel count and its byte size use +/// checked multiplication; the buffer length must equal `width * height`; and only then is the +/// byte count compared with `max_image_bytes`, rejecting a count greater than it (equality is +/// accepted). `max_image_bytes` bounds this one image, not an aggregate request budget. Returns the +/// same `Arc` without waking the viewport or requesting a repaint. +fn checked_image(image: Arc, max_image_bytes: usize) -> Result, CaptureError> { + let [width, height] = image.size; + if width == 0 || height == 0 { + return Err(CaptureError::MalformedImage { width, height, pixels: image.pixels.len() }); + } + let pixels = width.checked_mul(height).ok_or(CaptureError::DimensionsOverflow { width, height })?; + let bytes = pixels.checked_mul(size_of::()).ok_or(CaptureError::DimensionsOverflow { width, height })?; + if image.pixels.len() != pixels { + return Err(CaptureError::MalformedImage { width, height, pixels: image.pixels.len() }); + } + if bytes > max_image_bytes { + return Err(CaptureError::ImageTooLarge { bytes, max_bytes: max_image_bytes }); + } + Ok(image) +} + +#[cfg(test)] +mod tests; diff --git a/crates/ui-egui/src/capture/tests.rs b/crates/ui-egui/src/capture/tests.rs new file mode 100644 index 000000000..dd666d719 --- /dev/null +++ b/crates/ui-egui/src/capture/tests.rs @@ -0,0 +1,491 @@ +use std::sync::atomic::{AtomicBool, Ordering}; +use std::sync::{Arc, Barrier}; + +use super::*; + +/// Allocate a filled `Arc` fixture of `size` with every pixel set to `color`. +fn image(size: [usize; 2], color: egui::Color32) -> Arc { + Arc::new(ColorImage::filled(size, color)) +} + +/// Install a repaint observer and return the viewport requests it records. +fn observe_repaints(ctx: &Context) -> Arc>> { + let requests = Arc::new(Mutex::new(Vec::new())); + let observed = requests.clone(); + ctx.set_repaint_observer(move |info| observed.lock().unwrap().push(info.viewport_id)); + requests +} + +#[test] +/// Compile-time assertion that `CaptureSlot` and `ScreenshotCallback` are `Send + Sync`. +fn slot_is_send_and_sync() { + /// Compile-time helper requiring `T: Send + Sync`; the enclosing test uses it to + /// assert the public capture types are thread-safe. + fn assert_send_sync() {} + assert_send_sync::(); + assert_send_sync::(); +} + +#[test] +/// Two independent slots for different viewports may complete in reverse order; each `take` +/// returns exactly its own image and dimensions. +fn distinct_requests_complete_in_reverse_order() { + let ctx = Context::default(); + let first_viewport = ViewportId::from_hash_of("first-window"); + let second_viewport = ViewportId::from_hash_of("second-window"); + let (first, first_callback) = CaptureSlot::new(&ctx, first_viewport, 1024); + let (second, second_callback) = CaptureSlot::new(&ctx, second_viewport, 1024); + let first_image = image([2, 1], egui::Color32::RED); + let second_image = image([1, 3], egui::Color32::BLUE); + + // The renderer may answer the later request first. + second_callback.complete(second_image.clone()); + first_callback.complete(first_image.clone()); + + let taken_first = first.take().unwrap().unwrap(); + let taken_second = second.take().unwrap().unwrap(); + assert!(Arc::ptr_eq(&taken_first, &first_image)); + assert!(Arc::ptr_eq(&taken_second, &second_image)); + assert_eq!(taken_first.size, [2, 1]); + assert_eq!(taken_second.size, [1, 3]); +} + +#[test] +/// Slots keep separate results and byte caps: a 2×2 image over the first slot's 4-byte cap is +/// rejected as too large while the second stays pending, then the second accepts its own image and +/// a taken slot remains empty. +fn slots_do_not_share_results_or_byte_bounds() { + let ctx = Context::default(); + let first_viewport = ViewportId::from_hash_of("first-slot"); + let second_viewport = ViewportId::from_hash_of("second-slot"); + let (first, first_callback) = CaptureSlot::new(&ctx, first_viewport, 4); + let (second, second_callback) = CaptureSlot::new(&ctx, second_viewport, 16); + + let rejected_for_first = image([2, 2], egui::Color32::RED); + first_callback.complete(rejected_for_first); + + assert!(second.take().is_none(), "completing one slot leaves the other pending"); + assert!(matches!(first.take(), Some(Err(CaptureError::ImageTooLarge { bytes: 16, max_bytes: 4 })))); + + let accepted_for_second = image([2, 2], egui::Color32::BLUE); + second_callback.complete(accepted_for_second.clone()); + assert!(Arc::ptr_eq(&second.take().unwrap().unwrap(), &accepted_for_second)); + assert!(first.take().is_none(), "a taken slot stays empty"); +} + +#[test] +/// Cloned callbacks share one completion: the first result wins, the losing image is released, and +/// `take` yields the result only once. +fn callback_clones_share_one_completion_and_take_is_single_use() { + let ctx = Context::default(); + let (slot, callback) = CaptureSlot::new(&ctx, ViewportId::ROOT, 1024); + let duplicate = callback.clone(); + let first_image = image([1, 1], egui::Color32::RED); + let second_image = image([1, 1], egui::Color32::BLUE); + let weak_loser = Arc::downgrade(&second_image); + + callback.complete(first_image.clone()); + duplicate.complete(second_image); + assert!(weak_loser.upgrade().is_none(), "the losing completion releases its image"); + + let taken = slot.take().unwrap().unwrap(); + assert!(Arc::ptr_eq(&taken, &first_image), "the first completion wins"); + assert!(slot.take().is_none(), "the result is taken once"); +} + +#[test] +/// After `take`, both a duplicate callback and a direct completion release their images without +/// storing a result or requesting a repaint. +fn duplicate_completion_after_take_neither_stores_nor_wakes() { + let ctx = Context::default(); + let requests = observe_repaints(&ctx); + let (slot, callback) = CaptureSlot::new(&ctx, ViewportId::ROOT, 1024); + let duplicate_callback = callback.clone(); + let first_image = image([1, 1], egui::Color32::RED); + callback.complete(first_image.clone()); + assert!(Arc::ptr_eq(&slot.take().unwrap().unwrap(), &first_image)); + assert_eq!(requests.lock().unwrap().len(), 1, "the first completion wakes"); + + let duplicate_image = image([1, 1], egui::Color32::BLUE); + let weak_duplicate = Arc::downgrade(&duplicate_image); + duplicate_callback.complete(duplicate_image); + + assert!(weak_duplicate.upgrade().is_none(), "a duplicate after take is released"); + assert!(slot.take().is_none()); + assert_eq!(requests.lock().unwrap().len(), 1, "a duplicate after take does not wake"); + + // Deliver a second completion straight to the slot; egui already consumed its callback. + let direct_image = image([1, 1], egui::Color32::GREEN); + let weak_direct = Arc::downgrade(&direct_image); + complete(&slot.state_weak(), direct_image); + assert!(weak_direct.upgrade().is_none(), "a direct second completion after take is released"); + assert!(slot.take().is_none()); + assert_eq!(requests.lock().unwrap().len(), 1, "a direct second completion after take does not wake"); +} + +#[test] +/// An early `take` returns `None` without closing the request; a later completion still delivers. +fn take_before_completion_is_empty_and_keeps_the_request_open() { + let ctx = Context::default(); + let (slot, callback) = CaptureSlot::new(&ctx, ViewportId::ROOT, 1024); + assert!(slot.take().is_none()); + let expected = image([1, 1], egui::Color32::RED); + callback.complete(expected.clone()); + assert!(Arc::ptr_eq(&slot.take().unwrap().unwrap(), &expected)); +} + +#[test] +/// Cancelling before completion releases a late image, leaves `take` empty, and suppresses the +/// repaint wakeup. +fn cancel_releases_late_images_without_waking() { + let ctx = Context::default(); + let requests = observe_repaints(&ctx); + let viewport = ViewportId::from_hash_of("cancelled-window"); + let (slot, callback) = CaptureSlot::new(&ctx, viewport, 1024); + slot.cancel(); + + let late_image = image([2, 2], egui::Color32::RED); + let weak_image = Arc::downgrade(&late_image); + callback.complete(late_image.clone()); + drop(late_image); + + assert!(weak_image.upgrade().is_none(), "a cancelled slot releases the late image"); + assert!(slot.take().is_none()); + assert!(requests.lock().unwrap().is_empty(), "cancellation suppresses the wakeup"); +} + +#[test] +/// A ready slot retains its image and has woken once; `cancel` releases the image and does not wake +/// again. +fn cancel_after_ready_releases_the_image() { + let ctx = Context::default(); + let requests = observe_repaints(&ctx); + let (slot, callback) = CaptureSlot::new(&ctx, ViewportId::ROOT, 1024); + let completed = image([2, 2], egui::Color32::RED); + let weak_image = Arc::downgrade(&completed); + callback.complete(completed.clone()); + drop(completed); + assert!(weak_image.upgrade().is_some(), "the ready slot retains the image"); + assert_eq!(requests.lock().unwrap().len(), 1, "the completion woke the viewport"); + + slot.cancel(); + + assert!(weak_image.upgrade().is_none(), "cancel releases a ready image"); + assert!(slot.take().is_none()); + assert_eq!(requests.lock().unwrap().len(), 1, "cancellation itself does not wake"); +} + +#[test] +/// Dropping the slot releases an image that is only retained by the completed slot. +fn dropping_the_slot_releases_a_completed_image() { + let ctx = Context::default(); + let (slot, callback) = CaptureSlot::new(&ctx, ViewportId::ROOT, 1024); + let completed = image([2, 2], egui::Color32::RED); + callback.complete(completed.clone()); + let weak_image = Arc::downgrade(&completed); + drop(completed); + assert!(weak_image.upgrade().is_some(), "the slot retains the completed image"); + + drop(slot); + assert!(weak_image.upgrade().is_none(), "dropping the slot releases its image"); +} + +#[test] +/// A completion after the slot is dropped releases the image and does not wake the viewport. +fn late_completion_after_drop_is_inert() { + let ctx = Context::default(); + let requests = observe_repaints(&ctx); + let viewport = ViewportId::ROOT; + let (slot, callback) = CaptureSlot::new(&ctx, viewport, 1024); + drop(slot); + + let late_image = image([1, 1], egui::Color32::RED); + let weak_image = Arc::downgrade(&late_image); + callback.complete(late_image.clone()); + drop(late_image); + + assert!(weak_image.upgrade().is_none()); + assert!(requests.lock().unwrap().is_empty(), "a late result does not wake the viewport"); +} + +#[test] +/// Callbacks hold only a weak reference: the slot state has one strong owner, dropping the slot +/// releases the context and state, and a later completion is inert. +fn callback_retains_only_a_weak_reference_to_live_state() { + let ctx = Context::default(); + let requests = observe_repaints(&ctx); + let (slot, callback) = CaptureSlot::new(&ctx, ViewportId::ROOT, 1024); + let callback_clone = callback.clone(); + assert_eq!(slot.state_strong_count(), 1, "the callback must not own the slot state"); + + let weak_state = slot.state_weak(); + drop(slot); + assert!(weak_state.upgrade().is_none(), "dropping the slot releases its context and state"); + + let late_image = image([1, 1], egui::Color32::RED); + let weak_image = Arc::downgrade(&late_image); + callback_clone.complete(late_image.clone()); + drop(late_image); + assert!(weak_image.upgrade().is_none()); + assert!(requests.lock().unwrap().is_empty()); +} + +#[test] +/// A completion distinguishes the per-image size cap, a malformed pixel buffer, and overflow of +/// the pixel or byte count; a returned error is taken at most once. +fn rejects_oversized_malformed_and_overflowing_images() { + let ctx = Context::default(); + + let (slot, callback) = CaptureSlot::new(&ctx, ViewportId::ROOT, 16); + callback.complete(image([3, 3], egui::Color32::RED)); + assert!(matches!(slot.take(), Some(Err(CaptureError::ImageTooLarge { bytes: 36, max_bytes: 16 })))); + assert!(slot.take().is_none(), "a completion error is reported once"); + + let (slot, callback) = CaptureSlot::new(&ctx, ViewportId::ROOT, 1024); + callback.complete(Arc::new(ColorImage { size: [2, 2], source_size: egui::Vec2::ZERO, pixels: vec![egui::Color32::RED; 3] })); + assert!(matches!(slot.take(), Some(Err(CaptureError::MalformedImage { width: 2, height: 2, pixels: 3 })))); + + let (slot, callback) = CaptureSlot::new(&ctx, ViewportId::ROOT, 1024); + callback.complete(Arc::new(ColorImage { size: [usize::MAX, 2], source_size: egui::Vec2::ZERO, pixels: Vec::new() })); + assert!(matches!(slot.take(), Some(Err(CaptureError::DimensionsOverflow { width, height })) if width == usize::MAX && height == 2)); + + // The pixel count fits but the byte count does not. + let wide = usize::MAX / 2; + let (slot, callback) = CaptureSlot::new(&ctx, ViewportId::ROOT, 1024); + callback.complete(Arc::new(ColorImage { size: [wide, 1], source_size: egui::Vec2::ZERO, pixels: Vec::new() })); + assert!(matches!(slot.take(), Some(Err(CaptureError::DimensionsOverflow { width, height })) if width == wide && height == 1)); +} + +#[test] +/// Oversized and malformed images are dropped immediately and each rejection still wakes the error +/// consumer exactly once before `take` reports it. +fn rejected_oversized_and_malformed_images_are_released_before_take() { + let ctx = Context::default(); + let requests = observe_repaints(&ctx); + + let (slot, callback) = CaptureSlot::new(&ctx, ViewportId::ROOT, 16); + let oversized = image([3, 3], egui::Color32::RED); + let weak_oversized = Arc::downgrade(&oversized); + callback.complete(oversized); + assert!(weak_oversized.upgrade().is_none(), "an oversized image is released"); + assert_eq!(*requests.lock().unwrap(), [ViewportId::ROOT], "rejection wakes the error consumer"); + assert!(matches!(slot.take(), Some(Err(CaptureError::ImageTooLarge { bytes: 36, max_bytes: 16 })))); + + let (slot, callback) = CaptureSlot::new(&ctx, ViewportId::ROOT, 1024); + let malformed = Arc::new(ColorImage { size: [2, 2], source_size: egui::Vec2::ZERO, pixels: vec![egui::Color32::RED; 3] }); + let weak_malformed = Arc::downgrade(&malformed); + callback.complete(malformed); + assert!(weak_malformed.upgrade().is_none(), "a malformed image is released"); + assert_eq!(*requests.lock().unwrap(), [ViewportId::ROOT, ViewportId::ROOT]); + assert!(matches!(slot.take(), Some(Err(CaptureError::MalformedImage { width: 2, height: 2, pixels: 3 })))); +} + +#[test] +/// Any zero width or height is rejected as malformed before overflow or size-cap decisions, even +/// for extreme extents such as `usize::MAX × 0`. +fn zero_area_images_are_rejected_even_with_extreme_extents() { + let ctx = Context::default(); + + for size in [[0, 4], [4, 0], [0, 0], [usize::MAX, 0], [0, usize::MAX]] { + let (slot, callback) = CaptureSlot::new(&ctx, ViewportId::ROOT, 1024); + callback.complete(Arc::new(ColorImage { size, source_size: egui::Vec2::ZERO, pixels: Vec::new() })); + let rejected = slot.take(); + assert!( + matches!(rejected, Some(Err(CaptureError::MalformedImage { width, height, pixels })) + if width == size[0] && height == size[1] && pixels == 0), + "zero-area image {size:?} must be rejected" + ); + } +} + +#[test] +/// A 2×2 image at exactly the 16-byte cap is accepted: the bound is inclusive. +fn accepts_an_image_exactly_at_the_byte_bound() { + let ctx = Context::default(); + let (slot, callback) = CaptureSlot::new(&ctx, ViewportId::ROOT, 16); + let exact = image([2, 2], egui::Color32::GREEN); + callback.complete(exact.clone()); + assert!(Arc::ptr_eq(&slot.take().unwrap().unwrap(), &exact)); +} + +#[test] +/// A worker thread completes a child-window slot; every recorded wake belongs to that slot's +/// viewport and the expected image is delivered. +fn another_thread_completes_and_wakes_only_the_owning_viewport() { + let ctx = Context::default(); + let requests = observe_repaints(&ctx); + let viewport = ViewportId::from_hash_of("child-window"); + let (slot, callback) = CaptureSlot::new(&ctx, viewport, 1024); + let expected = image([1, 1], egui::Color32::RED); + let sent = expected.clone(); + + let handle = std::thread::spawn(move || callback.complete(sent)); + handle.join().unwrap(); + + let requested = requests.lock().unwrap(); + assert!(!requested.is_empty(), "completion wakes the owning viewport"); + assert!(requested.iter().all(|requested_viewport| *requested_viewport == viewport), "completion wakes only the owning viewport: {requested:?}"); + drop(requested); + assert!(Arc::ptr_eq(&slot.take().unwrap().unwrap(), &expected)); +} + +#[test] +/// The repaint observer can `take` the image re-entrantly: `try_lock` succeeds during the wakeup, +/// proving the slot lock is released before `request_repaint_of`. +fn wakeup_runs_after_the_slot_lock_is_released() { + let ctx = Context::default(); + let (slot, callback) = CaptureSlot::new(&ctx, ViewportId::ROOT, 1024); + let slot = Arc::new(slot); + let weak_slot = Arc::downgrade(&slot); + let observed = Arc::new(AtomicBool::new(false)); + let lock_free = Arc::new(AtomicBool::new(true)); + let taken = Arc::new(AtomicBool::new(false)); + let observer_observed = observed.clone(); + let observer_lock_free = lock_free.clone(); + let observer_taken = taken.clone(); + ctx.set_repaint_observer(move |info| { + if info.viewport_id == ViewportId::ROOT { + observer_observed.store(true, Ordering::SeqCst); + if let Some(slot) = weak_slot.upgrade() { + if slot.lock_is_free() { + observer_taken.store(slot.take().is_some(), Ordering::SeqCst); + } else { + observer_lock_free.store(false, Ordering::SeqCst); + } + } + } + }); + + callback.complete(image([1, 1], egui::Color32::RED)); + + assert!(observed.load(Ordering::SeqCst), "completion wakes the owning viewport"); + assert!(lock_free.load(Ordering::SeqCst), "the slot lock is released before the wakeup"); + assert!(taken.load(Ordering::SeqCst), "the observer can consume the image reentrantly"); + assert!(slot.take().is_none()); +} + +/// Complete, cancel and take all racing on one slot. Every interleaving must leave at most one +/// wake and at most one taken result, and every image must be released once the slot and result +/// are dropped. +#[test] +fn complete_cancel_and_take_race_without_retaining_or_double_waking() { + const RACE_TRIALS: usize = 100; + + for trial in 0..RACE_TRIALS { + let ctx = Context::default(); + let requests = observe_repaints(&ctx); + let viewport = ViewportId::from_hash_of("race-window"); + let (slot, callback) = CaptureSlot::new(&ctx, viewport, 4096); + let slot = Arc::new(slot); + let completed = image([1, 1], egui::Color32::RED); + let weak_image = Arc::downgrade(&completed); + let barrier = Arc::new(Barrier::new(3)); + + let taken = std::thread::scope(|scope| { + let completion_barrier = barrier.clone(); + let completion_image = completed.clone(); + scope.spawn(move || { + completion_barrier.wait(); + callback.complete(completion_image); + }); + + let cancel_barrier = barrier.clone(); + let cancel_slot = slot.clone(); + scope.spawn(move || { + cancel_barrier.wait(); + cancel_slot.cancel(); + }); + + barrier.wait(); + slot.take() + }); + + let wake_count = requests.lock().unwrap().len(); + assert!(wake_count <= 1, "trial {trial}: one completion wakes at most once, got {wake_count}"); + if taken.is_some() { + assert_eq!(wake_count, 1, "trial {trial}: a published result wakes exactly once"); + } + if let Some(result) = &taken { + match result { + Ok(taken_image) => assert!(Arc::ptr_eq(taken_image, &completed), "trial {trial}: only the completed image is returned"), + Err(error) => panic!("trial {trial}: a valid image was rejected: {error:?}"), + } + } + + drop(taken); + drop(slot); + drop(completed); + assert!(weak_image.upgrade().is_none(), "trial {trial}: the slot and any taken result release the image"); + } +} + +#[test] +/// A zero byte budget rejects any nonempty image as too large and wakes once. +fn zero_budget_rejects_a_nonempty_image_and_wakes() { + let ctx = Context::default(); + let requests = observe_repaints(&ctx); + let (slot, callback) = CaptureSlot::new(&ctx, ViewportId::ROOT, 0); + callback.complete(image([1, 1], egui::Color32::GREEN)); + assert!(matches!(slot.take(), Some(Err(CaptureError::ImageTooLarge { bytes: 4, max_bytes: 0 })))); + assert_eq!(*requests.lock().unwrap(), [ViewportId::ROOT]); +} + +#[test] +/// Two threads racing on `take` produce exactly one result, and a subsequent take is empty. +fn concurrent_takers_receive_the_result_exactly_once() { + let ctx = Context::default(); + let (slot, callback) = CaptureSlot::new(&ctx, ViewportId::ROOT, 4); + let expected = image([1, 1], egui::Color32::GREEN); + callback.complete(expected.clone()); + let barrier = Barrier::new(3); + let results = std::thread::scope(|scope| { + let first = scope.spawn(|| { + barrier.wait(); + slot.take() + }); + let second = scope.spawn(|| { + barrier.wait(); + slot.take() + }); + barrier.wait(); + [first.join().unwrap(), second.join().unwrap()] + }); + assert_eq!(results.iter().filter(|result| result.is_some()).count(), 1); + for result in results.into_iter().flatten() { + assert!(Arc::ptr_eq(&result.unwrap(), &expected)); + } + assert!(slot.take().is_none()); +} + +#[test] +/// A renderer thread can complete a capture while a UI closure is blocked; the image is delivered +/// and the owning child viewport is woken exactly once. +fn renderer_completion_during_a_live_ui_pass_can_wake_and_deliver() { + let ctx = Context::default(); + let requests = observe_repaints(&ctx); + let viewport = ViewportId::from_hash_of("render-readback"); + let (slot, callback) = CaptureSlot::new(&ctx, viewport, 4); + let expected = image([1, 1], egui::Color32::GREEN); + let sent = expected.clone(); + let (start_tx, start_rx) = std::sync::mpsc::channel(); + let (done_tx, done_rx) = std::sync::mpsc::channel(); + std::thread::scope(|scope| { + scope.spawn(move || { + start_rx.recv().unwrap(); + callback.complete(sent); + done_tx.send(()).unwrap(); + }); + let mut start_tx = Some(start_tx); + let mut output = ctx.run_ui(Default::default(), |ui| { + ui.label("A live frame while readback completes"); + if let Some(tx) = start_tx.take() { + tx.send(()).unwrap(); + done_rx.recv_timeout(std::time::Duration::from_secs(3)).expect("readback must complete while the UI closure is active"); + } + }); + // This synchronization test has no renderer to apply the atlas upload. + output.textures_delta.clear(); + }); + assert!(Arc::ptr_eq(&slot.take().unwrap().unwrap(), &expected)); + assert_eq!(requests.lock().unwrap().iter().filter(|id| **id == viewport).count(), 1); +} diff --git a/crates/ui-egui/src/combo_menu.rs b/crates/ui-egui/src/combo_menu.rs new file mode 100644 index 000000000..2dc8cb331 --- /dev/null +++ b/crates/ui-egui/src/combo_menu.rs @@ -0,0 +1,67 @@ +//! The drop-down menu of the ribbon's combo fields (font name and size): a menu under a field that +//! scrolls its rows and can keep a header (the filter field) in place above them. + +use egui::{Frame, Popup, PopupCloseBehavior, RectAlign, Response, ScrollArea, TextWrapMode, Ui}; + +/// A menu under a field that opens and closes on the field's clicks, closes on a click, and opens +/// below the field or above it, never beside it. +pub(crate) struct Menu<'a> { + popup: Popup<'a>, + field: egui::Rect, + height: f32, +} + +impl<'a> Menu<'a> { + /// The menu under `field`, a widget in `ui`. + pub(crate) fn new(ui: &Ui, field: &Response) -> Self { + let flipped: &'static [RectAlign] = if ui.ctx().global_style().right_to_left { &[RectAlign::TOP_END] } else { &[RectAlign::TOP_START] }; + Self { popup: Popup::menu(field).align_alternatives(flipped), field: field.rect, height: ui.spacing().combo_height } + } + + /// The most height of the menu's contents, inside its frame; the room on the field's roomier + /// side caps it. + pub(crate) fn height(mut self, height: f32) -> Self { + self.height = height; + self + } + + /// Shows `add` in the menu while it is open, scrolling when it is taller than the menu. + /// Returns what `add` returned, or `None` while the menu is closed. + pub(crate) fn show_ui(self, add: impl FnOnce(&mut Ui) -> R) -> Option { + self.show(|_| (), |ui, ()| add(ui)) + } + + /// Shows `header` at the top of the menu and `list` under it while the menu is open, and + /// returns what `list` returned. `list` gets what `header` returned. Only `list` scrolls; the + /// header stays in place. + pub(crate) fn show_ui_with_header(self, header: impl FnOnce(&mut Ui) -> H, list: impl FnOnce(&mut Ui, H) -> R) -> Option { + self.show(header, list) + } + + fn show(self, header: impl FnOnce(&mut Ui) -> H, list: impl FnOnce(&mut Ui, H) -> R) -> Option { + let Self { popup, field, height } = self; + let ctx = popup.ctx().clone(); + let screen = ctx.content_rect(); + let room = (screen.bottom() - field.bottom()).max(field.top() - screen.top()); + let style = egui::style::StyleModifier::from(egui::containers::menu::menu_style); + let mut popup_style = (*ctx.global_style()).clone(); + style.apply(&mut popup_style); + let frame = Frame::popup(&popup_style).total_margin().sum().y; + let height = height.min(room - frame).max(0.0); + popup + .width(field.width()) + .style(style) + .close_behavior(PopupCloseBehavior::CloseOnClick) + .show(|ui| { + ui.set_min_width(ui.available_width()); + // egui offers the popup last pass's height; offer the full height so a list that + // shrank (a filter with no matches) grows back. + ui.set_max_height(height); + let header = header(ui); + // Labels widen a narrow menu rather than wrap early, as in egui's combo box. + ui.style_mut().wrap_mode = Some(TextWrapMode::Extend); + ScrollArea::vertical().max_height(ui.available_height().max(0.0)).show(ui, |ui| list(ui, header)).inner + }) + .map(|shown| shown.inner) + } +} diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rs index 75ccf2f4b..85eeb1704 100644 --- a/crates/ui-egui/src/control.rs +++ b/crates/ui-egui/src/control.rs @@ -19,7 +19,7 @@ use std::sync::mpsc::Sender; -use craft_ui::capture::CaptureSlot; +use crate::capture::CaptureSlot; use gridcraft_engine::core::CellRef; use serde_json::{Value as Json, json}; diff --git a/crates/ui-egui/src/control_ui.rs b/crates/ui-egui/src/control_ui.rs index a44442942..f099752c0 100644 --- a/crates/ui-egui/src/control_ui.rs +++ b/crates/ui-egui/src/control_ui.rs @@ -50,7 +50,7 @@ pub fn place(app: &mut SheetApp, ui: &Ui, resp: &egui::Response, geo: &Geo, sh: return false; }; let ctx = ui.ctx().clone(); - if ctx.input(|i| i.key_pressed(egui::Key::Escape)) { + if crate::framework::escape_pressed(&ctx) { app.grid.placing = None; app.grid.place_start = None; return true; diff --git a/crates/ui-egui/src/dialogs/ref_edit.rs b/crates/ui-egui/src/dialogs/ref_edit.rs index 30dc899d3..551012cf1 100644 --- a/crates/ui-egui/src/dialogs/ref_edit.rs +++ b/crates/ui-egui/src/dialogs/ref_edit.rs @@ -186,7 +186,7 @@ pub(super) fn place_window<'a>( // Escape and Enter are used up either way: left in the frame's input, the dialog would // read them as its own and close or confirm. When another field owned them, that field // (drawn before the dialogs) has read them already, and nothing more happens here. - if ctx.input_mut(|i| i.consume_key(egui::Modifiers::NONE, egui::Key::Escape) | i.consume_key(egui::Modifiers::NONE, egui::Key::Enter)) { + if crate::framework::consume_escape(&ctx) | ctx.input_mut(|i| i.consume_key(egui::Modifiers::NONE, egui::Key::Enter)) { if !other_field { d.refs.collapsed = None; } diff --git a/crates/ui-egui/src/dialogs/show.rs b/crates/ui-egui/src/dialogs/show.rs index 0482aa0a7..e1f6981ce 100644 --- a/crates/ui-egui/src/dialogs/show.rs +++ b/crates/ui-egui/src/dialogs/show.rs @@ -400,7 +400,7 @@ pub fn show(app: &mut SheetApp, ctx: &egui::Context) { open_url(&u); } } - if ctx.input(|i| i.key_pressed(Key::Escape)) || !win_open { + if crate::framework::escape_pressed(&ctx) || !win_open { // In Solver Options, Escape (or closing the window) cancels the options only. if in_solver_options(&d) { cancel_solver_options(&mut d); diff --git a/crates/ui-egui/src/doc_windows.rs b/crates/ui-egui/src/doc_windows.rs index 7bf3a799d..904563c3b 100644 --- a/crates/ui-egui/src/doc_windows.rs +++ b/crates/ui-egui/src/doc_windows.rs @@ -18,10 +18,12 @@ //! //! [`Session::windows`]: gridcraft_engine::Session::windows -use craft_window::{CASCADE_STEP, Frame, Rect, Viewports, WindowEvent, WindowId, WindowList, cascade}; +use craft_window::{WindowId, WindowList}; +use egui::Rect; use serde_json::json; use crate::SheetApp; +use crate::viewports::{CASCADE_STEP, Viewports, WindowEvent}; /// The native windows (see the module docs). pub struct DocWindows { @@ -40,8 +42,7 @@ impl DocWindows { /// Takes over `app`'s windows. `base` is the root window's builder, used for new windows. pub fn new(app: &mut SheetApp, base: egui::ViewportBuilder, quit_with_last_window: bool) -> DocWindows { app.native_windows = true; - // The root window keeps the desktop's frame, so every window does. - DocWindows { list: WindowList::new(), viewports: Viewports::new(Frame::Desktop), base, quit_with_last_window, root_hidden: false } + DocWindows { list: WindowList::new(), viewports: Viewports::default(), base, quit_with_last_window, root_hidden: false } } /// The platform default for the last window closing: macOS keeps running, others quit. @@ -91,7 +92,7 @@ impl DocWindows { let (monitor, infos) = ctx.input(|i| (i.viewport().monitor_size, i.raw.viewports.clone())); // Platforms that don't report the monitor (Wayland, tests) get a common laptop screen. let size = monitor.filter(|m| m.x > 0.0 && m.y > 0.0).unwrap_or(egui::vec2(1280.0, 800.0)); - let mut rects = arrange_rects(arrange, ids.len(), Rect::new(0.0, 0.0, size.x, size.y)); + let mut rects = arrange_rects(arrange, ids.len(), Rect::from_min_size(egui::Pos2::ZERO, size)); if arrange == "cascade" { // The active window goes in front: the last step of the cascade. rects.reverse(); @@ -100,8 +101,8 @@ impl DocWindows { let vp = self.viewports.viewport_id(*id); // Inner size is what can be set: take off the frame the window has now. let frame = infos.get(&vp).and_then(|v| Some(v.outer_rect?.size() - v.inner_rect?.size())).unwrap_or(egui::Vec2::ZERO); - ctx.send_viewport_cmd_to(vp, egui::ViewportCommand::OuterPosition(egui::pos2(r.x, r.y))); - ctx.send_viewport_cmd_to(vp, egui::ViewportCommand::InnerSize((egui::vec2(r.width, r.height) - frame).max(egui::vec2(240.0, 160.0)))); + ctx.send_viewport_cmd_to(vp, egui::ViewportCommand::OuterPosition(r.min)); + ctx.send_viewport_cmd_to(vp, egui::ViewportCommand::InnerSize((r.size() - frame).max(egui::vec2(240.0, 160.0)))); } if let Some(first) = ids.first() { self.viewports.focus(ctx, *first); @@ -123,7 +124,7 @@ impl DocWindows { // The window the engine brought forward, else the most recently focused. let next = app.session.active_window().and_then(|w| self.find(w)).or_else(|| self.list.active()); match next { - Some(id) => self.viewports.adopt(ctx, &self.list, id), + Some(id) => self.viewports.adopt(ctx, id), None => self.viewports.set_root(None), } } @@ -205,7 +206,7 @@ impl DocWindows { match event { WindowEvent::Focused(_) => {} WindowEvent::CloseRequested(id) => { - if let Some(w) = self.close_requested(app, &ctx, id) { + if let Some(w) = self.close_requested(app, id) { requested = Some(w); } } @@ -228,16 +229,13 @@ impl DocWindows { /// A window's close button. Returns the window to bring forward when the close needs an /// answer (or moved focus); `None` when nothing changed. - fn close_requested(&mut self, app: &mut SheetApp, ctx: &egui::Context, id: WindowId) -> Option { - let is_root = self.viewports.root() == Some(id); + /// The root window's close request is held by the app's close path ([`SheetApp::close_decision`]), + /// so closing it closes only its workbook window, as for any other window. + fn close_requested(&mut self, app: &mut SheetApp, id: WindowId) -> Option { if app.allow_close { // Quitting: every workbook has been answered for; the root's close ends the app. return None; } - if is_root { - // eframe would end the app with the root window; closing it is the app's decision. - ctx.send_viewport_cmd_to(egui::ViewportId::ROOT, egui::ViewportCommand::CancelClose); - } let window = *self.list.get(id)?; app.enter_window(window); app.run_or_alert("window.close", json!({"window": window})); @@ -271,34 +269,28 @@ pub fn arrange_rects(arrange: &str, n: usize, bounds: Rect) -> Vec { let count = n as f32; match arrange { "horizontal" => { - let h = bounds.height / count; - (0..n).map(|i| Rect::new(bounds.x, bounds.y + h * i as f32, bounds.width, h)).collect() + let h = bounds.height() / count; + (0..n).map(|i| Rect::from_min_size(bounds.min + egui::vec2(0.0, h * i as f32), egui::vec2(bounds.width(), h))).collect() } "vertical" => { - let w = bounds.width / count; - (0..n).map(|i| Rect::new(bounds.x + w * i as f32, bounds.y, w, bounds.height)).collect() + let w = bounds.width() / count; + (0..n).map(|i| Rect::from_min_size(bounds.min + egui::vec2(w * i as f32, 0.0), egui::vec2(w, bounds.height()))).collect() } "cascade" => { let shift = CASCADE_STEP * (count - 1.0); - let size = [(bounds.width - shift).max(bounds.width * 0.5), (bounds.height - shift).max(bounds.height * 0.5)]; - let mut previous = Rect::new(bounds.x - CASCADE_STEP, bounds.y - CASCADE_STEP, size[0], size[1]); - (0..n) - .map(|_| { - previous = cascade(previous, size, bounds, CASCADE_STEP); - previous - }) - .collect() + let size = egui::vec2((bounds.width() - shift).max(bounds.width() * 0.5), (bounds.height() - shift).max(bounds.height() * 0.5)); + craft_behavior::placement::cascade_rects(bounds, size, n, CASCADE_STEP) } _ => { let cols = (count.sqrt().ceil() as usize).max(1); let rows = n.div_ceil(cols); - let h = bounds.height / rows as f32; + let h = bounds.height() / rows as f32; (0..n) .map(|i| { let (row, col) = (i / cols, i % cols); let in_row = if row + 1 == rows { n - row * cols } else { cols }; - let w = bounds.width / in_row as f32; - Rect::new(bounds.x + w * col as f32, bounds.y + h * row as f32, w, h) + let w = bounds.width() / in_row as f32; + Rect::from_min_size(bounds.min + egui::vec2(w * col as f32, h * row as f32), egui::vec2(w, h)) }) .collect() } diff --git a/crates/ui-egui/src/framework.rs b/crates/ui-egui/src/framework.rs new file mode 100644 index 000000000..357cdef3b --- /dev/null +++ b/crates/ui-egui/src/framework.rs @@ -0,0 +1,149 @@ +//! The craft-ui runtime, hosted from GridCraft's own eframe `App` (craft-libs docs/craft-framework.md, section 2.2). +//! The desktop app calls [`install`] once, [`SheetApp::before_input`] in `raw_input_hook`, [`SheetApp::close_path`] +//! last in `logic`, and [`before_ui`] first in `ui`; the browser build and tests install with [`install_headless`]. +//! The framework dialogs run on [`SheetApp::framework_dialogs`] after GridCraft's own UI. +//! +//! The runtime takes Escape, Tab and the clipboard events for the whole window unless one of GridCraft's own egui +//! widgets has the keyboard. The window's Escape is read with [`escape_pressed`] and taken with [`consume_escape`]; +//! the grid is declared to the runtime with [`host_canvas`], which keeps Tab, the edit chords and the clipboard +//! events in egui's input for GridCraft's shortcuts. + +use std::sync::{Arc, OnceLock}; + +use craft_host::target::ShellInfo; +use craft_host::{AppInfo, Host}; +use craft_keymap::Overrides; +use craft_ui::fonts::{I18nScripts, SystemFonts, UiFonts}; +use craft_ui::runtime::commands::{CommandInput, CommandSet as _, QuitCommand}; +use craft_ui::runtime::env::{RootEnv, Scale}; +use craft_ui::runtime::focus::{EditSet, KeepKeys, KeyUse}; +use craft_ui::runtime::frame::{FrameInput, FrameOutput}; +use craft_ui::runtime::keys::{Intent, with_window_intents}; +use craft_ui::shell::embed; +use craft_window::system::WindowSystem; + +use crate::SheetApp; + +/// Each pass of the root window, first in `App::ui`: hands the runtime the native window it answers the hit test of +/// (Windows) and fits the window to its monitor once. +#[cfg(not(target_arch = "wasm32"))] +pub use craft_ui::shell::embed::before_ui; + +/// The id every OS window of the app carries, as the main window's builder sets it. +const APP_ID: &str = "ai.storyteller.gridcraft"; + +/// The scripts of the interface languages, for the font stack. +static SCRIPTS: I18nScripts = I18nScripts; + +/// The runtime's first font stack: egui's bundled faces and no installed system fonts. GridCraft's own definitions +/// ([`SheetApp::setup_context_for_language`]) replace it before anything is drawn. +fn ui_fonts() -> UiFonts<'static> { + UiFonts::new(&SCRIPTS).system_fonts(SystemFonts::Off) +} + +fn install_with(ctx: &egui::Context, shell: ShellInfo, windows: Arc) -> Result<(), String> { + let spec = craft_ui::InstallSpec::new(shell, windows).app_id(APP_ID); + embed::install(ctx, spec, &ui_fonts()).map(drop).map_err(|error| format!("the UI runtime could not be installed: {error}")) +} + +/// Installs the runtime on the desktop window's context, once, before the first pass. GridCraft draws its own title +/// bar (and, where the desktop leaves the frame to the app, its own window buttons), so no frame decision is handed +/// over and the runtime answers no hit test of the window. +#[cfg(not(target_arch = "wasm32"))] +pub fn install(ctx: &egui::Context) -> Result<(), String> { + let shell = ShellInfo::default().backend(craft_host::target::Backend::from_env()); + install_with(ctx, shell, Arc::new(craft_window::system::SystemWindows)) +} + +/// Installs the runtime on a context with no native window of its own: the browser build's canvas and test windows. +pub fn install_headless(ctx: &egui::Context) { + if let Err(error) = install_with(ctx, ShellInfo::default(), Arc::new(craft_window::system::NoWindows)) { + log::warn!("{error}"); + } +} + +/// Who GridCraft is to the framework's dialogs (the update dialogs show its name and icon). +pub(crate) fn host() -> Arc { + Arc::new( + Host::builder(AppInfo { id: "gridcraft", name: "GridCraft", version: env!("CARGO_PKG_VERSION") }) + .icon_png(include_bytes!("../../../assets/app-icon/hicolor/128x128/apps/ai.storyteller.gridcraft.png")) + .build(), + ) +} + +/// GridCraft quits through its own Quit (the macOS app menu, the last window closing, an update's restart), which +/// asks about every unsaved workbook in its window, and Ctrl+Q is no quit key on Windows and Linux (Excel's Quick +/// Analysis), so the framework's `window.quit` is unbound. Overrides are keyed by command id, which the command set +/// gives. +fn command_overrides() -> Arc { + static OVERRIDES: OnceLock> = OnceLock::new(); + OVERRIDES + .get_or_init(|| { + let mut overrides = Overrides::new(); + overrides.insert(QuitCommand::Quit.id(), Vec::new()); + Arc::new(overrides) + }) + .clone() +} + +impl SheetApp { + /// The framework's part of `App::raw_input_hook`, once per frame before the first pass: takes what the runtime + /// gathered since the last frame and gives the coming passes the root values (theme mode, interface scale). + pub fn before_input(&mut self, ctx: &egui::Context) { + embed::before_input(ctx, |output| self.frame_input(output)); + } + + /// The root values of this frame. GridCraft registers no commands with the runtime (it unbinds the framework's + /// quit, [`command_overrides`]) and lets it toggle no chrome, so the output carries nothing it acts on. The + /// interface scale is the Interface Size preference: the runtime is the one writer of egui's zoom factor. + fn frame_input(&mut self, _output: FrameOutput) -> FrameInput { + let mode = if self.effective_dark { craft_theme::Mode::Dark } else { craft_theme::Mode::Light }; + let root = RootEnv::new().mode(mode).scale(Scale::new(self.ui.zoom_factor())); + FrameInput::new(root).commands(CommandInput::new().overrides(command_overrides())).host(Arc::clone(&self.framework_host)) + } + + /// The framework's part of `App::logic`, last, after GridCraft's own logic and the native windows': the root + /// window's close path, decided by [`SheetApp::close_decision`]. + pub fn close_path(&mut self, ctx: &egui::Context) { + embed::logic(ctx, || self.close_decision(ctx)); + } + + /// The framework dialogs open on [`SheetApp::framework_dialogs`], once per frame after GridCraft's own UI. + pub(crate) fn run_framework_dialogs(&mut self, ui: &mut egui::Ui) { + self.framework_dialogs.run(ui); + } +} + +/// Declares the grid `id`, drawn in this pass, as the window's document canvas. With nothing focused it is the +/// window's key target: Tab, the edit chords and the clipboard events stay in egui's input for GridCraft's shortcuts, +/// as do the arrows, Enter and the page keys. +pub(crate) fn host_canvas(ctx: &egui::Context, id: egui::Id) { + const KEYS: KeyUse = KeyUse::CANVAS.with_keep(KeepKeys::Tab).with_edits(EditSet::ALL); + craft_ui::runtime::focus::host_canvas(ctx, id, KEYS); +} + +/// Whether Escape was pressed in this pass: from egui while one of GridCraft's own widgets or popups has the +/// keyboard, otherwise the window's cancel, which the runtime routes to no component. Leaves it for later readers. +pub(crate) fn escape_pressed(ctx: &egui::Context) -> bool { + ctx.input(|i| i.key_pressed(egui::Key::Escape)) || window_cancel(ctx, false) +} + +/// Takes a plain Escape pressed in this pass, from egui or as the window's cancel: no later reader sees it. +pub(crate) fn consume_escape(ctx: &egui::Context) -> bool { + ctx.input_mut(|i| i.consume_key(egui::Modifiers::NONE, egui::Key::Escape)) || take_window_cancel(ctx) +} + +/// Takes the window's cancel (an Escape while nothing has framework focus) when it is there: no later reader sees it. +pub(crate) fn take_window_cancel(ctx: &egui::Context) -> bool { + window_cancel(ctx, true) +} + +/// Whether the window's cancel is there and untaken; `take` takes it. +fn window_cancel(ctx: &egui::Context, take: bool) -> bool { + let mut pending = false; + with_window_intents(ctx, false, |intents| { + pending = if take { intents.take(Intent::Cancel) } else { intents.untaken(&Intent::Cancel) }; + take && pending + }); + pending +} diff --git a/crates/ui-egui/src/grid/interact.rs b/crates/ui-egui/src/grid/interact.rs index f0ab7bc8e..736bc4ad9 100644 --- a/crates/ui-egui/src/grid/interact.rs +++ b/crates/ui-egui/src/grid/interact.rs @@ -648,19 +648,22 @@ fn handle_context_menu_and_keyboard(app: &mut SheetApp, input: &InteractionInput if primary_clicked || resp.drag_started() { resp.request_focus(); } + crate::framework::host_canvas(&ctx, resp.id); keyboard(app, &ctx, resp, geo, sh); } -/// Whether Esc was pressed this frame, with any modifiers; every Esc press is then spent, so the -/// grid's own Esc doesn't also drop a pending copy or Format Painter. +/// Whether Esc was pressed this frame, with any modifiers, in egui's input or as the window's +/// cancel; every Esc press is then spent, so the grid's own Esc doesn't also drop a pending copy or +/// Format Painter. fn spend_escape(ctx: &egui::Context) -> bool { - ctx.input_mut(|i| { + let in_egui = ctx.input_mut(|i| { let pressed = i.key_pressed(egui::Key::Escape); if pressed { i.events.retain(|e| !matches!(e, egui::Event::Key { key: egui::Key::Escape, pressed: true, .. })); } pressed - }) + }); + in_egui || crate::framework::take_window_cancel(ctx) } fn handle_dragging(app: &mut SheetApp, input: &InteractionInput<'_>) { @@ -810,7 +813,7 @@ fn handle_release(app: &mut SheetApp, input: &InteractionInput<'_>) { Drag::Fill { target: Some(t), menu: true } => { if let Some(p) = pos && t != sel.current() - && !ctx.input_mut(|i| i.consume_key(egui::Modifiers::NONE, egui::Key::Escape)) + && !crate::framework::consume_escape(&ctx) { app.grid.fill_menu = Some((sel.current(), t, geo.mirror_pos(p))); } diff --git a/crates/ui-egui/src/grid/menus.rs b/crates/ui-egui/src/grid/menus.rs index e9ee1a976..16b06e9e3 100644 --- a/crates/ui-egui/src/grid/menus.rs +++ b/crates/ui-egui/src/grid/menus.rs @@ -221,7 +221,7 @@ pub(super) fn context_menu(app: &mut SheetApp, ui: &mut egui::Ui) { // menu, so it doesn't count as a click elsewhere. let opened_now = app.grid.context_menu_frame == ui.ctx().cumulative_frame_nr(); if close - || ui.input(|i| i.key_pressed(egui::Key::Escape)) + || crate::framework::escape_pressed(ui.ctx()) || (!opened_now && ui.input(|i| i.pointer.any_pressed()) && !resp.response.contains_pointer() @@ -428,7 +428,7 @@ pub(super) fn object_menu(app: &mut SheetApp, ui: &mut egui::Ui) { }); }); if close - || ui.input(|i| i.key_pressed(egui::Key::Escape)) + || crate::framework::escape_pressed(ui.ctx()) || (ui.input(|i| i.pointer.any_pressed()) && !resp.response.contains_pointer() && !resp.response.hovered() diff --git a/crates/ui-egui/src/keytips.rs b/crates/ui-egui/src/keytips.rs index 356d7189f..f2e3d9bf3 100644 --- a/crates/ui-egui/src/keytips.rs +++ b/crates/ui-egui/src/keytips.rs @@ -120,15 +120,7 @@ impl KeyTips { } else if self.prefix.is_some() && !matches!(key, Key::ShiftLeft | Key::ShiftRight) { handled = true; if *key == Key::Escape { - // Escape pops one level; at a single-letter level it - // returns to the armed root (empty prefix). - if let Some(prefix) = self.prefix.as_mut() { - if prefix.is_empty() { - self.prefix = None; - } else { - prefix.pop(); - } - } + self.back(); } else if key.name().len() == 1 { let next = format!("{}{key_name}", self.prefix.as_deref().unwrap_or_default(), key_name = key.name()); match keytip_table::lookup(&next) { @@ -171,9 +163,25 @@ impl KeyTips { ctx.input_mut(|i| { i.events = events.into_iter().enumerate().filter_map(|(index, event)| (!consumed.contains(&index)).then_some(event)).collect() }); + // With none of GridCraft's widgets focused (the File view), the runtime takes Escape as the + // window's cancel. + if self.prefix.is_some() && crate::framework::take_window_cancel(ctx) { + self.back(); + } actions } + /// Escape pops one level; at a single-letter level it returns to the armed root (empty prefix). + fn back(&mut self) { + if let Some(prefix) = self.prefix.as_mut() { + if prefix.is_empty() { + self.prefix = None; + } else { + prefix.pop(); + } + } + } + fn finish(&mut self, action: Action, actions: &mut Vec) { self.prefix = None; actions.push(action); diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 65cca4d58..33472c83a 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -17,10 +17,12 @@ pub const UPDATE_APP: craft_update::app::App = craft_update::app::App { pub mod backstage; mod border_preview; +mod capture; mod cell_pictures; mod chartcache; pub mod chartview; pub mod code_editor; +mod combo_menu; pub mod control; pub mod control_ui; mod craft_fonts_policy; @@ -37,6 +39,7 @@ pub mod form_controls; pub mod formula_bar; mod formula_locale; pub mod frame; +pub mod framework; pub mod function_library; pub mod grid; pub mod i18n; @@ -59,6 +62,7 @@ mod text_direction; pub mod theme; #[cfg(not(target_arch = "wasm32"))] mod updates_ui; +mod viewports; pub mod widgets; mod window_ui; pub mod wordart; @@ -347,6 +351,11 @@ pub struct SheetApp { /// The update check, the startup prompt and a running self-update (desktop only). #[cfg(not(target_arch = "wasm32"))] updates_rt: updates_ui::Runtime, + /// The framework dialogs GridCraft keeps as values (the update dialogs), run once per frame + /// after GridCraft's own UI in the root window's pass. + pub framework_dialogs: craft_ui::dialog::DialogHost, + /// Who GridCraft is to the framework's dialogs. + framework_host: std::sync::Arc, } /// Strips the engine's error prefixes for message boxes. diff --git a/crates/ui-egui/src/macro_editor.rs b/crates/ui-egui/src/macro_editor.rs index 7cdf41ac5..5f220efdc 100644 --- a/crates/ui-egui/src/macro_editor.rs +++ b/crates/ui-egui/src/macro_editor.rs @@ -959,7 +959,7 @@ pub fn window(app: &mut SheetApp, ctx: &egui::Context, d: &mut Dialog, open: &mu *open = false; } } - if ctx.input(|i| i.key_pressed(egui::Key::Escape)) && ed.picker.is_some() { + if crate::framework::escape_pressed(&ctx) && ed.picker.is_some() { ed.picker = None; } prompts(app, ctx, &mut ed, open); @@ -1110,7 +1110,7 @@ fn prompts(app: &mut SheetApp, ctx: &egui::Context, ed: &mut Editor, open: &mut ui.label("Keep the changes the macro has made so far? They are one undo step either way."); ui.add_space(8.0); ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { - if ui.button("Cancel").clicked() || ui.input(|i| i.key_pressed(egui::Key::Escape)) { + if ui.button("Cancel").clicked() || crate::framework::escape_pressed(ui.ctx()) { answer = Some(None); } if ui.button("Undo Changes").clicked() { @@ -1147,7 +1147,7 @@ fn prompts(app: &mut SheetApp, ctx: &egui::Context, ed: &mut Editor, open: &mut ui.label(egui::RichText::new(format!("Save changes to macro “{}”?", ed.draft.name)).strong()); ui.add_space(8.0); ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { - if ui.button("Cancel").clicked() || ui.input(|i| i.key_pressed(egui::Key::Escape)) { + if ui.button("Cancel").clicked() || crate::framework::escape_pressed(ui.ctx()) { answer = Some(None); } if ui.button("Don't Save").clicked() { diff --git a/crates/ui-egui/src/macro_ui.rs b/crates/ui-egui/src/macro_ui.rs index 0332c3276..7dc4248ba 100644 --- a/crates/ui-egui/src/macro_ui.rs +++ b/crates/ui-egui/src/macro_ui.rs @@ -216,7 +216,7 @@ pub fn question_box(app: &mut SheetApp, ctx: &egui::Context) { ui.add(egui::Label::new(&q.text).wrap()); ui.add_space(8.0); ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { - if ui.button("Cancel").clicked() || ui.input(|i| i.key_pressed(egui::Key::Escape)) { + if ui.button("Cancel").clicked() || crate::framework::escape_pressed(ui.ctx()) { answer = Some(None); } // Right to left: list the choices reversed, so the first one ends up next to Cancel diff --git a/crates/ui-egui/src/panes.rs b/crates/ui-egui/src/panes.rs index d9207cd07..d3f35427a 100644 --- a/crates/ui-egui/src/panes.rs +++ b/crates/ui-egui/src/panes.rs @@ -332,7 +332,7 @@ fn format_chart(app: &mut SheetApp, ui: &mut Ui) { let b = ui.add(egui::DragValue::new(&mut h).prefix("Height ").range(range(current.1))); if a.drag_stopped() || a.lost_focus() || b.drag_stopped() || b.lost_focus() { ui.data_mut(|d| d.remove::<(f32, f32)>(draft)); - if !ui.input(|i| i.key_pressed(egui::Key::Escape)) { + if !crate::framework::escape_pressed(ui.ctx()) { // Only an edited dimension is sent: the other keeps what the chart has, however // large a file made it. let mut params = serde_json::Map::new(); @@ -363,7 +363,7 @@ fn chart_slider(ui: &mut Ui, draft: egui::Id, value: u32, range: std::ops::Range let r = ui.add(egui::Slider::new(&mut current, range).text(label)); if r.drag_stopped() || r.clicked() || r.lost_focus() { ui.data_mut(|d| d.remove::(draft)); - if ui.input(|i| i.key_pressed(egui::Key::Escape)) || current == value { None } else { Some(current) } + if crate::framework::escape_pressed(ui.ctx()) || current == value { None } else { Some(current) } } else if r.dragged() || r.has_focus() { ui.data_mut(|d| d.insert_temp(draft, current)); None diff --git a/crates/ui-egui/src/paper_view.rs b/crates/ui-egui/src/paper_view.rs index 9db376fbf..eaf551e77 100644 --- a/crates/ui-egui/src/paper_view.rs +++ b/crates/ui-egui/src/paper_view.rs @@ -9,7 +9,7 @@ use std::sync::Arc; -use egui::{Align2, Color32, FontId, Key, Painter, Pos2, Rect, Stroke, StrokeKind, TextEdit, pos2, vec2}; +use egui::{Align2, Color32, FontId, Painter, Pos2, Rect, Stroke, StrokeKind, TextEdit, pos2, vec2}; use gridcraft_engine::cf::CfCache; use gridcraft_engine::cmd::print::{self, HfContext}; use gridcraft_engine::model::{HfPage, Sheet, SheetViewMode, Workbook}; @@ -468,7 +468,7 @@ pub fn go_to(app: &mut SheetApp, footer: bool) { /// Edits a header/footer section across left/center/right, cancels on Esc, switches sections and preserves focus/caret while the page scrolls. fn editor(app: &mut SheetApp, ui: &mut egui::Ui, geo: &Geo, pg: &PageGrid) { let Some(mut e) = app.grid.hf_edit.take() else { return }; - if ui.input_mut(|i| i.consume_key(egui::Modifiers::NONE, Key::Escape)) { + if crate::framework::consume_escape(ui.ctx()) { app.grid.hf_edit = Some(e); cancel(app); return; @@ -823,7 +823,7 @@ fn ruler_margins(app: &mut SheetApp, ui: &mut egui::Ui, geo: &Geo, pg: &PageGrid ui.ctx().set_cursor_icon(if edge.horizontal() { egui::CursorIcon::ResizeHorizontal } else { egui::CursorIcon::ResizeVertical }); }; if let Some(d) = app.grid.ruler_drag.clone() { - if ui.input_mut(|i| i.consume_key(egui::Modifiers::NONE, Key::Escape)) { + if crate::framework::consume_escape(ui.ctx()) { app.grid.ruler_drag = None; return; } diff --git a/crates/ui-egui/src/printing.rs b/crates/ui-egui/src/printing.rs index 46a2576d3..8f636633d 100644 --- a/crates/ui-egui/src/printing.rs +++ b/crates/ui-egui/src/printing.rs @@ -1,33 +1,27 @@ -//! Localized print-page wording around the shared, backend-independent controls. -use craft_ui::printing::Labels; -pub use craft_ui::printing::{Discover, Duplex, Feedback, Printer, Settings, State, Submit}; +//! The print page's printer controls (craft-print's `PrintPanel` over its `State`) and their +//! localized feedback. The panel's own words come from the framework host. +pub use craft_print::ui::{Destination, Discover, Duplex, Feedback, Printer, Settings, State, Submit}; -/// Draws the shared print controls. +/// Draws the shared print controls and the feedback of the last discovery or job. /// -/// `craft_ui::printing::State::show` also calls `poll`, so this path polls a second time on top of -/// [`crate::SheetApp::poll_printing`] in `logic`. That poll is idempotent (it only drains worker -/// messages into the same state), and the logic-side poll is what lets a hidden window and a -/// logic-only frame see completion, so it stays. Splitting poll out of the shared `show` API is a -/// craft-ui follow-up, not a GridCraft-local change. +/// `State::run` also polls the workers, on top of [`crate::SheetApp::poll_printing`] in `logic`. +/// That poll is idempotent (it only drains worker messages into the same state), and the +/// logic-side poll is what lets a hidden window and a logic-only frame see completion, so it stays. pub fn show(state: &mut State, ui: &mut egui::Ui, discover: &Discover, translate: impl Fn(&str) -> String) { - let labels = Labels { - printer: &translate("Printer"), - select_printer: &translate("Select a printer"), - refresh: &translate("Refresh printers"), - copies: &translate("Copies"), - duplex: &translate("Two-sided printing"), - printer_default: &translate("Printer default"), - one_sided: &translate("One-sided"), - long_edge: &translate("Two-sided: long edge"), - short_edge: &translate("Two-sided: short edge"), - grayscale: &translate("Grayscale"), - }; - state.show(ui, egui::Id::unique("gridcraft_print_settings"), discover, &labels); + ui.push_id("gridcraft_print_settings", |ui| state.run(ui, discover)); if let Some(message) = &state.message { ui.label(feedback(message, crate::i18n::current(ui.ctx()), translate)); } } +/// The printer queue the settings name; empty for none. +fn printer_name(settings: &Settings) -> &str { + match &settings.destination { + Destination::Printer(name) => name, + _ => "", + } +} + /// Read print settings/status, or validate an explicit update before changing anything. /// `refresh: true` starts discovery only; this command never submits a job or opens a dialog. pub fn settings(state: &mut State, params: &serde_json::Value, discover: Option<&Discover>) -> Result { @@ -45,7 +39,7 @@ pub fn settings(state: &mut State, params: &serde_json::Value, discover: Option< if !state.printers.iter().any(|available| available.name == printer) { return Err("printer must be a name from the discovered list".into()); } - next.printer = printer.to_owned(); + next.destination = Destination::Printer(printer.to_owned()); } if let Some(value) = object.get("copies") { let copies = value.as_u64().filter(|copies| (1..=999).contains(copies)).ok_or("copies must be an integer from 1 to 999")?; @@ -81,10 +75,11 @@ pub fn settings(state: &mut State, params: &serde_json::Value, discover: Option< Some(Feedback::Submitted(receipt)) => ("submitted", receipt.as_str()), Some(Feedback::Failed(error)) => ("failed", error.as_str()), Some(Feedback::WorkerStopped) => ("workerStopped", ""), + Some(_) => ("unknown", ""), }; Ok(json!({ - "printer": state.settings.printer, "copies": state.settings.copies, - "duplex": match state.settings.duplex { None => "printerDefault", Some(Duplex::Off) => "off", Some(Duplex::LongEdge) => "longEdge", Some(Duplex::ShortEdge) => "shortEdge" }, + "printer": printer_name(&state.settings), "copies": state.settings.copies, + "duplex": match state.settings.duplex { Some(Duplex::Off) => "off", Some(Duplex::LongEdge) => "longEdge", Some(Duplex::ShortEdge) => "shortEdge", _ => "printerDefault" }, "grayscale": state.settings.grayscale, "printers": state.printers.iter().map(|printer| json!({"name": printer.name, "default": printer.default})).collect::>(), "busy": state.busy(), "discovering": state.discovering(), "ready": state.ready(), "status": status, "detail": detail, @@ -101,5 +96,6 @@ pub fn feedback(message: &Feedback, language: crate::i18n::Language, translate: Feedback::Submitted(receipt) => translate("Print job submitted: {receipt}").replace("{receipt}", receipt), Feedback::Failed(error) => translate("Print failed: {error}").replace("{error}", &language.tr_error(error)), Feedback::WorkerStopped => translate("Print failed: the printing worker stopped."), + _ => String::new(), } } diff --git a/crates/ui-egui/src/ribbon/controls.rs b/crates/ui-egui/src/ribbon/controls.rs index 5d10e13e0..3b8e252f4 100644 --- a/crates/ui-egui/src/ribbon/controls.rs +++ b/crates/ui-egui/src/ribbon/controls.rs @@ -248,7 +248,7 @@ fn combo_popup( if filter { height += ui.spacing().interact_size.y + 4.0 * spacing + 1.0; } - let menu = craft_ui::combo::Menu::new(ui, &field).height(height); + let menu = crate::combo_menu::Menu::new(ui, &field).height(height); let text_id = anchor.id.with(salt).with("__combo_text"); let sel0 = st.sel; let shown = if filter { diff --git a/crates/ui-egui/src/tabs.rs b/crates/ui-egui/src/tabs.rs index 7cd939e64..02ff3de7a 100644 --- a/crates/ui-egui/src/tabs.rs +++ b/crates/ui-egui/src/tabs.rs @@ -270,7 +270,7 @@ pub fn sheet_tabs(app: &mut SheetApp, ui: &mut Ui) { ed.request_focus(); } if ed.lost_focus() { - if !ui.input(|i| i.key_pressed(egui::Key::Escape)) && text != name { + if !crate::framework::escape_pressed(ui.ctx()) && text != name { app.run_or_alert("sheet.rename", json!({"sheet": i, "name": text})); } app.grid.renaming_tab = None; diff --git a/crates/ui-egui/src/text_box.rs b/crates/ui-egui/src/text_box.rs index 7324abcfb..2eae0148c 100644 --- a/crates/ui-egui/src/text_box.rs +++ b/crates/ui-egui/src/text_box.rs @@ -93,7 +93,7 @@ impl SheetApp { /// Resolve outside clicks before the ribbon/tabs can save or switch the workbook. pub(crate) fn before_ui(app: &mut SheetApp, ctx: &egui::Context) { let Some(ed) = &app.text_box_editor else { return }; - if ctx.input_mut(|i| i.consume_key(Modifiers::NONE, Key::Escape)) { + if crate::framework::consume_escape(&ctx) { app.cancel_text_box_edit(); ctx.memory_mut(|m| m.surrender_focus(editor_id())); return; diff --git a/crates/ui-egui/src/theme/font_setup.rs b/crates/ui-egui/src/theme/font_setup.rs index 31e4c63eb..a2819d7fd 100644 --- a/crates/ui-egui/src/theme/font_setup.rs +++ b/crates/ui-egui/src/theme/font_setup.rs @@ -526,6 +526,13 @@ pub(super) fn font_definitions_impl( if let Some(ui) = fonts.families.get(&FontFamily::Name(UI.into())).cloned() { fonts.families.insert(FontFamily::Proportional, ui); } + // The framework's dialogs draw in two families of their own besides the proportional and + // monospace ones: the signature family follows the proportional one, and the semibold family + // (titles, strong text) is the bold UI face. A family left out draws missing-glyph boxes. + let proportional = fonts.families.get(&FontFamily::Proportional).cloned().unwrap_or_default(); + let bold = fonts.families.get(&FontFamily::Name(UI_BOLD.into())).cloned().unwrap_or_else(|| proportional.clone()); + fonts.families.insert(craft_ui::fonts::FontRef::signature().family(), proportional); + fonts.families.insert(FontFamily::Name(craft_ui::fonts::SEMIBOLD.into()), bold); // Installed workbook fonts, so a cell's chosen font actually renders in it. They are bound // after the proportional chain has the script faces, which their chains end with. for (family, faces) in installed { diff --git a/crates/ui-egui/src/updates_ui.rs b/crates/ui-egui/src/updates_ui.rs index cded96c85..407393b72 100644 --- a/crates/ui-egui/src/updates_ui.rs +++ b/crates/ui-egui/src/updates_ui.rs @@ -1,8 +1,10 @@ //! One background check at startup (and on Help ▸ Check for Updates…) and the modal prompt that //! offers the new release: Update and Restart (direct self-update), Download or Later. The flow -//! itself is `craft_update::updater::Updater`. +//! itself is `craft_update::updater::Updater`; its dialogs run on the app's +//! [`DialogHost`](craft_ui::dialog::DialogHost). -use craft_update::CheckResultResponse; +use craft_ui::dialog::DialogResult; +use craft_update::stack_dialogs::{CheckChoice, UpdateCheckDialog}; use craft_update::updater::{Action, Status, Updater}; use crate::SheetApp; @@ -35,9 +37,9 @@ pub(crate) fn start(app: &mut SheetApp, manual: bool) { pub(crate) fn tick(app: &mut SheetApp, ctx: &egui::Context) { let rt = &mut app.updates_rt; if std::mem::take(&mut rt.manual) { - rt.updater.check_now(ctx); + rt.updater.check_now(); } else if rt.startup { - rt.updater.check_at_start(ctx); + rt.updater.check_at_start(); } rt.updater.tick(ctx); } @@ -54,28 +56,50 @@ fn result_window_shows(status: &Status, prompt_open: bool) -> bool { !prompt_open && !matches!(status, Status::Idle) } +/// One frame of the update flow, before the dialog host runs: answers the result dialog closed in +/// the last pass, drives the startup prompt, and keeps the result dialog open and current while the +/// updater has something to report. pub(crate) fn show(app: &mut SheetApp, ctx: &egui::Context) { // The close for a ready update waits until no workbook holds unsaved work. let clean = !app.session.documents().iter().any(|d| d.is_dirty()); - match app.updates_rt.updater.show_if(ctx, clean) { - Action::OpenUrl(url) => { - if let Some(open) = &app.services.open_url { - open(&url); - } + // Answered before the dialog is kept open below, so a dismissed outcome does not open again at once. + match app.framework_dialogs.take::() { + Some(DialogResult::Ok(CheckChoice::CheckNow | CheckChoice::CheckAgain)) => app.updates_rt.manual = true, + // The next `run` asks the window to close once nothing is unsaved. + Some(DialogResult::Ok(CheckChoice::RestartToUpdate)) => app.updates_rt.updater.restart_to_update(), + Some(DialogResult::Ok(CheckChoice::Update)) => { + app.updates_rt.updater.request_install(clean); } + Some(DialogResult::Ok(CheckChoice::Download)) => open_url(app, &crate::UPDATE_APP.releases_url()), + // Closing the dialog dismisses the outcome it showed. + Some(_) => app.updates_rt.updater.dismiss_status(), + None => {} + } + match app.updates_rt.updater.run(&mut app.framework_dialogs, clean) { + Action::OpenUrl(url) => open_url(app, &url), // Quit closes every workbook window. The install helper starts once the app exits. Action::Close => app.request_quit(ctx), - Action::None => {} + _ => {} } - let rt = &mut app.updates_rt; - if result_window_shows(rt.updater.status(), rt.updater.prompt_open()) { - match craft_update::CheckResultDialog::new(&crate::UPDATE_APP, VERSION).show(ctx, rt.updater.status()) { - CheckResultResponse::Close => rt.updater.dismiss_status(), - CheckResultResponse::CheckAgain => rt.updater.check_now(ctx), - // The next `show_if` asks the window to close once nothing is unsaved. - CheckResultResponse::RestartToUpdate => rt.updater.restart_to_update(), - CheckResultResponse::None => {} - } + let updater = &app.updates_rt.updater; + let shows = result_window_shows(updater.status(), updater.prompt_open()); + let (status, installing, message) = (updater.status().clone(), updater.is_installing(), updater.status_message()); + let dialogs = &mut app.framework_dialogs; + if shows && !dialogs.is_open::() { + dialogs.open(UpdateCheckDialog::new(VERSION)); + } else if !shows && dialogs.is_open::() { + dialogs.cancel::(ctx); + } + if let Some(dialog) = dialogs.get_mut::() { + dialog.set_status(status); + dialog.set_installing(installing); + dialog.set_message(message); + } +} + +fn open_url(app: &SheetApp, url: &str) { + if let Some(open) = &app.services.open_url { + open(url); } } diff --git a/crates/ui-egui/src/viewports.rs b/crates/ui-egui/src/viewports.rs new file mode 100644 index 000000000..dbc13d6e7 --- /dev/null +++ b/crates/ui-egui/src/viewports.rs @@ -0,0 +1,207 @@ +//! Shows each open workbook window as an egui immediate viewport, one native window each. +//! +//! Call [`Viewports::show`] once per frame from the root viewport's UI. The root viewport stays the +//! app's: the window mapped to it with [`Viewports::set_root`] is drawn into the root UI, and every +//! other window gets its own viewport, placed one cascade step from the window used last. Close and +//! quit policy stays with the app: the driver reports [`WindowEvent`]s. + +use std::collections::HashMap; + +use craft_window::{WindowId, WindowList}; +use egui::{Context, Pos2, Rect, Ui, Vec2, ViewportBuilder, ViewportCommand, ViewportId}; + +/// How far right and down a new window opens from the window used last, in points: about one +/// title bar. +pub const CASCADE_STEP: f32 = 28.0; + +/// How far a maximized window's frame may reach past its monitor's edges: a window rectangle that +/// starts up to this far left of or above a monitor is on that monitor. +const FRAME_OVERSHOOT: f32 = 16.0; + +/// Something that happened to a window this frame. The app decides what follows. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum WindowEvent { + /// The window got focus. The driver has already made it the list's active window. + Focused(WindowId), + /// The user asked to close the window (its close button, Alt+F4, ⌘W through the desktop). + /// A child window stays open until the app closes it in the [`WindowList`], so the app can ask + /// to save first. The root window's close request is the app's close path to hold. + CloseRequested(WindowId), +} + +/// What the driver remembers about a window between frames. +#[derive(Default)] +struct Seen { + focused: bool, + /// The window's outer rectangle as it last reported it. + outer: Option, + inner_size: Option, + monitor_size: Option, + /// The cascade position chosen when the window was created; repeated every frame so egui sees + /// an unchanged builder. + position: Option, + /// The root viewport's title, sent as a command when it changes. + title: Option, +} + +/// The windows of a [`WindowList`] as egui viewports (see the module docs). +#[derive(Default)] +pub struct Viewports { + root: Option, + seen: HashMap, +} + +impl Viewports { + /// The window drawn into the root viewport. + pub fn root(&self) -> Option { + self.root + } + + /// Maps window `id` to the root viewport, or none. + pub fn set_root(&mut self, id: Option) { + if let Some(id) = id { + // The root is a different native window: forget the child's focus and title. + self.seen.insert(id, Seen::default()); + } + self.root = id; + } + + /// Moves window `id` into the root viewport, for when the root's own window closes while others + /// stay open. The root window takes `id`'s position and size and gets focus; `id`'s data and + /// [`WindowId`] are unchanged, so its UI state carries over. + pub fn adopt(&mut self, ctx: &Context, id: WindowId) { + let (outer, inner_size) = self.seen.get(&id).map_or((None, None), |seen| (seen.outer, seen.inner_size)); + self.set_root(Some(id)); + if let Some(rect) = outer { + ctx.send_viewport_cmd_to(ViewportId::ROOT, ViewportCommand::OuterPosition(rect.min)); + } + if let Some(size) = inner_size { + ctx.send_viewport_cmd_to(ViewportId::ROOT, ViewportCommand::InnerSize(size)); + } + ctx.send_viewport_cmd_to(ViewportId::ROOT, ViewportCommand::Focus); + } + + /// The egui viewport showing window `id`. + pub fn viewport_id(&self, id: WindowId) -> ViewportId { + if self.root == Some(id) { ViewportId::ROOT } else { child_viewport_id(id) } + } + + /// Brings window `id` to the front. + pub fn focus(&self, ctx: &Context, id: WindowId) { + ctx.send_viewport_cmd_to(self.viewport_id(id), ViewportCommand::Focus); + } + + /// Draws every window of `windows`: the root's into `ui`, every other one in an immediate + /// viewport built by `builder` (with system decorations) and drawn by `content`. Returns what + /// happened to the windows this frame. + pub fn show( + &mut self, + ui: &mut Ui, + windows: &mut WindowList, + mut builder: impl FnMut(WindowId, &T) -> ViewportBuilder, + mut content: impl FnMut(&mut Ui, WindowId, &mut T), + ) -> Vec { + self.seen.retain(|id, _| windows.contains(*id)); + let ctx = ui.ctx().clone(); + let mut events = Vec::new(); + + if let Some(root) = self.root.filter(|&id| windows.contains(id)) { + if let Some(title) = windows.get(root).and_then(|data| builder(root, data).title) { + let seen = self.seen.entry(root).or_default(); + if seen.title.as_ref() != Some(&title) { + ctx.send_viewport_cmd_to(ViewportId::ROOT, ViewportCommand::Title(title.clone())); + seen.title = Some(title); + } + } + if let Some(data) = windows.get_mut(root) { + content(ui, root, data); + } + self.record(Snapshot::read(&ctx), windows, root, &mut events); + } + + let children: Vec = windows.ids().filter(|&id| self.root != Some(id)).collect(); + for id in children { + let Some(data) = windows.get(id) else { continue }; + let mut viewport = builder(id, data).with_decorations(true); + let position = match self.seen.get(&id) { + Some(seen) => seen.position, + None => self.place(windows, id, &viewport), + }; + if let Some(position) = position { + viewport = viewport.with_position(position); + } + self.seen.entry(id).or_default().position = position; + + let Some(data) = windows.get_mut(id) else { continue }; + let snapshot = ctx.show_viewport_immediate(child_viewport_id(id), viewport, |child_ui, _class| { + content(child_ui, id, data); + Snapshot::read(child_ui.ctx()) + }); + self.record(snapshot, windows, id, &mut events); + } + events + } + + fn record(&mut self, snapshot: Snapshot, windows: &mut WindowList, id: WindowId, events: &mut Vec) { + let Snapshot { close, focused, outer, inner, monitor } = snapshot; + let seen = self.seen.entry(id).or_default(); + seen.outer = outer; + seen.inner_size = inner.map(|r| r.size()).or(seen.inner_size); + seen.monitor_size = monitor.or(seen.monitor_size); + if focused && !seen.focused { + windows.focus(id); + events.push(WindowEvent::Focused(id)); + } + seen.focused = focused; + if close { + events.push(WindowEvent::CloseRequested(id)); + } + } + + /// Where a new window opens: one cascade step from the window used most recently whose + /// rectangle is known, within that window's monitor. `None` when no window's rectangle is known. + fn place(&self, windows: &WindowList, id: WindowId, viewport: &ViewportBuilder) -> Option { + let (previous_id, previous) = windows.recent().filter(|&w| w != id).find_map(|w| Some((w, self.seen.get(&w)?.outer?)))?; + let seen = self.seen.get(&previous_id); + let frame = seen.and_then(|s| s.inner_size).map(|inner| previous.size() - inner).unwrap_or_default(); + let size = viewport.inner_size.map(|s| s + frame).unwrap_or(previous.size()); + let bounds = monitor_bounds(previous, seen?.monitor_size?); + Some(craft_behavior::placement::cascade(previous, size, bounds, CASCADE_STEP).min) + } +} + +/// What a window reported in its pass. +struct Snapshot { + close: bool, + focused: bool, + outer: Option, + inner: Option, + monitor: Option, +} + +impl Snapshot { + fn read(ctx: &Context) -> Self { + ctx.input(|i| { + let v = i.viewport(); + Self { + close: v.close_requested(), + focused: v.focused.unwrap_or(false), + outer: v.outer_rect, + inner: v.inner_rect, + monitor: v.monitor_size, + } + }) + } +} + +/// The egui viewport of a window that is not in the root viewport. +pub fn child_viewport_id(id: WindowId) -> ViewportId { + ViewportId::from_hash_of(("craft_window", id.get())) +} + +/// The monitor `window` is on, for a desktop of monitors of one `monitor` size side by side: egui +/// reports only the size of the window's monitor, not where it is. +fn monitor_bounds(window: Rect, monitor: Vec2) -> Rect { + let tile = |pos: f32, len: f32| if len > 0.0 { ((pos + FRAME_OVERSHOOT) / len).floor() * len } else { 0.0 }; + Rect::from_min_size(egui::pos2(tile(window.min.x, monitor.x), tile(window.min.y, monitor.y)), monitor) +} diff --git a/crates/ui-egui/src/widgets.rs b/crates/ui-egui/src/widgets.rs index 28c02840e..29d37c523 100644 --- a/crates/ui-egui/src/widgets.rs +++ b/crates/ui-egui/src/widgets.rs @@ -303,7 +303,7 @@ pub fn committed_text(ui: &mut Ui, id: egui::Id, current: &str, width: Option(draft)); - return (!ui.input(|i| i.key_pressed(egui::Key::Escape))).then_some(text); + return (!crate::framework::escape_pressed(ui.ctx())).then_some(text); } if r.has_focus() { ui.data_mut(|d| d.insert_temp(draft, text)); @@ -598,7 +598,7 @@ pub fn message_box(app: &mut SheetApp, ctx: &egui::Context) { }); ui.add_space(8.0); ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { - if ui.button(" OK ").clicked() || ui.input(|i| i.key_pressed(egui::Key::Enter) || i.key_pressed(egui::Key::Escape)) { + if ui.button(" OK ").clicked() || ui.input(|i| i.key_pressed(egui::Key::Enter)) || crate::framework::escape_pressed(ui.ctx()) { close = true; } }); diff --git a/crates/ui-egui/tests/arabic_editing.rs b/crates/ui-egui/tests/arabic_editing.rs index d3d85c603..2af96c88e 100644 --- a/crates/ui-egui/tests/arabic_editing.rs +++ b/crates/ui-egui/tests/arabic_editing.rs @@ -13,14 +13,17 @@ fn editing(text: &str, formula_bar: bool) -> egui_kittest::Harness<'static, Shee let mut session = Session::new(); session.new_workbook(); session.execute("cell.set", json!({"cell": "A1", "input": text})).unwrap(); - let mut h = egui_kittest::Harness::builder().with_size(vec2(1200.0, 800.0)).build_ui_state( - |ui, app: &mut SheetApp| { - let ctx = ui.ctx().clone(); - app.logic(&ctx); - app.ui(ui); - }, - SheetApp::new(session, Default::default()), - ); + let mut h = egui_kittest::Harness::builder() + .with_context_setup(gridcraft_ui_egui::framework::install_headless) + .with_size(vec2(1200.0, 800.0)) + .build_ui_state( + |ui, app: &mut SheetApp| { + let ctx = ui.ctx().clone(); + app.logic(&ctx); + app.ui(ui); + }, + SheetApp::new(session, Default::default()), + ); h.run_steps(4); if formula_bar { h.get_by_label(text).click(); diff --git a/crates/ui-egui/tests/cjk_baseline.rs b/crates/ui-egui/tests/cjk_baseline.rs index 21b62e557..49c3d2500 100644 --- a/crates/ui-egui/tests/cjk_baseline.rs +++ b/crates/ui-egui/tests/cjk_baseline.rs @@ -49,6 +49,7 @@ fn primary_text_bounds(galley: &egui::Galley) -> (f32, f32) { #[test] fn cjk_and_latin_share_a_baseline_in_cells_and_window_titles() { let ctx = Context::default(); + gridcraft_ui_egui::framework::install_headless(&ctx); ctx.set_pixels_per_point(2.0); activate(&ctx, theme::font_definitions_for_language(Language::Zh)); for role in [theme::CELL, theme::CELL_BOLD, theme::CELL_ITALIC, theme::CELL_BOLD_ITALIC, theme::UI_BOLD] { @@ -72,6 +73,7 @@ fn mixed_script_wrapping_keeps_fixed_row_clips_alignment_and_editor_height() { const TEXT: &str = "中文ABC2026\n文字xyz123"; for zoom in [80, 100, 280] { let ctx = Context::default(); + gridcraft_ui_egui::framework::install_headless(&ctx); ctx.set_pixels_per_point(2.0); let mut session = Session::new(); session.new_workbook(); @@ -139,6 +141,7 @@ fn same_row_cells_keep_their_baseline_with_baseline_aligned_fallbacks() { for valign in ["Top", "Bottom", "Center"] { let mixed = if wraps[1] && valign == "Top" { "Hello\n中文" } else { "Hello 中文" }; let ctx = Context::default(); + gridcraft_ui_egui::framework::install_headless(&ctx); ctx.set_pixels_per_point(2.0); activate(&ctx, theme::font_definitions_for_language(Language::Zh)); let mut session = Session::new(); diff --git a/crates/ui-egui/tests/common/mod.rs b/crates/ui-egui/tests/common/mod.rs index aa7774fc1..f5ea88666 100644 --- a/crates/ui-egui/tests/common/mod.rs +++ b/crates/ui-egui/tests/common/mod.rs @@ -14,9 +14,11 @@ use gridcraft_ui_egui::{Services, SheetApp}; pub type Harness = egui_kittest::Harness<'static, SheetApp>; -/// A kittest builder with the deterministic font set and GridCraft's visuals installed. +/// A kittest builder with the UI runtime, the deterministic font set and GridCraft's visuals +/// installed. pub fn builder() -> HarnessBuilder { egui_kittest::Harness::builder().with_context_setup(|ctx| { + gridcraft_ui_egui::framework::install_headless(ctx); ctx.set_fonts(gridcraft_ui_egui::theme::pinned_font_definitions()); gridcraft_ui_egui::theme::apply(ctx, false); }) @@ -33,7 +35,7 @@ pub fn prepare(mut app: SheetApp) -> SheetApp { app } -/// Drive `app`'s `logic` then `ui` each frame in a harness built with `builder`. +/// Drive `app`'s `logic`, its close path, then `ui` each frame in a harness built with `builder`. /// /// Tests that need a non-standard size, step timing, OS or pixel ratio configure the builder /// here so those details stay explicit; the shared font and lifecycle setup lives in `builder` @@ -43,6 +45,7 @@ pub fn harness_with(builder: HarnessBuilder, app: SheetApp, steps: usi |ui, app: &mut SheetApp| { let ctx = ui.ctx().clone(); app.logic(&ctx); + app.close_path(&ctx); app.ui(ui); }, app, diff --git a/crates/ui-egui/tests/doc_windows.rs b/crates/ui-egui/tests/doc_windows.rs index 595f50707..67ff73492 100644 --- a/crates/ui-egui/tests/doc_windows.rs +++ b/crates/ui-egui/tests/doc_windows.rs @@ -42,6 +42,7 @@ impl Desk { fn new(quit_with_last_window: bool) -> Desk { INFOS.with(|i| i.borrow_mut().clear()); let ctx = Context::default(); + gridcraft_ui_egui::framework::install_headless(&ctx); ctx.set_embed_viewports(false); Context::set_immediate_viewport_renderer(|ctx, viewport| { let id = viewport.ids.this; @@ -77,6 +78,7 @@ impl Desk { } app.logic(&ctx); windows.logic(app, &ctx); + app.close_path(&ctx); windows.show(app, ui); }); record(out); @@ -458,8 +460,8 @@ fn arrange_all_lays_out_the_native_windows_active_first() { // Without parameters, as a script calls it: tiled. let r = desk.app.run("view.arrangeAll", json!({})).unwrap(); assert_eq!(r["arrange"], "tiled"); - let tiled = gridcraft_ui_egui::doc_windows::arrange_rects("tiled", 3, craft_window::Rect::new(0.0, 0.0, 1000.0, 800.0)); - let r = |x, y, w, h| craft_window::Rect::new(x, y, w, h); + let r = |x, y, w, h| egui::Rect::from_min_size(egui::pos2(x, y), egui::vec2(w, h)); + let tiled = gridcraft_ui_egui::doc_windows::arrange_rects("tiled", 3, r(0.0, 0.0, 1000.0, 800.0)); assert_eq!(tiled, [r(0.0, 0.0, 500.0, 400.0), r(500.0, 0.0, 500.0, 400.0), r(0.0, 400.0, 1000.0, 400.0)]); } diff --git a/crates/ui-egui/tests/header_autofit_fonts.rs b/crates/ui-egui/tests/header_autofit_fonts.rs index 9a2ff8a99..e0193c047 100644 --- a/crates/ui-egui/tests/header_autofit_fonts.rs +++ b/crates/ui-egui/tests/header_autofit_fonts.rs @@ -25,13 +25,17 @@ fn harness(selection: &str) -> egui_kittest::Harness<'static, SheetApp> { session.execute("home.columnWidth", json!({"cols": "A:D", "width": 100})).unwrap(); session.execute("home.rowHeight", json!({"rows": "1:4", "height": 60})).unwrap(); session.execute("selection.set", json!({"range": selection})).unwrap(); - let mut h = egui_kittest::Harness::builder().with_step_dt(1.0 / 60.0).with_size(vec2(1200.0, 800.0)).build_ui_state( - |ui, app: &mut SheetApp| { - app.logic(ui.ctx()); - app.ui(ui); - }, - SheetApp::new(session, Default::default()), - ); + let mut h = egui_kittest::Harness::builder() + .with_context_setup(gridcraft_ui_egui::framework::install_headless) + .with_step_dt(1.0 / 60.0) + .with_size(vec2(1200.0, 800.0)) + .build_ui_state( + |ui, app: &mut SheetApp| { + app.logic(ui.ctx()); + app.ui(ui); + }, + SheetApp::new(session, Default::default()), + ); h.run_steps(4); h.state_mut().session.active_mut().unwrap().undo.clear(); h.state_mut().session.journal.clear(); diff --git a/crates/ui-egui/tests/it/argument_names.rs b/crates/ui-egui/tests/it/argument_names.rs index 725c2edce..10edeeb57 100644 --- a/crates/ui-egui/tests/it/argument_names.rs +++ b/crates/ui-egui/tests/it/argument_names.rs @@ -27,6 +27,7 @@ fn ctrl_shift_a() -> Event { /// A cell editor holding `text`, caret at the end. fn editing(text: &str) -> (Context, SheetApp) { let ctx = Context::default(); + gridcraft_ui_egui::framework::install_headless(&ctx); let mut session = Session::new(); session.new_workbook(); let mut app = crate::common::app(session); diff --git a/crates/ui-egui/tests/it/cell_editor_caret.rs b/crates/ui-egui/tests/it/cell_editor_caret.rs index 39c7f4cec..42706456d 100644 --- a/crates/ui-egui/tests/it/cell_editor_caret.rs +++ b/crates/ui-egui/tests/it/cell_editor_caret.rs @@ -18,6 +18,7 @@ fn frame(ctx: &Context, app: &mut SheetApp) -> egui::FullOutput { /// The caret painted while editing A1 over `fill` (`None`: no fill), with the app in `dark` mode. fn caret(fill: Option<&str>, dark: bool) -> Color32 { let ctx = Context::default(); + gridcraft_ui_egui::framework::install_headless(&ctx); theme::apply(&ctx, dark); let mut session = Session::new(); session.new_workbook(); diff --git a/crates/ui-egui/tests/it/equation_editor.rs b/crates/ui-egui/tests/it/equation_editor.rs index c7ef5c654..75e46491e 100644 --- a/crates/ui-egui/tests/it/equation_editor.rs +++ b/crates/ui-egui/tests/it/equation_editor.rs @@ -12,8 +12,12 @@ use serde_json::{Value as Json, json}; type Harness = egui_kittest::Harness<'static, SheetApp>; fn harness(s: Session) -> Harness { - let mut h = - egui_kittest::Harness::builder().with_os(OperatingSystem::Mac).with_size(vec2(1400.0, 900.0)).with_step_dt(1.0 / 60.0).build_ui_state( + let mut h = egui_kittest::Harness::builder() + .with_context_setup(gridcraft_ui_egui::framework::install_headless) + .with_os(OperatingSystem::Mac) + .with_size(vec2(1400.0, 900.0)) + .with_step_dt(1.0 / 60.0) + .build_ui_state( |ui, app: &mut SheetApp| { app.logic(ui.ctx()); app.ui(ui); diff --git a/crates/ui-egui/tests/it/form_controls.rs b/crates/ui-egui/tests/it/form_controls.rs index 004563fe9..86e416568 100644 --- a/crates/ui-egui/tests/it/form_controls.rs +++ b/crates/ui-egui/tests/it/form_controls.rs @@ -38,6 +38,7 @@ fn fixture() -> (Harness, Ids) { let button = id(s.execute("insert.button", json!({"at": "E12", "text": "Mark it", "macro": "Mark"})).unwrap()); s.execute("selection.set", json!({"cell": "A20"})).unwrap(); let mut h = egui_kittest::Harness::builder() + .with_context_setup(gridcraft_ui_egui::framework::install_headless) .with_size(vec2(1400.0, 900.0)) .with_step_dt(1.0 / 60.0) .with_os(egui::os::OperatingSystem::Mac) @@ -591,6 +592,7 @@ fn insert_tab() -> Harness { let mut app = SheetApp::new(s, Default::default()); app.ui.ribbon_tab = "Insert".into(); let mut h = egui_kittest::Harness::builder() + .with_context_setup(gridcraft_ui_egui::framework::install_headless) .with_size(vec2(1400.0, 900.0)) .with_step_dt(1.0 / 60.0) .with_os(egui::os::OperatingSystem::Mac) diff --git a/crates/ui-egui/tests/it/formula_popup.rs b/crates/ui-egui/tests/it/formula_popup.rs index cb2055370..59f7f82d6 100644 --- a/crates/ui-egui/tests/it/formula_popup.rs +++ b/crates/ui-egui/tests/it/formula_popup.rs @@ -31,6 +31,7 @@ fn visible(ctx: &Context, editor: &str) -> bool { fn cell_formula_helpers_hide_when_scrolled_out_and_return_with_the_editor() { for text in ["=SU", "=SUM("] { let ctx = Context::default(); + gridcraft_ui_egui::framework::install_headless(&ctx); ctx.set_fonts(gridcraft_ui_egui::theme::pinned_font_definitions()); let mut session = Session::new(); session.new_workbook(); @@ -57,6 +58,7 @@ fn cell_formula_helpers_hide_when_scrolled_out_and_return_with_the_editor() { #[test] fn hidden_row_and_column_hide_the_wrapped_editor_until_unhidden() { let ctx = Context::default(); + gridcraft_ui_egui::framework::install_headless(&ctx); ctx.set_fonts(gridcraft_ui_egui::theme::pinned_font_definitions()); let mut session = Session::new(); session.new_workbook(); @@ -95,6 +97,7 @@ fn paints_visible_text(output: &egui::FullOutput, text: &str, cells: Rect) -> bo /// Formula-bar help stays visible while the sheet scrolls. fn formula_bar_hint_remains_visible_when_the_worksheet_scrolls() { let ctx = Context::default(); + gridcraft_ui_egui::framework::install_headless(&ctx); ctx.set_fonts(gridcraft_ui_egui::theme::pinned_font_definitions()); let mut session = Session::new(); session.new_workbook(); @@ -112,6 +115,7 @@ fn formula_bar_hint_remains_visible_when_the_worksheet_scrolls() { /// Cell argument help is clipped to the worksheet instead of painting over the headers. fn cell_argument_hint_is_clipped_to_the_worksheet() { let ctx = Context::default(); + gridcraft_ui_egui::framework::install_headless(&ctx); ctx.set_fonts(gridcraft_ui_egui::theme::pinned_font_definitions()); let mut session = Session::new(); session.new_workbook(); @@ -131,6 +135,7 @@ fn cell_argument_hint_is_clipped_to_the_worksheet() { /// An editor for a scrolled-out cell still handles Esc. fn scrolled_out_cell_editor_still_handles_escape() { let ctx = Context::default(); + gridcraft_ui_egui::framework::install_headless(&ctx); ctx.set_fonts(gridcraft_ui_egui::theme::pinned_font_definitions()); let mut session = Session::new(); session.new_workbook(); @@ -162,6 +167,7 @@ fn scrolled_out_cell_editor_still_handles_escape() { /// The editor and its helper clip below the frozen top row, stay hidden while the cell is under it, and return on scroll-back. fn cell_editor_and_helper_stay_below_the_frozen_top_row() { let ctx = Context::default(); + gridcraft_ui_egui::framework::install_headless(&ctx); ctx.set_fonts(gridcraft_ui_egui::theme::pinned_font_definitions()); let mut session = Session::new(); session.new_workbook(); @@ -214,6 +220,7 @@ fn cell_editor_and_helper_stay_below_the_frozen_top_row() { fn frozen_column_editor_paints_in_both_panes_on_a_right_to_left_sheet() { for (cell, text) in [("A2", "frozen"), ("B2", "scrolling")] { let ctx = Context::default(); + gridcraft_ui_egui::framework::install_headless(&ctx); ctx.set_fonts(gridcraft_ui_egui::theme::pinned_font_definitions()); let mut session = Session::new(); session.new_workbook(); @@ -257,6 +264,7 @@ fn frozen_column_editor_paints_in_both_panes_on_a_right_to_left_sheet() { fn argument_hint_shows_the_function_description() { // #363: inside DATEDIF( the hint lists the units the third argument takes. let ctx = Context::default(); + gridcraft_ui_egui::framework::install_headless(&ctx); ctx.set_fonts(gridcraft_ui_egui::theme::pinned_font_definitions()); let mut session = Session::new(); session.new_workbook(); diff --git a/crates/ui-egui/tests/it/in_cell_editor_wrap.rs b/crates/ui-egui/tests/it/in_cell_editor_wrap.rs index f3592b5fa..cc1fcce2d 100644 --- a/crates/ui-egui/tests/it/in_cell_editor_wrap.rs +++ b/crates/ui-egui/tests/it/in_cell_editor_wrap.rs @@ -23,6 +23,7 @@ fn frames(ctx: &Context, app: &mut SheetApp) { /// The editor's text field rect while A1 (narrow, wrap on or off) is edited with [`TEXT`]. fn editor_rect(wrap: bool) -> Rect { let ctx = Context::default(); + gridcraft_ui_egui::framework::install_headless(&ctx); let mut session = Session::new(); session.new_workbook(); session.execute("home.columnWidth", json!({"cols": "A:A", "chars": 12})).unwrap(); @@ -47,6 +48,7 @@ fn a_wrap_text_cell_edits_wrapped_at_the_column_width() { #[test] fn a_short_wrap_text_edit_stays_one_line_tall() { let ctx = Context::default(); + gridcraft_ui_egui::framework::install_headless(&ctx); let mut session = Session::new(); session.new_workbook(); session.execute("home.wrapText", json!({"range": "A1", "on": true})).unwrap(); @@ -64,6 +66,7 @@ fn a_short_wrap_text_edit_stays_one_line_tall() { #[test] fn the_editor_measures_the_text_at_the_fields_wrap_width() { let ctx = Context::default(); + gridcraft_ui_egui::framework::install_headless(&ctx); let mut session = Session::new(); session.new_workbook(); session.execute("home.columnWidth", json!({"cols": "A:A", "chars": 12})).unwrap(); @@ -91,6 +94,7 @@ fn the_editor_measures_the_text_at_the_fields_wrap_width() { fn an_unwrapped_multiline_edit_shows_every_line() { let field = |text: &str| { let ctx = Context::default(); + gridcraft_ui_egui::framework::install_headless(&ctx); let mut session = Session::new(); session.new_workbook(); let mut app = crate::common::app(session); diff --git a/crates/ui-egui/tests/it/interface_scale.rs b/crates/ui-egui/tests/it/interface_scale.rs index 44991bbec..e80b3f377 100644 --- a/crates/ui-egui/tests/it/interface_scale.rs +++ b/crates/ui-egui/tests/it/interface_scale.rs @@ -16,11 +16,11 @@ fn interface_size_applies_persists_and_clamps() { }, crate::common::app(session), ); - h.run_steps(2); + crate::support::frames(&mut h, 2); assert_eq!(h.ctx.zoom_factor(), 1.0); h.state_mut().run("view.interfaceScale", json!({"percent": 125})).unwrap(); - h.run_steps(2); + crate::support::frames(&mut h, 2); assert_eq!(h.ctx.zoom_factor(), 1.25); let saved: UiState = serde_json::from_str(&serde_json::to_string(&h.state().ui).unwrap()).unwrap(); assert_eq!(saved.interface_scale, 125); @@ -31,7 +31,7 @@ fn interface_size_applies_persists_and_clamps() { assert!(h.state_mut().run("view.interfaceScale", json!({})).is_err(), "no value is an error, not a dialog"); assert!(h.state_mut().run("view.interfaceScale", json!({"percent": "huge"})).is_err()); h.state_mut().run("view.interfaceScale", json!({"percent": "auto"})).unwrap(); - h.run_steps(2); + crate::support::frames(&mut h, 2); assert_eq!(h.ctx.zoom_factor(), 1.0); // A malformed or out-of-range ui.json keeps the other preferences. diff --git a/crates/ui-egui/tests/it/macro_editor.rs b/crates/ui-egui/tests/it/macro_editor.rs index 6523dd039..07f439f2c 100644 --- a/crates/ui-egui/tests/it/macro_editor.rs +++ b/crates/ui-egui/tests/it/macro_editor.rs @@ -20,14 +20,17 @@ fn harness_with(services: Services) -> Harness { session.new_workbook(); let mut app = SheetApp::new(session, services); app.ui.ribbon_tab = "Automate".into(); - let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_ui_state( - |ui, app: &mut SheetApp| { - let ctx = ui.ctx().clone(); - app.logic(&ctx); - app.ui(ui); - }, - app, - ); + let mut h = egui_kittest::Harness::builder() + .with_context_setup(gridcraft_ui_egui::framework::install_headless) + .with_size(egui::vec2(1400.0, 900.0)) + .build_ui_state( + |ui, app: &mut SheetApp| { + let ctx = ui.ctx().clone(); + app.logic(&ctx); + app.ui(ui); + }, + app, + ); h.run_steps(4); h } @@ -566,14 +569,15 @@ fn the_editor_fits_a_narrow_window() { let mut session = Session::new(); session.new_workbook(); let app = SheetApp::new(session, Default::default()); - let mut h = egui_kittest::Harness::builder().with_size(size).build_ui_state( - |ui, app: &mut SheetApp| { - let ctx = ui.ctx().clone(); - app.logic(&ctx); - app.ui(ui); - }, - app, - ); + let mut h = + egui_kittest::Harness::builder().with_context_setup(gridcraft_ui_egui::framework::install_headless).with_size(size).build_ui_state( + |ui, app: &mut SheetApp| { + let ctx = ui.ctx().clone(); + app.logic(&ctx); + app.ui(ui); + }, + app, + ); h.run_steps(4); three(&mut h); h.run_steps(4); diff --git a/crates/ui-egui/tests/it/macros_ui.rs b/crates/ui-egui/tests/it/macros_ui.rs index 171821cb7..d48a65079 100644 --- a/crates/ui-egui/tests/it/macros_ui.rs +++ b/crates/ui-egui/tests/it/macros_ui.rs @@ -16,14 +16,17 @@ fn harness(tab: &str) -> Harness { session.new_workbook(); let mut app = SheetApp::new(session, Default::default()); app.ui.ribbon_tab = tab.into(); - let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(1280.0, 800.0)).build_ui_state( - |ui, app: &mut SheetApp| { - let ctx = ui.ctx().clone(); - app.logic(&ctx); - app.ui(ui); - }, - app, - ); + let mut h = egui_kittest::Harness::builder() + .with_context_setup(gridcraft_ui_egui::framework::install_headless) + .with_size(egui::vec2(1280.0, 800.0)) + .build_ui_state( + |ui, app: &mut SheetApp| { + let ctx = ui.ctx().clone(); + app.logic(&ctx); + app.ui(ui); + }, + app, + ); h.run_steps(4); h } @@ -115,14 +118,17 @@ fn the_macros_dialog_lists_scripts_and_the_vba_project_beside_macros() { s.execute("macro.save", json!({"name": "Mark", "steps": []})).unwrap(); let mut app = SheetApp::new(s, Default::default()); app.ui.ribbon_tab = "Automate".into(); - let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(1280.0, 800.0)).build_ui_state( - |ui, app: &mut SheetApp| { - let ctx = ui.ctx().clone(); - app.logic(&ctx); - app.ui(ui); - }, - app, - ); + let mut h = egui_kittest::Harness::builder() + .with_context_setup(gridcraft_ui_egui::framework::install_headless) + .with_size(egui::vec2(1280.0, 800.0)) + .build_ui_state( + |ui, app: &mut SheetApp| { + let ctx = ui.ctx().clone(); + app.logic(&ctx); + app.ui(ui); + }, + app, + ); h.run_steps(3); h.state_mut().open_dialog("macros", json!({})); h.run_steps(2); @@ -260,14 +266,17 @@ fn the_macros_dialog_offers_trust_for_scripts_that_came_with_a_file() { s.active_mut().unwrap().scripts_trusted = false; let mut app = SheetApp::new(s, Default::default()); app.ui.ribbon_tab = "Automate".into(); - let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(1280.0, 800.0)).build_ui_state( - |ui, app: &mut SheetApp| { - let ctx = ui.ctx().clone(); - app.logic(&ctx); - app.ui(ui); - }, - app, - ); + let mut h = egui_kittest::Harness::builder() + .with_context_setup(gridcraft_ui_egui::framework::install_headless) + .with_size(egui::vec2(1280.0, 800.0)) + .build_ui_state( + |ui, app: &mut SheetApp| { + let ctx = ui.ctx().clone(); + app.logic(&ctx); + app.ui(ui); + }, + app, + ); h.run_steps(3); h.state_mut().open_dialog("macros", json!({})); h.run_steps(2); @@ -291,14 +300,15 @@ fn the_macros_and_record_macro_dialogs_fit_a_narrow_window() { s.new_workbook(); s.execute("macro.save", json!({"name": "Tidy", "steps": []})).unwrap(); let app = SheetApp::new(s, Default::default()); - let mut h = egui_kittest::Harness::builder().with_size(size).build_ui_state( - |ui, app: &mut SheetApp| { - let ctx = ui.ctx().clone(); - app.logic(&ctx); - app.ui(ui); - }, - app, - ); + let mut h = + egui_kittest::Harness::builder().with_context_setup(gridcraft_ui_egui::framework::install_headless).with_size(size).build_ui_state( + |ui, app: &mut SheetApp| { + let ctx = ui.ctx().clone(); + app.logic(&ctx); + app.ui(ui); + }, + app, + ); h.run_steps(3); let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, size); for (dialog, labels) in [("macros", &["Run", "Delete", "Options…", "Cancel"][..]), ("recordMacro", &["OK", "Cancel"][..])] { diff --git a/crates/ui-egui/tests/it/native_print.rs b/crates/ui-egui/tests/it/native_print.rs index 542083df4..01c91890e 100644 --- a/crates/ui-egui/tests/it/native_print.rs +++ b/crates/ui-egui/tests/it/native_print.rs @@ -1,6 +1,6 @@ //! Native print onboarding preserves engine PDF generation and submits the selected settings. use gridcraft_engine::Session; -use gridcraft_ui_egui::printing::{Duplex, Feedback, Printer}; +use gridcraft_ui_egui::printing::{Destination, Duplex, Feedback, Printer}; use gridcraft_ui_egui::{Services, SheetApp}; use serde_json::json; use std::{cell::RefCell, rc::Rc}; @@ -25,7 +25,7 @@ fn native_print_uses_selected_settings_and_reports_spool_errors() { let pdf = app.run("file.print", json!({"sheets":"active"})).unwrap(); assert!(pdf["base64"].as_str().is_some(), "the engine still returns PDF bytes without submitting"); assert!(jobs.borrow().is_empty(), "opening settings/exporting does not spool"); - app.printing.printers.push(Printer { name: "Chosen queue".into(), label: String::new(), default: false }); + app.printing.printers.push(Printer::new("Chosen queue")); let configured = app.run("ui.printSettings", json!({"printer":"Chosen queue", "copies":3,"duplex":"shortEdge","grayscale":true})).unwrap(); assert_eq!(configured["ready"], true); assert_eq!(configured["printers"][0]["name"], "Chosen queue"); @@ -34,7 +34,7 @@ fn native_print_uses_selected_settings_and_reports_spool_errors() { let jobs = jobs.borrow(); assert_eq!(jobs.len(), 1); assert!(jobs[0].0.starts_with(b"%PDF")); - assert_eq!(jobs[0].1.printer, "Chosen queue"); + assert_eq!(jobs[0].1.destination, Destination::Printer("Chosen queue".into())); assert_eq!(jobs[0].1.copies, 3); assert_eq!(jobs[0].1.duplex, Some(Duplex::ShortEdge)); assert!(jobs[0].1.grayscale); @@ -53,7 +53,7 @@ fn print_settings_are_visible_in_a_narrow_window() { app.run("cell.set", json!({"cell":"A1", "input":"A sheet to print"})).unwrap(); app.services.printers = Some(Box::new(|| { let (sender, receiver) = std::sync::mpsc::channel(); - sender.send(vec![Printer { name: "Test queue".into(), label: String::new(), default: true }]).unwrap(); + sender.send(vec![Printer::new("Test queue").is_default(true)]).unwrap(); receiver })); app.services.print_native = Some(Box::new(|_, _| { @@ -70,7 +70,7 @@ fn print_settings_are_visible_in_a_narrow_window() { app, ); harness.run_steps(5); - assert!(!harness.get_by_label("Refresh printers").accesskit_node().is_disabled()); + assert!(!harness.get_by_label("Refresh").accesskit_node().is_disabled()); assert!(!harness.get_by_label("Grayscale").accesskit_node().is_disabled()); harness.get_by_label("Grayscale").click(); harness.run_steps(2); @@ -84,7 +84,7 @@ fn invalid_print_settings_are_rejected_without_partial_changes() { let mut session = Session::new(); session.new_workbook(); let mut app = SheetApp::new(session, Services::default()); - app.printing.printers.push(Printer { name: "Queue".into(), label: String::new(), default: true }); + app.printing.printers.push(Printer::new("Queue").is_default(true)); let before = app.run("ui.printSettings", json!({})).unwrap(); for params in [ json!({"printer":"Missing"}), @@ -110,7 +110,7 @@ fn repeated_fast_jobs_each_surface_an_identical_receipt() { let mut session = Session::new(); session.new_workbook(); let mut app = SheetApp::new(session, Services::default()); - app.printing.printers.push(Printer { name: "Queue".into(), label: String::new(), default: true }); + app.printing.printers.push(Printer::new("Queue").is_default(true)); app.run("ui.printSettings", json!({"printer":"Queue"})).unwrap(); app.services.print_native = Some(Box::new(|_, _| { let (sender, receiver) = std::sync::mpsc::channel(); diff --git a/crates/ui-egui/tests/it/objects.rs b/crates/ui-egui/tests/it/objects.rs index b1b59afbb..7b45378ee 100644 --- a/crates/ui-egui/tests/it/objects.rs +++ b/crates/ui-egui/tests/it/objects.rs @@ -53,6 +53,7 @@ fn fixture() -> (Harness, Objects) { slicer: ObjRef::new(ObjKind::Slicer, slicer), }; let mut h = egui_kittest::Harness::builder() + .with_context_setup(gridcraft_ui_egui::framework::install_headless) .with_size(vec2(1400.0, 900.0)) .with_step_dt(1.0 / 60.0) .with_os(egui::os::OperatingSystem::Mac) diff --git a/crates/ui-egui/tests/it/pivot_pane.rs b/crates/ui-egui/tests/it/pivot_pane.rs index 1076e3e14..d9edd8045 100644 --- a/crates/ui-egui/tests/it/pivot_pane.rs +++ b/crates/ui-egui/tests/it/pivot_pane.rs @@ -18,6 +18,7 @@ fn render_pivot_field_buttons(dark: bool) -> Vec { let mut app = crate::common::app(session); app.ui.dark = dark; let ctx = egui::Context::default(); + gridcraft_ui_egui::framework::install_headless(&ctx); let mut output = egui::FullOutput::default(); for _ in 0..6 { output = ctx.run_ui(RawInput { screen_rect: Some(Rect::from_min_size(pos2(0.0, 0.0), vec2(1200.0, 800.0))), ..Default::default() }, |ui| { @@ -76,14 +77,17 @@ fn the_field_list_scrollbar_sits_at_the_pane_edge() { session.execute("range.setValues", json!({"range": "A1", "values": [names.clone(), (1..=14).collect::>()]})).unwrap(); session.execute("insert.pivotTable", json!({"source": "Sheet1!A1:N2", "destination": "Sheet1!A5", "rows": ["F1"], "values": ["F2"]})).unwrap(); session.execute("selection.set", json!({"cell": "A5"})).unwrap(); - let mut h = egui_kittest::Harness::builder().with_size(vec2(1200.0, 800.0)).build_ui_state( - |ui, app: &mut SheetApp| { - let ctx = ui.ctx().clone(); - app.logic(&ctx); - app.ui(ui); - }, - SheetApp::new(session, Default::default()), - ); + let mut h = egui_kittest::Harness::builder() + .with_context_setup(gridcraft_ui_egui::framework::install_headless) + .with_size(vec2(1200.0, 800.0)) + .build_ui_state( + |ui, app: &mut SheetApp| { + let ctx = ui.ctx().clone(); + app.logic(&ctx); + app.ui(ui); + }, + SheetApp::new(session, Default::default()), + ); h.run_steps(4); let first = h.get_by_label("F1").rect(); // A floating scrollbar is drawn while the pointer is over its area. diff --git a/crates/ui-egui/tests/it/selection_glide.rs b/crates/ui-egui/tests/it/selection_glide.rs index b09a61b64..b1f43df9b 100644 --- a/crates/ui-egui/tests/it/selection_glide.rs +++ b/crates/ui-egui/tests/it/selection_glide.rs @@ -190,6 +190,7 @@ fn view_animations_sets_and_toggles_without_a_dialog() { fn agents_find_run_and_read_the_setting_over_the_control_channel() { let mut a = app(); let ctx = egui::Context::default(); + gridcraft_ui_egui::framework::install_headless(&ctx); let found = reply(control::handle(&mut a, &ctx, "engine.commands", &json!({"search": "animations"}))); let entry = found["result"].as_array().and_then(|all| all.iter().find(|c| c["id"] == "view.animations")).cloned().unwrap(); assert_eq!((&entry["label"], &entry["ui"]), (&json!("Animations"), &json!(true))); diff --git a/crates/ui-egui/tests/it/support.rs b/crates/ui-egui/tests/it/support.rs index 0136b3d5e..e9dc6a317 100644 --- a/crates/ui-egui/tests/it/support.rs +++ b/crates/ui-egui/tests/it/support.rs @@ -39,3 +39,13 @@ pub fn services_harness(services: Services, steps: usize) -> Harness { pub fn app_harness(app: SheetApp, steps: usize) -> Harness { harness_with(builder().with_size(egui::vec2(1200.0, 800.0)), app, steps) } + +/// Runs `n` frames as the desktop and web shells do: the app hands the runtime its frame input +/// (theme mode, interface scale) before each one. +pub fn frames(h: &mut Harness, n: usize) { + for _ in 0..n { + let ctx = h.ctx.clone(); + h.state_mut().before_input(&ctx); + h.step(); + } +} diff --git a/crates/ui-egui/tests/shape_select.rs b/crates/ui-egui/tests/shape_select.rs index a3d674572..27907bfb7 100644 --- a/crates/ui-egui/tests/shape_select.rs +++ b/crates/ui-egui/tests/shape_select.rs @@ -25,14 +25,17 @@ fn fixture_of(kind: &str) -> (Harness, u32) { let shape = session.execute("insert.shape", json!({"kind": kind, "at": "D3", "width": 160, "height": height})).unwrap(); shape["shape"].as_u64().unwrap() as u32 }; - let mut h = egui_kittest::Harness::builder().with_size(vec2(1200.0, 800.0)).build_ui_state( - |ui, app: &mut SheetApp| { - let ctx = ui.ctx().clone(); - app.logic(&ctx); - app.ui(ui); - }, - SheetApp::new(session, Default::default()), - ); + let mut h = egui_kittest::Harness::builder() + .with_context_setup(gridcraft_ui_egui::framework::install_headless) + .with_size(vec2(1200.0, 800.0)) + .build_ui_state( + |ui, app: &mut SheetApp| { + let ctx = ui.ctx().clone(); + app.logic(&ctx); + app.ui(ui); + }, + SheetApp::new(session, Default::default()), + ); h.run_steps(4); h.state_mut().selected_object = None; h.run_steps(2);