diff --git a/.config/cargo-ci.toml b/.config/cargo-ci.toml index 30eba421cc..956491323b 100644 --- a/.config/cargo-ci.toml +++ b/.config/cargo-ci.toml @@ -1,6 +1,8 @@ # The Workspace gate's additions to .config/cargo-dev.toml (scripts/ci-workspace-tests.sh passes both). The gate runs # every test of these crates, and their tests spend nearly all their time in sample and pixel loops, which run several -# times faster at opt-level 1; locally they stay at 0, so an edit to them rebuilds fast. +# times faster at opt-level 1; locally they stay at 0, so an edit to them rebuilds fast. craft-pdf (R6 hash and AES-CBC +# loops), craft-pkcs7 and craft-odf (PBKDF2 rounds, monomorphised in the crate) and craft-cms (CLUT builds) run their +# own hot loops in tests, so they take part too. [profile.dev.package.craft-audio-dsp] opt-level = 1 @@ -15,3 +17,15 @@ opt-level = 1 [profile.dev.package.craft-imaging] opt-level = 1 + +[profile.dev.package.craft-pdf] +opt-level = 1 + +[profile.dev.package.craft-pkcs7] +opt-level = 1 + +[profile.dev.package.craft-odf] +opt-level = 1 + +[profile.dev.package.craft-cms] +opt-level = 1 diff --git a/.github/workflows/workspace.yml b/.github/workflows/workspace.yml index bc6077bfac..63170f1214 100644 --- a/.github/workflows/workspace.yml +++ b/.github/workflows/workspace.yml @@ -44,6 +44,7 @@ jobs: filter: ${{ steps.select.outputs.filter }} audit: ${{ steps.audit.outputs.audit }} profile: ${{ steps.audit.outputs.profile }} + deps-profile: ${{ steps.audit.outputs.deps-profile }} steps: - name: Harden runner uses: step-security/harden-runner@v2.22.4 @@ -67,6 +68,10 @@ jobs: # passes (scripts/ci-workspace-tests.sh), which names the Workspace legs' cache entries: # rust-cache's key does not hash these files, and an entry built with other overrides would be # rebuilt in full on every run. Other events than a pull request check out only these files. + # The macOS and Windows legs cache dependencies only, so `deps-profile` hashes only the + # settings that reach a dependency: `[profile.dev]` and `[profile.dev.package."*"]`. Every + # other override names a workspace crate (scripts/test-workspace-tests.py), so changing one + # keeps those entries, and next's runs restore main's. - uses: actions/checkout@v7.0.1 if: github.event_name != 'pull_request' with: @@ -83,6 +88,18 @@ jobs: run: | echo "audit=$(bash scripts/ci-workspace-tests.sh audit)" >> "$GITHUB_OUTPUT" echo "profile=$(cat .config/cargo-dev.toml .config/cargo-ci.toml | sha256sum | cut -c1-12)" >> "$GITHUB_OUTPUT" + # An assignment, so a failure stops the step (`bash -e`) instead of naming every entry `v2-`. + deps=$(python3 -I - <<'PY' + import hashlib, json, tomllib + kept = [] + for path in (".config/cargo-dev.toml", ".config/cargo-ci.toml"): + with open(path, "rb") as file: + dev = tomllib.load(file)["profile"]["dev"] + kept.append([dev, dev.pop("package", {}).get("*", {})]) + print(hashlib.sha256(json.dumps(kept, sort_keys=True).encode()).hexdigest()[:12]) + PY + ) + echo "deps-profile=$deps" >> "$GITHUB_OUTPUT" # The Linux leg keeps the compiled workspace crates between runs (`cache-workspace-crates`): each # main run saves a rolling cache entry of its own, every run restores the newest one, and Cargo @@ -150,7 +167,8 @@ jobs: cargo clippy --workspace --all-targets --all-features --locked -- -D warnings # A selection that reaches a replay-audit crate builds once in a `build` job, which writes # three nextest archives and then runs the doctests; three shard legs run them in parallel: - # every selected test, the replay audit, and the default-feature crates. Any other selection + # every selected test outside the replay audit's crates, those crates (run plainly, then with the + # audit), and craft-image-codecs with default features. Any other selection # (and every macOS and Windows leg) builds and runs in one leg. scripts/ci-workspace-tests.sh # holds every step. test-shards: ${{ needs.platforms.outputs.audit == 'true' && 3 || 0 }} @@ -172,7 +190,8 @@ jobs: with: os: '["windows-latest","macos-latest"]' lint-cache: false - cache-version: *cache-version + # Named by the dependency settings alone (`deps-profile`), so next restores main's entries. + cache-version: v2-${{ needs.platforms.outputs.deps-profile }} timeout-minutes: *timeout tools: *tools craft-fonts-ref: *craft-fonts diff --git a/Cargo.lock b/Cargo.lock index 664f291e39..62dfc38e65 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2301,6 +2301,7 @@ dependencies = [ name = "craft-crw" version = "0.1.0" dependencies = [ + "craft-testkit", "serde", "serde_json", "sha2 0.10.9", @@ -2375,6 +2376,7 @@ dependencies = [ "craft-geom", "craft-raw", "craft-render-parity", + "craft-testkit", "proptest", "rayon", "serde", @@ -2533,6 +2535,7 @@ name = "craft-drawingml" version = "0.1.0" dependencies = [ "chrono", + "craft-testkit", "craft-xml", "kurbo", "log", @@ -2945,6 +2948,7 @@ dependencies = [ name = "craft-heif" version = "0.1.0" dependencies = [ + "craft-testkit", "heic-rs", "proptest", "rayon", @@ -3127,6 +3131,7 @@ dependencies = [ name = "craft-jpeg" version = "0.1.0" dependencies = [ + "craft-testkit", "jpeg-decoder", "jpeg-encoder 0.6.1", "rayon", @@ -3248,6 +3253,7 @@ dependencies = [ name = "craft-material-graph" version = "0.1.0" dependencies = [ + "craft-testkit", "libm", "rayon", ] @@ -3404,6 +3410,7 @@ dependencies = [ "chardetng", "chrono", "craft-codepage", + "craft-testkit", "encoding_rs", "proptest", ] @@ -3841,6 +3848,7 @@ name = "craft-ps" version = "0.1.0" dependencies = [ "craft-eps", + "craft-testkit", "flate2", "kurbo", "miniz_oxide 0.8.9", @@ -4771,6 +4779,7 @@ dependencies = [ name = "craft-xcf" version = "0.1.0" dependencies = [ + "craft-testkit", "flate2", "thiserror 2.0.21", ] @@ -5562,7 +5571,7 @@ dependencies = [ [[package]] name = "ecolor" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=a87d00caaec947ea781657c6ff410c9838016d18#a87d00caaec947ea781657c6ff410c9838016d18" +source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec" dependencies = [ "bytemuck", "emath", @@ -5618,7 +5627,7 @@ dependencies = [ [[package]] name = "eframe" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=a87d00caaec947ea781657c6ff410c9838016d18#a87d00caaec947ea781657c6ff410c9838016d18" +source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec" dependencies = [ "ahash", "bytemuck", @@ -5653,7 +5662,7 @@ dependencies = [ [[package]] name = "egui" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=a87d00caaec947ea781657c6ff410c9838016d18#a87d00caaec947ea781657c6ff410c9838016d18" +source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec" dependencies = [ "accesskit", "ahash", @@ -5672,7 +5681,7 @@ dependencies = [ [[package]] name = "egui-wgpu" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=a87d00caaec947ea781657c6ff410c9838016d18#a87d00caaec947ea781657c6ff410c9838016d18" +source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec" dependencies = [ "ahash", "bytemuck", @@ -5691,7 +5700,7 @@ dependencies = [ [[package]] name = "egui-winit" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=a87d00caaec947ea781657c6ff410c9838016d18#a87d00caaec947ea781657c6ff410c9838016d18" +source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec" dependencies = [ "block2 0.6.2", "bytemuck", @@ -5711,7 +5720,7 @@ dependencies = [ [[package]] name = "egui_glow" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=a87d00caaec947ea781657c6ff410c9838016d18#a87d00caaec947ea781657c6ff410c9838016d18" +source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec" dependencies = [ "bytemuck", "egui", @@ -5724,7 +5733,7 @@ dependencies = [ [[package]] name = "egui_kittest" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=a87d00caaec947ea781657c6ff410c9838016d18#a87d00caaec947ea781657c6ff410c9838016d18" +source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec" dependencies = [ "eframe", "egui", @@ -5801,7 +5810,7 @@ dependencies = [ [[package]] name = "emath" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=a87d00caaec947ea781657c6ff410c9838016d18#a87d00caaec947ea781657c6ff410c9838016d18" +source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec" dependencies = [ "bytemuck", ] @@ -5874,7 +5883,7 @@ dependencies = [ [[package]] name = "epaint" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=a87d00caaec947ea781657c6ff410c9838016d18#a87d00caaec947ea781657c6ff410c9838016d18" +source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec" dependencies = [ "ahash", "bytemuck", @@ -5900,7 +5909,7 @@ dependencies = [ [[package]] name = "epaint_default_fonts" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=a87d00caaec947ea781657c6ff410c9838016d18#a87d00caaec947ea781657c6ff410c9838016d18" +source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec" [[package]] name = "equator" @@ -15232,19 +15241,19 @@ dependencies = [ [[patch.unused]] name = "egui_demo_lib" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=a87d00caaec947ea781657c6ff410c9838016d18#a87d00caaec947ea781657c6ff410c9838016d18" +source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec" [[patch.unused]] name = "egui_extras" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=a87d00caaec947ea781657c6ff410c9838016d18#a87d00caaec947ea781657c6ff410c9838016d18" +source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec" [[patch.unused]] name = "egui_inspection" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=a87d00caaec947ea781657c6ff410c9838016d18#a87d00caaec947ea781657c6ff410c9838016d18" +source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec" [[patch.unused]] name = "egui_system_font_provider" version = "0.37.0" -source = "git+https://github.com/storytold/egui.git?rev=a87d00caaec947ea781657c6ff410c9838016d18#a87d00caaec947ea781657c6ff410c9838016d18" +source = "git+https://github.com/storytold/egui.git?rev=b15ffe9bfc2c8e6748533b32b708e10abaf2afec#b15ffe9bfc2c8e6748533b32b708e10abaf2afec" diff --git a/Cargo.toml b/Cargo.toml index 3ab56cbec0..cc40daf56d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -316,20 +316,20 @@ hayro-postscript = { path = "vendor/hayro-postscript" } linesweeper = { path = "vendor/linesweeper" } vello_common = { path = "vendor/vello_common" } vello_cpu = { path = "vendor/vello_cpu" } -ecolor = { git = "https://github.com/storytold/egui.git", rev = "a87d00caaec947ea781657c6ff410c9838016d18" } -emath = { git = "https://github.com/storytold/egui.git", rev = "a87d00caaec947ea781657c6ff410c9838016d18" } -epaint = { git = "https://github.com/storytold/egui.git", rev = "a87d00caaec947ea781657c6ff410c9838016d18" } -epaint_default_fonts = { git = "https://github.com/storytold/egui.git", rev = "a87d00caaec947ea781657c6ff410c9838016d18" } -egui = { git = "https://github.com/storytold/egui.git", rev = "a87d00caaec947ea781657c6ff410c9838016d18" } -egui-winit = { git = "https://github.com/storytold/egui.git", rev = "a87d00caaec947ea781657c6ff410c9838016d18" } -egui-wgpu = { git = "https://github.com/storytold/egui.git", rev = "a87d00caaec947ea781657c6ff410c9838016d18" } -egui_glow = { git = "https://github.com/storytold/egui.git", rev = "a87d00caaec947ea781657c6ff410c9838016d18" } -egui_extras = { git = "https://github.com/storytold/egui.git", rev = "a87d00caaec947ea781657c6ff410c9838016d18" } -egui_kittest = { git = "https://github.com/storytold/egui.git", rev = "a87d00caaec947ea781657c6ff410c9838016d18" } -egui_system_font_provider = { git = "https://github.com/storytold/egui.git", rev = "a87d00caaec947ea781657c6ff410c9838016d18" } -eframe = { git = "https://github.com/storytold/egui.git", rev = "a87d00caaec947ea781657c6ff410c9838016d18" } -egui_demo_lib = { git = "https://github.com/storytold/egui.git", rev = "a87d00caaec947ea781657c6ff410c9838016d18" } -egui_inspection = { git = "https://github.com/storytold/egui.git", rev = "a87d00caaec947ea781657c6ff410c9838016d18" } +ecolor = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" } +emath = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" } +epaint = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" } +epaint_default_fonts = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" } +egui = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" } +egui-winit = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" } +egui-wgpu = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" } +egui_glow = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" } +egui_extras = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" } +egui_kittest = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" } +egui_system_font_provider = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" } +eframe = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" } +egui_demo_lib = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" } +egui_inspection = { git = "https://github.com/storytold/egui.git", rev = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec" } winit = { git = "https://github.com/storytold/winit.git", rev = "a517b3846ee8457d84ee4975110bfda6797c44dc" } # symphonia's FLAC decoder restores LPC samples as `residual + (prediction as i32)`. In a valid diff --git a/crates/audio-dsp/src/effects.rs b/crates/audio-dsp/src/effects.rs index 862ee0f46a..679b7c5f9a 100644 --- a/crates/audio-dsp/src/effects.rs +++ b/crates/audio-dsp/src/effects.rs @@ -291,6 +291,7 @@ mod tests { std::thread::scope(|scope| { for e in crate::testutil::sampled_effects() { scope.spawn(move || { + let started = std::time::Instant::now(); for setting in [0.0f32, 1.0] { let mut fx = (e.create)(SR, 2); for p in e.params { @@ -318,6 +319,9 @@ mod tests { ); } } + if started.elapsed() > std::time::Duration::from_secs(1) { + eprintln!("DIAG extreme settings: {} took {:?}", e.id, started.elapsed()); + } }); } }); diff --git a/crates/audio-dsp/src/resample.rs b/crates/audio-dsp/src/resample.rs index 745e628e47..12b5664706 100644 --- a/crates/audio-dsp/src/resample.rs +++ b/crates/audio-dsp/src/resample.rs @@ -418,21 +418,20 @@ mod tests { /// returns `MAX_RESAMPLE_BLOCK` frames. #[test] fn source_held_and_block_length_are_bounded() { - let t0 = std::time::Instant::now(); + // At this ratio a pull holds about 42 output frames' worth of source, so 64 frames take two pulls; each output + // frame pulls 1,536 source frames of 64 channels, so nightly runs a longer block. + let frames = if craft_testkit::hostile::divisor() == 1 { 1_024 } else { 64 }; let mut r = StreamResampler::new(1_536_000, 1_000); let mut widest = 0; - let out = r.process(0, 1_024, |_, frames| { + let out = r.process(0, frames, |_, frames| { widest = widest.max(frames); vec![vec![0.5; frames]; 64] }); - assert_eq!((out.len(), out[0].len()), (64, 1_024)); + assert_eq!((out.len(), out[0].len()), (64, frames)); assert!(widest <= MAX_RESAMPLE_HELD / 64, "{widest}"); assert!(r.held.iter().map(Vec::len).sum::() <= MAX_RESAMPLE_HELD); - eprintln!("DIAG resample wide ratio {:?}", t0.elapsed()); - let t1 = std::time::Instant::now(); let mut r = StreamResampler::new(48_000, 48_000); let out = r.process(0, usize::MAX, |_, frames| vec![vec![0.5; frames]]); - eprintln!("DIAG resample oversized block {:?}", t1.elapsed()); assert_eq!(out[0].len(), MAX_RESAMPLE_BLOCK); assert!(out[0].iter().all(|&x| x == 0.5)); } diff --git a/crates/behavior/src/press.rs b/crates/behavior/src/press.rs index 50269615ff..227098fa3f 100644 --- a/crates/behavior/src/press.rs +++ b/crates/behavior/src/press.rs @@ -78,12 +78,14 @@ pub struct PressStart { pub time: f64, /// 1 for a single press, 2 for a double press, and so on. pub clicks: u32, + /// The press went down on another target, which handed it to this one ([`PressMachine::take_over`]). + pub handed: bool, } impl PressStart { /// A press of `button` at `origin`. pub const fn new(origin: Pos2, button: PointerButton, time: f64, clicks: u32) -> Self { - PressStart { origin, button, time, clicks } + PressStart { origin, button, time, clicks, handed: false } } } @@ -629,8 +631,9 @@ impl PressMachine { } /// Takes over a press whose button is down and went down elsewhere, as a drag of `target` from `start`: the next - /// pass reports `DragStart`, and later ones the press's own `Drag`, `Release` or `Cancel` from their input. A - /// press this machine holds already stays as it is. + /// pass reports `DragStart`, and later ones the press's own `Drag`, `Release` or `Cancel` from their input, each + /// with a start that says it was handed over ([`PressStart::handed`]). A press this machine holds already stays as + /// it is. // PLAN: the sheet's Files table has no row for this file; the handover of a held press (decision q346) needs the // machine to open a press that did not begin on it, which only the machine can build. pub fn take_over(&mut self, target: T, sense: Sense, start: PressStart) { @@ -640,7 +643,7 @@ impl PressMachine { self.open = Some(Open { target, sense: sense - Sense::CLICK, - start, + start: PressStart { handed: true, ..start }, dragging: true, abandoned: false, left: false, diff --git a/crates/captions/tests/it/limits.rs b/crates/captions/tests/it/limits.rs index 0b010ed412..8a7c14ba62 100644 --- a/crates/captions/tests/it/limits.rs +++ b/crates/captions/tests/it/limits.rs @@ -18,7 +18,10 @@ fn input_over_the_size_limit_is_refused() { for format in Format::ALL { assert_eq!(parse(&big, format), Err(Error::TooLarge(MAX_INPUT)), "{format:?}"); } - assert!(parse(big.get(..MAX_INPUT).unwrap(), Format::Srt).is_ok()); + // Reading 64 MiB at the limit takes seconds: nightly only. + if craft_testkit::hostile::divisor() == 1 { + assert!(parse(big.get(..MAX_INPUT).unwrap(), Format::Srt).is_ok()); + } } /// TTML is read without entity expansion: a document type with entities defines nothing. diff --git a/crates/craft/src/egui_fork.rs b/crates/craft/src/egui_fork.rs index 182581c420..b8535c5c1e 100644 --- a/crates/craft/src/egui_fork.rs +++ b/crates/craft/src/egui_fork.rs @@ -3,7 +3,7 @@ /// The egui fork the library is built and tested with. Apps patch egui to exactly this. pub const GIT: &str = "https://github.com/storytold/egui.git"; /// The commit of [`GIT`]. -pub const REV: &str = "a87d00caaec947ea781657c6ff410c9838016d18"; +pub const REV: &str = "b15ffe9bfc2c8e6748533b32b708e10abaf2afec"; /// The packages the workspace patches to the fork (the `[patch.crates-io]` entries that name [`GIT`]). pub const PACKAGES: &[&str] = &[ diff --git a/crates/crw/Cargo.toml b/crates/crw/Cargo.toml index e44839e70d..9c58c68340 100644 --- a/crates/crw/Cargo.toml +++ b/crates/crw/Cargo.toml @@ -15,6 +15,7 @@ workspace = true thiserror = { workspace = true } [dev-dependencies] +craft-testkit = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } # Pinned digests of the decoded CC0 sample files (tests/samples.rs); not a product dependency. diff --git a/crates/crw/tests/robust.rs b/crates/crw/tests/robust.rs index b12df3a8d4..8368ceb3d0 100644 --- a/crates/crw/tests/robust.rs +++ b/crates/crw/tests/robust.rs @@ -61,11 +61,13 @@ fn crw() -> Vec { #[test] fn every_truncation_and_single_byte_mutation_survives() { let good = crw(); - for n in 0..good.len() { + // The gate runs every divisor-th position; nightly runs all. + let step = craft_testkit::hostile::divisor(); + for n in (0..good.len()).step_by(step) { let _ = header(&good[..n], &Limits::default()); let _ = decode(&good[..n], &Limits::default()); } - for i in 0..good.len() { + for i in (0..good.len()).step_by(step) { let mut bad = good.clone(); bad[i] ^= 0xa5; let _ = decode(&bad, &Limits::default()); diff --git a/crates/develop/Cargo.toml b/crates/develop/Cargo.toml index 19335b990f..c271ad26bf 100644 --- a/crates/develop/Cargo.toml +++ b/crates/develop/Cargo.toml @@ -24,4 +24,5 @@ rayon = { workspace = true } [dev-dependencies] craft-render-parity = { workspace = true } +craft-testkit = { workspace = true } proptest = { workspace = true } diff --git a/crates/develop/src/camera_raw/local_tone.rs b/crates/develop/src/camera_raw/local_tone.rs index 33f825b666..8751a2a633 100644 --- a/crates/develop/src/camera_raw/local_tone.rs +++ b/crates/develop/src/camera_raw/local_tone.rs @@ -652,7 +652,7 @@ mod tests { apply(&mut px, n, n, 70.0, -60.0, SRGB); [px[(n / 8) * n + n / 8][0], px[(3 * n / 4) * n + 3 * n / 4][0]] }; - let (a, b) = (at(96), at(384)); + let (a, b) = (at(64), at(256)); assert!((a[0] - b[0]).abs() < 0.02 && (a[1] - b[1]).abs() < 0.02, "{a:?} {b:?}"); } } diff --git a/crates/develop/src/sensor/highlight/tests.rs b/crates/develop/src/sensor/highlight/tests.rs index 3386e5d73d..7d2f6c05b4 100644 --- a/crates/develop/src/sensor/highlight/tests.rs +++ b/crates/develop/src/sensor/highlight/tests.rs @@ -163,8 +163,13 @@ fn rebuilt_ramp_is_continuous_from_the_first_clip_to_the_last() { /// background surrounds it. #[test] fn thin_line_without_reliable_colour_is_continuous_where_it_clips() { - for height in [32usize, 512, 1024] { - for width in [1usize, 4, 16] { + // The gate runs a one-row line in 32 rows and a four-row line in 512; nightly every pair, up to 1024 rows. + let full = craft_testkit::hostile::divisor() == 1; + for (h, height) in [32usize, 512, 1024].into_iter().enumerate() { + for (w, width) in [1usize, 4, 16].into_iter().enumerate() { + if !full && (w != h || h > 1) { + continue; + } let top = (height - width) / 2; let (row, first) = rebuilt_ramp(top..top + width, height); assert_continuous(&row, first, 0.002, &format!("{width} rows of {height}")); diff --git a/crates/develop/src/tests_crystal.rs b/crates/develop/src/tests_crystal.rs index bb6a7bddcd..a01ca4dc17 100644 --- a/crates/develop/src/tests_crystal.rs +++ b/crates/develop/src/tests_crystal.rs @@ -103,8 +103,8 @@ fn reference_render_has_unit_variance_and_no_mean() { fn small_render_is_the_downscaled_reference() { for (size, rough) in [(0.0, 50.0), (25.0, 50.0), (100.0, 50.0), (25.0, 0.0), (25.0, 100.0)] { let t = tile_of(size, rough); - for k in [2usize, 4, 8] { - let n = 48; + for k in [2usize, 8] { + let n = 32; let full = patch(&t, REF_LONG, n * k, 0); let down: Vec = (0..n * n) .map(|q| { @@ -120,6 +120,7 @@ fn small_render_is_the_downscaled_reference() { .collect(); let small = patch(&t, REF_LONG / k as f64, n, 0); let worst = down.iter().zip(&small).map(|(a, b)| (a - b).abs()).fold(0.0, f32::max); + eprintln!("DIAG downscale size {size} roughness {rough} 1/{k}: worst {worst} (limit 2e-3)"); assert!(worst < 2e-3, "size {size} roughness {rough} 1/{k}: differs by {worst}"); } } @@ -129,7 +130,7 @@ fn small_render_is_the_downscaled_reference() { fn strength_matches_the_target_at_mid_grey() { for (a, s, r) in [(50.0, 25.0, 50.0), (25.0, 25.0, 50.0), (50.0, 0.0, 50.0), (50.0, 100.0, 50.0), (50.0, 25.0, 0.0)] { let g = CrystalGrain::new(&Grain { amount: a, size: s, roughness: r, seed: 3 }, REF_LONG).expect("grain"); - let n = 320; + let n = 200; let lum: Vec = (0..n * n) .map(|k| { let (x, y) = ((k % n) as f32 + 0.5, (k / n) as f32 + 0.5); @@ -138,6 +139,7 @@ fn strength_matches_the_target_at_mid_grey() { }) .collect(); let want = strength_levels(a, s, r); + eprintln!("DIAG strength {a}/{s}/{r}: deviation {:.4} (limit 0.06)", std(&lum) / want - 1.0); assert!((std(&lum) / want - 1.0).abs() < 0.06, "{a}/{s}/{r}: {} levels, want {want}", std(&lum)); } } @@ -443,8 +445,10 @@ fn a_waiting_render_gets_the_tile_the_cache_evicted() { keep(&OWN, key, drawn.clone()); // other renders' tiles push it out of the cache before the waiter wakes // (each its own tile: a waiter that took another key's would fail the check below) + // (one tile of another seed under every key: a different `Arc` from the drawn one, drawn once) + let other_tile = Arc::new(CrystalTile::new(look, seed + 1).expect("tile")); for other in 1..=CACHE as u32 { - keep(&OWN, key_of(look, seed + other), Arc::new(CrystalTile::new(look, seed + other).expect("tile"))); + keep(&OWN, key_of(look, seed + other), other_tile.clone()); } assert!(cached(&OWN, key).is_none(), "the tile is still cached"); drop(marker); @@ -477,7 +481,8 @@ fn renders_that_miss_a_tile_together_draw_it_once() { static OWN: Cache = Mutex::new(Vec::new()); const N: usize = 8; // the first render's draw waits for the other seven to miss the tile too - const SEEDS: u32 = 5; + // (each seed is a full trial, as the draw is held until the others wait, so a few are enough) + const SEEDS: u32 = 2; HOLDS.lock().unwrap_or_else(PoisonError::into_inner).push((std::ptr::from_ref(&OWN) as usize, N - 1, SEEDS as usize)); let look = CrystalLook::new(0.0, 50.0); for seed in 0x0d4a_1000..0x0d4a_1000 + SEEDS { @@ -502,7 +507,8 @@ fn renders_that_miss_a_tile_together_draw_it_once() { fn width_matches_lightroom_classic() { let lrc = [(0.0, 50.0, 0.5), (25.0, 50.0, 1.13), (100.0, 50.0, 3.38), (25.0, 0.0, 0.86), (25.0, 100.0, 1.54)]; for (s, r, want) in lrc { - let got = half_width(&patch(&tile_of(s, r), REF_LONG, 360, 0), 360); + let got = half_width(&patch(&tile_of(s, r), REF_LONG, 256, 0), 256); + eprintln!("DIAG width size {s} roughness {r}: {got:.3} want {want} (limit 10 percent)"); assert!((got / want - 1.0).abs() < 0.1, "size {s} roughness {r}: width {got:.3}, want {want}"); } } diff --git a/crates/develop/tests/it/balanced.rs b/crates/develop/tests/it/balanced.rs index bf7b6bbcaf..b0d2ca95bb 100644 --- a/crates/develop/tests/it/balanced.rs +++ b/crates/develop/tests/it/balanced.rs @@ -552,7 +552,9 @@ fn coloured_highlights_keep_their_brightness_at_the_edges() { let tubes = [([1.0f32, 0.15, 0.1], 3.5f32), ([1.0, 0.85, 0.15], 2.6), ([0.25, 1.0, 0.4], 2.0)]; let scenes = suns.map(|(tint, level)| (tint, level, true)).into_iter().chain(tubes.map(|(tint, level)| (tint, level, false))); let lum = |p: [f32; 3]| 0.2126 * p[0] + 0.7152 * p[1] + 0.0722 * p[2]; - for (tint, level, sun) in scenes { + // The gate develops every divisor-th (scene, layout) pair, a different layout per scene; nightly all of them. + let divisor = craft_testkit::hostile::divisor(); + for (scene_index, (tint, level, sun)) in scenes.enumerate() { let scene_name = if sun { "sun" } else { "tube" }; let scene = |x: f32, y: f32| { if sun { @@ -572,7 +574,10 @@ fn coloured_highlights_keep_their_brightness_at_the_edges() { }) }); let truth = |x: usize, y: usize| -> [f32; 3] { std::array::from_fn(|c| lights[c][y * w + x]) }; - for (name, cfa, method) in layouts() { + for (layout_index, (name, cfa, method)) in layouts().into_iter().enumerate() { + if !(scene_index + layout_index).is_multiple_of(divisor) { + continue; + } let raw = raw_of(w, h, &cfa, DAYLIGHT, truth); let (mut img, mask) = raw.develop_balanced_masked(method, DAYLIGHT, CLIP).unwrap(); let mut by_value = img.clone(); diff --git a/crates/dialogs/src/ui/chooser/tests.rs b/crates/dialogs/src/ui/chooser/tests.rs index 9b92f573f2..0e38060c32 100644 --- a/crates/dialogs/src/ui/chooser/tests.rs +++ b/crates/dialogs/src/ui/chooser/tests.rs @@ -117,7 +117,7 @@ fn saved(path: impl AsRef) -> Option> { // `a_selected_folder_never_replaces_the_typed_save_name` and `a_removed_selected_file_keeps_its_exact_save_path`, with // `~` and "not found". The extension is the service's policy now, so the chooser answers the name as typed. #[trial] -fn the_chooser_lists_and_accepts_like_a_file_panel() { +fn a_typed_folder_is_entered_and_a_new_name_is_saved_as_typed() { // A typed folder is entered and its name used up; a new name is answered as typed. let mut save = Chooser::open(PickRequest::save("document").directory("/d")); save.type_name("drafts"); @@ -126,7 +126,10 @@ fn the_chooser_lists_and_accepts_like_a_file_panel() { save.type_name("chapter"); save.click("Save"); assert_eq!(save.answer(), saved("/d/drafts/chapter"), "a new name is saved to as typed"); +} +#[trial] +fn a_listed_file_is_replaced_only_after_the_question() { // A listed file is replaced only after the question, asked once. let mut replace = Chooser::open(PickRequest::save("document").directory("/d/drafts")); replace.type_name("old.docx"); @@ -134,7 +137,10 @@ fn the_chooser_lists_and_accepts_like_a_file_panel() { assert_eq!(replace.answer(), None, "the chooser asks before replacing"); replace.click("Replace"); assert_eq!(replace.answer(), saved("/d/drafts/old.docx")); +} +#[trial] +fn a_selected_file_keeps_its_exact_name_for_open_and_for_the_save_question() { // A selected file keeps its exact name, leading space and all, for Open and for Save's question. let mut open = Chooser::open(PickRequest::open("document").directory("/d")); open.click(" report.docx"); @@ -147,7 +153,10 @@ fn the_chooser_lists_and_accepts_like_a_file_panel() { assert_eq!(save.answer(), None, "Save asks before replacing the selected file"); save.click("Replace"); assert_eq!(save.answer(), saved("/d/ report.docx")); +} +#[trial] +fn a_removed_selected_file_keeps_its_exact_save_path() { // A selected file removed meanwhile still names the exact path, and nothing is asked. let mut removed = Chooser::open(PickRequest::save("document").file_name("Draft.docx").directory("/d")); removed.click(" report.docx"); @@ -155,7 +164,10 @@ fn the_chooser_lists_and_accepts_like_a_file_panel() { removed.refocus(); removed.click("Save"); assert_eq!(removed.answer(), saved("/d/ report.docx"), "the removed selection keeps its path, not `report.docx`"); +} +#[trial] +fn a_selected_folder_is_entered_and_never_becomes_the_save_name() { // A selected folder is entered and never becomes the save name; once it is gone, the typed name is saved to. let mut folder = Chooser::open(PickRequest::save("document").file_name("chapter.docx").directory("/d")); folder.click("Chapters"); @@ -168,13 +180,19 @@ fn the_chooser_lists_and_accepts_like_a_file_panel() { gone.refocus(); gone.click("Save"); assert_eq!(gone.answer(), saved("/d/chapter.docx"), "the removed folder is not saved over as `Chapters.docx`"); +} +#[trial] +fn the_home_root_and_a_typed_path_elsewhere_open() { // `~` is the Home root; a typed path elsewhere is listed, then opened. let mut home = Chooser::open(PickRequest::open("document").directory("/d")); home.type_name("~/Letters/aunt.txt"); home.click("Open"); assert_eq!(home.answer(), picked("/home/u/Letters/aunt.txt")); +} +#[trial] +fn a_missing_name_on_open_is_refused_and_said() { // A missing name on Open is refused and said. let mut missing = Chooser::open(PickRequest::open("document").directory("/d")); missing.type_name("missing.docx"); diff --git a/crates/draw/src/ui/transform/transform_fields.rs b/crates/draw/src/ui/transform/transform_fields.rs index cfc007bbfa..d6e039acf7 100644 --- a/crates/draw/src/ui/transform/transform_fields.rs +++ b/crates/draw/src/ui/transform/transform_fields.rs @@ -16,8 +16,8 @@ use craft_behavior::{ColumnWidth, EditEvent, EditEvents, GestureId, IconId, Mixe use craft_ui::buttons::ToggleButton; use craft_ui::canvas::CanvasRulers; use craft_ui::contract::{ - Bind, BodyCx, Entry, FieldLayout, GlyphLabel, LabelKind, LabelPress, NoValue, Outcome, Props as _, Show as _, ShowContainer as _, SideLabel, - Sizing, + Bind, BodyCx, Bracket, Entry, FieldLayout, GlyphLabel, LabelKind, LabelPress, NoValue, Outcome, Props as _, Show as _, ShowContainer as _, + SideLabel, Sizing, }; use craft_ui::display::Divider; use craft_ui::form::{Field, FieldGroup}; @@ -135,7 +135,8 @@ pub enum FieldArrangement { /// W, the link and H on the first row, then X and Y. #[default] SizeFirst, - /// X and W on the first row, Y and H on the second, the link after them: Tab runs X, W, Y, H. + /// X and W on the first row, Y and H on the second, the link beside them centred across the two rows: Tab runs X, + /// W, Y, H. PositionFirst, } @@ -224,7 +225,8 @@ impl Outcome for TransformFieldsOutput { /// - **Panel form** (the default): two field columns that fill the width, the link's column between them: W, the /// link and H on one row, X and Y on the next, the angle, then the H and V skews; the compact reference point, when /// shown, leads the first row. [`groups`](Self::groups) leaves out the rows of hidden groups. With -/// [`FieldArrangement::PositionFirst`] the grid is X and W, then Y and H, with the link after them. +/// [`FieldArrangement::PositionFirst`] the grid is X and W, then Y and H, with the link beside it, centred across +/// the two rows. /// - **Bar form** ([`bar`](Self::bar)): the compact reference point, then captioned fields in Photoshop's order with a /// divider between the groups, the Δ toggle between X and Y, the interpolation select last. /// [`groups`](Self::groups) narrows the strip. @@ -437,10 +439,10 @@ struct Cells<'a> { const FIELD_COLUMNS: [ColumnWidth; 3] = [ColumnWidth::fill(1.0), ColumnWidth::Content, ColumnWidth::fill(1.0)]; /// The panel form's columns with the reference point before them. const REFERENCE_COLUMNS: [ColumnWidth; 4] = [ColumnWidth::Content, ColumnWidth::fill(1.0), ColumnWidth::Content, ColumnWidth::fill(1.0)]; -/// The position-first panel form's columns: two fields, then the link's column. -const POSITION_COLUMNS: [ColumnWidth; 3] = [ColumnWidth::fill(1.0), ColumnWidth::fill(1.0), ColumnWidth::Content]; +/// The position-first panel form's columns: two fields that share the width. +const PAIR_COLUMNS: [ColumnWidth; 2] = [ColumnWidth::fill(1.0), ColumnWidth::fill(1.0)]; /// The position-first panel form's columns with the reference point before them. -const POSITION_REFERENCE_COLUMNS: [ColumnWidth; 4] = [ColumnWidth::Content, ColumnWidth::fill(1.0), ColumnWidth::fill(1.0), ColumnWidth::Content]; +const REFERENCE_PAIR_COLUMNS: [ColumnWidth; 3] = [ColumnWidth::Content, ColumnWidth::fill(1.0), ColumnWidth::fill(1.0)]; /// Which form the cells show in. #[derive(Clone, Copy, PartialEq, Eq)] @@ -690,43 +692,39 @@ impl Cells<'_> { }); } - /// The position-first grid of [`rows`](Self::rows): X and W, Y and H with the link after them, the angle, then the - /// skews; two field columns and the link's column, the reference point, when shown, in a column before them. + /// The position-first form of [`rows`](Self::rows): X and W, then Y and H, in a grid beside the link, which stands + /// centred across their two rows; the reference point, when shown, leads the grid's first row in a column of its + /// own. The angle and the skews follow in a grid of their own. fn position_first(&mut self, ui: &mut Ui, cx: &mut BodyCx<'_>, pass: &mut Pass) { let groups = self.groups; - let columns: &'static [ColumnWidth] = if groups.reference { &POSITION_REFERENCE_COLUMNS } else { &POSITION_COLUMNS }; - Grid::new(columns).id_salt("fields").fill_width().show(ui, |ui, _| { - let mut first = true; - let pair = [(groups.position, TransformField::X, TransformField::Y), (groups.size, TransformField::W, TransformField::H)]; - if groups.position || groups.size || groups.reference { - self.lead(ui, cx, pass, &mut first); - for (shown, top, _) in pair { - self.field_or_empty(ui, cx, pass, shown, top); - } + if groups.position || groups.size || groups.reference { + let columns: &'static [ColumnWidth] = if groups.reference { &REFERENCE_PAIR_COLUMNS } else { &PAIR_COLUMNS }; + Row::new().bracket(Bracket::Unlinked).fill_width().show(ui, |ui, _| { + Grid::new(columns).id_salt("fields").fill_width().show(ui, |ui, _| { + let mut first = true; + let rows = if groups.position || groups.size { 2 } else { 1 }; + for row in [[TransformField::X, TransformField::W], [TransformField::Y, TransformField::H]].into_iter().take(rows) { + self.lead(ui, cx, pass, &mut first); + self.field_or_empty(ui, cx, pass, groups.position, row[0]); + self.field_or_empty(ui, cx, pass, groups.size, row[1]); + } + }); if groups.size { self.link(ui); - } else { - empty(ui); } - } - if groups.position || groups.size { - self.lead(ui, cx, pass, &mut first); - for (shown, _, bottom) in pair { - self.field_or_empty(ui, cx, pass, shown, bottom); - } - empty(ui); - } + }); + } + if !(groups.angle || groups.skew) { + return; + } + Grid::new(&PAIR_COLUMNS).id_salt("turns").fill_width().show(ui, |ui, _| { if groups.angle { - self.lead(ui, cx, pass, &mut first); self.field(ui, cx, pass, TransformField::Angle, Form::Panel); empty(ui); - empty(ui); } if groups.skew { - self.lead(ui, cx, pass, &mut first); self.field(ui, cx, pass, TransformField::SkewH, Form::Panel); self.field(ui, cx, pass, TransformField::SkewV, Form::Panel); - empty(ui); } }); } diff --git a/crates/draw/tests/it/transform_fields.rs b/crates/draw/tests/it/transform_fields.rs index 7a7341445d..b83456aa9b 100644 --- a/crates/draw/tests/it/transform_fields.rs +++ b/crates/draw/tests/it/transform_fields.rs @@ -4,7 +4,7 @@ use craft_behavior::geometry::quad::BoxState; use craft_behavior::kurbo::{Point, Rect, Size}; use craft_behavior::{EditEvent, Mixed, RulerUnits}; -use craft_draw::ui::transform::{SizeUnit, TransformField, TransformFields, TransformGroups, TransformRow, TransformSource}; +use craft_draw::ui::transform::{FieldArrangement, SizeUnit, TransformField, TransformFields, TransformGroups, TransformRow, TransformSource}; use craft_ui::canvas::{CanvasRulers, RulerText}; use craft_ui::contract::Bind; use craft_ui::runtime::env::UnitKind; @@ -286,3 +286,44 @@ fn a_start_box_that_moves_with_a_scrub_keeps_the_scrub_running() { assert!(events.iter().any(|event| matches!(event, EditEvent::Commit { .. })), "the release committed it: {events:?}"); assert!(row.state.quad[0].distance(row.state.quad[1]) > START.width(), "the scrub widened the box: {row:?}"); } + +/// The position-first panel form stands the reference point before the X and W, Y and H rows and the link after them +/// centred across the rows, both clear of every field, in a wide room, a narrow one and a host sized from its content. +#[trial] +fn the_position_first_link_stands_between_the_width_and_height_rows() { + use craft_ui::contract::ShowContainer as _; + for (width, content) in [(260.0, false), (400.0, false), (400.0, true)] { + let mut row = TransformRow::new(BoxState::from_rect(START), 0.0); + let mut linked = true; + let mut fixture = Fixture::new(move |ui| { + let mut show = |ui: &mut egui::Ui| { + TransformFields::new("Transform", Bind::bound(&mut row), START, Bind::bound(&mut linked)) + .arrangement(FieldArrangement::PositionFirst) + .show(ui) + }; + if content { + craft_ui::layout_components::Stack::new().show(ui, |ui, _| show(ui)); + } else { + show(ui); + } + }); + fixture.room(egui::vec2(width, 400.0)).settle(); + let rect = |label: &str| fixture.by_label(label).unwrap_or_else(|| panic!("the fields show {label}")).rect; + let link = rect("Maintain aspect ratio"); + let reference = rect("Reference point"); + let fields = ["X position", "Width", "Y position", "Height"].map(rect); + let dump = format!("in {width} (content: {content}): reference {reference:?}, link {link:?}, fields {fields:?}"); + assert!( + fields.iter().all(|field| !field.intersects(link) && !field.intersects(reference)), + "no field overlaps the link or the point: {dump}" + ); + let [x, w, _, h] = fields; + assert!( + reference.right() <= x.left() && w.right() <= link.left() && link.right() <= width, + "point, fields, link in order, inside the room: {dump}" + ); + assert!(h.top() >= w.bottom(), "H is under W: {dump}"); + let middle = (w.top() + h.bottom()) / 2.0; + assert!((link.center().y - middle).abs() <= 1.0, "the link is centred across the two rows: {dump}"); + } +} diff --git a/crates/drawingml/Cargo.toml b/crates/drawingml/Cargo.toml index 9a8fe2f9ab..46a6c596f2 100644 --- a/crates/drawingml/Cargo.toml +++ b/crates/drawingml/Cargo.toml @@ -18,4 +18,5 @@ log = "0.4" serde = { workspace = true } [dev-dependencies] +craft-testkit = { workspace = true } serde_json = { workspace = true } diff --git a/crates/drawingml/src/table.rs b/crates/drawingml/src/table.rs index 02e3066994..dd6c90d03f 100644 --- a/crates/drawingml/src/table.rs +++ b/crates/drawingml/src/table.rs @@ -342,30 +342,42 @@ impl Table { } /// Whether [`Table::normalize`] would drop rows or columns to fit [`MAX_CELLS`]. pub fn over_cap(&self) -> bool { - let n = self.cols.len(); - n > MAX_CELLS || self.rows.len() > (MAX_CELLS / n.max(1)).max(1) + self.over(MAX_CELLS) } /// What [`Table::normalize`] would leave of this table, cloning only the rows and cells that /// survive (an oversized table is not copied whole first). pub fn normalized(&self) -> Table { - let n = self.cols.len().min(MAX_CELLS); - let keep = (MAX_CELLS / n.max(1)).max(1); - let rows = self.rows.iter().take(keep).map(|r| Row { height: r.height, cells: r.cells.iter().take(n).cloned().collect() }).collect(); - let mut t = Table { cols: self.cols[..n].to_vec(), rows, background: self.background.clone(), style: self.style.clone(), ..*self }; - t.normalize(); - if self.over_cap() { - t.clip_spans(); - } - t + self.normalized_within(MAX_CELLS) } /// Make every row have exactly `cols.len()` cells (repair after loading). A grid over /// [`MAX_CELLS`] loses its last rows (and columns) first, so a file naming many rows and many /// columns but few cells cannot make this allocate their product. pub fn normalize(&mut self) { - let truncated = self.over_cap(); - self.cols.truncate(MAX_CELLS); + self.normalize_within(MAX_CELLS); + } + /// [`Table::over_cap`] for a cap of `max` cells. + fn over(&self, max: usize) -> bool { let n = self.cols.len(); - self.rows.truncate((MAX_CELLS / n.max(1)).max(1)); + n > max || self.rows.len() > (max / n.max(1)).max(1) + } + /// [`Table::normalized`] for a cap of `max` cells. + fn normalized_within(&self, max: usize) -> Table { + let n = self.cols.len().min(max); + let keep = (max / n.max(1)).max(1); + let rows = self.rows.iter().take(keep).map(|r| Row { height: r.height, cells: r.cells.iter().take(n).cloned().collect() }).collect(); + let mut t = Table { cols: self.cols[..n].to_vec(), rows, background: self.background.clone(), style: self.style.clone(), ..*self }; + t.normalize_within(max); + if self.over(max) { + t.clip_spans(); + } + t + } + /// [`Table::normalize`] for a cap of `max` cells. + fn normalize_within(&mut self, max: usize) { + let truncated = self.over(max); + self.cols.truncate(max); + let n = self.cols.len(); + self.rows.truncate((max / n.max(1)).max(1)); for r in &mut self.rows { r.cells.resize_with(n, || Cell::new("")); for c in &mut r.cells { @@ -741,22 +753,27 @@ mod tests { #[test] fn normalize_caps_a_sparse_grid_at_max_cells() { - let mut t = Table { cols: vec![10.0; 1000], rows: vec![Row::default(); 1000], ..Default::default() }; - t.normalize(); - assert_eq!(t.cols.len(), 1000); - assert_eq!(t.rows.len(), MAX_CELLS / 1000); - assert!(t.rows.iter().all(|r| r.cells.len() == 1000)); - let mut t = Table { cols: vec![1.0; MAX_CELLS + 5], rows: vec![Row::default(); 3], ..Default::default() }; - t.normalize(); - assert_eq!((t.cols.len(), t.rows.len()), (MAX_CELLS, 1)); - let wide = Table { - cols: vec![10.0; 1000], - rows: vec![Row { height: 1.0, cells: vec![Cell::new("x"); 1100] }; MAX_CELLS / 1000 + 1], - ..Default::default() - }; - let mut n = wide.clone(); - n.normalize(); - assert_eq!(wide.normalized(), n); + // At a cap 100 times smaller; nightly also at MAX_CELLS. + let full = craft_testkit::hostile::divisor() == 1; + for max in [MAX_CELLS / 100].into_iter().chain(full.then_some(MAX_CELLS)) { + let cols = max / 100; + let mut t = Table { cols: vec![10.0; cols], rows: vec![Row::default(); 1000], ..Default::default() }; + t.normalize_within(max); + assert_eq!(t.cols.len(), cols); + assert_eq!(t.rows.len(), max / cols); + assert!(t.rows.iter().all(|r| r.cells.len() == cols)); + let mut t = Table { cols: vec![1.0; max + 5], rows: vec![Row::default(); 3], ..Default::default() }; + t.normalize_within(max); + assert_eq!((t.cols.len(), t.rows.len()), (max, 1)); + let wide = Table { + cols: vec![10.0; cols], + rows: vec![Row { height: 1.0, cells: vec![Cell::new("x"); cols + cols / 10] }; max / cols + 1], + ..Default::default() + }; + let mut n = wide.clone(); + n.normalize_within(max); + assert_eq!(wide.normalized_within(max), n); + } let mut t = Table::new(4, 4, 400.0, 30.0); t.normalize(); assert_eq!((t.n_rows(), t.n_cols()), (4, 4)); diff --git a/crates/font-manager/src/store.rs b/crates/font-manager/src/store.rs index 4e8bc303db..8f12de134c 100644 --- a/crates/font-manager/src/store.rs +++ b/crates/font-manager/src/store.rs @@ -13,7 +13,7 @@ use std::sync::{Condvar, Mutex}; #[cfg(not(target_arch = "wasm32"))] use craft_font_catalog::Catalog; -pub use craft_font_store::preview::PreviewStore; +pub use craft_font_store::PreviewStore; #[cfg(not(target_arch = "wasm32"))] use craft_font_store::{Cancel, Client, Face, FontStore, Network, PINNED_INDEX, verify_font}; pub use craft_font_store::{LegalText, PREVIEW_SERVICE_ENV, PreviewServiceSource, UserSource}; diff --git a/crates/font-manager/src/store/fake.rs b/crates/font-manager/src/store/fake.rs index e91e8c3562..869333641a 100644 --- a/crates/font-manager/src/store/fake.rs +++ b/crates/font-manager/src/store/fake.rs @@ -281,7 +281,11 @@ impl Installer for FakeStore { } fn set_preview_service(&self, url: Option<&str>) -> Result<(), StoreError> { + // The address check is the native store's; the browser has no preview service to reach. + #[cfg(not(target_arch = "wasm32"))] let url = url.map(craft_font_store::check_preview_service).transpose().map_err(err)?; + #[cfg(target_arch = "wasm32")] + let url = url.map(str::to_owned); *self.preview_service.lock().map_err(err)? = url; Ok(()) } diff --git a/crates/font-store/src/lib.rs b/crates/font-store/src/lib.rs index 7623ae8758..d55fc84fe8 100644 --- a/crates/font-store/src/lib.rs +++ b/crates/font-store/src/lib.rs @@ -24,6 +24,7 @@ mod index; mod pin; +mod service; mod source; mod sources; mod verify; @@ -42,6 +43,7 @@ pub use index::{ MAX_FILE_BYTES, MAX_INDEX_BYTES, MAX_LICENSE_BYTES, Sample, Script, SourceProblem, Unavailable, parse_style, }; pub use pin::{IndexPin, PINNED_INDEX}; +pub use service::{LegalText, PREVIEW_SERVICE_ENV, PreviewServiceSource, PreviewStore}; pub use sources::{SourceEntry, SourcesFile}; pub use verify::{VerifyError, is_font, sha256_hex, verify_font}; @@ -67,10 +69,7 @@ pub use language_packs::{ MAX_PACK_INDEX_BYTES, MAX_PACK_UNPACKED_BYTES, PackEntry, PackIndex, PackIndexPin, language_pack_index_overridden, }; #[cfg(not(target_arch = "wasm32"))] -pub use store::{ - Caller, Error, FontStore, InstalledFamily, InstalledFile, LegalText, Network, PREVIEW_SERVICE_ENV, PreviewServiceSource, Problem, Progress, - check_preview_service, -}; +pub use store::{Caller, Error, FontStore, InstalledFamily, InstalledFile, Network, Problem, Progress, check_preview_service}; #[cfg(test)] mod tests; diff --git a/crates/font-store/src/preview.rs b/crates/font-store/src/preview.rs index f7b9b7b3c9..3e9b6d0740 100644 --- a/crates/font-store/src/preview.rs +++ b/crates/font-store/src/preview.rs @@ -246,31 +246,7 @@ pub struct Preview { pub font: Result, PreviewError>, } -/// What [`Previews`] reads from the font store: the service and the user's setting on each request, the client and -/// the cache folder when the pool is made. The font manager's `Installer` builds on it. -pub trait PreviewStore: Send + Sync { - /// The preview service's base URL, if one is set: [`PREVIEW_SERVICE_ENV`](crate::PREVIEW_SERVICE_ENV), else the - /// font store's `preview_service` setting, else the host's default. Installs try it as a mirror first. - fn preview_service(&self) -> Option { - None - } - - /// The store's HTTP client, if it has one. [`Previews`] fetches with it, so a preview service that installs - /// found unreachable is skipped by previews too, and the reverse. - fn http_client(&self) -> Option { - None - } - - /// Whether previews may be fetched from the preview service: the user's setting, on by default. - fn previews_enabled(&self) -> bool { - true - } - - /// The folder [`Previews`] caches preview subsets in; none keeps them only for as long as the caller holds them. - fn preview_cache(&self) -> Option { - None - } -} +pub use crate::service::PreviewStore; /// How the pool downloads: the store's [`Client`], or a stand-in in tests. pub trait Fetch: Send + Sync { diff --git a/crates/font-store/src/service.rs b/crates/font-store/src/service.rs new file mode 100644 index 0000000000..996c26c57a --- /dev/null +++ b/crates/font-store/src/service.rs @@ -0,0 +1,57 @@ +//! What the font store and the preview service's client share with the font manager on every target: which legal +//! text to read, where the preview service comes from, and what the preview pool reads from a store. The store and +//! the client themselves are native only. + +use std::path::PathBuf; + +/// Which of a family's legal texts [`FontStore::legal_text`](crate::FontStore::legal_text) reads. +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +pub enum LegalText { + /// The licence file (`OFL.txt`, `LICENSE.txt`). + License, + /// An Apache family's `NOTICE` file. + Notice, +} + +/// The environment variable that sets the preview service's base URL; it beats the saved setting. +pub const PREVIEW_SERVICE_ENV: &str = "CRAFT_FONT_PREVIEW_URL"; + +/// Where the preview service in effect comes from. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum PreviewServiceSource { + /// [`PREVIEW_SERVICE_ENV`]; the setting can't change it. + Env, + /// The `preview_service` setting in `settings.json`. + Saved, + /// The host's default, [`FontStore::with_default_preview_service`](crate::FontStore::with_default_preview_service). + Default, + /// There is no service. + None, +} + +/// What [`Previews`](crate::preview::Previews) reads from the font store: the service and the user's setting on each request, the client and +/// the cache folder when the pool is made. The font manager's `Installer` builds on it. +pub trait PreviewStore: Send + Sync { + /// The preview service's base URL, if one is set: [`PREVIEW_SERVICE_ENV`](crate::PREVIEW_SERVICE_ENV), else the + /// font store's `preview_service` setting, else the host's default. Installs try it as a mirror first. + fn preview_service(&self) -> Option { + None + } + + /// The store's HTTP client, if it has one. [`Previews`](crate::preview::Previews) fetches with it, so a preview service that installs + /// found unreachable is skipped by previews too, and the reverse. + #[cfg(not(target_arch = "wasm32"))] + fn http_client(&self) -> Option { + None + } + + /// Whether previews may be fetched from the preview service: the user's setting, on by default. + fn previews_enabled(&self) -> bool { + true + } + + /// The folder [`Previews`](crate::preview::Previews) caches preview subsets in; none keeps them only for as long as the caller holds them. + fn preview_cache(&self) -> Option { + None + } +} diff --git a/crates/font-store/src/store.rs b/crates/font-store/src/store.rs index c90c0af457..b5015c481d 100644 --- a/crates/font-store/src/store.rs +++ b/crates/font-store/src/store.rs @@ -30,6 +30,7 @@ use crate::index::{ Face, Family, FontFile, GOOGLE_FONTS, Index, IndexError, LicenseFile, MAX_INDEX_BYTES, MAX_LICENSE_BYTES, SourceProblem, Unavailable, }; use crate::pin::IndexPin; +use crate::service::{LegalText, PREVIEW_SERVICE_ENV, PreviewServiceSource}; use crate::source::{is_source_url, safe_dir, safe_file_name, slug}; use crate::sources::{MAX_SOURCES_BYTES, SourceEntry, SourcesFile}; use crate::verify::{VerifyError, is_font, sha256_hex, verify_font}; @@ -237,15 +238,6 @@ pub struct Problem { pub error: Option, } -/// Which of a family's legal texts [`FontStore::legal_text`] reads. -#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] -pub enum LegalText { - /// The licence file (`OFL.txt`, `LICENSE.txt`). - License, - /// An Apache family's `NOTICE` file. - Notice, -} - /// A licence or NOTICE file's size and sha256, when the index has them. A format 1.0 index has /// neither for the licence: the size cap is then the only check. fn check_license(file: Option<&LicenseFile>, bytes: &[u8]) -> Result<(), VerifyError> { @@ -690,22 +682,6 @@ pub(crate) fn read_limited(path: &Path, max: u64) -> Option> { std::fs::read(path).ok() } -/// The environment variable that sets the preview service's base URL; it beats the saved setting. -pub const PREVIEW_SERVICE_ENV: &str = "CRAFT_FONT_PREVIEW_URL"; - -/// Where the preview service in effect comes from. -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum PreviewServiceSource { - /// [`PREVIEW_SERVICE_ENV`]; the setting can't change it. - Env, - /// The `preview_service` setting in `settings.json`. - Saved, - /// The host's default, [`FontStore::with_default_preview_service`]. - Default, - /// There is no service. - None, -} - /// The environment value when set and not empty, else the setting; an unusable value counts as /// unset. #[cfg(test)] diff --git a/crates/heif/Cargo.toml b/crates/heif/Cargo.toml index b79b8f989e..8b505eaf28 100644 --- a/crates/heif/Cargo.toml +++ b/crates/heif/Cargo.toml @@ -20,6 +20,7 @@ heic-rs = { version = "=0.1.4", default-features = false, features = ["std", "pa rayon = { workspace = true, optional = true } [dev-dependencies] +craft-testkit = { workspace = true } proptest = { workspace = true } [features] diff --git a/crates/heif/src/tests_synthetic.rs b/crates/heif/src/tests_synthetic.rs index dbd4ca70bb..8d4f9fd96f 100644 --- a/crates/heif/src/tests_synthetic.rs +++ b/crates/heif/src/tests_synthetic.rs @@ -186,7 +186,9 @@ fn grid_tiles_are_held_to_the_pixel_budget_together() { fn truncated_and_corrupted_files_are_errors_not_panics() { let bytes = build(&Spec { props: vec![FULL_601, Prop::Irot(1)], thumbnail: Some(&grey), ..Spec::new(64, 64, &grey) }); let full = decode(&bytes, &Options::default()).unwrap(); - for cut in (0..bytes.len()).step_by(7) { + // The gate runs a divisor's fraction of the cuts and flips; nightly runs all. + let divisor = craft_testkit::hostile::divisor(); + for cut in (0..bytes.len()).step_by(7 * divisor) { let b = &bytes[..cut]; // Cut inside the photo: an error. Cut in the trailing thumbnail: the whole photo. if let (Ok(_), Ok(d)) = (probe(b), decode(b, &Options::default())) { @@ -197,7 +199,7 @@ fn truncated_and_corrupted_files_are_errors_not_panics() { } // Flip bits all over the file: any outcome but a panic. let mut state = 0x2545_f491_u32; - for _ in 0..400 { + for _ in 0..400 / divisor { let mut b = bytes.clone(); for _ in 0..3 { state ^= state << 13; diff --git a/crates/image-codecs/src/codecs/png.rs b/crates/image-codecs/src/codecs/png.rs index 454068d76d..e16ef945d1 100644 --- a/crates/image-codecs/src/codecs/png.rs +++ b/crates/image-codecs/src/codecs/png.rs @@ -2324,6 +2324,9 @@ mod streamed_tests { /// gives, at 8 and 16 bits, with a profile, resolution, text and XMP. #[test] fn streamed_rows_match_the_whole_image_encoder() { + // The gate runs every divisor-th (image, level, bands) case, nightly all twelve. + let divisor = craft_media_testkit::hostile::divisor(); + let mut case = 0usize; for (layout, sample, ch, bytes, w, h) in [(ChannelLayout::Rgba, SampleType::U8, 4usize, 1usize, 1024u32, 1025u32), (ChannelLayout::Rgb, SampleType::U16, 3, 2, 1024, 700)] { @@ -2339,9 +2342,20 @@ mod streamed_tests { .with_meta(meta); for level in [PngCompression::Fast, PngCompression::Default] { let opts = EncodeOptions { png_compression: level, ..Default::default() }; + let one_band = [h]; + let cases: Vec<&[u32]> = [&[1u32, 77, 300][..], &[256, 256, 256], &one_band] + .into_iter() + .filter(|_| { + case += 1; + (case - 1).is_multiple_of(divisor) + }) + .collect(); + if cases.is_empty() { + continue; + } let whole = crate::encode(&img, Format::Png, &opts).unwrap(); let (head, zlib, _) = split(&whole); - for heights in [&[1u32, 77, 300][..], &[256, 256, 256], &[h]] { + for heights in cases { let png = streamed(&img, heights, &opts); let (h2, z2, _) = split(&png); assert!(h2 == head, "{layout:?} {level:?} {heights:?}: header chunks differ"); diff --git a/crates/image-codecs/tests/it/malformed.rs b/crates/image-codecs/tests/it/malformed.rs index 7ccb7819b4..bd6bd605b7 100644 --- a/crates/image-codecs/tests/it/malformed.rs +++ b/crates/image-codecs/tests/it/malformed.rs @@ -99,9 +99,12 @@ fn byte_overwrites_in_header_never_panic() { let step = craft_media_testkit::hostile::divisor(); for (k, (f, bytes)) in samples().into_iter().enumerate() { for i in (0..bytes.len().min(64)).filter(|i| (i + k) % step == 0) { - for v in [0x00, 0x7F, 0xFF] { + // nightly writes every value to each byte; the gate one per byte, rotating, so the sampled bytes together see all + let values = [0x00, 0x7F, 0xFF]; + let one = [values[(i / step) % 3]]; + for v in if step == 1 { &values[..] } else { &one[..] } { let mut b = bytes.clone(); - b[i] = v; + b[i] = *v; no_panic(f, &b); } } diff --git a/crates/image-codecs/tests/it/tiff_bands.rs b/crates/image-codecs/tests/it/tiff_bands.rs index 88376e2c35..c7c4f6e3e4 100644 --- a/crates/image-codecs/tests/it/tiff_bands.rs +++ b/crates/image-codecs/tests/it/tiff_bands.rs @@ -340,24 +340,28 @@ fn blank_g4(h: u32) -> Vec { fn a_blank_fax_page_wider_than_4096_px_passes_the_bomb_guard() { // A blank page codes each row in one bit, so a row wider than 4096 pixels is past 4096:1: it // must open, with or without the metadata and other pages that used to raise the bound. The - // page has enough rows to hold more than the guard's fixed 1 MiB of slack. - for (w, h) in [(20_000u32, 800u32)] { - let mut d = Dir { entries: base(w, h, 1, 1, 0), chunks: vec![blank_g4(h)], tiled: false }.tag(278, LONG, &[u64::from(h)]); - d.entries.retain(|e| e.0 != 259); - let d = d.tag(259, SHORT, &[4]); - let pages: Vec = (0..2).map(|_| d.clone()).collect(); - for (what, bytes) in - [("one page", build(true, false, std::slice::from_ref(&d), &[0]).bytes), ("two pages", build(true, false, &pages, &[0, 1]).bytes)] - { - let img = decode(&bytes).unwrap_or_else(|e| panic!("{w}x{h} {what}: {e}")); - assert_eq!(img.dimensions(), (w, h), "{what}"); - assert!(img.data().iter().all(|&v| v == 255), "{w}x{h} {what}: not white"); - } - } - let mut d = Dir { entries: base(20_000, 800, 1, 1, 0), chunks: vec![blank_g4(800)], tiled: false }.tag(278, LONG, &[800]); + // page has enough rows to hold more than the guard's fixed 1 MiB of slack: (w - 4096) * h / 8 + // bytes past 4096:1, so a wider page needs fewer pixels. The gate decodes the one-page file; + // nightly also the two-page file and the banded decode. + let full = craft_media_testkit::hostile::divisor() == 1; + let (w, h) = (60_000u32, 160u32); + let mut d = Dir { entries: base(w, h, 1, 1, 0), chunks: vec![blank_g4(h)], tiled: false }.tag(278, LONG, &[u64::from(h)]); d.entries.retain(|e| e.0 != 259); - let bytes = build(true, false, &[d.tag(259, SHORT, &[4])], &[0]).bytes; - assert!(banded(&bytes, None, &Limits::banded(), true).unwrap().data() == decode(&bytes).unwrap().data()); + let d = d.tag(259, SHORT, &[4]); + let one_page = build(true, false, std::slice::from_ref(&d), &[0]).bytes; + let mut files = vec![("one page", one_page.clone())]; + if full { + let pages: Vec = (0..2).map(|_| d.clone()).collect(); + files.push(("two pages", build(true, false, &pages, &[0, 1]).bytes)); + } + for (what, bytes) in files { + let img = decode(&bytes).unwrap_or_else(|e| panic!("{w}x{h} {what}: {e}")); + assert_eq!(img.dimensions(), (w, h), "{what}"); + assert!(img.data().iter().all(|&v| v == 255), "{w}x{h} {what}: not white"); + } + if full { + assert!(banded(&one_page, None, &Limits::banded(), true).unwrap().data() == decode(&one_page).unwrap().data()); + } // Still a bound: 100 bytes of Group 4 can't hold that page (4096:1 for Group 3, which is not decoded). for compression in [4, 3] { let mut d = Dir { entries: base(7016, 4961, 1, 1, 0), chunks: vec![vec![0x80; 100]], tiled: false }.tag(278, LONG, &[4961]); diff --git a/crates/image-codecs/tests/it/tiff_pages.rs b/crates/image-codecs/tests/it/tiff_pages.rs index a015231916..ec30eff2c4 100644 --- a/crates/image-codecs/tests/it/tiff_pages.rs +++ b/crates/image-codecs/tests/it/tiff_pages.rs @@ -840,7 +840,11 @@ fn zoo_decodes_and_never_panics_when_cut_or_corrupted() { poke(&f[..cut]); } for i in (0..f.len()).filter(|i| (i + k) % step == 0) { - for flip in [0xffu8, 0x80, 0x01] { + // nightly flips each byte three ways; the gate one way per byte, rotating, so the sampled bytes together see all + let flips = [0xffu8, 0x80, 0x01]; + let one = [flips[(i / step) % 3]]; + for flip in if step == 1 { &flips[..] } else { &one[..] } { + let flip = *flip; let mut g = f.clone(); g[i] ^= flip; poke(&g); diff --git a/crates/jpeg/Cargo.toml b/crates/jpeg/Cargo.toml index dcae832eee..f6bb93eb38 100644 --- a/crates/jpeg/Cargo.toml +++ b/crates/jpeg/Cargo.toml @@ -16,6 +16,7 @@ thiserror = { workspace = true } rayon = { workspace = true, optional = true } [dev-dependencies] +craft-testkit = { workspace = true } # Reference encoder and baseline decoder for the comparison tests. jpeg-encoder = "0.6" zune-jpeg = "0.5" diff --git a/crates/jpeg/src/encode_low_memory_tests.rs b/crates/jpeg/src/encode_low_memory_tests.rs index de45f8dfe0..df350755f6 100644 --- a/crates/jpeg/src/encode_low_memory_tests.rs +++ b/crates/jpeg/src/encode_low_memory_tests.rs @@ -42,12 +42,19 @@ fn compare(src: &[u8], w: usize, h: usize, ch: usize, q: u8, sub: ChromaSubsampl #[test] fn all_sampling_and_channels_match_retained_tokens_byte_for_byte() { + // The gate compares every divisor-th case, so every size, channel count, subsampling and quality still runs; + // nightly compares them all. + let divisor = craft_testkit::hostile::divisor(); + let mut case = 0usize; for (w, h) in [(1, 1), (7, 9), (17, 31), (33, 65), (17, 1025)] { for ch in [1, 3, 4] { let src = noise(w * h * ch); for sub in [ChromaSubsampling::S444, ChromaSubsampling::S422, ChromaSubsampling::S420] { for q in [0, 1, 25, 50, 90, 100, 255] { - compare(&src, w, h, ch, q, sub, &[]); + case += 1; + if case.is_multiple_of(divisor) { + compare(&src, w, h, ch, q, sub, &[]); + } } } } diff --git a/crates/layers/src/ui/filter/mod.rs b/crates/layers/src/ui/filter/mod.rs index 70a7973ea6..d0a46b70b9 100644 --- a/crates/layers/src/ui/filter/mod.rs +++ b/crates/layers/src/ui/filter/mod.rs @@ -821,6 +821,19 @@ impl Outcome for LayerFilterOutput { } } +/// How wide the Objects filter's search field stands in the filter bar. An app sets it once at its root +/// (`RootEnv::values`); the default is `Natural`. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, craft_ui::runtime::env::EnvValue, craft_ui::contract::MemoProps)] +#[env(style)] +#[non_exhaustive] +pub enum ObjectsSearch { + /// The field's own width, with the Filter button right after it. + #[default] + Natural, + /// The field fills the row, with the Filter button at the end edge: VectorCraft's Layers panel. + Fill, +} + /// Whether the Objects filter's popover is open: the bar's memory, so it stays open across passes until a /// click outside or Escape closes it. #[derive(Clone, Default)] @@ -859,7 +872,10 @@ impl<'a> LayerFilterBar<'a> { } let words = Env::of(ui).words::(); let mut edit = None; - let row = Row::new().show(ui, |ui, cx| { + // A filling search field needs a row as wide as the bar to fill. + let fill = Env::of(ui).get::() == ObjectsSearch::Fill; + let row = if fill { Row::new().fill_width() } else { Row::new() }; + let row = row.show(ui, |ui, cx| { let select_name = std::mem::replace(&mut cx.memory::().select, focus_name); let Some(Mixed::Same(current)) = filter.reborrow().read(cx) else { return }; let stored = current; @@ -948,9 +964,12 @@ impl<'a> LayerFilterBar<'a> { // The selected layers pick the artboards; Group lists every group. FilterBy::Artboard | FilterBy::Group => {} FilterBy::Objects => { - let typed = TextField::search(words.search_layers.clone(), Bind::given(current.name.clone())) - .placeholder(words.search_all.clone()) - .show(ui); + let mut field = + TextField::search(words.search_layers.clone(), Bind::given(current.name.clone())).placeholder(words.search_all.clone()); + if fill { + field = field.sizing(Sizing::FillWidth); + } + let typed = field.show(ui); if let Some(text) = typed.value() { next.name.clone_from(text); } diff --git a/crates/layers/src/ui/filter/stories.rs b/crates/layers/src/ui/filter/stories.rs index c648621ece..119d72e1bb 100644 --- a/crates/layers/src/ui/filter/stories.rs +++ b/crates/layers/src/ui/filter/stories.rs @@ -1,9 +1,10 @@ //! Stories of `LayerFilterBar`: each filter type in one card, with the count of a document's layers it lets through. -use super::{EffectKind, FilterBy, FilterKind, FilterObject, FilterState, LayerAttribute, LayerFilter, LayerFilterBar, SmartKind}; +use super::{EffectKind, FilterBy, FilterKind, FilterObject, FilterState, LayerAttribute, LayerFilter, LayerFilterBar, ObjectsSearch, SmartKind}; use crate::ui::mock::FakeLayers; use crate::ui::tree::LayerTree as _; use craft_theme::LabelColor; +use craft_ui::runtime::env::with_env; use craft_ui::testing::{Drive, Fixture, StoryData, StoryOutput, ValueAt, story}; use egui::Ui; @@ -103,3 +104,17 @@ fn layer_filter_objects(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { ); show(ui, filter, filter_at) } + +/// The Objects filter in an app whose search field fills the bar (`ObjectsSearch::Fill`, VectorCraft's Layers panel): +/// the Filter button at the end edge. +#[story(LayerFilterBar<'static>, covers = [], drive = Drive::Never, group = "Types", title = "Filter by Objects, filling search")] +fn layer_filter_objects_fill(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + let (filter, filter_at) = data.value_at("filter", LayerFilter { by: FilterBy::Objects, ..LayerFilter::default() }); + with_env( + ui, + |overrides| { + overrides.values.set(ObjectsSearch::Fill); + }, + |ui| show(ui, filter, filter_at), + ) +} diff --git a/crates/layers/tests/it/panel_filter.rs b/crates/layers/tests/it/panel_filter.rs index b1df0c8f4c..8430e83cf7 100644 --- a/crates/layers/tests/it/panel_filter.rs +++ b/crates/layers/tests/it/panel_filter.rs @@ -338,3 +338,23 @@ fn a_filter_the_bar_applies_deselects_what_it_hides() { fixture.idle(2); assert!(selects(&seen).is_empty(), "a layer selected later, while the filter hides it, stays selected"); } + +/// Where the Objects filter's Filter button ends under `search`. +fn filter_button_end(search: craft_layers::ui::filter::ObjectsSearch) -> f32 { + let mut fixture = Fixture::new(move |ui| { + let mut filter = LayerFilter::default(); + filter.by = FilterBy::Objects; + let _ = craft_layers::ui::filter::LayerFilterBar::new(Bind::bound(&mut filter)).filter_types([FilterBy::Objects]).show(ui); + }); + fixture.root_value(search).room(ONE_PANEL).settle(); + fixture.by_label("Filter").expect("the Objects filter shows its Filter button").rect.right() +} + +/// An app whose Objects search fills the bar (`ObjectsSearch::Fill`, VectorCraft's Layers panel) gets its Filter +/// button further toward the end edge than the field's own width leaves it. +#[trial] +fn a_filling_objects_search_puts_the_filter_button_at_the_end() { + use craft_layers::ui::filter::ObjectsSearch; + let (natural, fill) = (filter_button_end(ObjectsSearch::Natural), filter_button_end(ObjectsSearch::Fill)); + assert!(fill > natural, "the Filter button ends at {fill} under Fill, {natural} under Natural"); +} diff --git a/crates/material-graph/Cargo.toml b/crates/material-graph/Cargo.toml index 9bae5c7f60..1cc2fed771 100644 --- a/crates/material-graph/Cargo.toml +++ b/crates/material-graph/Cargo.toml @@ -15,3 +15,6 @@ workspace = true libm = "0.2.16" # Data-parallel loops (MIT OR Apache-2.0). rayon = { workspace = true } + +[dev-dependencies] +craft-testkit = { workspace = true } diff --git a/crates/material-graph/src/graph.rs b/crates/material-graph/src/graph.rs index f4fc04eb35..f16573d51b 100644 --- a/crates/material-graph/src/graph.rs +++ b/crates/material-graph/src/graph.rs @@ -5459,6 +5459,38 @@ mod grey_tests { pub(super) static GREY_RUNS: std::cell::Cell = const { std::cell::Cell::new(0) }; } + /// A sample of a sweep of `total` cases: all of them when `craft_testkit::hostile::divisor()` is 1 (nightly), at the + /// gate every `per_div * divisor - 1`-th (an odd stride, so every axis of a nested loop varies). + struct Sweep { + stride: usize, + total: usize, + seen: usize, + visited: usize, + } + + impl Sweep { + fn new(total: usize, per_div: usize) -> Sweep { + #[cfg(not(target_arch = "wasm32"))] + let div = craft_testkit::hostile::divisor(); + #[cfg(target_arch = "wasm32")] + let div = 1; + Sweep { stride: if div == 1 { 1 } else { per_div * div - 1 }, total, seen: 0, visited: 0 } + } + + /// Whether the next case of the sweep is in the sample. + fn take(&mut self) -> bool { + let take = self.seen.is_multiple_of(self.stride); + self.seen += 1; + self.visited += usize::from(take); + take + } + + /// What `full` grey runs over all the cases comes to over the cases visited. + fn share(&self, full: usize) -> usize { + full * self.visited / self.total + } + } + fn bits(outs: &BTreeMap) -> Vec<(String, Vec)> { outs.iter().map(|(k, t)| (k.clone(), t.px.iter().flat_map(|p| p.map(f32::to_bits)).collect())).collect() } @@ -5532,6 +5564,7 @@ mod grey_tests { "m00=-1 m01=0 m10=0 m11=1", ]; let bgs = ["", "bg_r=0.5 bg_g=0.5 bg_b=0.5 bg_a=1", "bg_r=0.2 bg_g=0.3 bg_b=0.2 bg_a=1", "bg_a=0.5"]; + let mut sweep = Sweep::new(2 * mats.len() * bgs.len() * 3 * 4 * 4, 16); let n = greys(|| { for compiled in [false, true] { for m in mats { @@ -5544,6 +5577,9 @@ mod grey_tests { (" osize_log2_x=4 osize_log2_y=5", " ofmt=5"), (" osize_log2_x=6 osize_log2_y=6", " ofmt=6 offset_x=0.13 offset_y=-0.3"), ] { + if !sweep.take() { + continue; + } let body = format!("node 10 transform_matrix in=@2 {m} {bg} {tiles} {filt}{osz}{fmt}\noutput out 10\n"); same(&body, 32, compiled); } @@ -5553,7 +5589,7 @@ mod grey_tests { } } }); - assert!(n > 300, "{n} grey runs"); + assert!(n > sweep.share(300), "{n} grey runs in {} of {} cases", sweep.visited, sweep.total); } #[test] @@ -5663,6 +5699,7 @@ mod grey_tests { #[test] fn blend_grey_is_rgba() { + let mut sweep = Sweep::new(2 * 26 * 5 * 10, 16); let n = greys(|| { for compiled in [false, true] { for mode in (0..=21).chain(32..=35) { @@ -5679,6 +5716,9 @@ mod grey_tests { ("0.6", " ofmt=1 tile_x=0.25"), ("0.6", " ofmt=7"), ] { + if !sweep.take() { + continue; + } let body = format!("node 10 blend fg=@1 bg=@2 mode={mode} alpha_mode={am} opacity={op}{extra}\noutput out 10\n"); same(&body, 24, compiled); } @@ -5686,7 +5726,7 @@ mod grey_tests { } } }); - assert!(n > 300, "{n} grey runs"); + assert!(n > sweep.share(300), "{n} grey runs in {} of {} cases", sweep.visited, sweep.total); } #[test] diff --git a/crates/material-graph/tests/it/deep.rs b/crates/material-graph/tests/it/deep.rs index 2cb7751116..1fe1e23f16 100644 --- a/crates/material-graph/tests/it/deep.rs +++ b/crates/material-graph/tests/it/deep.rs @@ -8,6 +8,12 @@ use std::fmt::Write; /// The stack of a thread spawned without asking for one (Rust's default), and of rayon's workers. const NORMAL_STACK: usize = 2 << 20; +/// Stacks too small for a walk that recurses once per node: a frame takes at least tens of bytes (an unoptimised one about +/// a kilobyte), so the chains below overflow them if the evaluator recurses, and the chain length needs no more work than +/// that. +const SMALL_STACK: usize = 128 << 10; +const MEDIUM_STACK: usize = 512 << 10; + /// The stack a function as deep as allowed is run with: the normal one in an optimised build (measured: 2040 nodes in a /// row take under 1 MB); an unoptimised build's frames are about fifteen times larger. const FUNCTION_STACK: usize = if cfg!(debug_assertions) { 32 << 20 } else { NORMAL_STACK }; @@ -51,22 +57,22 @@ fn nested(levels: u32) -> String { } #[test] -fn a_chain_of_a_hundred_thousand_nodes_evaluates_on_a_normal_stack() { - let g = Graph::parse(&image_chain(100_000)).expect("parses"); +fn a_long_chain_evaluates_on_a_small_stack() { + let g = Graph::parse(&image_chain(10_000)).expect("parses"); let shallow = Graph::parse(&image_chain(2)).expect("parses"); let (deep, two) = - on_stack(NORMAL_STACK, move || (g.evaluate(None).map_err(|e| e.to_string()), shallow.evaluate(None).map_err(|e| e.to_string()))); + on_stack(MEDIUM_STACK, move || (g.evaluate(None).map_err(|e| e.to_string()), shallow.evaluate(None).map_err(|e| e.to_string()))); let (deep, two) = (deep.expect("evaluates"), two.expect("evaluates")); // an even number of inverts is the gradient again, as two are assert_eq!(deep["o"].px, two["o"].px); } #[test] -fn every_node_of_a_long_chain_gets_a_thumbnail_on_a_normal_stack() { - let g = Graph::parse(&image_chain(20_000)).expect("parses"); - let all = on_stack(NORMAL_STACK, move || g.evaluate_all(16, &[20_000])); +fn every_node_of_a_long_chain_gets_a_thumbnail_on_a_small_stack() { + let g = Graph::parse(&image_chain(300)).expect("parses"); + let all = on_stack(SMALL_STACK, move || g.evaluate_all(16, &[300])); assert!(all.errors.is_empty(), "{:?}", all.errors.iter().next()); - assert_eq!(all.thumbs.len(), 20_001); + assert_eq!(all.thumbs.len(), 301); } #[test] diff --git a/crates/material-graph/tests/it/determinism.rs b/crates/material-graph/tests/it/determinism.rs index 4043590643..563af3833b 100644 --- a/crates/material-graph/tests/it/determinism.rs +++ b/crates/material-graph/tests/it/determinism.rs @@ -38,13 +38,14 @@ fn in_pool(threads: usize, f: impl FnOnce() -> R + Send) -> R { #[test] fn one_thread_and_eight_render_the_same_bytes() { - let graphs = demo_graphs(); - assert!(graphs.len() > 100, "only {} demo graphs", graphs.len()); + let all = demo_graphs(); + assert!(all.len() > 100, "only {} demo graphs", all.len()); + let graphs = crate::sampled(all, 0); let one = in_pool(1, || graphs.iter().map(|(_, g)| render(g)).collect::>()); let eight = in_pool(8, || graphs.iter().map(|(_, g)| render(g)).collect::>()); let differ: Vec<&str> = graphs.iter().zip(one.iter().zip(&eight)).filter(|(_, (a, b))| a != b).map(|((k, _), _)| *k).collect(); assert!(differ.is_empty(), "these kinds render differently on 1 and 8 threads: {differ:?}"); - assert!(one.iter().filter(|r| r.is_ok()).count() > 100, "most demo graphs must render"); + assert!(one.iter().filter(|r| r.is_ok()).count() * 10 > graphs.len() * 8, "most demo graphs must render"); } #[test] @@ -52,7 +53,7 @@ fn cached_and_uncached_evaluations_give_the_same_bytes() { let cache = Arc::new(NodeCache::new(256)); let mut differ = Vec::new(); let mut not_reused = Vec::new(); - for (kind, g) in demo_graphs() { + for (kind, g) in crate::sampled(demo_graphs(), 0) { let keep: Vec = g.nodes.keys().copied().collect(); let fresh = g.evaluate_all(SIDE, &keep); let first = g.evaluate_all_cached(&EvalContext::default(), SIDE, &keep, &cache, None, &mut |_| {}); diff --git a/crates/material-graph/tests/it/kind_versions.rs b/crates/material-graph/tests/it/kind_versions.rs index 3c23915174..0b6f857437 100644 --- a/crates/material-graph/tests/it/kind_versions.rs +++ b/crates/material-graph/tests/it/kind_versions.rs @@ -53,11 +53,15 @@ fn a_fix_in_one_operation_leaves_most_kinds_alone() { files.iter().for_each(|f| println!(" {}", f.name)); } assert!(files.len() > 20, "{} of {} files reachable", files.len(), all.len()); + let started = std::time::Instant::now(); let tree = SourceTree::scan(&files, DISPATCHERS); + eprintln!("DIAG kind_versions first scan {:?}", started.elapsed()); let kinds: Vec = tree.kinds().map(str::to_string).collect(); assert!(kinds.len() > 100, "the kinds were found: {}", kinds.len()); let versions = |t: &SourceTree| kinds.iter().map(|k| t.kind_version(k, SHARED).unwrap()).collect::>(); + let started = std::time::Instant::now(); let before = versions(&tree); + eprintln!("DIAG kind_versions first versions {:?}", started.elapsed()); let distinct: std::collections::BTreeSet<_> = before.iter().collect(); if std::env::var_os("TC_VERSIONS_DUMP").is_some() { for k in &kinds { @@ -72,24 +76,38 @@ fn a_fix_in_one_operation_leaves_most_kinds_alone() { } assert!(distinct.len() > kinds.len() / 2, "{} distinct versions of {} kinds", distinct.len(), kinds.len()); - let changed_by = |file: &str, from: &str, to: &str| { + let changed_by_all = |edits: &[(&str, &str, &str)]| { let edited: Vec = files .iter() .map(|f| { - let text = if f.name == file { f.text.replacen(from, to, 1) } else { f.text.clone() }; - assert!(f.name != file || text != f.text, "{from} is in {file}"); + let mut text = f.text.clone(); + for (file, from, to) in edits.iter().filter(|e| e.0 == f.name) { + let next = text.replacen(from, to, 1); + assert!(next != text, "{from} is in {file}"); + text = next; + } SourceFile { text, ..f.clone() } }) .collect(); - let after = versions(&SourceTree::scan(&edited, DISPATCHERS)); + let started = std::time::Instant::now(); + let scanned = SourceTree::scan(&edited, DISPATCHERS); + let scan = started.elapsed(); + let after = versions(&scanned); + eprintln!( + "DIAG kind_versions edit of {:?}: scan {scan:?}, versions {:?}", + edits.iter().map(|e| e.0).collect::>(), + started.elapsed() - scan + ); kinds.iter().zip(before.iter().zip(&after)).filter(|(_, (a, b))| a != b).map(|(k, _)| k.clone()).collect::>() }; + let changed_by = |file: &str, from: &str, to: &str| changed_by_all(&[(file, from, to)]); - let added = changed_by("src/compiled_ops.rs", "pub fn compute(kind: &str", "fn __added_helper() -> u8 { 1 }\npub fn compute(kind: &str"); - assert_eq!(added, Vec::::new(), "an added function nothing uses changes nothing"); - - let comment = changed_by("src/atomic.rs", "\"levels_mid\" => {", "\"levels_mid\" => { // a comment\n"); - assert_eq!(comment, Vec::::new(), "a comment changes nothing"); + // an added function nothing uses, and a comment: both change nothing (edits in two files, one pass) + let unchanged = changed_by_all(&[ + ("src/compiled_ops.rs", "pub fn compute(kind: &str", "fn __added_helper() -> u8 { 1 }\npub fn compute(kind: &str"), + ("src/atomic.rs", "\"levels_mid\" => {", "\"levels_mid\" => { // a comment\n"), + ]); + assert_eq!(unchanged, Vec::::new(), "an unused added function and a comment change nothing"); // a fix inside one node's arm let arm = changed_by("src/atomic.rs", "\"levels_mid\" => {", "\"levels_mid\" => { let _fixed = 1;"); diff --git a/crates/material-graph/tests/it/main.rs b/crates/material-graph/tests/it/main.rs index 3b2886dcfa..a7828f053c 100644 --- a/crates/material-graph/tests/it/main.rs +++ b/crates/material-graph/tests/it/main.rs @@ -14,3 +14,21 @@ mod kind_versions; mod nodes; mod seam; mod vector; + +/// The gate's share of a sweep over `items`: every `craft_testkit::hostile::divisor()`-th one from `offset` (all of them +/// nightly, where the divisor is 1), so tests sweeping the same list with different offsets together reach more of it. +fn sampled(items: impl IntoIterator, offset: usize) -> Vec { + let div = divisor(); + items.into_iter().enumerate().filter(|(i, _)| (i + offset).is_multiple_of(div)).map(|(_, t)| t).collect() +} + +fn divisor() -> usize { + #[cfg(not(target_arch = "wasm32"))] + { + craft_testkit::hostile::divisor() + } + #[cfg(target_arch = "wasm32")] + { + 1 + } +} diff --git a/crates/material-graph/tests/it/nodes.rs b/crates/material-graph/tests/it/nodes.rs index a92e395664..0b769d2935 100644 --- a/crates/material-graph/tests/it/nodes.rs +++ b/crates/material-graph/tests/it/nodes.rs @@ -309,7 +309,7 @@ fn node_parameters_survive_extreme_values() { use craft_material_graph::graph::{SPECS, demo_graph_for}; let mut problems = Vec::new(); let mut ran = 0usize; - for sp in SPECS { + for sp in crate::sampled(SPECS, 0) { let Some(text) = demo_graph_for(sp.kind) else { continue }; let doc = sp.doc.split_once(':').map(|x| x.1).unwrap_or(""); let names: Vec = doc @@ -338,7 +338,7 @@ fn node_parameters_survive_extreme_values() { } problems.sort(); problems.dedup(); - assert!(ran > 500, "only {ran} parameter cases ran"); + assert!(ran > 500 / crate::divisor(), "only {ran} parameter cases ran"); assert!(problems.is_empty(), "{} parameter problems:\n{}", problems.len(), problems.join("\n")); } @@ -446,17 +446,17 @@ fn large_sizes_are_accepted() { fn a_cancelled_evaluation_stops_early() { use craft_material_graph::context::{Cancel, EvalContext}; let mut g = Graph::parse(EXAMPLE).unwrap(); - g.size = 1024; + g.size = 256; let keep: Vec = g.output_nodes().iter().map(|o| o.2).collect(); let job = EvalContext::with_cancel(Cancel::new()); let t0 = std::time::Instant::now(); - let full = g.evaluate_all_in(&job, 1024, &keep); + let full = g.evaluate_all_in(&job, 256, &keep); let full_time = t0.elapsed(); assert!(!full.kept.is_empty(), "a current job must deliver its outputs"); // a newer job exists: the old one is cancelled from the start job.cancel.cancel(); let t1 = std::time::Instant::now(); - let r = g.evaluate_all_in(&job, 1024, &keep); + let r = g.evaluate_all_in(&job, 256, &keep); assert!(r.kept.is_empty(), "a cancelled run must not deliver outputs"); assert!( t1.elapsed() < full_time / 4 + std::time::Duration::from_millis(50), diff --git a/crates/material-graph/tests/it/seam.rs b/crates/material-graph/tests/it/seam.rs index f5f39c96fc..ed68e63f26 100644 --- a/crates/material-graph/tests/it/seam.rs +++ b/crates/material-graph/tests/it/seam.rs @@ -18,7 +18,7 @@ fn seam(t: &Tex) -> (f32, f32) { #[test] fn every_node_is_seamless() { let mut bad = Vec::new(); - for sp in SPECS { + for sp in crate::sampled(SPECS, 0) { let Some(text) = demo_graph_for(sp.kind) else { continue }; let g = Graph::parse(&text).unwrap(); let out = match g.evaluate(Some(seam_size())) { @@ -83,7 +83,7 @@ fn filters_commute_with_wrapped_shifts() { "quantize", ]; let mut bad = Vec::new(); - for c in filters { + for c in crate::sampled(filters.iter(), 0) { let kind = c.split(' ').next().unwrap(); let mut line = format!("node 1 {c}"); // (the nodes that read no `in` are given their inputs in the line) @@ -144,7 +144,7 @@ fn filters_commute_with_wrapped_shifts() { fn every_node_is_seamless_when_not_square() { let mut bad = Vec::new(); for (wide, name) in [(true, "2:1"), (false, "1:2")] { - for sp in SPECS { + for sp in crate::sampled(SPECS, 4) { let Some(text) = demo_graph_for(sp.kind) else { continue }; let mut g = Graph::parse(&text).unwrap(); let s = g.size; diff --git a/crates/media/src/mxf/hostile_tests.rs b/crates/media/src/mxf/hostile_tests.rs index 77e4799e45..c905164dbb 100644 --- a/crates/media/src/mxf/hostile_tests.rs +++ b/crates/media/src/mxf/hostile_tests.rs @@ -159,13 +159,15 @@ fn extreme(f: &mut [u8], at: usize, len: usize, r: &mut Rng) { fn extreme_metadata_index_and_partition_fields_never_panic() { let mut r = Rng(0x00C0_FFEE_1234_5678); let mut opened = 0; + // The gate damages each base the hostile divisor's fraction of the rounds; nightly all 600. + let rounds = 600 / craft_media_testkit::hostile::divisor(); for base in bases() { assert!(exercise(&base), "the unchanged file opens"); // local sets (header metadata, index table segments) and partition packs let sets: Vec<(usize, usize, usize)> = klvs(&base).into_iter().filter(|&(k, _, len)| len > 0 && base[k + 4] == 0x02 && matches!(base[k + 5], 0x53 | 0x05)).collect(); assert!(sets.len() > 10, "{} packets to damage", sets.len()); - for round in 0..600 { + for round in 0..rounds { let mut f = base.clone(); for _ in 0..1 + round % 3 { let (k, v, len) = sets[r.below(sets.len())]; @@ -184,7 +186,7 @@ fn extreme_metadata_index_and_partition_fields_never_panic() { opened += usize::from(exercise(&f)); } } - assert!(opened > 1200, "most damaged files still open and are read: {opened}"); + assert!(opened > 2 * rounds, "most damaged files still open and are read: {opened} of {rounds} rounds a base"); } /// KLV lengths that lie (longer than the file, the largest BER lengths, zero) and keys that stop diff --git a/crates/menu/tests/it/shortcuts/review.rs b/crates/menu/tests/it/shortcuts/review.rs index 2ab0953a7d..8f5b3e8069 100644 --- a/crates/menu/tests/it/shortcuts/review.rs +++ b/crates/menu/tests/it/shortcuts/review.rs @@ -44,15 +44,15 @@ fn review_rig() -> Rig { rig } -/// Only the lines in view are drawn: the review of 2,000 entries holds a few include boxes, not 2,000. +/// Only the lines in view are drawn: a review of several hundred entries holds a few include boxes, not one per entry. #[trial] fn a_large_review_draws_only_the_rows_in_view() { - let commands: Vec = (0..2000).map(|i| command(&format!("Entry {i}"), "Cmd+K")).collect(); + let commands: Vec = (0..400).map(|i| command(&format!("Entry {i}"), "Cmd+K")).collect(); let mut rig = Rig::new(keymap(Platform::Mac), options(), None); rig.review(set(&commands), ImportOptions::default()); let drawn = rig.names_with(Role::CHECK_BOX, "").len(); assert!(drawn > 0, "the lines in view carry include boxes"); - assert!(drawn < 100, "{drawn} include boxes drawn for 2,000 entries"); + assert!(drawn < 100, "{drawn} include boxes drawn for 400 entries"); } /// Start, include and a picked target re-plan the import; a pick and No equivalent reach the app. diff --git a/crates/metadata/src/xmp_merge.rs b/crates/metadata/src/xmp_merge.rs index 33714269af..76759f680f 100644 --- a/crates/metadata/src/xmp_merge.rs +++ b/crates/metadata/src/xmp_merge.rs @@ -512,10 +512,10 @@ mod tests { assert_eq!(found.descs[0].attrs.len(), n + 2, "every attribute is read"); took }; - let (n, small_packet, large_packet) = (50_000, packet(50_000), packet(200_000)); + let (n, small_packet, large_packet) = (20_000, packet(20_000), packet(80_000)); // interleaved, so a burst of load slows both sizes rather than one; the fastest run of each counts let (mut small, mut large) = (std::time::Duration::MAX, std::time::Duration::MAX); - for _ in 0..5 { + for _ in 0..3 { small = small.min(run(&small_packet, n)); large = large.min(run(&large_packet, 4 * n)); } diff --git a/crates/midi/tests/it/lenient.rs b/crates/midi/tests/it/lenient.rs index e328115458..67b88a49c9 100644 --- a/crates/midi/tests/it/lenient.rs +++ b/crates/midi/tests/it/lenient.rs @@ -117,12 +117,20 @@ fn names_instruments_and_lyrics() { assert_eq!((read.smf.tracks.len(), read.instruments), (2, vec!["Sax".to_string(), String::new()])); } +/// Three bytes a note-on under running status: more events than are read. Built once for the tests that need it. +fn event_flood_body() -> &'static [u8] { + static BODY: std::sync::OnceLock> = std::sync::OnceLock::new(); + BODY.get_or_init(|| { + let mut body = vec![0x00, 0x90, 60, 100]; + body.extend((0..MAX_EVENTS + 1).flat_map(|i| [0x00, (i % 128) as u8, 1])); + body + }) +} + #[test] fn a_file_of_any_size_is_read_into_a_bounded_number_of_events_and_warnings() { - // Three bytes a note-on under running status: more events than are read. - let mut body = vec![0x00, 0x90, 60, 100]; - body.extend((0..MAX_EVENTS + 1000).flat_map(|i| [0x00, (i % 128) as u8, 1])); - let LenientRead { smf, warnings, over_limit, .. } = read_smf_lenient(&file(1, 96, &[&body])).unwrap(); + let body = event_flood_body(); + let LenientRead { smf, warnings, over_limit, .. } = read_smf_lenient(&file(1, 96, &[body])).unwrap(); assert_eq!(smf.tracks[0].sequence.notes.len(), MAX_EVENTS); assert!(warnings.iter().any(|w| w.contains("more events")), "{warnings:?}"); assert!(over_limit, "the event limit left events out"); @@ -140,10 +148,9 @@ fn a_file_of_any_size_is_read_into_a_bounded_number_of_events_and_warnings() { fn a_limit_reached_after_the_warnings_are_full_is_still_reported() { // MAX_WARNINGS damaged tracks fill the warnings; the track after them holds more events than are // read, so its warning is dropped, and over_limit is what says the file was cut. - let mut body = vec![0x00, 0x90, 60, 100]; - body.extend((0..MAX_EVENTS + 1000).flat_map(|i| [0x00, (i % 128) as u8, 1])); + let body = event_flood_body(); let mut tracks = vec![&[0x00, 60][..]; MAX_WARNINGS]; - tracks.push(&body); + tracks.push(body); let LenientRead { warnings, over_limit, .. } = read_smf_lenient(&file(1, 96, &tracks)).unwrap(); assert_eq!(warnings.len(), MAX_WARNINGS); assert!(!warnings.iter().any(|w| w.contains("more events")), "the test needs the limit's warning dropped: {warnings:?}"); diff --git a/crates/mime/Cargo.toml b/crates/mime/Cargo.toml index 524bca8fb4..60702e1099 100644 --- a/crates/mime/Cargo.toml +++ b/crates/mime/Cargo.toml @@ -24,4 +24,5 @@ chardetng = { version = "1", optional = true } detect = ["dep:chardetng"] [dev-dependencies] +craft-testkit = { workspace = true } proptest = { workspace = true } diff --git a/crates/mime/tests/hostile.rs b/crates/mime/tests/hostile.rs index 36c8327db8..5b677eaf6d 100644 --- a/crates/mime/tests/hostile.rs +++ b/crates/mime/tests/hostile.rs @@ -145,7 +145,8 @@ fn mutations_read() { }; const INTERESTING: &[u8] = b"\0\r\n\t \"\\()<>;:=?-_%*'/@,.\x7f\x80\xff"; for original in [sample(), archive()] { - for round in 0..4000u32 { + // The gate runs a divisor's fraction of the rounds; nightly runs all. + for round in 0..4000 / craft_testkit::hostile::divisor() as u32 { let mut bytes = original.clone(); for _ in 0..=(round % 4) { let at = (next() as usize) % bytes.len().max(1); diff --git a/crates/openpgp/src/coverage_tests.rs b/crates/openpgp/src/coverage_tests.rs index ffad12ce21..9bc8aeabe0 100644 --- a/crates/openpgp/src/coverage_tests.rs +++ b/crates/openpgp/src/coverage_tests.rs @@ -4,7 +4,7 @@ use pgp::crypto::hash::HashAlgorithm; use crate::fixtures::*; -use crate::{CantCheck, Checked, Coverage, Fingerprint, KeyRing, MAX_MESSAGE, NotVerified, Outcome, verify}; +use crate::{CantCheck, Checked, Coverage, Fingerprint, KeyRing, MAX_MESSAGE, NotVerified, Outcome, verify, verify_within}; const ALICE: &str = "Alice "; @@ -120,17 +120,21 @@ fn an_armour_header_other_than_hash_or_an_unescaped_dash_line_is_unreadable() { #[test] fn a_signed_message_too_large_to_check_says_so() { - let mut big = signed_message(&secret(ALICE, Make::default()), HashAlgorithm::Sha256); - big.resize(MAX_MESSAGE + 1, b'a'); - let checked = verify(&big, ALICE, &KeyRing::new(), LATER, yes).unwrap(); - assert!(matches!(checked.outcome, Outcome::CantCheck { why: CantCheck::TooLarge, .. })); - // Inline-signed, the block found anywhere in it. - let mut big = plain(ALICE, "7bit", &"a".repeat(1 << 20)); - big.extend_from_slice(b"\r\n-----BEGIN PGP SIGNED MESSAGE-----\r\n"); - big.resize(MAX_MESSAGE + 1, b'a'); - assert!(verify(&big, ALICE, &KeyRing::new(), LATER, yes).is_some()); - // Not signed at all: nothing to say. - let mut big = plain(ALICE, "7bit", "Just text.\r\n"); - big.resize(MAX_MESSAGE + 1, b'a'); - assert_eq!(verify(&big, ALICE, &KeyRing::new(), LATER, yes), None); + // At a 64 KiB limit; nightly also at MAX_MESSAGE. + let full = craft_testkit::hostile::divisor() == 1; + for max in [64 << 10].into_iter().chain(full.then_some(MAX_MESSAGE)) { + let mut big = signed_message(&secret(ALICE, Make::default()), HashAlgorithm::Sha256); + big.resize(max + 1, b'a'); + let checked = verify_within(&big, max, ALICE, &KeyRing::new(), LATER, yes).unwrap(); + assert!(matches!(checked.outcome, Outcome::CantCheck { why: CantCheck::TooLarge, .. })); + // Inline-signed, the block found anywhere in it. + let mut big = plain(ALICE, "7bit", &"a".repeat(max / 2)); + big.extend_from_slice(b"\r\n-----BEGIN PGP SIGNED MESSAGE-----\r\n"); + big.resize(max + 1, b'a'); + assert!(verify_within(&big, max, ALICE, &KeyRing::new(), LATER, yes).is_some()); + // Not signed at all: nothing to say. + let mut big = plain(ALICE, "7bit", "Just text.\r\n"); + big.resize(max + 1, b'a'); + assert_eq!(verify_within(&big, max, ALICE, &KeyRing::new(), LATER, yes), None); + } } diff --git a/crates/openpgp/src/lib.rs b/crates/openpgp/src/lib.rs index 01ec0af435..bb312aa047 100644 --- a/crates/openpgp/src/lib.rs +++ b/crates/openpgp/src/lib.rs @@ -101,7 +101,19 @@ pub(crate) fn guard(f: impl FnOnce() -> T) -> Option { /// [`Outcome::Verified`] only when the signature covers all of it ([`Coverage::whole`]); one /// that covers part of it is at best [`Outcome::Valid`] with [`NotVerified::partly_signed`]. pub fn verify(original: &[u8], from: &str, keys: &KeyRing, now: u64, verified: impl Fn(&Fingerprint, &str) -> bool) -> Option { - if original.len() > MAX_MESSAGE { + verify_within(original, MAX_MESSAGE, from, keys, now, verified) +} + +/// [`verify`] for messages of at most `max` bytes. +fn verify_within( + original: &[u8], + max: usize, + from: &str, + keys: &KeyRing, + now: u64, + verified: impl Fn(&Fingerprint, &str) -> bool, +) -> Option { + if original.len() > max { return looks_signed(original).then(|| Checked { outcome: Outcome::cant(CantCheck::TooLarge), coverage: Coverage::default() }); } let cx = check::Context { diff --git a/crates/pages/tests/it/views.rs b/crates/pages/tests/it/views.rs index fb02cdc9c4..3ddb1e268c 100644 --- a/crates/pages/tests/it/views.rs +++ b/crates/pages/tests/it/views.rs @@ -512,7 +512,8 @@ fn a_page_gap_change_keeps_the_scroll_offset() { #[trial] fn the_pictures_a_view_holds_stay_bounded_as_it_scrolls_through_many_pages() { let budget = TextureStoreOptions::pages().budget.max_entries; - let count = 2 * budget; + // Past the budget by half again: the store has to evict for the bound to be tested. + let count = budget + budget / 2; let state = Rc::new(RefCell::new(state_with(|s| { s.continuous = true; s.fit = Fit::None; @@ -539,6 +540,7 @@ fn the_pictures_a_view_holds_stay_bounded_as_it_scrolls_through_many_pages() { assert!(drawn > 0, "the view drew pages"); // The pages of the last two passes, in view and one row either side, are never evicted. let bound = budget + 2 * (drawn + 2); + eprintln!("DIAG pictures_bounded: budget {budget}, count {count}, held {held}, drawn {drawn}"); assert!(held > 0 && held <= bound, "{held} pictures held over {count} pages scrolled through, at most {bound} expected"); } diff --git a/crates/pdf/tests/crypt/proptests.rs b/crates/pdf/tests/crypt/proptests.rs index 80277ae605..e3e8ca04df 100644 --- a/crates/pdf/tests/crypt/proptests.rs +++ b/crates/pdf/tests/crypt/proptests.rs @@ -120,10 +120,10 @@ fn open_aes256() -> &'static SecurityHandler { HANDLER.get_or_init(|| make(Algorithm::Aes256, "", "owner")) } -/// Cases for the expensive properties (each draws fresh AES-256 files): the gate's fraction of -/// `full` (the hostile-input divisor), at least `floor`; nightly runs `full`. -fn cases(full: u32, floor: u32) -> ProptestConfig { - ProptestConfig::with_cases((full / craft_testkit::hostile::divisor() as u32).max(floor)) +/// Cases for the expensive properties (each case creates a file and runs a password hash per +/// password it tries): `gate` cases at the gate, `full` nightly (hostile-input divisor 1). +fn cases(full: u32, gate: u32) -> ProptestConfig { + ProptestConfig::with_cases(if craft_testkit::hostile::divisor() == 1 { full } else { gate }) } proptest! { @@ -280,7 +280,7 @@ proptest! { } proptest! { - #![proptest_config(cases(256, 12))] + #![proptest_config(cases(256, 3))] /// A file created for `user` and `owner` opens for exactly the passwords whose effective bytes /// equal one of theirs, and reports the role that match earned — owner first, since viewers try /// `/O` before `/U`. Everything else is `WrongPassword`: never an opening, and no panic on odd @@ -414,7 +414,7 @@ proptest! { } proptest! { - #![proptest_config(cases(256, 12))] + #![proptest_config(cases(256, 5))] /// `/Perms` certifies the permission bits and `/EncryptMetadata`: decrypted with the file key it /// must hold `/P` little-endian, four set bytes, 'T' or 'F', and the `adb` sentinel (Algorithm 10). /// Nothing else in this crate reads it — `cos` writes it out and no code takes it back apart — so diff --git a/crates/proto/src/imap/limits_tests.rs b/crates/proto/src/imap/limits_tests.rs index 01e91e7de1..f0afbd5dc8 100644 --- a/crates/proto/src/imap/limits_tests.rs +++ b/crates/proto/src/imap/limits_tests.rs @@ -29,13 +29,13 @@ fn a_flood_of_long_lines_ends_the_command() { // 600 lines of 60 KB are more than the 32 MB one command may bring. The gate sends lines that // are not parsed (the cap counts the text read); nightly sends the lines of a real listing. let full = craft_testkit::hostile::divisor() == 1; - let server = - flood(600, |n| if full { format!("* {n} FETCH (UID {} FLAGS ({pad}))\r\n", n + 1) } else { format!("* OK {pad}\r\n") }) + "A0001 OK done\r\n"; + let ok_lines = format!("* OK {pad}\r\n").repeat(600); + let server = if full { flood(600, |n| format!("* {n} FETCH (UID {} FLAGS ({pad}))\r\n", n + 1)) } else { ok_lines.clone() } + "A0001 OK done\r\n"; let mut s = Script::new(server); let err = opened(&mut s, 1000, 2000).uid_fetch_flags("1:*").unwrap_err(); assert!(matches!(err, ProtoError::Protocol(ref m) if m.to_string().contains("too much")), "{err:?}"); // The same in a list. - let server = flood(600, |n| if full { format!("* LIST () \"/\" \"{n}{pad}\"\r\n") } else { format!("* OK {pad}\r\n") }) + "A0001 OK done\r\n"; + let server = if full { flood(600, |n| format!("* LIST () \"/\" \"{n}{pad}\"\r\n")) } else { ok_lines } + "A0001 OK done\r\n"; let mut s = Script::new(server); assert!(matches!(opened(&mut s, 0, 0).list(), Err(ProtoError::Protocol(_)))); } diff --git a/crates/ps/Cargo.toml b/crates/ps/Cargo.toml index 2f0316e594..cee8ce5c19 100644 --- a/crates/ps/Cargo.toml +++ b/crates/ps/Cargo.toml @@ -24,6 +24,9 @@ skrifa = { workspace = true, optional = true } kurbo = { workspace = true, optional = true } flate2 = { version = "1.1.10", default-features = false, features = ["rust_backend"], optional = true } +[dev-dependencies] +craft-testkit = { workspace = true } + [[example]] name = "eps2pdf" required-features = ["read"] diff --git a/crates/ps/src/write.rs b/crates/ps/src/write.rs index 4405a0393a..09793a8ebe 100644 --- a/crates/ps/src/write.rs +++ b/crates/ps/src/write.rs @@ -602,9 +602,13 @@ mod tests { #[test] fn numbers_match_base_formatter() { - let mut integer_path = 0usize; + // The gate walks every `divisor()`-th value (offset by `places` so the places differ); nightly walks all. + let step = craft_testkit::hostile::divisor(); + let (mut integer_path, mut visited) = (0usize, 0usize); + let samples = number_samples(); for places in 0..=12 { - for v in number_samples() { + for v in samples.iter().copied().skip(places as usize % step).step_by(step) { + visited += 1; let mut expected = String::from("x "); base_push_num_places(&mut expected, v, places); let mut got = String::from("x "); @@ -616,7 +620,8 @@ mod tests { } } // The comparison covers the integer path, not only the fallback. - assert!(integer_path > 200_000, "{integer_path} values took the integer path"); + eprintln!("DIAG numbers_match_base_formatter: visited {visited}, integer path {integer_path}"); + assert!(integer_path * 20 > visited, "{integer_path} of {visited} values took the integer path"); } #[test] diff --git a/crates/psd/src/float.rs b/crates/psd/src/float.rs index 658538bc22..ad10fbafe7 100644 --- a/crates/psd/src/float.rs +++ b/crates/psd/src/float.rs @@ -781,7 +781,8 @@ mod tests { #[test] fn a_mesh_that_makes_every_triangle_cover_the_output_is_refused() { // A 48×48 custom mesh whose patch corners scatter over the four corners of the - // content, so most of the 4608 triangles span the whole 2048² output. + // content, so most of the 4608 triangles span the whole output (the work budget grows with + // the output's pixels, so the size only sets how much is filled before it runs out). let (cols, rows) = (48usize, 48usize); let stride = cols * 3 + 1; let mut mesh = vec![[0.0, 0.0]; stride * (rows * 3 + 1)]; @@ -794,9 +795,9 @@ mod tests { } } let warp = crate::smart::Warp { style: "warpCustom".into(), bounds: [0.0, 0.0, 16.0, 16.0], cols, rows, mesh, ..Default::default() }; - let s = so([[0.0, 0.0], [2048.0, 0.0], [2048.0, 2048.0], [0.0, 2048.0]], Some(warp)); + let s = so([[0.0, 0.0], [512.0, 0.0], [512.0, 512.0], [0.0, 512.0]], Some(warp)); let content = FloatImage { width: 16, height: 16, data: vec![[1.0, 0.0, 0.0, 1.0]; 256] }; - assert!(s.render_placed(&content, 1.0, Some((2048, 2048))).is_none()); + assert!(s.render_placed(&content, 1.0, Some((512, 512))).is_none()); } #[test] diff --git a/crates/raw/src/nef.rs b/crates/raw/src/nef.rs index 9321deb308..073a393f18 100644 --- a/crates/raw/src/nef.rs +++ b/crates/raw/src/nef.rs @@ -987,10 +987,12 @@ mod tests { /// D70 and D70s get best-guess frames (the D40 shares the D50 / D70 / D70s data size but not their frame). #[test] fn measured_older_dx_bodies_image_area() { - let decode_as = |model: &str, (w, h): (usize, usize)| { - let nef = nef_model_in(ByteOrder::Big, model, 1, 12, vec![vec![0x10; w * h * 2]], w as u32, h as u32, h as u32, None); - crate::decode(&nef).unwrap() + let nef_as = |model: &str, (w, h): (usize, usize)| { + nef_model_in(ByteOrder::Big, model, 1, 12, vec![vec![0x10; w * h * 2]], w as u32, h as u32, h as u32, None) }; + // The headers decide the frame (`probe_info` equals the decoded image's info); one body decodes in full. + let crop_of = |model: &str, size: (usize, usize)| crate::probe_info(&nef_as(model, size)).unwrap().crop; + assert_eq!(crate::decode(&nef_as("NIKON D200", (3904, 2616))).unwrap().crop, Rect::new(16, 12, 3872, 2592)); for (model, size, crop) in [ ("NIKON D200", (3904, 2616), Rect::new(16, 12, 3872, 2592)), ("NIKON D80", (3904, 2616), Rect::new(14, 9, 3872, 2592)), @@ -1003,10 +1005,10 @@ mod tests { ("NIKON D70", (3040, 2014), Rect::new(15, 7, 3008, 2000)), ("NIKON D70s", (3040, 2014), Rect::new(15, 7, 3008, 2000)), ] { - assert_eq!(decode_as(model, size).crop, crop, "{model}"); + assert_eq!(crop_of(model, size), crop, "{model}"); } // the V1's area on the V2's data size: no entry, the whole data - assert_eq!(decode_as("NIKON 1 V1", (4620, 3084)).crop, Rect::new(0, 0, 4620, 3084)); + assert_eq!(crop_of("NIKON 1 V1", (4620, 3084)), Rect::new(0, 0, 4620, 3084)); } /// Every measured entry is a crop inside its data, once per model, data size and depth, with a white level (if @@ -1028,21 +1030,25 @@ mod tests { /// image areas (full frame and 1.3x crop), so renders came out larger and Lightroom crops landed off. #[test] fn measured_d7100_image_area() { - let decode_as = |model: &str, (w, h): (usize, usize)| { + let nef_as = |model: &str, (w, h): (usize, usize)| { let mut nef = nef(1, 14, vec![vec![0x10; w * h * 2]], w as u32, h as u32, h as u32); // the fixture's model is "NIKON TEST" plus its NUL: 11 bytes to overwrite let at = nef.windows(11).position(|b| b == b"NIKON TEST\0").unwrap(); let name = format!("{model:\0<11}"); nef[at..at + 11].copy_from_slice(name.as_bytes()); - crate::decode(&nef).unwrap() + nef }; + // The headers decide the frame (`probe_info` equals the decoded image's info); the white level needs the + // samples, so the full-frame area decodes in full. + let d7100 = crate::decode(&nef_as("NIKON D7100", (6036, 4020))).unwrap(); + assert_eq!(d7100.crop, Rect::new(18, 10, 6000, 4000)); + assert_ne!(d7100.white, vec![15520.0]); for (size, crop) in [((6036, 4020), Rect::new(18, 10, 6000, 4000)), ((4812, 3212), Rect::new(6, 6, 4800, 3200))] { - let d7100 = decode_as("NIKON D7100", size); + let d7100 = crate::probe_info(&nef_as("NIKON D7100", size)).unwrap(); assert_eq!(d7100.crop, crop); assert_eq!((d7100.crop.width, d7100.crop.height), (crop.width, crop.height)); - assert_ne!(d7100.white, vec![15520.0]); - assert_eq!(d7100.info().developed_size(), (crop.width, crop.height)); - assert_eq!(decode_as("NIKON D7200", size).crop, Rect::new(0, 0, size.0, size.1)); + assert_eq!(d7100.developed_size(), (crop.width, crop.height)); + assert_eq!(crate::probe_info(&nef_as("NIKON D7200", size)).unwrap().crop, Rect::new(0, 0, size.0, size.1)); } } diff --git a/crates/scraft-format/src/b64.rs b/crates/scraft-format/src/b64.rs index b4421c00bc..4ecd1c6dd8 100644 --- a/crates/scraft-format/src/b64.rs +++ b/crates/scraft-format/src/b64.rs @@ -37,7 +37,12 @@ fn value(c: u8) -> Option { /// Decodes padded (or unpadded) standard base64. `None` for malformed input or a result larger /// than [`MAX_DECODED_BYTES`]. pub fn decode(text: &str) -> Option> { - if text.bytes().filter(|c| !c.is_ascii_whitespace()).count() > MAX_DECODED_BYTES.div_ceil(3).saturating_mul(4) { + decode_capped(text, MAX_DECODED_BYTES) +} + +/// [`decode`] with the output capped at `max` bytes. +fn decode_capped(text: &str, max: usize) -> Option> { + if text.bytes().filter(|c| !c.is_ascii_whitespace()).count() > max.div_ceil(3).saturating_mul(4) { return None; } let syms: Vec = text.bytes().filter(|c| !c.is_ascii_whitespace()).collect(); @@ -46,7 +51,7 @@ pub fn decode(text: &str) -> Option> { return None; } let decoded_len = body.len() / 4 * 3 + body.len() % 4 * 3 / 4; - if decoded_len > MAX_DECODED_BYTES { + if decoded_len > max { return None; } let mut out = Vec::with_capacity(decoded_len); @@ -99,19 +104,17 @@ mod tests { encoded } - // Build valid base64 directly instead of encoding a 64 MiB allocation on every case. - // This keeps the same decoded-size boundary checks while making the workspace gate much - // faster and using less temporary memory. - let exact = encoded_zero_bytes(MAX_DECODED_BYTES); - assert_eq!(decode(&exact).map(|bytes| bytes.len()), Some(MAX_DECODED_BYTES), "padded boundary"); - let too_large = encoded_zero_bytes(MAX_DECODED_BYTES + 1); - assert!(decode(&too_large).is_none(), "padded over boundary"); - // Each case decodes tens of MiB: the gate runs the two above, nightly the rest. - if craft_testkit::hostile::divisor() > 1 { - return; + // The boundary at a cap of every remainder mod 3; nightly also at the real 64 MiB cap. + let full = craft_testkit::hostile::divisor() == 1; + let caps = [97, 98, 99].into_iter().chain(full.then_some(MAX_DECODED_BYTES)); + for max in caps { + let exact = encoded_zero_bytes(max); + assert_eq!(decode_capped(&exact, max).map(|bytes| bytes.len()), Some(max), "padded boundary at {max}"); + let too_large = encoded_zero_bytes(max + 1); + assert!(decode_capped(&too_large, max).is_none(), "padded over boundary at {max}"); + assert_eq!(decode_capped(exact.trim_end_matches('='), max).map(|bytes| bytes.len()), Some(max), "unpadded boundary at {max}"); + let spaced = format!("{}\n {}", &too_large[..8], &too_large[8..]); + assert!(decode_capped(&spaced, max).is_none(), "whitespace over boundary at {max}"); } - assert_eq!(decode(exact.trim_end_matches('=')).map(|bytes| bytes.len()), Some(MAX_DECODED_BYTES), "unpadded boundary"); - let spaced = format!("{}\n {}", &too_large[..8], &too_large[8..]); - assert!(decode(&spaced).is_none(), "whitespace over boundary"); } } diff --git a/crates/stream-codecs/src/jbig2.rs b/crates/stream-codecs/src/jbig2.rs index a90484b95f..e95841d387 100644 --- a/crates/stream-codecs/src/jbig2.rs +++ b/crates/stream-codecs/src/jbig2.rs @@ -434,6 +434,10 @@ mod tests { self.0 += 1; } } + // The largest page, 2^28 pixels, takes seconds to encode and decode: nightly only. + if craft_testkit::hostile::divisor() > 1 { + return; + } // One black pixel, so a page that came back blank wouldn't pass. let mut largest = vec![0xFF; 2_048 * 16_384]; largest[0] = 0x7F; diff --git a/crates/stream-codecs/src/jbig2/decode.rs b/crates/stream-codecs/src/jbig2/decode.rs index 0e04bd6483..b718863c65 100644 --- a/crates/stream-codecs/src/jbig2/decode.rs +++ b/crates/stream-codecs/src/jbig2/decode.rs @@ -518,7 +518,10 @@ mod tests { // decoder, which has the same one and can refuse it first. let large = |rows| decode_jbig2(&page_of(&data, 16_384, rows), None, 16_384, rows, usize::MAX); assert!(matches!(large(16_385), Err(CodecError::Unsupported(_) | CodecError::Corrupt { .. })), "{:?}", large(16_385)); - assert!(large(16_384).is_ok(), "{:?}", large(16_384).map(|page| page.len())); + // Decoding the 2^28-pixel page takes seconds: nightly only. + if craft_testkit::hostile::divisor() == 1 { + assert!(large(16_384).is_ok(), "{:?}", large(16_384).map(|page| page.len())); + } // An extension segment (ISO/IEC 14492 7.4.14), which a decoder skips: its 11-byte header // gives the length of the data after it. diff --git a/crates/stream-codecs/src/jbig2/symbols.rs b/crates/stream-codecs/src/jbig2/symbols.rs index 56f5e26ffb..33e16c13d5 100644 --- a/crates/stream-codecs/src/jbig2/symbols.rs +++ b/crates/stream-codecs/src/jbig2/symbols.rs @@ -398,6 +398,11 @@ fn symbols(page: &mut Page) -> Option<()> { /// here, and the page's own dictionary holds only the others (none, when it has none), as /// [`encode_shared`] writes them; `None` too for a page that places none of the shared ones. fn plan(page: &Page, columns: u32, rows: u32, copies: u32, log_strips: Option, shared: Option<&Shared>) -> Option> { + plan_within(page, columns, rows, copies, log_strips, shared, MAX_CODED_SYMBOLS) +} + +/// [`plan`] coding at most `max` symbols. +fn plan_within(page: &Page, columns: u32, rows: u32, copies: u32, log_strips: Option, shared: Option<&Shared>, max: usize) -> Option> { let symbol = |s: u32| page.symbols.get(s as usize); let global = |s: u32| shared.and_then(|g| g.ids.get(s as usize).copied().flatten()); let globals = shared.map_or(0, |g| g.count); @@ -405,7 +410,7 @@ fn plan(page: &Page, columns: u32, rows: u32, copies: u32, log_strips: Option = (0..page.symbols.len() as u32).filter(|s| global(*s).is_none() && symbol(*s).is_some_and(|s| s.uses >= copies)).collect(); let count = usize::try_from(globals).ok()?.checked_add(kept.len())?; - if !(2..=MAX_CODED_SYMBOLS).contains(&count) { + if !(2..=max).contains(&count) { return None; } kept.sort_by_key(|s| symbol(*s).map(|s| (s.height, s.width))); @@ -934,18 +939,26 @@ mod tests { } (samples(&picture), columns as u32, rows as u32) }; + // At a cap of 300 symbols, then (nightly: each picture is tens of thousands of marks coded and decoded) at + // MAX_CODED_SYMBOLS and past it through `encode_jbig2`. + let max = 300; + let (data, columns, rows) = codes(max, 0); + let at_cap = page(&data, columns).unwrap(); + assert_eq!(decode(&plan_within(&at_cap, columns, rows, 1, None, None, max).unwrap()), unpack(&data, columns, rows)); + // One more distinct mark, each once: neither plan is made. + let (data, columns, rows) = codes(max + 1, 0); + let past = page(&data, columns).unwrap(); + assert!(plan_within(&past, columns, rows, 1, None, None, max).is_none() && plan_within(&past, columns, rows, 2, None, None, max).is_none()); + if craft_testkit::hostile::divisor() > 1 { + return; + } let (data, columns, rows) = codes(MAX_CODED_SYMBOLS, 0); let at_cap = page(&data, columns).unwrap(); assert_eq!(decode(&plan(&at_cap, columns, rows, 1, None, None).unwrap()), unpack(&data, columns, rows)); - // One more distinct mark, each once: neither plan is made. let (data, columns, rows) = codes(MAX_CODED_SYMBOLS + 1, 0); let past = page(&data, columns).unwrap(); assert!(plan(&past, columns, rows, 1, None, None).is_none() && plan(&past, columns, rows, 2, None, None).is_none()); assert_eq!(encode_jbig2(&data, columns, rows).unwrap(), encode_jbig2_generic(&data, columns, rows).unwrap()); - // Each picture below is another 65,536 marks coded and decoded: nightly only. - if craft_testkit::hostile::divisor() > 1 { - return; - } // With two of them repeated, the second plan codes those two. let (data, columns, rows) = codes(MAX_CODED_SYMBOLS + 1, 200); let past = page(&data, columns).unwrap(); @@ -1245,6 +1258,10 @@ mod tests { /// in. Ten marks of the first image are in two images after it, with 464 first seen there. #[test] fn past_the_marks_a_group_holds_later_ones_arent_shared() { + // 66,000 marks coded in four images: nightly only. + if craft_testkit::hostile::divisor() > 1 { + return; + } let (a, b) = (samples(&combs(0..40_000)), samples(&combs(40_000..65_536))); let late = combs((0..10).chain(65_536..66_000).collect::>().into_iter()); let (rows, late) = (late.len() as u32, samples(&late)); @@ -1263,6 +1280,10 @@ mod tests { /// or a generic region, whichever is smaller). #[test] fn past_the_shared_limit_the_most_widely_held_marks_are_shared() { + // 50,000 marks coded in three images: nightly only. + if craft_testkit::hostile::divisor() > 1 { + return; + } let (both, first) = (combs(0..20_000), combs(0..10_000)); let rows = both.len(); let first: Bitmap = first.iter().cloned().chain(std::iter::repeat_n(vec![0u8; 120 * 36], rows - first.len())).collect(); diff --git a/crates/svg/src/guard.rs b/crates/svg/src/guard.rs index e2a11ae6a4..c9575f5992 100644 --- a/crates/svg/src/guard.rs +++ b/crates/svg/src/guard.rs @@ -487,7 +487,10 @@ mod tests { #[test] fn a_repeated_large_entity_is_too_large_and_a_namespace_entity_is_not() { - let big = "x".repeat(1 << 20); + // (the limit is passed in: the same arithmetic as `MAX_ENTITY_EXPANSION` over entities 256 times smaller, which + // only expand to 16 references' worth, so the strings the test builds and scans stay small) + let big = "x".repeat(1 << 16); + let expansion_too_large = |svg: &str| entities_expand_past(svg, 16 << 16); let refs = "&a;".repeat(20); let bomb = format!("]>"); assert!(expansion_too_large(&bomb)); @@ -500,6 +503,7 @@ mod tests { let ampersands = format!("]>", "&".repeat(1 << 20)); let start = std::time::Instant::now(); assert!(!expansion_too_large(&ersands)); + eprintln!("DIAG svg ampersand run read in {:?}", start.elapsed()); // A quadratic read would take hours; the bound is loose for a loaded machine. assert!(start.elapsed() < std::time::Duration::from_secs(120), "{:?}", start.elapsed()); } diff --git a/crates/theme/sizes/comfortable.json b/crates/theme/sizes/comfortable.json index c9a0e265f6..3f3144323e 100644 --- a/crates/theme/sizes/comfortable.json +++ b/crates/theme/sizes/comfortable.json @@ -22,6 +22,7 @@ "tab_large": 38.0, "title": 38.0 }, + "button": 30.0, "checker": 4.0, "control": { "md": 30.0, @@ -70,6 +71,11 @@ "short": 120.0, "track": 144.0 }, + "page": { + "action": 30.0, + "column": 820.0, + "margin": 50.0 + }, "pane": { "least": 50.0 }, diff --git a/crates/theme/sizes/compact.json b/crates/theme/sizes/compact.json index 1911106a6a..691f064615 100644 --- a/crates/theme/sizes/compact.json +++ b/crates/theme/sizes/compact.json @@ -22,6 +22,7 @@ "tab_large": 32.0, "title": 32.0 }, + "button": 24.0, "checker": 4.0, "control": { "md": 24.0, @@ -70,6 +71,11 @@ "short": 96.0, "track": 128.0 }, + "page": { + "action": 24.0, + "column": 820.0, + "margin": 40.0 + }, "pane": { "least": 40.0 }, diff --git a/crates/theme/src/app_sizes.rs b/crates/theme/src/app_sizes.rs index 25822a87dd..da08249df0 100644 --- a/crates/theme/src/app_sizes.rs +++ b/crates/theme/src/app_sizes.rs @@ -33,6 +33,10 @@ pub struct AppSizes { pub text_steps: TextSizeSteps, } +/// Base values that follow another's override when an app sets none of their own: a push button stands a control high +/// in an app that changes the control's height alone. +const FOLLOWS: [(&str, &str); 1] = [("size.button", "size.control.md")]; + /// The base paths an app may override: sizes, spacing, corner radii, strokes and type sizes, not the /// edge or fonts. pub(crate) fn base_path(path: &str) -> bool { @@ -80,6 +84,12 @@ impl AppSizes { self.all.is_empty() && self.compact.is_empty() && self.comfortable.is_empty() } + /// The override of base value `path` (with no `base.` prefix) in `merged`: its own, else the one of the value it + /// follows when it has none. + pub(crate) fn override_of<'m>(merged: &'m SizeMap, path: &str) -> Option<&'m SizeValue> { + merged.get(path).or_else(|| FOLLOWS.iter().find(|(own, _)| *own == path).and_then(|(_, of)| merged.get(*of))) + } + /// The overrides for `size`: `all`, with the set's own map over it. pub(crate) fn merged(&self, size: Size) -> SizeMap { let own = match size { @@ -98,7 +108,7 @@ impl AppSizes { return; } for Leaf { path, slot, .. } in leaves(base) { - let Some(value) = path.strip_prefix("base.").and_then(|p| merged.get(p)) else { continue }; + let Some(value) = path.strip_prefix("base.").and_then(|p| Self::override_of(&merged, p)) else { continue }; let SizeValue::Number(n) = value; if let Slot::Num(x) | Slot::Length(x) = slot { *x = *n; diff --git a/crates/theme/src/app_sizes_tests.rs b/crates/theme/src/app_sizes_tests.rs index 41ac24ab89..c8d9466581 100644 --- a/crates/theme/src/app_sizes_tests.rs +++ b/crates/theme/src/app_sizes_tests.rs @@ -20,3 +20,20 @@ fn written_sizes_parse_back_to_the_same_overrides() { assert_eq!(AppSizes::parse(text.as_bytes()).unwrap(), original); assert_eq!(AppSizes::default().to_json(), "{}\n"); } + +/// An app that sets only the control height keeps its push buttons a control high; one that sets the button height +/// gets that height. +#[test] +fn a_push_button_follows_the_control_height_unless_the_app_sets_its_own() { + let base = crate::sizes::builtin(Size::Compact).base; + let applied = |v: &Value| { + let mut preset = base; + sizes(v).apply_base(Size::Compact, &mut preset); + preset.size + }; + let follows = applied(&json!({ "all": { "size.control.md": 40 } })); + assert!(follows.control.md > base.size.button, "the override raises the control height"); + assert_eq!(follows.button, follows.control.md, "the button follows the control height"); + let own = applied(&json!({ "all": { "size.control.md": 40, "size.button": 30 } })); + assert!(own.button < own.control.md, "the app's own button height wins"); +} diff --git a/crates/theme/src/dump.rs b/crates/theme/src/dump.rs index 6d4f822b92..c818c44553 100644 --- a/crates/theme/src/dump.rs +++ b/crates/theme/src/dump.rs @@ -7,8 +7,8 @@ use std::fmt::Write as _; use crate::{ BarSizes, ColorToken, ControlSizes, DialogSizes, DockColumnSizes, Easing, Edge, Elevation, ElevationTokens, FloatSizes, FontSlot, Gaps, - GripShape, HandleSizes, HitSizes, IconSizes, Insets, KnobShape, LengthSizes, Motion, MotionTokens, Pads, PaneSizes, PlotSizes, RadiusSet, - RailSizes, RampSizes, Rgba, RowSizes, ShapeTokens, SizeTokens, SpaceTokens, StrokeTokens, ThumbSamples, ThumbSizes, Tokens, TypeStyle, + GripShape, HandleSizes, HitSizes, IconSizes, Insets, KnobShape, LengthSizes, Motion, MotionTokens, Pads, PageSizes, PaneSizes, PlotSizes, + RadiusSet, RailSizes, RampSizes, Rgba, RowSizes, ShapeTokens, SizeTokens, SpaceTokens, StrokeTokens, ThumbSamples, ThumbSizes, Tokens, TypeStyle, TypeTokens, WellShape, WindowSizes, }; @@ -66,7 +66,7 @@ fn edge(e: Edge) -> String { } fn shape_lines(out: &mut Lines, shape: &ShapeTokens) { - let ShapeTokens { radius, edge: e, knob, wells, grip } = shape; + let ShapeTokens { radius, edge: e, knob, wells, grip, locator } = shape; let RadiusSet { sm, control, surface, window, panel, button, pill } = radius; for (k, v) in [("sm", sm), ("control", control), ("surface", surface), ("window", window), ("panel", panel), ("button", button), ("pill", pill)] { out.line(&format!("shape.radius.{k}"), len(*v)); @@ -81,6 +81,8 @@ fn shape_lines(out: &mut Lines, shape: &ShapeTokens) { for (k, v) in [("length", length), ("width", width), ("gap", gap)] { out.line(&format!("shape.grip.{k}"), len(*v)); } + out.line("shape.locator.cell", len(locator.cell)); + out.line("shape.locator.square", len(locator.square)); } fn stroke_lines(out: &mut Lines, stroke: &StrokeTokens) { @@ -120,6 +122,7 @@ fn space_lines(out: &mut Lines, space: &SpaceTokens) { fn size_lines(out: &mut Lines, size: &SizeTokens) { let SizeTokens { control, + button, icon, rail, bar, @@ -140,10 +143,12 @@ fn size_lines(out: &mut Lines, size: &SizeTokens) { pane, dock, dialog, + page, } = size; let ControlSizes { sm, md } = control; out.line("size.control.sm", len(*sm)); out.line("size.control.md", len(*md)); + out.line("size.button", len(*button)); let IconSizes { sm, md, lg, glyph_sm, glyph_md } = icon; out.line("size.icon.sm", len(*sm)); out.line("size.icon.md", len(*md)); @@ -211,6 +216,10 @@ fn size_lines(out: &mut Lines, size: &SizeTokens) { out.line("size.dialog.wrap", len(*wrap)); out.line("size.dialog.button", len(*button)); out.line("size.dialog.side_button", len(*side_button)); + let PageSizes { column, margin, action } = page; + out.line("size.page.column", len(*column)); + out.line("size.page.margin", len(*margin)); + out.line("size.page.action", len(*action)); } fn slot(s: FontSlot) -> &'static str { diff --git a/crates/theme/src/edit.rs b/crates/theme/src/edit.rs index 179f4e036d..67536e8fd3 100644 --- a/crates/theme/src/edit.rs +++ b/crates/theme/src/edit.rs @@ -10,7 +10,7 @@ use crate::format::FormatErrors; use crate::id::{AppId, IconPackId}; use crate::ramp::Mode; use crate::theme::{ - AppOverrides, ContrastIntent, EdgeSeed, GripSeed, ModePins, Pins, RadiusOffset, SeedOverrides, Seeds, ShapeSeed, ThemeDef, Variants, + AppOverrides, ContrastIntent, EdgeSeed, GripSeed, LocatorSeed, ModePins, Pins, RadiusOffset, SeedOverrides, Seeds, ShapeSeed, ThemeDef, Variants, }; use crate::tokens::{ColorToken, KnobShape, RadiusSet, WellShape}; @@ -140,6 +140,8 @@ pub enum ShapeValue { Wells(Option), /// [`ShapeSeed::grip`]. Grip(Option), + /// [`ShapeSeed::locator`]. + Locator(Option), } /// Which field of the shape a [`ShapeValue`] holds. @@ -159,10 +161,12 @@ pub enum ShapeField { Wells, /// [`ShapeSeed::grip`]. Grip, + /// [`ShapeSeed::locator`]. + Locator, } impl ShapeField { - const ALL: [ShapeField; 7] = [ + const ALL: [ShapeField; 8] = [ ShapeField::Radius, ShapeField::RadiusOffset, ShapeField::ButtonRadius, @@ -170,6 +174,7 @@ impl ShapeField { ShapeField::Knob, ShapeField::Wells, ShapeField::Grip, + ShapeField::Locator, ]; fn get(self, s: &ShapeSeed) -> ShapeValue { @@ -181,6 +186,7 @@ impl ShapeField { ShapeField::Knob => ShapeValue::Knob(s.knob), ShapeField::Wells => ShapeValue::Wells(s.wells), ShapeField::Grip => ShapeValue::Grip(s.grip), + ShapeField::Locator => ShapeValue::Locator(s.locator), } } } @@ -195,6 +201,7 @@ impl ShapeValue { ShapeValue::Knob(_) => ShapeField::Knob, ShapeValue::Wells(_) => ShapeField::Wells, ShapeValue::Grip(_) => ShapeField::Grip, + ShapeValue::Locator(_) => ShapeField::Locator, } } @@ -207,11 +214,13 @@ impl ShapeValue { ShapeValue::Knob(v) => s.knob = v, ShapeValue::Wells(v) => s.wells = v, ShapeValue::Grip(v) => s.grip = v, + ShapeValue::Locator(v) => s.locator = v, } } } -const NO_SHAPE: ShapeSeed = ShapeSeed { radius: None, radius_offset: None, button_radius: None, edge: None, knob: None, wells: None, grip: None }; +const NO_SHAPE: ShapeSeed = + ShapeSeed { radius: None, radius_offset: None, button_radius: None, edge: None, knob: None, wells: None, grip: None, locator: None }; /// A theme's name, variants, contrast intent or icon pack. #[derive(Clone, Debug, PartialEq)] diff --git a/crates/theme/src/explain.rs b/crates/theme/src/explain.rs index 39e717cdeb..08675dc8eb 100644 --- a/crates/theme/src/explain.rs +++ b/crates/theme/src/explain.rs @@ -257,7 +257,7 @@ fn size_origins(resolved: &Resolved, size: Size, app: &AppSizes) -> Vec continue, }; // A theme's own corner radii win over the app's, so an override that did not take is the set's. - let set_by_app = merged.get(path).is_some_and(|o| !path.starts_with("radius.") || *o == value); + let set_by_app = AppSizes::override_of(&merged, path).is_some_and(|o| !path.starts_with("radius.") || *o == value); let layer = if set_by_app { SizeLayer::App } else { SizeLayer::SizeSet }; out.push(SizeOrigin { path: path.to_owned(), layer, value, range: (leaf.lo, leaf.hi) }); } diff --git a/crates/theme/src/format/mod.rs b/crates/theme/src/format/mod.rs index 59d490ba6a..729099f079 100644 --- a/crates/theme/src/format/mod.rs +++ b/crates/theme/src/format/mod.rs @@ -43,8 +43,8 @@ const KNOB: &str = "\"round\" or \"tab\""; const WELLS: &str = "\"square\" or \"round\""; /// What `shape.grip.mark` takes. const GRIP_MARK: &str = "\"ticks\", \"dots\" or \"bar\""; -/// What the numbers of `shape.grip` take. -const GRIP_NUMBER: &str = "a number"; +/// What the numbers of `shape.grip` and `shape.locator` take. +const SHAPE_NUMBER: &str = "a number"; /// What `icon_pack` takes. const ICON_PACK: &str = "an icon pack id: 2 to 64 of a-z, 0-9, '.', '_' or '-', starting with a-z or 0-9"; const EDGE: &str = "\"flat\" or {\"bevel\": {\"width\": n}} with n above 0"; diff --git a/crates/theme/src/format/parse.rs b/crates/theme/src/format/parse.rs index b9c37f05df..f0e6dde89a 100644 --- a/crates/theme/src/format/parse.rs +++ b/crates/theme/src/format/parse.rs @@ -5,13 +5,14 @@ use std::collections::BTreeMap; use serde_json::{Map, Value}; use super::{ - EDGE, ErrorKind, FormatError, FormatErrors, GRIP_MARK, GRIP_NUMBER, ICON_PACK, KNOB, LENGTH, MAX_THEME_BYTES, OFFSET, SCHEMA, SCHEMA_VERSION, + EDGE, ErrorKind, FormatError, FormatErrors, GRIP_MARK, ICON_PACK, KNOB, LENGTH, MAX_THEME_BYTES, OFFSET, SCHEMA, SCHEMA_VERSION, SHAPE_NUMBER, ThemeFile, WELLS, }; use crate::color::Rgba; use crate::scale::Radius; use crate::theme::{ - AppOverrides, ContrastIntent, EdgeSeed, GripSeed, ModePins, ModeSeeds, Pins, RadiusOffset, SeedOverrides, Seeds, ShapeSeed, ThemeDef, Variants, + AppOverrides, ContrastIntent, EdgeSeed, GripSeed, LocatorSeed, ModePins, ModeSeeds, Pins, RadiusOffset, SeedOverrides, Seeds, ShapeSeed, + ThemeDef, Variants, }; use crate::tokens::{ColorToken, GripMark, KnobShape, RadiusSet, Status, WellShape}; use crate::{AppId, IconPackId, ThemeId}; @@ -271,8 +272,13 @@ impl Parser { Some(g) => p.at("grip", |p| p.grip(g)).map(Some), None => Some(None), }; + let locator = match p.optional_object(shape, "locator") { + Some(l) => p.at("locator", |p| p.locator(l)).map(Some), + None => Some(None), + }; Some(Some(ShapeSeed { grip: grip?, + locator: locator?, radius: radius?, radius_offset: radius_offset?, button_radius: button_radius?, @@ -324,29 +330,38 @@ impl Parser { None } }); - let number = |p: &mut Self, key: &str, min: f32, max: f32, whole: bool| -> Option> { - p.at(key, |p| match g.get(key) { - None | Some(Value::Null) => Some(None), - Some(v) => match v.as_f64().filter(|x| x.is_finite() && (!whole || x.fract() == 0.0)) { - Some(x) if (f64::from(min)..=f64::from(max)).contains(&x) => Some(Some(x as f32)), - Some(_) => { - p.fail(ErrorKind::OutOfRange { min, max }); - None - } - None => { - p.fail(ErrorKind::BadValue { expected: GRIP_NUMBER }); - None - } - }, - }) - }; - let count = number(self, "count", 1.0, 32.0, true); - let length = number(self, "length", 0.5, 32.0, false); - let width = number(self, "width", 0.5, 8.0, false); - let gap = number(self, "gap", 0.5, 16.0, false); + let count = self.optional_number(g, "count", (1.0, 32.0), true); + let length = self.optional_number(g, "length", (0.5, 32.0), false); + let width = self.optional_number(g, "width", (0.5, 8.0), false); + let gap = self.optional_number(g, "gap", (0.5, 16.0), false); Some(GripSeed { mark: mark?, count: count?.map(|c| c as u16), length: length?, width: width?, gap: gap? }) } + /// `shape.locator`: the reference point's squares. Each value is optional. + fn locator(&mut self, l: &Map) -> Option { + let cell = self.optional_number(l, "cell", (1.0, 32.0), false); + let square = self.optional_number(l, "square", (1.0, 16.0), false); + Some(LocatorSeed { cell: cell?, square: square? }) + } + + /// The optional number at `key` of `map`, in `range` and, when `whole`, a whole number. + fn optional_number(&mut self, map: &Map, key: &str, (min, max): (f32, f32), whole: bool) -> Option> { + self.at(key, |p| match map.get(key) { + None | Some(Value::Null) => Some(None), + Some(v) => match v.as_f64().filter(|x| x.is_finite() && (!whole || x.fract() == 0.0)) { + Some(x) if (f64::from(min)..=f64::from(max)).contains(&x) => Some(Some(x as f32)), + Some(_) => { + p.fail(ErrorKind::OutOfRange { min, max }); + None + } + None => { + p.fail(ErrorKind::BadValue { expected: SHAPE_NUMBER }); + None + } + }, + }) + } + /// A signed length in logical pixels. fn offset(&mut self, v: &Value) -> Option { let out = v.as_f64().filter(|x| x.is_finite()).map(|x| x as f32); diff --git a/crates/theme/src/format/write.rs b/crates/theme/src/format/write.rs index 28376b1c43..1e5ffb5d60 100644 --- a/crates/theme/src/format/write.rs +++ b/crates/theme/src/format/write.rs @@ -4,7 +4,7 @@ use serde_json::{Map, Number, Value}; use super::{FormatErrors, SCHEMA, SCHEMA_VERSION, ThemeFile}; use crate::scale::Radius; -use crate::theme::{AppOverrides, ContrastIntent, EdgeSeed, GripSeed, ModePins, ModeSeeds, Pins, ShapeSeed, ThemeDef, Variants}; +use crate::theme::{AppOverrides, ContrastIntent, EdgeSeed, GripSeed, LocatorSeed, ModePins, ModeSeeds, Pins, ShapeSeed, ThemeDef, Variants}; use crate::tokens::{KnobShape, WellShape}; /// Top-level keys in the order a file lists them; other keys follow, sorted. @@ -167,6 +167,19 @@ fn update_shape(shape: &mut Map, s: &ShapeSeed) { shape.insert("grip".to_owned(), Value::Object(obj)); } } + match s.locator { + None => { + shape.remove("locator"); + } + Some(l) => { + let mut obj = match shape.remove("locator") { + Some(Value::Object(m)) => m, + _ => Map::new(), + }; + locator(&mut obj, &l); + shape.insert("locator".to_owned(), Value::Object(obj)); + } + } } /// Updates the `shape.grip` object `out` to the values the theme sets: a set value is written, an unset one removed. @@ -187,13 +200,23 @@ fn grip(out: &mut Map, g: &GripSeed) { out.remove("count"); } } - for (key, v) in [("length", g.length), ("width", g.width), ("gap", g.gap)] { + numbers(out, &[("length", g.length), ("width", g.width), ("gap", g.gap)]); +} + +/// Updates the `shape.locator` object `out` to the values the theme sets: a set value is written, an unset one removed. +fn locator(out: &mut Map, l: &LocatorSeed) { + numbers(out, &[("cell", l.cell), ("square", l.square)]); +} + +/// Writes each set number of `values` into `out` and removes each unset one. +fn numbers(out: &mut Map, values: &[(&str, Option)]) { + for (key, v) in values { match v.and_then(|v| Number::from_f64(f64::from(v))) { Some(n) => { - out.insert(key.to_owned(), Value::Number(n)); + out.insert((*key).to_owned(), Value::Number(n)); } None => { - out.remove(key); + out.remove(*key); } } } diff --git a/crates/theme/src/format_tests.rs b/crates/theme/src/format_tests.rs index 1ff301b8c0..283b3da34b 100644 --- a/crates/theme/src/format_tests.rs +++ b/crates/theme/src/format_tests.rs @@ -186,6 +186,32 @@ fn reference_cycles_are_errors() { assert_eq!(e.len(), 1, "{e:?}"); } +/// `shape.locator` sets the reference point's squares: left out, a value is the Size preset's handle size; set, the +/// tokens take it and the file writes it back; a value of the wrong kind or out of range is an error at its key. +#[test] +fn the_locator_shape_is_read_resolved_written_and_checked() { + let appearance = super::semantic_tests::app(Mode::Dark, Contrast::Standard); + let plain = crate::resolve(&parse_value(&full()).unwrap().theme, appearance, None).tokens; + let handle = plain.size.handle; + assert_eq!((plain.shape.locator.cell, plain.shape.locator.square), (handle.md, handle.sm), "no locator: the preset's handles"); + + let mut v = full(); + v["shape"]["locator"] = json!({ "square": 5 }); + let file = parse_value(&v).unwrap(); + let locator = crate::resolve(&file.theme, appearance, None).tokens.shape.locator; + assert_eq!((locator.cell, locator.square), (handle.md, 5.0), "a set value over the preset's"); + let written: Value = serde_json::from_str(&format::write(&file).unwrap()).unwrap(); + assert_eq!(written.pointer("/shape/locator/square"), Some(&json!(5.0))); + assert_eq!(written.pointer("/shape/locator/cell"), None, "an unset value is not written"); + + for (key, bad) in [("cell", json!(0)), ("cell", json!(33)), ("square", json!("small")), ("square", json!(17))] { + let mut v = full(); + v["shape"]["locator"] = json!({ key: bad }); + let found = errors(&v); + assert!(found.iter().any(|e| e.contains(&format!("shape.locator.{key}"))), "{key} = {bad}: {found:?}"); + } +} + /// photocraft#16426: `shape.grip` sets the dock grips' marks. Each value is optional and keeps the default's when /// left out; the theme's tokens take them, the file writes them back, and a value of the wrong kind or out of range /// is an error at its key. diff --git a/crates/theme/src/lib.rs b/crates/theme/src/lib.rs index c1a9de2fdd..28e950415e 100644 --- a/crates/theme/src/lib.rs +++ b/crates/theme/src/lib.rs @@ -91,16 +91,16 @@ pub use selection::{ }; pub use stateful::{FlagMask, Flags, Mix, Resolve, StateMix, Stateful}; pub use theme::{ - AppOverrides, Appearance, Contrast, ContrastIntent, EdgeSeed, GripSeed, InterfaceFont, ModePins, ModeSeeds, PinLayer, Pins, RadiusOffset, - SeedOverrides, Seeds, ShapeSeed, Size, TextSize, TextSizeSteps, ThemeDef, Variants, + AppOverrides, Appearance, Contrast, ContrastIntent, EdgeSeed, GripSeed, InterfaceFont, LocatorSeed, ModePins, ModeSeeds, PinLayer, Pins, + RadiusOffset, SeedOverrides, Seeds, ShapeSeed, Size, TextSize, TextSizeSteps, ThemeDef, Variants, }; pub use token_group::{GroupValues, TokenGroup}; pub use tokens::{ AccentColors, BarSizes, CaptionColors, ColorToken, ColorTokens, ControlSizes, DataColors, DialogSizes, DockColumnSizes, Edge, EdgeColors, ElevationTokens, FloatSizes, FontSlot, Gaps, GripMark, GripShape, HandleSizes, HitSizes, IconSizes, Insets, KnobShape, LengthSizes, LetterCase, - LineColors, Motion, MotionTokens, OverlayColors, Pads, PaneSizes, PlotSizes, RadiusSet, RailSizes, RampSizes, RowSizes, ShapeTokens, SizeTokens, - SpaceTokens, StateColors, Status, StatusColors, StatusKind, StrokeTokens, SurfaceColors, TextColors, ThumbSamples, ThumbSizes, Tokens, TypeRole, - TypeStyle, TypeTokens, WellShape, WindowSizes, + LineColors, LocatorShape, Motion, MotionTokens, OverlayColors, Pads, PageSizes, PaneSizes, PlotSizes, RadiusSet, RailSizes, RampSizes, RowSizes, + ShapeTokens, SizeTokens, SpaceTokens, StateColors, Status, StatusColors, StatusKind, StrokeTokens, SurfaceColors, TextColors, ThumbSamples, + ThumbSizes, Tokens, TypeRole, TypeStyle, TypeTokens, WellShape, WindowSizes, }; pub use values::ColorSource; pub use variant::{CustomVariant, Emphasis, RadiusStep, Variant, VariantLook}; diff --git a/crates/theme/src/resolve.rs b/crates/theme/src/resolve.rs index d594b5c9dc..eb4f684281 100644 --- a/crates/theme/src/resolve.rs +++ b/crates/theme/src/resolve.rs @@ -6,7 +6,7 @@ use super::ramp::Mode; use super::scale::{Easing, Elevation}; use super::sizes; use super::theme::{Appearance, Contrast, ContrastIntent, PinLayer, Pins, ThemeDef}; -use super::tokens::{ColorToken, Edge, ElevationTokens, GripShape, Motion, MotionTokens, RadiusSet, ShapeTokens, SizeTokens, Tokens}; +use super::tokens::{ColorToken, Edge, ElevationTokens, GripShape, LocatorShape, Motion, MotionTokens, RadiusSet, ShapeTokens, SizeTokens, Tokens}; use super::values; use crate::AppId; @@ -207,6 +207,10 @@ fn resolve_concrete(theme: &ThemeDef, appearance: Appearance, app: Option<&AppId knob: seed.and_then(|s| s.knob).unwrap_or_default(), wells: seed.and_then(|s| s.wells).unwrap_or_default(), grip: seed.and_then(|s| s.grip).map_or(GripShape::DEFAULT, |g| g.shape()), + locator: { + let own = seed.and_then(|s| s.locator).unwrap_or_default(); + LocatorShape { cell: own.cell.unwrap_or(preset.size.handle.md), square: own.square.unwrap_or(preset.size.handle.sm) } + }, }; let text_factor = sizes.text_steps.factor(appearance.text_size); let typography = preset.typography.scaled(text_factor, values::TYPE_ROUNDING); diff --git a/crates/theme/src/sizes.rs b/crates/theme/src/sizes.rs index 6101f7a76b..1c4e81cbd2 100644 --- a/crates/theme/src/sizes.rs +++ b/crates/theme/src/sizes.rs @@ -93,6 +93,7 @@ pub(crate) fn leaves(b: &mut Preset) -> Vec> { leaves! { out; "base.size.control.sm" Num 16.0..=48.0 => s.control.sm; "base.size.control.md" Num 16.0..=48.0 => s.control.md; + "base.size.button" Num 16.0..=48.0 => s.button; "base.size.icon.sm" Num 10.0..=32.0 => s.icon.sm; "base.size.icon.md" Num 10.0..=32.0 => s.icon.md; "base.size.icon.lg" Num 10.0..=32.0 => s.icon.lg; @@ -145,6 +146,9 @@ pub(crate) fn leaves(b: &mut Preset) -> Vec> { "base.size.dialog.wrap" Num 120.0..=1024.0 => s.dialog.wrap; "base.size.dialog.button" Num 24.0..=240.0 => s.dialog.button; "base.size.dialog.side_button" Num 24.0..=240.0 => s.dialog.side_button; + "base.size.page.column" Num 240.0..=2048.0 => s.page.column; + "base.size.page.margin" Num 0.0..=240.0 => s.page.margin; + "base.size.page.action" Num 16.0..=96.0 => s.page.action; } let sp = &mut b.space; leaves! { out; diff --git a/crates/theme/src/theme.rs b/crates/theme/src/theme.rs index 8c92466def..36235decfe 100644 --- a/crates/theme/src/theme.rs +++ b/crates/theme/src/theme.rs @@ -242,6 +242,18 @@ pub struct ShapeSeed { pub wells: Option, /// The dock grips' marks; each value left unset keeps [`GripShape::DEFAULT`]'s. pub grip: Option, + /// The reference point's squares; each value left unset is the Size preset's handle size. + pub locator: Option, +} + +/// A theme's reference point squares ([`LocatorShape`](crate::LocatorShape)): each `None` takes the Size preset's value, `size.handle.md` +/// for the step and `size.handle.sm` for the square. +#[derive(Clone, Copy, Debug, Default, PartialEq)] +pub struct LocatorSeed { + /// The step from one square's centre to the next, in points. + pub cell: Option, + /// A square's side, in points. + pub square: Option, } /// A theme's grip marks: each `None` keeps [`GripShape::DEFAULT`]'s value. diff --git a/crates/theme/src/tokens/color.rs b/crates/theme/src/tokens/color.rs index 35e7a7916d..601d964651 100644 --- a/crates/theme/src/tokens/color.rs +++ b/crates/theme/src/tokens/color.rs @@ -55,6 +55,8 @@ pub struct SurfaceColors { /// The dots or grid an app may draw on the canvas outside the document. Equal to `canvas` (no /// pattern) unless the theme sets it. pub canvas_pattern: Rgba, + /// A full-window page with no document open (a start page); follows `canvas` unless pinned. + pub page: Rgba, /// Panels, bars and rails. pub panel: Rgba, /// Window chrome: title bars, toolbars, option bars, rulers and scrollbar tracks; follows @@ -322,6 +324,7 @@ impl ColorTokens { background: c, canvas: c, canvas_pattern: c, + page: c, panel: c, chrome: c, raised: c, @@ -436,6 +439,8 @@ color_tokens! { SurfaceCanvas = "surface.canvas" => surface.canvas; /// `surface.canvas_pattern` SurfaceCanvasPattern = "surface.canvas_pattern" => surface.canvas_pattern; + /// `surface.page` + SurfacePage = "surface.page" => surface.page; /// `surface.panel` SurfacePanel = "surface.panel" => surface.panel; /// `surface.chrome` @@ -657,14 +662,15 @@ impl ColorToken { /// (`surface.*` except `scrim` and `shadow`); those must be opaque. pub const fn is_opaque_surface(self) -> bool { use ColorToken::{ - SurfaceBackground, SurfaceCanvas, SurfaceCanvasPattern, SurfaceChrome, SurfaceInverse, SurfaceKnob, SurfacePanel, SurfaceRaised, - SurfaceSunken, + SurfaceBackground, SurfaceCanvas, SurfaceCanvasPattern, SurfaceChrome, SurfaceInverse, SurfaceKnob, SurfacePage, SurfacePanel, + SurfaceRaised, SurfaceSunken, }; matches!( self, SurfaceBackground | SurfaceCanvas | SurfaceCanvasPattern + | SurfacePage | SurfaceChrome | SurfacePanel | SurfaceRaised diff --git a/crates/theme/src/tokens/size.rs b/crates/theme/src/tokens/size.rs index 9daaee0f88..e4e27432c1 100644 --- a/crates/theme/src/tokens/size.rs +++ b/crates/theme/src/tokens/size.rs @@ -123,7 +123,17 @@ impl Default for GripShape { } } -/// Corner radii, edge style, knob shape, well shape and grip marks. +/// The squares of a reference point picker's square look: the step from one square's centre to the next and a +/// square's side, in points. The picker is two steps and a square wide. +#[derive(Clone, Copy, Debug, Default, PartialEq)] +pub struct LocatorShape { + /// The step from one square's centre to the next. + pub cell: f32, + /// A square's side. + pub square: f32, +} + +/// Corner radii, edge style, knob shape, well shape, grip marks and the reference point's squares. #[derive(Clone, Copy, Debug, PartialEq)] pub struct ShapeTokens { /// Corner radii. @@ -136,6 +146,8 @@ pub struct ShapeTokens { pub wells: WellShape, /// The marks of the dock grips. pub grip: GripShape, + /// The squares of a reference point picker's square look. + pub locator: LocatorShape, } /// Gaps between neighbouring elements, in logical pixels. @@ -254,6 +266,9 @@ pub struct BarSizes { pub struct SizeTokens { /// Control heights. pub control: ControlSizes, + /// The height of a standard push button, a text button's face (a small one stands `control.sm` high). An app that + /// sets `size.control.md` and not this keeps its buttons a control high. + pub button: f32, /// Icon sizes. pub icon: IconSizes, /// Tool rail. @@ -295,6 +310,19 @@ pub struct SizeTokens { pub dock: DockColumnSizes, /// Dialogs: their content width and their buttons. pub dialog: DialogSizes, + /// Full-window pages. + pub page: PageSizes, +} + +/// The sizes of a full-window page (a start page), in logical pixels. +#[derive(Clone, Copy, Debug, Default, PartialEq)] +pub struct PageSizes { + /// The widest a page's centred column of content grows; a narrower room keeps the page's margin at each side. + pub column: f32, + /// The room above and below a page's centred column. + pub margin: f32, + /// The height of a page's call to action (`ControlPlace::CallToAction`). + pub action: f32, } /// The sizes of the panes of a dock's split, in logical pixels. diff --git a/crates/theme/src/values.rs b/crates/theme/src/values.rs index f99b78b45f..dc77ea1382 100644 --- a/crates/theme/src/values.rs +++ b/crates/theme/src/values.rs @@ -197,6 +197,7 @@ pub(super) fn source(token: ColorToken, mode: Mode) -> ColorSource { T::SurfaceBackground => Anchored(pick(2, 3)), T::SurfaceCanvas => Same(T::SurfaceBackground), T::SurfaceCanvasPattern => Same(T::SurfaceCanvas), + T::SurfacePage => Same(T::SurfaceCanvas), T::SurfacePanel => Neutral(panel_step(mode)), T::SurfaceChrome => Same(T::SurfacePanel), T::SurfaceRaised => Anchored(pick(4, 1)), diff --git a/crates/theme/tests/dumps/tokens/adwaita-dark-high-comfortable.txt b/crates/theme/tests/dumps/tokens/adwaita-dark-high-comfortable.txt index 28bb4e5401..97214109f0 100644 --- a/crates/theme/tests/dumps/tokens/adwaita-dark-high-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/adwaita-dark-high-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #222226ff surface.canvas = #1d1d20ff surface.canvas_pattern = #1d1d20ff +surface.page = #1d1d20ff surface.panel = #36363aff surface.chrome = #2e2e32ff surface.raised = #404044ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/adwaita-dark-high-compact.txt b/crates/theme/tests/dumps/tokens/adwaita-dark-high-compact.txt index 049f56f19c..3d8e2e80e0 100644 --- a/crates/theme/tests/dumps/tokens/adwaita-dark-high-compact.txt +++ b/crates/theme/tests/dumps/tokens/adwaita-dark-high-compact.txt @@ -2,6 +2,7 @@ surface.background = #222226ff surface.canvas = #1d1d20ff surface.canvas_pattern = #1d1d20ff +surface.page = #1d1d20ff surface.panel = #36363aff surface.chrome = #2e2e32ff surface.raised = #404044ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/adwaita-dark-standard-comfortable.txt b/crates/theme/tests/dumps/tokens/adwaita-dark-standard-comfortable.txt index 46ae206f3e..527db8c474 100644 --- a/crates/theme/tests/dumps/tokens/adwaita-dark-standard-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/adwaita-dark-standard-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #222226ff surface.canvas = #1d1d20ff surface.canvas_pattern = #1d1d20ff +surface.page = #1d1d20ff surface.panel = #36363aff surface.chrome = #2e2e32ff surface.raised = #39393eff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/adwaita-dark-standard-compact.txt b/crates/theme/tests/dumps/tokens/adwaita-dark-standard-compact.txt index cf3838c0da..166ac8320c 100644 --- a/crates/theme/tests/dumps/tokens/adwaita-dark-standard-compact.txt +++ b/crates/theme/tests/dumps/tokens/adwaita-dark-standard-compact.txt @@ -2,6 +2,7 @@ surface.background = #222226ff surface.canvas = #1d1d20ff surface.canvas_pattern = #1d1d20ff +surface.page = #1d1d20ff surface.panel = #36363aff surface.chrome = #2e2e32ff surface.raised = #39393eff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/adwaita-light-high-comfortable.txt b/crates/theme/tests/dumps/tokens/adwaita-light-high-comfortable.txt index 1bfc924395..0e9374c074 100644 --- a/crates/theme/tests/dumps/tokens/adwaita-light-high-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/adwaita-light-high-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #ebebedff surface.canvas = #dededfff surface.canvas_pattern = #dededfff +surface.page = #dededfff surface.panel = #ffffffff surface.chrome = #ffffffff surface.raised = #ffffffff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/adwaita-light-high-compact.txt b/crates/theme/tests/dumps/tokens/adwaita-light-high-compact.txt index 829789b5bf..7ffd6bff25 100644 --- a/crates/theme/tests/dumps/tokens/adwaita-light-high-compact.txt +++ b/crates/theme/tests/dumps/tokens/adwaita-light-high-compact.txt @@ -2,6 +2,7 @@ surface.background = #ebebedff surface.canvas = #dededfff surface.canvas_pattern = #dededfff +surface.page = #dededfff surface.panel = #ffffffff surface.chrome = #ffffffff surface.raised = #ffffffff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/adwaita-light-standard-comfortable.txt b/crates/theme/tests/dumps/tokens/adwaita-light-standard-comfortable.txt index 8becd841b2..a128232f33 100644 --- a/crates/theme/tests/dumps/tokens/adwaita-light-standard-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/adwaita-light-standard-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #ebebedff surface.canvas = #dededfff surface.canvas_pattern = #dededfff +surface.page = #dededfff surface.panel = #ffffffff surface.chrome = #ffffffff surface.raised = #ffffffff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/adwaita-light-standard-compact.txt b/crates/theme/tests/dumps/tokens/adwaita-light-standard-compact.txt index 3be11340e7..b1c506ef28 100644 --- a/crates/theme/tests/dumps/tokens/adwaita-light-standard-compact.txt +++ b/crates/theme/tests/dumps/tokens/adwaita-light-standard-compact.txt @@ -2,6 +2,7 @@ surface.background = #ebebedff surface.canvas = #dededfff surface.canvas_pattern = #dededfff +surface.page = #dededfff surface.panel = #ffffffff surface.chrome = #ffffffff surface.raised = #ffffffff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/artcraft-dark-high-comfortable.txt b/crates/theme/tests/dumps/tokens/artcraft-dark-high-comfortable.txt index 032d4a3230..8905789e4d 100644 --- a/crates/theme/tests/dumps/tokens/artcraft-dark-high-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/artcraft-dark-high-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #424242ff surface.canvas = #282828ff surface.canvas_pattern = #282828ff +surface.page = #282828ff surface.panel = #535353ff surface.chrome = #535353ff surface.raised = #595959ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/artcraft-dark-high-compact.txt b/crates/theme/tests/dumps/tokens/artcraft-dark-high-compact.txt index d13f08ba9d..48674bae19 100644 --- a/crates/theme/tests/dumps/tokens/artcraft-dark-high-compact.txt +++ b/crates/theme/tests/dumps/tokens/artcraft-dark-high-compact.txt @@ -2,6 +2,7 @@ surface.background = #424242ff surface.canvas = #282828ff surface.canvas_pattern = #282828ff +surface.page = #282828ff surface.panel = #535353ff surface.chrome = #535353ff surface.raised = #595959ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/artcraft-dark-standard-comfortable.txt b/crates/theme/tests/dumps/tokens/artcraft-dark-standard-comfortable.txt index a9ad075e49..65b00fd8f5 100644 --- a/crates/theme/tests/dumps/tokens/artcraft-dark-standard-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/artcraft-dark-standard-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #424242ff surface.canvas = #282828ff surface.canvas_pattern = #282828ff +surface.page = #282828ff surface.panel = #535353ff surface.chrome = #535353ff surface.raised = #5c5c5cff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/artcraft-dark-standard-compact.txt b/crates/theme/tests/dumps/tokens/artcraft-dark-standard-compact.txt index c3197b3d9f..d0c756bbec 100644 --- a/crates/theme/tests/dumps/tokens/artcraft-dark-standard-compact.txt +++ b/crates/theme/tests/dumps/tokens/artcraft-dark-standard-compact.txt @@ -2,6 +2,7 @@ surface.background = #424242ff surface.canvas = #282828ff surface.canvas_pattern = #282828ff +surface.page = #282828ff surface.panel = #535353ff surface.chrome = #535353ff surface.raised = #5c5c5cff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/artcraft-light-high-comfortable.txt b/crates/theme/tests/dumps/tokens/artcraft-light-high-comfortable.txt index b18e615c97..bbf7652198 100644 --- a/crates/theme/tests/dumps/tokens/artcraft-light-high-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/artcraft-light-high-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #e2e2e2ff surface.canvas = #d6d6d6ff surface.canvas_pattern = #d6d6d6ff +surface.page = #d6d6d6ff surface.panel = #f0f0f0ff surface.chrome = #f0f0f0ff surface.raised = #f6f6f6ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/artcraft-light-high-compact.txt b/crates/theme/tests/dumps/tokens/artcraft-light-high-compact.txt index 7c1bdafc65..e9b5c2a339 100644 --- a/crates/theme/tests/dumps/tokens/artcraft-light-high-compact.txt +++ b/crates/theme/tests/dumps/tokens/artcraft-light-high-compact.txt @@ -2,6 +2,7 @@ surface.background = #e2e2e2ff surface.canvas = #d6d6d6ff surface.canvas_pattern = #d6d6d6ff +surface.page = #d6d6d6ff surface.panel = #f0f0f0ff surface.chrome = #f0f0f0ff surface.raised = #f6f6f6ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/artcraft-light-standard-comfortable.txt b/crates/theme/tests/dumps/tokens/artcraft-light-standard-comfortable.txt index c04d76f9d1..fae2a7f079 100644 --- a/crates/theme/tests/dumps/tokens/artcraft-light-standard-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/artcraft-light-standard-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #e2e2e2ff surface.canvas = #d6d6d6ff surface.canvas_pattern = #d6d6d6ff +surface.page = #d6d6d6ff surface.panel = #f0f0f0ff surface.chrome = #f0f0f0ff surface.raised = #f6f6f6ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/artcraft-light-standard-compact.txt b/crates/theme/tests/dumps/tokens/artcraft-light-standard-compact.txt index f7448bea32..311f1caca8 100644 --- a/crates/theme/tests/dumps/tokens/artcraft-light-standard-compact.txt +++ b/crates/theme/tests/dumps/tokens/artcraft-light-standard-compact.txt @@ -2,6 +2,7 @@ surface.background = #e2e2e2ff surface.canvas = #d6d6d6ff surface.canvas_pattern = #d6d6d6ff +surface.page = #d6d6d6ff surface.panel = #f0f0f0ff surface.chrome = #f0f0f0ff surface.raised = #f6f6f6ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/breeze-dark-high-comfortable.txt b/crates/theme/tests/dumps/tokens/breeze-dark-high-comfortable.txt index 6f2fb58490..f78a73a717 100644 --- a/crates/theme/tests/dumps/tokens/breeze-dark-high-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/breeze-dark-high-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #1a1d22ff surface.canvas = #111418ff surface.canvas_pattern = #111418ff +surface.page = #111418ff surface.panel = #1d2126ff surface.chrome = #262a30ff surface.raised = #272b30ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/breeze-dark-high-compact.txt b/crates/theme/tests/dumps/tokens/breeze-dark-high-compact.txt index f7033fe8fa..4a3a71bfbb 100644 --- a/crates/theme/tests/dumps/tokens/breeze-dark-high-compact.txt +++ b/crates/theme/tests/dumps/tokens/breeze-dark-high-compact.txt @@ -2,6 +2,7 @@ surface.background = #1a1d22ff surface.canvas = #111418ff surface.canvas_pattern = #111418ff +surface.page = #111418ff surface.panel = #1d2126ff surface.chrome = #262a30ff surface.raised = #272b30ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/breeze-dark-standard-comfortable.txt b/crates/theme/tests/dumps/tokens/breeze-dark-standard-comfortable.txt index 8dfdb66731..2778cbf09d 100644 --- a/crates/theme/tests/dumps/tokens/breeze-dark-standard-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/breeze-dark-standard-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #1a1d22ff surface.canvas = #111418ff surface.canvas_pattern = #111418ff +surface.page = #111418ff surface.panel = #1d2126ff surface.chrome = #262a30ff surface.raised = #272b30ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/breeze-dark-standard-compact.txt b/crates/theme/tests/dumps/tokens/breeze-dark-standard-compact.txt index 4959b6cc60..d1055c5693 100644 --- a/crates/theme/tests/dumps/tokens/breeze-dark-standard-compact.txt +++ b/crates/theme/tests/dumps/tokens/breeze-dark-standard-compact.txt @@ -2,6 +2,7 @@ surface.background = #1a1d22ff surface.canvas = #111418ff surface.canvas_pattern = #111418ff +surface.page = #111418ff surface.panel = #1d2126ff surface.chrome = #262a30ff surface.raised = #272b30ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/breeze-light-high-comfortable.txt b/crates/theme/tests/dumps/tokens/breeze-light-high-comfortable.txt index a7a3b4adf6..0a34ade73b 100644 --- a/crates/theme/tests/dumps/tokens/breeze-light-high-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/breeze-light-high-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #e0e3e7ff surface.canvas = #dbdee2ff surface.canvas_pattern = #dbdee2ff +surface.page = #dbdee2ff surface.panel = #eceef1ff surface.chrome = #dbdee2ff surface.raised = #f2f4f7ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/breeze-light-high-compact.txt b/crates/theme/tests/dumps/tokens/breeze-light-high-compact.txt index ca17d13ecc..63932a93e8 100644 --- a/crates/theme/tests/dumps/tokens/breeze-light-high-compact.txt +++ b/crates/theme/tests/dumps/tokens/breeze-light-high-compact.txt @@ -2,6 +2,7 @@ surface.background = #e0e3e7ff surface.canvas = #dbdee2ff surface.canvas_pattern = #dbdee2ff +surface.page = #dbdee2ff surface.panel = #eceef1ff surface.chrome = #dbdee2ff surface.raised = #f2f4f7ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/breeze-light-standard-comfortable.txt b/crates/theme/tests/dumps/tokens/breeze-light-standard-comfortable.txt index cddf7cf0d7..5df6f0ec52 100644 --- a/crates/theme/tests/dumps/tokens/breeze-light-standard-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/breeze-light-standard-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #e0e3e7ff surface.canvas = #dbdee2ff surface.canvas_pattern = #dbdee2ff +surface.page = #dbdee2ff surface.panel = #eceef1ff surface.chrome = #dbdee2ff surface.raised = #f2f4f7ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/breeze-light-standard-compact.txt b/crates/theme/tests/dumps/tokens/breeze-light-standard-compact.txt index 134343b10a..b586bf86cf 100644 --- a/crates/theme/tests/dumps/tokens/breeze-light-standard-compact.txt +++ b/crates/theme/tests/dumps/tokens/breeze-light-standard-compact.txt @@ -2,6 +2,7 @@ surface.background = #e0e3e7ff surface.canvas = #dbdee2ff surface.canvas_pattern = #dbdee2ff +surface.page = #dbdee2ff surface.panel = #eceef1ff surface.chrome = #dbdee2ff surface.raised = #f2f4f7ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/classic-light-high-comfortable.txt b/crates/theme/tests/dumps/tokens/classic-light-high-comfortable.txt index 4989b3eaf0..4d9b5acf95 100644 --- a/crates/theme/tests/dumps/tokens/classic-light-high-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/classic-light-high-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #d4d0c8ff surface.canvas = #808080ff surface.canvas_pattern = #808080ff +surface.page = #808080ff surface.panel = #d4d0c8ff surface.chrome = #d4d0c8ff surface.raised = #d4d0c8ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/classic-light-high-compact.txt b/crates/theme/tests/dumps/tokens/classic-light-high-compact.txt index 68563809d0..d7fa038740 100644 --- a/crates/theme/tests/dumps/tokens/classic-light-high-compact.txt +++ b/crates/theme/tests/dumps/tokens/classic-light-high-compact.txt @@ -2,6 +2,7 @@ surface.background = #d4d0c8ff surface.canvas = #808080ff surface.canvas_pattern = #808080ff +surface.page = #808080ff surface.panel = #d4d0c8ff surface.chrome = #d4d0c8ff surface.raised = #d4d0c8ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/classic-light-standard-comfortable.txt b/crates/theme/tests/dumps/tokens/classic-light-standard-comfortable.txt index b52c28cad2..cac48b4d49 100644 --- a/crates/theme/tests/dumps/tokens/classic-light-standard-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/classic-light-standard-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #d4d0c8ff surface.canvas = #808080ff surface.canvas_pattern = #808080ff +surface.page = #808080ff surface.panel = #d4d0c8ff surface.chrome = #d4d0c8ff surface.raised = #d4d0c8ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/classic-light-standard-compact.txt b/crates/theme/tests/dumps/tokens/classic-light-standard-compact.txt index e9b370a382..85abdaa3dc 100644 --- a/crates/theme/tests/dumps/tokens/classic-light-standard-compact.txt +++ b/crates/theme/tests/dumps/tokens/classic-light-standard-compact.txt @@ -2,6 +2,7 @@ surface.background = #d4d0c8ff surface.canvas = #808080ff surface.canvas_pattern = #808080ff +surface.page = #808080ff surface.panel = #d4d0c8ff surface.chrome = #d4d0c8ff surface.raised = #d4d0c8ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/graphite-dark-high-comfortable.txt b/crates/theme/tests/dumps/tokens/graphite-dark-high-comfortable.txt index b94b40adb8..30e9dd81c3 100644 --- a/crates/theme/tests/dumps/tokens/graphite-dark-high-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/graphite-dark-high-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #19191cff surface.canvas = #19191cff surface.canvas_pattern = #19191cff +surface.page = #19191cff surface.panel = #26262aff surface.chrome = #26262aff surface.raised = #2e2e33ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/graphite-dark-high-compact.txt b/crates/theme/tests/dumps/tokens/graphite-dark-high-compact.txt index 16a7e2e94e..c7837bdaa7 100644 --- a/crates/theme/tests/dumps/tokens/graphite-dark-high-compact.txt +++ b/crates/theme/tests/dumps/tokens/graphite-dark-high-compact.txt @@ -2,6 +2,7 @@ surface.background = #19191cff surface.canvas = #19191cff surface.canvas_pattern = #19191cff +surface.page = #19191cff surface.panel = #26262aff surface.chrome = #26262aff surface.raised = #2e2e33ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/graphite-dark-standard-comfortable.txt b/crates/theme/tests/dumps/tokens/graphite-dark-standard-comfortable.txt index 5223539c48..3a0c7efcdd 100644 --- a/crates/theme/tests/dumps/tokens/graphite-dark-standard-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/graphite-dark-standard-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #19191cff surface.canvas = #19191cff surface.canvas_pattern = #19191cff +surface.page = #19191cff surface.panel = #26262aff surface.chrome = #26262aff surface.raised = #2e2e33ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/graphite-dark-standard-compact.txt b/crates/theme/tests/dumps/tokens/graphite-dark-standard-compact.txt index bf757ef21e..f2002683b4 100644 --- a/crates/theme/tests/dumps/tokens/graphite-dark-standard-compact.txt +++ b/crates/theme/tests/dumps/tokens/graphite-dark-standard-compact.txt @@ -2,6 +2,7 @@ surface.background = #19191cff surface.canvas = #19191cff surface.canvas_pattern = #19191cff +surface.page = #19191cff surface.panel = #26262aff surface.chrome = #26262aff surface.raised = #2e2e33ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/graphite-light-high-comfortable.txt b/crates/theme/tests/dumps/tokens/graphite-light-high-comfortable.txt index feea7e8c09..257b6467b1 100644 --- a/crates/theme/tests/dumps/tokens/graphite-light-high-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/graphite-light-high-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #f1f1f3ff surface.canvas = #f1f1f3ff surface.canvas_pattern = #f1f1f3ff +surface.page = #f1f1f3ff surface.panel = #ffffffff surface.chrome = #ffffffff surface.raised = #ffffffff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/graphite-light-high-compact.txt b/crates/theme/tests/dumps/tokens/graphite-light-high-compact.txt index ac715e1054..148b62371e 100644 --- a/crates/theme/tests/dumps/tokens/graphite-light-high-compact.txt +++ b/crates/theme/tests/dumps/tokens/graphite-light-high-compact.txt @@ -2,6 +2,7 @@ surface.background = #f1f1f3ff surface.canvas = #f1f1f3ff surface.canvas_pattern = #f1f1f3ff +surface.page = #f1f1f3ff surface.panel = #ffffffff surface.chrome = #ffffffff surface.raised = #ffffffff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/graphite-light-standard-comfortable.txt b/crates/theme/tests/dumps/tokens/graphite-light-standard-comfortable.txt index 109721a5c8..c7399d4424 100644 --- a/crates/theme/tests/dumps/tokens/graphite-light-standard-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/graphite-light-standard-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #f1f1f3ff surface.canvas = #f1f1f3ff surface.canvas_pattern = #f1f1f3ff +surface.page = #f1f1f3ff surface.panel = #ffffffff surface.chrome = #ffffffff surface.raised = #ffffffff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/graphite-light-standard-compact.txt b/crates/theme/tests/dumps/tokens/graphite-light-standard-compact.txt index 546ddb2ce0..bd569c4d0d 100644 --- a/crates/theme/tests/dumps/tokens/graphite-light-standard-compact.txt +++ b/crates/theme/tests/dumps/tokens/graphite-light-standard-compact.txt @@ -2,6 +2,7 @@ surface.background = #f1f1f3ff surface.canvas = #f1f1f3ff surface.canvas_pattern = #f1f1f3ff +surface.page = #f1f1f3ff surface.panel = #ffffffff surface.chrome = #ffffffff surface.raised = #ffffffff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/pro-dark-high-comfortable.txt b/crates/theme/tests/dumps/tokens/pro-dark-high-comfortable.txt index e6d3fca3b1..bb87961d24 100644 --- a/crates/theme/tests/dumps/tokens/pro-dark-high-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/pro-dark-high-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #1e1e1eff surface.canvas = #282828ff surface.canvas_pattern = #282828ff +surface.page = #282828ff surface.panel = #323232ff surface.chrome = #323232ff surface.raised = #3c3c3cff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/pro-dark-high-compact.txt b/crates/theme/tests/dumps/tokens/pro-dark-high-compact.txt index 20995a4ed6..e3f0477dfc 100644 --- a/crates/theme/tests/dumps/tokens/pro-dark-high-compact.txt +++ b/crates/theme/tests/dumps/tokens/pro-dark-high-compact.txt @@ -2,6 +2,7 @@ surface.background = #1e1e1eff surface.canvas = #282828ff surface.canvas_pattern = #282828ff +surface.page = #282828ff surface.panel = #323232ff surface.chrome = #323232ff surface.raised = #3c3c3cff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/pro-dark-standard-comfortable-app-sizes.txt b/crates/theme/tests/dumps/tokens/pro-dark-standard-comfortable-app-sizes.txt index 41ef2b8fb8..e2baacfe8a 100644 --- a/crates/theme/tests/dumps/tokens/pro-dark-standard-comfortable-app-sizes.txt +++ b/crates/theme/tests/dumps/tokens/pro-dark-standard-comfortable-app-sizes.txt @@ -2,6 +2,7 @@ surface.background = #1e1e1eff surface.canvas = #282828ff surface.canvas_pattern = #282828ff +surface.page = #282828ff surface.panel = #323232ff surface.chrome = #323232ff surface.raised = #3c3c3cff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 28 +size.button = 28 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/pro-dark-standard-comfortable.txt b/crates/theme/tests/dumps/tokens/pro-dark-standard-comfortable.txt index 1cfb24ce16..bdbe993eac 100644 --- a/crates/theme/tests/dumps/tokens/pro-dark-standard-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/pro-dark-standard-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #1e1e1eff surface.canvas = #282828ff surface.canvas_pattern = #282828ff +surface.page = #282828ff surface.panel = #323232ff surface.chrome = #323232ff surface.raised = #3c3c3cff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/pro-dark-standard-compact.txt b/crates/theme/tests/dumps/tokens/pro-dark-standard-compact.txt index 0613337f34..29caba27ef 100644 --- a/crates/theme/tests/dumps/tokens/pro-dark-standard-compact.txt +++ b/crates/theme/tests/dumps/tokens/pro-dark-standard-compact.txt @@ -2,6 +2,7 @@ surface.background = #1e1e1eff surface.canvas = #282828ff surface.canvas_pattern = #282828ff +surface.page = #282828ff surface.panel = #323232ff surface.chrome = #323232ff surface.raised = #3c3c3cff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/pro-light-gray-light-high-comfortable.txt b/crates/theme/tests/dumps/tokens/pro-light-gray-light-high-comfortable.txt index d4bc3c92cf..1c177daaaf 100644 --- a/crates/theme/tests/dumps/tokens/pro-light-gray-light-high-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/pro-light-gray-light-high-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #a8a8a8ff surface.canvas = #a0a0a0ff surface.canvas_pattern = #a0a0a0ff +surface.page = #a0a0a0ff surface.panel = #b8b8b8ff surface.chrome = #b8b8b8ff surface.raised = #bdbdbdff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/pro-light-gray-light-high-compact.txt b/crates/theme/tests/dumps/tokens/pro-light-gray-light-high-compact.txt index c08ddb36e3..b11a4ee8ef 100644 --- a/crates/theme/tests/dumps/tokens/pro-light-gray-light-high-compact.txt +++ b/crates/theme/tests/dumps/tokens/pro-light-gray-light-high-compact.txt @@ -2,6 +2,7 @@ surface.background = #a8a8a8ff surface.canvas = #a0a0a0ff surface.canvas_pattern = #a0a0a0ff +surface.page = #a0a0a0ff surface.panel = #b8b8b8ff surface.chrome = #b8b8b8ff surface.raised = #bdbdbdff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/pro-light-gray-light-standard-comfortable.txt b/crates/theme/tests/dumps/tokens/pro-light-gray-light-standard-comfortable.txt index 4e755587f0..f2396ce7b5 100644 --- a/crates/theme/tests/dumps/tokens/pro-light-gray-light-standard-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/pro-light-gray-light-standard-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #a8a8a8ff surface.canvas = #a0a0a0ff surface.canvas_pattern = #a0a0a0ff +surface.page = #a0a0a0ff surface.panel = #b8b8b8ff surface.chrome = #b8b8b8ff surface.raised = #bdbdbdff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/pro-light-gray-light-standard-compact.txt b/crates/theme/tests/dumps/tokens/pro-light-gray-light-standard-compact.txt index d101cd1e89..fe12225a17 100644 --- a/crates/theme/tests/dumps/tokens/pro-light-gray-light-standard-compact.txt +++ b/crates/theme/tests/dumps/tokens/pro-light-gray-light-standard-compact.txt @@ -2,6 +2,7 @@ surface.background = #a8a8a8ff surface.canvas = #a0a0a0ff surface.canvas_pattern = #a0a0a0ff +surface.page = #a0a0a0ff surface.panel = #b8b8b8ff surface.chrome = #b8b8b8ff surface.raised = #bdbdbdff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/pro-light-high-comfortable.txt b/crates/theme/tests/dumps/tokens/pro-light-high-comfortable.txt index 946945fae4..87ce0338e6 100644 --- a/crates/theme/tests/dumps/tokens/pro-light-high-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/pro-light-high-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #e2e2e2ff surface.canvas = #d6d6d6ff surface.canvas_pattern = #d6d6d6ff +surface.page = #d6d6d6ff surface.panel = #f0f0f0ff surface.chrome = #f0f0f0ff surface.raised = #f6f6f6ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/pro-light-high-compact.txt b/crates/theme/tests/dumps/tokens/pro-light-high-compact.txt index 102ba36e01..04bd4a7a3d 100644 --- a/crates/theme/tests/dumps/tokens/pro-light-high-compact.txt +++ b/crates/theme/tests/dumps/tokens/pro-light-high-compact.txt @@ -2,6 +2,7 @@ surface.background = #e2e2e2ff surface.canvas = #d6d6d6ff surface.canvas_pattern = #d6d6d6ff +surface.page = #d6d6d6ff surface.panel = #f0f0f0ff surface.chrome = #f0f0f0ff surface.raised = #f6f6f6ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/pro-light-standard-comfortable.txt b/crates/theme/tests/dumps/tokens/pro-light-standard-comfortable.txt index 5f921a8cd1..0010638c8a 100644 --- a/crates/theme/tests/dumps/tokens/pro-light-standard-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/pro-light-standard-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #e2e2e2ff surface.canvas = #d6d6d6ff surface.canvas_pattern = #d6d6d6ff +surface.page = #d6d6d6ff surface.panel = #f0f0f0ff surface.chrome = #f0f0f0ff surface.raised = #f6f6f6ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/pro-light-standard-compact.txt b/crates/theme/tests/dumps/tokens/pro-light-standard-compact.txt index 6b320a4809..229ad03d4f 100644 --- a/crates/theme/tests/dumps/tokens/pro-light-standard-compact.txt +++ b/crates/theme/tests/dumps/tokens/pro-light-standard-compact.txt @@ -2,6 +2,7 @@ surface.background = #e2e2e2ff surface.canvas = #d6d6d6ff surface.canvas_pattern = #d6d6d6ff +surface.page = #d6d6d6ff surface.panel = #f0f0f0ff surface.chrome = #f0f0f0ff surface.raised = #f6f6f6ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/soft-dark-high-comfortable.txt b/crates/theme/tests/dumps/tokens/soft-dark-high-comfortable.txt index 809ad26579..1bece30c56 100644 --- a/crates/theme/tests/dumps/tokens/soft-dark-high-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/soft-dark-high-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #2f2f38ff surface.canvas = #282830ff surface.canvas_pattern = #282830ff +surface.page = #282830ff surface.panel = #363640ff surface.chrome = #3a3a44ff surface.raised = #40404bff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/soft-dark-high-compact.txt b/crates/theme/tests/dumps/tokens/soft-dark-high-compact.txt index 17b68a56a3..553d048da8 100644 --- a/crates/theme/tests/dumps/tokens/soft-dark-high-compact.txt +++ b/crates/theme/tests/dumps/tokens/soft-dark-high-compact.txt @@ -2,6 +2,7 @@ surface.background = #2f2f38ff surface.canvas = #282830ff surface.canvas_pattern = #282830ff +surface.page = #282830ff surface.panel = #363640ff surface.chrome = #3a3a44ff surface.raised = #40404bff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/soft-dark-standard-comfortable.txt b/crates/theme/tests/dumps/tokens/soft-dark-standard-comfortable.txt index c8213d01c7..b185adc363 100644 --- a/crates/theme/tests/dumps/tokens/soft-dark-standard-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/soft-dark-standard-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #2f2f38ff surface.canvas = #282830ff surface.canvas_pattern = #282830ff +surface.page = #282830ff surface.panel = #363640ff surface.chrome = #3a3a44ff surface.raised = #40404bff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/soft-dark-standard-compact.txt b/crates/theme/tests/dumps/tokens/soft-dark-standard-compact.txt index e7bd9f094f..c0df85540a 100644 --- a/crates/theme/tests/dumps/tokens/soft-dark-standard-compact.txt +++ b/crates/theme/tests/dumps/tokens/soft-dark-standard-compact.txt @@ -2,6 +2,7 @@ surface.background = #2f2f38ff surface.canvas = #282830ff surface.canvas_pattern = #282830ff +surface.page = #282830ff surface.panel = #363640ff surface.chrome = #3a3a44ff surface.raised = #40404bff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/soft-light-high-comfortable.txt b/crates/theme/tests/dumps/tokens/soft-light-high-comfortable.txt index 1da506ba38..9da6fb3422 100644 --- a/crates/theme/tests/dumps/tokens/soft-light-high-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/soft-light-high-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #e2e0e7ff surface.canvas = #dad8e0ff surface.canvas_pattern = #dad8e0ff +surface.page = #dad8e0ff surface.panel = #f0eef3ff surface.chrome = #e8e6ecff surface.raised = #f6f4f9ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/soft-light-high-compact.txt b/crates/theme/tests/dumps/tokens/soft-light-high-compact.txt index 0765c69df4..bad97b7a99 100644 --- a/crates/theme/tests/dumps/tokens/soft-light-high-compact.txt +++ b/crates/theme/tests/dumps/tokens/soft-light-high-compact.txt @@ -2,6 +2,7 @@ surface.background = #e2e0e7ff surface.canvas = #dad8e0ff surface.canvas_pattern = #dad8e0ff +surface.page = #dad8e0ff surface.panel = #f0eef3ff surface.chrome = #e8e6ecff surface.raised = #f6f4f9ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/soft-light-standard-comfortable.txt b/crates/theme/tests/dumps/tokens/soft-light-standard-comfortable.txt index aa6f1f5aff..0e6ec0d87d 100644 --- a/crates/theme/tests/dumps/tokens/soft-light-standard-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/soft-light-standard-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #e2e0e7ff surface.canvas = #dad8e0ff surface.canvas_pattern = #dad8e0ff +surface.page = #dad8e0ff surface.panel = #f0eef3ff surface.chrome = #e8e6ecff surface.raised = #f6f4f9ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/soft-light-standard-compact.txt b/crates/theme/tests/dumps/tokens/soft-light-standard-compact.txt index 608d7b62fe..6ea6ef3e5d 100644 --- a/crates/theme/tests/dumps/tokens/soft-light-standard-compact.txt +++ b/crates/theme/tests/dumps/tokens/soft-light-standard-compact.txt @@ -2,6 +2,7 @@ surface.background = #e2e0e7ff surface.canvas = #dad8e0ff surface.canvas_pattern = #dad8e0ff +surface.page = #dad8e0ff surface.panel = #f0eef3ff surface.chrome = #e8e6ecff surface.raised = #f6f4f9ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/solarized-dark-dark-high-comfortable.txt b/crates/theme/tests/dumps/tokens/solarized-dark-dark-high-comfortable.txt index 3ec91240c3..c1e98773bc 100644 --- a/crates/theme/tests/dumps/tokens/solarized-dark-dark-high-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/solarized-dark-dark-high-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #00252fff surface.canvas = #002b36ff surface.canvas_pattern = #0a3d4aff +surface.page = #002b36ff surface.panel = #073642ff surface.chrome = #073642ff surface.raised = #15414dff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/solarized-dark-dark-high-compact.txt b/crates/theme/tests/dumps/tokens/solarized-dark-dark-high-compact.txt index 5074be5a19..03d4694907 100644 --- a/crates/theme/tests/dumps/tokens/solarized-dark-dark-high-compact.txt +++ b/crates/theme/tests/dumps/tokens/solarized-dark-dark-high-compact.txt @@ -2,6 +2,7 @@ surface.background = #00252fff surface.canvas = #002b36ff surface.canvas_pattern = #0a3d4aff +surface.page = #002b36ff surface.panel = #073642ff surface.chrome = #073642ff surface.raised = #15414dff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/solarized-dark-dark-standard-comfortable.txt b/crates/theme/tests/dumps/tokens/solarized-dark-dark-standard-comfortable.txt index 9c81b7d0c9..cf0f273e88 100644 --- a/crates/theme/tests/dumps/tokens/solarized-dark-dark-standard-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/solarized-dark-dark-standard-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #00252fff surface.canvas = #002b36ff surface.canvas_pattern = #0a3d4aff +surface.page = #002b36ff surface.panel = #073642ff surface.chrome = #073642ff surface.raised = #15414dff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/solarized-dark-dark-standard-compact.txt b/crates/theme/tests/dumps/tokens/solarized-dark-dark-standard-compact.txt index 2b5e409fdf..58c8ea3cb7 100644 --- a/crates/theme/tests/dumps/tokens/solarized-dark-dark-standard-compact.txt +++ b/crates/theme/tests/dumps/tokens/solarized-dark-dark-standard-compact.txt @@ -2,6 +2,7 @@ surface.background = #00252fff surface.canvas = #002b36ff surface.canvas_pattern = #0a3d4aff +surface.page = #002b36ff surface.panel = #073642ff surface.chrome = #073642ff surface.raised = #15414dff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/studio-dark-high-comfortable.txt b/crates/theme/tests/dumps/tokens/studio-dark-high-comfortable.txt index da22e8f42e..343160396e 100644 --- a/crates/theme/tests/dumps/tokens/studio-dark-high-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/studio-dark-high-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #111112ff surface.canvas = #0e0e0fff surface.canvas_pattern = #2e2e32ff +surface.page = #0e0e0fff surface.panel = #1a1a1cff surface.chrome = #141415ff surface.raised = #232325ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/studio-dark-high-compact.txt b/crates/theme/tests/dumps/tokens/studio-dark-high-compact.txt index 4c0a039d71..f67f595938 100644 --- a/crates/theme/tests/dumps/tokens/studio-dark-high-compact.txt +++ b/crates/theme/tests/dumps/tokens/studio-dark-high-compact.txt @@ -2,6 +2,7 @@ surface.background = #111112ff surface.canvas = #0e0e0fff surface.canvas_pattern = #2e2e32ff +surface.page = #0e0e0fff surface.panel = #1a1a1cff surface.chrome = #141415ff surface.raised = #232325ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/studio-dark-standard-comfortable.txt b/crates/theme/tests/dumps/tokens/studio-dark-standard-comfortable.txt index 72edc0bc3e..1dc872c253 100644 --- a/crates/theme/tests/dumps/tokens/studio-dark-standard-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/studio-dark-standard-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #111112ff surface.canvas = #0e0e0fff surface.canvas_pattern = #2e2e32ff +surface.page = #0e0e0fff surface.panel = #1a1a1cff surface.chrome = #141415ff surface.raised = #232325ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/studio-dark-standard-compact.txt b/crates/theme/tests/dumps/tokens/studio-dark-standard-compact.txt index 0b3cebd636..1929ef4f1f 100644 --- a/crates/theme/tests/dumps/tokens/studio-dark-standard-compact.txt +++ b/crates/theme/tests/dumps/tokens/studio-dark-standard-compact.txt @@ -2,6 +2,7 @@ surface.background = #111112ff surface.canvas = #0e0e0fff surface.canvas_pattern = #2e2e32ff +surface.page = #0e0e0fff surface.panel = #1a1a1cff surface.chrome = #141415ff surface.raised = #232325ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/studio-light-high-comfortable.txt b/crates/theme/tests/dumps/tokens/studio-light-high-comfortable.txt index 696d0c65d3..816f246495 100644 --- a/crates/theme/tests/dumps/tokens/studio-light-high-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/studio-light-high-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #f0f0f3ff surface.canvas = #e2e2e6ff surface.canvas_pattern = #c8c8ceff +surface.page = #e2e2e6ff surface.panel = #fcfcfdff surface.chrome = #f6f6f8ff surface.raised = #ffffffff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/studio-light-high-compact.txt b/crates/theme/tests/dumps/tokens/studio-light-high-compact.txt index d02a991db0..414c17e58e 100644 --- a/crates/theme/tests/dumps/tokens/studio-light-high-compact.txt +++ b/crates/theme/tests/dumps/tokens/studio-light-high-compact.txt @@ -2,6 +2,7 @@ surface.background = #f0f0f3ff surface.canvas = #e2e2e6ff surface.canvas_pattern = #c8c8ceff +surface.page = #e2e2e6ff surface.panel = #fcfcfdff surface.chrome = #f6f6f8ff surface.raised = #ffffffff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/studio-light-standard-comfortable.txt b/crates/theme/tests/dumps/tokens/studio-light-standard-comfortable.txt index 0eed9e1dc0..8efa894323 100644 --- a/crates/theme/tests/dumps/tokens/studio-light-standard-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/studio-light-standard-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #f0f0f3ff surface.canvas = #e2e2e6ff surface.canvas_pattern = #c8c8ceff +surface.page = #e2e2e6ff surface.panel = #fcfcfdff surface.chrome = #f6f6f8ff surface.raised = #ffffffff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/studio-light-standard-compact.txt b/crates/theme/tests/dumps/tokens/studio-light-standard-compact.txt index 4795b318f1..0920634b06 100644 --- a/crates/theme/tests/dumps/tokens/studio-light-standard-compact.txt +++ b/crates/theme/tests/dumps/tokens/studio-light-standard-compact.txt @@ -2,6 +2,7 @@ surface.background = #f0f0f3ff surface.canvas = #e2e2e6ff surface.canvas_pattern = #c8c8ceff +surface.page = #e2e2e6ff surface.panel = #fcfcfdff surface.chrome = #f6f6f8ff surface.raised = #ffffffff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 5 shape.grip.width = 1 shape.grip.gap = 1 +shape.locator.cell = 8 +shape.locator.square = 6 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/vectorcraft-modern-dark-high-comfortable.txt b/crates/theme/tests/dumps/tokens/vectorcraft-modern-dark-high-comfortable.txt index 7a10096f47..706fd0c2cd 100644 --- a/crates/theme/tests/dumps/tokens/vectorcraft-modern-dark-high-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/vectorcraft-modern-dark-high-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #0b0d12ff surface.canvas = #101217ff surface.canvas_pattern = #101217ff +surface.page = #13161cff surface.panel = #181b22ff surface.chrome = #181b22ff surface.raised = #21242cff @@ -27,7 +28,7 @@ line.outline = #4a5363ff line.knob_edge = #00000000 line.frame = #0d0d0eff line.mark = #a3a8b0ff -line.grip = #2b2e36ff +line.grip = #5a6271ff line.focus = #f06a52ff accent.solid = #f26b53ff accent.hover = #f26f57ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 18 shape.grip.width = 3 shape.grip.gap = 1 +shape.locator.cell = 9 +shape.locator.square = 5 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/vectorcraft-modern-dark-high-compact.txt b/crates/theme/tests/dumps/tokens/vectorcraft-modern-dark-high-compact.txt index c3b5559b0c..edf0d2d7b9 100644 --- a/crates/theme/tests/dumps/tokens/vectorcraft-modern-dark-high-compact.txt +++ b/crates/theme/tests/dumps/tokens/vectorcraft-modern-dark-high-compact.txt @@ -2,6 +2,7 @@ surface.background = #0b0d12ff surface.canvas = #101217ff surface.canvas_pattern = #101217ff +surface.page = #13161cff surface.panel = #181b22ff surface.chrome = #181b22ff surface.raised = #21242cff @@ -27,7 +28,7 @@ line.outline = #4a5363ff line.knob_edge = #00000000 line.frame = #0d0d0eff line.mark = #a3a8b0ff -line.grip = #2b2e36ff +line.grip = #5a6271ff line.focus = #f06a52ff accent.solid = #f26b53ff accent.hover = #f26f57ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 18 shape.grip.width = 3 shape.grip.gap = 1 +shape.locator.cell = 9 +shape.locator.square = 5 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/vectorcraft-modern-dark-standard-comfortable.txt b/crates/theme/tests/dumps/tokens/vectorcraft-modern-dark-standard-comfortable.txt index 76834950c9..5babd1d779 100644 --- a/crates/theme/tests/dumps/tokens/vectorcraft-modern-dark-standard-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/vectorcraft-modern-dark-standard-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #0b0d12ff surface.canvas = #101217ff surface.canvas_pattern = #101217ff +surface.page = #13161cff surface.panel = #181b22ff surface.chrome = #181b22ff surface.raised = #21242cff @@ -27,7 +28,7 @@ line.outline = #4a5363ff line.knob_edge = #00000000 line.frame = #0d0d0eff line.mark = #83878fff -line.grip = #2b2e36ff +line.grip = #5a6271ff line.focus = #f06a52ff accent.solid = #f06a52ff accent.hover = #f26f57ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 18 shape.grip.width = 3 shape.grip.gap = 1 +shape.locator.cell = 9 +shape.locator.square = 5 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/vectorcraft-modern-dark-standard-compact.txt b/crates/theme/tests/dumps/tokens/vectorcraft-modern-dark-standard-compact.txt index 1f0db7af85..c9e1fd086e 100644 --- a/crates/theme/tests/dumps/tokens/vectorcraft-modern-dark-standard-compact.txt +++ b/crates/theme/tests/dumps/tokens/vectorcraft-modern-dark-standard-compact.txt @@ -2,6 +2,7 @@ surface.background = #0b0d12ff surface.canvas = #101217ff surface.canvas_pattern = #101217ff +surface.page = #13161cff surface.panel = #181b22ff surface.chrome = #181b22ff surface.raised = #21242cff @@ -27,7 +28,7 @@ line.outline = #4a5363ff line.knob_edge = #00000000 line.frame = #0d0d0eff line.mark = #83878fff -line.grip = #2b2e36ff +line.grip = #5a6271ff line.focus = #f06a52ff accent.solid = #f06a52ff accent.hover = #f26f57ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 18 shape.grip.width = 3 shape.grip.gap = 1 +shape.locator.cell = 9 +shape.locator.square = 5 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/vectorcraft-modern-light-high-comfortable.txt b/crates/theme/tests/dumps/tokens/vectorcraft-modern-light-high-comfortable.txt index 8facf78e90..f3a5ad5c7a 100644 --- a/crates/theme/tests/dumps/tokens/vectorcraft-modern-light-high-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/vectorcraft-modern-light-high-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #e6e9eeff surface.canvas = #dfe3e9ff surface.canvas_pattern = #dfe3e9ff +surface.page = #e9ecf1ff surface.panel = #f3f5f8ff surface.chrome = #f3f5f8ff surface.raised = #f9fbfeff @@ -27,7 +28,7 @@ line.outline = #a4abb8ff line.knob_edge = #383f4dff line.frame = #c3c9d3ff line.mark = #5a5b5dff -line.grip = #e2e4e7ff +line.grip = #9aa1adff line.focus = #c4321aff accent.solid = #af1c00ff accent.hover = #af1d02ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 18 shape.grip.width = 3 shape.grip.gap = 1 +shape.locator.cell = 9 +shape.locator.square = 5 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/vectorcraft-modern-light-high-compact.txt b/crates/theme/tests/dumps/tokens/vectorcraft-modern-light-high-compact.txt index 1e52e2f79d..c7a1bc99c8 100644 --- a/crates/theme/tests/dumps/tokens/vectorcraft-modern-light-high-compact.txt +++ b/crates/theme/tests/dumps/tokens/vectorcraft-modern-light-high-compact.txt @@ -2,6 +2,7 @@ surface.background = #e6e9eeff surface.canvas = #dfe3e9ff surface.canvas_pattern = #dfe3e9ff +surface.page = #e9ecf1ff surface.panel = #f3f5f8ff surface.chrome = #f3f5f8ff surface.raised = #f9fbfeff @@ -27,7 +28,7 @@ line.outline = #a4abb8ff line.knob_edge = #383f4dff line.frame = #c3c9d3ff line.mark = #5a5b5dff -line.grip = #e2e4e7ff +line.grip = #9aa1adff line.focus = #c4321aff accent.solid = #af1c00ff accent.hover = #af1d02ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 18 shape.grip.width = 3 shape.grip.gap = 1 +shape.locator.cell = 9 +shape.locator.square = 5 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/vectorcraft-modern-light-standard-comfortable.txt b/crates/theme/tests/dumps/tokens/vectorcraft-modern-light-standard-comfortable.txt index dc816777a1..5fd31f242e 100644 --- a/crates/theme/tests/dumps/tokens/vectorcraft-modern-light-standard-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/vectorcraft-modern-light-standard-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #e6e9eeff surface.canvas = #dfe3e9ff surface.canvas_pattern = #dfe3e9ff +surface.page = #e9ecf1ff surface.panel = #f3f5f8ff surface.chrome = #f3f5f8ff surface.raised = #f9fbfeff @@ -27,7 +28,7 @@ line.outline = #a4abb8ff line.knob_edge = #58606eff line.frame = #c3c9d3ff line.mark = #757678ff -line.grip = #e2e4e7ff +line.grip = #9aa1adff line.focus = #d9472fff accent.solid = #d9472fff accent.hover = #d1412aff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 18 shape.grip.width = 3 shape.grip.gap = 1 +shape.locator.cell = 9 +shape.locator.square = 5 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/vectorcraft-modern-light-standard-compact.txt b/crates/theme/tests/dumps/tokens/vectorcraft-modern-light-standard-compact.txt index b212acf2f9..f8828fa20f 100644 --- a/crates/theme/tests/dumps/tokens/vectorcraft-modern-light-standard-compact.txt +++ b/crates/theme/tests/dumps/tokens/vectorcraft-modern-light-standard-compact.txt @@ -2,6 +2,7 @@ surface.background = #e6e9eeff surface.canvas = #dfe3e9ff surface.canvas_pattern = #dfe3e9ff +surface.page = #e9ecf1ff surface.panel = #f3f5f8ff surface.chrome = #f3f5f8ff surface.raised = #f9fbfeff @@ -27,7 +28,7 @@ line.outline = #a4abb8ff line.knob_edge = #58606eff line.frame = #c3c9d3ff line.mark = #757678ff -line.grip = #e2e4e7ff +line.grip = #9aa1adff line.focus = #d9472fff accent.solid = #d9472fff accent.hover = #d1412aff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 18 shape.grip.width = 3 shape.grip.gap = 1 +shape.locator.cell = 9 +shape.locator.square = 5 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/vectorcraft-modern-medium-dark-high-comfortable.txt b/crates/theme/tests/dumps/tokens/vectorcraft-modern-medium-dark-high-comfortable.txt index 7451513b5c..d8b6ce06c7 100644 --- a/crates/theme/tests/dumps/tokens/vectorcraft-modern-medium-dark-high-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/vectorcraft-modern-medium-dark-high-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #1b1f27ff surface.canvas = #1e222aff surface.canvas_pattern = #1e222aff +surface.page = #21262fff surface.panel = #272c36ff surface.chrome = #272c36ff surface.raised = #313640ff @@ -27,7 +28,7 @@ line.outline = #5a6476ff line.knob_edge = #00000000 line.frame = #0d0d0eff line.mark = #b0b7c3ff -line.grip = #3b404bff +line.grip = #626b7aff line.focus = #fc755cff accent.solid = #fc755cff accent.hover = #f26f57ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 18 shape.grip.width = 3 shape.grip.gap = 1 +shape.locator.cell = 9 +shape.locator.square = 5 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/vectorcraft-modern-medium-dark-high-compact.txt b/crates/theme/tests/dumps/tokens/vectorcraft-modern-medium-dark-high-compact.txt index b911c77736..fa43b9602b 100644 --- a/crates/theme/tests/dumps/tokens/vectorcraft-modern-medium-dark-high-compact.txt +++ b/crates/theme/tests/dumps/tokens/vectorcraft-modern-medium-dark-high-compact.txt @@ -2,6 +2,7 @@ surface.background = #1b1f27ff surface.canvas = #1e222aff surface.canvas_pattern = #1e222aff +surface.page = #21262fff surface.panel = #272c36ff surface.chrome = #272c36ff surface.raised = #313640ff @@ -27,7 +28,7 @@ line.outline = #5a6476ff line.knob_edge = #00000000 line.frame = #0d0d0eff line.mark = #b0b7c3ff -line.grip = #3b404bff +line.grip = #626b7aff line.focus = #fc755cff accent.solid = #fc755cff accent.hover = #f26f57ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 18 shape.grip.width = 3 shape.grip.gap = 1 +shape.locator.cell = 9 +shape.locator.square = 5 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/vectorcraft-modern-medium-dark-standard-comfortable.txt b/crates/theme/tests/dumps/tokens/vectorcraft-modern-medium-dark-standard-comfortable.txt index aa422862bc..7b0559933d 100644 --- a/crates/theme/tests/dumps/tokens/vectorcraft-modern-medium-dark-standard-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/vectorcraft-modern-medium-dark-standard-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #1b1f27ff surface.canvas = #1e222aff surface.canvas_pattern = #1e222aff +surface.page = #21262fff surface.panel = #272c36ff surface.chrome = #272c36ff surface.raised = #313640ff @@ -27,7 +28,7 @@ line.outline = #5a6476ff line.knob_edge = #00000000 line.frame = #0d0d0eff line.mark = #8e95a0ff -line.grip = #3b404bff +line.grip = #626b7aff line.focus = #f06a52ff accent.solid = #f06a52ff accent.hover = #f26f57ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 18 shape.grip.width = 3 shape.grip.gap = 1 +shape.locator.cell = 9 +shape.locator.square = 5 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/vectorcraft-modern-medium-dark-standard-compact.txt b/crates/theme/tests/dumps/tokens/vectorcraft-modern-medium-dark-standard-compact.txt index 3465acfd49..006eaa302d 100644 --- a/crates/theme/tests/dumps/tokens/vectorcraft-modern-medium-dark-standard-compact.txt +++ b/crates/theme/tests/dumps/tokens/vectorcraft-modern-medium-dark-standard-compact.txt @@ -2,6 +2,7 @@ surface.background = #1b1f27ff surface.canvas = #1e222aff surface.canvas_pattern = #1e222aff +surface.page = #21262fff surface.panel = #272c36ff surface.chrome = #272c36ff surface.raised = #313640ff @@ -27,7 +28,7 @@ line.outline = #5a6476ff line.knob_edge = #00000000 line.frame = #0d0d0eff line.mark = #8e95a0ff -line.grip = #3b404bff +line.grip = #626b7aff line.focus = #f06a52ff accent.solid = #f06a52ff accent.hover = #f26f57ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 18 shape.grip.width = 3 shape.grip.gap = 1 +shape.locator.cell = 9 +shape.locator.square = 5 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/vectorcraft-modern-medium-light-high-comfortable.txt b/crates/theme/tests/dumps/tokens/vectorcraft-modern-medium-light-high-comfortable.txt index 7958e66eb0..fcce02ab84 100644 --- a/crates/theme/tests/dumps/tokens/vectorcraft-modern-medium-light-high-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/vectorcraft-modern-medium-light-high-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #c4cad4ff surface.canvas = #b9c0cbff surface.canvas_pattern = #b9c0cbff +surface.page = #c9cfd8ff surface.panel = #d3d8e0ff surface.chrome = #d3d8e0ff surface.raised = #d9dee6ff @@ -27,7 +28,7 @@ line.outline = #8a93a2ff line.knob_edge = #292f3dff line.frame = #9aa2b0ff line.mark = #494c53ff -line.grip = #c3c8d0ff +line.grip = #7d8594ff line.focus = #a81a00ff accent.solid = #af1b00ff accent.hover = #af1d02ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 18 shape.grip.width = 3 shape.grip.gap = 1 +shape.locator.cell = 9 +shape.locator.square = 5 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/vectorcraft-modern-medium-light-high-compact.txt b/crates/theme/tests/dumps/tokens/vectorcraft-modern-medium-light-high-compact.txt index 4fe899cf58..b30c030ff4 100644 --- a/crates/theme/tests/dumps/tokens/vectorcraft-modern-medium-light-high-compact.txt +++ b/crates/theme/tests/dumps/tokens/vectorcraft-modern-medium-light-high-compact.txt @@ -2,6 +2,7 @@ surface.background = #c4cad4ff surface.canvas = #b9c0cbff surface.canvas_pattern = #b9c0cbff +surface.page = #c9cfd8ff surface.panel = #d3d8e0ff surface.chrome = #d3d8e0ff surface.raised = #d9dee6ff @@ -27,7 +28,7 @@ line.outline = #8a93a2ff line.knob_edge = #292f3dff line.frame = #9aa2b0ff line.mark = #494c53ff -line.grip = #c3c8d0ff +line.grip = #7d8594ff line.focus = #a81a00ff accent.solid = #af1b00ff accent.hover = #af1d02ff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 18 shape.grip.width = 3 shape.grip.gap = 1 +shape.locator.cell = 9 +shape.locator.square = 5 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/vectorcraft-modern-medium-light-standard-comfortable.txt b/crates/theme/tests/dumps/tokens/vectorcraft-modern-medium-light-standard-comfortable.txt index d873d8be6b..a0b1f1dc08 100644 --- a/crates/theme/tests/dumps/tokens/vectorcraft-modern-medium-light-standard-comfortable.txt +++ b/crates/theme/tests/dumps/tokens/vectorcraft-modern-medium-light-standard-comfortable.txt @@ -2,6 +2,7 @@ surface.background = #c4cad4ff surface.canvas = #b9c0cbff surface.canvas_pattern = #b9c0cbff +surface.page = #c9cfd8ff surface.panel = #d3d8e0ff surface.chrome = #d3d8e0ff surface.raised = #d9dee6ff @@ -27,7 +28,7 @@ line.outline = #8a93a2ff line.knob_edge = #4a5160ff line.frame = #9aa2b0ff line.mark = #63676dff -line.grip = #c3c8d0ff +line.grip = #7d8594ff line.focus = #cd3b24ff accent.solid = #d9472fff accent.hover = #d1412aff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 18 shape.grip.width = 3 shape.grip.gap = 1 +shape.locator.cell = 9 +shape.locator.square = 5 space.gap.tight = 3 space.gap.inline = 6 space.gap.row = 6 @@ -143,6 +146,7 @@ space.inset.page_margin = 28 space.inset.page_gap = 14 size.control.sm = 24 size.control.md = 30 +size.button = 30 size.icon.sm = 14 size.icon.md = 18 size.icon.lg = 22 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 50 +size.page.action = 30 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/tests/dumps/tokens/vectorcraft-modern-medium-light-standard-compact.txt b/crates/theme/tests/dumps/tokens/vectorcraft-modern-medium-light-standard-compact.txt index a5aeb65db0..3b4e7a95f2 100644 --- a/crates/theme/tests/dumps/tokens/vectorcraft-modern-medium-light-standard-compact.txt +++ b/crates/theme/tests/dumps/tokens/vectorcraft-modern-medium-light-standard-compact.txt @@ -2,6 +2,7 @@ surface.background = #c4cad4ff surface.canvas = #b9c0cbff surface.canvas_pattern = #b9c0cbff +surface.page = #c9cfd8ff surface.panel = #d3d8e0ff surface.chrome = #d3d8e0ff surface.raised = #d9dee6ff @@ -27,7 +28,7 @@ line.outline = #8a93a2ff line.knob_edge = #4a5160ff line.frame = #9aa2b0ff line.mark = #63676dff -line.grip = #c3c8d0ff +line.grip = #7d8594ff line.focus = #cd3b24ff accent.solid = #d9472fff accent.hover = #d1412aff @@ -124,6 +125,8 @@ shape.grip.count = 11 shape.grip.length = 18 shape.grip.width = 3 shape.grip.gap = 1 +shape.locator.cell = 9 +shape.locator.square = 5 space.gap.tight = 2 space.gap.inline = 4 space.gap.row = 4 @@ -143,6 +146,7 @@ space.inset.page_margin = 24 space.inset.page_gap = 12 size.control.sm = 20 size.control.md = 24 +size.button = 24 size.icon.sm = 12 size.icon.md = 16 size.icon.lg = 20 @@ -195,6 +199,9 @@ size.dialog.least = 380 size.dialog.wrap = 440 size.dialog.button = 84 size.dialog.side_button = 96 +size.page.column = 820 +size.page.margin = 40 +size.page.action = 24 stroke.thin = 1 stroke.medium = 1.5 stroke.thick = 2 diff --git a/crates/theme/themes/vectorcraft-modern-medium.json b/crates/theme/themes/vectorcraft-modern-medium.json index 2985b90598..45029c879f 100644 --- a/crates/theme/themes/vectorcraft-modern-medium.json +++ b/crates/theme/themes/vectorcraft-modern-medium.json @@ -21,6 +21,10 @@ "mark": "bar", "length": 18, "width": 3 + }, + "locator": { + "cell": 9, + "square": 5 } }, "light": { @@ -30,6 +34,7 @@ "line.border": "#a9b0bc", "line.control_edge": "#9aa2b0", "line.divider": "#bcc3ce", + "line.grip": "#7d8594", "line.outline": "#8a93a2", "seeds": { "accent": "#d9472f", @@ -42,6 +47,7 @@ "surface.background": "#c4cad4", "surface.canvas": "#b9c0cb", "surface.control": "#c9d0da", + "surface.page": "#c9cfd8", "surface.panel": "#d3d8e0", "surface.sunken": "#e9ecf1", "text.disabled": "#7d8594", @@ -56,6 +62,7 @@ "line.border": "#11141a", "line.control_edge": "#3a414e", "line.divider": "#323946", + "line.grip": "#626b7a", "line.outline": "#5a6476", "state.hover": "#353c49", "state.pressed": "#633f3e", @@ -64,6 +71,7 @@ "surface.background": "#1b1f27", "surface.canvas": "#1e222a", "surface.control": "#39404d", + "surface.page": "#21262f", "surface.panel": "#272c36", "surface.sunken": "#1a1e26", "text.disabled": "#626b7a", diff --git a/crates/theme/themes/vectorcraft-modern.json b/crates/theme/themes/vectorcraft-modern.json index c710606364..c33372ae3e 100644 --- a/crates/theme/themes/vectorcraft-modern.json +++ b/crates/theme/themes/vectorcraft-modern.json @@ -21,6 +21,10 @@ "mark": "bar", "length": 18, "width": 3 + }, + "locator": { + "cell": 9, + "square": 5 } }, "light": { @@ -30,6 +34,7 @@ "line.border": "#d0d5dd", "line.control_edge": "#c3c9d3", "line.divider": "#dde1e8", + "line.grip": "#9aa1ad", "line.outline": "#a4abb8", "seeds": { "accent": "#d9472f", @@ -42,6 +47,7 @@ "surface.background": "#e6e9ee", "surface.canvas": "#dfe3e9", "surface.control": "#e3e7ed", + "surface.page": "#e9ecf1", "surface.panel": "#f3f5f8", "surface.sunken": "#ffffff", "text.disabled": "#9aa1ad", @@ -56,6 +62,7 @@ "line.border": "#06070a", "line.control_edge": "#2c323e", "line.divider": "#232832", + "line.grip": "#5a6271", "line.outline": "#4a5363", "state.hover": "#262b35", "state.pressed": "#593330", @@ -64,6 +71,7 @@ "surface.background": "#0b0d12", "surface.canvas": "#101217", "surface.control": "#282d37", + "surface.page": "#13161c", "surface.panel": "#181b22", "surface.sunken": "#0f1116", "text.disabled": "#5a6271", diff --git a/crates/ui-contract/src/contract/body/inherit.rs b/crates/ui-contract/src/contract/body/inherit.rs index c8494bf358..c16d15959c 100644 --- a/crates/ui-contract/src/contract/body/inherit.rs +++ b/crates/ui-contract/src/contract/body/inherit.rs @@ -2,7 +2,7 @@ use super::BodyHooks; use super::reorder::REORDER_SCOPE; -use crate::contract::{Container, ContainerProps, Cx, DragBand, Mount, Scroll}; +use crate::contract::{Container, ContainerProps, Cx, DragBand, Mount, QuietHeader, Scroll}; use crate::runtime::commands::{self, CommandSet as _, WindowCommand}; use crate::runtime::env::{AppValues, ArenaId, Scoped, ScrollOwner}; use crate::style::{ComponentStyle as _, SurfaceKind}; @@ -113,9 +113,11 @@ impl BodyHooks<'_> { if props.arena { scoped.arena = Some(ArenaId::new(id)); } - // The body's flow starts after a rule when the container draws one under its header, or when the container - // draws nothing of its own (no header, surface or mount) and itself started after a rule. - scoped.after_rule = props.header.is_some_and(|header| header.rule && !header.inline) + // The body's flow starts after a rule when the container draws one under its header or its title heads the + // body as one would (`QuietHeader::Heads`), or when the container draws nothing of its own (no header, surface + // or mount) and itself started after a rule. + let heads = scoped.values.get::() == QuietHeader::Heads; + scoped.after_rule = props.header.is_some_and(|header| (header.rule || (header.heads && heads)) && !header.inline) || (props.header.is_none() && props.surface.is_none() && props.mount == Mount::Inline && self.after_rule); scoped.flow_body = None; scoped.column_row = diff --git a/crates/ui-contract/src/contract/body/pane.rs b/crates/ui-contract/src/contract/body/pane.rs index b9468431e0..573f6605c6 100644 --- a/crates/ui-contract/src/contract/body/pane.rs +++ b/crates/ui-contract/src/contract/body/pane.rs @@ -83,7 +83,8 @@ impl BodyHooks<'_> { ResizeEdge::Bottom => Rect::from_min_size(rect.min, Vec2::new(rect.width(), extent)), _ => Rect::from_min_max(Pos2::new(rect.min.x, rect.max.y - extent), rect.max), }; - let change = |rect: Rect, phase: GesturePhase| PlacementChange { rect, phase, pointer: pos, kind: PlacementKind::Size(edge) }; + let change = + |rect: Rect, phase: GesturePhase| PlacementChange { rect, phase, pointer: pos, kind: PlacementKind::Size(edge), continued: false }; if gesture == GesturePhase::Begin { self.reports.push(change(resized(began), GesturePhase::Begin)); } diff --git a/crates/ui-contract/src/contract/body/presses.rs b/crates/ui-contract/src/contract/body/presses.rs index 4924066366..ca96137d03 100644 --- a/crates/ui-contract/src/contract/body/presses.rs +++ b/crates/ui-contract/src/contract/body/presses.rs @@ -8,7 +8,7 @@ use crate::runtime::egui::areas; use crate::runtime::memory::sub; use crate::runtime::pointer; use craft_behavior::{Cursor, CursorPriority, PartRef, PointerButton, PressState}; -use egui::Pos2; +use egui::{Pos2, Ui}; /// Whether the second press of a double click went down on the container's move band in this pass. #[derive(Clone, Default)] @@ -47,6 +47,16 @@ impl BodyCx<'_> { self.memory.recall::(sub(self.id, "surface_press")).pressed } + /// Whether the primary press of this pass went down in the body's rect, on the layer `ui` (a `Ui` of this body) + /// paints on, whatever takes it: a child, a part, an app's own egui widget or the surface itself. A press on a + /// popup or a window above the body is not in it. The container decides what it means (a dock group whose body is + /// the app's own egui code names its panel as the one pressed into); it moves no focus by itself. A measuring run + /// sees none, for the reason [`band_double_pressed`](Self::band_double_pressed) gives. + pub fn pressed_within(&self, ui: &Ui) -> bool { + let ctx = self.memory.ctx(); + !self.memory.is_peek() && pointer::primary_press_in(ctx, ui.layer_id(), self.rect).is_some() + } + /// Whether the press of [`surface_pressed`](Self::surface_pressed) is the second press of a double click: no child /// or part takes it and its click count is two or more. One own-surface signal for every container (an empty /// workspace opens a file on it). A measuring run sees none, for the reason @@ -85,17 +95,12 @@ impl BodyHooks<'_> { let ctx = core.ctx.clone(); let pass = pointer::pass_pointer(&ctx); let (layer, rect) = (core.response.layer_id, core.rect); - // Whether `pos` lies in the container's rect, on its layer. - let inside = |pos: Pos2| { - let at = areas::layer_map(&ctx, layer).map_or(pos, |map| map.to_layer(pos)); - areas::layer_at(&ctx, pos) == Some(layer) && rect.contains(at) - }; + let inside = |pos: Pos2| areas::lies_in(&ctx, layer, rect, pos); let surface = if sensed { - pass.frame.as_ref().and_then(|frame| frame.press).filter(|press| press.button == PointerButton::Primary).filter(|press| { - inside(press.origin) - && pointer::press_winner(&ctx, press.origin, pass.press_targets).is_none() + pointer::primary_press_in(&ctx, layer, rect).filter(|press| { + pointer::press_winner(&ctx, press.origin, pass.press_targets).is_none() && !pointer::text_takes_press(&ctx, pass.press_targets) - && !pass.press_targets.click.is_some_and(|widget| pointer::foreign_target(&ctx, widget)) + && ![pass.press_targets.click, pass.press_targets.drag].into_iter().flatten().any(|widget| pointer::foreign_target(&ctx, widget)) }) } else { None diff --git a/crates/ui-contract/src/contract/body/window.rs b/crates/ui-contract/src/contract/body/window.rs index 257398beaf..79eb032b4d 100644 --- a/crates/ui-contract/src/contract/body/window.rs +++ b/crates/ui-contract/src/contract/body/window.rs @@ -412,7 +412,7 @@ impl BodyHooks<'_> { let rtl = cx.core.env.direction().is_rtl(); let mut slot = PlacementSlot::new(&mut *cx.core.memory, id, self.save.as_ref(), overlay); let current = slot.read(); - let step = |rect: Rect, phase: GesturePhase| PlacementChange { rect, phase, pointer: None, kind: PlacementKind::Keyboard }; + let step = |rect: Rect, phase: GesturePhase| PlacementChange { rect, phase, pointer: None, kind: PlacementKind::Keyboard, continued: false }; let started = commands::take_for_instance(&ctx, Some(window), false, WindowCommand::from_ref).map(|(command, _)| command); let mut mode = self.mode.clone(); if let Some(command) = started { @@ -509,7 +509,7 @@ impl BodyHooks<'_> { }; let mut slot = PlacementSlot::new(&mut *cx.core.memory, id, self.save.as_ref(), overlay); let current = slot.read(); - let (origin, pos, gesture) = match phase { + let (start, pos, gesture) = match phase { PressPhase::Down { .. } => { self.mode.pressed = Some(current.rect_over(rect)); return; @@ -520,13 +520,14 @@ impl BodyHooks<'_> { self.mode.began = Some(self.mode.pressed.unwrap_or_else(|| current.rect_over(rect))); self.mode.restore = current.clone(); self.mode.held = grip; - (start.origin, Some(pos), GesturePhase::Begin) + (start, Some(pos), GesturePhase::Begin) } - PressPhase::Drag { start, pos, .. } => (start.origin, Some(pos), GesturePhase::Update), - PressPhase::Release { start, pos, .. } => (start.origin, Some(pos), GesturePhase::Commit), - PressPhase::Cancel { start, .. } => (start.origin, None, GesturePhase::Cancel), + PressPhase::Drag { start, pos, .. } => (start, Some(pos), GesturePhase::Update), + PressPhase::Release { start, pos, .. } => (start, Some(pos), GesturePhase::Commit), + PressPhase::Cancel { start, .. } => (start, None, GesturePhase::Cancel), _ => return, }; + let origin = start.origin; if matches!(gesture, GesturePhase::Commit | GesturePhase::Cancel) { self.mode.pressed = None; } @@ -538,7 +539,9 @@ impl BodyHooks<'_> { Some(pos) => limits.moved(began, pos - origin), None => began, }; - let change = |rect: Rect, phase: GesturePhase| PlacementChange { rect, phase, pointer: pos, kind }; + // A move band press another component handed over (`Overlay::continue_move`) continues that component's drag. + let continued = grip.is_none() && start.handed; + let change = |rect: Rect, phase: GesturePhase| PlacementChange { rect, phase, pointer: pos, kind, continued }; if gesture == GesturePhase::Begin { self.reports.push(change(began, GesturePhase::Begin)); } @@ -600,7 +603,7 @@ impl BodyHooks<'_> { let phase = |index: usize| core.results.get(&(GRIP, Some(index as u64))).map(|result| result.press.phase); let change = |rect: Rect, phase: GesturePhase, grip: usize| { let (dx, dy, _) = GRIPS[grip]; - PlacementChange { rect, phase, pointer: None, kind: PlacementKind::Size(edge_of(dx, dy)) } + PlacementChange { rect, phase, pointer: None, kind: PlacementKind::Size(edge_of(dx, dy)), continued: false } }; let resized = |sizing: &WindowSize, desktop: Pos2| { let (dx, dy, _) = GRIPS[sizing.grip]; @@ -661,7 +664,7 @@ impl BodyHooks<'_> { let outer = facts.outer.unwrap_or(facts.inner); // Where the inner area lies in the outer rect. let inset = facts.inner.min - outer.min; - let change = |rect: Rect, phase: GesturePhase| PlacementChange { rect, phase, pointer: None, kind: PlacementKind::Move }; + let change = |rect: Rect, phase: GesturePhase| PlacementChange { rect, phase, pointer: None, kind: PlacementKind::Move, continued: false }; let pointer_of = |moving: &WindowMove| moving.at.min + inset + moving.grab; let Some(mut moving) = self.mode.moving else { let tracked = windows::shell_of(&ctx, viewport).caps.contains(Caps::OS_MOVES_TRACKED); @@ -772,7 +775,7 @@ impl BodyHooks<'_> { if matches!(kind, PlacementKind::Size(_)) && overlay_of(props).is_some_and(|overlay| overlay.resize.by_caller) { return; } - self.reports.push(PlacementChange { rect: now, phase: GesturePhase::Commit, pointer: None, kind }); + self.reports.push(PlacementChange { rect: now, phase: GesturePhase::Commit, pointer: None, kind, continued: false }); } /// The move band and the grips (16.3). A layer's move and resize the layer; those of an OS window (`os_window`) diff --git a/crates/ui-contract/src/contract/container.rs b/crates/ui-contract/src/contract/container.rs index 39148cc4f3..cb3bef55fd 100644 --- a/crates/ui-contract/src/contract/container.rs +++ b/crates/ui-contract/src/contract/container.rs @@ -321,6 +321,20 @@ pub enum SectionRhythm { Spaced, } +/// Whether a titled header that draws no rule under it (a quiet title, [`HeaderRegion::heads`]) still heads its body as +/// a rule would. An app sets it once at its root (`RootEnv::values`); the default is `Ruled`. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, crate::runtime::env::EnvValue, crate::contract::MemoProps)] +#[env(style)] +#[non_exhaustive] +pub enum QuietHeader { + /// The body's first section draws its own rule above, as under no header. + #[default] + Ruled, + /// The header heads the body: its flow starts as after a rule, so the first section under the title draws no rule + /// above it and sections after it keep theirs. Production VectorCraft's kind line over its inspector's sections. + Heads, +} + /// A header region, filled by `Container::header`. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] #[non_exhaustive] @@ -332,6 +346,9 @@ pub struct HeaderRegion { /// Whether a rule separates the header from the body, in a band of its own between them. An inline header has no /// rule. pub rule: bool, + /// Whether the header is a title that heads the body as a rule would where the app asks for it + /// ([`QuietHeader::Heads`]), though it draws none. + pub heads: bool, /// Whether a rule runs across the container's width above the header, in a band of its own at the top edge. pub rule_above: bool, /// Whether the header shares a line with the body: the header at its measured width, the body in the rest. @@ -351,7 +368,17 @@ pub struct HeaderRegion { impl HeaderRegion { /// A header with no drag band, no rule, on its own line, with no trailing region, no fill and no inset. pub const fn new() -> Self { - HeaderRegion { band: DragBand::None, rule: false, rule_above: false, inline: false, trailing: false, fill: None, inset: Pad::None, gap: None } + HeaderRegion { + band: DragBand::None, + rule: false, + heads: false, + rule_above: false, + inline: false, + trailing: false, + fill: None, + inset: Pad::None, + gap: None, + } } /// The surface of a band behind the header. @@ -391,6 +418,13 @@ impl HeaderRegion { self } + /// Whether the header is a title that heads the body as a rule would where the app asks for it + /// ([`QuietHeader::Heads`]), though it draws none. + pub const fn heads(mut self, on: bool) -> Self { + self.heads = on; + self + } + /// Whether a rule runs above the header. pub const fn rule_above(mut self, on: bool) -> Self { self.rule_above = on; diff --git a/crates/ui-contract/src/contract/cx/context.rs b/crates/ui-contract/src/contract/cx/context.rs index 4446f4c658..b3323c5ad9 100644 --- a/crates/ui-contract/src/contract/cx/context.rs +++ b/crates/ui-contract/src/contract/cx/context.rs @@ -42,6 +42,8 @@ pub(crate) trait TextResult { fn tab(&self) -> Option; /// The part's caret as a byte offset into its text after the pass; `None` while its widget has no caret. fn caret(&self) -> Option; + /// Whether the part lost key focus this pass, edited or not. + fn text_lost_focus(&self) -> bool; fn as_any(&self) -> &dyn Any; } @@ -51,6 +53,7 @@ pub(crate) struct RecordedText { pub(crate) left_by_tab: Option, pub(crate) tab: Option, pub(crate) caret: Option, + pub(crate) text_lost_focus: bool, } impl TextResult for RecordedText { @@ -70,6 +73,10 @@ impl TextResult for RecordedText { self.caret } + fn text_lost_focus(&self) -> bool { + self.text_lost_focus + } + fn as_any(&self) -> &dyn Any { self } diff --git a/crates/ui-contract/src/contract/cx/edit.rs b/crates/ui-contract/src/contract/cx/edit.rs index 875ac8e818..03b8f146a6 100644 --- a/crates/ui-contract/src/contract/cx/edit.rs +++ b/crates/ui-contract/src/contract/cx/edit.rs @@ -243,6 +243,7 @@ impl Edit for Cx<'_, C> { response.activation_mods = if self.events.is_empty() { craft_keymap::Mods::NONE } else { self.activation().map_or(craft_keymap::Mods::NONE, |a| a.mods) }; response.left_by_tab = self.core.texts.as_ref().and_then(|(_, text)| text.left_by_tab()); + response.text_lost_focus = self.core.texts.as_ref().is_some_and(|(_, text)| text.text_lost_focus()); response.tab = self.core.texts.as_ref().and_then(|(_, text)| text.tab()); response.caret = self.core.texts.as_ref().and_then(|(_, text)| text.caret()); response.unparsed = self.core.text_invalid; diff --git a/crates/ui-contract/src/contract/editor.rs b/crates/ui-contract/src/contract/editor.rs index 78e8e9e13a..d20a202b6e 100644 --- a/crates/ui-contract/src/contract/editor.rs +++ b/crates/ui-contract/src/contract/editor.rs @@ -72,7 +72,10 @@ pub(crate) fn run(cx: &mut Cx<'_, C>, ui: &mut Ui, step: &mut supe } let (ctx, id) = (cx.core.ctx.clone(), cx.core.id); let widget = ImeSurface::of(id, decl.key).widget(); - let focused = egui_editor::show(ui, widget, decl.rect, egui_focus::event_filter(keys.keep, false)); + let focusable = super::steps::takes_focus(cx.core.resolved); + let focused = egui_editor::show(ui, widget, decl.rect, egui_focus::event_filter(keys.keep, false), focusable); + // The focus widget is the component's, enabled or not: it is never one of the app's own widgets (`take_app_widgets`). + crate::runtime::pointer::record_text_widget(&ctx, widget, id); let read_only = cx.core.resolved.read_only || !cx.core.resolved.enabled; let mut inputs: Vec<(Order, EditorInput)> = Vec::new(); if focused { diff --git a/crates/ui-contract/src/contract/items.rs b/crates/ui-contract/src/contract/items.rs index 8ce1170bda..76235defe3 100644 --- a/crates/ui-contract/src/contract/items.rs +++ b/crates/ui-contract/src/contract/items.rs @@ -152,13 +152,15 @@ struct Renaming { draft: String, gesture: GestureId, focused: bool, + /// The field has held the focus: losing it afterwards ends the rename. + held: bool, /// The field opened with a draft the collection proposed that differs from the row's text. proposed: bool, } impl Default for Renaming { fn default() -> Self { - Renaming { key: None, draft: String::new(), gesture: GestureId::default(), focused: false, proposed: false } + Renaming { key: None, draft: String::new(), gesture: GestureId::default(), focused: false, held: false, proposed: false } } } diff --git a/crates/ui-contract/src/contract/items/hooks.rs b/crates/ui-contract/src/contract/items/hooks.rs index f4166d548c..a274babf17 100644 --- a/crates/ui-contract/src/contract/items/hooks.rs +++ b/crates/ui-contract/src/contract/items/hooks.rs @@ -678,6 +678,18 @@ impl ShapeHooks for ItemsHooks<'_, '_, C> { if self.scrolls && !ui.is_sizing_pass() && !crate::runtime::measure::active(&ctx) { self.follow_anchor(comp, (&ctx, id), &layout, (rect, rtl)); } + // The renamed item left the source (removed, renamed or hidden by the app, or folded away): its editor is gone, so the + // rename ends rather than waiting for the item to return and open the old draft again. + if let Some(key) = self.renaming.key.clone() + && !self.ended_rename + && !ui.is_sizing_pass() + && !crate::runtime::measure::active(&ctx) + && self.index_of(&key).is_none() + { + let before = Rename { key, name: self.renaming.draft.clone() }; + self.events.push(CollectionEvent::Rename(EditEvent::cancel(self.renaming.gesture, CancelReason::Removed, Some(Mixed::Same(before))))); + self.ended_rename = true; + } if self.ended_rename { self.renaming = Renaming::default(); if self.refocus { @@ -956,6 +968,13 @@ impl ItemsHooks<'_, '_, C> { let shifted = editor.submitted && editor.submit_mods.shift; let before = Mixed::Same(Rename { key: key.clone(), name: name.clone() }); let (end, escaped) = rename_input(ctx, &editor, rtl, &mut self.renaming.focused, &mut self.refocus); + // A pass that only measures keeps no focus, so it neither opens nor ends the hold. + let real = !row_ui.is_sizing_pass() && !crate::runtime::measure::active(ctx); + let has_focus = focus::is_focused(ctx, editor.response.id); + // The field lost the focus with nothing typed (a click elsewhere): the text field reports no event for an + // unedited name, so the rename ends here, as it does by Tab and as a typed name does by committing. + let blurred = real && self.renaming.held && !has_focus; + self.renaming.held |= real && has_focus; match end { None if !editor.events.is_empty() => {} None if escaped => { @@ -996,6 +1015,10 @@ impl ItemsHooks<'_, '_, C> { self.events.push(CollectionEvent::Rename(EditEvent::cancel(gesture, CancelReason::Blur, Some(before)))); self.ended_rename = true; } + None if blurred => { + self.events.push(CollectionEvent::Rename(EditEvent::cancel(gesture, CancelReason::Blur, Some(before)))); + self.ended_rename = true; + } _ => {} } if let Some(forward) = editor.left_by_tab.filter(|_| self.ended_rename) { diff --git a/crates/ui-contract/src/contract/items/press.rs b/crates/ui-contract/src/contract/items/press.rs index cf6819543d..f107bac6db 100644 --- a/crates/ui-contract/src/contract/items/press.rs +++ b/crates/ui-contract/src/contract/items/press.rs @@ -84,10 +84,12 @@ impl ItemsHooks<'_, '_, C> { _ => None, }; // Under `AutoScroll` a middle press on the rows starts or ends the latch (the items step's `middle_scroll`) and - // picks no row. + // picks no row. In a collection that senses `MIDDLE_CLICK` the middle click is the row's own action + // (`CollectionEvent::MiddleClick`: a tab strip closes the tab), so the press picks no row there either. + let middle_clicks = cx.core.root_sense.contains(craft_behavior::Sense::MIDDLE_CLICK); if let PressPhase::Down { start, .. } = cx.core.press.phase && local(start.origin).y >= 0.0 - && !(start.button == PointerButton::Middle && props.middle_button == MiddleButton::AutoScroll) + && !(start.button == PointerButton::Middle && (props.middle_button == MiddleButton::AutoScroll || middle_clicks)) { // A second press, slow or not, ends the wait of the first. self.drags.slow = None; diff --git a/crates/ui-contract/src/contract/items/rename.rs b/crates/ui-contract/src/contract/items/rename.rs index 492487ba51..7ff121b6ef 100644 --- a/crates/ui-contract/src/contract/items/rename.rs +++ b/crates/ui-contract/src/contract/items/rename.rs @@ -17,7 +17,7 @@ impl ItemsHooks<'_, '_, C> { let gesture = crate::runtime::edit::next_gesture_id(&cx.core.ctx); let before = Rename { key: key.clone(), name: draft.clone() }; self.events.push(CollectionEvent::Rename(EditEvent::begin(gesture, Mixed::Same(before), cx.core.label_arc(), None))); - self.renaming = Renaming { key: Some(key), draft, gesture, focused: false, proposed }; + self.renaming = Renaming { key: Some(key), draft, gesture, focused: false, held: false, proposed }; } /// A rename requested from outside (`request_rename`): the lead moves to the item, the item is revealed and its diff --git a/crates/ui-contract/src/contract/label.rs b/crates/ui-contract/src/contract/label.rs index 881564478e..3becbef258 100644 --- a/crates/ui-contract/src/contract/label.rs +++ b/crates/ui-contract/src/contract/label.rs @@ -14,7 +14,7 @@ pub use leaf::colon_of; pub(crate) use place::{control_after, label_gap}; pub(crate) use props::inside; pub use props::{ - CaptionColumn, CaptionInk, CellWidth, FieldLayout, GlyphColon, GlyphLabel, InsideLabel, LabelKind, LabelPress, LabelScheme, LinkLabelInk, Scrub, - SideLabel, + CaptionColumn, CaptionInk, CellWidth, FieldLayout, GlyphColon, GlyphLabel, InsideLabel, LabelKind, LabelPress, LabelScheme, LinkLabelInk, + LinkLabelUnderline, Scrub, SideLabel, }; pub(crate) use step::{LabelIn, LeafLabel, Trailing, flow_leaf, in_column, leaf, leaf_under, report_after_reach, run, show_leaf_in_flow}; diff --git a/crates/ui-contract/src/contract/label/leaf.rs b/crates/ui-contract/src/contract/label/leaf.rs index 3e0f7cb32d..0f145b7242 100644 --- a/crates/ui-contract/src/contract/label/leaf.rs +++ b/crates/ui-contract/src/contract/label/leaf.rs @@ -1,11 +1,11 @@ //! The side label as a leaf component: its node, press state, reset dot and colon. -use super::props::{CaptionInk, FieldLayout, Glyph, GlyphColon, LabelKind, LabelScheme, LinkLabelInk}; +use super::props::{CaptionInk, FieldLayout, Glyph, GlyphColon, LabelKind, LabelScheme, LinkLabelInk, LinkLabelUnderline}; use super::step::LabelIn; use crate::contract::InBar; use crate::contract::{Component, Props}; use crate::contract::{Cx, MeasureCx, PaintUi, PartsCx, Styled as _}; -use crate::primitives::{IconSpec, Span, TextRun, Wrap}; +use crate::primitives::{IconSpec, PaintShape, Span, StrokeWidth, TextRun, Wrap}; use crate::runtime::access::{Access, Name}; use crate::runtime::env::{Env, Label}; use crate::runtime::words::CommonWords; @@ -36,6 +36,9 @@ pub(super) struct LabelStyle { name: TextLook, /// The glyph and icon: their own ink (`None`), `text.disabled` with a disabled control. glyph: Stateful>, + /// The width (`stroke.thin`) of a one-line link's underline where the label draws it inside its rect + /// ([`LinkLabelUnderline::Inside`]); `None` where egui draws it with the text. + underline: Option, } /// What the label leaf reports. @@ -190,6 +193,7 @@ impl Component for LabelLeaf { let off = Some(cx.color(cx.tokens.color.text.disabled)); Stateful::new(None).off(States::new(None, None, None, off)) }, + underline: (cx.env::() == LinkLabelUnderline::Inside).then_some(cx.tokens.stroke.thin), } } @@ -366,8 +370,12 @@ impl Component for LabelLeaf { let name_ink = cx.resolve(&cx.style.name.color); let colon = self.colon.as_deref().map(|colon| TextRun::new(colon).role(cx.style.name.role).color(name_ink)); let colon_width = colon.as_ref().map_or(0.0, |run| draw.layout(run, f32::INFINITY).size().x); - let named = - if self.link { TextRun::spans(vec![Span::new(cx.core.resolved.label).underline()]) } else { TextRun::new(cx.core.resolved.label) }; + let underline = cx.style.underline.filter(|_| self.link && !wrapped); + let named = if self.link && underline.is_none() { + TextRun::spans(vec![Span::new(cx.core.resolved.label).underline()]) + } else { + TextRun::new(cx.core.resolved.label) + }; let run = named.role(cx.style.name.role).color(name_ink); let run = if wrapped { run.wrap(Wrap::Wrap) } else { run.elide() }; let name = draw.layout(&run, (rest.rect().width() - colon_width).max(0.0)).size(); @@ -375,6 +383,11 @@ impl Component for LabelLeaf { let name_at = if wrapped { Rect::from_min_size(egui::pos2(name_rect.min.x, middle - line / 2.0), name) } else { centred(name_rect, name.y) }; draw.text(name_at, &run); + if let Some(width) = underline { + // egui's underline lies on the text box's bottom edge, which a rect shorter than the box would clip. + let y = name_at.bottom().min(cx.rect.bottom()) - width / 2.0; + draw.stroke(&PaintShape::Path(vec![egui::pos2(name_at.left(), y), egui::pos2(name_at.right(), y)]), StrokeWidth::Thin, name_ink); + } let after = match colon { Some(run) => { let (colon_rect, after) = after.take_start(colon_width); diff --git a/crates/ui-contract/src/contract/label/props.rs b/crates/ui-contract/src/contract/label/props.rs index 548ed5e223..641b60b456 100644 --- a/crates/ui-contract/src/contract/label/props.rs +++ b/crates/ui-contract/src/contract/label/props.rs @@ -136,6 +136,21 @@ pub enum LinkLabelInk { Neutral, } +/// Where a one-line link label ([`SideLabel::link`]) draws its underline. An app sets it once at its root +/// (`RootEnv::values`); the default is `Edge`. Neither changes the label's rect. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, crate::runtime::env::EnvValue, crate::contract::MemoProps)] +#[env(style)] +#[non_exhaustive] +pub enum LinkLabelUnderline { + /// On the name's text box's bottom edge, where egui strokes an underlined span. The label's rect, which clips its + /// paint, can stand shorter than that box, and then it cuts the underline away. + #[default] + Edge, + /// On the text box's bottom edge or the rect's, whichever is higher, so the rect always holds it: VectorCraft's + /// "Stroke" and "Opacity:" links, as production drew them. + Inside, +} + /// The ink of a side label's name, other than a link's ([`LinkLabelInk`]) and the text after a check box or a radio, /// which reads at full ink. An app sets it once at its root (`RootEnv::values`); the default is the muted ink of a /// caption that reads as secondary. diff --git a/crates/ui-contract/src/contract/mod.rs b/crates/ui-contract/src/contract/mod.rs index ba740f9eed..60c7bfd0c1 100644 --- a/crates/ui-contract/src/contract/mod.rs +++ b/crates/ui-contract/src/contract/mod.rs @@ -69,8 +69,8 @@ pub use container::InBar; pub use container::InMenu; pub use container::{ BandFill, Bracket, Collapse, ContainerProps, DragBand, EndRegion, FooterPlace, FooterRegion, Gap, HeaderEdge, HeaderParts, HeaderRegion, - LeastWidth, Mount, Notch, POPUP_PAD, Pad, PadEdges, PaneEdge, Scroll, ScrollAnchor, ScrollAxes, ScrollIndicator, SectionRhythm, ShellPane, - Sizing, ThemeScope, WrapWidth, + LeastWidth, Mount, Notch, POPUP_PAD, Pad, PadEdges, PaneEdge, QuietHeader, Scroll, ScrollAnchor, ScrollAxes, ScrollIndicator, SectionRhythm, + ShellPane, Sizing, ThemeScope, WrapWidth, }; pub use craft_tracked::{PlainData, Revision, Tracked}; pub use craft_ui_macros::{CommandSet, Component, Pattern, PlainData, Props, register_contract}; @@ -95,7 +95,7 @@ pub use items::{measure_item, show_item, show_item_in_flow}; pub use label::colon_of; pub use label::{ CaptionColumn, CaptionInk, CellWidth, FieldLabelRole, FieldLayout, GlyphColon, GlyphLabel, InsideLabel, LabelKind, LabelPress, LabelScheme, - LinkLabelInk, Scrub, SideLabel, + LinkLabelInk, LinkLabelUnderline, Scrub, SideLabel, }; pub use lazy::Lazy; #[doc(hidden)] diff --git a/crates/ui-contract/src/contract/overlay/dismissal.rs b/crates/ui-contract/src/contract/overlay/dismissal.rs index 71d475b847..75f8a6c7de 100644 --- a/crates/ui-contract/src/contract/overlay/dismissal.rs +++ b/crates/ui-contract/src/contract/overlay/dismissal.rs @@ -139,7 +139,20 @@ fn escape(ctx: &Context, layer: &Layer<'_>, scope: Option, inside: } // The focus may be in no record of the layer's host: the Escape is read from the events of the frame. crate::runtime::replay::note_input(ctx, crate::runtime::inputs::Input::Sent); - let step = keys::scope_escape(ctx, policy.cancel, pointer::press_captured(ctx), false)?; + // A Menu may close after its OWN child's captured press has already been cancelled by this Escape. The + // first Escape still goes only to that press: do not manufacture a component Cancel or relax another scope's + // capture priority. Require the current actual area and the arena's same-pass Escape outcome, not a latched + // native press target, old registration or merely a capture that has disappeared. + let cancelled_menu_press = policy.kind == craft_behavior::ScopeKind::Menu + && policy.cancel == CancelRule::Close + && layer.overlay.rank == Rank::Popup + && matches!(pointer::cancel_of_pass(ctx), Some(craft_behavior::PressCancel::Escape)) + && overlay::current_egui_layer(ctx, layer.id).is_some_and(|area| crate::primitives::sensing::escape_cancelled_in_layer(ctx, area)); + let step = if cancelled_menu_press { + craft_behavior::focus::EscapeStep::CloseScope + } else { + keys::scope_escape(ctx, policy.cancel, pointer::press_captured(ctx), false)? + }; if !matches!(step, craft_behavior::focus::EscapeStep::CloseScope) { return None; } diff --git a/crates/ui-contract/src/contract/overlay/props.rs b/crates/ui-contract/src/contract/overlay/props.rs index ae87777ef2..94340a45e7 100644 --- a/crates/ui-contract/src/contract/overlay/props.rs +++ b/crates/ui-contract/src/contract/overlay/props.rs @@ -597,4 +597,7 @@ pub struct PlacementChange { pub pointer: Option, /// What changed the rect. pub kind: PlacementKind, + /// The move continues a press that went down outside the overlay and was handed to its move band + /// ([`Overlay::continue_move`]): a drag the host began elsewhere (a panel's tab) that the layer carries on. + pub continued: bool, } diff --git a/crates/ui-contract/src/contract/run.rs b/crates/ui-contract/src/contract/run.rs index c87b86cf68..942b93fd31 100644 --- a/crates/ui-contract/src/contract/run.rs +++ b/crates/ui-contract/src/contract/run.rs @@ -702,13 +702,10 @@ fn own_sense(e: &dyn ErasedPass<'_>, resolved: &Resolved, inert: bool) -> Sense } /// The widget that holds the component's text or editor and the keys it keeps, when it has either. -fn text_holder(ctx: &Context, id: Id, parts: &PartsStep, base: focus::KeyUse, memory: &mut MemoryStage) -> (Option, Option) { +fn text_holder(id: Id, parts: &PartsStep, base: focus::KeyUse) -> (Option, Option) { let text = parts.text.decl.as_ref().map(|decl| { let decl = &decl.part; - let widget = crate::primitives::text_adapter::text_id(id, decl.key); - let held = crate::contract::text::held_selection(memory, id); - let draft = crate::contract::text::draft(memory, id); - (widget, crate::primitives::text_adapter::keys_of(ctx, widget, held, draft.as_deref().unwrap_or(&decl.shown), base, &decl.options)) + (crate::primitives::text_adapter::text_id(id, decl.key), crate::primitives::text_adapter::keys_of(base, &decl.options)) }); let editor = parts.text.editor.as_ref().map(|decl| (crate::primitives::ImeSurface::of(id, decl.key).widget(), super::editor::keys_of(base, decl.purpose))); @@ -718,6 +715,17 @@ fn text_holder(ctx: &Context, id: Id, parts: &PartsStep, base: focus::KeyUse, me } } +/// `keys`, those of the component's text part, with the edits it cannot run now inactive (`text_adapter::with_idle`), +/// read after the text step, so they are as the pass's edits left the selection and the undo steps. +fn idle_keys(ctx: &Context, id: Id, parts: &PartsStep, keys: focus::KeyUse, memory: &mut MemoryStage) -> focus::KeyUse { + let Some(decl) = &parts.text.decl else { return keys }; + let decl = &decl.part; + let held = crate::contract::text::held_selection(memory, id); + let draft = crate::contract::text::draft(memory, id); + let widget = crate::primitives::text_adapter::text_id(id, decl.key); + crate::primitives::text_adapter::with_idle(ctx, widget, held, draft.as_deref().unwrap_or(&decl.shown), keys) +} + /// What the stops of a component read: the owner, its place in a member group and the text it holds. struct StopsStep<'a> { ctx: &'a Context, @@ -1000,7 +1008,7 @@ fn sense_steps(p: &mut Pass<'_, '_, '_>, ui: &mut Ui, host_at: Option, e } steps::check_parts(&ctx, facts.name, &parts); let keys = e.keys(); - let (holder_widget, text_keys) = text_holder(&ctx, id, &parts, keys, &mut *e.core().memory); + let (holder_widget, text_keys) = text_holder(id, &parts, keys); let own = own_sense(e, resolved, inert); // The collection handles a row's click, but its access node must still offer the redirected action. let unnarrowed = own; @@ -1175,9 +1183,10 @@ fn update_steps(p: &mut Pass<'_, '_, '_>, env: &Env, h: &HostStep) { } e.updated(); steps::record_context(e.core_ref()); - // The stops register after `update`, which says whether the component joins its body's roving group. - let at = - StopsStep { ctx, id, rtl, env, resolved: p.resolved, holder_widget: h.holder_widget, member: h.member, own: h.own, text_keys: h.text_keys }; + // The stops register after `update`, which says whether the component joins its body's roving group, and after + // the text step, so a Select All of the pass makes Copy active. + let text_keys = h.text_keys.map(|keys| idle_keys(ctx, id, &h.parts, keys, &mut *e.core().memory)); + let at = StopsStep { ctx, id, rtl, env, resolved: p.resolved, holder_widget: h.holder_widget, member: h.member, own: h.own, text_keys }; stops_step(at, e, facts, &h.parts); // The body's group registers after `update`, which may change its rules from what the component knows now. if let Some(roving) = e.roving() { diff --git a/crates/ui-contract/src/contract/steps/value.rs b/crates/ui-contract/src/contract/steps/value.rs index e3e265fb8a..ceb49e352a 100644 --- a/crates/ui-contract/src/contract/steps/value.rs +++ b/crates/ui-contract/src/contract/steps/value.rs @@ -102,6 +102,9 @@ fn resolve_value(comp: &mut dyn ValueSource, stage: &mut MemoryStag // ends here, the first pass it is shown again. let removed = !crate::runtime::memory::shown_last_pass(stage.ctx(), id); if stage.shown::>(slot).is_running() { + // A typing run cut short by the removal is forgotten: its text reached the binding as it was typed, and the value + // from before it may be long stale by the time the component is shown again. + let typing_cut_short = removed && crate::contract::text::run_open(stage, id); // `(given, value)` of a single-valued binding the app owns. let host = comp.binding().and_then(|bind| match bind.get() { Some(Mixed::Same(value)) if !bind.is_kept() => Some((bind.is_given(), value)), @@ -130,8 +133,8 @@ fn resolve_value(comp: &mut dyn ValueSource, stage: &mut MemoryStag gesture.last_given = Some(value.clone()); } if let Some(reason) = reason { - // The document moved under the gesture, so there is nothing to restore. - let before = gesture.before.clone().filter(|_| !reason.document_moved()); + // The document moved under the gesture, so there is nothing to restore; nor for a typing run cut short. + let before = gesture.before.clone().filter(|_| !reason.document_moved() && !typing_cut_short); cancelled = Some(EditEvent::cancel(gesture.id, reason, before)); *gesture = gesture.ended(true); } diff --git a/crates/ui-contract/src/contract/text.rs b/crates/ui-contract/src/contract/text.rs index beae157bcf..5a855c7f06 100644 --- a/crates/ui-contract/src/contract/text.rs +++ b/crates/ui-contract/src/contract/text.rs @@ -36,6 +36,11 @@ pub(crate) fn held_selection(memory: &mut MemoryStage, id: egui::Id) -> Option<( memory.shown::(state_id(id)).held_selection } +/// Whether the text part of the component `id` has a typing run open, as its last pass left it. +pub(crate) fn run_open(memory: &MemoryStage, id: egui::Id) -> bool { + memory.recall::(state_id(id)).start.is_some() +} + /// The draft the text part of the component `id` holds while a typing run is open. pub(crate) fn draft(memory: &mut MemoryStage, id: egui::Id) -> Option { memory.shown::(state_id(id)).draft.clone() @@ -94,8 +99,9 @@ pub(crate) fn run_selections(core: &mut super::cx::CxCore<'_>, selections: &[Sel pub(crate) struct TextDecl { pub part: TextPart, - /// A `Resolve` for the component's value type, invoked after the adapter records the pass. - resolve: Box, + /// A `Resolve` for the component's value type, which the text step takes and invokes after the adapter records + /// the pass; the part stays declared, so the stops read its keys as the pass's edits left them. + resolve: Option>, values: ValueOps, } @@ -163,14 +169,16 @@ struct Resolved { /// The typing run over the state the adapter recorded this pass, the component's value (`None` while mixed) and /// whether a commit is due. -type Resolve = Box, bool) -> Resolved>; +type Resolve = Box, bool, bool) -> Resolved>; /// Turns what the adapter recorded this pass into the typing run's events: a parsed draft applies in the pass it /// is typed, and a commit proposes and commits in one pass. `fallback` is the value the part shows, the run's start -/// while the component's value is mixed. +/// while the component's value is mixed. The closure's last argument says whether the part keeps its text on Escape +/// this pass: the option alone is not enough, since a part that went read-only or disabled mid-run takes Escape as a +/// plain field does. fn resolver(codec: K, options: &TextOptions, rect: Rect, fallback: K::Value) -> Resolve { let (live, limit, clear_on_escape) = (options.live, options.limit, options.clear_on_escape); - Box::new(move |state, value, commit_now| { + Box::new(move |state, value, commit_now, keep_on_escape| { let value = value.unwrap_or(&fallback); let mut typing = TypingRun::new(codec).live(live); if let Some(limit) = limit { @@ -211,6 +219,15 @@ fn resolver(codec: K, options: &TextOptions, rect: R events.push(TextEvent::Cancel(CancelReason::Escape)); } } + Some(End::Escape) if keep_on_escape => { + // The text stays: an open run commits once, neither submitted nor cancelled. + escaped = true; + if let (Ended::Commit(committed), note) = typing.commit_tagged(&mut run) { + committed_note = Some(note); + state.normalised = Some(typing.codec().normalise(&draft_text, &committed)); + events.push(TextEvent::Commit(committed)); + } + } Some(End::Escape) => { escaped = true; if clear_on_escape && !run.is_open() { @@ -293,7 +310,7 @@ impl PartsCx<'_, C> { shown, options: declared, }, - resolve, + resolve: Some(resolve), values: ValueOps::of::(), }); } @@ -401,6 +418,10 @@ struct PreparedText { was_focused: bool, /// The window lost focus in this pass while the text part had it. window_blur: bool, + /// The part's edit menu is open and holds its editing focus. + menu_open: bool, + /// Focus moved from the text part to another part of its component in this pass. + left_for_part: bool, } /// Run the text adapter and adjust focus before the component's typed resolver handles its value. @@ -440,6 +461,8 @@ fn prepare(core: &mut CxCore<'_>, ui: &mut Ui, decl: &TextPart, state: &mut Text let ink = decl.options.ink.map_or(ink, |own| crate::style::ink_color(&crate::runtime::env::Env::of(ui).tokens, own)); let ink = if enabled { ink } else { crate::style::rgba_color(crate::runtime::env::Env::of(ui).tokens.color.text.disabled) }; let held = core.popup(EDIT_MENU).is_open_in(core); + // The text the part shows now: its resting text while it is idle and has one, else the value's own. + let current = decl.options.resting.as_deref().filter(|_| !focused && !held && state.draft.is_none()).unwrap_or(&decl.shown); // A menu bar or a menu the keyboard goes back to the part from has the focus: their Cut and Copy act on the // selection the part keeps for them. Only a part that had the focus last pass, or keeps a selection already, can be // gone back to: asking reads the focus, which a part that never held it has not read, so its replay stays true. @@ -454,14 +477,24 @@ fn prepare(core: &mut CxCore<'_>, ui: &mut Ui, decl: &TextPart, state: &mut Text // caret. let caret_placed = state.preedit.is_none() && adapter::place_caret(&ctx, widget, state.draft.as_deref().unwrap_or(&decl.shown), decl.options.caret); - serve_access(core, state, widget, &decl.shown, read_only); + serve_access(core, state, widget, current, read_only); let select_all = (std::mem::take(&mut state.select_all) || decl.options.select_all) && !crate::runtime::ime::composing(&ctx, widget); if select_all { - let len = state.draft.as_deref().unwrap_or(&decl.shown).chars().count(); + let len = state.draft.as_deref().unwrap_or(current).chars().count(); adapter::select(&ctx, widget, 0, len); } core.surface_slot = Some(ui.painter().add(egui::Shape::Noop)); let menu_held = state.held_selection.is_some(); + // Focus that arrived between passes (a request after the field was drawn, which takes effect at the end of that + // pass) places the caret before this pass's input is applied, so the first text typed replaces a selection. Focus + // back from the edit menu is no arrival. + let arrived_before = focused && !was_focused && !held && !menu_held && core.active_part().is_none(); + // Focus that arrives while a button is down over the field came with a press on it. + let frame = crate::runtime::pointer::frame_raw(&ctx); + let by_pointer = !frame.buttons.is_empty() && frame.pos.is_some_and(|at| core.visible.contains(at)); + if arrived_before { + arrive(&ctx, widget, decl, state, by_pointer, select_all); + } let out = adapter::run( state, adapter::AdapterIn { @@ -508,22 +541,43 @@ fn prepare(core: &mut CxCore<'_>, ui: &mut Ui, decl: &TextPart, state: &mut Text crate::runtime::egui::repaint::request(&ctx); } // A select asked for in the pass that brings focus (`Cx::select_all_text`) is kept, as `select_on_focus` keeps it. - if out.focused && !left_for_part && !was_focused && !back_from_menu { - let len = decl.shown.chars().count(); - // A dialog that opens on this field selects its whole text whatever the codec's caret, so typing replaces it - // (photocraft#15540). - let opened = !decl.options.keep_caret_on_open - && crate::runtime::focus::focused_rec(&ctx) - .and_then(|rec| crate::runtime::focus::origin(&ctx, &rec)) - .is_some_and(|origin| origin == crate::runtime::focus::FocusOrigin::Open); - match if opened || select_all { Caret::All } else { decl.caret } { - Caret::All => adapter::select(&ctx, widget, 0, len), - // A bound caret is where the app put it: focus arriving keeps it. - _ if decl.options.caret.is_some() => {} - _ => adapter::select(&ctx, widget, len, len), + if out.focused && !left_for_part && !was_focused && !back_from_menu && !arrived_before { + arrive(&ctx, widget, decl, state, by_pointer, select_all); + } + if state.select_on_click { + if out.clicked && out.focused { + adapter::select(&ctx, widget, 0, decl.shown.chars().count()); + state.select_on_click = false; + } else if !out.focused || frame.buttons.is_empty() { + // A drag, or a press that ended elsewhere: the pointer's caret or range stays. + state.select_on_click = false; } } - PreparedText { widget, out, read_only, list_open, caret_visible, commit_now, was_focused, window_blur } + PreparedText { widget, out, read_only, list_open, caret_visible, commit_now, was_focused, window_blur, menu_open: held, left_for_part } +} + +/// Places the caret of the text part's widget `widget` as focus arrives on the part: where the codec puts it, or over +/// the whole text for `select_on_focus`, or when a select was asked for (`select_all`). `select_on_focus` is for focus +/// by key or request: focus a pointer press brings (`by_pointer`) keeps the caret or range the pointer makes, and a +/// plain click selects the whole text once it is released (`TextState::select_on_click`). +fn arrive(ctx: &egui::Context, widget: egui::Id, decl: &TextPart, state: &mut TextState, by_pointer: bool, select_all: bool) { + let len = decl.shown.chars().count(); + // A dialog that opens on this field selects its whole text whatever the codec's caret, so typing replaces it + // (photocraft#15540). + let opened = !decl.options.keep_caret_on_open + && crate::runtime::focus::focused_rec(ctx) + .and_then(|rec| crate::runtime::focus::origin(ctx, &rec)) + .is_some_and(|origin| origin == crate::runtime::focus::FocusOrigin::Open); + if by_pointer && decl.options.select_on_focus && !opened && !select_all { + state.select_on_click = true; + return; + } + match if opened || select_all { Caret::All } else { decl.caret } { + Caret::All => adapter::select(ctx, widget, 0, len), + // A bound caret is where the app put it: focus arriving keeps it. + _ if decl.options.caret.is_some() => {} + _ => adapter::select(ctx, widget, len, len), + } } /// Step 8b: runs the text adapter at the part's rect, then the typing run over what it recorded, and applies the @@ -537,8 +591,9 @@ pub(crate) fn run( ink: egui::Color32, underline: f32, ) { - let Some(decl) = step.decl.take() else { return }; - let Ok(resolve) = decl.resolve.downcast::>>() else { + let Some(decl) = step.decl.as_mut() else { return }; + let Some(resolve) = decl.resolve.take() else { return }; + let Ok(resolve) = resolve.downcast::>>() else { debug_assert!(false, "the text part's codec value is the component's value"); return; }; @@ -547,9 +602,14 @@ pub(crate) fn run( let (ctx, id) = (cx.core.ctx.clone(), cx.core.id); let state_id = state_id(id); let mut state = std::mem::take(cx.core.memory.shown::(state_id)); + // A part that was not shown last pass lost its focus, and its typing run with it: the run is forgotten (step 4 + // ended its gesture without putting back the value from before it), and the part starts afresh from its value. + if !crate::runtime::memory::shown_last_pass(&ctx, id) { + state = TextState::default(); + } (decl.values.resync)(&mut state, shown_copy(cx).as_ref()); let text = prepare(cx.core, ui, part, &mut state, AdapterSettings { keys, rtl, ink, underline }, step.commit_now); - let PreparedText { widget, out, read_only, list_open, caret_visible, commit_now, was_focused, window_blur } = text; + let PreparedText { widget, out, read_only, list_open, caret_visible, commit_now, was_focused, window_blur, menu_open, left_for_part } = text; if part.options.complete.is_some() { drive_completions(cx, &mut state); } @@ -562,7 +622,14 @@ pub(crate) fn run( state.end = Some(End::Rewrite { refuses: false }); } } - let resolved = resolve(&mut state, cx.value(), commit_now); + let keeps_escape = part.options.keep_on_escape && !part.options.clear_on_escape && !read_only && cx.core.resolved.enabled && part.options.enabled; + let resolved = resolve(&mut state, cx.value(), commit_now, keeps_escape); + if resolved.escaped && keeps_escape && !state.invalid { + // The same Escape goes on to the enclosing scope in this pass, which still finds this focused stop; the field + // lets focus go once the scopes have run. + cx.core.intents.pass_on(craft_behavior::Intent::Cancel); + crate::runtime::focus::surrender_after_scopes(&ctx, widget); + } if resolved.refused { crate::runtime::frame::refuse(&ctx); } @@ -579,7 +646,7 @@ pub(crate) fn run( cx.core.text_invalid = state.invalid; cx.core.text_unparsed = part.options.unparsed.clone().filter(|_| state.invalid); cx.core.escape_to_list = state.completions.open || list_open; - if state.draft.is_some() || (part.options.clear_on_escape && !out.layout.full().is_empty()) { + if state.draft.is_some() || (part.options.clear_on_escape && !out.layout.full().is_empty()) || (keeps_escape && out.focused) { keys::hold_escape(&ctx, id); } let completions = state.completions.items.clone(); @@ -594,7 +661,11 @@ pub(crate) fn run( outcome.clicked = out.clicked; // The focus service moved focus off the widget with Tab before this pass's widgets ran. let left_by_tab = if was_focused && !out.focused { crate::runtime::focus::tabbed_off(&ctx, widget) } else { None }; - cx.core.texts = Some((part.key, Box::new(RecordedText { outcome, submit_mods: resolved.submit_mods, left_by_tab, tab: out.tab, caret }))); + // The edit menu holds the part's editing focus while it is open (`was_focused` stays true through it): key focus + // that is with the menu is not lost until the menu is gone and focus is not back. + let text_lost_focus = was_focused && !menu_open && (!out.focused || left_for_part); + cx.core.texts = + Some((part.key, Box::new(RecordedText { outcome, submit_mods: resolved.submit_mods, left_by_tab, tab: out.tab, caret, text_lost_focus }))); apply_events(cx, resolved.events); cx.core.memory.shown::(state_id).seen = shown_copy(cx); cx.core.submitted |= resolved.submitted; diff --git a/crates/ui-contract/src/contract/values.rs b/crates/ui-contract/src/contract/values.rs index b735a85fdb..df6c71379f 100644 --- a/crates/ui-contract/src/contract/values.rs +++ b/crates/ui-contract/src/contract/values.rs @@ -646,6 +646,10 @@ pub struct EditResponse { /// Tab (`Some(true)`) or Shift+Tab (`Some(false)`) moved focus off the text part in this pass, which ended its /// edit; a list's rename continues on the next or previous row. pub left_by_tab: Option, + /// The text part lost key focus in this pass, with or without an edit: a click elsewhere, Tab, or an Escape that + /// keeps the text (`keep_on_escape`). It decides nothing; `submitted`, `escaped` and `left_by_tab` stay their own + /// facts. False for a component with no text part. + pub text_lost_focus: bool, /// The edit was abandoned with Escape. pub escaped: bool, /// A text part holds text that does not parse: the value is the last one that did, and a form that commits the @@ -692,6 +696,7 @@ impl EditResponse { submit_mods: craft_keymap::Mods::NONE, activation_mods: craft_keymap::Mods::NONE, left_by_tab: None, + text_lost_focus: false, escaped: false, unparsed: false, validity, @@ -715,6 +720,7 @@ impl EditResponse { submit_mods: craft_keymap::Mods::NONE, activation_mods: craft_keymap::Mods::NONE, left_by_tab: None, + text_lost_focus: false, escaped: false, unparsed: false, validity: Validity::Ok, @@ -756,6 +762,7 @@ impl EditResponse { submit_mods: self.submit_mods, activation_mods: self.activation_mods, left_by_tab: self.left_by_tab, + text_lost_focus: self.text_lost_focus, escaped: self.escaped, unparsed: self.unparsed, validity, diff --git a/crates/ui-contract/src/primitives/sensing.rs b/crates/ui-contract/src/primitives/sensing.rs index c7486de5a7..b2d1f5c9d3 100644 --- a/crates/ui-contract/src/primitives/sensing.rs +++ b/crates/ui-contract/src/primitives/sensing.rs @@ -244,6 +244,8 @@ impl Hovered { #[derive(Clone, Copy, Debug, Default)] pub(crate) struct Outcome { pass: u64, + /// The layer in which this outcome was actually resolved, even if an early result is later reused. + layer: Option, pub hover: Hovered, /// A shape of the arena lies under the pointer, on top or not. pub contains: bool, @@ -431,31 +433,57 @@ pub fn cancel_press_of(ctx: &Context, owner: Id) { /// Gives the held primary press to the part `part` of the root `owner`, as a drag from `origin`: the move band of a /// window floated from a torn-off group carries on the press that tore it off (`Overlay::continue_move`). The arena -/// that holds the press lets it go with no phase; the owner's next lifecycle run reports `DragStart`, and the runs -/// after it the press's own `Drag`, `Release` or `Cancel` from their pass's input, so the handover turns no held -/// button into an event. Nothing happens when no arena of the running viewport holds an open primary press other than -/// `owner`'s, and so a rerun of the pass that asks again takes nothing. Call it before the owner's step 8 (in its parts -/// step) for the press to show in the same pass. +/// that holds the press lets it go with no phase; when no arena holds a press, a plain egui widget holds the primary +/// button (an app's own popup title), and the owner takes the press from egui's pointer state. The owner's next +/// lifecycle run reports `DragStart`, and the runs after it the press's own `Drag`, `Release` or `Cancel` from their +/// pass's input, so the handover turns no held button into an event. Nothing happens when the primary button is up, +/// when another arena holds a press it cannot hand over, or when `owner` holds the press already, and so a rerun of +/// the pass that asks again takes nothing. Call it before the owner's step 8 (in its parts step) for the press to show in +/// the same pass. pub(crate) fn hand_over_press(ctx: &Context, owner: Id, part: PartRef, origin: Pos2) { let read = PassRead::of(ctx); - let start = PerViewport::::with(ctx, read.viewport, |arenas| { - let (_, state) = arenas + let held = PerViewport::::with(ctx, read.viewport, |arenas| { + if !arenas.by_root.iter().any(|(root, state)| *root != owner && state.machine.button().is_some()) { + return Held::ByNoArena; + } + let Some((_, state)) = arenas .by_root .iter_mut() - .find(|(root, state)| **root != owner && state.machine.button() == Some(PointerButton::Primary) && !state.machine.release_held())?; - let start = state.machine.start()?; + .find(|(root, state)| **root != owner && state.machine.button() == Some(PointerButton::Primary) && !state.machine.release_held()) + else { + return Held::Elsewhere; + }; + let Some(start) = state.machine.start() else { return Held::Elsewhere }; state.machine = PressMachine::default(); state.host_cancel = false; - Some(start) + Held::Taken(start.time) }); - let Some(start) = start else { return }; + let time = match held { + Held::Taken(time) => time, + // An egui widget holds the press, or no button is down. + Held::ByNoArena => match ctx.input(|input| input.pointer.primary_down().then(|| input.pointer.press_start_time()).flatten()) { + Some(time) => time, + None => return, + }, + Held::Elsewhere => return, + }; let target = Hit { owner, part: Some(part), sense: Sense::DRAG, local: false }; with_arena_in(ctx, read.viewport, ArenaId::new(owner), read.pass_nr, |state| { - state.machine.take_over(target, Sense::DRAG, PressStart::new(origin, PointerButton::Primary, start.time, 1)); + state.machine.take_over(target, Sense::DRAG, PressStart::new(origin, PointerButton::Primary, time, 1)); state.handed = Some((part, read.pass_nr)); }); } +/// Where `hand_over_press` found the held press. +enum Held { + /// An arena held the primary press and let it go; the press began at this time. + Taken(f64), + /// No arena but the owner's holds a press. + ByNoArena, + /// Another arena holds a press it cannot hand over: of another button, or released and waiting for its pass. + Elsewhere, +} + /// Records the transformed body's egui layer. pub(crate) fn set_layer(ctx: &Context, arena: ArenaId, layer: Layer) { crate::runtime::replay::journal(ctx, || (arena, layer), |ctx, &(arena, layer)| set_layer(ctx, arena, layer)); @@ -1084,8 +1112,18 @@ fn outcome_in(ctx: &Context, read: &PassRead, arena: ArenaId, layer: Layer, enab None if others_press => Hovered::default(), None => under, }; - let outcome = - Outcome { pass: pass_nr, hover, contains, target: step.target, phase: step.phase, dragging, activated: step.activated, aside, xf }; + let outcome = Outcome { + pass: pass_nr, + layer: Some(layer), + hover, + contains, + target: step.target, + phase: step.phase, + dragging, + activated: step.activated, + aside, + xf, + }; state.outcome = Some(outcome); outcome }); @@ -1138,6 +1176,25 @@ fn note_pressed_parts(ctx: &Context) { crate::runtime::pointer::set_pressed_parts(ctx, parts); } +/// Whether an actually captured press in exactly `layer` already ended by Escape in this pass. This observes +/// the arena's existing outcome after its body ran; it neither delivers a key nor changes the press machine. +pub(crate) fn escape_cancelled_in_layer(ctx: &Context, layer: Layer) -> bool { + let viewport = pass::current_viewport(ctx); + let pass_nr = pass::pass_nr(ctx, viewport); + PerViewport::::with(ctx, viewport, |arenas| { + arenas.by_root.values().any(|state| { + state.pass == pass_nr + && state.machine.target().is_none() + && state.outcome.is_some_and(|outcome| { + outcome.pass == pass_nr + && outcome.layer == Some(layer) + && outcome.target.is_some() + && matches!(outcome.phase, Some(PressPhase::Cancel { reason: craft_behavior::PressCancel::Escape, .. })) + }) + }) + }) +} + /// The arena's outcome of the running pass, idle when the root has not run yet. pub(crate) fn read_outcome(ctx: &Context, arena: ArenaId) -> Outcome { let pass_nr = pass::pass_nr(ctx, pass::current_viewport(ctx)); diff --git a/crates/ui-contract/src/primitives/text_adapter.rs b/crates/ui-contract/src/primitives/text_adapter.rs index 92fd681222..f57d2d47f0 100644 --- a/crates/ui-contract/src/primitives/text_adapter.rs +++ b/crates/ui-contract/src/primitives/text_adapter.rs @@ -83,6 +83,9 @@ pub(crate) struct TextState { pub change: Option, /// `Cx::select_all_text` asked for the whole text to be selected at the start of the next pass. pub select_all: bool, + /// Focus arrived on a `select_on_focus` part with a pointer press that is still down: the press keeps the caret or + /// range the pointer makes, and its release as a plain click selects the whole text, as an address bar does. + pub select_on_click: bool, /// The selection, `(caret, anchor)`, the text part had when its edit menu, or a menu bar or menu the keyboard goes /// back to it from, took the focus (`AdapterIn::keeps_selection`): egui collapses the selection of a widget without /// focus, and the menu's command acts on it once the focus is back, which reaches the widget the pass after the @@ -95,15 +98,8 @@ pub(crate) fn text_id(id: Id, key: PartKey) -> Id { crate::runtime::memory::sub(id, ("text", key)) } -/// The keys the text part keeps, from its options and the selection of its widget `widget`: with no selection Cut, -/// Copy and Delete are inactive, and so are Undo and Redo while the widget has no step for them, so their keys and menu -/// picks still reach the part and the edit menu shows them disabled. Cut, Copy and Delete then do nothing and never -/// reach the app; an Undo or Redo with no step goes on to the app command (`commands::fall_through`), which the board -/// resolves it to. The board reads the keys the stop registered; a selection or text change repaints, which registers -/// them again. The selection is the one the part acts on: `held`, the one it kept while its edit menu or a menu bar has -/// the focus (egui collapses the selection of a widget without focus), else its widget's. `text` is the part's current text, which -/// the widget's undo steps are judged against. -pub(crate) fn keys_of(ctx: &Context, widget: Id, held: Option<(usize, usize)>, text: &str, base: KeyUse, options: &TextOptions) -> KeyUse { +/// The keys the text part keeps, from its options. +pub(crate) fn keys_of(base: KeyUse, options: &TextOptions) -> KeyUse { // A part whose Tab inserts, rewrites or reports keeps Tab, so the focus service never moves focus on it. let keys = if options.tab != TabKey::Moves { base.with_keep(KeepKeys::Tab) @@ -114,6 +110,19 @@ pub(crate) fn keys_of(ctx: &Context, widget: Id, held: Option<(usize, usize)>, t }; let keys = keys.with_value(base.value || options.steps_value); let keys = if options.holds_drafts { keys.with_holds_drafts() } else { keys }; + // A multi-line part makes a plain Enter a line break. + if options.submits || options.multiline() { keys.with_submits() } else { keys } +} + +/// `keys`, the text part's, with the edits its widget `widget` cannot run now inactive: with no selection Cut, Copy +/// and Delete, and Undo and Redo while the widget has no step for them, so their keys and menu picks still reach the +/// part and the edit menu shows them disabled. Cut, Copy and Delete then do nothing and never reach the app; an Undo +/// or Redo with no step goes on to the app command (`commands::fall_through`), which the board resolves it to. The +/// board reads the keys the stop registered, which reads them after the part applied the pass's edits, so a Select All +/// of the pass makes Copy active. The selection is the one the part acts on: `held`, the one it kept while its edit +/// menu or a menu bar has the focus (egui collapses the selection of a widget without focus), else its widget's. +/// `text` is the part's current text, which the widget's undo steps are judged against. +pub(crate) fn with_idle(ctx: &Context, widget: Id, held: Option<(usize, usize)>, text: &str, keys: KeyUse) -> KeyUse { let selected = held.or_else(|| selection(ctx, widget)).is_some_and(|(caret, anchor)| caret != anchor); let (undo, redo) = text_edit::history(ctx, widget, text); let idle = [ @@ -124,11 +133,9 @@ pub(crate) fn keys_of(ctx: &Context, widget: Id, held: Option<(usize, usize)>, t (EditCommand::Redo, !redo), ] .into_iter() - .filter(|(command, idle)| *idle && base.edits.contains(*command)) + .filter(|(command, idle)| *idle && keys.edits.contains(*command)) .map(|(command, _)| command); - let keys = keys.with_inactive(idle.fold(base.inactive, EditSet::with)); - // A multi-line part makes a plain Enter a line break. - if options.submits || options.multiline() { keys.with_submits() } else { keys } + keys.with_inactive(idle.fold(keys.inactive, EditSet::with)) } pub(crate) struct AdapterIn<'a> { @@ -460,7 +467,13 @@ pub(crate) fn run(state: &mut TextState, mut input: AdapterIn<'_>) -> AdapterOut // The menu closed a pass ago and the focus went elsewhere: nothing comes back to the held selection. state.held_selection = None; } - let mut base = state.draft.clone().or_else(|| state.normalised.take()).unwrap_or_else(|| input.shown.to_owned()); + // An idle part shows its resting text, if it has one; focus (or the edit menu holding it) and any draft show the + // value's own text. A pass that edits an idle part's text (the host replacing its selection, or putting a draft in) + // edits the value's own text, not the resting text drawn in its place. + let edits_idle = input.options.replace_selection.is_some() || state.change.is_some(); + let resting = input.options.resting.as_deref().filter(|_| !input.focused && !input.held && !edits_idle); + let mut base = + state.draft.clone().or_else(|| state.normalised.take()).or_else(|| resting.map(str::to_owned)).unwrap_or_else(|| input.shown.to_owned()); let mut edited = apply(&mut input, state, &mut base, widget); if let Some((range, insert)) = state.completions.take(&base) { let chars = |byte: usize| base.get(..byte).map_or_else(|| base.chars().count(), |head| head.chars().count()); @@ -481,8 +494,11 @@ pub(crate) fn run(state: &mut TextState, mut input: AdapterIn<'_>) -> AdapterOut // a list open on it (a search box's results) then gets the Escape that finds the field empty and closes. // A draft in a dialog whose Escape closes it does not take the Escape: the one Escape cancels the dialog and // the typing with it (Word, and the old apps). Outside dialogs Escape reverts the draft first. In any modal dialog - // a draft leaves Escape to the dialog's Cancel, which discards it with the dialog's other edits. + // a draft leaves Escape to the dialog's Cancel, which discards it with the dialog's other edits. A field that keeps + // its text on Escape takes every Escape while editable and hands it on after committing (`keep_on_escape`). + let keep_on_escape = input.options.keep_on_escape && !input.options.clear_on_escape && input.enabled && !input.read_only; let closes_dialog = focused_before + && !keep_on_escape && state.preedit.is_none() && !input.options.clear_on_escape && input.intents.untaken(&Intent::Cancel) @@ -497,8 +513,8 @@ pub(crate) fn run(state: &mut TextState, mut input: AdapterIn<'_>) -> AdapterOut // With `RootEnv::escape_leaves_fields` a field takes Escape with nothing to revert too, and gives up the focus; // in a dialog that Escape closes, the Escape stays the dialog's. let leaves = !input.options.clear_on_escape && !closes_dialog && crate::runtime::env::Env::of(input.ui).escape_leaves_fields; - let takes_escape = - if input.options.clear_on_escape { !base.is_empty() || state.preedit.is_some() } else { draft_takes || state.preedit.is_some() || leaves }; + let takes_escape = keep_on_escape + || if input.options.clear_on_escape { !base.is_empty() || state.preedit.is_some() } else { draft_takes || state.preedit.is_some() || leaves }; let list_first = input.list_open && !input.options.clear_on_escape; if focused_before && takes_escape && !state.completions.open && !list_first && input.intents.take(Intent::Cancel) { // Escape over a composition alone ends the composition and leaves the text. diff --git a/crates/ui-contract/src/primitives/text_input.rs b/crates/ui-contract/src/primitives/text_input.rs index da22da7025..c815c535ec 100644 --- a/crates/ui-contract/src/primitives/text_input.rs +++ b/crates/ui-contract/src/primitives/text_input.rs @@ -67,6 +67,10 @@ pub struct TextOptions { pub live: bool, /// Escape clears the text and commits the empty text while text shows, and goes on to the host once it is empty. pub clear_on_escape: bool, + /// Escape keeps the text: an open typing run commits once, editing ends by leaving focus, and the same Escape + /// goes on to the enclosing scope. A live filter keeps its query this way. Ignored with `clear_on_escape`, and on a + /// disabled or read-only part. + pub keep_on_escape: bool, /// Monospace text. pub mono: bool, /// The type role the text is set in; a monospace text takes the mono role's face and size instead. @@ -129,6 +133,10 @@ pub struct TextOptions { /// The key that submits a multi-line text: under `Enter`, plain, Cmd and Ctrl+Enter submit and Shift+Enter breaks /// the line. pub submit_key: SubmitKey, + /// The text shown, and exposed as the part's accessible value, instead of the value's own text while the part has + /// neither focus nor a draft (a derived number in parentheses). Focus, and any typing, start from the value's own + /// text: this changes only what an idle part shows, never what the codec formats or parses. + pub resting: Option, } /// Which Enter chord submits a multi-line text. @@ -151,6 +159,7 @@ impl Default for TextOptions { mask: false, live: false, clear_on_escape: false, + keep_on_escape: false, mono: false, role: TypeRole::Body, ink: None, @@ -175,6 +184,7 @@ impl Default for TextOptions { holds_drafts: false, whole_paste: None, submit_key: SubmitKey::CommandEnter, + resting: None, } } } diff --git a/crates/ui-contract/src/runtime/drag.rs b/crates/ui-contract/src/runtime/drag.rs index 357c3484ad..884a870cff 100644 --- a/crates/ui-contract/src/runtime/drag.rs +++ b/crates/ui-contract/src/runtime/drag.rs @@ -221,12 +221,11 @@ impl DropZone { } } -/// What a drag moves along with the pointer when its source is a container: the container's layer, and its window -/// where it opens one. Targets never see the pointer through the layer or inside the window, so the targets under -/// the moving unit take the drop. +/// The window a drag moves along with the pointer when its source is a container that opens one. Targets never see +/// the pointer inside the window, so the targets under the moving unit take the drop; the container's layer is looked +/// through the same way ([`moving_layer`]). #[derive(Clone, Copy, Default)] struct Moving { - layer: Option, viewport: Option, } @@ -357,7 +356,7 @@ pub fn start( .unwrap_or(PointerButton::Primary); board.session = Some(Session { source, - moving: Moving { layer: overlay::entry(ctx, source).map(|entry| entry.layer), viewport: Some(viewports::viewport_id(source)) }, + moving: Moving { viewport: Some(viewports::viewport_id(source)) }, viewport, button, payload, @@ -637,9 +636,13 @@ pub(crate) fn dragging_of(ctx: &Context, payload: TypeId) -> Option<(Arc Option { - board(ctx, |board| board.session.as_ref().and_then(|session| session.moving.layer)) + let source = board(ctx, |board| board.session.as_ref().map(|session| session.source))?; + overlay::entry(ctx, source).map(|entry| entry.layer) } /// Whether the running session's source is the window of the running viewport: its targets take no drop of the diff --git a/crates/ui-contract/src/runtime/egui/areas.rs b/crates/ui-contract/src/runtime/egui/areas.rs index f9a3b58a09..107d48ea80 100644 --- a/crates/ui-contract/src/runtime/egui/areas.rs +++ b/crates/ui-contract/src/runtime/egui/areas.rs @@ -53,6 +53,12 @@ pub(crate) fn layer_position(ctx: &Context, layer: LayerId) -> usize { ctx.memory(|memory| memory.layer_ids().position(|listed| listed == layer).map_or(0, |at| at + 1)) } +/// Whether the screen position `pos` lies in `rect`, given in the space of `layer`, with `layer` the topmost layer there. +pub(crate) fn lies_in(ctx: &Context, layer: LayerId, rect: Rect, pos: Pos2) -> bool { + let at = layer_map(ctx, layer).map_or(pos, |map| map.to_layer(pos)); + layer_at(ctx, pos) == Some(layer) && rect.contains(at) +} + /// The topmost layer under a screen position. Inside the canvas a modal layer leaves open (`runtime::sampler`) and /// where nothing but the canvas lies over it, it answers the canvas's own layer as if the modal's gate and its scrim /// were not there. @@ -374,7 +380,9 @@ pub(crate) fn show_cover_layer(ctx: &Context, cover: CoverLayer) { sizing = ui.is_sizing_pass(); for rect in covered { ui.painter().rect_filled(rect, 0.0, scrim); - let absorber = ui.allocate_rect(rect, Sense::click_and_drag()); + // It absorbs presses and never takes key focus: a focusable egui widget no component made is a Tab stop + // of the app's own (`focus::take_app_widgets`). + let absorber = ui.allocate_rect(rect, Sense::CLICK | Sense::DRAG); crate::runtime::egui::widgets::note_widget(ui.ctx(), absorber.id); crate::runtime::egui::access::hide(ui.ctx(), absorber.id); } @@ -538,6 +546,30 @@ pub(crate) fn host_popup(ui: &Ui, id: egui::Id, at: Pos2) { egui::Popup::new(id, ui.ctx().clone(), at, ui.layer_id()).open_memory(None).show(|ui| ui.allocate_space(ui.spacing().interact_size)); } +/// The size of one entry of [`host_popup_list`], as an app's popup list entry. +#[cfg(feature = "suite")] +const HOST_LIST_ENTRY: Vec2 = Vec2::new(104.0, 22.0); + +/// A host's own popup list `id` at `at`, as an app draws one: an egui foreground area with one clickable entry per id +/// in `entries`, stacked from the top. It leaves arrow keys to egui's directional focus. Returns the entries' rects. +#[cfg(feature = "suite")] +pub(crate) fn host_popup_list(ctx: &Context, id: Id, at: Pos2, entries: &[Id]) -> Vec { + egui::Area::new(id) + .order(Order::Foreground) + .fixed_pos(at) + .show(ctx, |ui| { + let mut rects = Vec::new(); + for (row, &entry) in entries.iter().enumerate() { + let rect = Rect::from_min_size(at + Vec2::Y * (HOST_LIST_ENTRY.y * row as f32), HOST_LIST_ENTRY); + ui.allocate_rect(rect, Sense::hover()); + let _ = ui.interact(rect, entry, Sense::click()); + rects.push(rect); + } + rects + }) + .inner +} + /// Opens the host's egui popup `id`. #[cfg(feature = "suite")] pub(crate) fn open_host_popup(ctx: &Context, id: egui::Id) { diff --git a/crates/ui-contract/src/runtime/egui/editor.rs b/crates/ui-contract/src/runtime/egui/editor.rs index e1824adda2..63e618eede 100644 --- a/crates/ui-contract/src/runtime/egui/editor.rs +++ b/crates/ui-contract/src/runtime/egui/editor.rs @@ -4,9 +4,11 @@ use egui::{EventFilter, Id, Rect, Ui}; /// Registers the editor's focus widget over `rect` and applies `filter` while it holds focus; returns whether it holds -/// focus. -pub(crate) fn show(ui: &mut Ui, id: Id, rect: Rect, filter: EventFilter) -> bool { - let response = ui.interact(rect, id, egui::Sense::focusable_noninteractive()); +/// focus. The widget is one of egui's focus candidates only while `focusable` (its component takes focus), so neither +/// Tab nor egui's arrows reach the editor of a disabled component. +pub(crate) fn show(ui: &mut Ui, id: Id, rect: Rect, filter: EventFilter, focusable: bool) -> bool { + let sense = if focusable { egui::Sense::focusable_noninteractive() } else { egui::Sense::hover() }; + let response = ui.interact(rect, id, sense); let focused = response.has_focus(); if focused { ui.memory_mut(|memory| memory.set_focus_lock_filter(id, filter)); diff --git a/crates/ui-contract/src/runtime/egui/fixture.rs b/crates/ui-contract/src/runtime/egui/fixture.rs index 9f13a11714..c7a8eca3e6 100644 --- a/crates/ui-contract/src/runtime/egui/fixture.rs +++ b/crates/ui-contract/src/runtime/egui/fixture.rs @@ -115,7 +115,8 @@ pub(crate) struct OsFiles { /// The viewport facts a frame reports: the root window's inner rect when the frame is the root's (`inner`), and its /// focus: a window-focus event also sets the root viewport's focus fact, as a host reports both, and the fact stays -/// until the next such event. Before any event the focus is unknown. +/// until the next such event. Before any event the focus is unknown. The root's input +/// reports the same focus (`RawInput::focused`), a window with focus while it is unknown. fn window_facts( ctx: &Context, events: &[Event], @@ -256,6 +257,7 @@ pub(crate) fn run_frame( } Service::::run(ctx, |resets| resets.input(viewport, &mut events)); let mut viewports = window_facts(ctx, &events, native_pixels_per_point, (viewport == egui::ViewportId::ROOT).then_some(screen)); + let focused = viewport != egui::ViewportId::ROOT || viewports.get(&egui::ViewportId::ROOT).and_then(|info| info.focused).unwrap_or(true); let children = open_children(ctx, viewport); for child in &children { viewports @@ -265,6 +267,7 @@ pub(crate) fn run_frame( screen_rect: Some(screen), time: Some(time), viewport_id: viewport, + focused, events, hovered_files, dropped_files, @@ -416,7 +419,21 @@ pub(crate) fn bare_context() -> Context { /// one build to the next. fn test_fonts() -> egui::FontDefinitions { static FONTS: std::sync::OnceLock = std::sync::OnceLock::new(); - FONTS.get_or_init(crate::fonts::deflated_default_definitions).clone() + FONTS + .get_or_init(|| { + let mut definitions = crate::fonts::deflated_default_definitions(); + // A fixture reads text through the AccessKit tree and the painted bounds, never the atlas pixels, and + // hinting changes only how outlines are rasterized (advances and layout do not read it). Without it no + // face builds a hinting instance and no glyph runs the hinter. An app's own stack (`UiFonts::install`) + // keeps hinting, which the review renders use. + for data in definitions.font_data.values_mut() { + let mut face = (**data).clone(); + face.tweak.hinting = Some(false); + *data = Arc::new(face); + } + definitions + }) + .clone() } /// A paragraph of `text` wrapped to the available width. @@ -500,6 +517,86 @@ pub(crate) fn host_field(ui: &mut Ui, id: egui::Id, text: &mut String) -> Rect { ui.add(egui::TextEdit::singleline(text).id(id)).rect } +/// A host's own multi-line egui text field of `id` over `text` that locks focus, as a code editor of the app's own: +/// its egui key filter keeps Tab, which it types. +#[cfg(feature = "suite")] +pub(crate) fn host_code_field(ui: &mut Ui, id: egui::Id, text: &mut String) -> Rect { + ui.add(egui::TextEdit::multiline(text).id(id).lock_focus(true)).rect +} + +/// A host's own text editor of `id` at `rect`, as a canvas text tool draws it: it reads the IME events from egui's +/// input into `text` (a commit appends, a deletion before the caret removes characters from its end) and writes the +/// pass's IME output, context generation 1. +#[cfg(feature = "suite")] +pub(crate) fn host_ime_editor(ui: &Ui, id: egui::Id, rect: Rect, text: &mut String) { + let _ = ui.interact(rect, id, egui::Sense::click()); + for event in ui.input(|input| input.events.clone()) { + match event { + Event::Ime(egui::ImeEvent::Commit(committed)) => text.push_str(&committed), + Event::Ime(egui::ImeEvent::DeleteSurrounding { before_chars, .. }) => { + for _ in 0..before_chars { + text.pop(); + } + } + _ => {} + } + } + ui.ctx().output_mut(|output| output.ime = Some(egui::output::IMEOutput::new(id, 1, egui::IMEPurpose::Normal, rect, rect))); +} + +/// What [`host_resetting_ime_editor`] holds between passes. +#[cfg(feature = "suite")] +#[derive(Default)] +pub(crate) struct ResettingEditor { + pub(crate) text: String, + pub(crate) composing: bool, + /// The reset the editor asked for last, until its completion arrives; the editor takes no IME event meanwhile. + pub(crate) reset: Option, + /// The editor also writes its request into its IME output's `reset_request`. Otherwise it leaves that field to egui, + /// which publishes the request asked through `Context::request_ime_reset`, as EffectCraft's editor does. + pub(crate) in_output: bool, + /// Ask for a reset at the next pass, as EffectCraft's editor does when its caret moves after an outside press. + pub(crate) ask: bool, +} + +/// A host's own text editor of `id` at `rect` that fences its own interrupted composition, as EffectCraft's viewer text +/// editor does: a primary press on it while it composes ends the composition and asks the platform for a reset, and the +/// editor ignores IME events until that reset's completion. A press elsewhere asks for nothing. Otherwise as +/// [`host_ime_editor`]. +#[cfg(feature = "suite")] +pub(crate) fn host_resetting_ime_editor(ui: &Ui, id: egui::Id, rect: Rect, editor: &mut ResettingEditor) { + let _ = ui.interact(rect, id, egui::Sense::click()); + let pressed = ui.input(|input| input.pointer.primary_pressed() && input.pointer.press_origin().is_some_and(|at| rect.contains(at))); + for event in ui.input(|input| input.events.clone()) { + match event { + Event::ImeResetCompleted { request_id } if editor.reset == Some(request_id) => editor.reset = None, + _ if editor.reset.is_some() => {} + Event::Ime(egui::ImeEvent::Preedit { text, .. }) => editor.composing = !text.is_empty(), + Event::Ime(egui::ImeEvent::Commit(committed)) => { + editor.text.push_str(&committed); + editor.composing = false; + } + Event::Ime(egui::ImeEvent::DeleteSurrounding { before_chars, .. }) => { + for _ in 0..before_chars { + editor.text.pop(); + } + } + _ => {} + } + } + let mut ime = egui::output::IMEOutput::new(id, 1, egui::IMEPurpose::Normal, rect, rect); + let interrupted = editor.composing && pressed; + if interrupted || std::mem::take(&mut editor.ask) { + editor.composing = false; + editor.reset = ui.ctx().request_ime_reset(ui.ctx().viewport_id()); + ime.should_interrupt_composition = interrupted; + if editor.in_output { + ime.reset_request = editor.reset; + } + } + ui.ctx().output_mut(|output| output.ime = Some(ime)); +} + /// Gives the host's own egui widget `id` key focus, as the host's code does. #[cfg(feature = "suite")] pub(crate) fn host_focus(ctx: &Context, id: egui::Id) { diff --git a/crates/ui-contract/src/runtime/egui/focus.rs b/crates/ui-contract/src/runtime/egui/focus.rs index f0f6b7fe54..0941e5d433 100644 --- a/crates/ui-contract/src/runtime/egui/focus.rs +++ b/crates/ui-contract/src/runtime/egui/focus.rs @@ -27,6 +27,17 @@ pub(crate) fn focused(ctx: &Context) -> Option { ctx.memory(|memory| memory.focused()) } +/// egui's focus candidates of the running pass from the `seen`th on (`Memory::focus_candidates`): the widgets +/// interested in key focus, in the order they registered. +pub(crate) fn candidates_since(ctx: &Context, seen: usize) -> Vec { + ctx.memory(|memory| memory.focus_candidates().get(seen..).map(<[_]>::to_vec).unwrap_or_default()) +} + +/// Whether the widget egui holds key focus on keeps Tab by its event filter (`Memory::focus_lock_filter`). +pub(crate) fn focused_keeps_tab(ctx: &Context) -> bool { + ctx.memory(|memory| memory.focus_lock_filter()).is_some_and(|filter| filter.tab) +} + /// Whether egui holds a label text selection, which egui copies on a copy or cut event. pub(crate) fn label_selection(ctx: &Context) -> bool { ctx.with_plugin::(|state| state.has_selection()).unwrap_or(false) @@ -57,9 +68,9 @@ pub(crate) fn surrender(ctx: &Context, id: Id) { } /// H7: egui's begin pass set a focus direction from an unmodified arrow or the Tab it kept. The focus service clears -/// it before any component runs unless egui focus is on an app's own widget (`FocusedRecord::host_focus`), or the -/// key stage left a Tab to egui in a window with no focus stop, and the service moves no focus in the pass: egui would -/// otherwise move focus off a framework stop that the same arrow reaches as an intent. +/// it before any component runs unless egui focus is on an app's own widget (`FocusedRecord::host_focus`) and the +/// service moves no focus in the pass: egui would otherwise move focus off a framework stop that the same arrow +/// reaches as an intent. pub(crate) fn clear_directional_focus(ctx: &Context) { ctx.memory_mut(|memory| memory.move_focus(FocusDirection::None)); } diff --git a/crates/ui-contract/src/runtime/egui/ime.rs b/crates/ui-contract/src/runtime/egui/ime.rs index c9e5d7d916..b06c469fae 100644 --- a/crates/ui-contract/src/runtime/egui/ime.rs +++ b/crates/ui-contract/src/runtime/egui/ime.rs @@ -27,14 +27,14 @@ pub(crate) enum Raw { ResetRetired(egui::ImeResetId), } -/// Removes the IME events from `events`, and the other events `drop` names, and returns the IME events in order, each -/// with its place: how many of the events left in `events` arrived before it. The key stage numbers the events it -/// reads by the same places (`keys::input_hook`), so an editor gets the two in the order they arrived. -pub(crate) fn take_events(events: &mut Vec, take: bool, drop: impl Fn(&Event) -> bool) -> Vec<(Raw, usize)> { +/// Removes the IME events `take` names from `events`, and the other events `drop` names, and returns the IME events +/// in order, each with its place: how many of the events left in `events` arrived before it. The key stage numbers the +/// events it reads by the same places (`keys::input_hook`), so an editor gets the two in the order they arrived. +pub(crate) fn take_events(events: &mut Vec, take: impl Fn(&Event) -> bool, drop: impl Fn(&Event) -> bool) -> Vec<(Raw, usize)> { let mut taken = Vec::new(); let mut kept = 0; events.retain(|Arrived { event, .. }| { - if let Some(raw) = take.then(|| raw_of(event)).flatten() { + if let Some(raw) = take(event).then(|| raw_of(event)).flatten() { taken.extend(raw.map(|raw| (raw, kept))); return false; } @@ -45,6 +45,12 @@ pub(crate) fn take_events(events: &mut Vec, take: bool, drop: impl Fn(& taken } +/// The IME event `event` is, as the engine reads it, for the engine to follow an app's own editor through the events +/// it leaves to egui. +pub(crate) fn read(event: &Event) -> Option { + raw_of(event).flatten() +} + /// What the IME engine reads from `event`: `None` for an event that is not the engine's, `Some(None)` for one it takes /// and ignores. fn raw_of(event: &Event) -> Option> { @@ -72,6 +78,9 @@ pub(crate) struct Output { pub caret: Rect, /// Interrupt the OS composition and ask for a reset. pub interrupt: bool, + /// The reset request the app's own editor asked for this pass (`app_reset`), which an interrupt publishes instead + /// of asking a new one: egui keeps one unpublished request per viewport, so a new one would replace the app's. + pub app_reset: Option, /// The context generation the tracker gave the owner: it changes when the owner, its epoch, its focus or its /// purpose changes, and stays for ordinary edits. pub generation: u64, @@ -83,9 +92,10 @@ pub(crate) struct Output { } /// Writes the pass's IME output; egui reads it only when it is `Some` at the end of the pass. Returns the reset -/// request an interrupt published: its completion is the one that matches (`None` when the ids ran out). +/// request an interrupt published, the app's own when it asked for one: its completion is the one that matches +/// (`None` when the ids ran out). pub(crate) fn write(ctx: &Context, viewport: ViewportId, out: Output) -> Option { - let reset = out.interrupt.then(|| ctx.request_ime_reset(viewport)).flatten(); + let reset = out.interrupt.then(|| out.app_reset.or_else(|| ctx.request_ime_reset(viewport))).flatten(); ctx.output_mut(|output| { let mut ime = egui::output::IMEOutput::new( out.owner, @@ -103,6 +113,27 @@ pub(crate) fn write(ctx: &Context, viewport: ViewportId, out: Output) -> Option< reset } +/// The reset request the app asked for this pass, as egui publishes it at the end of the pass: one asked through +/// `Context::request_ime_reset`, which replaces the IME output's own `reset_request`, or else the one the app wrote +/// there. +pub(crate) fn app_reset(ctx: &Context, viewport: ViewportId) -> Option { + ctx.pending_ime_reset(viewport).or_else(|| ctx.output(|output| output.ime.as_ref().and_then(|ime| ime.reset_request))) +} + +/// Interrupts the composition of the IME output the app's own editor wrote this pass, in its context, and asks for a +/// reset. An editor that asked for its own reset this pass (`app`, from `app_reset`) keeps its request, so the platform +/// answers the app's id and the app gets its completion. Returns the reset request the output carries, as `write` does. +pub(crate) fn interrupt_written(ctx: &Context, viewport: ViewportId, app: Option) -> Option { + let reset = app.or_else(|| ctx.request_ime_reset(viewport)); + ctx.output_mut(|output| { + if let Some(ime) = &mut output.ime { + ime.should_interrupt_composition = true; + ime.reset_request = reset; + } + }); + reset +} + /// Drops what `TextEdit` wrote in a pass whose IME output the engine writes. pub(crate) fn clear(ctx: &Context) { ctx.output_mut(|output| output.ime = None); diff --git a/crates/ui-contract/src/runtime/egui/text_edit.rs b/crates/ui-contract/src/runtime/egui/text_edit.rs index 779684c381..0d543d9b81 100644 --- a/crates/ui-contract/src/runtime/egui/text_edit.rs +++ b/crates/ui-contract/src/runtime/egui/text_edit.rs @@ -246,7 +246,10 @@ pub(crate) fn show(ui: &mut Ui, env: &crate::runtime::env::Env, edit: Edit<'_>) let content = placed.union(output.response.rect).union(text_rect); super::widgets::note_scroll_region(ui.ctx(), rect.intersect(ui.clip_rect()), content); } - let focused = output.response.has_focus(); + // The widget's key focus, whether or not the window has the system's: switching to another app is no focus move, + // so the typing run, caret and selection carry on (egui's `Response::has_focus` is false while the window is in + // the background). + let focused = ui.memory(|memory| memory.has_focus(id)); let caret = output.cursor_range.map(|range| { let at = output.galley.pos_from_cursor(range.primary); at.translate(output.galley_pos.to_vec2()) diff --git a/crates/ui-contract/src/runtime/focus.rs b/crates/ui-contract/src/runtime/focus.rs index 640a326dab..c03e1fa31a 100644 --- a/crates/ui-contract/src/runtime/focus.rs +++ b/crates/ui-contract/src/runtime/focus.rs @@ -76,7 +76,8 @@ pub(crate) struct FocusedRecord { pub(crate) claims: Vec, /// The component of the focused stop: only its state-dependent claims hold. pub(crate) focused: Option, - /// The focused stop is the app's own egui widget (`Stop::host`): it reads the presses it claims from egui. + /// The focused stop is the app's own egui widget (`Stop::host`: one of the app's focusable egui widgets, or its + /// canvas): it reads the presses it claims from egui. pub(crate) host: bool, /// The arena root of the focused stop when the stop is a non-text member of an arena (a part of a canvas's frame /// overlay): the root's state-dependent claims hold too, so a canvas tool's keys work with a part focused. @@ -96,11 +97,18 @@ pub(crate) struct FocusedRecord { /// focused. pub(crate) canvas: Option, /// egui focus is on a widget no framework component made, or an egui popup is open, and no framework press or - /// drag is captured: an app's own focused widget or popup keeps the keys a focused component keeps (Tab, Escape, - /// the clipboard events). Written by the end hook after its focus moves. + /// drag is captured: an app's own focused widget or popup keeps the keys a focused component keeps (Escape, the + /// plain Enter, the clipboard events), and no window intent comes of them. Written by the end hook after its focus + /// moves. pub(crate) foreign: bool, - /// egui focus is on a widget no framework component made, and no framework press or drag is captured: egui - /// moves focus among the app's own widgets with the arrows and the Tab it keeps. Written by the end hook. + /// A bare Tab is egui's: an egui popup is open (`foreign`), or egui focus is on the app's own widget and its egui + /// key filter keeps Tab (a multi-line text edit that locks focus, a code editor). Any other bare Tab is the + /// framework's move over its one order, which holds the app's widgets (`take_app_widgets`). Written by the end + /// hook. + pub(crate) tab_in_egui: bool, + /// egui focus is on a widget no framework component made (`State::app_widget`: its stop of the app's own does not + /// count, the app's canvas does), and no framework press or drag is captured: egui moves focus among the app's own + /// widgets with the arrows. Written by the end hook. pub(crate) host_focus: bool, /// `host_focus`, on a text edit the app drew itself. Written by the end hook. pub(crate) host_text: bool, @@ -141,6 +149,8 @@ pub(crate) struct RowGroups { pub(crate) struct State { pub(crate) stops: Vec, stop_ids: IdSet, + /// The egui roots of `stops`. + stop_roots: IdSet, pub(crate) last_stops: Vec, pub(crate) scopes: FastMap, pub(crate) last_scopes: FastMap, @@ -181,8 +191,14 @@ pub(crate) struct State { /// The stop focus last moved onto, the frame whose passes see the move, and what moved it there. It stays until focus /// moves again: while the stop keeps the focus, it is how the stop got it (`origin`). pub(super) arrived: Option<(u64, StopKey, FocusOrigin)>, - /// The running pass's begin hook left a Tab to egui (`NavKeys::tab_to_egui`); its end hook takes it. - pub(super) tab_to_egui: bool, + /// How many of egui's focus candidates of the running pass (`Memory::focus_candidates`) `take_app_widgets` has + /// read. + pub(super) candidates_seen: usize, + /// A text widget that gave its Escape on to the enclosing scopes and lets focus go at the end of the pass. + surrender_after_scopes: Option, + /// A text widget in a scope that gives focus back to its opener, held one more pass: the scope the Escape closes is + /// closing by the next pass, and its restoration needs the widget to still hold the focus. + surrender_deferred: Option, } fn viewport(ctx: &Context) -> ViewportId { @@ -218,36 +234,92 @@ pub(crate) fn apply(ctx: &Context, acts: Vec) { } } -/// Registers a stop of the running pass in the innermost open scope, in registration order. +/// Registers a stop of the running pass in the innermost open scope, in registration order: after the app's own +/// widgets drawn before it (`take_app_widgets`). The app's own widget `stop` names (`host_canvas`) takes the place of +/// its stop as one of those widgets, if the pass took it already. pub(crate) fn register_stop(ctx: &Context, stop: Stop) { + take_app_widgets(ctx, Some(stop.root)); let acts = with(ctx, |state| { - let scope = state.open.last().map(|(id, _)| *id); - state.stop_ids.insert(stop.id); + if stop.host + && let Some(rec) = state.stops.iter_mut().find(|rec| rec.stop.host && rec.stop.id == stop.id) + { + state.stop_roots.insert(stop.root); + rec.stop = stop; + return Vec::new(); + } + state.push_stop(stop) + }); + apply(ctx, acts); +} + +impl State { + /// Appends `stop` to the running pass's stops in the innermost open scope; it takes the focus a request of the pass + /// awaits for it. + fn push_stop(&mut self, stop: Stop) -> Vec { + let scope = self.open.last().map(|(id, _)| *id); + self.stop_ids.insert(stop.id); + self.stop_roots.insert(stop.root); let rec = StopRec { stop, scope, group_position: false }; - let acts = if state.awaited == Some(rec.stop.key()) { - state.awaited = None; - state.focus_stop(rec.clone()) + let acts = if self.awaited == Some(rec.stop.key()) { + self.awaited = None; + self.focus_stop(rec.clone()) } else { Vec::new() }; - state.stops.push(rec); + self.stops.push(rec); + acts + } +} + +/// Registers the app's own egui widgets that egui listed as focus candidates since the last take of the running pass +/// (`Memory::focus_candidates`, in the order they registered with egui), each as a stop of the app's own +/// (`Stop::host`) with the keys of a pointer control, a text stop for a text edit: every focusable egui widget the app +/// draws is a Tab and F6 stop among the framework's, where it was drawn. A widget a component made is none: its +/// component registers its stops (`pointer::made_by_component`, or the root of a stop of the pass), and so is +/// `except`, the root of the stop being registered. Every registration that depends on order takes them first, and +/// the end hook takes the last ones, so a stop range (`mark`, `stop_count`) holds the app's widgets drawn in it. +fn take_app_widgets(ctx: &Context, except: Option) { + let seen = with(ctx, |state| state.candidates_seen); + let fresh = egui_focus::candidates_since(ctx, seen); + if fresh.is_empty() { + return; + } + let viewport = viewport(ctx); + let app: Vec = fresh + .iter() + .filter(|candidate| Some(candidate.id) != except && !crate::runtime::pointer::made_by_component(ctx, viewport, candidate.id)) + .copied() + .collect(); + let acts = with(ctx, |state| { + state.candidates_seen = seen + fresh.len(); + let mut acts = Vec::new(); + for candidate in app { + if state.stop_roots.contains(&candidate.id) { + continue; + } + let stop = Stop::new(candidate.id, KeyUse::of(craft_behavior::Input::Pointer)).host(); + acts.extend(state.push_stop(if candidate.text { stop.text() } else { stop })); + } acts }); apply(ctx, acts); } -/// Registers the app's own egui widget `id`, drawn in the running pass, as its window's document canvas: a focus stop -/// with `keys`, marked as the canvas (`KeyUse::chrome_key`). The window then shows a document, so with +/// Registers the app's own egui widget `id`, drawn in the running pass, as its window's document canvas: its focus stop +/// takes `keys` and is marked as the canvas (`KeyUse::chrome_key`), in place of the stop it has as one of the app's +/// focusable egui widgets, at the same place in Tab order. The window then shows a document, so with /// `RootEnv::tab_toggles_chrome` a bare Tab with nothing focused toggles its panels, as with a framework canvas. Focus /// reaches the canvas by Tab, F6, `request` or the app's own egui focus request; while it has focus, Tab and the arrows /// route as `keys` says (the arrows as nudges, Tab moving focus on or toggling the panels unless it keeps Tab). `keys` /// is `KeyUse::CANVAS`, or a variant such as `KeyUse::CANVAS.with_keep(KeepKeys::Tab).with_edits(..)` while Tab and the /// clipboard are the canvas's own. The canvas reads its keys from egui: with nothing focused it is the key target, and -/// a bare Tab it keeps, the chords it claims (`KeyUse::with_claims`; Alt+numpad code entry leaves a claimed Alt+digit -/// alone), and the clipboard events and edit chords of its edit set stay in egui's input for the app, and nothing -/// toggles or fires with them; Page Up and Down, Home and End arrive as its `Intent::Move`, as while it has the focus. -/// With the canvas focused, the same keys stay in egui, and Escape too, as for any focused widget of the app's own; -/// Escape with nothing focused is the window's cancel. Call it each pass the canvas shows. +/// the chords it claims (`KeyUse::with_claims`; Alt+numpad code entry leaves a claimed Alt+digit alone) and the +/// clipboard events and edit chords of its edit set stay in egui's input for the app, and nothing toggles or fires with +/// them; Page Up and Down, Home and End arrive as its `Intent::Move`, as while it has the focus. A bare Tab with nothing +/// focused is never the canvas's, even when it keeps Tab: it moves focus into the window or toggles the panels, so the +/// canvas cannot trap keyboard navigation. With the canvas focused, the same keys stay in egui, a Tab it keeps and +/// Escape too, as for any focused widget of the app's own; Escape with nothing focused is the window's cancel. Call it +/// each pass the canvas shows. pub fn host_canvas(ctx: &Context, id: Id, keys: KeyUse) { register_stop(ctx, Stop::new(id, keys.with_chrome_key(true)).host()); } @@ -277,14 +349,17 @@ pub(crate) fn is_canvas_member(ctx: &Context, rec: &StopRec) -> bool { }) } -/// Whether a Tab in `viewport` has nothing to leave and nowhere to go: egui held no focus at the end of its last pass -/// and it registered no focus stop there. Read by the input hook, before the begin hook rotates the registrations. -pub(crate) fn tab_from_nothing(ctx: &Context, viewport: ViewportId) -> bool { - with_viewport(ctx, viewport, |state| state.focus_now.is_none() && state.stops.is_empty()) +/// Whether a bare Tab in `viewport` has no stop to move the focus to: the window's last pass registered no stop (the +/// app's focusable egui widgets are stops too, `take_app_widgets`) and nothing held the focus at its end. Such a Tab +/// stays in egui's input for the app's own binding. Read by the input hook, before the begin hook rotates the +/// registrations. +pub(crate) fn tab_has_no_stop(ctx: &Context, viewport: ViewportId) -> bool { + with_viewport(ctx, viewport, |state| state.stops.is_empty() && state.focus_now.is_none()) } /// How many stops the running pass has registered so far. pub(crate) fn stop_count(ctx: &Context) -> usize { + take_app_widgets(ctx, None); with(ctx, |state| state.stops.len()) } @@ -370,6 +445,7 @@ impl Eq for Transcript {} /// Where the running pass's registrations stand. pub(crate) fn mark(ctx: &Context) -> Mark { + take_app_widgets(ctx, None); with(ctx, |state| Mark { stops: state.stops.len(), scopes: state.scope_order.len(), @@ -380,6 +456,7 @@ pub(crate) fn mark(ctx: &Context) -> Mark { /// What the running pass registered since `mark`, which a run that closed every scope it opened left. pub(crate) fn transcript(ctx: &Context, mark: Mark) -> Transcript { + take_app_widgets(ctx, None); with(ctx, |state| { let stops = state.stops.get(mark.stops..).unwrap_or_default().to_vec(); let scopes = state.scope_order.get(mark.scopes..).unwrap_or_default(); @@ -398,6 +475,7 @@ pub(crate) fn transcript(ctx: &Context, mark: Mark) -> Transcript { /// Registers `transcript` again in the running pass, in place of the run that left it: in the innermost open scope, /// as the run would have. A replayed scope is no new scope: it moves no focus when it shows again. pub(crate) fn replay(ctx: &Context, transcript: &Transcript) { + take_app_widgets(ctx, None); let frame = crate::runtime::egui::pass::frame_nr(ctx, viewport(ctx)); let focused = egui_focus::focused(ctx); with(ctx, |state| { @@ -414,6 +492,7 @@ pub(crate) fn replay(ctx: &Context, transcript: &Transcript) { } for rec in placed.stops { state.stop_ids.insert(rec.stop.id); + state.stop_roots.insert(rec.stop.root); state.stops.push(rec); } for group in placed.groups { @@ -438,6 +517,7 @@ pub(crate) fn has_reachable_stop(ctx: &Context, id: Id) -> bool { /// Where a request for the component `id` goes when it has no stop of its own: the first stop registered since /// `from` (a `stop_count`), which a component inside it holds. pub(crate) fn first_stop_inside(ctx: &Context, id: Id, from: usize) -> Option { + take_app_widgets(ctx, None); with(ctx, |state| { if state.stop_ids.contains(&id) { return None; @@ -471,6 +551,7 @@ pub(crate) fn focus_in(ctx: &Context, range: std::ops::Range) -> bool { /// order, then the footer's, then the header's, and initial focus goes to the first of them, not to the title /// row's close action. The first mark of a pass stands. pub(crate) fn begin_body(ctx: &Context) { + take_app_widgets(ctx, None); with(ctx, |state| { if let Some((scope, _)) = state.open.last().copied() { let at = state.stops.len(); @@ -534,6 +615,7 @@ pub(crate) fn push_scope_from( closing: bool, entering: Option, ) { + take_app_widgets(ctx, None); let focused = egui_focus::focused(ctx); with(ctx, |state| { let parent = state.open.last().map(|(parent, _)| *parent); @@ -565,6 +647,7 @@ pub fn open_scope(ctx: &Context) -> Option { /// Closes the innermost open scope. A scope pushed for the first time (or again after a gap of a frame) /// moves focus to its initial stop, in this pass. pub(crate) fn pop_scope(ctx: &Context) { + take_app_widgets(ctx, None); let frame = crate::runtime::egui::pass::frame_nr(ctx, viewport(ctx)); let acts = with(ctx, |state| { nav::order_regions(state); @@ -1004,17 +1087,15 @@ pub(crate) fn begin(ctx: &Context, tab_all_controls: bool, dialog_tab: TabReach) dialog_tab, frame: crate::runtime::egui::pass::frame_nr(ctx, viewport(ctx)), }; - let tab_to_egui = input.nav.tab_to_egui; let (acts, announcements, host_focus) = with(ctx, |state| { state.awaited = None; let host_focus = state.record.host_focus; - state.tab_to_egui = tab_to_egui; let (acts, announcements) = nav::begin(state, input); (acts, announcements, host_focus) }); - // egui's direction moves focus from the widget it holds, an app's own, or from nothing with a Tab the key stage - // left to egui; never in a pass whose focus the framework moves. - if !(host_focus || tab_to_egui) || !acts.is_empty() { + // egui's direction (its arrows, a Tab the key stage left to egui) moves focus from the widget it holds when that is + // an app's own; never in a pass whose focus the framework moves. + if !host_focus || !acts.is_empty() { egui_focus::clear_directional_focus(ctx); } apply(ctx, acts); @@ -1023,16 +1104,44 @@ pub(crate) fn begin(ctx: &Context, tab_all_controls: bool, dialog_tab: TabReach) } } +/// Releases the text widget `widget` at the end of this pass, after the enclosing scopes have had its Escape: a scope +/// deciding whether to close still finds the focused stop. No key is replayed and no other widget loses focus. +pub(crate) fn surrender_after_scopes(ctx: &Context, widget: Id) { + with(ctx, |state| state.surrender_after_scopes = Some(widget)); +} + /// The end hook: applies the press's focus move, returns focus to the opener of a scope that went away, /// moves it off a stop that was not registered, and records what the next input hook reads. pub(crate) fn end(ctx: &Context) { let viewport = viewport(ctx); - // A Tab left to egui moves egui focus into the app's own widgets only: a component's egui widget takes focus - // through its stop, and a component that registered none (a disabled one) takes none. - if with(ctx, |state| std::mem::take(&mut state.tab_to_egui)) - && let Some(id) = egui_focus::focused(ctx).filter(|id| crate::runtime::pointer::made_by_component(ctx, viewport, *id)) + take_app_widgets(ctx, None); + // A field held a pass for the scope it sits in lets go now, unless that scope is going away with focus in the field: + // nav::end below then gives the focus back to the scope's opener from where the field holds it. + if let Some(widget) = with(ctx, |state| state.surrender_deferred.take()) + && !with(ctx, |state| state.restored_focus(Some(widget)).is_some()) { - egui_focus::surrender(ctx, id); + egui_focus::surrender(ctx, widget); + } + if let Some(widget) = with(ctx, |state| state.surrender_after_scopes.take()) { + // A field in a scope that restores focus to an opener (a popover, a dialog) may be in the scope its Escape closes, + // which is only closing by the next pass: it is let go then, once the restoration has had its chance. + let restoring = with(ctx, |state| { + let key = state.focused.get(&widget).copied().unwrap_or((widget, None)); + let mut at = state.stops.iter().find(|rec| rec.stop.key() == key).and_then(|rec| rec.scope); + while let Some(id) = at { + let Some(scope) = state.scopes.get(&id).or_else(|| state.last_scopes.get(&id)) else { break }; + if scope.opener.is_some() { + return true; + } + at = scope.parent; + } + false + }); + if restoring { + with(ctx, |state| state.surrender_deferred = Some(widget)); + } else { + egui_focus::surrender(ctx, widget); + } } let app_widget = |id: Id| { let made = crate::runtime::pointer::made_by_component(ctx, viewport, id); @@ -1046,7 +1155,9 @@ pub(crate) fn end(ctx: &Context) { // Escape over a captured framework press or drag cancels it (`frame::begin_pass`), whatever egui has focused. let captured = crate::runtime::pointer::press_captured(ctx) || crate::runtime::drag::running(ctx); let host_focus = !captured && with(ctx, |state| state.focus_now).is_some_and(app_widget); - let foreign = host_focus || (!captured && crate::runtime::egui::areas::popup_open(ctx)); + let popup = !captured && crate::runtime::egui::areas::popup_open(ctx); + let foreign = host_focus || popup; + let tab_in_egui = popup || (host_focus && egui_focus::focused_keeps_tab(ctx)); let label_selection = egui_focus::label_selection(ctx); let host_text = host_focus && ctx.text_edit_focused(); // A modal layer keeps the canvas's claims from it, as it keeps the arrows (`overlay::end_pass` ran before). @@ -1054,6 +1165,7 @@ pub(crate) fn end(ctx: &Context) { with(ctx, |state| { state.record.canvas = state.record.canvas.filter(|_| !modal); state.record.foreign = foreign; + state.record.tab_in_egui = tab_in_egui; state.record.host_focus = host_focus; state.record.host_text = host_text; state.record.label_selection = label_selection; diff --git a/crates/ui-contract/src/runtime/focus/nav.rs b/crates/ui-contract/src/runtime/focus/nav.rs index abaaf0cdbd..ea4a6b2a94 100644 --- a/crates/ui-contract/src/runtime/focus/nav.rs +++ b/crates/ui-contract/src/runtime/focus/nav.rs @@ -184,6 +184,7 @@ impl State { pub(super) fn rotate(&mut self) { self.last_stops = std::mem::take(&mut self.stops); self.stop_ids.clear(); + self.stop_roots.clear(); self.last_scopes = std::mem::take(&mut self.scopes); self.last_scope_order = std::mem::take(&mut self.scope_order); self.last_groups = std::mem::take(&mut self.groups); @@ -193,6 +194,7 @@ impl State { self.body_from.clear(); self.entered = false; self.asked = false; + self.candidates_seen = 0; } /// The registrations of last pass, which Tab and the arrows move over. @@ -228,10 +230,12 @@ impl State { .or_else(|| self.stops.iter().chain(&self.last_stops).find(|rec| rec.stop.root == root).cloned()) } - /// Whether `id`, holding egui focus, is an app's own widget: no stop's root and, as `made` says, no widget a - /// component made (`pointer::made_by_component`). + /// Whether `id`, holding egui focus, is an app's own widget: as `made` says, no widget a component made + /// (`pointer::made_by_component`), and the root of no stop but the one every focusable egui widget of the app has + /// (`Stop::automatic`). The app's canvas (`host_canvas`, `KeyUse::chrome_key`) is none: its declared + /// keys route as a framework stop's do, so egui's arrows and Tab never move focus off it. pub(super) fn app_widget(&self, id: Id, made: bool) -> bool { - !made && self.find_stop((id, None)).is_none() && !self.stops.iter().chain(&self.last_stops).any(|rec| rec.stop.root == id) + !made && !self.stops.iter().chain(&self.last_stops).any(|rec| !rec.stop.automatic() && (rec.stop.root == id || rec.stop.key() == (id, None))) } /// Moves focus to `rec` and asks the enclosing scroll owner to reveal it: the egui widget is its root, and the stop @@ -648,7 +652,7 @@ impl State { } /// The opener of a scope that went away, or plays its exit, while focus was inside it. - fn restored_focus(&self, focused: Option) -> Option { + pub(super) fn restored_focus(&self, focused: Option) -> Option { let root = focused?; let key = *self.focused.get(&root).unwrap_or(&(root, None)); let inside = self.last_stops.iter().find(|rec| rec.stop.key() == key)?; @@ -910,6 +914,7 @@ pub(super) fn end(state: &mut State, focused: Option, on_app_widget: bool, f menu_bar_by_claim: std::mem::take(&mut state.menu_bar_by_claim), canvas: if stop.is_none() { state.stops.iter().find(|rec| rec.stop.keys.chrome_key).map(|rec| rec.stop.id) } else { None }, foreign: false, + tab_in_egui: false, host_focus: false, host_text: false, label_selection: false, diff --git a/crates/ui-contract/src/runtime/focus/registration.rs b/crates/ui-contract/src/runtime/focus/registration.rs index 56eaddb64f..a83dc80a26 100644 --- a/crates/ui-contract/src/runtime/focus/registration.rs +++ b/crates/ui-contract/src/runtime/focus/registration.rs @@ -37,8 +37,8 @@ pub struct Stop { /// The arena root the stop is shown in (a canvas whose body holds it), whether or not it joined the arena: a text /// stop keeps its own egui widget. A removed stop hands focus back to it. pub arena: Option, - /// The app's own egui widget (`focus::host_canvas`), which reads its keys from egui's input: the key stage leaves - /// the presses it routes to the stop there. + /// The app's own egui widget (`focus::host_canvas`, or any focusable egui widget the app draws), which reads its + /// keys from egui's input: the key stage leaves the presses it routes to the stop there. pub host: bool, } @@ -128,6 +128,12 @@ impl Stop { self } + /// Whether this is the stop every focusable egui widget the app draws gets by itself (`focus::take_app_widgets`): + /// the app's own widget, not declared as its canvas (`KeyUse::chrome_key`). No component or app call registered it. + pub fn automatic(&self) -> bool { + self.host && !self.keys.chrome_key + } + pub(crate) fn key(&self) -> StopKey { (self.id, self.part) } diff --git a/crates/ui-contract/src/runtime/frame.rs b/crates/ui-contract/src/runtime/frame.rs index 3531e0db63..98672ec6f1 100644 --- a/crates/ui-contract/src/runtime/frame.rs +++ b/crates/ui-contract/src/runtime/frame.rs @@ -582,6 +582,14 @@ pub fn discardable(ctx: &Context) -> bool { crate::runtime::egui::sizing::discardable(ctx) } +/// Whether egui will run the running pass again, so nothing of it paints: egui's `Context::will_discard`, or a discard +/// pass that layout memory asked for in this pass and requests from egui only at the pass's end. Host code that does +/// work once per shown frame (a frame count, a settle count) skips it while this is true; `will_discard` alone is still +/// false during the app's UI in a pass that a changed size runs again. +pub fn will_rerun(ctx: &Context) -> bool { + ctx.will_discard() || crate::runtime::layout_memory::discard_pending(ctx) +} + /// Discards the running pass, so nothing of it paints, and runs it again, when [`discardable`]: for a host that learns /// only after a part ran that the part showed what it must not. A pass after a discard carries no input (events, /// injected steps and press edges enter a frame's first pass only); held state persists. diff --git a/crates/ui-contract/src/runtime/ime.rs b/crates/ui-contract/src/runtime/ime.rs index edbfed6350..6c97d87ac6 100644 --- a/crates/ui-contract/src/runtime/ime.rs +++ b/crates/ui-contract/src/runtime/ime.rs @@ -51,6 +51,21 @@ struct Engine { discard: bool, /// What the editor that owns the IME reported at its last pass. editor: Option, + /// The app's own editor that wrote the IME output of the last pass while no framework editor owned the IME. + host: Option, + /// The reset requests of the app's own editor that a published IME output carried, its own or a framework editor's + /// it interrupted, oldest first, unanswered yet: their completions and retirements are the app's and stay in + /// egui's input for it, fence or not. The latest one published while the fence is up is the fence's `reset`. + host_resets: Vec, +} + +/// An app's own editor holding the IME: the owner and context generation of the IME output it wrote, and whether it +/// is composing, as the IME events left to it in egui's input say. +#[derive(Clone, Copy)] +struct HostIme { + owner: Id, + generation: u64, + composing: bool, } impl Stored for Engine {} @@ -185,6 +200,55 @@ impl Engine { self.interrupt = Some(owner); self.discard = true; } + + /// Interrupts the owner's input method context: a running composition is ended and fenced (`interrupt`); with none + /// running there are no late events to drop, and only the interrupt goes out. + fn interrupt_owner(&mut self, owner: Id) { + if self.composing { + self.interrupt(owner); + } else { + self.interrupt = Some(owner); + } + } + + /// Notes an answer to one of the app's own reset requests. A completion answers that request and every older one, + /// as completions arrive in request order, and ends the fence when it waits for one of them; a retirement answers + /// only its own request and, when the fence waits for it, leaves the end hook to ask again. + fn host_answered(&mut self, event: &Event) { + let (Event::ImeResetCompleted { request_id: id } | Event::ImeResetRetired { request_id: id }) = event else { return }; + let Some(at) = self.host_resets.iter().position(|own| own == id) else { return }; + let answered: Vec<_> = match event { + Event::ImeResetCompleted { .. } => self.host_resets.drain(..=at).collect(), + _ => vec![self.host_resets.remove(at)], + }; + if self.reset.is_some_and(|reset| answered.contains(&reset)) { + self.reset = None; + if matches!(event, Event::ImeResetCompleted { .. }) { + self.stale = false; + } + } + } + + /// Follows the composition of the app's own editor through the IME events left to it in egui's input, and + /// interrupts it at a pointer press, as a press ends a framework editor's composition. The one-press rule (H0) + /// holds the events after the press for the next frame, where the fence drops the composition's late deletions and + /// commits until the reset completes. + fn watch_host(&mut self, events: &[Arrived]) { + let Some(host) = self.host.as_mut() else { return }; + for arrived in events { + match (os::read(&arrived.event), &arrived.event) { + (Some(os::Raw::Preedit { text, .. }), _) => host.composing = !text.is_empty(), + (Some(os::Raw::Commit(_)), _) => host.composing = false, + (None, Event::PointerButton { pressed: true, .. }) if host.composing => { + host.composing = false; + let owner = host.owner; + self.interrupt(owner); + return; + } + _ => {} + } + } + } } fn with(ctx: &Context, viewport: ViewportId, f: impl FnOnce(&mut Engine) -> R) -> R { @@ -197,17 +261,46 @@ fn current(ctx: &Context, f: impl FnOnce(&mut Engine) -> R) -> R { /// The input hook: takes the IME events out of raw input while a framework editor owns the IME, or while the reset /// the engine asked for is pending (the late events of the interrupted composition, and the OS's answer), and removes -/// the keys that would end the composition. +/// the keys that would end the composition. With no framework editor, the events after the reset's completion are +/// the app's own editor's again, and the hook follows that editor's composition (`Engine::watch_host`). The answers to +/// the app's own reset requests always stay in egui's input for it; when the fence waits for one of them, its +/// completion ends the fence too. pub(crate) fn input_hook(ctx: &Context, events: &mut Vec, viewport: ViewportId) { with(ctx, viewport, |engine| { let take = engine.owner.is_some() || engine.reset.is_some(); + let host_resets = engine.host_resets.clone(); + let host_answer = |event: &Event| match event { + Event::ImeResetCompleted { request_id } | Event::ImeResetRetired { request_id } => host_resets.contains(request_id), + _ => false, + }; + let completed = + |id: egui::ImeResetId| move |arrived: &Arrived| matches!(arrived.event, Event::ImeResetCompleted { request_id } if request_id == id); + // The events after the completion are the app's; the completion too when it answers the app's own request. + let mut after = match engine.reset { + Some(id) if engine.owner.is_none() => { + let own = host_resets.contains(&id); + events.iter().position(completed(id)).map(|at| events.split_off(if own { at } else { at + 1 })) + } + _ => None, + }; let guarded = engine.composing || engine.guard > 0; let ends_composition = |event: &Event| { matches!(event, Event::Key { key: Key::Enter | Key::Escape | Key::Backspace | Key::Delete | Key::Space, pressed: true, .. }) }; - let taken = os::take_events(events, take, |event| guarded && ends_composition(event)); + let taken = os::take_events(events, |event| take && !host_answer(event), |event| guarded && ends_composition(event)); engine.queue.extend(taken); engine.guard = engine.guard.saturating_sub(1); + for arrived in events.iter().chain(after.iter().flatten()) { + engine.host_answered(&arrived.event); + } + if engine.owner.is_none() { + match &mut after { + Some(after) => engine.watch_host(after), + None if !take => engine.watch_host(events), + None => {} + } + } + events.extend(after.into_iter().flatten()); }); } @@ -340,11 +433,7 @@ pub(crate) fn request_interrupt(ctx: &Context, owner: Id) { if engine.owner != Some(owner) { return; } - if engine.composing { - engine.interrupt(owner); - } else { - engine.interrupt = Some(owner); - } + engine.interrupt_owner(owner); }); } @@ -405,11 +494,16 @@ pub(crate) fn note_caret(ctx: &Context, owner: Id, field: Rect, caret: Rect, pas } /// The end hook: observes the owner on the tracker, then writes the pass's IME output while a framework editor owns the -/// IME or an interrupt is due. Otherwise the output is egui's: an app's own `TextEdit` or IME reader writes it. +/// IME or an interrupt is due. Otherwise the output is egui's: an app's own `TextEdit` or IME reader writes it, and the +/// engine records that editor (`Engine::host`). An interrupt of the app's editor rides on the output it wrote this +/// pass, so its context does not change. pub(crate) fn end_pass(ctx: &Context) { let viewport = pass::current_viewport(ctx); let (frame_nr, pass_nr) = (ctx.cumulative_frame_nr_for(viewport), ctx.cumulative_pass_nr_for(viewport)); - let (owner, interrupt, caret, update, published) = with(ctx, viewport, |engine| { + let app_wrote = ctx.output(|output| output.ime.as_ref().map(|ime| (ime.owner, ime.context_generation))); + // egui publishes the app's request only in a pass that has an IME output. + let app_reset = app_wrote.and(os::app_reset(ctx, viewport)); + let (owner, interrupt, caret, update, published, host) = with(ctx, viewport, |engine| { let ran = std::mem::take(&mut engine.ran); if !ran { engine.edits.clear(); @@ -423,20 +517,38 @@ pub(crate) fn end_pass(ctx: &Context) { { engine.set_owner(None); } - // The fence has no request the integration can answer: the owner's output asks again. + // The app's editor as the last pass recorded it: an interrupt in a pass it wrote nothing names its context. + let last_host = engine.host; + let kept = engine.host.filter(|host| app_wrote.is_some_and(|(owner, _)| owner == host.owner)).is_some_and(|host| host.composing); + engine.host = app_wrote.filter(|_| engine.owner.is_none()).map(|(owner, generation)| HostIme { owner, generation, composing: kept }); + // The app's request: every output this pass publishes carries it, the app's own or the engine's, and a new one + // becomes the fence's request after the write. While a framework editor owns the IME, egui publishes it on that + // editor's output as an interrupt, so the engine takes it as its own interrupt of the owner. + let fresh = app_reset.filter(|id| !engine.host_resets.contains(id)); + if fresh.is_some() + && let Some(owner) = engine.owner + { + engine.interrupt_owner(owner); + } + // The fence has no request the integration can answer: the owner's output asks again, a framework editor's + // or the app's own. if engine.stale && engine.reset.is_none() - && let Some(owner) = engine.owner + && fresh.is_none() + && let Some(owner) = engine.owner.or(engine.host.map(|host| host.owner)) { engine.interrupt.get_or_insert(owner); } let caret = engine.caret.take(); let password = caret.filter(|(id, ..)| Some(*id) == engine.owner).map(|(.., password)| password); let update = engine.observe(viewport, frame_nr, pass_nr, password); - (engine.owner, engine.interrupt.take(), caret, update, engine.published) + (engine.owner, engine.interrupt.take(), caret, update, engine.published, last_host) }); + let host_interrupt = interrupt.filter(|old| owner.is_none() && app_wrote.is_some_and(|(id, _)| id == *old)); let written = if owner.is_none() && interrupt.is_none() { None + } else if host_interrupt.is_some() { + Some((os::interrupt_written(ctx, viewport, app_reset), None)) } else { os::clear(ctx); match (caret, interrupt, update) { @@ -447,6 +559,7 @@ pub(crate) fn end_pass(ctx: &Context) { field, caret, interrupt: interrupt.is_some(), + app_reset, generation, password, surrounding: update.surrounding_text, @@ -455,14 +568,16 @@ pub(crate) fn end_pass(ctx: &Context) { Some((os::write(ctx, viewport, out), Some(generation))) } // The old owner still gets an output in the pass it lost focus, or the OS never interrupts. It names the - // context the OS composes in, the last one published. + // context the OS composes in: the last one published, or the one the app's editor wrote last. (_, Some(old), _) => { + let generation = host.filter(|host| host.owner == old).map_or(published.unwrap_or_default(), |host| host.generation); let out = os::Output { owner: old, field: Rect::NOTHING, caret: Rect::NOTHING, interrupt: true, - generation: published.unwrap_or_default(), + app_reset, + generation, password: false, surrounding: IMESurroundingText::Unavailable, cause: ImeChangeCause::Other, @@ -472,14 +587,27 @@ pub(crate) fn end_pass(ctx: &Context) { _ => None, } }; - if let Some((reset, generation)) = written { - with(ctx, viewport, |engine| { + // The app's request counts as its own only when the published output carries it: egui's own output when the + // engine wrote none, else the engine's. + let carried = app_reset.filter(|id| written.as_ref().is_none_or(|(reset, _)| *reset == Some(*id))); + with(ctx, viewport, |engine| { + if let Some((reset, generation)) = written { if generation.is_some() { engine.published = generation; } if interrupt.is_some() { engine.reset = reset; } - }); - } + } + if let Some(id) = carried + && !engine.host_resets.contains(&id) + { + engine.host_resets.push(id); + // Completions arrive in request order: the latest request's completion ends the interrupted composition, + // whichever request the fence waited for. + if engine.stale { + engine.reset = Some(id); + } + } + }); } diff --git a/crates/ui-contract/src/runtime/keys.rs b/crates/ui-contract/src/runtime/keys.rs index a09f13fb0a..c2762c7415 100644 --- a/crates/ui-contract/src/runtime/keys.rs +++ b/crates/ui-contract/src/runtime/keys.rs @@ -66,9 +66,6 @@ pub enum MenuKey { pub(crate) struct NavKeys { pub(crate) tabs: Vec, pub(crate) panes: Vec, - /// The input hook left a bare Tab in egui's input: nothing has the focus and the window registered no focus stop, - /// so the framework has nothing to move to and egui moves its own focus. - pub(crate) tab_to_egui: bool, } struct Press { @@ -325,6 +322,9 @@ pub(crate) struct Stage { pasted: Option<(Id, ClipContent)>, /// Edit commands fired from the queue for the focused component. queued_edits: Vec, + /// A component read its intents in this pass, so the pass's UI is running: an edit fired from now on waits for the + /// next pass. + intents_read: bool, /// The components that asked for a context menu in this pass, with the rect it opens at. contexts: Vec<(Id, egui::Rect, Option)>, /// Components with an open edit run this pass: Escape cancels the run before it leaves a row's child. diff --git a/crates/ui-contract/src/runtime/keys/input.rs b/crates/ui-contract/src/runtime/keys/input.rs index f1f0c09e1f..10fc04150f 100644 --- a/crates/ui-contract/src/runtime/keys/input.rs +++ b/crates/ui-contract/src/runtime/keys/input.rs @@ -42,24 +42,20 @@ struct Strip<'a> { holds_drafts: bool, /// A dialog keeps a canvas open and Space belongs to it: the press is the canvas's momentary command chord. canvas_space: bool, - /// An app's own egui widget or popup has the focus (`FocusedRecord::foreign`): Tab, Escape and the clipboard - /// events are its own. + /// An app's own egui widget or popup has the focus (`FocusedRecord::foreign`): Escape, the plain Enter and the + /// clipboard events are its own, and no window intent comes of them. foreign: bool, + /// A bare Tab is egui's: an app's own popup is open, or the app's own focused widget keeps Tab by its egui key + /// filter (`FocusedRecord::tab_in_egui`), or the window has no stop to move the focus to and nothing focused + /// (`focus::tab_has_no_stop`), so the Tab is the app's own binding's. + tab_in_egui: bool, /// The focused stop is the app's own egui widget (`Stop::host`, `FocusedRecord::host`), which reads its keys from /// egui: its Escape stays there, as an app's own focused widget's does. Tab and the arrows follow its `KeyUse`, as /// the framework's navigation reads it. host: bool, - /// The keys of the window's canvas while nothing has the focus, neither a framework stop nor an app's own widget - /// or popup: the canvas is then the key target, as the chrome gate takes it, and reads from egui the keys its - /// `KeyUse` keeps (Tab with `KeepKeys::Tab`). - canvas: Option, /// The edit set whose clipboard events and edit chords stay in egui's input: the focused stop's when it is the - /// app's own widget (`host`), else the canvas's with nothing focused (`canvas`). + /// app's own widget (`host`), else the window canvas's with nothing focused (`target_canvas`). egui_edits: EditSet, - /// egui holds no focus and the window registered no focus stop in its last pass: a framework focus move has - /// nowhere to go, so a bare Tab is egui's. Focus on a component's widget without a stop is focus: egui would take - /// a Tab from it as a move to the next widget it shows, in a later pass. - no_stops: bool, /// egui holds a label text selection, which a copy or cut event copies. label_selection: bool, /// A tool host claimed the lone Alt tap: it goes to the claimer on every OS, not to the menu bar. @@ -346,6 +342,7 @@ impl Strip<'_> { let ctrl_tab = key == Key::Tab && (if self.os == Os::Mac { mods.ctrl && !mods.cmd } else { mods.cmd }); let ctrl_tab = ctrl_tab && self.pages && !self.keeps_tab; let bare_tab = key == Key::Tab && !mods.cmd && !mods.ctrl && !mods.alt; + let plain_enter = key == Key::Enter && mods.is_none(); // Alt and Shift ride along, as with Enter: a canvas tool reads them; Cmd and Ctrl chords are the app's. While // the focused stop records, Escape with any modifier held is a chord for the recorder; only plain Escape is a // scope escape. Over an open press any Escape is the press's cancel: a borrowed tool's drag holds Cmd. Shift or @@ -364,7 +361,6 @@ impl Strip<'_> { let edit = self.edit_chords.iter().find(|(command, chord)| (self.edits)(*command) && self.layout.matches(chord, input, self.os)); let egui_edit = self.edit_chords.iter().any(|(command, chord)| self.egui_edits.contains(*command) && self.layout.matches(chord, input, self.os)); - let canvas_tab = bare_tab && self.canvas.is_some_and(|canvas| canvas.keep == focus::KeepKeys::Tab); // The chrome keys are Tab's, which the bare-Tab arm and `take_nav` read. let window_shortcut = self .window_shortcuts @@ -377,10 +373,12 @@ impl Strip<'_> { PressUse::Edit(*command) } else if key == Key::Space && self.canvas_space { PressUse::CanvasSpace - } else if (self.foreign && (bare_tab || escape)) || (self.host && escape && !self.press_captured) || canvas_tab || egui_edit { + } else if (self.foreign && (escape || plain_enter)) + || (bare_tab && self.tab_in_egui) + || (self.host && escape && !self.press_captured) + || egui_edit + { PressUse::Egui - } else if bare_tab && self.no_stops { - PressUse::TabToEgui } else if bare_tab && !self.keeps_tab { PressUse::Tab } else if ctrl_tab { @@ -441,11 +439,6 @@ impl Strip<'_> { // the key from egui; the runtime routes nothing for it, so no shortcut toggles the chrome or fires an edit // command with it either. PressUse::Egui => true, - PressUse::TabToEgui => { - // egui moves its own focus with it, from nothing focused into the app's own widgets (`focus::begin`). - batch.nav.tab_to_egui = true; - true - } PressUse::Tab => { batch.tabs.push(TabPress { input: *input, repeat, at, place: batch.place }); false @@ -535,8 +528,6 @@ enum PressUse { CanvasSpace, /// The app's own widget or popup, or the canvas with nothing focused, reads the key from egui. Egui, - /// A bare Tab egui moves its own focus with. - TabToEgui, /// A bare Tab: a focus move or a chrome toggle, which `take_nav` decides. Tab, /// The page switch of the focused stop. @@ -667,7 +658,6 @@ pub(crate) fn input_hook(ctx: &Context, input: &RawInput, events: &mut Vec; @@ -676,6 +666,7 @@ pub(crate) fn input_hook(ctx: &Context, input: &RawInput, events: &mut Vec bool { @@ -256,7 +264,11 @@ fn editor_input_of(intent: &Intent, shift: bool) -> Option { /// The intents routed to `id` this pass, with physical horizontal moves read in the component's direction. #[doc(hidden)] pub fn intents_of(ctx: &Context, id: Option, rtl: bool) -> Intents { - let routed = current(ctx, |stage| stage.routed.get(&id).cloned()).unwrap_or_default(); + let routed = current(ctx, |stage| { + stage.intents_read = true; + stage.routed.get(&id).cloned() + }) + .unwrap_or_default(); let flip = |mv| match (rtl, mv) { (true, NavMove::Back) => NavMove::Forward, (true, NavMove::Forward) => NavMove::Back, diff --git a/crates/ui-contract/src/runtime/keys/nodes.rs b/crates/ui-contract/src/runtime/keys/nodes.rs index aed007d293..5cb66d5313 100644 --- a/crates/ui-contract/src/runtime/keys/nodes.rs +++ b/crates/ui-contract/src/runtime/keys/nodes.rs @@ -11,6 +11,7 @@ pub(crate) fn redirect_node(ctx: &Context, node: Id, owner: Id, part: PartRef) { // Journaled after the `register_node` it amends, so a settled view's replay leaves the row's node with the // collection, as a run does. crate::runtime::replay::journal(ctx, || (node, owner, part), |ctx, &(node, owner, part)| redirect_node(ctx, node, owner, part)); + crate::runtime::replay::note_node_owner(ctx, owner); current(ctx, |stage| { if let Some(entry) = stage.nodes.get_mut(&node_key(node)) { entry.owner = owner; @@ -37,6 +38,7 @@ pub(crate) fn register_node(ctx: &Context, node: Id, owner: Id, part: Option EscapeRouting { let target = focus::focused_rec(ctx); let (batch, nodes, captures, held_claims, alt_claims, fired_claims, hover_deletes) = current(ctx, |stage| { stage.routed.clear(); + stage.intents_read = false; stage.contexts.clear(); stage.claimed.clear(); stage.activated.clear(); @@ -548,19 +549,27 @@ pub(crate) fn take_shortcuts(ctx: &Context) -> Shortcuts { shortcuts } -/// Asks the focused component of the running viewport to take `command` as `Intent::Edit` in the next pass. +/// Asks the focused component of the running viewport to take `command` as `Intent::Edit`: in this pass when no +/// component has read its intents in it yet (a system menu pick the host dispatches before the UI), else in the next +/// pass (a pick in the window's own menus or bars, which run in the UI). /// `false` when it does not list the command, or is the app's own widget (`Stop::host`), whose edits are the app's. A paste asks the platform for the clipboard text, which arrives as /// the paste event that becomes the intent. Focus is read as it is now: a menu pick returns focus in its pass /// before its command fires, and the command goes where focus returned. pub(crate) fn queue_edit(ctx: &Context, command: EditCommand) -> bool { let viewport = crate::runtime::egui::pass::current_viewport(ctx); - if !focus::focused_rec(ctx).is_some_and(|rec| !rec.stop.host && rec.stop.keys.edits.contains(command)) { + let Some(id) = focus::focused_rec(ctx).filter(|rec| !rec.stop.host && rec.stop.keys.edits.contains(command)).map(|rec| rec.stop.id) else { return false; - } + }; if command == EditCommand::Paste { crate::runtime::egui::clipboard::request_paste(ctx); - } else { - with(ctx, viewport, |stage| stage.queued_edits.push(command)); + } else if with(ctx, viewport, |stage| { + if !stage.intents_read { + push(&mut stage.routed, Some(id), Intent::Edit(command), false); + } else { + stage.queued_edits.push(command); + } + stage.intents_read + }) { crate::runtime::egui::repaint::request_of(ctx, viewport); } true diff --git a/crates/ui-contract/src/runtime/layout_memory.rs b/crates/ui-contract/src/runtime/layout_memory.rs index 41cb3f9623..dbea6d3e98 100644 --- a/crates/ui-contract/src/runtime/layout_memory.rs +++ b/crates/ui-contract/src/runtime/layout_memory.rs @@ -244,9 +244,11 @@ pub(crate) struct Entries { replaying: Vec<(Arc, Id, usize)>, /// The drafts open, innermost last. drafts: Vec, + /// This pass asked for the frame's discard pass; the end hook requests it. ask: bool, /// How many times a discard pass was asked, so a record open around the asking run notes it (`with`). asks: u64, + /// The frame whose one discard pass the end hook requested. asked: Option, } @@ -1175,6 +1177,13 @@ pub(crate) fn ask_discard(ctx: &Context) { with(ctx, &moment, Entries::ask_discard); } +/// Whether this pass asked for the frame's discard pass and the end hook will request it from egui: no earlier pass of +/// the frame got it, and egui can still run this one again. +pub(crate) fn discard_pending(ctx: &Context) -> bool { + let moment = Moment::of(ctx); + with(ctx, &moment, |memory| memory.ask && memory.asked != Some(moment.frame)) && sizing::discardable(ctx) +} + /// Keeps the entries and kept transcripts of `ids` through this frame, for a replayed run that kept them /// (`replay::note_layout_keep`): the replay does not reach them, and an entry no pass touched in a frame is dropped. pub(crate) fn keep(ctx: &Context, ids: &[Id]) { diff --git a/crates/ui-contract/src/runtime/lazy.rs b/crates/ui-contract/src/runtime/lazy.rs index 9c6694bf8e..db7583281b 100644 --- a/crates/ui-contract/src/runtime/lazy.rs +++ b/crates/ui-contract/src/runtime/lazy.rs @@ -552,7 +552,7 @@ pub(crate) fn settled( && !facts.discards && facts.quiet(now, edited.as_ref()) && !settled.record.focus.stop_ids().any(|stop| revealed == Some(stop) || routed.contains(&stop)) - && !routed.iter().any(|id| settled.record.widgets.contains(id)) + && !routed.iter().any(|id| settled.record.widgets.contains(id) || settled.record.facts.node_owners.contains(id)) && !dragged.is_some_and(|widget| settled.record.widgets.contains(&widget)) && focused.within(&settled.record.focus, &settled.record.widgets) == settled.record.held }); diff --git a/crates/ui-contract/src/runtime/overlay.rs b/crates/ui-contract/src/runtime/overlay.rs index d844675ba1..90159f12f3 100644 --- a/crates/ui-contract/src/runtime/overlay.rs +++ b/crates/ui-contract/src/runtime/overlay.rs @@ -501,6 +501,11 @@ pub fn entry(ctx: &Context, id: Id) -> Option { with_pass(ctx, |pass| pass.last.iter().find(|entry| entry.id == id).cloned()) } +/// The actual egui layer registered for `id` in this pass, never an old or exiting entry or an OS-window placeholder. +pub(crate) fn current_egui_layer(ctx: &Context, id: Id) -> Option { + with_pass(ctx, |pass| pass.current.iter().find(|entry| entry.id == id && !entry.exiting && !entry.window).map(|entry| entry.layer)) +} + /// The side of its anchor the layer `id` was placed on in this pass, once its host placed it by a known size. pub(crate) fn placed_side(ctx: &Context, id: Id) -> Option { with_pass(ctx, |pass| pass.sides.iter().rev().find(|(layer, _)| *layer == id).map(|(_, side)| *side)) @@ -659,7 +664,8 @@ pub(crate) fn released_inside(ctx: &Context, rect: Rect) -> bool { } /// Brings the family of the open layer `id` in front of the other families of its class at the end of this pass, as a -/// press on it does. +/// press on it does: a floating window goes to the top of egui's area order, which it shares with the app's own egui +/// windows. pub fn raise(ctx: &Context, id: Id) { with_pass(ctx, |pass| pass.raise.push(id)); } diff --git a/crates/ui-contract/src/runtime/pointer.rs b/crates/ui-contract/src/runtime/pointer.rs index 5c3f115005..58539fbe32 100644 --- a/crates/ui-contract/src/runtime/pointer.rs +++ b/crates/ui-contract/src/runtime/pointer.rs @@ -229,6 +229,9 @@ pub(crate) struct Shapes { /// the last, each with its component: such a widget takes its press itself. this_texts: IdMap, last_texts: IdMap, + /// Every id components registered or made in the running pass: the roots, their egui widgets and the widgets made + /// for their text and editor parts (`made_by_component`). + this_made: IdSet, /// The layers' own egui widgets (an overlay `Area`'s, which senses a click where nothing on the layer does) in the /// running pass and the last: such a widget lies under every widget and shape on its layer and stands for none. this_grounds: IdSet, @@ -250,6 +253,9 @@ pub(crate) struct Shapes { /// The resolutions the running pass made (`find_under`), for the count trials. #[cfg(feature = "testing")] resolutions: u32, + /// The `made_by_component` lookups the running pass made, for the count trials. + #[cfg(feature = "testing")] + made_lookups: u32, } /// The begin hook (H5): converts the pass's pointer input. @@ -373,6 +379,7 @@ pub(crate) fn begin(ctx: &Context, hit: HitSizes, latched: craft_keymap::Mods) { shapes.last = std::mem::take(&mut shapes.this); shapes.last_bodies = std::mem::take(&mut shapes.this_bodies); shapes.last_texts = std::mem::take(&mut shapes.this_texts); + shapes.this_made.clear(); shapes.last_grounds = std::mem::take(&mut shapes.this_grounds); shapes.next = 0; shapes.hover = None; @@ -381,6 +388,7 @@ pub(crate) fn begin(ctx: &Context, hit: HitSizes, latched: craft_keymap::Mods) { #[cfg(feature = "testing")] { shapes.resolutions = 0; + shapes.made_lookups = 0; } }); // The pointer's hover is resolved once for the pass, over last pass's complete record, with the targets egui's hit @@ -411,6 +419,13 @@ pub(crate) fn pass_of(ctx: &Context) -> u64 { pass::pass_nr(ctx, pass::current_viewport(ctx)) } +/// The primary press of this pass when it went down in `rect` on `layer` (`areas::lies_in`), whatever takes it. Read +/// as the press step reads it, without noting a pointer input: the press engages the sensing of what it lands on. +pub(crate) fn primary_press_in(ctx: &Context, layer: Layer, rect: egui::Rect) -> Option { + with_pass_raw(ctx, |pass| pass.frame.as_ref().and_then(|frame| frame.press)) + .filter(|press| press.button == PointerButton::Primary && areas::lies_in(ctx, layer, rect, press.origin)) +} + /// What the begin hook read of the running pass. pub(crate) fn pass_pointer(ctx: &Context) -> Arc { let viewport = pass::current_viewport(ctx); @@ -614,6 +629,7 @@ pub(crate) fn add_shapes_in(ctx: &Context, viewport: ViewportId, layer: Layer, r PerViewport::::with(ctx, viewport, |record| { let order = record.next; record.next += 1; + record.this_made.insert(root); let entry = record.this.entry(layer).or_default().entry(root).or_default(); entry.shapes.extend(shapes); entry.placed.resize(entry.shapes.len(), Placed { order, clip }); @@ -621,11 +637,13 @@ pub(crate) fn add_shapes_in(ctx: &Context, viewport: ViewportId, layer: Layer, r } /// Records the egui widget `widget` that the component `owner` made for its own text (a field's text, a selection -/// part): a press egui gives it is the widget's own and goes to no root, and the hover goes to `owner`. +/// part, an editor part's focus widget): a press egui gives it is the widget's own and goes to no root, and the hover +/// goes to `owner`. pub(crate) fn record_text_widget(ctx: &Context, widget: Id, owner: Id) { crate::runtime::replay::journal(ctx, || (widget, owner), |ctx, &(widget, owner)| record_text_widget(ctx, widget, owner)); PerViewport::::with(ctx, pass::current_viewport(ctx), |record| { record.this_texts.insert(widget, owner); + record.this_made.insert(widget); }); } @@ -662,6 +680,8 @@ pub(crate) fn record_widgets_in(ctx: &Context, viewport: ViewportId, layer: Laye |ctx, (layer, root, widgets, click)| record_widgets(ctx, *layer, *root, widgets, *click), ); PerViewport::::with(ctx, viewport, |record| { + record.this_made.insert(root); + record.this_made.extend(widgets.iter().copied()); let entry = record.this.entry(layer).or_default().entry(root).or_default(); entry.widgets.extend_from_slice(widgets); entry.click |= click; @@ -834,13 +854,24 @@ pub(crate) fn registered_widgets(ctx: &Context) -> std::collections::HashSet }) } -/// Whether `id` is a root or an egui widget that a component registered in the running pass of `viewport`. +/// Whether `id` is a root, an egui widget that a component registered, or a widget a component made for its text or +/// editor part, in the running pass of `viewport`. pub(crate) fn made_by_component(ctx: &Context, viewport: ViewportId, id: Id) -> bool { PerViewport::::with(ctx, viewport, |record| { - record.this.values().any(|roots| roots.contains_key(&id) || roots.values().any(|root| root.widgets.contains(&id))) + #[cfg(feature = "testing")] + { + record.made_lookups += 1; + } + record.this_made.contains(&id) }) } +/// How many `made_by_component` lookups the running pass of `viewport` made so far, for the count trials. +#[cfg(feature = "testing")] +pub(crate) fn made_lookups(ctx: &Context, viewport: ViewportId) -> u32 { + PerViewport::::with(ctx, viewport, |record| record.made_lookups) +} + /// The roots a press at a point goes to, each with the shape of it that wins it: its click's and its drag's (8.3, H7). /// Among the roots under the point ([`Under`]), each resolves its own shapes by the arena rule, and the roots rank by /// their winning shapes' place in the pass's paint order, top first. The top one takes every kind of press its shape diff --git a/crates/ui-contract/src/runtime/replay.rs b/crates/ui-contract/src/runtime/replay.rs index c89872ac5b..68213a9c3b 100644 --- a/crates/ui-contract/src/runtime/replay.rs +++ b/crates/ui-contract/src/runtime/replay.rs @@ -167,6 +167,9 @@ pub(crate) struct Facts { /// The components whose memory owners registered in the run (`memory::register_owner`): a replay needs their /// shown-tier state still kept (`memory::ended_since`). pub(crate) owners: Vec, + /// The components that take the AccessKit requests on the nodes the run registered (`note_node_owner`): a request + /// routed to one of them is routed into the run, though the component is no egui widget (a collection's row). + pub(crate) node_owners: Vec, /// The layout memory entries the run kept (`note_layout_keep`): a replay keeps them (`layout_memory::keep`). pub(crate) layout_keeps: Vec, /// The derived values the run asked for (`note_derived_keep`): a replay keeps them, since it asks for none. @@ -293,6 +296,7 @@ pub(crate) fn close(ctx: &Context, layer: Layer) -> Record { outer.facts.blocked |= open.facts.blocked; outer.facts.discards |= open.facts.discards; outer.facts.owners.extend(open.facts.owners.iter().copied()); + outer.facts.node_owners.extend(open.facts.node_owners.iter().copied()); outer.facts.layout_keeps.extend(open.facts.layout_keeps.iter().copied()); outer.facts.derived_keeps.extend(open.facts.derived_keeps.iter().copied()); outer.facts.wake = min_wake(outer.facts.wake, open.facts.wake); @@ -579,6 +583,12 @@ pub(crate) fn note_derived_keep(ctx: &Context, slot: egui::Id) { with_open(ctx, |facts| facts.derived_keeps.push(slot)); } +/// Notes that `owner` takes the AccessKit requests on a node the running code registered (`keys::register_node`). A +/// replay registers the node again from its journal, which notes it in the records open around the replay. +pub(crate) fn note_node_owner(ctx: &Context, owner: egui::Id) { + with_open(ctx, |facts| facts.node_owners.push(owner)); +} + /// Notes that the memory owner `owner` registered in the running code. pub(crate) fn note_owner(ctx: &Context, owner: egui::Id) { with_open(ctx, |facts| facts.owners.push(owner)); diff --git a/crates/ui-contract/src/style/cx.rs b/crates/ui-contract/src/style/cx.rs index ccc0377e8f..30d36336f3 100644 --- a/crates/ui-contract/src/style/cx.rs +++ b/crates/ui-contract/src/style/cx.rs @@ -396,6 +396,15 @@ impl<'a> StyleCx<'a> { BySize { sm: icon.glyph_sm, md: icon.glyph_md }.get(self.size) } + /// The height of a push button at the ambient size: `size.button` at the medium size, grown as a control's height + /// is; a small button stands a small control high. + pub fn button_height(&self) -> f32 { + match self.size { + ControlSize::Sm => self.control().height, + ControlSize::Md => grown(self.tokens, self.tokens.size.button, self.line_ratio), + } + } + /// How the icon-only buttons of the scope show their glyph. pub fn glyph_role(&self) -> GlyphRole { self.glyphs @@ -564,10 +573,15 @@ impl<'a> StyleCx<'a> { /// token's type line: the control's vertical padding (the token height less the label role's line height, which /// the token already holds) around the leading face's line height at the label size. `line_ratio` is that face's /// line height per point of text (`0` with no stack installed: the token alone). +/// A control height token grown by what a label line under `line_ratio` takes beyond the label's line height. +fn grown(tokens: &UiTokens, token: f32, line_ratio: f32) -> f32 { + let label = tokens.typography.label; + token + (line_ratio * label.size - label.line_height).max(0.0) +} + pub(crate) fn control_metrics(tokens: &UiTokens, size: ControlSize, line_ratio: f32) -> ControlMetrics { let sizes = &tokens.size; - let label = tokens.typography.label; - let grown = |token: f32| token + (line_ratio * label.size - label.line_height).max(0.0); + let grown = |token: f32| grown(tokens, token, line_ratio); let pad = tokens.space.pad.control; let gap = tokens.space.gap.inline; ControlMetrics::at( diff --git a/crates/ui-contract/src/testing/bypass.rs b/crates/ui-contract/src/testing/bypass.rs index ec44a2076b..815bf36289 100644 --- a/crates/ui-contract/src/testing/bypass.rs +++ b/crates/ui-contract/src/testing/bypass.rs @@ -1,7 +1,8 @@ //! Bypass detection (24.2): the pass-end walk that finds what a component made without the runtime. //! //! Every interactive egui widget of the latest pass must be one a component registered (a root or one of its -//! widgets, a focus stop's root) or one the runtime noted. Every AccessKit node that declares an action must +//! widgets, the root of a focus stop that something registered: not the stop every focusable egui widget gets by +//! itself, `Stop::automatic`) or one the runtime noted. Every AccessKit node that declares an action must //! come from the runtime's node writer. A raw `ui.interact`, `ui.button` or `ui.add(Slider)` in a component //! fails here, with the id of the offender. @@ -24,7 +25,7 @@ pub fn findings(fixture: &Fixture) -> Vec { let mut registered: HashSet = pointer::registered_widgets(ctx); registered.extend(noted_widgets); focus::with_viewport(ctx, egui::ViewportId::ROOT, |state| { - registered.extend(state.stops.iter().chain(&state.last_stops).map(|rec| rec.stop.root)); + registered.extend(state.stops.iter().chain(&state.last_stops).filter(|rec| !rec.stop.automatic()).map(|rec| rec.stop.root)); }); let mut found: Vec = widgets::interactive(ctx) .into_iter() diff --git a/crates/ui-contract/src/testing/host_key_trials.rs b/crates/ui-contract/src/testing/host_key_trials.rs index b010e48678..393718b49f 100644 --- a/crates/ui-contract/src/testing/host_key_trials.rs +++ b/crates/ui-contract/src/testing/host_key_trials.rs @@ -9,6 +9,7 @@ use crate::runtime::egui::{areas, fixture}; use crate::runtime::env::{Env, RootEnv}; use crate::runtime::focus::{EditSet, FocusPolicy, FocusTarget, KeepKeys, KeyUse, host_canvas, request}; use crate::runtime::frame::{ChromeToggle, take_output}; +use crate::runtime::ime; use crate::runtime::keys::with_window_intents; use crate::style::{ComponentStyle, StyleCx}; use crate::testing::focus::{Stop, egui_focused, key_release, named_id, pop_scope, push_scope, register_stop, widget}; @@ -172,8 +173,216 @@ fn a_focused_egui_field_takes_the_ime() { assert_eq!(host.borrow().text, "世", "the commit reaches the field"); } +fn host_editor_id() -> Id { + named_id("host editor") +} + +/// A window with the app's own IME editor (`fixture::host_ime_editor`), and the text it holds. +fn host_editor() -> (Rc>, impl FnMut(&mut Ui)) { + let text = Rc::new(RefCell::new(String::new())); + let held = Rc::clone(&text); + let rect = Rect::from_min_size(Pos2::new(100.0, 100.0), egui::vec2(200.0, 30.0)); + (text, move |ui: &mut Ui| fixture::host_ime_editor(ui, host_editor_id(), rect, &mut held.borrow_mut())) +} + +/// A press during the app's own editor's composition interrupts it, in the editor's own IME context, and fences the +/// composition's late deletion and commit, which the one-press rule holds for the next frame, until the reset +/// completes; the events after the completion reach the editor. #[trial] -fn a_focused_egui_field_keeps_tab_escape_and_the_clipboard() { +fn a_press_during_an_app_editor_s_composition_fences_its_late_ime_events() { + let (editor, mut show) = host_editor(); + let mut frames = Frames::new(); + frames.idle(2, &mut show); + frames.frame(vec![Event::Ime(ImeEvent::Commit("ab".to_owned()))], &mut show); + frames.frame(vec![Event::Ime(ImeEvent::Preedit { text: "z".to_owned(), active_range_chars: None })], &mut show); + let at = Pos2::new(150.0, 115.0); + let late = vec![ + moved(at), + press(at), + Event::Ime(ImeEvent::DeleteSurrounding { before_chars: 1, after_chars: 0 }), + Event::Ime(ImeEvent::Commit("Q".to_owned())), + ]; + frames.frame(late, &mut show); + let ime = frames.ime(); + assert!(ime.is_some(), "the editor writes the pass's IME output"); + let Some(ime) = ime else { return }; + assert!(ime.owner == host_editor_id() && ime.interrupt, "the press interrupts the editor's composition in its own context"); + assert!(ime.reset.is_some(), "the interrupt asks for a reset"); + let Some(reset) = ime.reset else { return }; + frames.frame(vec![release(at)], &mut show); + frames.frame(Vec::new(), &mut show); + assert_eq!(*editor.borrow(), "ab", "the composition's late deletion and commit never reach the editor"); + frames.frame(vec![Event::ImeResetCompleted { request_id: reset }, Event::Ime(ImeEvent::Commit("X".to_owned()))], &mut show); + assert_eq!(*editor.borrow(), "abX", "the commit after the completion reaches the editor"); +} + +/// The app's own resetting editor at its rect, the show closure that draws it, and the frames after two idle ones, +/// a commit of "ab" and a preedit of "z": the editor composes. `in_output`: the editor writes its reset request into +/// its IME output too, instead of leaving it to egui as EffectCraft's editor does. +fn composing_resetting_editor(in_output: bool) -> (Rc>, impl FnMut(&mut Ui), Frames) { + let editor = Rc::new(RefCell::new(fixture::ResettingEditor { in_output, ..Default::default() })); + let held = Rc::clone(&editor); + let rect = Rect::from_min_size(Pos2::new(100.0, 100.0), egui::vec2(200.0, 30.0)); + let mut show = move |ui: &mut Ui| fixture::host_resetting_ime_editor(ui, host_editor_id(), rect, &mut held.borrow_mut()); + let mut frames = Frames::new(); + frames.idle(2, &mut show); + frames.frame(vec![Event::Ime(ImeEvent::Commit("ab".to_owned()))], &mut show); + frames.frame(vec![Event::Ime(ImeEvent::Preedit { text: "z".to_owned(), active_range_chars: None })], &mut show); + (editor, show, frames) +} + +/// The press at `at` with the composition's late deletion and commit after it, in one frame. +fn press_with_late_ime(at: Pos2) -> Vec { + vec![ + moved(at), + press(at), + Event::Ime(ImeEvent::DeleteSurrounding { before_chars: 1, after_chars: 0 }), + Event::Ime(ImeEvent::Commit("Q".to_owned())), + ] +} + +/// An app editor that asks for its own reset at the press that interrupts its composition keeps that request: the +/// platform is asked to answer the app's id, the late events stay fenced, and the completion reaches the editor, which +/// takes the events after it and composes again. The editor asks through egui alone, or writes the request into its +/// output too. +#[trial] +fn an_app_editor_s_own_reset_at_the_press_reaches_it_and_it_composes_again() { + for in_output in [false, true] { + let (editor, mut show, mut frames) = composing_resetting_editor(in_output); + let at = Pos2::new(150.0, 115.0); + frames.frame(press_with_late_ime(at), &mut show); + let own = editor.borrow().reset; + assert!(own.is_some(), "the editor asked for its own reset at the press"); + let reset = frames.ime().and_then(|ime| ime.interrupt.then_some(ime.reset).flatten()); + assert_eq!(reset, own, "the interrupt asks the platform to answer the editor's own request (in_output {in_output})"); + let Some(reset) = reset else { return }; + frames.frame(vec![release(at)], &mut show); + frames.frame(Vec::new(), &mut show); + assert_eq!(editor.borrow().text, "ab", "the composition's late deletion and commit never reach the editor"); + frames.frame(vec![Event::ImeResetCompleted { request_id: reset }, Event::Ime(ImeEvent::Commit("X".to_owned()))], &mut show); + assert_eq!(editor.borrow().reset, None, "the completion of its own request reaches the editor"); + assert_eq!(editor.borrow().text, "abX", "the commit after it reaches the editor"); + frames.frame(vec![Event::Ime(ImeEvent::Preedit { text: "y".to_owned(), active_range_chars: None })], &mut show); + assert!(editor.borrow().composing, "the editor composes again"); + } +} + +/// A press outside the app's editor fences its composition with the framework's own reset request; a reset the app +/// asks for in a later pass becomes the one the fence waits for. Its completion ends the fence, the commit after it +/// reaches the editor, and the framework's request is never answered. +#[trial] +fn an_app_editor_s_later_reset_ends_the_fence() { + let (editor, mut show, mut frames) = composing_resetting_editor(false); + let outside = Pos2::new(500.0, 400.0); + frames.frame(press_with_late_ime(outside), &mut show); + let fence = frames.ime().and_then(|ime| ime.interrupt.then_some(ime.reset).flatten()); + assert!(fence.is_some() && editor.borrow().reset.is_none(), "the framework fences with its own request; the editor asks nothing"); + frames.frame(vec![release(outside)], &mut show); + editor.borrow_mut().ask = true; + frames.frame(Vec::new(), &mut show); + let later = editor.borrow().reset; + assert!(later.is_some() && later != fence, "the editor asks for its own reset later"); + assert_eq!(frames.ime().and_then(|ime| ime.reset), later, "the pass publishes the editor's request"); + let Some(later) = later else { return }; + frames.frame( + vec![ + Event::Ime(ImeEvent::Commit("Q".to_owned())), + Event::ImeResetCompleted { request_id: later }, + Event::Ime(ImeEvent::Commit("X".to_owned())), + ], + &mut show, + ); + assert_eq!(editor.borrow().reset, None, "the completion of its later request reaches the editor"); + assert_eq!(editor.borrow().text, "abX", "the late commit is fenced and the commit after the completion reaches the editor"); + frames.frame(vec![Event::Ime(ImeEvent::Preedit { text: "y".to_owned(), active_range_chars: None })], &mut show); + assert!(editor.borrow().composing, "the editor composes again"); +} + +/// A framework text field of `id`, as a text component's part draws it: a text stop that takes the IME edits meant for +/// it and notes its caret. +fn framework_field(ui: &mut Ui, id: Id) { + let rect = widget(ui, id); + register_stop(ui.ctx(), Stop::new(id, KeyUse::of(Input::Text)).text()); + let _ = ime::take(ui.ctx(), id, false); + ime::note_caret(ui.ctx(), id, rect, rect, false); +} + +/// The framework field of `framework_field` and the app's resetting editor beside it at its rect, the show closure that +/// draws both, and the frames after the field took the focus and composed "k". +fn framework_field_composing_beside_an_app_editor() -> (Id, Rect, Rc>, impl FnMut(&mut Ui), Frames) { + let editor = Rc::new(RefCell::new(fixture::ResettingEditor::default())); + let held = Rc::clone(&editor); + let rect = Rect::from_min_size(Pos2::new(100.0, 100.0), egui::vec2(200.0, 30.0)); + let framework = named_id("framework field"); + let mut show = move |ui: &mut Ui| { + framework_field(ui, framework); + fixture::host_resetting_ime_editor(ui, host_editor_id(), rect, &mut held.borrow_mut()); + }; + let mut frames = Frames::new(); + frames.idle(2, &mut show); + request(&frames.ctx, FocusTarget::Id(framework)); + frames.frame(Vec::new(), &mut show); + frames.frame(vec![Event::Ime(ImeEvent::Preedit { text: "k".to_owned(), active_range_chars: None })], &mut show); + assert_eq!(frames.ime().map(|ime| ime.owner), Some(framework), "the framework field composes"); + (framework, rect, editor, show, frames) +} + +/// A press on the app's editor takes the focus from a composing framework field, and the editor asks for its own reset +/// in the pass the field loses the IME, as EffectCraft's editor does when its caret moves after the press. The interrupt +/// of the field's composition publishes the editor's request, so the platform's answer in the next frame reaches the +/// editor, the field's late commit stays fenced until then, and the commit after it reaches the editor. +#[trial] +fn an_app_editor_s_reset_asked_as_it_takes_the_focus_from_a_composing_framework_field_completes() { + let (framework, rect, editor, mut show, mut frames) = framework_field_composing_beside_an_app_editor(); + let at = rect.center(); + frames.frame(vec![moved(at), press(at)], &mut show); + assert!(!frames.ime().is_some_and(|ime| ime.interrupt), "the field keeps the IME through the press pass"); + editor.borrow_mut().ask = true; + frames.frame(vec![release(at)], &mut show); + let own = editor.borrow().reset; + assert!(own.is_some(), "the editor asked for its own reset"); + let ime = frames.ime().cloned(); + assert!(ime.as_ref().is_some_and(|ime| ime.owner == framework && ime.interrupt), "the pass interrupts the field's composition"); + assert_eq!(ime.and_then(|ime| ime.reset), own, "the interrupt publishes the editor's request, not a new one"); + let Some(own) = own else { return }; + frames.frame( + vec![ + Event::Ime(ImeEvent::Commit("Q".to_owned())), + Event::ImeResetCompleted { request_id: own }, + Event::Ime(ImeEvent::Commit("X".to_owned())), + ], + &mut show, + ); + assert_eq!(editor.borrow().reset, None, "the completion of its request reaches the editor"); + assert_eq!(editor.borrow().text, "X", "the field's late commit is fenced and the commit after the completion reaches the editor"); +} + +/// The app's editor asks for its own reset at the press that takes the focus from a composing framework field, while +/// the field still owns the IME. egui publishes that request on the field's output as an interrupt; the engine takes it +/// as its interrupt of the field and fences on it. The field loses the IME in the next pass with no second interrupt, +/// the platform's answer in that frame reaches the editor, the field's late commit stays fenced, and the editor takes +/// the commits after it. +#[trial] +fn an_app_editor_s_reset_asked_at_the_press_on_it_while_a_framework_field_composes_completes() { + let (framework, rect, editor, mut show, mut frames) = framework_field_composing_beside_an_app_editor(); + let at = rect.center(); + editor.borrow_mut().ask = true; + frames.frame(vec![moved(at), press(at)], &mut show); + let own = editor.borrow().reset; + assert!(own.is_some(), "the editor asked for its own reset at the press"); + let ime = frames.ime().cloned(); + assert!(ime.as_ref().is_some_and(|ime| ime.owner == framework && ime.interrupt), "the request interrupts the field's composition"); + assert_eq!(ime.and_then(|ime| ime.reset), own, "the field's output carries the editor's request"); + let Some(own) = own else { return }; + frames.frame(vec![release(at), Event::Ime(ImeEvent::Commit("Q".to_owned())), Event::ImeResetCompleted { request_id: own }], &mut show); + assert!(!frames.ime().is_some_and(|ime| ime.interrupt), "the field loses the IME without a second interrupt"); + assert_eq!(editor.borrow().reset, None, "the completion of its request reaches the editor"); + frames.frame(vec![Event::Ime(ImeEvent::Commit("X".to_owned()))], &mut show); + assert_eq!(editor.borrow().text, "X", "the field's late commit is fenced and the editor takes the commit after the completion"); +} + +#[trial] +fn a_focused_egui_field_keeps_escape_and_the_clipboard_and_tabs_on_through_the_one_order() { let (host, mut show) = host_window(); let mut frames = Frames::new(); frames.frame(Vec::new(), &mut show); @@ -184,15 +393,50 @@ fn a_focused_egui_field_keeps_tab_escape_and_the_clipboard() { frames.frame(vec![Event::Paste("x".to_owned())], &mut show); assert_eq!(host.borrow().text, "x", "the paste reaches the focused field"); press_key(&mut frames, &mut show, Key::Tab); - assert_eq!(seen(&host), (vec![Key::Tab], 0), "the field's Tab is egui's"); + assert_eq!(seen(&host), (Vec::new(), 0), "a single-line field's Tab is the framework's move, never egui's"); frames.frame(Vec::new(), &mut show); - assert_eq!(egui_focused(&frames.ctx), Some(named_id("button")), "egui's Tab moves focus on to the next widget"); + assert_eq!(egui_focused(&frames.ctx), Some(named_id("button")), "the field is the last stop: Tab wraps to the framework's button"); fixture::host_focus(&frames.ctx, field()); frames.frame(Vec::new(), &mut show); press_key(&mut frames, &mut show, Key::Escape); assert_eq!(seen(&host), (vec![Key::Escape], 0), "the field's Escape is egui's, and no window Cancel"); } +/// The Enter presses in egui's input and the window Submits taken after one Enter, with the host's field focused or +/// nothing focused. +fn enter_with(field_focused: bool) -> (usize, usize) { + let counts = Rc::new(Cell::new((0usize, 0usize))); + let counted = Rc::clone(&counts); + let (_host, mut base) = host_window(); + let mut show = move |ui: &mut Ui| { + let enters = ui.input(|input| input.events.iter().filter(|event| matches!(event, Event::Key { key: Key::Enter, pressed: true, .. })).count()); + let submit = with_window_intents(ui.ctx(), false, |intents| intents.take(Intent::Submit)); + let (seen, taken) = counted.get(); + counted.set((seen + enters, taken + usize::from(submit))); + base(ui); + }; + let mut frames = Frames::new(); + frames.frame(Vec::new(), &mut show); + if field_focused { + fixture::host_focus(&frames.ctx, field()); + frames.frame(Vec::new(), &mut show); + assert_eq!(egui_focused(&frames.ctx), Some(field()), "the host's field holds egui focus"); + } + counts.set((0, 0)); + press_key(&mut frames, &mut show, Key::Enter); + frames.idle(2, &mut show); + counts.get() +} + +/// An app's own focused widget keeps the plain Enter as it keeps Escape: it reads it from egui once, and no window +/// Submit comes of it, so an app that turns the window's Submit back into an Enter does not get two. With nothing +/// focused the plain Enter is the window's Submit and stays in egui's input too. +#[trial] +fn a_focused_egui_field_keeps_enter_and_the_window_gets_no_submit() { + assert_eq!(enter_with(true), (1, 0), "the field reads one Enter and the window takes no Submit"); + assert_eq!(enter_with(false), (1, 1), "with nothing focused, Enter is the window's Submit and stays in egui"); +} + #[trial] fn an_open_egui_popup_keeps_escape() { let popup = named_id("host popup"); @@ -233,8 +477,10 @@ fn escape_cancels_a_framework_drag_while_an_egui_field_has_focus() { frames.frame(vec![release(inside)], &mut show); } +/// The app's own buttons drawn after the window's framework button and host field: egui's arrows move focus among +/// them, and Tab and Shift+Tab move it through the window's one order, which holds them. #[trial] -fn arrows_and_tab_move_egui_focus_among_host_buttons() { +fn arrows_move_egui_focus_among_host_buttons_and_tab_moves_through_the_one_order() { let (left, right) = (named_id("host left"), named_id("host right")); let (_host, mut base) = host_window(); let mut show = move |ui: &mut Ui| { @@ -251,7 +497,7 @@ fn arrows_and_tab_move_egui_focus_among_host_buttons() { press_key(&mut frames, &mut show, Key::ArrowLeft); assert_eq!(egui_focused(&frames.ctx), Some(left), "ArrowLeft moves it back"); press_key(&mut frames, &mut show, Key::Tab); - assert_eq!(egui_focused(&frames.ctx), Some(right), "Tab moves egui focus on"); + assert_eq!(egui_focused(&frames.ctx), Some(right), "Tab moves focus on to the next stop"); frames.frame(vec![key_press(Key::Tab, Modifiers::SHIFT)], &mut show); frames.frame(Vec::new(), &mut show); assert_eq!(egui_focused(&frames.ctx), Some(left), "Shift+Tab moves it back"); @@ -264,6 +510,27 @@ fn arrows_and_tab_move_egui_focus_among_host_buttons() { assert_eq!(egui_focused(&frames.ctx), Some(named_id("button")), "egui's arrows leave a framework stop's focus alone"); } +/// Arrows from an entry of the app's own popup list stay in the list: the app's button under the list, a Tab stop as +/// every focusable widget of the app is, is no arrow target while the list covers it, though it lies nearer below the +/// first entry than the second entry does. +#[trial] +fn arrows_in_an_app_popup_list_skip_the_widget_it_covers() { + let (button, popup, first, second) = (named_id("host tool"), named_id("host popup"), named_id("host entry 1"), named_id("host entry 2")); + let mut show = move |ui: &mut Ui| { + fixture::host_button(ui, button, Rect::from_min_max(Pos2::new(228.0, 31.0), Pos2::new(254.0, 57.0))); + areas::host_popup_list(ui.ctx(), popup, Pos2::new(201.0, 18.0), &[first, second]); + }; + let mut frames = Frames::new(); + frames.idle(2, &mut show); + fixture::host_focus(&frames.ctx, first); + frames.idle(2, &mut show); + assert_eq!(egui_focused(&frames.ctx), Some(first)); + press_key(&mut frames, &mut show, Key::ArrowDown); + assert_eq!(egui_focused(&frames.ctx), Some(second), "ArrowDown goes to the list's next entry, not to the button under it"); + press_key(&mut frames, &mut show, Key::ArrowUp); + assert_eq!(egui_focused(&frames.ctx), Some(first), "ArrowUp comes back to the first entry"); +} + /// What the window shows before the app's own egui buttons. #[derive(Clone, Copy)] enum Before { @@ -316,15 +583,271 @@ fn tab_from_nothing(before: Before, shift: bool) -> (Option, bool) { (egui_focused(&frames.ctx), reached) } +/// Tab is the framework's move whatever the window holds: from nothing focused it reaches the app's own widgets as its +/// stops, and never egui's input. A component's widget that registered no stop is no stop of the app's own. #[trial] -fn tab_from_nothing_focused_in_a_window_without_stops_moves_egui_focus() { +fn tab_from_nothing_reaches_the_app_s_widgets_as_the_framework_s_move() { let (first, last) = (Some(named_id("host first")), Some(named_id("host last"))); - assert_eq!(tab_from_nothing(Before::Nothing, false), (first, true), "Tab gives egui focus to the first host button"); - assert_eq!(tab_from_nothing(Before::Nothing, true), (last, true), "Shift+Tab to the last"); - assert_eq!(tab_from_nothing(Before::Stop, false), (Some(named_id("button")), false), "with a framework stop, Tab is the framework's move"); - assert_eq!(tab_from_nothing(Before::Unstopped, false), (None, true), "egui's Tab gives no focus to a component's widget without a stop"); - let (focused, reached) = tab_from_nothing(Before::FocusedUnstopped, false); - assert!(focused.is_some() && focused != first && !reached, "egui focus on that widget is focus: the Tab is not egui's and moves nothing"); + assert_eq!(tab_from_nothing(Before::Nothing, false), (first, false), "Tab focuses the first host button"); + assert_eq!(tab_from_nothing(Before::Nothing, true), (last, false), "Shift+Tab the last"); + assert_eq!(tab_from_nothing(Before::Stop, false), (Some(named_id("button")), false), "the framework stop drawn first comes first"); + assert_eq!(tab_from_nothing(Before::Unstopped, false), (first, false), "a component's widget without a stop gets no focus"); + assert_eq!(tab_from_nothing(Before::FocusedUnstopped, false), (first, false), "from that widget holding focus, Tab goes to the first stop"); +} + +/// A window with a framework stop, two of the app's own buttons and the app's canvas, which keeps Tab, unfocused: Tab +/// from nothing is the framework's move over its one order, which holds the app's buttons beside the framework's +/// stop. The unfocused canvas does not keep the Tab; it is the last entry, and once Tab focuses it, it keeps Tab. +#[trial] +fn tab_from_nothing_goes_through_the_framework_order_with_the_app_s_widgets() { + let (stop, first, second, canvas) = (named_id("button"), named_id("host first"), named_id("host second"), named_id("host canvas")); + let reached = Rc::new(Cell::new(false)); + let seen_tab = Rc::clone(&reached); + let mut show = move |ui: &mut Ui| { + seen_tab.set(seen_tab.get() || key_reached(ui.ctx(), Key::Tab)); + widget(ui, stop); + register_stop(ui.ctx(), Stop::new(stop, KeyUse::of(Input::Pointer))); + for (id, x) in [(first, 300.0), (second, 420.0)] { + fixture::host_button(ui, id, Rect::from_min_size(Pos2::new(x, 300.0), egui::vec2(80.0, 30.0))); + } + widget(ui, canvas); + host_canvas(ui.ctx(), canvas, KeyUse::CANVAS.with_keep(KeepKeys::Tab)); + }; + let mut frames = Frames::new(); + frames.idle(2, &mut show); + let mut tab = |frames: &mut Frames| { + reached.set(false); + press_key(frames, &mut show, Key::Tab); + frames.frame(Vec::new(), &mut show); + (egui_focused(&frames.ctx), reached.get()) + }; + assert_eq!(tab(&mut frames), (Some(stop), false), "Tab from nothing goes to the first stop, not to the unfocused canvas"); + assert_eq!(tab(&mut frames), (Some(first), false), "then to the app's first button"); + assert_eq!(tab(&mut frames), (Some(second), false), "and its second, in the order the pass registered them"); + assert_eq!(tab(&mut frames), (Some(canvas), false), "then to the canvas"); + assert_eq!(tab(&mut frames), (Some(canvas), true), "the focused canvas keeps Tab and reads it from egui"); +} + +/// A window of the app's own canvas between two of the app's own buttons, with no framework stop: a bare Tab moves +/// focus through them in the order the pass drew them, from nothing focused and from the canvas alike, and never +/// reaches egui; a canvas that keeps Tab keeps it. +#[trial] +fn tab_moves_through_the_app_s_widgets_and_canvas_in_a_window_without_framework_stops() { + let (first, canvas, last) = (named_id("host first"), named_id("host canvas"), named_id("host last")); + let keeps = Rc::new(Cell::new(false)); + let reached = Rc::new(Cell::new(false)); + let (keep, seen) = (Rc::clone(&keeps), Rc::clone(&reached)); + let mut show = move |ui: &mut Ui| { + seen.set(seen.get() || key_reached(ui.ctx(), Key::Tab)); + fixture::host_button(ui, first, Rect::from_min_size(Pos2::new(100.0, 300.0), egui::vec2(80.0, 30.0))); + fixture::host_button(ui, canvas, Rect::from_min_size(Pos2::new(220.0, 300.0), egui::vec2(80.0, 30.0))); + host_canvas(ui.ctx(), canvas, if keep.get() { KeyUse::CANVAS.with_keep(KeepKeys::Tab) } else { KeyUse::CANVAS }); + fixture::host_button(ui, last, Rect::from_min_size(Pos2::new(340.0, 300.0), egui::vec2(80.0, 30.0))); + }; + let mut frames = Frames::new(); + frames.idle(2, &mut show); + let tab = |frames: &mut Frames, show: &mut dyn FnMut(&mut Ui)| { + reached.set(false); + frames.frame(vec![key_press(Key::Tab, Modifiers::NONE), key_release(Key::Tab, Modifiers::NONE)], &mut *show); + frames.frame(Vec::new(), &mut *show); + (egui_focused(&frames.ctx), reached.get()) + }; + assert_eq!(tab(&mut frames, &mut show), (Some(first), false), "Tab from nothing focuses the first widget drawn"); + assert_eq!(tab(&mut frames, &mut show), (Some(canvas), false), "the next Tab reaches the canvas"); + assert_eq!(tab(&mut frames, &mut show), (Some(last), false), "Tab from the canvas moves on"); + keeps.set(true); + request(&frames.ctx, FocusTarget::Id(canvas)); + frames.idle(2, &mut show); + assert_eq!(egui_focused(&frames.ctx), Some(canvas)); + assert_eq!(tab(&mut frames, &mut show), (Some(canvas), true), "a canvas that keeps Tab gets it from egui and keeps the focus"); +} + +/// The window the one-order trials show: the app's own button, a framework stop, the app's own single-line text field +/// inside a framework scope, a framework stop and the app's own button, in that order. +const MIXED: [&str; 5] = ["app first", "framework one", "app field", "framework two", "app last"]; + +fn mixed_window() -> impl FnMut(&mut Ui) { + let mut text = String::new(); + move |ui: &mut Ui| { + let [first, one, field, two, last] = MIXED.map(named_id); + fixture::host_button(ui, first, Rect::from_min_size(Pos2::new(20.0, 300.0), egui::vec2(80.0, 30.0))); + widget(ui, one); + register_stop(ui.ctx(), Stop::new(one, KeyUse::of(Input::Pointer))); + push_scope(ui.ctx(), named_id("group"), FocusPolicy::NONE, None); + fixture::host_field(ui, field, &mut text); + pop_scope(ui.ctx()); + widget(ui, two); + register_stop(ui.ctx(), Stop::new(two, KeyUse::of(Input::Pointer))); + fixture::host_button(ui, last, Rect::from_min_size(Pos2::new(420.0, 300.0), egui::vec2(80.0, 30.0))); + } +} + +/// A Tab press with `mods`, released in the same frame, and the frame after it: where egui focus is then. +fn tab_with(frames: &mut Frames, show: &mut impl FnMut(&mut Ui), mods: Modifiers) -> Option { + frames.frame(vec![key_press(Key::Tab, mods), key_release(Key::Tab, mods)], &mut *show); + frames.frame(Vec::new(), &mut *show); + egui_focused(&frames.ctx) +} + +/// Every focusable egui widget the app draws is a Tab stop of the window's one order, where the pass drew it among the +/// framework's stops, with no registration of its own: Tab from nothing visits the five in order and wraps, and +/// Shift+Tab walks back. +#[trial] +fn tab_reaches_the_app_s_egui_widgets_beside_the_framework_stops_in_registration_order() { + let mut show = mixed_window(); + let mut frames = Frames::new(); + frames.idle(2, &mut show); + let order = MIXED.map(|name| Some(named_id(name))); + let forward: Vec> = (0..6).map(|_| tab_with(&mut frames, &mut show, Modifiers::NONE)).collect(); + assert_eq!(forward, [&order[..], &order[..1]].concat(), "Tab visits the five in the order the pass drew them, then wraps"); + let back: Vec> = (0..5).map(|_| tab_with(&mut frames, &mut show, Modifiers::SHIFT)).collect(); + let reversed: Vec> = order.iter().rev().copied().collect(); + assert_eq!(back, reversed, "Shift+Tab walks back from the first, wrapping to the last"); +} + +/// F6 lands on the app's own widget in a pane whose only content it is. +#[trial] +fn f6_lands_on_an_app_widget_in_a_pane() { + let button = named_id("app pane button"); + let mut show = move |ui: &mut Ui| { + show_panes(ui); + push_scope(ui.ctx(), named_id("app pane"), FocusPolicy::PANE, Some(Arc::from("App"))); + fixture::host_button(ui, button, Rect::from_min_size(Pos2::new(420.0, 300.0), egui::vec2(80.0, 30.0))); + pop_scope(ui.ctx()); + }; + let mut frames = Frames::new(); + frames.idle(2, &mut show); + focus_stop(&mut frames, &mut show, named_id("right")); + let (focused, said) = pane_key(&mut frames, &mut show, Modifiers::NONE); + assert_eq!(focused, Some(button), "F6 from the right pane goes to the app's pane and its button"); + assert!(said.contains(&"App".to_owned()), "and announces the pane: {said:?}"); +} + +/// A focused multi-line text field of the app's own whose egui key filter keeps Tab (it locks focus) gets the Tab in +/// egui and types it; a single-line field of the app's own moves on to the next stop. +#[trial] +fn an_app_field_that_keeps_tab_types_it_and_a_single_line_field_tabs_on() { + let (code, line, after) = (named_id("app code"), named_id("app line"), named_id("framework after")); + let texts = Rc::new(RefCell::new((String::new(), String::new()))); + let shared = Rc::clone(&texts); + let mut show = move |ui: &mut Ui| { + let mut texts = shared.borrow_mut(); + let (code_text, line_text) = &mut *texts; + fixture::host_code_field(ui, code, code_text); + fixture::host_field(ui, line, line_text); + widget(ui, after); + register_stop(ui.ctx(), Stop::new(after, KeyUse::of(Input::Pointer))); + }; + let mut frames = Frames::new(); + frames.idle(2, &mut show); + fixture::host_focus(&frames.ctx, code); + frames.idle(2, &mut show); + assert_eq!(tab_with(&mut frames, &mut show, Modifiers::NONE), Some(code), "the field that keeps Tab keeps the focus"); + assert!(texts.borrow().0.contains('\t'), "and types the Tab: {:?}", texts.borrow().0); + fixture::host_focus(&frames.ctx, line); + frames.idle(2, &mut show); + assert_eq!(tab_with(&mut frames, &mut show, Modifiers::NONE), Some(after), "the single-line field's Tab moves on"); + assert_eq!(texts.borrow().1, "", "and types nothing"); +} + +/// Where Tab reaches only text fields (the Mac's default), it reaches the app's own text field and skips the app's +/// own buttons, as it skips the framework's. +#[trial] +fn tab_that_reaches_only_text_fields_reaches_the_app_s_field_and_skips_its_buttons() { + let mut show = mixed_window(); + let mut frames = Frames::new(); + crate::runtime::windows::set_os(&frames.ctx, craft_host::target::Os::Mac); + frames.root({ + let mut root = RootEnv::default(); + root.tab_all_controls = false; + root + }); + frames.idle(2, &mut show); + let field = Some(named_id("app field")); + assert_eq!(tab_with(&mut frames, &mut show, Modifiers::NONE), field, "Tab from nothing goes to the app's field"); + assert_eq!(tab_with(&mut frames, &mut show, Modifiers::NONE), field, "the field is the one entry: the next Tab stays on it"); +} + +/// While an app's own egui popup is open, Tab is egui's, as Escape is: the framework moves no focus with it. +#[trial] +fn an_open_app_popup_keeps_tab() { + let popup = named_id("host popup"); + let (host, mut base) = host_window(); + let mut show = move |ui: &mut Ui| { + base(ui); + areas::host_popup(ui, popup, Pos2::ZERO); + }; + let mut frames = Frames::new(); + frames.frame(Vec::new(), &mut show); + request(&frames.ctx, FocusTarget::Id(named_id("button"))); + frames.idle(2, &mut show); + areas::open_host_popup(&frames.ctx, popup); + frames.frame(Vec::new(), &mut show); + assert!(areas::host_popup_open(&frames.ctx, popup)); + seen(&host); + press_key(&mut frames, &mut show, Key::Tab); + assert_eq!(seen(&host).0, vec![Key::Tab], "the popup's Tab is egui's"); + frames.frame(Vec::new(), &mut show); + assert_eq!(egui_focused(&frames.ctx), Some(named_id("button")), "the framework moved no focus"); +} + +/// The scan that makes the app's egui widgets Tab stops classifies each focus candidate of a pass once, however many +/// registrations take candidates in between: the pass's lookups grow with its widgets, one per app widget. +#[trial] +fn each_focus_candidate_of_a_pass_is_classified_once() { + let lookups = |n: usize| { + let mut show = move |ui: &mut Ui| { + for at in 0..n { + fixture::host_button( + ui, + crate::runtime::egui::memory::unique(("app", at)), + Rect::from_min_size(Pos2::new(10.0, 30.0 * at as f32), egui::vec2(60.0, 20.0)), + ); + widget(ui, crate::runtime::egui::memory::unique(("framework", at))); + register_stop(ui.ctx(), Stop::new(crate::runtime::egui::memory::unique(("framework", at)), KeyUse::of(Input::Pointer))); + } + }; + let mut frames = Frames::new(); + frames.idle(2, &mut show); + crate::runtime::pointer::made_lookups(&frames.ctx, ViewportId::ROOT) as usize + }; + // The framework widget is the root of the stop registered after it, so only the app's widgets need a lookup. + let (small, large) = (lookups(8), lookups(16)); + assert!(small >= 8, "every app widget is looked up: {small}"); + assert_eq!(large - small, 8, "eight more app widgets cost one lookup each: {small} then {large}"); +} + +/// A Tab in a window with no stop and nothing focused moves no focus, so it stays in egui's input for the app's own +/// binding (EffectCraft's Tab for the timeline's mini flowchart), from the window's first pass on. Once the app draws a +/// focusable widget, that widget is a stop and the Tab is the framework's move to it. +#[trial] +fn an_unowned_tab_with_no_stops_reaches_the_app() { + let button = named_id("app button"); + let (reached, draw) = (Rc::new(Cell::new(0)), Rc::new(Cell::new(false))); + let mut show = { + let (reached, draw) = (Rc::clone(&reached), Rc::clone(&draw)); + move |ui: &mut Ui| { + if key_reached(ui.ctx(), Key::Tab) { + reached.set(reached.get() + 1); + } + if draw.get() { + fixture::host_button(ui, button, Rect::from_min_size(Pos2::new(40.0, 40.0), egui::vec2(80.0, 30.0))); + } + } + }; + let mut frames = Frames::new(); + press_key(&mut frames, &mut show, Key::Tab); + assert_eq!(reached.take(), 1, "the window's first pass has no stop: its Tab is the app's"); + frames.idle(2, &mut show); + frames.frame(vec![key_press(Key::Tab, Modifiers::SHIFT), key_release(Key::Tab, Modifiers::SHIFT)], &mut show); + assert_eq!(reached.take(), 1, "with nothing drawn, Shift+Tab is the app's too"); + assert_eq!(egui_focused(&frames.ctx), None); + draw.set(true); + frames.idle(2, &mut show); + press_key(&mut frames, &mut show, Key::Tab); + frames.frame(Vec::new(), &mut show); + assert_eq!(reached.take(), 0, "the app's button is a stop: the Tab is the framework's move"); + assert_eq!(egui_focused(&frames.ctx), Some(button), "and the Tab moved focus to the button"); } #[trial] @@ -470,8 +993,8 @@ fn a_host_canvas_marks_the_window_and_tab_toggles_its_panels() { ); assert_eq!( tab_with_canvas(Some(KeyUse::CANVAS.with_keep(KeepKeys::Tab)), false), - (Vec::new(), true), - "with nothing focused, a canvas that keeps Tab gets it from egui and nothing toggles" + (vec![(ViewportId::ROOT, ChromeToggle::Panels)], false), + "a canvas keeps Tab only while focused: with nothing focused, Tab toggles the panels" ); } diff --git a/crates/ui-contract/src/testing/replay_trials.rs b/crates/ui-contract/src/testing/replay_trials.rs index 30981b5812..2f3e2741c9 100644 --- a/crates/ui-contract/src/testing/replay_trials.rs +++ b/crates/ui-contract/src/testing/replay_trials.rs @@ -125,6 +125,34 @@ fn replayed_focus_stops_keep_their_own_target() { }); } +// The app's own egui widgets drawn inside a recorded view are stops of its transcript, and none drawn before it; the +// replay registers each once, where the view shows, after the widgets drawn before it. +#[trial] +fn a_recorded_view_holds_the_app_s_widgets_drawn_in_it_and_its_replay_registers_them_once() { + let mut frames = Frames::new(); + let [before, inside] = [fixture::named_id("app before"), fixture::named_id("app inside")]; + let rect = |x: f32| Rect::from_min_size(Pos2::new(x, 100.0), Vec2::new(80.0, 30.0)); + let mut recorded = None; + frames.frame(Vec::new(), |ui| { + let ctx = ui.ctx().clone(); + fixture::host_button(ui, before, rect(20.0)); + replay::open(&ctx); + fixture::host_button(ui, inside, rect(120.0)); + recorded = Some(replay::close(&ctx, fixture::layer_of(ui))); + }); + let recorded = recorded.expect("the frame ran"); + assert_eq!(recorded.focus.stop_ids().collect::>(), [inside], "the transcript holds the widget drawn in the view alone"); + let mut order = Vec::new(); + frames.frame(Vec::new(), |ui| { + let ctx = ui.ctx(); + fixture::host_button(ui, before, rect(20.0)); + focus::replay(ctx, &recorded.focus); + focus::stop_count(ctx); + order = focus::tab_order(ctx, |_| true).into_iter().map(|(id, _)| id).collect(); + }); + assert_eq!(order, [before, inside], "the replay registers the view's widget once, after the one drawn before it"); +} + /// Records `stops` run inside a record, with `entering` the first-pass flag of the layer scope it pushes, inside the /// scope `outer` when one is given. fn layer_scope_record(frames: &mut Frames, outer: Option, entering: bool) -> replay::Record { diff --git a/crates/ui-contract/src/testing/suite.rs b/crates/ui-contract/src/testing/suite.rs index 037d70f809..9e98515818 100644 --- a/crates/ui-contract/src/testing/suite.rs +++ b/crates/ui-contract/src/testing/suite.rs @@ -127,6 +127,7 @@ const SHAPES: &[Case] = &[ Case::new("items-click-select", ANY, collection::click_selects_one_row), Case::new("items-type-ahead", ANY, collection::type_ahead_moves_the_lead), Case::new("items-rename", ANY, collection::rename_commits_and_cancels_once), + Case::new("items-rename-blur", ANY, collection::rename_ends_when_the_editor_loses_focus), Case::new("items-reorder", ANY, collection::keyboard_reorder_ends_once), Case::new("items-empty", ANY, collection::empty_collection_shows_no_rows), Case::new("items-virtualisation", ANY, collection::long_collection_builds_rows_within_the_room_only), @@ -173,6 +174,8 @@ fn panic_text(payload: Box) -> String { /// The cases of `group` over the stories of the type `probe` describes, and with `check_exemptions` the check that /// each exemption names a known case. `home`: the stories are the package's that registers the type ([`Subject::home`]). fn run_group(probe: Probe, group: &'static Group, check_exemptions: bool, home: bool, stories: Vec) -> Result<(), Failed> { + // The cases that read the type as a whole look at one story of each kind at the gate; the others keep every story. + let stories = if matches!(group.name, "reads" | "variants" | "containers") { nodes::sampled_stories(stories) } else { stories }; let subject = Subject::new(&probe, stories, home); let mut failures = Vec::new(); if check_exemptions && home { diff --git a/crates/ui-contract/src/testing/suite/activation.rs b/crates/ui-contract/src/testing/suite/activation.rs index 719ca9754f..dd74cfdea8 100644 --- a/crates/ui-contract/src/testing/suite/activation.rs +++ b/crates/ui-contract/src/testing/suite/activation.rs @@ -25,6 +25,13 @@ pub(super) const CASES: &[Case] = &[ Case::new("press-removal", ANY, removal_cancels_a_press), ]; +/// Whether a click path left the component as it found it: no node state changed and no layer opened. The paths of one +/// part share a fixture while this holds; a path that moved something starts the next in a fresh fixture, so +/// a path never sees another's effect. +fn left_as_found(fixture: &Fixture, before: &HashMap, layers: usize) -> bool { + signature(fixture.tree()) == *before && crate::runtime::overlay::open_entries(fixture.ctx()).len() == layers +} + /// Enter, Space, AccessKit `Click` and a primary click each give exactly one click on a component that reports /// clicks and carries no value (value types are checked by the values case). fn each_activation_clicks_once(subject: &Subject) -> Result<(), String> { @@ -37,14 +44,20 @@ fn each_activation_clicks_once(subject: &Subject) -> Result<(), String> { if !matches!(plan, Plan::Activate) || !fixture.tree().declares_key(root.node, Declared::Click) { continue; } + // The variants share one fixture while each leaves the component as it found it ([`left_as_found`]). + let mut shared: Option = None; for variant in variants(plan, subject.probe) { - let mut fixture = input_fixture(story); + let mut fixture = shared.take().unwrap_or_else(|| input_fixture(story)); + let (before, layers) = (signature(fixture.tree()), crate::runtime::overlay::open_entries(fixture.ctx()).len()); fixture.take_outputs(); run(&mut fixture, plan, variant); let clicks = fixture.take_outputs().iter().filter(|output| output.activated()).count(); if clicks != 1 { return Err(format!("{}: {} gave {clicks} clicks", story.name, variant_name(plan, variant))); } + if left_as_found(&fixture, &before, layers) { + shared = Some(fixture); + } } } Ok(()) @@ -82,12 +95,15 @@ fn each_part_activates_once(subject: &Subject) -> Result<(), String> { (2, "Enter", keys[0].1 && declares(Declared::Focus)), (3, "Space", keys[1].1 && declares(Declared::Focus)), ]; + // The paths of a part share one fixture while each leaves the component as it found it ([`left_as_found`]). + let mut shared: Option = None; for (path, name, _) in paths.into_iter().filter(|(_, _, has)| *has) { - let mut fixture = input_fixture(story); + let mut fixture = shared.take().unwrap_or_else(|| input_fixture(story)); let Some(target) = fixture.root_id().and_then(|id| fixture.part(id, part)) else { continue }; if fixture.tree().data_of(target.node).is_some_and(|node| node.is_disabled()) { continue; } + let (before, layers) = (signature(fixture.tree()), crate::runtime::overlay::open_entries(fixture.ctx()).len()); fixture.take_outputs(); match path { 0 => { @@ -107,6 +123,9 @@ fn each_part_activates_once(subject: &Subject) -> Result<(), String> { if clicks != 1 { return Err(format!("{}: {name} on the part {part:?} gave {clicks} clicks", story.name)); } + if left_as_found(&fixture, &before, layers) { + shared = Some(fixture); + } } } } diff --git a/crates/ui-contract/src/testing/suite/collection.rs b/crates/ui-contract/src/testing/suite/collection.rs index 275f31cd93..e2c43420d4 100644 --- a/crates/ui-contract/src/testing/suite/collection.rs +++ b/crates/ui-contract/src/testing/suite/collection.rs @@ -251,6 +251,37 @@ pub(super) fn rename_commits_and_cancels_once(subject: &Subject) -> Result<(), S Ok(()) } +/// F2 on the first row of a collection that renames, nothing typed, then a click on the second row: the editor lost the +/// focus to the rows, so the rename ends once with a blur cancel and no commit, and the editor closes (a typed name commits +/// by the same loss; an unedited one gave the text field no event to end the rename by). +pub(super) fn rename_ends_when_the_editor_loses_focus(subject: &Subject) -> Result<(), String> { + if !is_items(subject) { + return Ok(()); + } + let rename = |kinds: &[CollectionKind], edit: EditKind| kinds.iter().filter(|kind| **kind == CollectionKind::Rename(edit)).count(); + for story in &subject.stories { + let Some((mut fixture, _, shown)) = with_rows(story, 2) else { continue }; + row_click::click(&mut fixture, &shown[0]); + fixture.take_outputs(); + fixture.key(Key::F2, Modifiers::NONE); + fixture.settle(); + if rename(&events(&mut fixture), EditKind::Begin) == 0 { + continue; + } + row_click::click(&mut fixture, &shown[1]); + fixture.settle(); + let ended = events(&mut fixture); + let name = story.name; + if rename(&ended, EditKind::Cancel) != 1 || rename(&ended, EditKind::Commit) != 0 { + return Err(format!("{name}: a click on another row gave {ended:?}, expected one rename cancel")); + } + if fixture.tree().role_of(fixture.tree().focused_key()) == Some(Role::TEXT_INPUT) { + return Err(format!("{name}: the rename ended and the editor still holds the focus")); + } + } + Ok(()) +} + /// A stacking key on the first row, for a reorderable collection: one end event and no cancel. Cmd+[ moves the row /// toward the back, the end of a vertical order; a horizontal order (a strip) moves it later with Cmd+]. pub(super) fn keyboard_reorder_ends_once(subject: &Subject) -> Result<(), String> { diff --git a/crates/ui-contract/src/testing/suite/nodes.rs b/crates/ui-contract/src/testing/suite/nodes.rs index 20cf49b1eb..81321a4d18 100644 --- a/crates/ui-contract/src/testing/suite/nodes.rs +++ b/crates/ui-contract/src/testing/suite/nodes.rs @@ -3,6 +3,7 @@ use crate::runtime::access::Role; use crate::runtime::egui::access::{AccessTree, Declared, NodeKey}; use crate::testing::fixture::{Fixture, Target}; +use crate::testing::story::Story; use craft_behavior::PartRef; /// `node` and every node below it. @@ -160,3 +161,21 @@ pub(super) fn sampled_actions(tree: &AccessTree, mut pairs: Vec<(NodeKey, Declar } sets.iter().flat_map(|set| sample(set)).collect() } + +/// `stories` cut, when [`samples_repeats`], to the first story of each distinct kind: stories that cover the same +/// required states, drive the same way, give the same disabled reason and set command states alike differ only in +/// what they show, which the cases that read the type as a whole (`reads`, `variants`, `containers`) see through +/// the first of them. The nightly run keeps every story. +pub(super) fn sampled_stories(stories: Vec) -> Vec { + if !samples_repeats() { + return stories; + } + let kind = |story: &Story| (story.covers, std::mem::discriminant(&story.drive), story.disabled_text, story.commands.is_some()); + let mut kept: Vec = Vec::new(); + for story in stories { + if !kept.iter().any(|known| kind(known) == kind(&story)) { + kept.push(story); + } + } + kept +} diff --git a/crates/ui-contract/src/testing/suite/size.rs b/crates/ui-contract/src/testing/suite/size.rs index a17c1c4baf..e13d818b5c 100644 --- a/crates/ui-contract/src/testing/suite/size.rs +++ b/crates/ui-contract/src/testing/suite/size.rs @@ -101,32 +101,28 @@ pub fn text_size_case(story: &Story) -> Result<(), String> { /// The text-size case for `story`, whose settled default shot is `base`. fn text_size_from(story: &Story, base: Shot) -> Result<(), String> { - let variants: [(&str, Shot); 4] = [ - ( - "text size", + // The shot at the default density is the base shot, so a density is shot only when it is not the default. + let densities = [("compact density", Size::Compact), ("comfortable density", Size::Comfortable)]; + let mut variants: Vec<(&str, Shot)> = vec![( + "text size", + shot(story, &|f| { + f.text_size(TextSize::Large); + }), + )]; + for (name, density) in densities.into_iter().filter(|(_, density)| *density != Size::default()) { + variants.push(( + name, shot(story, &|f| { - f.text_size(TextSize::Large); + f.density(density); }), - ), - ( - "compact density", - shot(story, &|f| { - f.density(Size::Compact); - }), - ), - ( - "comfortable density", - shot(story, &|f| { - f.density(Size::Comfortable); - }), - ), - ( - "scale 2", - shot(story, &|f| { - f.scale(Scale(2.0)); - }), - ), - ]; + )); + } + variants.push(( + "scale 2", + shot(story, &|f| { + f.scale(Scale(2.0)); + }), + )); let (before, after) = (base.shown.size(), |shot: &Shot| shot.shown.size()); for (name, grown) in &variants { let size = after(grown); diff --git a/crates/ui-contract/src/testing/suite/variants.rs b/crates/ui-contract/src/testing/suite/variants.rs index dabbeabae3..08dc605d90 100644 --- a/crates/ui-contract/src/testing/suite/variants.rs +++ b/crates/ui-contract/src/testing/suite/variants.rs @@ -36,12 +36,15 @@ fn acted(fixture: &mut Fixture, before: &crate::testing::story::StorySnapshot) - fn disabled_changes_nothing(subject: &Subject) -> Result<(), String> { for story in &subject.stories { let plan = subject.base(story).plan; + // One fixture takes every drive: a disabled story that acts on one is an error at once, so a drive that + // passes leaves it as it was for the next. + let mut driven = for_input(Fixture::story_scoped(story, |scope| scope.enabled = Some(false))); for variant in variants(plan, subject.probe).into_iter().filter(|variant| !cancels(plan, *variant)) { - let mut fixture = for_input(Fixture::story_scoped(story, |scope| scope.enabled = Some(false))); + let fixture = &mut driven; let before = fixture.data().snapshot(); fixture.take_outputs(); - run(&mut fixture, plan, variant); - if acted(&mut fixture, &before) { + run(fixture, plan, variant); + if acted(fixture, &before) { return Err(format!("{}: a disabled story acted on drive {variant}", story.name)); } } @@ -87,12 +90,15 @@ fn read_only_changes_nothing(subject: &Subject) -> Result<(), String> { } for story in &subject.stories { let plan = subject.base(story).plan; + // One fixture takes every drive: a read-only story that acts on one is an error at once, so a drive that + // passes leaves it as it was for the next. + let mut driven = for_input(Fixture::story_scoped(story, |scope| scope.read_only = Some(true))); for variant in variants(plan, subject.probe).into_iter().filter(|variant| !cancels(plan, *variant)) { - let mut fixture = for_input(Fixture::story_scoped(story, |scope| scope.read_only = Some(true))); + let fixture = &mut driven; let before = fixture.data().snapshot(); fixture.take_outputs(); - run(&mut fixture, plan, variant); - if acted(&mut fixture, &before) { + run(fixture, plan, variant); + if acted(fixture, &before) { return Err(format!("{}: a read-only story acted on drive {variant}", story.name)); } } diff --git a/crates/ui-contract/tests/it/collection/rows.rs b/crates/ui-contract/tests/it/collection/rows.rs index 205c1f26a9..46b82811dc 100644 --- a/crates/ui-contract/tests/it/collection/rows.rs +++ b/crates/ui-contract/tests/it/collection/rows.rs @@ -3,7 +3,7 @@ use super::kit::{Count, Dismissed, List, ROW_H, RowOut, Words}; use craft_behavior::{ - CellAt, CellRange, CellSelection, ColumnKey, EditEvent, EditEvents, GestureId, ItemSource, Mixed, PartKey, ScrollPos, Selection, + CancelReason, CellAt, CellRange, CellSelection, ColumnKey, EditEvent, EditEvents, GestureId, ItemSource, Mixed, PartKey, ScrollPos, Selection, SelectionModel as _, Sense, SheetLayout, SpanLayout, keyed, }; use craft_keymap::Mods; @@ -258,6 +258,9 @@ impl Collection for Probe<'_> { None => (enter.get(), Mods::NONE), }; let mut editor = EditResponse::lifted(ui.allocate_rect(label, egui::Sense::hover()), events, None); + // The probe field is no focus stop, so it asks for the focus a real text field keeps: a field that holds the focus + // and then loses it ends the rename. + request(ui.ctx(), FocusTarget::Id(editor.response.id)); editor.submitted = submitted; editor.submit_mods = mods; Some(editor) @@ -741,3 +744,41 @@ fn a_rename_request_runs_the_settled_view_of_its_collection() { let begun = log.events.borrow().iter().any(|event| matches!(event, CollectionEvent::Rename(EditEvent::Begin { .. }))); assert!(begun, "the settled view ran and its collection opened the requested rename"); } + +/// A rename whose item leaves the source (here, the source shrinks past it) ends once with a removed cancel and writes +/// nothing: the draft is not committed, and the rename does not open again with the old draft. +#[trial] +fn a_rename_whose_item_leaves_the_source_ends_with_a_removed_cancel() { + let (log, enter, shrunk) = (Log::new(), Cell::new(false), Cell::new(false)); + let mut frames = Frames::new(); + let mut show = |ui: &mut Ui| { + let words = if shrunk.get() { Words::flat(&["a"]) } else { Words::flat(&["a", "b", "c"]) }; + in_region(ui, Rect::from_min_size(ORIGIN, VIEW), |ui| { + let list = Probe::new(SelectMode::Single).id_salt("list").renaming("proposed", &enter); + log.take(list.show_items(ui, &words, &mut |key, _| ProbeRow::new(*key, log))); + }); + }; + frames.idle(3, &mut show); + request_rename(&frames.ctx, log.id(), &1_usize); + frames.idle(3, &mut show); + let ends = |log: &Log| -> Vec<&'static str> { + log.events + .borrow() + .iter() + .filter_map(|event| match event { + CollectionEvent::Rename(EditEvent::Begin { .. }) => Some("begin"), + CollectionEvent::Rename(EditEvent::Commit { .. }) => Some("commit"), + CollectionEvent::Rename(EditEvent::Cancel { reason: CancelReason::Removed, .. }) => Some("removed"), + CollectionEvent::Rename(EditEvent::Cancel { .. }) => Some("cancel"), + _ => None, + }) + .collect() + }; + assert_eq!(ends(log), ["begin"], "the rename is open"); + shrunk.set(true); + frames.idle(3, &mut show); + assert_eq!(ends(log), ["begin", "removed"], "the rename ended once, with a removed cancel and no commit"); + enter.set(true); + frames.idle(3, &mut show); + assert_eq!(ends(log), ["begin", "removed"], "nothing more is written after the item left"); +} diff --git a/crates/ui-contract/tests/it/layout/memory.rs b/crates/ui-contract/tests/it/layout/memory.rs index 16a7a5e041..e8bcb82888 100644 --- a/crates/ui-contract/tests/it/layout/memory.rs +++ b/crates/ui-contract/tests/it/layout/memory.rs @@ -4,6 +4,7 @@ use super::fill::{Held, scrolled_fixture}; use craft_behavior::ColumnWidth; use craft_ui::contract::{ContainerProps, Props as _, Show as _, ShowContainer as _, Sizing}; use craft_ui::layout::BodyLayout; +use craft_ui::runtime::frame; use craft_ui::testing::layout::{Block, body, measured_block}; use craft_ui::testing::{Frames, last_pass_measuring_runs, pointer, trial}; use craft_ui_test_kit::body::Slab; @@ -99,3 +100,25 @@ fn a_container_sharing_a_scrolled_view_runs_its_body_at_most_the_draft_more_than assert!(wheel <= plain_wheel + 1, "a wheel frame runs the body at most the draft more: {case}"); } } + +/// A block whose size asks for the frame's discard pass shows in `frame::will_rerun` for the rest of the pass, a host +/// after it included, while egui's `will_discard` stays false until the end hook requests the discard. +#[trial] +fn a_discard_asked_by_a_block_shows_in_will_rerun_in_the_same_pass() { + let mut frames = Frames::new(); + let seen = std::cell::RefCell::new(Vec::new()); + let mut run = |width: f32| { + seen.borrow_mut().clear(); + let passes = frames.frame(vec![], |ui| { + measured_block(ui, "readout", Vec2::new(width, 20.0)); + seen.borrow_mut().push((frame::will_rerun(ui.ctx()), ui.ctx().will_discard())); + }); + (passes, seen.borrow().clone()) + }; + assert_eq!(run(20.0), (2, vec![(true, false), (false, false)]), "the first appearance asks, and the host after it reads the rerun"); + for _ in 0..3 { + run(20.0); + } + assert_eq!(run(20.0), (1, vec![(false, false)]), "a settled block asks nothing"); + assert_eq!(run(300.0), (2, vec![(true, false), (false, false)]), "a change after a settled frame asks in its first pass"); +} diff --git a/crates/ui-contract/tests/it/text/editor.rs b/crates/ui-contract/tests/it/text/editor.rs index c3246338f9..fed1efee1c 100644 --- a/crates/ui-contract/tests/it/text/editor.rs +++ b/crates/ui-contract/tests/it/text/editor.rs @@ -1029,3 +1029,46 @@ fn an_alt_chord_bound_only_out_of_scope_leaves_its_text_typed() { let fired: Vec = take_output(&frames.ctx).fired.into_iter().map(|fired| fired.command.id).collect(); assert!(fired.is_empty(), "nothing ran: {fired:?}"); } + +/// A disabled editor registers no stop, and its focus widget is still the component's own and no egui focus candidate: +/// it never becomes a Tab stop of the app's own widgets, and egui's arrows from the app's own focused widget never +/// reach it. With every control in Tab order, Tab and Shift+Tab land on the button beside it each time. +#[trial] +fn tab_never_focuses_a_disabled_editor_s_widget() { + let log = RefCell::new(Vec::new()); + let seen = RefCell::new(Seen::default()); + let (editor, button) = (Cell::new(Id::NULL), Cell::new(Id::NULL)); + // The app's own egui button, level with the editor on its right: the editor lies straight to its left. + let app = craft_ui::testing::focus::named_id("app button"); + let app_at = Rect::from_min_size(Pos2::new(AT.right() + 40.0, AT.center().y - 10.0), egui::vec2(60.0, 20.0)); + let mut show = |ui: &mut egui::Ui| { + editor.set(Probe::new(&log, true).label("Source").enabled(false).id_salt("code").show_at(ui, AT).id); + button.set(Button::new(&seen).id_salt("next").show_at(ui, NEXT).id); + ui.interact(app_at, app, egui::Sense::click()); + }; + let mut frames = Frames::new(); + frames.root({ + let mut root = craft_ui::runtime::env::RootEnv::default(); + root.tab_all_controls = true; + root + }); + frames.idle(3, &mut show); + for shift in [false, false, true, true] { + let mods = if shift { Modifiers::SHIFT } else { Modifiers::NONE }; + frames.frame(vec![key_press(Key::Tab, mods), key_release(Key::Tab, mods)], &mut show); + frames.frame(Vec::new(), &mut show); + let focused = craft_ui::testing::focus::egui_focused(&frames.ctx); + assert!( + focused == Some(button.get()) || focused == Some(app), + "Tab (shift {shift}) lands on a control, never on the disabled editor {:?}: {focused:?}", + editor.get() + ); + } + craft_ui::runtime::focus::request(&frames.ctx, craft_ui::runtime::focus::FocusTarget::Id(app)); + frames.idle(2, &mut show); + assert_eq!(craft_ui::testing::focus::egui_focused(&frames.ctx), Some(app), "the app's button has the focus"); + frames.frame(vec![key_press(Key::ArrowLeft, Modifiers::NONE), key_release(Key::ArrowLeft, Modifiers::NONE)], &mut show); + frames.frame(Vec::new(), &mut show); + let focused = craft_ui::testing::focus::egui_focused(&frames.ctx); + assert!(focused == Some(app) || focused == Some(button.get()), "the arrow never reaches the disabled editor {:?}: {focused:?}", editor.get()); +} diff --git a/crates/ui-contract/tests/it/text/mod.rs b/crates/ui-contract/tests/it/text/mod.rs index c121edcb90..67ebf9abe0 100644 --- a/crates/ui-contract/tests/it/text/mod.rs +++ b/crates/ui-contract/tests/it/text/mod.rs @@ -2,3 +2,4 @@ pub(crate) mod band; pub(crate) mod editor; pub(crate) mod input_cap; pub(crate) mod memo; +pub(crate) mod resting; diff --git a/crates/ui-contract/tests/it/text/resting.rs b/crates/ui-contract/tests/it/text/resting.rs new file mode 100644 index 0000000000..ad2973ce60 --- /dev/null +++ b/crates/ui-contract/tests/it/text/resting.rs @@ -0,0 +1,78 @@ +//! A text part's resting text is drawn while the part is idle; an edit made to an idle part (the host replacing its +//! selection) is made to the value's own text. + +use craft_behavior::{PartKey, PlainText, Sense}; +use craft_ui::contract::{Bind, BindMut, Common, Component, Edit as _, EditResponse, Input, MeasureCx, PartsCx, Role, Show as _}; +use craft_ui::primitives::{TextKey, TextOptions}; +use craft_ui::style::StyleCx; +use craft_ui::testing::{Fixture, trial}; +use craft_ui_test_kit::contract::PlainStyle; +use egui::{Id, Rect, Vec2}; +use std::cell::{Cell, RefCell}; +use std::rc::Rc; + +const TEXT: PartKey = PartKey::new("text"); + +/// One text part over a string: it shows `resting` while idle, and `insert` replaces its selection in the pass it is set. +#[derive(craft_ui::contract::Component)] +struct Resting<'a> { + #[common] + common: Common, + value: Bind<'a, String>, + resting: &'static str, + insert: Option<&'static str>, +} + +impl Component for Resting<'_> { + const ROLE: Role = Role::TEXT_INPUT; + const INPUT: Input = Input::Text; + type Style = PlainStyle; + type Output = EditResponse; + + fn style(_: &StyleCx<'_>, _: RestingStyleKey) -> PlainStyle { + PlainStyle::default() + } + + fn sense(&self) -> Sense { + Sense::CLICK | Sense::FOCUS | Sense::TAKE_FOCUS + } + + fn measure(&mut self, _: &MeasureCx<'_, Self>) -> Vec2 { + Vec2::new(120.0, 24.0) + } + + fn parts(&mut self, _: Rect, cx: &mut PartsCx<'_, Self>) { + let options = + TextOptions { resting: Some(self.resting.to_owned()), replace_selection: self.insert.map(str::to_owned), ..TextOptions::default() }; + let (shown, rect) = (cx.value().cloned().unwrap_or_default(), cx.content_rect); + cx.text(TextKey::::new(TEXT), rect, &PlainText, &shown, &options); + } + + fn bind(&mut self) -> Option> { + Some(self.value.reborrow()) + } + + fn finish(self, cx: craft_ui::contract::Cx<'_, Self>) -> EditResponse { + cx.edit_response() + } +} + +/// The host replaces the selection of an idle part that shows resting text: the insert goes into the value's own text +/// ("42" and "7" make "427"), not into the resting text drawn in its place ("(42)7"). +#[trial] +fn an_edit_to_an_idle_part_is_made_to_the_value_not_to_its_resting_text() { + let value = Rc::new(RefCell::new(String::from("42"))); + let insert = Rc::new(Cell::new(None)); + let id = Rc::new(Cell::new(Id::NULL)); + let (held, once, seen) = (value.clone(), insert.clone(), id.clone()); + let mut fixture = Fixture::new(move |ui| { + let mut text = held.borrow_mut(); + let out = Resting { common: Common::new(), value: Bind::bound(&mut *text), resting: "(42)", insert: once.take() }.show(ui); + seen.set(out.response.id); + }); + fixture.settle(); + assert_eq!(fixture.tree().value(id.get()), Some("(42)"), "an idle part shows its resting text"); + insert.set(Some("7")); + fixture.settle(); + assert_eq!(*value.borrow(), "427", "the insert went into the value's own text"); +} diff --git a/crates/ui-panels/src/docking/config.rs b/crates/ui-panels/src/docking/config.rs index d3b885867a..be2d0180e6 100644 --- a/crates/ui-panels/src/docking/config.rs +++ b/crates/ui-panels/src/docking/config.rs @@ -67,7 +67,8 @@ pub struct DockConfig { /// the drag; only Ctrl/Cmd held at the release or a release outside the window floats. pub float_on_empty_drop: bool, /// Dragging a floating window's title bar onto a drop target docks the whole window there. Off: the title bar - /// only moves the window; tabs and drag bars dock. + /// only moves the window; tabs and drag bars dock, and so does a window that took over a panel's drag + /// (`DockArea::continue_move`). pub title_bar_docks: bool, /// Shows the built-in Close items in tab and group menus for closable panels. A host that draws its own Close /// items turns this off. diff --git a/crates/ui-panels/src/docking/drop.rs b/crates/ui-panels/src/docking/drop.rs index 8aa8668a3b..3effbacf58 100644 --- a/crates/ui-panels/src/docking/drop.rs +++ b/crates/ui-panels/src/docking/drop.rs @@ -59,6 +59,10 @@ pub trait DockDrag

{ fn press(&self) -> Option { None } + /// The drag is a floating window's move by its title row ([`GroupDrag::title_row`]). + fn title_row(&self) -> bool { + false + } } impl DockDrag

for PanelDrag { @@ -87,6 +91,10 @@ impl DockDrag

for GroupDrag

{ fn press(&self) -> Option { self.press } + + fn title_row(&self) -> bool { + self.title_row + } } /// What a drop does and what the ghost paints for it. @@ -341,7 +349,7 @@ impl DockDropTarget<'_, P> { if pointer::mods(self.ctx).cmd { return if window { None } else { self.float(&unit, at, drag.source(), drag.strip(), drag.press()) }; } - if window && !self.title_bar_docks { + if window && drag.title_row() && !self.title_bar_docks { return None; } if let Some((spot, applies)) = DockTargets::

::resolve(self.ctx, self.dock, at) { @@ -487,7 +495,19 @@ where { let preview = name.map_or(DragPreview::None, DragPreview::Named); let started = started(&cx.env); - cx.start_drag(GroupDrag { unit, active, source, strip: None, press: None, started }, preview); + cx.start_drag(GroupDrag { unit, active, source, strip: None, press: None, started, title_row: false }, preview); +} + +/// Starts the drag of the floating window that holds `anchor`, whose shown panel is `active`, at its `size`: a move by +/// its title row when `title_row`, else a panel drag the window took over ([`GroupDrag::title_row`]). +pub(crate) fn start_window_drag(cx: &mut Cx<'_, C>, anchor: P, active: PanelKey, size: Vec2, title_row: bool) +where + P: Clone + Send + Sync + 'static, + C: Component, +{ + let started = started(&cx.env); + let drag = GroupDrag { unit: DragUnit::Window(anchor), active, source: Some(size), strip: None, press: None, started, title_row }; + cx.start_drag(drag, DragPreview::None); } /// Starts the drag of `unit` out of a collapsed column, from its icons of size `strip`, whose shown panel is @@ -499,7 +519,7 @@ where C: Component, { let started = started(&cx.env); - cx.start_drag(GroupDrag { unit, active, source: None, strip: Some(strip), press: None, started }, DragPreview::Named(label)); + cx.start_drag(GroupDrag { unit, active, source: None, strip: Some(strip), press: None, started, title_row: false }, DragPreview::Named(label)); } /// Ends a running tab or group drag that started on `shown`'s dock under another generation: another arrangement diff --git a/crates/ui-panels/src/docking/event.rs b/crates/ui-panels/src/docking/event.rs index d0adf59762..485280ab43 100644 --- a/crates/ui-panels/src/docking/event.rs +++ b/crates/ui-panels/src/docking/event.rs @@ -32,6 +32,22 @@ pub enum DockEvent

{ /// The command. command: DockCommands, }, + /// The tab of a panel's document was picked ([`PanelDocument`](super::PanelDocument)): the host shows the document + /// in the panel. The area also activates the panel, as a pick of its own tab does. + DocumentPicked { + /// The panel whose document it is. + panel: P, + /// The document's id. + document: u64, + }, + /// The close button or a middle click on the tab of a panel's document asked to close it. The host closes it by + /// removing it from the panel's spec; the layout does not change. + DocumentClosed { + /// The panel whose document it is. + panel: P, + /// The document's id. + document: u64, + }, /// A floating frame holding `panel` was moved or resized to `rect`. FloatPlaced { /// A panel of the frame. diff --git a/crates/ui-panels/src/docking/floating.rs b/crates/ui-panels/src/docking/floating.rs index 2d6643c1d8..7377e39240 100644 --- a/crates/ui-panels/src/docking/floating.rs +++ b/crates/ui-panels/src/docking/floating.rs @@ -8,7 +8,7 @@ //! A dock window's title row is also the bar of the column the window holds, with the column's double arrow. use super::dock_column::{CHEVRON, ColumnArrow, describe_chevron, paint_chevron}; -use super::drop::{DragUnit, start_group_drag}; +use super::drop::start_window_drag; use super::{DockDropTarget, DockDropped, DockSizes, DockWords, GroupDrag, PanelDrag, PanelKey, native}; use crate::contract::BodyCx; use crate::contract::SizeLimits; @@ -199,6 +199,8 @@ pub struct FloatingGroupOutput { /// The grips the group is resized by this pass, each with the edge or corner it moves and the id of its /// accessibility node; none while it does not resize (minimized). pub resize: Vec<(ResizeEdge, Rect, Id)>, + /// Where `files` were dropped, in the group's layer space, when the drop session knew the pointer. + pub files_at: Option, } impl Outcome for FloatingGroupOutput { @@ -301,8 +303,10 @@ pub struct FloatingGroup<'a> { start_drag: Option>, /// Takes the drops released on the group, on the group's own layer. take_drop: Option>, - /// A move by the title began this pass. + /// A move of the window began this pass. moving: bool, + /// That move continues a press another component handed over (`continue_move`), not a press on the title row. + continued: bool, /// The window takes over the held primary press in this pass: its own move gesture begins from that press with the /// pointer at this point inside the window, so the window follows the pointer and, with /// [`window_of`](FloatingGroup::window_of), docks where it would dock on release. A request of the pass, for the @@ -318,9 +322,12 @@ pub struct FloatingGroup<'a> { raise: bool, /// The files dropped on the group's OS window that no target there took. files: Vec, + /// Where they were dropped. + files_at: Option, } -type StartDrag<'a> = Box FnOnce(&'b mut Cx<'c, FloatingGroup<'a>>) + 'a>; +/// Starts the window-unit drag: a move by the title row when the flag is set, else a drag the window took over. +type StartDrag<'a> = Box FnOnce(&'b mut Cx<'c, FloatingGroup<'a>>, bool) + 'a>; type TakeDrop<'a> = Box FnMut(&'b mut Cx<'c, FloatingGroup<'a>>) + 'a>; @@ -366,9 +373,11 @@ impl<'a> FloatingGroup<'a> { start_drag: None, take_drop: None, moving: false, + continued: false, continue_move: None, raise: false, files: Vec::new(), + files_at: None, } .label(title) } @@ -379,7 +388,7 @@ impl<'a> FloatingGroup<'a> { pub fn window_of(mut self, anchor: P) -> Self { let active = PanelKey::of(&anchor); let size = self.rect.size(); - self.start_drag = Some(Box::new(move |cx| start_group_drag(cx, DragUnit::Window(anchor), active, Some(size), None))); + self.start_drag = Some(Box::new(move |cx, title_row| start_window_drag(cx, anchor, active, size, title_row))); self } @@ -530,6 +539,8 @@ impl Component for FloatingGroup<'_> { let target = WholeWindow::new(cx.rect); if let Some(dropped) = cx.window_drop_target::(&target) { self.files = dropped.files; + // The drop session's pointer, which a drop the OS sent before any position waits for. + self.files_at = cx.dragging::().map(|(_, at)| at); } } } @@ -553,7 +564,7 @@ impl Component for FloatingGroup<'_> { if self.moving && let Some(start) = self.start_drag.take() { - start(&mut cx); + start(&mut cx, !self.continued); } if let Some(opener) = self.menu_opener { Popup::toggle(opener, &mut cx); @@ -571,6 +582,7 @@ impl Component for FloatingGroup<'_> { files: self.files, grip: cx.move_band(), resize: cx.resize_grips(), + files_at: self.files_at, }; native::raise(&cx.core.ctx, &output, self.raise); native::fade(&cx.core.ctx, &output); @@ -640,7 +652,10 @@ impl Container for FloatingGroup<'_> { } else if self.minimized { change.rect = Rect::from_min_size(change.rect.min, Vec2::new(change.rect.width(), self.rect.height())); } - self.moving |= change.kind == PlacementKind::Move && change.phase == GesturePhase::Begin; + if change.kind == PlacementKind::Move && change.phase == GesturePhase::Begin { + self.moving = true; + self.continued = change.continued; + } self.placed = Some(change); } } diff --git a/crates/ui-panels/src/docking/group.rs b/crates/ui-panels/src/docking/group.rs index f7b0c664d0..395ab4a49f 100644 --- a/crates/ui-panels/src/docking/group.rs +++ b/crates/ui-panels/src/docking/group.rs @@ -15,7 +15,7 @@ use crate::contract::{ }; use crate::display::{Shade, Text}; use crate::menu::{GroupItem, Menu, PanelMenu, PanelRow}; -use crate::primitives::PaintShape; +use crate::primitives::{IconSpec, PaintShape}; use crate::runtime::commands::{self, CommandSet as _, CommandState, Commands as _}; use crate::runtime::env::Label; use crate::runtime::focus::{self, FocusRequest, FocusTarget}; @@ -45,7 +45,8 @@ pub struct GroupGripStyle { /// references' 0.83 of the panel was almost invisible on our darker panels). Its shape is the theme's `shape.grip` /// (photocraft#16426): ticks, dots or one level bar, how many, how large and how far apart; by default eleven upright ticks, a thin /// stroke wide, five points tall and a thin stroke apart. The marks keep their ink under the pointer. A toolbar's grip -/// under its column bar and the grip above each icon group of a collapsed column paint the same marks. +/// under its column bar and the grip above each icon group of a collapsed column paint the same marks, unless the app +/// separates icon groups by a rule (`IconGroupSeparator::Rule`). #[derive(Clone, Copy, Debug, PartialEq)] pub(super) struct GripMarks { ink: StyleColor, @@ -276,6 +277,10 @@ pub struct DockGroupOutput { pub picked: Option, /// The panels whose close button or middle click closed their tab this pass. pub closed: Vec, + /// The panel and document whose tab was picked this pass ([`PanelDocument`](super::PanelDocument)). + pub picked_document: Option<(PanelKey, u64)>, + /// The panels and documents whose close button or middle click closed their tab this pass. + pub closed_documents: Vec<(PanelKey, u64)>, /// A context request on a tab (right click, the Menu key, Shift+F10): the group menu opened at the pointer. pub menu: Option>, /// The dock row of the group menu that ran this pass: a Move Panel To target. The menu's command rows fire their @@ -297,6 +302,8 @@ pub struct DockGroupOutput { pub tabs: Vec<(PanelKey, Rect, Id)>, /// The band the group is dragged by this pass, with the id of its accessibility node. pub grip: Option<(Rect, Id)>, + /// The strip's overflow button, when some tabs do not fit, with the id of its accessibility node. + pub overflow: Option<(Rect, Id)>, } impl Outcome for DockGroupOutput { @@ -321,6 +328,8 @@ pub struct DockGroupStyle { struct Reported { picked: Option, closed: Vec, + picked_document: Option<(PanelKey, u64)>, + closed_documents: Vec<(PanelKey, u64)>, menu: Option>, item: Option, commands: Vec, @@ -330,6 +339,7 @@ struct Reported { /// A drag started on the strip's empty room, which `finish` starts as a drag of the group. empty_drag: bool, tabs: Vec<(PanelKey, Rect, Id)>, + overflow: Option<(Rect, Id)>, } /// A group of panels: a header of tab strip and panel menu button, dragged by its empty part, over the active panel's @@ -619,8 +629,37 @@ impl Component for cx.core.memory.shown::(sub(cx.core.id, MENU_ASKED)).0 = Some(request.at); } let grip = cx.part_if_declared(GRIP).map(|grip| (grip.rect, crate::runtime::access::sub_node_id(cx.core.id, GRIP.into()))); - let Reported { picked, closed, menu, item, commands, toggle_minimized, torn_off, drag_started, tabs, .. } = self.reported; - DockGroupOutput { response: cx.response.clone(), picked, closed, menu, item, commands, toggle_minimized, torn_off, drag_started, tabs, grip } + let Reported { + picked, + closed, + picked_document, + closed_documents, + menu, + item, + commands, + toggle_minimized, + torn_off, + drag_started, + tabs, + overflow, + .. + } = self.reported; + DockGroupOutput { + response: cx.response.clone(), + picked, + closed, + picked_document, + closed_documents, + menu, + item, + commands, + toggle_minimized, + torn_off, + drag_started, + tabs, + grip, + overflow, + } } } @@ -679,6 +718,9 @@ impl Container for let shown = self.panels.as_slice().iter().find(|panel| panel.key == self.active); if titled && let Some(panel) = shown { Text::new(panel.title.clone()).role(TypeRole::Title).show(ui); + if let Some(document) = panel.documents.iter().find(|document| document.shown) { + Text::new(document.label.clone()).role(TypeRole::Title).shade(Shade::Faint).show(ui); + } if let Some(count) = panel.count { let count = env.format().integer(u64::try_from(count).unwrap_or(u64::MAX)); Text::new(count).role(TypeRole::Caption).shade(Shade::Faint).show(ui); @@ -723,19 +765,26 @@ impl Container for // A press on the group's empty body focuses its panel, as in Photoshop; an app's own egui body keeps its presses. if surface_pressed && !self.host_body - && let Some((strip, _)) = &strip + && let Some((strip, _, _)) = &strip { focus::request(ui.ctx(), FocusTarget::Id(*strip)); } - if let Some((strip, tabs)) = &strip { + if let Some((strip, tabs, overflow)) = &strip { self.reported.tabs = tabs.iter().map(|(key, rect)| (*key, *rect, crate::contract::item_node(*strip, key))).collect(); + self.reported.overflow = *overflow; } let size = self.size; - let reported = &mut self.reported; + let (titles, reported) = (&self.panels, &mut self.reported); for event in sent { match event { - TabEvent::Picked(key) => reported.picked = Some(key), - TabEvent::Closed(key) => reported.closed.push(key), + TabEvent::Picked(key) => match titles.document_of(key) { + Some(document) => reported.picked_document = Some(document), + None => reported.picked = Some(key), + }, + TabEvent::Closed(key) => match titles.document_of(key) { + Some(document) => reported.closed_documents.push(document), + None => reported.closed.push(key), + }, TabEvent::Menu(request) => reported.menu = Some(request), TabEvent::TornOff(torn) => reported.torn_off = Some(torn), // The strip's empty room is a handle the group is dragged by; a double click on it minimizes the group. @@ -810,30 +859,86 @@ fn tab_marks(ctx: &egui::Context, panels: &[PanelTitle]) -> Vec<(PanelKey, Optio .collect() } -/// A group's tab strip with its tab insertion spots. Returns the strip's id and the rect of each tab it shows, which a -/// replay returns again, moved with the row. -fn tab_row(row: &mut TabRow<'_, P>, ui: &mut Ui) -> (Id, Vec<(PanelKey, Rect)>) { +/// One tab of a group's strip: a panel's, or one of a panel's documents. +struct StripTab<'t> { + key: PanelKey, + title: &'t Label, + swatch: Option>, + closes: bool, + count: Option, + /// A document's tab: it is not dragged. + document: bool, +} + +/// The tabs of a group's strip: the panels' tabs, then every panel's documents in panel order. +fn strip_tabs(panels: &[PanelTitle], closable: bool) -> Vec> { + let documents = panels.iter().flat_map(|panel| { + panel.documents.iter().map(move |document| StripTab { + key: panel.document_key(document.id), + title: &document.label, + swatch: document.swatch, + closes: closable && document.closable, + count: None, + document: true, + }) + }); + panels + .iter() + .map(|panel| StripTab { + key: panel.key, + title: &panel.title, + swatch: panel.swatch, + closes: closable && panel.closable, + count: panel.count, + document: false, + }) + .chain(documents) + .collect() +} + +/// The tab the strip shows as selected: the shown document of the `active` panel, else that panel's own tab. +fn shown_tab(panels: &[PanelTitle], active: PanelKey) -> PanelKey { + panels + .iter() + .find(|panel| panel.key == active) + .and_then(|panel| panel.documents.iter().find(|document| document.shown).map(|document| panel.document_key(document.id))) + .unwrap_or(active) +} + +/// What a group's tab row shows: the strip's id, each shown tab's rect and the overflow button with its node id. +type TabRowShown = (Id, Vec<(PanelKey, Rect)>, Option<(Rect, Id)>); + +/// A group's tab strip with its tab insertion spots. Returns the strip's id, the rect of each tab it shows and the +/// overflow button with its node id, which a replay returns again, moved with the row. The panels' documents are tabs of the same strip after the panel tabs: one +/// fit, one overflow menu and one keyboard order for both. Only panel tabs drag and take tab insertions. +fn tab_row(row: &mut TabRow<'_, P>, ui: &mut Ui) -> TabRowShown { let env = crate::runtime::env::Env::of(ui); let name = Label::from(env.words::().panels.as_str().to_owned()); let rtl = env.direction.is_rtl(); let (panels, active, closable) = (row.panels.as_slice(), row.active, row.closable); let from = PanelKey::of(&row.anchor); let drags = crate::runtime::drag::started(ui.ctx()); - let source = keyed(panels, |panel: &PanelTitle| panel.key).with_text(|panel| Cow::Borrowed(panel.title.as_str())); - let closes = |panel: &PanelTitle| closable && panel.closable; - let kind = if panels.iter().any(closes) { TabKind::Document } else { TabKind::Panel }; + let tabs = strip_tabs(panels, closable); + let source = keyed(&tabs, |tab: &StripTab<'_>| tab.key).with_text(|tab| Cow::Borrowed(tab.title.as_str())); + let tabs = &tabs; + let documents: Vec = tabs.iter().filter(|tab| tab.document).map(|tab| tab.key).collect(); // A press on a panel tab leaves key focus where it is, as in Photoshop: the document's keys keep working. let mut strip = TabStrip::new(name) - .kind(kind) + // Panel tabs whether or not they close: they shrink to their first letters, and the closable ones show a close + // button. + .kind(TabKind::Panel) .keeps_focus() .panel_look(row.look) - .shown(active) + .shown(shown_tab(panels, active)) .tear_off() .natural_height(true) // Group, column and icon drags name what they move inside the drop region; a tab drag does the same. .drag_preview(crate::contract::RowPreview::Named) - .can_close(move |key: &PanelKey| panels.iter().any(|panel| &panel.key == key && closes(panel))) - .drag_payload(move |drag: &ListDrag| Some(PanelDrag { panel: drag.grabbed, from, source: None, started: None })); + .can_close(move |key: &PanelKey| tabs.iter().any(|tab| &tab.key == key && tab.closes)) + .can_drag(move |key: &PanelKey| tabs.iter().any(|tab| &tab.key == key && !tab.document)) + .drag_payload(move |drag: &ListDrag| { + (!documents.contains(&drag.grabbed)).then_some(PanelDrag { panel: drag.grabbed, from, source: None, started: None }) + }); if row.wheel_selects { strip = strip.wheel_selects(); } @@ -843,17 +948,23 @@ fn tab_row(row: &mu } let marks = &row.marks; let strip = strip.show_items(ui, &source, &mut |key, _| { - let panel = panels.iter().find(|panel| &panel.key == key); - let title = panel.map_or_else(Label::default, |panel| panel.title.clone()); + let tab = tabs.iter().find(|tab| &tab.key == key); + let title = tab.map_or_else(Label::default, |tab| tab.title.clone()); // The panel's toggle command marks its tab as it marks the panel's rail button, with the hint to say why. let mark = marks.iter().find(|(marked, _)| marked == key); - let mut tab = Tab::new(title).closable(panel.is_some_and(closes)).marked(mark.is_some()); - if let Some(count) = panel.and_then(|panel| panel.count) { - tab = tab.detail(env.format().integer(u64::try_from(count).unwrap_or(u64::MAX))); + let mut shown = Tab::new(title).closable(tab.is_some_and(|tab| tab.closes)).marked(mark.is_some()); + if let Some(count) = tab.and_then(|tab| tab.count) { + shown = shown.detail(env.format().integer(u64::try_from(count).unwrap_or(u64::MAX))); + } + // A data colour before the name, in the tab's icon slot; not part of its name. + match tab.and_then(|tab| tab.swatch) { + Some(Some(color)) => shown = shown.icon(IconSpec::swatch(color)), + Some(None) => shown = shown.icon(IconSpec::empty_swatch()), + None => {} } match mark.and_then(|(_, hint)| hint.clone()) { - Some(hint) => tab.tooltip(hint), - None => tab, + Some(hint) => shown.tooltip(hint), + None => shown, } }); for event in strip.response.events { @@ -887,7 +998,7 @@ fn tab_row(row: &mu if strip.empty_double { row.sent.send(TabEvent::EmptyDouble); } - (strip.response.response.id, strip.tab_rects) + (strip.response.response.id, strip.tab_rects, strip.overflow) } /// Registers the tab insertion spots of a group: the half of each shown tab nearer the start edge inserts before diff --git a/crates/ui-panels/src/docking/iconic.rs b/crates/ui-panels/src/docking/iconic.rs index 382a9124eb..e3d2fe758c 100644 --- a/crates/ui-panels/src/docking/iconic.rs +++ b/crates/ui-panels/src/docking/iconic.rs @@ -16,9 +16,9 @@ use crate::contract::{ }; use crate::menu::GroupItem; use crate::primitives::{IconSpec, TextRun}; -use crate::runtime::env::Label; +use crate::runtime::env::{EnvValue, Label}; use crate::runtime::focus::KeyUse; -use crate::style::{ComponentStyle, Corners, GlyphRole, StyleColor, StyleCx, SurfaceKind, SurfaceStyle}; +use crate::style::{ComponentStyle, Corners, GlyphRole, RuleKind, StyleColor, StyleCx, SurfaceKind, SurfaceStyle}; use craft_behavior::dock::{Column, DockEdge, Group}; use craft_behavior::overlay::Side; use craft_behavior::{Axis, CursorIcon, DockSide, Metrics, PartKey, PressPhase, Sense, Value}; @@ -97,6 +97,20 @@ pub enum IconicMode { Rail, } +/// What marks the icon groups of a collapsed column apart. An app sets it once at its root (`RootEnv::values`). Either +/// way each group keeps its grip strip above its first icon, which drags the group. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, EnvValue, crate::contract::MemoProps)] +#[env(style)] +#[non_exhaustive] +pub enum IconGroupSeparator { + /// Each group's grip strip shows the dock's grip marks (`shape.grip`, in `line.grip`). + #[default] + Grip, + /// The grip strips are bare, and an edge rule (`line.border`) lies level across the room between two groups, + /// `space.gap.inline` short of the column's sides: VectorCraft's icon groups, as production drew them. + Rule, +} + /// What an iconic column reports. #[derive(Debug)] #[non_exhaustive] @@ -164,6 +178,10 @@ pub struct IconicColumnStyle { name_gap: f32, /// The marks of a group's grip. grip: GripMarks, + /// What marks the icon groups apart. + separator: IconGroupSeparator, + /// How far short of the column's sides a [`IconGroupSeparator::Rule`] stops. + rule_inset: f32, /// The card of a column shown as one ([`card`](IconicColumn::card)). card: SurfaceStyle, } @@ -487,6 +505,8 @@ impl Component for IconicColumn<'_, P> { name_gap: cx.tokens.space.gap.item, // The references' grip: a row of upright ticks, in the theme's grip ink. grip: GripMarks::style(cx), + separator: cx.env::(), + rule_inset: cx.tokens.space.gap.inline, card: card_style(cx), } } @@ -660,8 +680,18 @@ impl Component for IconicColumn<'_, P> { ui.face(CELL.at(at as u64), cell); } let style = &cx.style; - for (_, strip) in self.laid.as_ref().map_or(&[][..], |plan| &plan.grips[..]) { - style.grip.paint_in(ui, *strip); + if let Some(plan) = self.laid.as_ref() { + match style.separator { + IconGroupSeparator::Grip => plan.grips.iter().for_each(|(_, strip)| style.grip.paint_in(ui, *strip)), + IconGroupSeparator::Rule => { + let xs = plan.body.x_range().shrink(style.rule_inset); + // In the middle of the room from a group's last icon to the next group's first. + for ((_, above), (_, strip)) in plan.groups.iter().zip(plan.grips.iter().skip(1)) { + let y = (above.bottom() + strip.bottom()) / 2.0; + ui.draw().rule(RuleKind::Edge, Pos2::new(xs.min, y), Pos2::new(xs.max, y)); + } + } + } } // The edge's line lies on the column's inner edge; its handle stays inside the column. A floating window's // edges are the window's. diff --git a/crates/ui-panels/src/docking/iconic/stories.rs b/crates/ui-panels/src/docking/iconic/stories.rs index f068ad7a15..29171652a8 100644 --- a/crates/ui-panels/src/docking/iconic/stories.rs +++ b/crates/ui-panels/src/docking/iconic/stories.rs @@ -4,9 +4,9 @@ use super::CELL; use crate::buttons::Button; use crate::contract::ShowContainer as _; use crate::contract::{Bind, BodyCx, Show as _, Validity}; -use crate::docking::{ColumnBar, DockSizes, GroupAt, IconicColumn, IconicColumnOutput, IconicMode, PanelSpec}; +use crate::docking::{ColumnBar, DockSizes, GroupAt, IconGroupSeparator, IconicColumn, IconicColumnOutput, IconicMode, PanelSpec}; use crate::runtime::commands::{CommandState, CommandStates}; -use crate::runtime::env::{Env, Message}; +use crate::runtime::env::{Env, Message, with_env}; use crate::sections::Panel; use crate::testing::memory::global; use crate::testing::{Drive, Fixture, StoryData, StoryOutput, stage, story}; @@ -114,6 +114,23 @@ fn icons_as_a_card(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { .into() } +/// The icon groups of an app that sets `IconGroupSeparator::Rule` at its root (VectorCraft's): bare grip strips, and an +/// edge rule across the room between two groups. +#[story(IconicColumn<'static, u8>, covers = [], drive = Drive::Never, title = "Icon groups apart by a rule")] +fn icon_groups_apart_by_a_rule(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { + let column = Column::new(vec![Group::new(vec![0, 1], 0), Group::new(vec![2], 0)]); + with_env( + ui, + |overrides| { + overrides.values.set(IconGroupSeparator::Rule); + }, + |ui| { + let column = IconicColumn::new("Panels", global("iconic column", "rule story"), &column, Bind::kept(), &spec); + at_stage(ui, column, |_, _, _, _| None).into() + }, + ) +} + /// Cells bound to their panels' toggle commands: a marked command whose panel is closed shows the marker. #[story(IconicColumn<'static, u8>, covers = [Default], drive = Drive::Never, commands = marked_states)] fn icon_groups_with_marked_panels(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { diff --git a/crates/ui-panels/src/docking/iconic/trials.rs b/crates/ui-panels/src/docking/iconic/trials.rs index 99eb56e325..b3d65d6652 100644 --- a/crates/ui-panels/src/docking/iconic/trials.rs +++ b/crates/ui-panels/src/docking/iconic/trials.rs @@ -2,17 +2,18 @@ //! groups, the resizes of its flyouts, and a flyout that a command leaves open. #![allow(clippy::panic, clippy::expect_used, reason = "trials assert by panicking")] -use super::GRIP; +use super::{CELL, GRIP}; use crate::buttons::Button; use crate::contract::overlay::{self, OpenFilter}; use crate::contract::{Bind, Show as _, ShowContainer as _}; use crate::docking::group::GRIP_ABOVE; use crate::docking::{ - DockHeights, DockSizes, DockSpot, DockTargets, DragUnit, FlyoutResize, GroupAt, GroupDrag, GroupGrip, IconicColumn, PanelKey, PanelSpec, + DockHeights, DockSizes, DockSpot, DockTargets, DragUnit, FlyoutResize, GroupAt, GroupDrag, GroupGrip, IconGroupSeparator, IconicColumn, PanelKey, + PanelSpec, }; use crate::runtime::commands::{AppCatalog, Binding, CommandDef, CommandInput, Scope}; use crate::runtime::drag; -use crate::runtime::env::Direction; +use crate::runtime::env::{Direction, with_env}; use crate::runtime::focus::{FocusTarget, request}; use crate::runtime::frame::take_output; use crate::sections::Panel; @@ -598,6 +599,7 @@ fn themed_grip(shape: craft_theme::GripShape) -> (Vec, Rect) { knob: None, wells: None, grip: None, + locator: None, }); seed.grip = Some(craft_theme::GripSeed { mark: Some(shape.mark), @@ -659,3 +661,55 @@ fn a_themes_bar_grip_is_one_level_bar() { assert!(equals_token(bar.width(), shape.length) && equals_token(bar.height(), shape.width), "the theme's 18 by 3 bar: {bar:?}"); assert!((bar.center().x - strip.center().x).abs() <= 0.5, "centred across the strip: {bar:?} in {strip:?}"); } + +/// An app's `IconGroupSeparator::Rule` (VectorCraft's): the grip strips show no marks, and one level edge rule lies in +/// the room between the two groups, under the first group's last icon and over the second group's first, short of the +/// column's sides; none lies over the first group. +#[trial] +fn icon_groups_apart_by_a_rule_show_one_level_rule_between_them() { + let mut fixture = Fixture::hosted(|ui| { + let mut column = Column::new(vec![Group::new(vec![1, 2], 0), Group::new(vec![3], 0)]); + column.iconic = true; + let place = Rect::from_min_size(Pos2::ZERO, Vec2::new(RAIL, SCREEN.y)); + with_env( + ui, + |overrides| { + overrides.values.set(IconGroupSeparator::Rule); + }, + |ui| { + let output = IconicColumn::new("Panels", global("iconic column", "rule"), &column, Bind::kept(), &named) + .within(screen()) + .show_flyouts_at(ui, place, |_, _, _, _| None); + Some(output.into()) + }, + ) + }); + fixture.room(SCREEN).settle(); + let id = fixture.root_id().expect("the column shows"); + let border = StyleCx::with_root(fixture.ctx(), |cx| cx.tokens.color.line.border); + let shapes = fixture.frame_shapes(); + let level: Vec<(Pos2, Pos2, egui::Color32)> = shapes + .iter() + .filter_map(|shape| match shape { + egui::Shape::LineSegment { points: [a, b], stroke } if (a.y - b.y).abs() < EPS => Some((*a, *b, stroke.color)), + _ => None, + }) + .collect(); + for group in [0, 1] { + let strip = fixture.part_rect(id, GRIP.at(group)).expect("each group keeps its grip"); + assert!(grip_ticks(&shapes, strip).is_none(), "group {group}: the strip shows no marks"); + } + let first = fixture.part_rect(id, GRIP.at(0)).expect("the first group's grip"); + assert!(!level.iter().any(|(a, _, _)| first.y_range().contains(a.y)), "no rule over the first group: {level:?}"); + let (last, next) = ( + fixture.part_rect(id, CELL.at(1)).expect("the first group's last icon"), + fixture.part_rect(id, CELL.at(2)).expect("the second group's icon"), + ); + let between: Vec<_> = level.iter().filter(|(a, _, _)| a.y > last.bottom() && a.y < next.top()).collect(); + let [(a, b, ink)] = between.as_slice() else { panic!("one rule between the groups: {level:?}") }; + let (left, right) = (a.x.min(b.x), a.x.max(b.x)); + let span = right - left; + assert!(left > 0.0 && right < RAIL && span > RAIL - span, "the rule reaches across the column, short of its sides: {a:?} to {b:?}"); + let [r, g, bl, al] = border.0; + assert_eq!(*ink, egui::Color32::from_rgba_unmultiplied(r, g, bl, al), "the rule is in line.border"); +} diff --git a/crates/ui-panels/src/docking/mod.rs b/crates/ui-panels/src/docking/mod.rs index 56225e0aa6..76af4b07fb 100644 --- a/crates/ui-panels/src/docking/mod.rs +++ b/crates/ui-panels/src/docking/mod.rs @@ -45,7 +45,7 @@ pub use panels::{close_requests, open_requests}; pub use placed::{Placing, placed_rect, with_area_rules}; pub use root::{DockRoot, DockRootOutput, DockRootStyle}; pub use sources::{DividerKind, DockSource, SourceKind}; -pub use spec::{DockGrid, DockHeights, PanelSpec}; +pub use spec::{DockGrid, DockHeights, PanelDocument, PanelSpec}; pub use splitter::{Splitter, SplitterStyle}; pub use targets::{CardInset, DockSizes, DockSpot, DockTargets, GroupDrag, ZoneRule}; pub use words::DockWords; @@ -64,7 +64,7 @@ pub use dock_column::{ group_rects, scale_widths, stacked, width_bounds, }; pub use flyout::{Flyout, FlyoutOutput, FlyoutShown, FlyoutStyle, GroupAt}; -pub use iconic::{FlyoutResize, IconicColumn, IconicColumnOutput, IconicColumnStyle, IconicMode, IconicSizes}; +pub use iconic::{FlyoutResize, IconGroupSeparator, IconicColumn, IconicColumnOutput, IconicColumnStyle, IconicMode, IconicSizes}; pub use window_menu::{WindowMenuRows, WindowMenuRowsOutput}; use crate::contract::{ @@ -133,6 +133,10 @@ pub struct PanelTitle { pub count: Option, /// The line under the header row while the panel is shown ([`PanelSpec::caption`]). pub caption: Option

DockSource

{ pub enum SourceKind

{ /// The tab of a panel: a click shows it, a drag moves it. Tab(P), + /// The tab of a panel's document ([`PanelSpec::documents`](super::PanelSpec::documents)), named by the panel and + /// the document's id: a click shows the panel and picks the document. It is not dragged. + Document(P, u64), /// The bar a group is dragged by, named by the group's first panel. GroupBar(P), + /// The overflow button of a group's tab strip, named by the group's first panel: a click opens the menu of the tabs + /// that do not fit. Only while some tabs do not fit. + Overflow(P), /// The band a floating window is moved by, named by the window's first panel. WindowGrip(P), /// A grip a floating window is resized by, named by the window's first panel, with the edge or corner it moves. diff --git a/crates/ui-panels/src/docking/spec.rs b/crates/ui-panels/src/docking/spec.rs index 2aef553213..04645821cf 100644 --- a/crates/ui-panels/src/docking/spec.rs +++ b/crates/ui-panels/src/docking/spec.rs @@ -7,6 +7,7 @@ use crate::rails::RailDensity; use crate::runtime::commands::CommandRef; use crate::runtime::env::Label; use craft_host::target::WindowKind; +use craft_theme::Srgba; use egui::Vec2; /// Body heights a panel asks for in a dock column while the user has not resized its group. Like [`SizeLimits`] @@ -150,6 +151,54 @@ impl DockGrid { /// How far a width or height may pass the room and still fit it: the rounding of laid-out sizes. const WIDTH_SLACK: f32 = 0.5; +/// A document a panel shows (a composition in a Timeline): a tab of the panel's group after the group's panel tabs, +/// whichever panel the group shows. Picking the tab shows the panel and reports +/// [`DockEvent::DocumentPicked`](super::DockEvent::DocumentPicked); its close button and a middle click report +/// [`DockEvent::DocumentClosed`](super::DockEvent::DocumentClosed). The host opens, shows and closes documents by editing +/// the panel's spec; the dock never changes them. A document tab is not dragged and takes no tab drop. +#[derive(Clone, Debug, PartialEq, crate::contract::MemoProps)] +#[non_exhaustive] +pub struct PanelDocument { + /// The document's id, unique among the panel's documents. + pub id: u64, + /// The tab's text. + pub label: Label, + /// The data colour shown before the label ([`PanelSpec::swatch`]). + pub swatch: Option>, + /// The tab shows a close button, where the group's tabs close. + pub closable: bool, + /// The panel shows this document: its tab is the selected tab while the panel is the one its group shows. + pub shown: bool, +} + +impl PanelDocument { + /// The document `id` titled `label`: no swatch, not closable, not shown. + pub fn new(id: u64, label: impl Into

{ pub press: Option, /// The arrangement the drag started on, when it started in a dock area. pub(crate) started: Option, + /// The drag is a floating window's move by its title row, which docks only with `DockConfig::title_bar_docks`. A + /// window that took over a panel's drag ([`FloatingGroup::continue_move`](super::FloatingGroup::continue_move)) + /// docks as that drag would. + pub title_row: bool, } diff --git a/crates/ui-panels/src/sections/mod.rs b/crates/ui-panels/src/sections/mod.rs index 1b051bb4be..56c2ccbb66 100644 --- a/crates/ui-panels/src/sections/mod.rs +++ b/crates/ui-panels/src/sections/mod.rs @@ -20,7 +20,7 @@ pub use section::{Section, SectionOutput, SectionStyle}; pub use stack::{SectionStack, SectionStackOutput, SectionStackStyle, StackRows, StackSlot}; #[doc(hidden)] pub use title_row::MenuRows; -pub use title_row::{HeaderAction, HeaderCommand, HeaderStrength, TitleOutput, TitleRow, TitleRowStyle}; +pub use title_row::{HeaderAction, HeaderCommand, HeaderStrength, QuietTitleRow, TitleOutput, TitleRow, TitleRowStyle}; pub use words::SectionWords; pub use panel::{Panel, PanelOutput, PanelStyle}; diff --git a/crates/ui-panels/src/sections/panel.rs b/crates/ui-panels/src/sections/panel.rs index 2d27b2c036..16f330cc1a 100644 --- a/crates/ui-panels/src/sections/panel.rs +++ b/crates/ui-panels/src/sections/panel.rs @@ -133,10 +133,12 @@ impl<'a> Panel<'a> { } /// A header showing the title in a title row, with a rule under it unless the title's weight is a quiet one - /// ([`strength`](Panel::strength)): for a panel that no dock tab or window names. + /// ([`strength`](Panel::strength)): for a panel that no dock tab or window names. Where the app's quiet titles head + /// their body ([`QuietHeader::Heads`](crate::contract::QuietHeader)), the first section under a quiet title draws + /// no rule above it. #[must_use] pub fn titled(mut self) -> Self { - self.props.header = Some(HeaderRegion::new().rule(self.strength.ruled())); + self.props.header = Some(HeaderRegion::new().rule(self.strength.ruled()).heads(true)); self } diff --git a/crates/ui-panels/src/sections/section/stories.rs b/crates/ui-panels/src/sections/section/stories.rs index fd33261ef1..cb94ce0a95 100644 --- a/crates/ui-panels/src/sections/section/stories.rs +++ b/crates/ui-panels/src/sections/section/stories.rs @@ -6,7 +6,7 @@ use crate::display::Text; use crate::layout_components::Stack; use crate::runtime::env::with_env; use crate::sections::sample::body; -use crate::sections::{HeaderAction, HeaderStrength}; +use crate::sections::{HeaderAction, HeaderStrength, QuietTitleRow}; use crate::testing::{Drive, Fixture, StoryData, StoryOutput, story}; use egui::Ui; @@ -47,6 +47,19 @@ fn section_subheading(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { shown.output.into() } +/// A sub-heading of an app that sets `QuietTitleRow::Text` at its root: a text row high over its controls, not a +/// control high. +#[story(Section<'static>, covers = [], drive = Drive::Never)] +fn section_subheading_text_row(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { + with_env( + ui, + |overrides| { + overrides.values.set(QuietTitleRow::Text); + }, + |ui| Section::fixed("Shape modes").strength(HeaderStrength::Subheading).show(ui, |ui, _| body(ui)).output.into(), + ) +} + #[story(Section<'static>, covers = [], drive = Drive::Never)] fn section_with_menu_and_reorder(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { let shown = Section::new("Layers").open(data.bind("open", true)).actions([HeaderAction::Menu]).reorder(true).show(ui, |ui, _| body(ui)); diff --git a/crates/ui-panels/src/sections/title_row.rs b/crates/ui-panels/src/sections/title_row.rs index 32cfc9763e..4ec7e6297c 100644 --- a/crates/ui-panels/src/sections/title_row.rs +++ b/crates/ui-panels/src/sections/title_row.rs @@ -13,7 +13,7 @@ use crate::controls::disclosure::Disclosure; use crate::menu::Menu; use crate::primitives::{IconSpec, Span, TextRun}; use crate::runtime::commands::CommandRef; -use crate::runtime::env::Label; +use crate::runtime::env::{EnvValue, Label}; use crate::style::{ComponentStyle, IconLook, Ink, StyleCx, TextLook, TypeRole}; use craft_behavior::{CursorIcon, Flow, IconId, Metrics, Mixed, NavShape, PartKey, Roving, Sense}; use craft_theme::variant::Tone; @@ -58,6 +58,20 @@ impl HeaderStrength { } } +/// The row a title of a quiet weight (`Caption`, `Subheading`, `Quiet`, `Overline`) stands in. An app sets it once at +/// its root (`RootEnv::values`). +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, EnvValue, crate::contract::MemoProps)] +#[env(style)] +#[non_exhaustive] +pub enum QuietTitleRow { + /// A control high, as the rows of controls under it. + #[default] + Control, + /// A text row (`size.row.text`): VectorCraft's, whose sub-headings and kind line are a line of text over their + /// fields. + Text, +} + /// What a title row's action parts ask the container to do. #[derive(Clone, Copy, Debug, PartialEq, Eq)] #[non_exhaustive] @@ -174,6 +188,9 @@ pub struct TitleRowStyle { subtitle: TextLook, /// The side of an action part: the control height, which is below a tall header's height. action: f32, + /// Whether the row is a quiet title's text row (`QuietTitleRow::Text`), as tall as it must be to hold its title + /// on its centre line. + text_row: bool, } /// An optional icon, a title with an optional note run on after it ("· note", muted body text) and an optional @@ -357,16 +374,18 @@ impl Component for TitleRow<'_> { fn style(cx: &StyleCx<'_>, key: TitleRowStyleKey) -> TitleRowStyle { let text = &cx.tokens.color.text; + let text_row = !key.strength.ruled() && cx.env::() == QuietTitleRow::Text; + let quiet = if text_row { cx.tokens.size.row.text } else { cx.control().height }; let (height, role, shade) = match key.strength { HeaderStrength::Normal => (cx.control().height, TypeRole::Label, text.normal), HeaderStrength::Strong => (cx.tokens.size.panel_header, TypeRole::Title, text.normal), HeaderStrength::Section => (cx.tokens.size.panel_header, TypeRole::BodyStrong, text.normal), HeaderStrength::Heading => (cx.tokens.size.panel_header, TypeRole::Heading, text.normal), - HeaderStrength::Caption => (cx.control().height, TypeRole::Label, text.faint), - HeaderStrength::Subheading => (cx.control().height, TypeRole::Label, text.normal), - HeaderStrength::Quiet => (cx.control().height, TypeRole::Caption, text.muted), + HeaderStrength::Caption => (quiet, TypeRole::Label, text.faint), + HeaderStrength::Subheading => (quiet, TypeRole::Label, text.normal), + HeaderStrength::Quiet => (quiet, TypeRole::Caption, text.muted), HeaderStrength::Bar => (cx.tokens.size.row.text, TypeRole::Label, text.normal), - HeaderStrength::Overline => (cx.control().height, TypeRole::Caption, text.faint), + HeaderStrength::Overline => (quiet, TypeRole::Caption, text.faint), }; let shade = key.tone.map_or_else(|| cx.color(shade), |tone| cx.tone_on_fill(tone)); let (ink, disabled) = (cx.ink(key.icon_ink), cx.color(text.disabled)); @@ -379,6 +398,7 @@ impl Component for TitleRow<'_> { TextLook::new(TypeRole::Caption, Stateful::new(faint).off(States::new(faint, faint, faint, disabled))) }, action: cx.control().height, + text_row, } } @@ -397,7 +417,13 @@ impl Component for TitleRow<'_> { let natural = text + (side + cx.gap()) * parts as f32 + (cx.style.icon.side + cx.gap()) * glyphs as f32 + lead; // A row takes the room it is offered, a filling row all of it, and never more: the title elides to what is left. let width = cx.room.map_or(natural, |room| if self.fill { room } else { natural.min(room) }); - Vec2::new(width, title.y) + if !cx.style.text_row { + return Vec2::new(width, title.y); + } + // The title's x-height sits on the row's centre line (`text_on_centre_line`), so a text row no taller than its + // text holds it there. + let centre = cx.layout(&TextRun::new("x").role(role)).galley.mesh_bounds.center().y; + Vec2::new(width, title.y.max(2.0 * centre).max(2.0 * (title.y - centre))) } fn sense(&self) -> Sense { diff --git a/crates/ui-panels/tests/it/dock_group.rs b/crates/ui-panels/tests/it/dock_group.rs index 8b06514773..44240a12a4 100644 --- a/crates/ui-panels/tests/it/dock_group.rs +++ b/crates/ui-panels/tests/it/dock_group.rs @@ -268,3 +268,87 @@ fn a_click_on_an_app_field_in_the_body_keeps_its_focus() { assert!(group_stop.is_some() && fixture.focused() != Some(field_id), "a press on the empty body focuses the group's panel"); assert_ne!(on_field, group_stop, "the clicks on the field left the group's stop unfocused"); } + +// A press on an app's own egui widget in a group's body that only drags (a canvas) is the widget's, not a press on the +// group's empty body; a press on the body's empty room still is. +#[trial] +fn a_press_on_an_app_drag_widget_in_the_body_is_no_surface_press() { + let surface = Rc::new(Cell::new(false)); + let canvas = Rc::new(Cell::new(None::)); + let (pressed, shown) = (Rc::clone(&surface), Rc::clone(&canvas)); + let panels = vec![PanelTitle::new(PanelKey::new(1), "Navigator")]; + let mut fixture = Fixture::new(move |ui| { + let group = DockGroup::new(1usize, Titles::from_content(panels.clone()), panels[0].key); + let (pressed, shown) = (Rc::clone(&pressed), Rc::clone(&shown)); + group.show_at(ui, Rect::from_min_size(Pos2::new(10.0, 10.0), Vec2::new(300.0, 240.0)), move |ui, cx| { + pressed.set(pressed.get() || cx.surface_pressed()); + let (rect, _) = ui.allocate_exact_size(Vec2::new(120.0, 60.0), egui::Sense::drag()); + shown.set(Some(rect)); + }); + }); + fixture.settle(); + let Some(rect) = canvas.get() else { panic!("the body shows the app's canvas") }; + fixture.click_at(rect.center()).settle(); + assert!(!surface.get(), "a press on the drag-only widget is no press on the group's empty body"); + fixture.click_at(Pos2::new(rect.center().x, rect.bottom() + 80.0)).settle(); + assert!(surface.get(), "a press on the empty body is the group's surface press"); +} + +// Closable panel tabs stay panel tabs: in a group too narrow for their whole names every tab keeps its place in the +// strip, the shown one its whole name, and each shows a close button. A middle click closes an inactive tab without +// showing it first. +#[trial] +fn closable_panel_tabs_shrink_and_close_on_a_middle_click() { + let (picked, closed) = (Rc::new(Cell::new(None::)), Rc::new(Cell::new(None::))); + let (picks, closes) = (Rc::clone(&picked), Rc::clone(&closed)); + let names = ["Character", "Paragraph", "Glyphs"]; + let panels: Vec = (0..3).map(|at| PanelTitle::new(PanelKey::new(at as u64 + 1), names[at]).closable(true)).collect(); + let keys: Vec = panels.iter().map(|panel| panel.key).collect(); + let group_rect = Rect::from_min_size(Pos2::new(10.0, 10.0), Vec2::new(300.0, 200.0)); + let mut fixture = Fixture::new(move |ui| { + let out = DockGroup::new(1usize, Titles::from_content(panels.clone()), panels[0].key).closable().show_at(ui, group_rect, |_, _| ()); + if let Some(key) = out.output.picked { + picks.set(Some(key)); + } + if let Some(key) = out.output.closed.first() { + closes.set(Some(*key)); + } + }); + fixture.settle(); + let tabs: Vec<_> = names.iter().map(|name| fixture.by_label(name).unwrap_or_else(|| panic!("the {name} tab stays in the strip"))).collect(); + for (name, tab) in names.iter().zip(&tabs) { + assert!(group_rect.contains_rect(tab.rect), "the {name} tab {:?} lies inside the group", tab.rect); + assert!(fixture.by_label(&format!("Close {name}")).is_some(), "the {name} tab shows a close button"); + } + // Paragraph's name is as long as Character's: shrunk beside the shown tab, which keeps its whole name. + assert!(tabs[1].rect.width() < tabs[0].rect.width() - 0.5, "the other tabs shrink and the shown tab keeps its whole name"); + assert!(fixture.by_label("More tabs").is_none(), "no tab goes to the overflow menu while its first letters fit"); + let at = tabs[2].center(); + fixture.frame(vec![pointer::moved(at)]); + fixture.frame(vec![pointer::middle(at, true)]); + fixture.frame(vec![pointer::middle(at, false)]).settle(); + assert_eq!(closed.get(), Some(keys[2]), "the middle click closes the tab"); + assert_eq!(picked.get(), None, "the middle click does not show the tab first"); +} + +// An AccessKit click on a closable tab's close button closes the tab, as a click on it does, though the tab row has +// settled and replays its last run. +#[trial] +fn an_access_click_on_a_settled_tabs_close_button_closes_it() { + use craft_ui::testing::focus::AccessActionKind; + let closed = Rc::new(Cell::new(None::)); + let closes = Rc::clone(&closed); + let panels = vec![PanelTitle::new(PanelKey::new(1), "Color").closable(true), PanelTitle::new(PanelKey::new(2), "Swatches").closable(true)]; + let key = panels[1].key; + let mut fixture = Fixture::new(move |ui| { + let group = DockGroup::new(1usize, Titles::from_content(panels.clone()), panels[0].key).closable(); + let out = group.show_at(ui, Rect::from_min_size(Pos2::new(10.0, 10.0), Vec2::new(300.0, 240.0)), |_, _| ()); + if let Some(key) = out.output.closed.first() { + closes.set(Some(*key)); + } + }); + fixture.idle(4); + let Some(close) = fixture.by_label("Close Swatches") else { panic!("the Swatches tab shows a close button") }; + fixture.access(AccessActionKind::Click, &close).settle(); + assert_eq!(closed.get(), Some(key), "the access click closes the tab"); +} diff --git a/crates/ui-panels/tests/it/sections/caption.rs b/crates/ui-panels/tests/it/sections/caption.rs index d45449990c..82703ee6b3 100644 --- a/crates/ui-panels/tests/it/sections/caption.rs +++ b/crates/ui-panels/tests/it/sections/caption.rs @@ -42,3 +42,23 @@ fn an_overline_section_shows_its_title_in_capitals_with_no_rule() { let (_, section_lines) = rules("Pages to print", HeaderStrength::Section); assert!(section_lines > lines, "no rule above an overline"); } + +/// The height of a sub-heading's title row under `row`. +fn subheading_height(row: craft_ui::sections::QuietTitleRow) -> f32 { + let mut fixture = Fixture::new(|ui| { + Section::fixed("Ellipse Properties").strength(HeaderStrength::Subheading).show(ui, |ui, _| { + ui.label("body"); + }); + }); + fixture.root_value(row).room(ROOM).settle(); + fixture.by_role(craft_ui::contract::Role::HEADING).first().expect("the sub-heading is a heading").rect.height() +} + +/// An app whose sub-headings are a line of text over their fields (`QuietTitleRow::Text`) gets a title row shorter +/// than the control-high one other apps keep. +#[trial] +fn a_text_row_subheading_stands_lower_than_a_control_high_one() { + use craft_ui::sections::QuietTitleRow; + let (control, text) = (subheading_height(QuietTitleRow::Control), subheading_height(QuietTitleRow::Text)); + assert!(text < control, "the text row ({text}) is lower than the control-high row ({control})"); +} diff --git a/crates/ui-panels/tests/it/sections/panel_header.rs b/crates/ui-panels/tests/it/sections/panel_header.rs index 090b7c9da6..90efd080f0 100644 --- a/crates/ui-panels/tests/it/sections/panel_header.rs +++ b/crates/ui-panels/tests/it/sections/panel_header.rs @@ -70,3 +70,35 @@ fn panel_routes_unused_arrow_from_button_to_its_collection() { fixture.key(Key::ArrowDown, Modifiers::NONE).settle(); assert!(events.borrow().iter().any(|event| matches!(event, CollectionEvent::LeadMoved { .. })), "the list receives the move"); } + +/// An app whose quiet title heads its body (`QuietHeader::Heads`, VectorCraft's kind line) draws no rule between the +/// title and the first section, where the default keeps the section's rule; a second section still stands under its +/// rule. +#[trial] +fn the_first_section_under_a_heading_quiet_title_draws_no_rule() { + use craft_ui::contract::QuietHeader; + use craft_ui::sections::{HeaderStrength, Section}; + use egui::Shape; + let rules = |sections: &'static [&'static str], quiet: QuietHeader| { + let mut fixture = Fixture::new(move |ui| { + Panel::new("Properties").titled().strength(HeaderStrength::Quiet).show(ui, |ui, _| { + for title in sections { + Section::fixed(*title).show(ui, |ui, _| { + ui.label("body"); + }); + } + }); + }); + fixture.root_value(quiet).room(egui::Vec2::new(400.0, 300.0)).settle(); + fixture + .frame_shapes() + .iter() + .filter(|shape| !matches!(shape, Shape::Text(_))) + .map(Shape::visual_bounding_rect) + .filter(|rect| rect.is_finite() && rect.height() <= 2.0 && rect.width() >= 200.0) + .count() + }; + let one = rules(&["Transform"], QuietHeader::Heads); + assert!(one < rules(&["Transform"], QuietHeader::Ruled), "no rule between the heading title and the first section"); + assert!(rules(&["Transform", "Appearance"], QuietHeader::Heads) > one, "a section after another still stands under its rule"); +} diff --git a/crates/ui-patterns/src/patterns/dock/area.rs b/crates/ui-patterns/src/patterns/dock/area.rs index 29e963ccd9..ad4a690104 100644 --- a/crates/ui-patterns/src/patterns/dock/area.rs +++ b/crates/ui-patterns/src/patterns/dock/area.rs @@ -52,6 +52,17 @@ pub struct InvalidGeometry { pub error: DockError, } +/// Files dropped on a floating OS window of the dock: the shown panel of the group under the drop (the first group's for +/// a drop on the title row, or when the pointer was not known), and the files. +#[derive(Clone, Debug, PartialEq)] +#[non_exhaustive] +pub struct WindowFiles

{ + /// The shown panel of the group the files were dropped on. + pub panel: P, + /// The files, in the order the OS lists them. + pub files: Vec, +} + /// What a dock area reports in a pass: the actions it applied to the workspace and the events for the host. #[derive(Debug)] #[non_exhaustive] @@ -69,6 +80,11 @@ pub struct DockAreaOutput

{ pub events: Vec>, /// The shown panel of the group that holds key focus: focus is on the group or on a control inside it. pub focused: Option

, + /// The shown panel of the group whose body the primary press of this pass went down in, whatever took the press: a + /// framework control, the group's empty body or the app's own egui widget in a host body + /// ([`PanelSpec::host_body`](crate::docking::PanelSpec::host_body)), which keeps its presses and focus, so + /// `focused` does not name its group. A host that keeps a focused panel of its own makes it this one. + pub pressed: Option

, /// The panel whose tab the user clicked or picked this pass; a pick of the host's `DockArea::focus` is not the /// user's and shows only in `actions`. pub picked: Option

, @@ -85,8 +101,9 @@ pub struct DockAreaOutput

{ pub columns: Vec<(P, Rect)>, /// The OS windows the floating windows showed in this pass, each named by a panel of the window (the first). pub windows: Vec<(P, ViewportId)>, - /// The files dropped on the area's windows this pass, for the host to open. - pub window_files: Vec, + /// The files dropped on the area's floating OS windows this pass that no target there took, one entry per drop, + /// each with the panel it was dropped on, for the host to open. + pub window_files: Vec>, /// Every place the area drew this pass where a press starts a dock gesture: each tab, each group's drag bar, each /// floating window's grip and resize grips, and each divider, with its rect, its OS window and the id of its /// accessibility node. Nothing the area did not draw reports: a hidden panel, the groups of a column collapsed to @@ -168,6 +185,13 @@ pub struct DockArea<'a, P: Clone + Eq + Hash + Debug + Send + Sync + 'static> { /// `group_view` draws) takes neither; `DockAreaOutput::focused` tells the host where focus is. #[prop] focus: Option

, + /// The floating window holding the panel comes to the front in this pass: an OS window gets + /// `WindowAction::Focus`, an in-app window goes to the top of the floating windows. A request of the pass: a host + /// that opens or activates a floating panel (its Window menu, a command) passes the panel in the pass after. When + /// no floating window holds the panel, or the window opens in this pass (a new window opens in front), it does + /// nothing. + #[prop] + raise: Option

, /// Adds the host's fixed trailing controls to the docked rail containing `panel`. The panel identifies the /// column as it moves between dock sides. The host draws the controls through [`DockPanels::rail_footer`]; its /// icons scroll above them when the rail is short. Has no effect in flyout mode or on floating columns. @@ -201,6 +225,7 @@ impl<'a, P: Clone + Eq + Hash + Debug + Send + Sync + 'static> DockArea<'a, P> { flyout: None, continue_move: None, focus: None, + raise: None, rail_footer: None, top_inset: 0.0, } @@ -301,15 +326,18 @@ struct Report

{ actions: Vec>, events: Vec>, focused: Option

, + pressed: Option

, picked: Option

, flyout: Vec>>, placed: Vec<(P, Rect)>, /// The OS windows the floating windows showed in, by their first panel. windows: Vec<(P, ViewportId)>, /// The files dropped on the floating windows that no target there took. - files: Vec, + files: Vec>, /// The gesture sources the parts drew, in the order they showed. sources: Vec>, + /// The groups shown this pass, by their shown panel, in the order they showed. + shown: Vec<(P, Rect)>, } /// The inputs of the workspace's derived values: the workspace, the panels' specs and the lock. @@ -338,6 +366,8 @@ struct Scene<'s, P> { continue_move: Option<(&'s P, Vec2)>, /// The panel whose group takes key focus in this pass (`DockArea::focus`). focus: Option<&'s P>, + /// The panel whose window comes to the front (`DockArea::raise`). + raise: Option<&'s P>, rtl: bool, /// The docked places floating panels left, for Dock Panel. floated: &'s [(P, Location

)], @@ -464,12 +494,13 @@ struct Passed

{ actions: Vec>, events: Vec>, focused: Option

, + pressed: Option

, picked: Option

, edit: EditEvents>>, space: Option>, columns: Vec<(P, Rect)>, windows: Vec<(P, ViewportId)>, - files: Vec, + files: Vec>, sources: Vec>, } @@ -550,6 +581,7 @@ impl<'a, P: Clone + Eq + Hash + Debug + Send + Sync + 'static> DockArea<'a, P> { mut flyout, continue_move, focus, + raise, rail_footer, top_inset, } = self; @@ -611,6 +643,7 @@ impl<'a, P: Clone + Eq + Hash + Debug + Send + Sync + 'static> DockArea<'a, P> { auto_collapse, continue_move: continue_move.as_ref().map(|(panel, grab)| (panel, *grab)), focus: focus.as_ref(), + raise: raise.as_ref(), sizes, rtl, rail_footer: rail_footer.as_ref(), @@ -631,19 +664,21 @@ impl<'a, P: Clone + Eq + Hash + Debug + Send + Sync + 'static> DockArea<'a, P> { passed = Some(result); }); let requested = close_requests::

(&ctx); - let Passed { geometry, actions, events, focused, picked, edit, space, columns, windows, files, sources } = passed.unwrap_or_else(|| Passed { - geometry: Vec::new(), - actions: Vec::new(), - events: Vec::new(), - focused: None, - picked: None, - edit: EditEvents::new(), - space: None, - columns: Vec::new(), - windows: Vec::new(), - files: Vec::new(), - sources: Vec::new(), - }); + let Passed { geometry, actions, events, focused, pressed, picked, edit, space, columns, windows, files, sources } = + passed.unwrap_or_else(|| Passed { + geometry: Vec::new(), + actions: Vec::new(), + events: Vec::new(), + focused: None, + pressed: None, + picked: None, + edit: EditEvents::new(), + space: None, + columns: Vec::new(), + windows: Vec::new(), + files: Vec::new(), + sources: Vec::new(), + }); if shown.output.dropped.is_some() { cross_window::accept_cross_window(&ctx); } @@ -653,6 +688,7 @@ impl<'a, P: Clone + Eq + Hash + Debug + Send + Sync + 'static> DockArea<'a, P> { requested, events, focused, + pressed, picked, error, edit, @@ -720,6 +756,7 @@ struct Input<'i, P> { auto_collapse: bool, continue_move: Option<(&'i P, Vec2)>, focus: Option<&'i P>, + raise: Option<&'i P>, sizes: DockSizes, rtl: bool, rail_footer: Option<&'i P>, @@ -768,6 +805,7 @@ fn show_area( auto_collapse, continue_move, focus, + raise, sizes, rtl, rail_footer, @@ -796,6 +834,7 @@ fn show_area( auto_collapse, continue_move, focus, + raise, rtl, floated: current.floated(), rail_footer, @@ -809,12 +848,14 @@ fn show_area( actions: Vec::new(), events: Vec::new(), focused: None, + pressed: None, picked: None, flyout: Vec::new(), placed: Vec::new(), windows: Vec::new(), files: Vec::new(), sources: Vec::new(), + shown: Vec::new(), }, dock: id, }; @@ -913,6 +954,7 @@ fn show_area( actions: report.actions, events: report.events, focused: report.focused, + pressed: report.pressed, picked: report.picked, edit, space: Some(space), @@ -1173,6 +1215,8 @@ impl Pass<'_, P> { .command(spec.command) .count(spec.count) .caption(spec.caption) + .swatch(spec.swatch) + .documents(spec.documents) }) .collect(), ) @@ -1236,11 +1280,13 @@ impl Pass<'_, P> { } GroupAt::Show(rect) => rect, }; + self.report.shown.push((shown.clone(), rect)); // One child `Ui` held to the group's rect. It takes the parent's next id, so a change of the group's first tab // keeps every id inside. The host's view runs first, held to the group's rect and clipped to it: it lays out in // the group's room, never in the room the area has left. Where the host leaves the group to the dock, the // group shows in its place. Both run every pass; the host memoizes inside its view, the group inside its // header and its bodies. + let pressed = Cell::new(false); let (strip, view) = if grip > 0.0 { rect.split_top_bottom_at_y(rect.top() + grip.min(rect.height())) } else { (Rect::NOTHING, rect) }; let output = ui .scope_builder(UiBuilder::new().max_rect(rect), |ui| { @@ -1255,7 +1301,14 @@ impl Pass<'_, P> { None => { let group = make(active, look.minimized); let group = if focus.is_some() { group.take_focus() } else { group }; - Some(group.show_at(ui, rect, |ui, body| panel_body(scene, &panels, shown, ui, body)).output) + Some( + group + .show_at(ui, rect, |ui, body| { + pressed.set(pressed.get() || body.pressed_within(ui)); + panel_body(scene, &panels, shown, ui, body); + }) + .output, + ) } } }) @@ -1269,9 +1322,19 @@ impl Pass<'_, P> { } return None; }; - let tabs = - output.tabs.iter().filter_map(|(key, rect, node)| Some(DockSource::new(SourceKind::Tab(scene.panel(*key)?.clone()), *rect, *node))); + // A tab key is a panel's or one of its documents' (`Titles::document_of`). + let kind_of = |key: PanelKey| match scene.panel(key) { + Some(panel) => Some(SourceKind::Tab(panel.clone())), + None => { + let (panel, document) = parts_of().titles.document_of(key)?; + Some(SourceKind::Document(scene.panel(panel)?.clone(), document)) + } + }; + let tabs = output.tabs.iter().filter_map(|(key, rect, node)| Some(DockSource::new(kind_of(*key)?, *rect, *node))); self.report.sources.extend(tabs); + if let Some((rect, node)) = output.overflow { + self.report.sources.push(DockSource::new(SourceKind::Overflow(anchor.clone()), rect, node)); + } if let Some((rect, node)) = output.grip { self.report.sources.push(DockSource::new(SourceKind::GroupBar(anchor.clone()), rect, node)); } @@ -1304,7 +1367,9 @@ impl Pass<'_, P> { let torn = torn.map(|(panel, pointer)| { float_drop(&DragUnit::Panel(panel.clone()), scene.space, pointer, Some(fitted(ui, panel)), None, scene.rtl).action }); - let clicked = output.picked.and_then(|key| scene.panel(key)); + // A document's tab shows its panel, as the panel's own tab does, and names the document to the host. + let document = output.picked_document.and_then(|(key, document)| Some((scene.panel(key)?, document))); + let clicked = output.picked.and_then(|key| scene.panel(key)).or(document.map(|(panel, _)| panel)); if let Some(panel) = clicked { self.report.picked = Some(panel.clone()); } @@ -1313,6 +1378,15 @@ impl Pass<'_, P> { if let Some(panel) = picked { self.report.actions.push(Action::activate(panel.clone())); } + if let Some((panel, document)) = document { + self.report.events.push(DockEvent::DocumentPicked { panel: panel.clone(), document }); + } + for (panel, document) in output.closed_documents.into_iter().filter_map(|(key, document)| Some((scene.panel(key)?, document))) { + self.report.events.push(DockEvent::DocumentClosed { panel: panel.clone(), document }); + } + if pressed.get() { + self.report.pressed = Some(shown.clone()); + } // A tab picked in this pass is the group's shown panel from now on, though this pass drew the one before. if focus_within(ui.ctx(), output.response.id) { self.report.focused = Some(picked.unwrap_or(shown).clone()); @@ -1714,6 +1788,9 @@ impl Pass<'_, P> { if let Some((_, grab)) = scene.continue_move.filter(|(panel, _)| window.panels().any(|held| held == *panel)) { group = group.continue_move(grab); } + if scene.raise.is_some_and(|raised| window.panels().any(|held| held == raised)) { + group = group.raise(); + } group = match opening.spec.clone() { Some(window_spec) => group.native(window_spec), None => group.bounds(scene.bounds), @@ -1728,6 +1805,7 @@ impl Pass<'_, P> { } let area_dock = std::mem::replace(&mut self.dock, dock); let drawn = self.report.sources.len(); + let first_group = self.report.shown.len(); let shown = group.show_group(ui, |ui, body| { for (command, state) in states.iter().cloned() { body.publish(command, state); @@ -1754,7 +1832,13 @@ impl Pass<'_, P> { source.viewport = viewport; } } - self.report.files.extend(output.files); + if !output.files.is_empty() { + // The group under the drop, else the first group: a drop on the title row, or with no pointer known. + let groups = &self.report.shown[first_group..]; + let under = output.files_at.and_then(|at| groups.iter().find(|(_, rect)| rect.contains(at))); + let panel = under.or(groups.first()).map_or_else(|| active.clone(), |(panel, _)| panel.clone()); + self.report.files.push(WindowFiles { panel, files: output.files }); + } if let Some(dropped) = dropped.into_inner() { cross_window::accept_cross_window(&ctx); self.report.actions.push(dropped.action); diff --git a/crates/ui-patterns/src/patterns/dock/mod.rs b/crates/ui-patterns/src/patterns/dock/mod.rs index 42143c31a7..8fe3517e3f 100644 --- a/crates/ui-patterns/src/patterns/dock/mod.rs +++ b/crates/ui-patterns/src/patterns/dock/mod.rs @@ -9,7 +9,7 @@ pub(crate) mod workspace_dialogs; // Task panes: docked panes as shell panes, floating panes as floating frames. pub(crate) mod panes; -pub use area::{DockArea, DockAreaOutput, InvalidGeometry}; +pub use area::{DockArea, DockAreaOutput, InvalidGeometry, WindowFiles}; pub use panes::{ PaneArea, PaneAreaOutput, PaneCommands, PaneContent, PaneEdges, PaneFrame, PaneFrameOutput, PaneFrameStyle, PanePlace, PaneRequest, PaneSpec, PaneState, SidePolicy, diff --git a/crates/ui-patterns/src/patterns/form_dialogs/mod.rs b/crates/ui-patterns/src/patterns/form_dialogs/mod.rs index f7370238d9..3719e476ea 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/mod.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/mod.rs @@ -63,7 +63,7 @@ pub(crate) mod new_document; pub use new_document::{ BACKGROUND_COLOR_KEY, BackgroundContents, BitDepth, CardCx, CardSource, ColorMode, ColorProfiles, DetailsCx, DocumentCard, DocumentOptions, DocumentPreset, DocumentSettings, HostedNewDocument, NewDocumentDialog, NewDocumentOutput, NewDocumentPresetWords, NewDocumentResult, - NewDocumentWords, Orientation, PIXEL_ASPECTS, PresetCategory, RasterMemory, RasterSetup, SQUARE_PIXELS, + NewDocumentWords, Orientation, PIXEL_ASPECTS, PresetCardLook, PresetCategory, RasterMemory, RasterSetup, SQUARE_PIXELS, }; pub(crate) mod about; diff --git a/crates/ui-patterns/src/patterns/form_dialogs/new_document.rs b/crates/ui-patterns/src/patterns/form_dialogs/new_document.rs index ad1fd59986..e6820c921c 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/new_document.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/new_document.rs @@ -31,6 +31,7 @@ use craft_theme::Srgba; use egui::{Context, Response, Ui}; use std::cell::RefCell; +pub use cards::PresetCardLook; use cards::{Left, TabId}; use details::Right; diff --git a/crates/ui-patterns/src/patterns/form_dialogs/new_document/cards.rs b/crates/ui-patterns/src/patterns/form_dialogs/new_document/cards.rs index 85d75fd697..dff576276b 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/new_document/cards.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/new_document/cards.rs @@ -4,12 +4,12 @@ use super::presets::{DEFAULT_ID, DocumentOptions, DocumentPreset, NewDocumentPre use super::settings::{CardCx, CardSource, DocumentCard, DocumentSettings, RasterSetup}; use super::{NewDocumentWords, Read, Session, background_label, depth_label, mode_label}; use crate::buttons::{Button, ButtonOutput}; -use crate::contract::{Bind, CollectionEvent, Props as _, SelectMode, Show as _, ShowCollection as _, clicked}; +use crate::contract::{Bind, CollectionEvent, MemoProps, Props as _, SelectMode, Show as _, ShowCollection as _, clicked}; use crate::display::{Shade, Text}; use crate::list::{List, ListRow, ThumbAspect}; use crate::patterns::presets::{PresetId, PresetLibrary}; use crate::primitives::{ContentPainterCx, StrokeWidth}; -use crate::runtime::env::{Label, UnitKind}; +use crate::runtime::env::{Env, EnvValue, Label, UnitKind}; use crate::style::TypeRole; use crate::tabs::{Tab, TabKind, TabStrip}; use crate::tile_grid::{CardText, Tile, TileGrid}; @@ -172,17 +172,21 @@ pub(super) fn show(ui: &mut Ui, session: &Session, value let count = read.units.number(cards.len() as f64, 0..=0); let heading = Label::from(words.presets_heading.fill(&[("n", &count)])); Text::new(heading).role(TypeRole::SectionCaption).shade(Shade::Muted).show(ui); + let look = Env::of(ui).get::(); let shown = TileGrid::::new(words.cards.clone()) .card_columns(CARD_COLUMNS) .card() - .card_text(CardText::Preset) + .card_text(match look { + PresetCardLook::Outline => CardText::Preset, + PresetCardLook::Page => CardText::Page, + }) .fill_row() .aspect(2.0) .select(SelectMode::Single) .detail_line() .rows_stamp(stamp) .selection(Bind::given(selection)) - .show_items(ui, &list, &mut |index, _| tile_of(&cards[*index])); + .show_items(ui, &list, &mut |index, _| tile_of(&cards[*index], look)); route(shown.response.events, &cards, left); } } @@ -350,13 +354,29 @@ fn recent_title(recent: &DocumentOptions, cx: &CardCx<'_, DocumentOptions>) -> L found.map_or_else(|| cx.words.custom.clone(), |preset| preset_title(preset, cx.setup, cx.words, cx.preset_words)) } -/// The tile of a card: the page outline at the card's aspect, the title and the size line. -fn tile_of(card: &DocumentCard) -> Tile<'static> { +/// How New Document's preset cards show their page. An app sets it once at its root (`RootEnv::values`). +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, EnvValue, MemoProps)] +#[env(style)] +#[non_exhaustive] +pub enum PresetCardLook { + /// A small page outline in content ink on a raised card, the name and size line centred under it. + #[default] + Outline, + /// Blank paper on its shadow (`Tile::page`) on a flat card (`CardText::Page`): the name strong on up to two lines, + /// the size line under it. VectorCraft's preset cards, as production drew them. + Page, +} + +/// The tile of a card: the page at the card's aspect in `look`, the title and the size line. +fn tile_of(card: &DocumentCard, look: PresetCardLook) -> Tile<'static> { let page = card.settings.page(); - let tile = Tile::new(card.title.clone()) - .detail(card.line.clone()) - .flat_thumbnail() - .thumb(ThumbAspect::new(2, 1), move |painter: &ContentPainterCx<'_>, rect: Rect| paint_page(painter, rect, page)); + let tile = Tile::new(card.title.clone()).detail(card.line.clone()); + let tile = match look { + PresetCardLook::Outline => { + tile.flat_thumbnail().thumb(ThumbAspect::new(2, 1), move |painter: &ContentPainterCx<'_>, rect: Rect| paint_page(painter, rect, page)) + } + PresetCardLook::Page => tile.page(page.0, page.1), + }; match &card.tooltip { Some(tooltip) => tile.tooltip(tooltip.clone()), None => tile, diff --git a/crates/ui-patterns/src/patterns/form_dialogs/new_document/stories.rs b/crates/ui-patterns/src/patterns/form_dialogs/new_document/stories.rs index d1db0e5c02..fb9f2a7df5 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/new_document/stories.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/new_document/stories.rs @@ -1,6 +1,6 @@ //! Stories of `NewDocumentDialog`. -use super::{CardCx, CardSource, DetailsCx, DocumentCard, DocumentOptions, DocumentSettings, NewDocumentDialog}; +use super::{CardCx, CardSource, DetailsCx, DocumentCard, DocumentOptions, DocumentSettings, NewDocumentDialog, PresetCardLook}; use crate::buttons::Button; use crate::choice::Checkbox; use crate::contract::{Bind, Entry, Outcome as _, Props as _, Show as _, ShowContainer as _, clicked}; @@ -8,6 +8,7 @@ use crate::form::Field; use crate::patterns::presets::{GroupPath, PresetLibrary}; use crate::pickers::Select; use crate::popover::Popover; +use crate::runtime::env::with_env; use crate::testing::{Drive, StoryData, StoryOutput, story}; use craft_behavior::PixelSize; use egui::Ui; @@ -23,6 +24,20 @@ fn new_document_dialog(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { dialog.opened(data.bind("open", true)).show(ui).into() } +/// The preset cards in `PresetCardLook::Page`, which an app sets at its root (VectorCraft's): blank paper on flat +/// cards, the selected one with the hover fill and an accent edge. +#[story(NewDocumentDialog<'static>, covers = [], drive = Drive::Never, title = "Page cards")] +fn new_document_dialog_page_cards(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { + let opened = data.bind("open", true); + with_env( + ui, + |overrides| { + overrides.values.set(PresetCardLook::Page); + }, + |ui| NewDocumentDialog::new(Bind::kept()).clipboard(PixelSize::new(1920, 1080)).opened(opened).show(ui).into(), + ) +} + #[story(NewDocumentDialog<'static>, covers = [], drive = Drive::Never)] fn new_document_dialog_with_app_presets(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { let presets = ( diff --git a/crates/ui-patterns/src/patterns/panels/inspector/stories.rs b/crates/ui-patterns/src/patterns/panels/inspector/stories.rs index fb22c14c94..1b1a34a415 100644 --- a/crates/ui-patterns/src/patterns/panels/inspector/stories.rs +++ b/crates/ui-patterns/src/patterns/panels/inspector/stories.rs @@ -1,8 +1,9 @@ //! Stories of `Inspector`. use super::Inspector; -use crate::contract::{Bind, Props as _, Show as _, ShowContainer as _}; +use crate::contract::{Bind, Props as _, QuietHeader, Show as _, ShowContainer as _}; use crate::primitives::IconSpec; +use crate::runtime::env::with_env; use crate::sections::{HeaderStrength, Section, SectionStack}; use crate::testing::{Drive, StoryData, StoryOutput, story}; use crate::value_drag::Slider; @@ -63,6 +64,30 @@ fn inspector_quiet_title(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { .into() } +/// A quiet title in an app whose quiet titles head their body (`QuietHeader::Heads`): the first section under the kind +/// line draws no rule above it; the second keeps its rule. +#[story(Inspector<'static>, covers = [], drive = Drive::Never)] +fn inspector_quiet_title_heads(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { + with_env( + ui, + |overrides| { + overrides.values.set(QuietHeader::Heads); + }, + |ui| { + let inspector = Inspector::new("Properties").target("ellipse").header("Ellipse").title_strength(HeaderStrength::Quiet); + inspector + .show(ui, |ui, _| { + for title in &TITLES[..2] { + Section::fixed(*title).show(ui, |ui, _| { + Slider::new(Bind::given(30.0), 0.0..=100.0).label("Opacity").show(ui); + }); + } + }) + .into() + }, + ) +} + #[story(Inspector<'static>, covers = [], drive = Drive::Never)] fn inspector_empty(ui: &mut Ui, _: &mut StoryData) -> StoryOutput { Inspector::new("Properties").show(ui, |_, _| {}).into() diff --git a/crates/ui-patterns/tests/it/docking/documents.rs b/crates/ui-patterns/tests/it/docking/documents.rs new file mode 100644 index 0000000000..4b0dbed7a9 --- /dev/null +++ b/crates/ui-patterns/tests/it/docking/documents.rs @@ -0,0 +1,163 @@ +//! A panel's documents are tabs of its group's strip after the panel tabs; a tab's swatch is a data colour before its +//! name. + +use craft_behavior::dock::{Action, Layout, Node, Workspace}; +use craft_theme::Srgba; +use craft_ui::contract::{Bind, BodyCx, PlainData, Role, Tracked}; +use craft_ui::docking::{DockConfig, DockEvent, DockPanels, DockSource, PanelDocument, PanelSpec, PanelSpecs, SourceKind}; +use craft_ui::patterns::dock::DockArea; +use craft_ui::testing::pointer::{middle, moved}; +use craft_ui::testing::{Fixture, Target, access, trial}; +use egui::{Ui, Vec2}; +use std::cell::RefCell; +use std::rc::Rc; +use std::sync::Arc; + +/// A list the trial and the body it hosts both see. +type Shared = Rc>>; + +const TIMELINE: u32 = 1; +const OTHER: u32 = 2; + +/// The Timeline lists two compositions; the other panel has none. +#[derive(PlainData)] +struct Specs; + +impl PanelSpecs for Specs { + fn spec(&self, panel: &u32) -> PanelSpec { + match *panel { + TIMELINE => PanelSpec::new("Timeline") + .documents(vec![PanelDocument::new(1, "Comp 1").closable(true).shown(true), PanelDocument::new(2, "Comp 2").closable(true)]), + _ => PanelSpec::new("Effects"), + } + } +} + +struct Panels; + +impl DockPanels for Panels { + fn body(&mut self, _: &u32, _: &mut Ui, _: &mut BodyCx<'_>) {} +} + +struct Bed { + fixture: Fixture, + workspace: Rc>>>, + events: Rc>>>, + actions: Rc>>>, + /// The gesture sources the area reported in its last pass. + sources: Rc>>>, +} + +/// One group of the Timeline and Effects, Effects shown, in a room `width` wide. +fn bed(width: f32) -> Bed { + let workspace = Rc::new(RefCell::new(Arc::new(Workspace::new(Layout::new(Some(Node::tabs(vec![TIMELINE, OTHER], 1)), Vec::new()))))); + let (events, actions): (Shared>, Shared>) = Default::default(); + let (held, seen, taken, specs) = (Rc::clone(&workspace), Rc::clone(&events), Rc::clone(&actions), Tracked::new(Specs)); + let sources: Rc>>> = Rc::default(); + let reported = Rc::clone(&sources); + let mut fixture = Fixture::new(move |ui| { + let mut workspace = held.borrow().clone(); + let config = DockConfig::default().tab_close_buttons(true); + let shown = DockArea::new("Dock", Bind::bound(&mut workspace), &specs, &mut Panels, config).show(ui); + seen.borrow_mut().extend(shown.events); + taken.borrow_mut().extend(shown.actions); + *reported.borrow_mut() = shown.sources; + *held.borrow_mut() = workspace; + }); + fixture.room(Vec2::new(width, 300.0)).settle(); + Bed { fixture, workspace, events, actions, sources } +} + +/// The tabs the strip shows, by name, in reading order. +fn tabs(fixture: &Fixture) -> Vec<(String, Target)> { + let mut tabs: Vec<(String, Target)> = + fixture.by_role(Role::TAB).into_iter().filter_map(|tab| Some((access::name(fixture.tree(), tab.node)?.to_owned(), tab))).collect(); + tabs.sort_by(|a, b| a.1.rect.left().total_cmp(&b.1.rect.left())); + tabs +} + +fn tab(fixture: &Fixture, name: &str) -> Target { + tabs(fixture).into_iter().find(|(shown, _)| shown == name).map(|(_, tab)| tab).unwrap_or_else(|| panic!("the tab {name} shows")) +} + +#[trial] +fn a_panels_documents_are_tabs_after_the_panel_tabs_that_pick_and_close_through_the_host() { + let mut bed = bed(600.0); + let names: Vec = tabs(&bed.fixture).into_iter().map(|(name, _)| name).collect(); + assert_eq!(names, ["Timeline", "Effects", "Comp 1", "Comp 2"], "the panel tabs, then the Timeline's documents"); + + let second = tab(&bed.fixture, "Comp 2"); + bed.fixture.click(&second).settle(); + assert!( + bed.events.borrow().contains(&DockEvent::DocumentPicked { panel: TIMELINE, document: 2 }), + "the pick names the panel and the document: {:?}", + bed.events.borrow() + ); + assert!(bed.actions.borrow().contains(&Action::activate(TIMELINE)), "and shows the Timeline: {:?}", bed.actions.borrow()); + + let before = bed.workspace.borrow().layout().clone(); + bed.events.borrow_mut().clear(); + let at = tab(&bed.fixture, "Comp 2").rect.center(); + bed.fixture.frame(vec![moved(at)]).frame(vec![middle(at, true)]).frame(vec![middle(at, false)]).settle(); + assert!( + bed.events.borrow().contains(&DockEvent::DocumentClosed { panel: TIMELINE, document: 2 }), + "a middle click asks the host to close the document: {:?}", + bed.events.borrow() + ); + assert_eq!(bed.workspace.borrow().layout(), &before, "the layout does not change"); +} + +/// Each document tab is a gesture source of its own, named by its panel and document, where the tab shows. +#[trial] +fn a_panels_document_tabs_are_sources_named_by_the_panel_and_the_document() { + let bed = bed(600.0); + let sources = bed.sources.borrow(); + let at = |kind: SourceKind| sources.iter().find(|source| source.kind == kind).map(|source| source.rect); + for (document, name) in [(1, "Comp 1"), (2, "Comp 2")] { + let center = tab(&bed.fixture, name).rect.center(); + let rect = at(SourceKind::Document(TIMELINE, document)); + assert!(rect.is_some_and(|rect| rect.contains(center)), "the {name} tab is a source where it shows: {rect:?}, {sources:?}"); + } + assert!(at(SourceKind::Tab(TIMELINE)).is_some(), "the panel's own tab is one too"); +} + +/// A narrow group keeps one strip: the document that does not fit goes to the strip's overflow menu. +#[trial] +fn a_document_that_does_not_fit_goes_to_the_strips_overflow_menu() { + let mut bed = bed(190.0); + assert!(tabs(&bed.fixture).iter().all(|(name, _)| name != "Comp 2"), "the last document does not fit"); + let more = bed.fixture.by_label("More tabs").expect("the strip's overflow menu button shows"); + bed.fixture.click(&more).settle(); + assert!(bed.fixture.by_label("Comp 2").is_some(), "the overflow menu lists the document"); +} + +/// Swatch specs: two panels named alike, the first with a data colour before its name. +#[derive(PlainData)] +struct Swatches; + +impl PanelSpecs for Swatches { + fn spec(&self, panel: &u32) -> PanelSpec { + match *panel { + TIMELINE => PanelSpec::new("Comp").swatch(Some(Srgba::rgb(0.8, 0.3, 0.3))), + _ => PanelSpec::new("Comp"), + } + } +} + +#[trial] +fn a_tabs_swatch_comes_before_its_name_and_is_not_part_of_it() { + let mut workspace = Arc::new(Workspace::new(Layout::new(Some(Node::tabs(vec![TIMELINE, OTHER], 0)), Vec::new()))); + let specs = Tracked::new(Swatches); + let mut fixture = Fixture::new(move |ui| { + DockArea::new("Dock", Bind::bound(&mut workspace), &specs, &mut Panels, DockConfig::default()).show(ui); + }); + fixture.room(Vec2::new(600.0, 300.0)).settle(); + let shown = tabs(&fixture); + assert_eq!(shown.iter().map(|(name, _)| name.as_str()).collect::>(), ["Comp", "Comp"], "both tabs have the same name"); + let label_left = + |tab: &Target| fixture.texts().iter().find(|text| text.text == "Comp" && tab.rect.contains(text.rect.center())).map(|text| text.rect.left()); + let (with, without) = (&shown[0].1, &shown[1].1); + assert!(with.rect.width() > without.rect.width(), "the tab with the swatch is wider: {with:?} {without:?}"); + let (with_text, without_text) = (label_left(with).expect("the first label shows"), label_left(without).expect("the second label shows")); + assert!(with_text - with.rect.left() > without_text - without.rect.left(), "its label starts later in the tab"); +} diff --git a/crates/ui-patterns/tests/it/docking/drop_preview.rs b/crates/ui-patterns/tests/it/docking/drop_preview.rs index 412ef3e703..5fa2bf358e 100644 --- a/crates/ui-patterns/tests/it/docking/drop_preview.rs +++ b/crates/ui-patterns/tests/it/docking/drop_preview.rs @@ -2,7 +2,7 @@ use super::Numbered; use craft_behavior::Axis; -use craft_behavior::dock::{Layout, Node, SplitSize, Workspace}; +use craft_behavior::dock::{Column, DockEdge, Group, Layout, Node, SplitSize, Workspace}; use craft_ui::contract::{Bind, BodyCx, Role, Tracked}; use craft_ui::docking::{DockConfig, DockPanels, DragUnit, FloatSpace, GroupAt, float_drop}; use craft_ui::patterns::dock::DockArea; @@ -206,6 +206,24 @@ fn a_tab_dropped_on_a_strip_at_the_layouts_top_edge_joins_its_group_and_the_edge assert!(group_rect(&bed, 1).width() >= area.width() - SLACK, "the panel went to a full-width row on top"); } +/// A tab dropped at the window edge beside a start dock makes a new outer column there: the band centred on the +/// outermost column's start edge reaches the window edge, so the drop does not need room the dock lacks. +#[trial] +fn a_tab_dropped_at_the_window_edge_beside_a_start_dock_makes_a_new_outer_column() { + let start = Node::dock(DockEdge::Start, vec![Column::new(vec![Group::new(vec![1], 0)]).with_width(150.0)]); + let end = Node::dock(DockEdge::End, vec![Column::new(vec![Group::new(vec![3, 4], 0)]).with_width(150.0)]); + let rest = Node::split(Axis::X, SplitSize::Ratio(0.7), Node::tabs(vec![2], 0), end); + let mut bed = bed_on(Node::split(Axis::X, SplitSize::FixedFirst(150.0), start, rest)); + // The dock area fills the room from its origin, so x = 3 is 3 pt from the window edge. + drop_tab(&mut bed, 4, Pos2::new(3.0, ROOM.y * 0.5)); + let layout = bed.workspace.borrow().layout().clone(); + let path = layout.dock_path(DockEdge::Start).expect("the start dock stays"); + let Some(Node::Dock { columns, .. }) = craft_behavior::dock::node_at(layout.root.as_ref().unwrap(), &path) else { panic!("a start dock") }; + let panels: Vec> = columns.iter().map(|column| column.groups.iter().flat_map(|group| group.panels.clone()).collect()).collect(); + assert_eq!(panels, vec![vec![4], vec![1]], "the dropped panel is a new column on the window-edge side of the docked one"); + assert!(tab(&bed, 4).right() <= tab(&bed, 1).left() + SLACK, "the new column shows outside the old one"); +} + /// A drop that floats a panel in open room marks the region the window takes, as a docked drop marks its group's: one /// outline with a light fill around the pointer, where the window lands. #[trial] diff --git a/crates/ui-patterns/tests/it/docking/float_order.rs b/crates/ui-patterns/tests/it/docking/float_order.rs index 07a6651ca6..55f4ef2fd3 100644 --- a/crates/ui-patterns/tests/it/docking/float_order.rs +++ b/crates/ui-patterns/tests/it/docking/float_order.rs @@ -52,3 +52,39 @@ fn an_app_dialog_opened_over_a_floating_window_shows_above_it_until_the_window_i fixture.frame(vec![moved(WINDOW_ONLY)]).frame(vec![press(WINDOW_ONLY)]).frame(vec![release(WINDOW_ONLY)]).settle(); assert_eq!(fixture.ctx().layer_id_at(BOTH), Some(float), "a press raises the floating window above the dialog"); } + +const LOWER_AT: Rect = Rect { min: Pos2::new(100.0, 100.0), max: Pos2::new(300.0, 260.0) }; +const UPPER_AT: Rect = Rect { min: Pos2::new(200.0, 150.0), max: Pos2::new(400.0, 310.0) }; +/// Inside both windows. +const OVERLAP: Pos2 = Pos2::new(250.0, 220.0); +/// Inside the lower window only. +const LOWER_ONLY: Pos2 = Pos2::new(130.0, 240.0); + +/// `DockArea::raise` brings the floating window holding the panel to the front for the pass it is given in, and the +/// window stays there after it. +#[trial] +fn a_raised_floating_panel_comes_to_the_front_of_the_window_it_overlaps() { + let layout = + Layout::new(Some(Node::tabs(vec![1], 0)), vec![Floating::single(100, vec![2], 0, LOWER_AT), Floating::single(101, vec![3], 0, UPPER_AT)]); + let mut workspace = Arc::new(Workspace::new(layout)); + let raise = Rc::new(Cell::new(None)); + let asked = Rc::clone(&raise); + let specs = Tracked::new(Numbered); + let mut fixture = Fixture::new(move |ui| { + let mut panels = Panels; + let mut area = DockArea::new("Dock", Bind::bound(&mut workspace), &specs, &mut panels, DockConfig::default()); + if let Some(panel) = asked.take() { + area = area.raise(panel); + } + area.show(ui); + }); + fixture.room(Vec2::new(800.0, 600.0)).settle(); + let lower = fixture.ctx().layer_id_at(LOWER_ONLY).expect("the lower window shows"); + assert_ne!(fixture.ctx().layer_id_at(OVERLAP), Some(lower), "the window shown last is on top"); + raise.set(Some(2)); + fixture.frame(Vec::new()).settle(); + assert_eq!(fixture.ctx().layer_id_at(OVERLAP), Some(lower), "the raised window is on top"); + raise.set(Some(1)); + fixture.frame(Vec::new()).settle(); + assert_eq!(fixture.ctx().layer_id_at(OVERLAP), Some(lower), "a docked panel's raise moves no window"); +} diff --git a/crates/ui-patterns/tests/it/docking/floating_area.rs b/crates/ui-patterns/tests/it/docking/floating_area.rs index 88fc5991e9..060ab3797d 100644 --- a/crates/ui-patterns/tests/it/docking/floating_area.rs +++ b/crates/ui-patterns/tests/it/docking/floating_area.rs @@ -64,8 +64,14 @@ struct Bed { chrome: Rc>, /// The panel whose window the next pass asks to continue the held press, with its grab point. hand_over: Rc>>, + /// Where an egui area above the dock shows, whose plain egui drag floats `WINDOW` at `WINDOW_AT` and hands the press + /// to its window with the grab point `HOST_GRAB`, as an app's own popup does when its title is dragged out. + popup: Rc>>, } +/// The grab point inside the window a host's own drag hands its press to. +const HOST_GRAB: Vec2 = Vec2::new(40.0, 12.0); + fn bed(layout: Layout) -> Bed { bed_with(layout, DockConfig::default()) } @@ -80,6 +86,8 @@ fn bed_with(layout: Layout, config: DockConfig) -> Bed { let seen_chrome = Rc::clone(&chrome); let hand_over: Rc>> = Rc::default(); let asked = Rc::clone(&hand_over); + let popup: Rc>> = Rc::default(); + let (shown_popup, hands_over) = (Rc::clone(&popup), Rc::clone(&hand_over)); let mut other = Arc::new(Workspace::new(Layout::new(Some(Node::tabs(vec![SECOND], 0)), Vec::new()))); let specs = Tracked::new(Numbered); let mut fixture = Fixture::new(move |ui| { @@ -99,9 +107,21 @@ fn bed_with(layout: Layout, config: DockConfig) -> Bed { if shows_second.get() { DockArea::new("Second dock", Bind::bound(&mut other), &specs, &mut panels, DockConfig::default()).show(ui); } + if let Some(rect) = shown_popup.get() { + egui::Area::new(egui::Id::unique("host popup")).order(egui::Order::Foreground).fixed_pos(rect.min).show(ui.ctx(), |ui| { + let (_, drag) = ui.allocate_exact_size(rect.size(), egui::Sense::drag()); + if drag.drag_started() { + shown_popup.set(None); + let mut floated = held.borrow().layout().clone(); + floated.floating.push(Floating::single(100, vec![WINDOW], 0, WINDOW_AT)); + *held.borrow_mut() = Arc::new(Workspace::new(floated)); + hands_over.set(Some((WINDOW, HOST_GRAB))); + } + }); + } }); fixture.settle(); - Bed { fixture, workspace, actions, second, float_height, chrome, hand_over } + Bed { fixture, workspace, actions, second, float_height, chrome, hand_over, popup } } /// A point on the floating window's title row, on its band: clear of the actions and the double arrow at its end. @@ -261,6 +281,70 @@ fn a_window_asked_to_continue_the_held_press_follows_the_pointer() { assert!(!followed, "no window holds the docked panel, so none takes the press"); } +/// A floating window that took over a panel's drag docks on release as that drag would, though the window's title row +/// does not dock (`title_bar_docks(false)`): dropped on the docked group's tab strip, the panel joins the group. Its own +/// title row dragged there only moves the window. +#[trial] +fn a_window_that_took_over_a_panel_drag_docks_on_a_tab_strip_though_its_title_row_does_not() { + let config = DockConfig::default().title_bar_docks(false); + let joins = |handed_over: bool| { + let mut bed = bed_with(with_window(Some(Node::tabs(vec![DOCKED], 0))), config.clone()); + let tab = bed.fixture.by_role(Role::TAB).into_iter().find(|tab| !WINDOW_AT.contains(tab.center())).expect("the docked tab shows"); + let over = Pos2::new(tab.rect.right() + 20.0, tab.center().y); + let from = if handed_over { tab.center() } else { window_title() }; + bed.fixture.frame(vec![moved(from)]); + bed.fixture.frame(vec![press(from)]); + if handed_over { + bed.hand_over.set(Some((WINDOW, Vec2::new(40.0, 12.0)))); + bed.fixture.frame(Vec::new()); + } + for step in 1..=4 { + bed.fixture.frame(vec![moved(from + (over - from) * (step as f32 / 4.0))]); + } + bed.fixture.frame(vec![release(over)]).settle(); + let layout = bed.workspace.borrow().layout().clone(); + layout.floating.is_empty() && layout.place(&WINDOW).is_some_and(|place| layout.place(&DOCKED).is_some_and(|docked| docked == place)) + }; + assert!(joins(true), "the handed-over drag joins the docked group"); + assert!(!joins(false), "the title row only moves the window"); +} + +/// A press a host's own egui widget holds (a popup's title, which no framework part senses) carries on as the drag of +/// the window the host floats in that pass and hands the press to: the window follows the pointer and docks on the +/// docked group's tab strip. The window shows first in the pass its drag starts, before its layer is recorded; the +/// drop targets still look through it, so its own target does not take the drop and refuse it. +#[trial] +fn a_window_takes_over_a_press_a_plain_egui_widget_holds() { + let mut bed = bed_with(Layout::new(Some(Node::tabs(vec![DOCKED], 0)), Vec::new()), DockConfig::default().title_bar_docks(false)); + let tab = bed.fixture.by_role(Role::TAB).into_iter().next().expect("the docked tab shows"); + let over = Pos2::new(tab.rect.right() + 20.0, tab.center().y); + let popup = Rect::from_min_size(Pos2::new(WINDOW_AT.min.x, WINDOW_AT.max.y + 20.0), Vec2::new(160.0, 24.0)); + bed.popup.set(Some(popup)); + bed.fixture.frame(Vec::new()); + let from = popup.center(); + bed.fixture.frame(vec![moved(from)]); + bed.fixture.frame(vec![press(from)]); + for step in 1..=4 { + bed.fixture.frame(vec![moved(from + (over - from) * (step as f32 / 4.0))]); + } + assert!(dragging(&bed), "the window runs the handed-over drag"); + let mark = drag::mark(bed.fixture.ctx()).expect("a target under the dragged window takes the drop"); + let points = match mark { + DropMark::Line { from, to, .. } | DropMark::Region { line: Some([from, to]), .. } => vec![from, to], + DropMark::Into(rect) | DropMark::Region { area: rect, .. } => vec![rect.center()], + _ => Vec::new(), + }; + let strip = tab.rect.expand(SLACK); + assert!( + !points.is_empty() && points.iter().all(|point| point.y >= strip.top() && point.y <= strip.bottom()), + "the mark is the tab strip's: {mark:?}" + ); + bed.fixture.frame(vec![release(over)]).settle(); + let layout = bed.workspace.borrow().layout().clone(); + let joined = layout.floating.is_empty() && layout.place(&WINDOW).is_some_and(|place| layout.place(&DOCKED) == Some(place)); + assert!(joined, "the window's panel joins the docked group: {layout:?}"); +} + /// A dock area's first pass leaves a drag running in another area alone. #[trial] fn an_areas_first_pass_keeps_a_running_drag() { diff --git a/crates/ui-patterns/tests/it/docking/mod.rs b/crates/ui-patterns/tests/it/docking/mod.rs index 1228b00a51..766343ee05 100644 --- a/crates/ui-patterns/tests/it/docking/mod.rs +++ b/crates/ui-patterns/tests/it/docking/mod.rs @@ -26,6 +26,7 @@ pub(crate) mod sources; pub(crate) mod app_modal; pub(crate) mod columns; pub(crate) mod dock_back; +pub(crate) mod documents; pub(crate) mod group_view; pub(crate) mod host_body; pub(crate) mod host_keys; diff --git a/crates/ui-patterns/tests/it/docking/native.rs b/crates/ui-patterns/tests/it/docking/native.rs index 81f0909430..206c0b1e0d 100644 --- a/crates/ui-patterns/tests/it/docking/native.rs +++ b/crates/ui-patterns/tests/it/docking/native.rs @@ -10,7 +10,7 @@ use craft_ui::buttons::Button; use craft_ui::contract::Role; use craft_ui::contract::{Bind, BodyCx, DropMark, PlainData, Show as _, ShowContainer as _, SizeLimits, Tracked}; use craft_ui::display::Text; -use craft_ui::docking::{DockConfig, DockGrid, DockPanels, PanelSpec, PanelSpecs}; +use craft_ui::docking::{DockConfig, DockGrid, DockPanels, GroupAt, PanelSpec, PanelSpecs}; use craft_ui::menu::{Menu, MenuItem}; use craft_ui::patterns::dock::DockArea; use craft_ui::popover::DropVeil; @@ -105,6 +105,34 @@ fn a_native_dock_window_is_moved_by_the_app_from_its_first_pass() { assert!(probe.0.iter().all(|known| *known), "every pass of the window knows the app moves it: {:?}", probe.0); } +/// A dock restored with a native float in the second pass of the first frame, as an app that lays out its window in +/// the first pass and shows its dock in the next: the float's window paints during the frame's run, before the run's +/// output reaches the renderer the windows share, so its texture changes must come after the first pass's +/// allocations (the font atlas). The kit's renderer panics on a change to a texture it has not allocated. +#[trial] +fn a_dock_restored_with_a_native_float_in_a_later_pass_of_the_first_frame_paints() { + let windows = Windows::new(); + windows.root_info(info(true, ROOT_AT)); + windows.child_info(info(true, PALETTE_AT)); + let mut window = float(); + window.native = Some(Placement::new(PALETTE_AT.size().into(), 1.0)); + let mut workspace = Arc::new(Workspace::new(Layout::new(None, vec![window]))); + let mut probe = MoveProbe(Vec::new()); + let mut passes = 0; + windows.frame(vec![], vec![], |ui| { + passes += 1; + if passes == 1 { + ui.label("Starting"); + ui.ctx().request_discard("the dock shows in the next pass"); + return; + } + let config = DockConfig::default().native_windows(true); + let _ = DockArea::new("Native dock", Bind::bound(&mut workspace), &Specs::with(Permissions::ALL), &mut probe, config).show(ui); + }); + assert_eq!(passes, 2, "the first frame runs two passes"); + assert!(!probe.0.is_empty(), "the float's window runs its pass in the second one"); +} + /// The dock records a move the OS made to its native window, and nothing while the OS reports what the model holds. #[trial] fn the_dock_records_where_the_os_put_its_native_window() { @@ -276,6 +304,8 @@ struct NativeDock { palette_shapes: Vec, /// Whether Auto-Collapse Iconic Panels is on in the frames of a collapsed palette. auto_collapse: bool, + /// The panel the next frame asks the dock to raise (`DockArea::raise`). + raise: Option, } impl NativeDock { @@ -307,6 +337,7 @@ impl NativeDock { palette_tree: None, palette_shapes: Vec::new(), auto_collapse: false, + raise: None, }; for _ in 0..3 { dock.frame(vec![]); @@ -326,8 +357,13 @@ impl NativeDock { let (mut palettes, mut stepped) = (Palettes, SteppedPalette); let panels: &mut dyn DockPanels = if self.stepped { &mut stepped } else { &mut palettes }; let specs = &self.specs; + let raise = self.raise.take(); let out = self.windows.frame(root, child, |ui| { - actions.extend(DockArea::new("Native dock", Bind::bound(workspace), specs, &mut *panels, DockConfig::default()).show(ui).actions); + let mut area = DockArea::new("Native dock", Bind::bound(workspace), specs, &mut *panels, DockConfig::default()); + if let Some(panel) = raise { + area = area.raise(panel); + } + actions.extend(area.show(ui).actions); }); if self.palette.is_none() { self.palette = out.builders.iter().map(|(viewport, _)| *viewport).find(|viewport| *viewport != ViewportId::ROOT); @@ -348,6 +384,21 @@ impl NativeDock { } } +/// `DockArea::raise` of a panel in a native palette focuses the palette's OS window once, in the pass it is given in; +/// a pass without it sends nothing. +#[trial] +fn a_raised_native_palette_gets_the_os_focus_once() { + let mut dock = NativeDock::on(Os::Linux, Arc::new(FakeSystem::new())); + let focus = |commands: &[ViewportCommand]| commands.iter().filter(|command| matches!(command, ViewportCommand::Focus)).count(); + let (_, settled) = dock.frame(vec![]); + assert_eq!(focus(&settled), 0, "a pass without a raise focuses nothing"); + dock.raise = Some(1); + let (_, raised) = dock.frame(vec![]); + assert_eq!(focus(&raised), 1, "the raised palette's window gets the focus"); + let (_, after) = dock.frame(vec![]); + assert_eq!(focus(&after), 0, "the raise is a request of its pass"); +} + fn docks_window(actions: &[Action]) -> bool { actions.iter().any(|action| matches!(action, Action::MoveWindow { .. })) } @@ -1432,6 +1483,57 @@ fn a_file_dropped_on_a_native_float_reaches_window_files_once() { assert_eq!(reached(true), 0, "a file a target in the window took does not"); } +/// Palettes that record where each group showed, by its panels, in the window it showed in. +#[derive(Default)] +struct GroupRects(Vec<(Vec, Rect)>); + +impl DockPanels for GroupRects { + fn body(&mut self, _: &u32, _: &mut Ui, _: &mut BodyCx<'_>) {} + + fn group_view(&mut self, panels: &[u32], _: usize, _: &mut Ui, at: GroupAt, _: &mut BodyCx<'_>) -> Option { + if let GroupAt::Show(rect) = at { + self.0.retain(|(shown, _)| shown != panels); + self.0.push((panels.to_vec(), rect)); + } + None + } +} + +/// A file dropped on a native float of two groups names the shown panel of the group under the drop, once. +#[trial] +fn a_file_dropped_on_a_native_float_names_the_group_under_it() { + let dropped_on = |lower: bool| { + let windows = Windows::new(); + windows.root_info(info(true, ROOT_AT)); + windows.child_info(info(true, PALETTE_AT)); + let column = Column::new(vec![Group::new(vec![1], 0), Group::new(vec![2], 0)]); + let mut workspace = Arc::new(Workspace::new(Layout::new(None, vec![Floating::new(105, column, PALETTE_AT)]))); + let mut panels = GroupRects::default(); + let specs = Specs::with(Permissions::ALL); + let mut frame = |child: Vec, hovered: Vec, dropped: Vec, panels: &mut GroupRects| { + let mut reached = Vec::new(); + windows.frame_with_files(vec![], child, FilesOver::Child, hovered, dropped, |ui| { + let area = DockArea::new("Native dock", Bind::bound(&mut workspace), &specs, panels, DockConfig::default()); + reached.extend(area.show(ui).window_files.into_iter().map(|files| files.panel)); + }); + reached + }; + for _ in 0..4 { + frame(vec![], vec![], vec![], &mut panels); + } + let group = |panel: u32| panels.0.iter().find(|(shown, _)| shown == &[panel]).map(|(_, rect)| *rect).expect("the group showed"); + let at = group(if lower { 2 } else { 1 }).center(); + let mut reached = frame(vec![moved(at)], vec![HoveredFile::default()], vec![], &mut panels); + reached.extend(frame(vec![moved(at)], vec![], vec!["a.png".to_owned()], &mut panels)); + for _ in 0..2 { + reached.extend(frame(vec![moved(at)], vec![], vec![], &mut panels)); + } + reached + }; + assert_eq!(dropped_on(true), vec![2], "a drop on the lower group names its panel once"); + assert_eq!(dropped_on(false), vec![1], "a drop on the upper group names its panel once"); +} + /// A palette whose panel holds an Opacity field, then reads the keys its OS window's pass left, as an app passes a /// panel window's leftover Enter and Escape on to its main window: how many of each it read. #[derive(Default)] diff --git a/crates/ui-patterns/tests/it/docking/sources.rs b/crates/ui-patterns/tests/it/docking/sources.rs index 4756ae9cfc..d68e5cd2bd 100644 --- a/crates/ui-patterns/tests/it/docking/sources.rs +++ b/crates/ui-patterns/tests/it/docking/sources.rs @@ -3,11 +3,12 @@ use super::Numbered; use craft_behavior::Axis; -use craft_behavior::dock::{Column, DockEdge, Floating, Group, Layout, Node, SplitSize, Workspace}; -use craft_ui::contract::{Bind, BodyCx, Tracked}; +use craft_behavior::dock::{Column, DockEdge, Floating, Group, Layout, Node, SplitSize, StackEntry, Workspace}; +use craft_ui::contract::{Bind, BodyCx, Role, Tracked}; use craft_ui::docking::{DividerKind, DockConfig, DockPanels, DockSource, HidePanels, PanelKey, SourceKind}; use craft_ui::patterns::dock::DockArea; use craft_ui::runtime::env::{BodyMode, ShellCx, ShellEntry, WindowKey}; +use craft_ui::testing::access::NodeKey; use craft_ui::testing::{Fixture, trial}; use egui::{Pos2, Rect, Ui, Vec2}; use std::cell::RefCell; @@ -147,3 +148,50 @@ fn a_panel_the_shell_hides_reports_no_source() { assert!(sources.iter().all(|source| named(source) != Some(hidden)), "the hidden panel {hidden} reports no tab, bar or grip: {sources:#?}"); } } + +/// Each section of a stack is a group of one panel whose header holds that panel's tab: an open section and a closed +/// one each report it. +#[trial] +fn each_stack_section_reports_its_panels_tab() { + let mut closed = StackEntry::new(LOWER); + closed.open = false; + let layout = Layout::new(Some(Node::stack(vec![StackEntry::new(UPPER), closed])), Vec::new()); + let reported: Rc>>> = Rc::default(); + let seen = Rc::clone(&reported); + let mut fixture = Fixture::new(move |ui| { + let mut workspace = Arc::new(Workspace::new(layout.clone())); + let specs = Tracked::new(Numbered); + *seen.borrow_mut() = DockArea::new("Stack", Bind::bound(&mut workspace), &specs, &mut Bodies, DockConfig::default()).show(ui).sources; + }); + fixture.room(ROOM).settle(); + let tabs = panels(&reported.borrow(), |kind| if let SourceKind::Tab(panel) = kind { Some(*panel) } else { None }); + assert_eq!(tabs, [UPPER, LOWER], "{:?}", reported.borrow()); +} + +/// A group whose tabs do not fit reports its strip's overflow button, named by the group's first panel, under the id of +/// the button's node and where a click opens the menu of the hidden tabs; groups whose tabs fit report none. +#[trial] +fn a_group_whose_tabs_do_not_fit_reports_its_overflow_button() { + const PANELS: [usize; 6] = [11, 12, 13, 14, 15, 16]; + let reported: Rc>>> = Rc::default(); + let seen = Rc::clone(&reported); + let mut narrow = Fixture::new(move |ui| { + let mut workspace = Arc::new(Workspace::new(Layout::new(Some(Node::tabs(PANELS.to_vec(), 0)), Vec::new()))); + let specs = Tracked::new(Numbered); + let mut bodies = Bodies; + *seen.borrow_mut() = DockArea::new("Overflow", Bind::bound(&mut workspace), &specs, &mut bodies, DockConfig::default()).show(ui).sources; + }); + narrow.room(Vec2::new(160.0, 300.0)).settle(); + let overflow: Vec> = + reported.borrow().iter().filter(|source| matches!(source.kind, SourceKind::Overflow(_))).cloned().collect(); + let kinds: Vec> = overflow.iter().map(|source| source.kind.clone()).collect(); + assert_eq!(kinds, vec![SourceKind::Overflow(PANELS[0])], "one overflow button, named by the group's first panel"); + let more = narrow.by_label("More tabs").expect("the strip's overflow button shows"); + assert_eq!(more.node, NodeKey::of(overflow[0].id), "the source's id is the button's node"); + assert!(narrow.by_role(Role::MENU_ITEM).is_empty(), "no menu is open yet"); + narrow.click_at(overflow[0].rect.center()).settle(); + assert!(!narrow.by_role(Role::MENU_ITEM).is_empty(), "a click on the source's rect opens the menu of the hidden tabs"); + + let (_wide, wide) = fixture(None, None); + assert!(wide.borrow().iter().all(|source| !matches!(source.kind, SourceKind::Overflow(_))), "groups whose tabs fit report no overflow button"); +} diff --git a/crates/ui-patterns/tests/it/docking/tab_focus.rs b/crates/ui-patterns/tests/it/docking/tab_focus.rs index c4c21d266d..fb33776796 100644 --- a/crates/ui-patterns/tests/it/docking/tab_focus.rs +++ b/crates/ui-patterns/tests/it/docking/tab_focus.rs @@ -1,5 +1,6 @@ //! A pointer press on a dock's panel tab leaves key focus where it was, so a hosted app's own shortcuts keep working -//! after a tab click, a tab drag or the tab menu; a press on an app's own egui body is the app's. +//! after a tab click, a tab drag or the tab menu; a press on an app's own egui body is the app's, and the area names +//! the panel pressed into (`DockAreaOutput::pressed`). use craft_behavior::Axis; use craft_behavior::dock::{Layout, Node, SplitSize, Workspace}; @@ -29,21 +30,32 @@ impl PanelSpecs for Specs { struct Panels; impl DockPanels for Panels { - fn body(&mut self, _: &usize, _: &mut Ui, _: &mut BodyCx<'_>) {} + /// The hosted body holds an app's own egui button. + fn body(&mut self, panel: &usize, ui: &mut Ui, _: &mut BodyCx<'_>) { + if *panel == HOSTED { + let _ = ui.button("App button"); + } + } } -/// A dock of the plain group [0, 1] beside the hosted group [2], and the workspace it edits. -fn dock() -> (Fixture, Rc>>>) { +/// The panels the area named as pressed into, one entry per pass that named one. +type Pressed = Rc>>; + +/// A dock of the plain group [0, 1] beside the hosted group [2], the workspace it edits and the panels it reported +/// pressed. +fn dock() -> (Fixture, Rc>>>, Pressed) { let root = Node::split(Axis::X, SplitSize::Ratio(0.5), Node::tabs(vec![0, 1], 0), Node::tabs(vec![HOSTED], 0)); let workspace = Rc::new(RefCell::new(Arc::new(Workspace::new(Layout::new(Some(root), Vec::new()))))); - let (held, specs) = (Rc::clone(&workspace), Tracked::new(Specs)); + let pressed: Pressed = Rc::default(); + let (held, seen, specs) = (Rc::clone(&workspace), Rc::clone(&pressed), Tracked::new(Specs)); let mut fixture = Fixture::new(move |ui| { let mut shown = held.borrow().clone(); - DockArea::new("Dock", Bind::bound(&mut shown), &specs, &mut Panels, DockConfig::default()).show(ui); + let out = DockArea::new("Dock", Bind::bound(&mut shown), &specs, &mut Panels, DockConfig::default()).show(ui); + seen.borrow_mut().extend(out.pressed); *held.borrow_mut() = shown; }); fixture.room(Vec2::new(1200.0, 600.0)).settle(); - (fixture, workspace) + (fixture, workspace, pressed) } /// A secondary press and release at `at`, then an idle frame. @@ -54,7 +66,7 @@ fn secondary_click(fixture: &mut Fixture, at: Pos2) { #[trial] fn a_press_on_a_panel_tab_leaves_key_focus_where_it_was() { - let (mut fixture, workspace) = dock(); + let (mut fixture, workspace, _) = dock(); let tab = fixture.by_label("Panel 1").expect("the first group's second tab"); fixture.click(&tab).idle(1); let shows_one = @@ -78,7 +90,7 @@ fn a_press_on_a_panel_tab_leaves_key_focus_where_it_was() { #[trial] fn a_press_on_an_app_body_is_the_apps_and_one_on_a_plain_body_focuses_its_panel() { - let (mut fixture, _) = dock(); + let (mut fixture, ..) = dock(); let hosted = fixture.by_label("Panel 2").expect("the hosted group's tab").rect; fixture.click_at(Pos2::new(hosted.center().x, hosted.bottom() + 200.0)).idle(1); assert!(fixture.focused_stop().is_none(), "a press on the app's own body takes no framework focus"); @@ -86,3 +98,21 @@ fn a_press_on_an_app_body_is_the_apps_and_one_on_a_plain_body_focuses_its_panel( fixture.click_at(Pos2::new(plain.center().x, plain.bottom() + 200.0)).idle(1); assert!(fixture.focused_stop().is_some(), "a press on a framework panel's empty body focuses its panel"); } + +/// A press in a group's body names the group's shown panel, whatever takes it: the app's own button in a host body +/// (which keeps the press and takes no framework focus) or a plain panel's empty body. A press on a tab is no body +/// press. +#[trial] +fn a_press_in_a_groups_body_names_its_panel_whatever_takes_it() { + let (mut fixture, _, pressed) = dock(); + let button = fixture.by_label("App button").expect("the app's own button in the hosted body"); + fixture.click(&button).idle(1); + assert_eq!(pressed.borrow().as_slice(), [HOSTED], "a press on the app's own widget names the hosted panel"); + pressed.borrow_mut().clear(); + let plain = fixture.by_label("Panel 0").expect("the plain group's tab"); + fixture.click_at(Pos2::new(plain.rect.center().x, plain.rect.bottom() + 200.0)).idle(1); + assert_eq!(pressed.borrow().as_slice(), [0], "a press on a plain body names its shown panel"); + pressed.borrow_mut().clear(); + fixture.click(&plain).idle(1); + assert!(pressed.borrow().is_empty(), "a press on a tab is no body press: {:?}", pressed.borrow()); +} diff --git a/crates/ui-patterns/tests/it/form_dialogs/new_document.rs b/crates/ui-patterns/tests/it/form_dialogs/new_document.rs index f56c6eddc2..9faffb33ba 100644 --- a/crates/ui-patterns/tests/it/form_dialogs/new_document.rs +++ b/crates/ui-patterns/tests/it/form_dialogs/new_document.rs @@ -386,6 +386,50 @@ fn recent_preset_cards_paint_one_small_page_at_its_aspect() { } } +/// An app that sets `PresetCardLook::Page` (VectorCraft) gets each preset card's page as blank paper at the preset's +/// aspect above its title, and no page outline. +#[trial] +fn preset_cards_in_the_page_look_paint_paper_and_no_outline() { + use craft_behavior::PixelSize; + use craft_ui::patterns::form_dialogs::PresetCardLook; + use craft_ui::runtime::access::Role; + use craft_ui::runtime::env::with_env; + use craft_ui::testing::Frames; + + let wide = PixelSize::new(1200, 900); + let mut frames = Frames::new(); + frames.screen(Vec2::new(1440.0, 900.0)); + let mut options = DocumentOptions::default(); + let mut show = |ui: &mut egui::Ui| { + with_env( + ui, + |overrides| { + overrides.values.set(PresetCardLook::Page); + }, + |ui| drop(NewDocumentDialog::new(Bind::bound(&mut options)).clipboard(wide).show(ui)), + ); + }; + for _ in 0..30 { + frames.frame(Vec::new(), &mut show); + } + let tree = frames.tree(); + let card = tree + .with_role(Role::LIST_ITEM) + .into_iter() + .find(|key| tree.name_of(*key).is_some_and(|label| label.starts_with("Clipboard"))) + .and_then(|key| tree.bounds_of(key)) + .expect("the visible Clipboard card"); + let shapes = frames.frame_shapes(&mut show); + let caption = frames.texts().iter().find(|line| line.text == "Clipboard").expect("the preset title is painted").rect; + let above_title = + |rect: &egui::Rect| card.contains_rect(*rect) && rect.bottom() <= caption.top() && (rect.center().x - card.center().x).abs() <= 1.0; + let rects: Vec<_> = shapes.iter().filter_map(|shape| if let egui::Shape::Rect(rect) = shape { Some(rect) } else { None }).collect(); + let pages: Vec<_> = rects.iter().filter(|rect| rect.fill == egui::Color32::WHITE && above_title(&rect.rect)).map(|rect| rect.rect).collect(); + assert_eq!(pages.len(), 1, "one sheet of paper in the card: {pages:?}"); + assert!((pages[0].width() / pages[0].height() - wide.width as f32 / wide.height as f32).abs() < 0.05, "the paper has the preset's aspect"); + assert!(!rects.iter().any(|rect| rect.stroke.width > 0.0 && above_title(&rect.rect)), "no page outline"); +} + /// A Web card turns Artboards on and a Photo card turns it off again; Artboards the user ticked stays on. #[trial] fn web_cards_turn_artboards_on_and_only_take_back_their_own() { diff --git a/crates/ui-shell/src/shell/recent.rs b/crates/ui-shell/src/shell/recent.rs index 556f61dbe6..f5be8d1519 100644 --- a/crates/ui-shell/src/shell/recent.rs +++ b/crates/ui-shell/src/shell/recent.rs @@ -69,12 +69,22 @@ pub struct Template { pub name: String, /// The line under the name: "1920 × 1080 px". pub detail: String, + /// The width and height of the page the template makes, in any one unit: its card shows the page + /// (`Tile::page`), as New Document's presets do, in place of the template's thumbnail. + pub page: Option<(f64, f64)>, } impl Template { /// A template `id` named `name`, with `detail` under the name. pub fn new(id: impl Into, name: impl Into, detail: impl Into) -> Self { - Template { id: id.into(), name: name.into(), detail: detail.into() } + Template { id: id.into(), name: name.into(), detail: detail.into(), page: None } + } + + /// This template makes a `width` by `height` page, which its card shows. + #[must_use] + pub fn page(mut self, width: f64, height: f64) -> Self { + self.page = Some((width, height)); + self } } diff --git a/crates/ui-shell/src/shell/recent_list.rs b/crates/ui-shell/src/shell/recent_list.rs index 56d5dac416..7a13321409 100644 --- a/crates/ui-shell/src/shell/recent_list.rs +++ b/crates/ui-shell/src/shell/recent_list.rs @@ -98,6 +98,9 @@ impl<'a> RecentList<'a> { offers_new: true, offers_open: true, pinned_title: None, + templates_title: None, + new_label: None, + open_label: None, heading_sections: false, }; let files: Vec = recent.iter().take(max_recent).cloned().collect(); diff --git a/crates/ui-shell/src/shell/start.rs b/crates/ui-shell/src/shell/start.rs index 59d7a31a76..0a2945e1d0 100644 --- a/crates/ui-shell/src/shell/start.rs +++ b/crates/ui-shell/src/shell/start.rs @@ -8,13 +8,13 @@ use super::recent::{RecentFile, RecentSort, RecentView, Template, ThumbKey, sort use super::recent_list::{RecentList, recent_body}; use super::words::ShellWords; use crate::buttons::button::ButtonStyleKey; -use crate::buttons::{Button, Link}; +use crate::buttons::{Button, ControlPlace, Link}; use crate::choice::Segmented; use crate::contract::{ - ActivateOn, Bind, BodyCx, CollectionEvent, Entry, Gap, NoValue, Outcome, Pad, Pattern, Props, Remember as _, Scroll, SelectMode, Show as _, - ShowCollection as _, ShowContainer as _, Sizing, clicked, + ActivateOn, Bind, BodyCx, CollectionEvent, Entry, Gap, NoValue, Outcome, Pad, PadEdges, Pattern, Props, Remember as _, RowAlign, Scroll, + SelectMode, Show as _, ShowCollection as _, ShowContainer as _, Sizing, clicked, }; -use crate::display::{Divider, Icon, Text}; +use crate::display::{Divider, Icon, Shade, Text}; use crate::layout_components::{Row, Stack}; use crate::list::{List, ListRow, RowEvent, ThumbAspect, TrailingFace, TrailingPart}; use crate::menu::{Menu, MenuItem}; @@ -26,14 +26,14 @@ use crate::primitives::{ }; use crate::runtime::commands::{self, CommandRef, FireSource}; use crate::runtime::commands::{CommandSet as _, Commands as _}; -use crate::runtime::env::{AgeStyle, Env, Label}; +use crate::runtime::env::{AgeStyle, Env, Label, Overrides, with_env}; use crate::sections::{HeaderStrength, Section}; -use crate::style::{Corners, DataColor, StyleCx, SurfaceKind, SurroundLook, TypeRole}; -use crate::tile_grid::{CaptionPlace, GridZoom, Tile, TileGrid}; +use crate::style::{Corners, DataColor, StyleCx, SurfaceKind, SurroundLook, TypeRole, rgba_color}; +use crate::tile_grid::{CaptionPlace, CardText, GridZoom, Tile, TileGrid}; use craft_behavior::{DisplayOrder, IconId, ItemSource, Proposal, SelectionChange, keyed}; use craft_theme::variant::{CustomVariant, Emphasis, RadiusStep, Tone, VariantLook}; -use craft_theme::{Rgba, Tokens, Variant}; -use egui::{CornerRadius, Rect, Response, Ui, Vec2, pos2, vec2}; +use craft_theme::{PageSizes, Rgba, Tokens, Variant}; +use egui::{CornerRadius, Rect, Response, Ui, UiBuilder, Vec2, pos2, vec2}; use std::borrow::Cow; use std::cell::RefCell; use std::path::{Path, PathBuf}; @@ -150,6 +150,21 @@ pub enum StartLayout { Gallery, /// A greeting page: a title, the templates, then the recent files as rows. It shows neither Pinned nor the drop card. Greeting, + /// One centred column, at most `size.page.column` wide and a page margin from every edge: the title and subtitle, + /// New and Open, the recent files as rows when there are any, the app's section, the templates as cards that keep + /// their size and wrap, then the links, the call to action as a pill. It shows neither Pinned, the drop card nor + /// the recent files' view switch and sort. + Column, +} + +/// The column's template cards keep the card thumbnail's size, so as many as fit stand in a row and the rest wrap. +const COLUMN_CARD_ZOOM: f32 = 1.0; + +/// The call to action among a Column page's links: the primary variant at pill corners, with its icon. +const CALL_TO_ACTION_LOOK: CustomVariant = CustomVariant::new::("craft_ui.start-call-to-action", call_to_action_look); + +fn call_to_action_look(tokens: &Tokens) -> VariantLook { + Variant::PRIMARY.resolve(tokens).radius(RadiusStep::Pill) } /// Where a host section sits on the start screen. @@ -345,6 +360,15 @@ pub struct StartScreen<'a> { /// The page's heading. #[prop(into)] title: Option