From 92016bd894e64a5018e1408f34f4ab62d06b1003 Mon Sep 17 00:00:00 2001 From: hnoerenberg Date: Sat, 28 Nov 2026 03:22:34 +0100 Subject: [PATCH 01/44] fix(ui-shell): Tab in standard mode hides the bars, keeps title and status In standard screen mode Tab hid every slot and panel, so the window lost its menu bar, its status bar and its document tabs. That hiding belongs to the body-only state machine; the editor's chrome bars deserve their own. Reveal grows a chrome state, toggled by Panels in standard mode: the options bar and the rails built by options_bar/top/bottom/start/end hide and reveal like body-only slots (edge reveal and the pin keep working), while the title and status slots stay shown and the window does not become body-only. The pass carries the state to the body through ShellCx::chrome_hidden, so the dock machinery hides the panel docks, their toolbar and the floating windows with them and the document tabs stay. Full Screen Mode With Menu Bar and Full Screen keep the old state. A screen-mode change and ShowPanels clear it. Part of storytold/photocraft#16841. --- crates/ui-contract/src/runtime/env/shell.rs | 57 +++++++-- crates/ui-patterns/tests/it/docking/hidden.rs | 16 +++ crates/ui-shell/src/shell/app_shell.rs | 54 +++++++-- crates/ui-shell/src/shell/reveal.rs | 31 +++-- crates/ui-shell/tests/it/shell/reveal.rs | 112 +++++++++++++++++- 5 files changed, 238 insertions(+), 32 deletions(-) diff --git a/crates/ui-contract/src/runtime/env/shell.rs b/crates/ui-contract/src/runtime/env/shell.rs index 3d0b70fa5f..411a22787d 100644 --- a/crates/ui-contract/src/runtime/env/shell.rs +++ b/crates/ui-contract/src/runtime/env/shell.rs @@ -122,6 +122,9 @@ struct Inner { edges: [bool; 3], tabs: bool, panels_hidden: bool, + /// In standard screen mode the user hid the editor's chrome with Tab: the docks, rails and floating panels of the + /// body hide with the shell's bars, while the body itself and the document tabs stay. + chrome_hidden: bool, regions: ShellRegions, float_bounds: Rect, region: Option, @@ -197,6 +200,7 @@ impl ShellCx { edges: [false; 3], tabs: true, panels_hidden: false, + chrome_hidden: false, regions, float_bounds, region: None, @@ -224,6 +228,13 @@ impl ShellCx { self } + /// The editor's chrome is hidden: the user pressed Tab in standard screen mode, so the shell's bars and rails are + /// gone and the body's docks, rails and floating panels go with them, while the body and the document tabs stay. + pub fn with_chrome_hidden(mut self, hidden: bool) -> Self { + Arc::make_mut(&mut self.inner).chrome_hidden = hidden; + self + } + /// The Tab reveal is on or off. pub fn with_tab_reveal(mut self, on: bool) -> Self { Arc::make_mut(&mut self.inner).tab_reveal = on; @@ -280,11 +291,18 @@ impl ShellCx { self.inner.panels_hidden } - /// Whether the dock at `edge` shows: in normal mode and during the Tab reveal unless the panels are hidden, and the - /// `Start` and `End` docks also while that edge's reveal is on, in body-only mode or while the panels are hidden. + /// Whether the user hid the editor's chrome with Tab in standard screen mode: the shell's bars are gone and the + /// body's docks and floating panels hide with them, while the body and the document tabs stay. + pub fn chrome_hidden(&self) -> bool { + self.inner.chrome_hidden + } + + /// Whether the dock at `edge` shows: in normal mode and during the Tab reveal unless the panels are hidden or the + /// editor's chrome is, and the `Start` and `End` docks also while that edge's reveal is on, in body-only mode or + /// while the panels are hidden. pub fn dock_visible(&self, edge: super::PaneEdge) -> bool { let inner = &*self.inner; - let base = !inner.panels_hidden && (inner.mode == BodyMode::Normal || inner.tab_reveal); + let base = !inner.panels_hidden && !inner.chrome_hidden && (inner.mode == BodyMode::Normal || inner.tab_reveal); base || match edge { super::PaneEdge::Start => self.edge_revealed(RevealEdge::Start), super::PaneEdge::End => self.edge_revealed(RevealEdge::End), @@ -293,9 +311,9 @@ impl ShellCx { } /// Whether floating frames show: in normal mode; in body-only mode only during the Tab reveal; never while the - /// panels are hidden. + /// panels are hidden or the editor's chrome is. pub fn floating_visible(&self) -> bool { - !self.inner.panels_hidden && (self.inner.mode == BodyMode::Normal || self.inner.tab_reveal) + !self.inner.panels_hidden && !self.inner.chrome_hidden && (self.inner.mode == BodyMode::Normal || self.inner.tab_reveal) } /// The same skeleton with its revealed rects registered under `id`, which stays the same across passes. Without @@ -344,17 +362,19 @@ impl ShellCx { } /// Are slots shown by a reveal (Tab or edge) on this pass? Only body-only mode reveals with Tab; an edge reveals in - /// body-only mode and while the panels are hidden. + /// body-only mode, while the panels are hidden, and while the editor's chrome is. pub fn revealed(&self) -> bool { let inner = &*self.inner; let body_only = inner.mode == BodyMode::Only; - (body_only && inner.tab_reveal) || ((body_only || inner.panels_hidden) && inner.edges.iter().any(|on| *on)) + let hides_docks = body_only || inner.panels_hidden || inner.chrome_hidden; + (body_only && inner.tab_reveal) || (hides_docks && inner.edges.iter().any(|on| *on)) } - /// Is the edge reveal on for `edge`? False while the panels show in normal mode, and during the Tab reveal. + /// Is the edge reveal on for `edge`? False while the panels show in normal mode with the editor's chrome shown, + /// and during the Tab reveal. pub fn edge_revealed(&self, edge: RevealEdge) -> bool { let inner = &*self.inner; - (inner.mode == BodyMode::Only || inner.panels_hidden) && !inner.tab_reveal && inner.edges[edge.index()] + (inner.mode == BodyMode::Only || inner.panels_hidden || inner.chrome_hidden) && !inner.tab_reveal && inner.edges[edge.index()] } /// The body rect and the shown slots of this pass. @@ -390,12 +410,25 @@ pub struct ShellEntry(#[doc(hidden)] pub Option); impl crate::contract::MemoProps for ShellEntry { fn key(&self, key: &mut crate::contract::MemoKey) { let Some(shell) = &self.0 else { return key.write_u32(0) }; - let Inner { window, mode, tab_reveal, edges, tabs, panels_hidden, regions, float_bounds, region, page_band, reveals: _, dialog: _ } = - &*shell.inner; + let Inner { + window, + mode, + tab_reveal, + edges, + tabs, + panels_hidden, + chrome_hidden, + regions, + float_bounds, + region, + page_band, + reveals: _, + dialog: _, + } = &*shell.inner; key.write_u32(1); key.feed_hash(window); key.feed_hash(&std::mem::discriminant(mode)); - (*tab_reveal, *edges, *tabs, *panels_hidden).key(key); + (*tab_reveal, *edges, *tabs, *panels_hidden, *chrome_hidden).key(key); regions.body.key(key); key.write_u32(regions.slots.len() as u32); for (slot, rect) in ®ions.slots { diff --git a/crates/ui-patterns/tests/it/docking/hidden.rs b/crates/ui-patterns/tests/it/docking/hidden.rs index 1c16b76745..8e9b6063c4 100644 --- a/crates/ui-patterns/tests/it/docking/hidden.rs +++ b/crates/ui-patterns/tests/it/docking/hidden.rs @@ -93,6 +93,22 @@ fn shift_tab_keeps_the_panels_the_host_names_docked_and_floating_and_tab_hides_t assert_eq!(shown_under(tab, true), BTreeSet::from([CANVAS]), "Tab keeps the canvas only, whatever the host names"); } +#[trial] +fn the_standard_chrome_hiding_hides_every_dock_panel_and_floating_window_yet_keeps_the_body() { + let room = Rect::from_min_size(Pos2::ZERO, Vec2::new(400.0, 300.0)); + let chrome = ShellCx::detached(WindowKey::main(), BodyMode::Normal, room).with_chrome_hidden(true); + assert_eq!( + shown_under(chrome.clone(), true), + BTreeSet::from([CANVAS]), + "the standard Tab hides keeps the protected canvas alone, whatever the host names" + ); + assert_eq!( + shown_under(chrome.with_edge_reveal(RevealEdge::Start, true), false), + BTreeSet::from([CANVAS, TOOLBAR]), + "the start edge's reveal shows the start dock alone, as under Tab" + ); +} + #[trial] fn a_revealed_edge_shows_its_dock_alone_under_tab_and_shift_tab() { let room = Rect::from_min_size(Pos2::ZERO, Vec2::new(400.0, 300.0)); diff --git a/crates/ui-shell/src/shell/app_shell.rs b/crates/ui-shell/src/shell/app_shell.rs index 984c07aeca..8c58854932 100644 --- a/crates/ui-shell/src/shell/app_shell.rs +++ b/crates/ui-shell/src/shell/app_shell.rs @@ -327,6 +327,9 @@ struct Placed<'a, S> { title: bool, /// The options bar: it follows the place, and it is the options bar's height at every edge. options: bool, + /// An editor bar or rail: the user's Tab in standard screen mode hides it, while the title and the status bar + /// stay. + bars: bool, /// The slot's name in the shell's words, for a slot of the canvas preset. named: Option Label>, version: VersionFn<'a, S>, @@ -458,6 +461,8 @@ pub struct AppShellOutput { pub struct ChromeState { /// The user hid every panel, tool and bar. pub hidden: bool, + /// In standard screen mode the user hid the editor's bars and rails with Tab; the title and status slots stay. + pub chrome_hidden: bool, /// The panels are hidden while the tools and bars stay. pub panels_hidden: bool, /// The edge whose slots a reveal shows, when one is on. @@ -477,7 +482,12 @@ pub fn chrome_state(ctx: &Context, viewport: ViewportId) -> ChromeState { impl ChromeState { /// What `reveal` says: the one source of a pass's output and of [`chrome_state`]. fn of(reveal: &Reveal) -> Self { - ChromeState { hidden: reveal.hidden(), panels_hidden: reveal.panels_hidden(), revealed: reveal.revealed_edge() } + ChromeState { + hidden: reveal.hidden(), + chrome_hidden: reveal.chrome_hidden(), + panels_hidden: reveal.panels_hidden(), + revealed: reveal.revealed_edge(), + } } } @@ -505,7 +515,9 @@ impl Outcome for AppShellOutput { /// Tab; the pointer at the top, start or end edge shows that edge's slots, unless a button is held or a popup is /// open or `edge_reveal` is off. Revealed slots cover the body and leave its rect as it is. A screen-mode change ends /// a reveal. The shell takes its own window's Tab toggles from the frame state in the pass that records them: in -/// normal mode Tab hides every slot and panel and shows them again. +/// standard screen mode Tab hides the editor's bars and rails (the [`options_bar`](Self::options_bar) and the slots +/// put by [`top`](Self::top), [`bottom`](Self::bottom), [`start`](Self::start) and [`end`](Self::end)) and shows them +/// again, while the title and status slots stay shown; in the other normal-mode screen it hides every slot and panel. /// - **Canvas preset.** [`title_bar_if`](Self::title_bar_if), [`options_bar`](Self::options_bar), /// and [`status`](Self::status) add the slots of a document editor under the keys of [`slots`](super::slots), /// named by `ShellWords`; the toolbar is a panel of the dock, not a slot; each takes the host's `visible` flag, passed every frame. @@ -633,8 +645,16 @@ impl<'a, S> AppShell<'a, S> { /// The title slot with a slot of your own, for a title that follows the host's menu bar flag. pub fn title(mut self, slot: Slot, version: impl Fn(&S) -> Option + 'a, add: impl FnMut(&mut Ui, &mut BodyCx<'_>, &mut S) + 'a) -> Self { - self.title = - Some(Placed { slot, edge: PaneEdge::Top, title: true, options: false, named: None, version: Box::new(version), add: Box::new(add) }); + self.title = Some(Placed { + slot, + edge: PaneEdge::Top, + title: true, + options: false, + bars: false, + named: None, + version: Box::new(version), + add: Box::new(add), + }); self } @@ -649,7 +669,8 @@ impl<'a, S> AppShell<'a, S> { self.title(Slot::new(keys::TITLE).visible(visible).reveal_if(visible), version, add) } - /// The options bar, a top slot keyed `"options"` that reveals in body-only mode. + /// The options bar, a top slot keyed `"options"` that reveals in body-only mode and hides when the user hides the + /// editor's chrome in standard screen mode. pub fn options_bar( mut self, visible: bool, @@ -662,6 +683,7 @@ impl<'a, S> AppShell<'a, S> { edge: PaneEdge::Top, title: false, options: true, + bars: true, named: Some(|words| words.options.clone()), version: Box::new(version), add: Box::new(add), @@ -669,7 +691,8 @@ impl<'a, S> AppShell<'a, S> { self } - /// The status bar, a bottom slot keyed `"status"` that never reveals. + /// The status bar, a bottom slot keyed `"status"` that never reveals and stays shown while the user hides the + /// editor's chrome in standard screen mode. pub fn status(mut self, visible: bool, version: impl Fn(&S) -> Option + 'a, add: impl FnMut(&mut Ui, &mut BodyCx<'_>, &mut S) + 'a) -> Self { let slot = Slot::new(keys::STATUS).visible(visible); self.slots.push(Placed { @@ -677,6 +700,7 @@ impl<'a, S> AppShell<'a, S> { edge: PaneEdge::Bottom, title: false, options: false, + bars: false, named: Some(|words| words.status.clone()), version: Box::new(version), add: Box::new(add), @@ -727,7 +751,7 @@ impl<'a, S> AppShell<'a, S> { version: impl Fn(&S) -> Option + 'a, add: impl FnMut(&mut Ui, &mut BodyCx<'_>, &mut S) + 'a, ) -> Self { - self.slots.push(Placed { slot, edge, title: false, options: false, named: None, version: Box::new(version), add: Box::new(add) }); + self.slots.push(Placed { slot, edge, title: false, options: false, bars: true, named: None, version: Box::new(version), add: Box::new(add) }); self } @@ -818,14 +842,17 @@ impl<'a, S> AppShell<'a, S> { let paged = page.is_some(); let toggles = take_chrome_toggles(&ctx, viewport, &window); if !paged { - kept.reveal.apply(&toggles, host_only, allow_reveal); + kept.reveal.apply(&toggles, host_only, allow_reveal, mode == ScreenMode::Standard); } let only = kept.reveal.only(host_only); + // In standard screen mode the user's Tab hides the editor's bars and rails; those slots hide and reveal + // like they do in body-only mode, while the title and status slots and the body's own parts stay. + let bars = kept.reveal.chrome_hidden(); let pointer = pointer::frame(&ctx); let frozen = !pointer.buttons.is_empty() || any_open(&ctx, OpenFilter::Keys); let rtl = cx.env.direction().is_rtl(); if !paged { - kept.reveal.track(Tracking::new(only, allow_reveal, edge_reveal), Aim::new(pointer.pos, frozen, cx.rect, rtl)); + kept.reveal.track(Tracking::new(only || bars, allow_reveal, edge_reveal), Aim::new(pointer.pos, frozen, cx.rect, rtl)); } // Every shown slot's rect and the body's, before any slot runs. Slots that a reveal shows in body-only mode @@ -833,7 +860,9 @@ impl<'a, S> AppShell<'a, S> { let plan = |is_dropped: bool| { let visible: Vec = slots .iter() - .map(|placed| !bare && !paged && kept.reveal.shows(&placed.slot, placed.edge, only, allow_reveal, mode, is_dropped)) + .map(|placed| { + !bare && !paged && kept.reveal.shows(&placed.slot, placed.edge, only || (bars && placed.bars), allow_reveal, mode, is_dropped) + }) .collect(); let claims: Vec = slots .iter() @@ -844,7 +873,7 @@ impl<'a, S> AppShell<'a, S> { key: placed.slot.key(), edge: placed.edge, extent: placed.extent(&tokens, &kept.measured), - overlay: covers(&placed.slot, only), + overlay: covers(&placed.slot, only || (bars && placed.bars)), }) .collect(); let regions = layout(cx.rect, &claims, rtl); @@ -887,6 +916,7 @@ impl<'a, S> AppShell<'a, S> { .with_tabs(tabs) .with_tab_reveal(kept.reveal.tab()) .with_panels_hidden(chrome.panels_hidden) + .with_chrome_hidden(chrome.chrome_hidden) .with_reveals_key(sub(cx.id, "reveals")); // The room an embedded shell shows: its rect less what a scroll or a parent clips. Its dialogs are contained in // it. @@ -964,7 +994,7 @@ impl<'a, S> AppShell<'a, S> { for (placed, shown) in slots.iter_mut().zip(&visible) { let floats = floating && placed.options; // A floating bar is a layer over the body: it shows with the covering slots in every mode. - if !*shown || if floats { !covering } else { covers(&placed.slot, only) != covering } { + if !*shown || if floats { !covering } else { covers(&placed.slot, only || (bars && placed.bars)) != covering } { continue; } let by_content = placed.sized_by_content(); diff --git a/crates/ui-shell/src/shell/reveal.rs b/crates/ui-shell/src/shell/reveal.rs index ff694122ea..f6db702128 100644 --- a/crates/ui-shell/src/shell/reveal.rs +++ b/crates/ui-shell/src/shell/reveal.rs @@ -13,12 +13,15 @@ pub(crate) const EDGE_REVEAL_STRIP: f32 = 8.0; /// /// - `hidden`: the user hid every panel, tool and bar in normal mode (Tab); the window then behaves as in body-only /// mode, and Tab shows them again. +/// - `chrome`: in standard screen mode the user hid the editor's chrome (Tab): the bars and rails built to hide with it +/// go, the title and status slots stay, and Tab shows them again. The window does not become body-only. /// - `panels_hidden`: the panels are hidden and the tools and bars stay (Shift+Tab). /// - `tab`: in body-only mode, Tab shows the slots built to reveal until the next Tab. /// - `edges`: in body-only mode the pointer at the top, start or end edge shows the slots of that edge. #[derive(Clone, Debug, Default, PartialEq)] pub(crate) struct Reveal { hidden: bool, + chrome: bool, panels_hidden: bool, tab: bool, edges: [bool; 3], @@ -78,14 +81,15 @@ const EDGES: [RevealEdge; 3] = [RevealEdge::Top, RevealEdge::Start, RevealEdge:: impl Reveal { /// Applies the toggles the window's shell took from the frame state in this pass. `host_only` says the screen mode - /// shows the body only; `allow_reveal` is off for a presentation. - pub(crate) fn apply(&mut self, toggles: &[ChromeToggle], host_only: bool, allow_reveal: bool) { + /// shows the body only; `allow_reveal` is off for a presentation; `standard` says the screen mode is Standard, + /// where Tab hides the editor's chrome bars and rails while the window keeps its title and status slots. + pub(crate) fn apply(&mut self, toggles: &[ChromeToggle], host_only: bool, allow_reveal: bool, standard: bool) { for toggle in toggles { - self.toggle(*toggle, host_only, allow_reveal); + self.toggle(*toggle, host_only, allow_reveal, standard); } } - fn toggle(&mut self, toggle: ChromeToggle, host_only: bool, allow_reveal: bool) { + fn toggle(&mut self, toggle: ChromeToggle, host_only: bool, allow_reveal: bool, standard: bool) { match toggle { ChromeToggle::Panels if host_only => { if allow_reveal { @@ -96,20 +100,26 @@ impl Reveal { } } } + ChromeToggle::Panels if standard => { + self.chrome = !(self.chrome || self.panels_hidden); + self.panels_hidden = false; + self.end_reveal(); + } ChromeToggle::Panels => { self.hidden = !(self.hidden || self.panels_hidden); self.panels_hidden = false; self.end_reveal(); } - ChromeToggle::PanelsKeepTools if !host_only && !self.hidden => self.panels_hidden = !self.panels_hidden, + ChromeToggle::PanelsKeepTools if !host_only && !(self.hidden || self.chrome) => self.panels_hidden = !self.panels_hidden, ChromeToggle::ShowPanels => { - if self.hidden || self.panels_hidden { + if self.hidden || self.chrome || self.panels_hidden { self.hidden = false; + self.chrome = false; self.panels_hidden = false; self.end_reveal(); } } - ChromeToggle::Reveal(Some(edge)) if allow_reveal && !self.tab && (self.only(host_only) || self.panels_hidden()) => { + ChromeToggle::Reveal(Some(edge)) if allow_reveal && !self.tab && (self.only(host_only) || self.chrome || self.panels_hidden()) => { self.edges = [false; 3]; self.edges[at(edge)] = true; self.pinned = Some((edge, None)); @@ -125,6 +135,7 @@ impl Reveal { /// Ends the Tab and edge reveal and the user's hiding: every screen-mode change does. pub(crate) fn clear(&mut self) { self.hidden = false; + self.chrome = false; self.panels_hidden = false; self.end_reveal(); } @@ -155,6 +166,12 @@ impl Reveal { self.hidden } + /// Whether the user hid the editor's chrome bars and rails with Tab in standard screen mode; the window's title + /// and status slots, and everything of the body that is not a bar, stay. + pub(crate) fn chrome_hidden(&self) -> bool { + self.chrome + } + /// The edge whose reveal is on, when one is. pub(crate) fn revealed_edge(&self) -> Option { EDGES.into_iter().find(|edge| self.edges[at(*edge)]) diff --git a/crates/ui-shell/tests/it/shell/reveal.rs b/crates/ui-shell/tests/it/shell/reveal.rs index d8592e078c..710310f52c 100644 --- a/crates/ui-shell/tests/it/shell/reveal.rs +++ b/crates/ui-shell/tests/it/shell/reveal.rs @@ -198,7 +198,7 @@ fn chrome_state_reads_the_hiding_the_shell_left_and_show_panels_ends_it() { assert!(!seen.panels_hidden); let seen = tabbed(&mut windows, &mut mode); - assert_eq!(state(&windows), (true, false, None), "Tab hid the chrome"); + assert_eq!(state(&windows), (false, false, None), "Tab hid the chrome in standard mode: the window's own hiding, not the body-only one"); assert!(!seen.panels_hidden && !seen.revealed); tabbed(&mut windows, &mut mode); assert_eq!(state(&windows), (false, false, None), "Tab showed it"); @@ -229,3 +229,113 @@ fn chrome_state_reads_the_hiding_the_shell_left_and_show_panels_ends_it() { "a viewport with no shell reads the default" ); } + +/// What one pass of a full document window's shell showed: the slots it laid out, whether the shell put the +/// window into its body-only hiding, and whether the body saw the chrome hiding. +struct WindowSeen { + slots: Vec<&'static str>, + hidden: bool, + bars: bool, + body_sees_bars: bool, +} + +/// One frame of a document window's shell: a title bar under the host's menu-bar flag, an options bar, a status +/// bar and a tool rail, with a document canvas in the body and nothing focused, so Tab reaches the shell. +fn window_pass(windows: &mut Frames, mode: &mut ScreenMode, events: Vec) -> WindowSeen { + let ctx = windows.ctx.clone(); + let mut seen = WindowSeen { slots: Vec::new(), hidden: false, bars: false, body_sees_bars: false }; + windows.frame(events, |ui| { + let mut body_sees_bars = false; + let out = AppShell::new(WindowKey::main()) + .screen_mode(Bind::bound(&mut *mode)) + .title_bar_if( + true, + |_| Some(0), + |ui, _, _: &mut ()| { + Text::new("Title").show(ui); + }, + ) + .options_bar( + true, + |_| Some(0), + |ui, _, _: &mut ()| { + Text::new("Options").show(ui); + }, + ) + .status( + true, + |_| Some(0), + |ui, _, _: &mut ()| { + Text::new("Status").show(ui); + }, + ) + .start( + Slot::new("tools").reveal(), + |_| Some(0), + |ui, _, _: &mut ()| { + Text::new("Tools").show(ui); + }, + ) + .body(|ui, cx, _| { + body_sees_bars = cx.shell().is_some_and(|shell| shell.chrome_hidden()); + let canvas = ui.scope_id().with("document"); + ui.interact(ui.max_rect(), canvas, Sense::click()); + host_canvas(ui.ctx(), canvas, KeyUse::CANVAS); + }) + .show(ui, &mut ()); + let state = chrome_state(&ctx, ViewportId::ROOT); + seen = WindowSeen { + slots: out.regions.slots.iter().map(|(key, _)| *key).collect(), + hidden: state.hidden, + bars: state.chrome_hidden, + body_sees_bars, + }; + }); + seen +} + +fn window_settled(windows: &mut Frames, mode: &mut ScreenMode) -> WindowSeen { + (0..3).map(|_| window_pass(windows, mode, vec![])).last().expect("three passes") +} + +fn window_tabbed(windows: &mut Frames, mode: &mut ScreenMode) -> WindowSeen { + let key = |pressed| Event::Key { key: Key::Tab, physical_key: None, pressed, repeat: false, modifiers: Modifiers::NONE }; + window_pass(windows, mode, vec![key(true)]); + window_pass(windows, mode, vec![key(false)]); + window_settled(windows, mode) +} + +#[trial] +fn tab_in_standard_hides_the_options_bar_and_rail_and_keeps_the_title_and_status() { + let mut windows = window(); + let mut mode = ScreenMode::Standard; + let settled = window_settled(&mut windows, &mut mode); + assert_eq!(settled.slots, ["title", "options", "status", "tools"], "the document window shows its bars and its rail"); + assert!(!settled.bars && !settled.body_sees_bars, "nothing is hidden"); + let seen = window_tabbed(&mut windows, &mut mode); + assert_eq!(seen.slots, ["title", "status"], "Tab hides the options bar and the rail and keeps the title bar and the status bar"); + assert!(!seen.hidden, "the window does not become body-only: its own chrome stays"); + assert!(seen.bars && seen.body_sees_bars, "the pass and its body read the chrome hiding, so a body with panels hides them too"); + command(&windows, ChromeToggle::Reveal(Some(RevealEdge::Top))); + assert_eq!( + window_settled(&mut windows, &mut mode).slots, + ["title", "options", "status"], + "an edge reveal shows the hidden bar over the body, as it does today" + ); + command(&windows, ChromeToggle::Reveal(None)); + let seen = window_tabbed(&mut windows, &mut mode); + assert_eq!(seen.slots, ["title", "options", "status", "tools"], "Tab again shows what it hid"); + assert!(!seen.hidden && !seen.bars && !seen.body_sees_bars, "and the window is a normal window again"); +} + +#[trial] +fn tab_in_full_screen_with_menu_bar_hides_every_slot_as_before() { + let mut windows = window(); + let mut mode = ScreenMode::FullScreenWithMenuBar; + assert_eq!(window_settled(&mut windows, &mut mode).slots, ["title", "options", "status", "tools"], "the mode keeps the bars and the rail"); + let seen = window_tabbed(&mut windows, &mut mode); + assert!(seen.slots.is_empty(), "Tab there hides every slot, the title bar included, as it does today"); + assert!(seen.hidden, "the window behaves as body-only"); + let seen = window_tabbed(&mut windows, &mut mode); + assert_eq!(seen.slots, ["title", "options", "status", "tools"], "Tab again shows them"); +} From eccdfcd5b510d8b8039b06b54e7c56dbe8f77a50 Mon Sep 17 00:00:00 2001 From: hnoerenberg Date: Sat, 28 Nov 2026 05:47:00 +0100 Subject: [PATCH 02/44] test(ui-shell): pin the neighbours of the standard-mode chrome hiding The standard-mode trial now also shows what Tab again restores (slot for slot, and the body's flag back to false), refuses Shift+Tab while the bars hide, as Shift+Tab is refused while the window is body-only, and lets ShowPanels end the chrome hiding too. --- crates/ui-shell/tests/it/shell/reveal.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/crates/ui-shell/tests/it/shell/reveal.rs b/crates/ui-shell/tests/it/shell/reveal.rs index 710310f52c..9dec0f5391 100644 --- a/crates/ui-shell/tests/it/shell/reveal.rs +++ b/crates/ui-shell/tests/it/shell/reveal.rs @@ -316,6 +316,10 @@ fn tab_in_standard_hides_the_options_bar_and_rail_and_keeps_the_title_and_status assert_eq!(seen.slots, ["title", "status"], "Tab hides the options bar and the rail and keeps the title bar and the status bar"); assert!(!seen.hidden, "the window does not become body-only: its own chrome stays"); assert!(seen.bars && seen.body_sees_bars, "the pass and its body read the chrome hiding, so a body with panels hides them too"); + let seen = window_tabbed(&mut windows, &mut mode); + assert_eq!(seen.slots, ["title", "options", "status", "tools"], "Tab again shows what it hid"); + assert!(!seen.hidden && !seen.bars && !seen.body_sees_bars, "and the window is a normal window again"); + window_tabbed(&mut windows, &mut mode); command(&windows, ChromeToggle::Reveal(Some(RevealEdge::Top))); assert_eq!( window_settled(&mut windows, &mut mode).slots, @@ -323,9 +327,15 @@ fn tab_in_standard_hides_the_options_bar_and_rail_and_keeps_the_title_and_status "an edge reveal shows the hidden bar over the body, as it does today" ); command(&windows, ChromeToggle::Reveal(None)); - let seen = window_tabbed(&mut windows, &mut mode); - assert_eq!(seen.slots, ["title", "options", "status", "tools"], "Tab again shows what it hid"); - assert!(!seen.hidden && !seen.bars && !seen.body_sees_bars, "and the window is a normal window again"); + window_settled(&mut windows, &mut mode); + command(&windows, ChromeToggle::PanelsKeepTools); + let seen = window_settled(&mut windows, &mut mode); + assert_eq!(seen.slots, ["title", "status"], "Shift+Tab refuses while the bars are hidden, as it does while the window is body-only"); + assert!(seen.bars && !seen.hidden, "and stays in the chrome hiding, not the window's own one"); + command(&windows, ChromeToggle::ShowPanels); + let seen = window_settled(&mut windows, &mut mode); + assert_eq!(seen.slots, ["title", "options", "status", "tools"], "ShowPanels ends the chrome hiding too"); + assert!(!seen.bars && !seen.hidden, "and no hiding is left"); } #[trial] From e8fe6cc35456c978ba0c60f72f16b3da10ceff94 Mon Sep 17 00:00:00 2001 From: David Mann Date: Sat, 28 Nov 2026 23:29:10 +0100 Subject: [PATCH 03/44] Layer Style: offer Stroke Emboss in the Bevel & Emboss Style menu The Style menu lacked Stroke Emboss, so a layer whose bevel uses it (from a PSD, or set through a command) showed a blank Style. The menu now lists the five styles in the reference application's order: Outer Bevel, Inner Bevel, Emboss, Pillow Emboss, Stroke Emboss. Inner Bevel stays the default. Reported in storytold/photocraft#13413. Co-Authored-By: TheGalitube Co-Authored-By: Claude Opus 5.5 --- crates/imaging/src/layer_style/spec.rs | 12 +++++++++--- crates/imaging/src/ui/layer_style/labels.rs | 2 ++ crates/imaging/tests/it/layer_style.rs | 19 +++++++++++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/crates/imaging/src/layer_style/spec.rs b/crates/imaging/src/layer_style/spec.rs index b5c4670222..b55f01b12d 100644 --- a/crates/imaging/src/layer_style/spec.rs +++ b/crates/imaging/src/layer_style/spec.rs @@ -141,8 +141,8 @@ impl EffectSpec { /// field that the drag on the image moves. /// - Pattern Overlay: blend; opacity; pattern Pattern; angle; scale Scale 1..1000 %; link Link /// with Layer. Defaults: Normal, 100, "", 0, 100, true. - /// - Bevel & Emboss: style Style (inner Inner Bevel, outer Outer Bevel, emboss Emboss, pillow - /// Pillow Emboss); technique Technique (smooth Smooth, chiselHard Chisel Hard, chiselSoft + /// - Bevel & Emboss: style Style (outer Outer Bevel, inner Inner Bevel, emboss Emboss, pillow + /// Pillow Emboss, stroke Stroke Emboss); technique Technique (smooth Smooth, chiselHard Chisel Hard, chiselSoft /// Chisel Soft); depth Depth 1..1000 %; direction Direction (up Up, down Down); size 0..250 /// px; soften Soften 0..16 px; angle; useGlobalLight; altitude Altitude 0..90 °; /// glossContour Gloss Contour (anti-alias `glossAntiAlias`); highlightBlend Highlight Mode; @@ -360,7 +360,13 @@ impl EffectSpec { field( "style", "Style", - choice(&[("inner", "Inner Bevel"), ("outer", "Outer Bevel"), ("emboss", "Emboss"), ("pillow", "Pillow Emboss")]), + choice(&[ + ("outer", "Outer Bevel"), + ("inner", "Inner Bevel"), + ("emboss", "Emboss"), + ("pillow", "Pillow Emboss"), + ("stroke", "Stroke Emboss"), + ]), ), field("technique", "Technique", choice(&[("smooth", "Smooth"), ("chiselHard", "Chisel Hard"), ("chiselSoft", "Chisel Soft")])), field("depth", "Depth", slider(1.0, 1000.0, Percent)), diff --git a/crates/imaging/src/ui/layer_style/labels.rs b/crates/imaging/src/ui/layer_style/labels.rs index ecb0cdc591..88fcfa5660 100644 --- a/crates/imaging/src/ui/layer_style/labels.rs +++ b/crates/imaging/src/ui/layer_style/labels.rs @@ -90,6 +90,7 @@ craft_ui::words! { outer_bevel: "layerStyle.choiceOuter" = "Outer Bevel"; emboss: "layerStyle.choiceEmboss" = "Emboss"; pillow_emboss: "layerStyle.choicePillow" = "Pillow Emboss"; + stroke_emboss: "layerStyle.choiceStrokeEmboss" = "Stroke Emboss"; smooth: "layerStyle.choiceSmooth" = "Smooth"; chisel_hard: "layerStyle.choiceChiselHard" = "Chisel Hard"; chisel_soft: "layerStyle.choiceChiselSoft" = "Chisel Soft"; @@ -202,6 +203,7 @@ impl LayerStyleWords { "outer" => &self.outer_bevel, "emboss" => &self.emboss, "pillow" => &self.pillow_emboss, + "stroke" => &self.stroke_emboss, "smooth" => &self.smooth, "chiselHard" => &self.chisel_hard, "chiselSoft" => &self.chisel_soft, diff --git a/crates/imaging/tests/it/layer_style.rs b/crates/imaging/tests/it/layer_style.rs index 2668b1e5ad..20f67f5f17 100644 --- a/crates/imaging/tests/it/layer_style.rs +++ b/crates/imaging/tests/it/layer_style.rs @@ -161,6 +161,25 @@ fn page_rig(kind: EffectKind, params: Option) -> (Fixture, Rc = choices.iter().map(|choice| choice.value.as_ref()).collect(); + assert_eq!(values, ["outer", "inner", "emboss", "pillow", "stroke"]); + assert_eq!(spec.defaults.get("style"), Some(&StyleValue::Text("inner".into())), "Inner Bevel stays the default"); + + let mut params = spec.defaults.clone(); + params.set("style", StyleValue::Text("stroke".into())); + let (fixture, _host) = page_rig(EffectKind::BevelEmboss, Some(params)); + let style = one(&fixture, Role::COMBO_BOX, "Style"); + assert_eq!(fixture.tree().value_of(style.node), Some("Stroke Emboss")); +} + /// A page shows the spec's defaults for keys the instance lacks without writing them; editing one field writes only /// that key. #[trial] From 9a8b74c428db249ceb5542623aaf605249773a6e Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 28 Nov 2026 18:29:45 -0800 Subject: [PATCH 04/44] automation: a held confirm waits for the dialog it confirmed when another dialog shares its ID ui.dialog.confirm confirms the first open dialog with the named ID, but its held reply recorded the newest opening of that ID. When a dialog of another type opened under the same ID after the confirm, the next poll_held answered "the dialog closed while its OK waited for the app's answer" while the confirmed dialog was still open and waiting. DialogHost::held_state_with_open_serial returns the opening serial and held state of the dialog confirm_by_id addresses. dialog_reply records that serial, and poll_held reads the state of that same opening. --- crates/automation/src/control.rs | 17 ++++----- crates/automation/src/dialogs.rs | 7 +++- crates/automation/tests/it/dialogs.rs | 54 ++++++++++++++++++++++++++- crates/ui-panels/src/dialog/host.rs | 10 ++++- 4 files changed, 74 insertions(+), 14 deletions(-) diff --git a/crates/automation/src/control.rs b/crates/automation/src/control.rs index 2290c7c08f..7d31b469be 100644 --- a/crates/automation/src/control.rs +++ b/crates/automation/src/control.rs @@ -141,8 +141,8 @@ pub enum Reply { AfterHeldOk { /// The dialog whose OK is held. dialog: DialogId, - /// Which open of the dialog ([`DialogHost::open_serial`]): a later open of the same dialog - /// is not the one the request confirmed. + /// Which open of the dialog the request confirmed ([`DialogHost::held_state_with_open_serial`]): + /// a later open of the same dialog, or another dialog with its ID, is not that one. open: u64, /// The app's refusal of the dialog's previous OK, when this confirm filed OK again after it: /// the earlier confirms still held for this open are answered with it. @@ -343,13 +343,12 @@ impl ControlChannel { /// dialog the app accepted; calling it more than once in a pass is harmless. pub fn poll_held(&mut self, host: &DialogHost) { self.held_waiters.retain(|(dialog, open, reply)| { - let answer = match host.held_state(*dialog) { - _ if host.open_serial(*dialog) != Some(*open) => { - json!({"ok": false, "error": "the dialog closed while its OK waited for the app's answer"}) - } - Some(HeldOk::Waiting) => return true, - Some(HeldOk::Accepted) => json!({"ok": true, "result": null}), - Some(HeldOk::Refused(reason)) => json!({"ok": false, "error": reason.as_str()}), + let current = host.held_state_with_open_serial(*dialog).filter(|(serial, _)| serial == open); + let answer = match current { + None => json!({"ok": false, "error": "the dialog closed while its OK waited for the app's answer"}), + Some((_, Some(HeldOk::Waiting))) => return true, + Some((_, Some(HeldOk::Accepted))) => json!({"ok": true, "result": null}), + Some((_, Some(HeldOk::Refused(reason)))) => json!({"ok": false, "error": reason.as_str()}), _ => json!({"ok": false, "error": "the app refused OK"}), }; let _ = reply.send(answer); diff --git a/crates/automation/src/dialogs.rs b/crates/automation/src/dialogs.rs index 749626cc61..7e8a544f88 100644 --- a/crates/automation/src/dialogs.rs +++ b/crates/automation/src/dialogs.rs @@ -65,8 +65,11 @@ pub fn dialog_reply(host: &mut DialogHost, ctx: &Context, method: &str, params: _ => None, }; let result = dialog_method(host, ctx, method, params)?; - let held = named.filter(|&id| method == "ui.dialog.confirm" && result.is_ok() && host.held_state(id) == Some(HeldOk::Waiting)); - Some(match held.and_then(|id| Some((id, host.open_serial(id)?))) { + let held = named.filter(|_| method == "ui.dialog.confirm" && result.is_ok()).and_then(|id| { + let (open, state) = host.held_state_with_open_serial(id)?; + matches!(state, Some(HeldOk::Waiting)).then_some((id, open)) + }); + Some(match held { Some((dialog, open)) => Reply::AfterHeldOk { dialog, open, refused }, None => Reply::from_result(result), }) diff --git a/crates/automation/tests/it/dialogs.rs b/crates/automation/tests/it/dialogs.rs index b15b926dcd..374d2b4446 100644 --- a/crates/automation/tests/it/dialogs.rs +++ b/crates/automation/tests/it/dialogs.rs @@ -5,11 +5,11 @@ use std::sync::mpsc::{Receiver, channel}; use craft_automation::control::{ControlChannel, ControlRequest, ControlResponse}; use craft_automation::dialogs::{MAX_DIALOG_FIELDS, dialog_method, dialog_reply, inspect}; use craft_ui::contract::{Bind, SaveKey}; -use craft_ui::dialog::{DialogHost, DialogId, DialogResult, PromptChoice, PromptKind, StandardPrompt}; +use craft_ui::dialog::{DialogHost, DialogId, DialogResult, DialogStack, PromptChoice, PromptKind, StackDialog, StandardPrompt}; use craft_ui::patterns::form_dialogs::{DialogFields, HostedParamDialog, Param, ParamDialog, ParamKind}; use craft_ui::runtime::env::{Label, Word}; use craft_ui::testing::trial; -use egui::Context; +use egui::{Context, Ui}; use serde_json::{Value, json}; fn call(host: &mut DialogHost, ctx: &Context, method: &str, params: Value) -> Result { @@ -130,6 +130,56 @@ fn param_dialog_automation_follows_its_rows() { const TAKEN: Word = Word::keyed("craft_automation.nameTaken", "A preset with that name exists"); +struct OtherDialog(DialogId); + +impl StackDialog for OtherDialog { + type Result = (); + + fn id(&self) -> DialogId { + self.0 + } + + fn show(&mut self, _: &mut Ui, _: &DialogStack) -> Option> { + None + } +} + +/// Another type open under the same stable ID, before or after the confirm, doesn't answer the confirm whose OK +/// is waiting. +#[trial] +fn a_new_dialog_with_the_same_id_does_not_answer_a_pending_confirm() { + let ctx = Context::default(); + for other_was_open in [false, true] { + let mut host = DialogHost::new(); + let (_requests, rx) = channel(); + let mut control = ControlChannel::new(rx); + let id = host.open( + HostedParamDialog::new(&ctx, "blur", DialogFields::new(), |fields| { + ParamDialog::new("blur", "Blur", Param::parse_list(r#"{"radius":0.1..1000=1}"#)).values(Bind::bound(fields)) + }) + .held_ok(), + ); + if other_was_open { + host.open(OtherDialog(id)); + } + let (request, reply) = ControlRequest::new("ui.dialog.confirm", json!({"dialog": id.value()})); + let outcome = dialog_reply(&mut host, &ctx, &request.method, &request.params).expect("the confirm command"); + control.settle(request, outcome, None, 0.0); + if !other_was_open { + host.open(OtherDialog(id)); + } + assert_eq!(host.open_dialogs().len(), 2); + control.poll_held(&host); + assert_eq!(control.waiting(), 1, "the dialog that got the confirm is still waiting for the app (other open first: {other_was_open})"); + assert_eq!(reply.try_recv(), Err(std::sync::mpsc::TryRecvError::Empty)); + + assert!(held(&mut host, id).take_ok().is_some()); + held(&mut host, id).answer_ok(Ok(())); + control.poll_held(&host); + assert_eq!(reply.try_recv(), Ok(json!({"ok": true, "result": null}))); + } +} + /// The open parameter dialog `id` names. fn held(host: &mut DialogHost, id: DialogId) -> &mut HostedParamDialog { host.get_dyn_mut(id).and_then(|dialog| dialog.downcast_mut::()).expect("the held dialog is open") diff --git a/crates/ui-panels/src/dialog/host.rs b/crates/ui-panels/src/dialog/host.rs index 83f921c054..0f237460f5 100644 --- a/crates/ui-panels/src/dialog/host.rs +++ b/crates/ui-panels/src/dialog/host.rs @@ -634,7 +634,15 @@ impl DialogHost { /// Where the held OK of the open dialog `id` names stands ([`StackDialog::held_state`]); `None` when no such dialog /// is open or its OK holds nothing now. pub fn held_state(&self, id: DialogId) -> Option { - self.open.iter().find(|dialog| dialog.id() == id)?.held_state() + self.held_state_with_open_serial(id)?.1 + } + + /// The opening serial and held OK state for the dialog [`confirm_by_id`](Self::confirm_by_id) addresses. + /// If dialogs share the ID, this follows that action's first match. The outer `None` means no such dialog is + /// open. An opening with no held OK has a serial and a `None` state. + pub fn held_state_with_open_serial(&self, id: DialogId) -> Option<(u64, Option)> { + let dialog = &self.open[self.position_by_id(id)?]; + Some((dialog.serial, dialog.held_state())) } /// The canvas of the most recently opened dialog that shows the document on one ([`StackDialog::canvas`]): where From c04b57ecbf63c293ee9e8dc76ec4cbb356e1604e Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 28 Nov 2026 19:05:16 -0800 Subject: [PATCH 05/44] pointer: a move to the position of the last move does not stir the pass The begin hook marked a pass as stirred for every PointerMoved event, so a canvas tool host re-hovered a still pointer, with a full hit test, on every pass that repeated the pointer's position. A move now stirs the pass only when it goes to a new position or carries a pen or touch reading. The last move's position is kept per viewport and cleared when the pointer leaves the window. --- crates/ui-canvas/tests/it/canvas/tool.rs | 25 ++++++++++++++++++++ crates/ui-contract/src/runtime/egui/input.rs | 3 +-- crates/ui-contract/src/runtime/pointer.rs | 24 +++++++++++++++---- 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/crates/ui-canvas/tests/it/canvas/tool.rs b/crates/ui-canvas/tests/it/canvas/tool.rs index 2074e70bbe..146d014ccc 100644 --- a/crates/ui-canvas/tests/it/canvas/tool.rs +++ b/crates/ui-canvas/tests/it/canvas/tool.rs @@ -1045,6 +1045,31 @@ fn a_pass_with_only_a_key_or_modifier_change_re_hovers_a_still_pointer_and_re_dr rig.fixture.frame(vec![pointer::release(at + BY)]); } +/// A pointer move to the position of the last move does not hover the still pointer again, in any number of passes. A +/// move somewhere else hovers once, and so does a move back in after the pointer left the window. +#[trial] +fn a_move_to_the_same_position_does_not_re_hover_a_still_pointer() { + let log = Log::default(); + let mut rig = Rig::with(Probe::new("main", &log), &log, None, Setup::default()); + let at = rig.centre(); + let count = |rig: &Rig| rig.calls().iter().filter(|logged| logged.as_str() == "main hover").count(); + + rig.fixture.frame(vec![pointer::moved(at)]).idle(2); + rig.log.borrow_mut().clear(); + for _ in 0..3 { + rig.fixture.frame(vec![pointer::moved(at)]); + } + rig.fixture.frame(vec![pointer::moved(at), pointer::moved(at)]); + assert_eq!(count(&rig), 0, "moves to the same position hover nothing: {:?}", rig.calls()); + + rig.fixture.frame(vec![pointer::moved(at + BY)]); + assert_eq!(count(&rig), 1, "a move somewhere else hovers once: {:?}", rig.calls()); + + rig.log.borrow_mut().clear(); + rig.fixture.frame(vec![pointer::gone()]).frame(vec![pointer::moved(at + BY)]); + assert_eq!(count(&rig), 1, "a move back in at the same position hovers once: {:?}", rig.calls()); +} + /// What the drag session of `DropperTool` carries. #[derive(Clone, Debug, PartialEq)] struct Parcel(u32); diff --git a/crates/ui-contract/src/runtime/egui/input.rs b/crates/ui-contract/src/runtime/egui/input.rs index 049701d614..cef544496b 100644 --- a/crates/ui-contract/src/runtime/egui/input.rs +++ b/crates/ui-contract/src/runtime/egui/input.rs @@ -338,7 +338,7 @@ pub(crate) struct PointerRead { pub sample: Option, /// The window lost focus in this pass. pub focus_lost: bool, - /// Whether the real pointer moved or entered, or a held modifier or key changed, in this pass. + /// Whether a held modifier or key changed in this pass. The begin hook adds the pass's moves to a new position. pub stirred: bool, /// The pass's finger events, in arrival order. pub touches: Vec, @@ -432,7 +432,6 @@ pub(crate) fn pointer_read(ctx: &Context) -> PointerRead { } } Event::PointerMoved(pos) => { - stirred = true; moves.push(events.len()); events.push(PointerEvent::moved(*pos, None)); } diff --git a/crates/ui-contract/src/runtime/pointer.rs b/crates/ui-contract/src/runtime/pointer.rs index 3c8c1be49a..e851d5ef49 100644 --- a/crates/ui-contract/src/runtime/pointer.rs +++ b/crates/ui-contract/src/runtime/pointer.rs @@ -102,7 +102,8 @@ pub struct PassPointer { pub primary_down: bool, pub press_targets: PressTargets, pub focus_lost: bool, - /// Whether the real pointer moved or entered, or a held modifier or key changed, in the pass. + /// Whether the real pointer moved to a new position or entered, a pen or touch reading arrived with a move, or a + /// held modifier or key changed, in the pass. pub stirred: bool, /// A finger landed in the pass while another was down: a press open now is a gesture's. pub gesture: bool, @@ -127,6 +128,8 @@ pub(crate) struct Memory { withheld: IdMap, /// The touch under way, for the multi-finger tap. taps: Taps, + /// Where the pointer's last move went, until the pointer leaves the window. + last_move: Option, } /// What one pass's finger events made of the touch. @@ -286,7 +289,20 @@ pub(crate) fn begin(ctx: &Context, hit: HitSizes, latched: craft_keymap::Mods) { let hits = input::hit_targets(ctx); let other_pressed = read.events.iter().any(|event| matches!(event, PointerEvent::Pressed { button: PointerButton::Middle | PointerButton::Secondary, .. })); - let (events, targets, touched) = PerViewport::::with(ctx, viewport, |memory| { + let (events, targets, touched, moved) = PerViewport::::with(ctx, viewport, |memory| { + // A move stirs the pass when it goes somewhere other than the last move, or carries a pen or touch reading. A + // move that repeats the pointer's position does not. + let mut moved = false; + for event in &read.events { + match event { + PointerEvent::Moved { at, sample, .. } => { + moved |= memory.last_move != Some(*at) || sample.is_some(); + memory.last_move = Some(*at); + } + PointerEvent::Gone => memory.last_move = None, + _ => {} + } + } let mut events = read.events.clone(); // Every button's press runs on the click run, as a click of any button did in the old apps: a middle-button pan // click between two clicks makes the second a triple click. Only a primary press carries its count. @@ -313,7 +329,7 @@ pub(crate) fn begin(ctx: &Context, hit: HitSizes, latched: craft_keymap::Mods) { if read.primary_pressed || other_pressed { memory.press_targets = PressTargets { click: hits.0, drag: hits.1 }; } - (events, memory.press_targets, memory.taps.feed(&read.touches, read.time)) + (events, memory.press_targets, memory.taps.feed(&read.touches, read.time), moved) }); // Where a modal holds the wheel off the canvas, a tap is not reported and a touch under way is dropped, by the // wheel's own rule. @@ -355,7 +371,7 @@ pub(crate) fn begin(ctx: &Context, hit: HitSizes, latched: craft_keymap::Mods) { primary_down: read.primary_down, press_targets: targets, focus_lost: read.focus_lost, - stirred: read.stirred, + stirred: read.stirred || moved, gesture: touched.landed, }; let hover_at = pass_pointer.hover; From 929dc7b794c2fae42f2b087eb615ef0701e58985 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 28 Nov 2026 19:26:49 -0800 Subject: [PATCH 06/44] ui-patterns: the path row test checks the Browse button against the column width The fixture's shown rect grows with whatever the row allocates, so a button that overflowed the column also widened it and the check passed. The room starts at x = 0, so the test now compares the button's right edge with the requested width. --- crates/ui-patterns/tests/it/form_dialogs/path_row.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/ui-patterns/tests/it/form_dialogs/path_row.rs b/crates/ui-patterns/tests/it/form_dialogs/path_row.rs index f0072f019b..cd05ebf265 100644 --- a/crates/ui-patterns/tests/it/form_dialogs/path_row.rs +++ b/crates/ui-patterns/tests/it/form_dialogs/path_row.rs @@ -20,13 +20,12 @@ fn row_in(width: f32) -> Fixture { fn browse_shows_its_whole_label_inside_a_narrow_column() { for width in [360.0, 260.0, 200.0] { let fixture = row_in(width); - let shown = fixture.shown(); let label = fixture.texts().iter().find(|run| run.text == "Browse…").cloned(); let label = label .unwrap_or_else(|| panic!("{width}: Browse… is painted: {:?}", fixture.texts().iter().map(|run| run.text.clone()).collect::>())); assert!(!label.elided, "{width}: the Browse label is not cut"); let button = fixture.by_label("Browse…").expect("the Browse button"); - assert!(button.rect.right() <= shown.right() + 0.5, "{width}: the button {:?} ends inside the column {shown:?}", button.rect); + assert!(button.rect.right() <= width + 0.5, "{width}: the button {:?} ends inside the column of width {width}", button.rect); assert!( label.rect.left() >= button.rect.left() - 0.5 && label.rect.right() <= button.rect.right() + 0.5, "{width}: the label {:?} lies inside the button {:?}", From e05914e768f09951a3b9f44223201130a031c7d8 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 28 Nov 2026 19:45:58 -0800 Subject: [PATCH 07/44] ui-contract: a field's help line keeps its last line above the widest label While a measuring run lays out a field group, a row only sees the label column that the rows before it reported. A check box row with its label after it, above the first row with a side label, saw no column. A row beside a label narrower than the widest saw a narrower column. Both measured their help line wider than the control column of the real run, so the footer was sized for fewer lines and the last line was cut off. The label step now notes the column such a row read when the row has a help line, so the group runs its rows again at the final widths. This covers a label after the control, a label beside it and a hidden side label. --- .../ui-contract/src/contract/label/place.rs | 23 +++- .../ui-patterns/tests/it/preferences/help.rs | 117 ++++++++++++++++++ .../ui-patterns/tests/it/preferences/mod.rs | 1 + .../ui-widgets/tests/it/layout/field_help.rs | 117 ++++++++++++++++++ crates/ui-widgets/tests/it/layout/mod.rs | 1 + 5 files changed, 256 insertions(+), 3 deletions(-) create mode 100644 crates/ui-patterns/tests/it/preferences/help.rs create mode 100644 crates/ui-widgets/tests/it/layout/field_help.rs diff --git a/crates/ui-contract/src/contract/label/place.rs b/crates/ui-contract/src/contract/label/place.rs index 20b6169e14..4ac95b8a73 100644 --- a/crates/ui-contract/src/contract/label/place.rs +++ b/crates/ui-contract/src/contract/label/place.rs @@ -60,10 +60,21 @@ pub(super) fn hidden_control(ctx: &egui::Context, input: &LabelIn<'_>, flow: Flo match crate::layout::ambient_width(ctx, &crate::layout::LABELS, 0.0).filter(|column| *column > 0.0) { Some(column) if input.room >= column + gap + input.control_min => { crate::layout::note_beside(ctx, &crate::layout::LABELS, input.room - gap - input.control_min); + // The help line under the control wraps in the control column, so its measure holds only at the column read. + if input.help.is_some() { + crate::layout::note_beside(ctx, &crate::layout::LABELS, column); + } let (_, rest) = flow.take_start(column); rest.take_start(gap).1.rect() } - _ => input.row, + Some(_) => input.row, + None => { + // No row has reported the column yet: the control takes the row only until one does. + if input.help.is_some() { + crate::layout::note_beside(ctx, &crate::layout::LABELS, 0.0); + } + input.row + } } } @@ -99,10 +110,12 @@ pub(super) fn decide(ctx: &egui::Context, env: &Env, input: &LabelIn<'_>, kids: let room = (input.row.width() - indent - input.control_min - gap).max(0.0); let wraps = natural.x > room; // A wider label column leaves the label less room: the row's measure holds while the group's column stays - // within the column it read, or for a label on one line, within the widest column that keeps it there. + // within the column it read, or for a label on one line, within the widest column that keeps it there. A help + // line under the control wraps in the control column, so with one the measure holds only at the column read. if let Some(column) = after_column { let one_line = input.row.width() - input.control_min - gap - natural.x - gap; - crate::layout::note_beside(ctx, &crate::layout::LABELS, if wraps { column } else { one_line }); + let holds = if wraps || input.help.is_some() { column } else { one_line }; + crate::layout::note_beside(ctx, &crate::layout::LABELS, holds); } if wraps { natural = leaf.measure_in(kids, craft_behavior::Proposal::Width(room)); @@ -153,6 +166,10 @@ pub(super) fn decide(ctx: &egui::Context, env: &Env, input: &LabelIn<'_>, kids: // A label that sits beside the group's column measured so far stacks once the column passes this. if read && !stacks && !pinned { crate::layout::note_beside(ctx, &key, input.room - gap - input.control_min); + // The help line under the control wraps in the control column, so its measure holds only at the column read. + if input.help.is_some() { + crate::layout::note_beside(ctx, &key, column); + } } // A stacked label has the row's width at most, where its name elides; in an egui grid's cell it keeps its own. let column = if stacks && !input.egui_cell { column.min(input.row.width()) } else { column }; diff --git a/crates/ui-patterns/tests/it/preferences/help.rs b/crates/ui-patterns/tests/it/preferences/help.rs new file mode 100644 index 0000000000..d9ab40e5e1 --- /dev/null +++ b/crates/ui-patterns/tests/it/preferences/help.rs @@ -0,0 +1,117 @@ +//! A row's help line in the preferences window shows every line it wraps to. The rows above the first side-labelled +//! row read no label column while the window measures them, then start in the control column: their help lines wrap +//! there, under a check box with its label after it and under a control beside a label narrower than the widest. + +use craft_ui::contract::Bind; +use craft_ui::patterns::preferences::{ + GroupSpec, PageSpec, PrefValue, PreferencesDraft, PreferencesModel, PreferencesState, PreferencesWindow, RowKind, RowSpec, +}; +use craft_ui::testing::{Fixture, trial}; +use egui::{Rect, Ui, vec2}; + +/// Half a pixel at the scales the box runs. +const ROUNDING: f32 = 0.5; + +const HELPS: [&str; 7] = [ + "On the desktop, a save to a file is written in the background while you keep editing; off, you wait until it is written.", + "On the desktop, exports to files and packages are written in the background while you keep editing, except 3D exports; off, you wait for them.", + "Every few minutes, keeps a recovery copy of each document with unsaved changes made since its last copy; off, no timed copies are made.", + "On the desktop, the folder recovery copies are kept in; leave it blank for the app's own folder. The web version keeps them in the browser.", + "Open Recent Files and the Home screen list at most this many recent files; 0 lists none, and the app still remembers up to 30.", + "When a document opens, a linked EPS image that shows its saved preview keeps it instead of reading the EPS file again; changed files still follow Update Links.", + "In Pixel Preview, images are drawn smoothed; off, their pixels show with hard edges. Outside Pixel Preview, images are always smoothed.", +]; + +struct Model; + +impl PreferencesModel for Model { + fn pages(&self) -> Vec> { + let mut page = PageSpec::new("files", "File Handling", Vec::new()); + page.groups = vec![ + GroupSpec::new( + Some("File Handling"), + vec![ + RowSpec::new("save", "Enable Background Save", RowKind::Bool(true)).help(HELPS[0]), + RowSpec::new("export", "Enable Background Export", RowKind::Bool(true)).help(HELPS[1]), + ], + ), + GroupSpec::new( + Some("Data Recovery"), + vec![ + RowSpec::new("recovery", "Automatically Save Recovery Data", RowKind::Bool(true)).help(HELPS[2]), + RowSpec::new("folder", "Folder", RowKind::Text("")).help(HELPS[3]), + RowSpec::new("recent", "Number of Recent Files to Display", RowKind::Text("20")).help(HELPS[4]), + RowSpec::new("proxy", "Use Low Resolution Proxy for Linked EPS", RowKind::Bool(false)).help(HELPS[5]), + RowSpec::new("bitmaps", "Display Bitmaps as Anti-aliased Images in Pixel Preview", RowKind::Bool(false)).help(HELPS[6]), + ], + ), + ]; + vec![PageSpec::new("general", "General", vec![RowSpec::new("general.snap", "Snap to grid", RowKind::Bool(false))]), page] + } + fn set(&mut self, _: &str, _: PrefValue) {} + fn custom_row(&mut self, _: &mut Ui, _: &str) -> bool { + false + } + fn custom_page(&mut self, _: &mut Ui, _: &str) -> bool { + false + } + fn reset_page(&mut self, _: &str) {} +} + +impl PreferencesDraft for Model { + fn differs(&self) -> bool { + false + } + fn apply(&mut self) -> Result<(), String> { + Ok(()) + } + fn cancel(&mut self) {} +} + +/// A help line the window painted with part of it outside the clip it paints under. +#[derive(Debug)] +#[allow(dead_code, reason = "read through the failure message")] +struct Cut { + help: String, + rows: usize, + rect: Rect, + clip: Rect, +} + +/// The File Handling page in a window `width` wide at `ppp` pixels per point: every help line it painted, and the ones +/// cut off. +fn painted(ppp: f32, width: f32) -> (usize, Vec) { + let mut state = PreferencesState::default(); + state.selected = "files".to_owned(); + let mut fixture = Fixture::new(move |ui| { + let _ = PreferencesWindow::new(Bind::bound(&mut state)).size(vec2(width, 760.0)).show(ui, &mut Model); + }); + fixture.pixels_per_point(ppp).room(vec2(1200.0, 900.0)).settle(); + let mut seen = 0; + let mut cut = Vec::new(); + for (clip, shape) in fixture.frame_clipped_shapes() { + let egui::Shape::Text(text) = shape else { continue }; + if !HELPS.contains(&text.galley.text()) { + continue; + } + seen += 1; + let rect = text.galley.rect.translate(text.pos.to_vec2()); + if rect.max.y > clip.max.y + ROUNDING || rect.max.x > clip.max.x + ROUNDING { + cut.push(Cut { help: text.galley.text().to_owned(), rows: text.galley.rows.len(), rect, clip }); + } + } + (seen, cut) +} + +/// At 900 and 960 points the second and third help lines wrap to two lines in the control column and fit on one at +/// the width the rows had before the column was known. +#[trial] +fn every_line_of_a_rows_help_shows() { + for ppp in [1.0, 2.0] { + for width in [900.0, 960.0, 1036.0] { + let (seen, cut) = painted(ppp, width); + assert_eq!(seen, HELPS.len(), "every help line painted at {width} points, {ppp} pixels per point"); + assert!(cut.is_empty(), "help lines cut off at {width} points, {ppp} pixels per point: {cut:#?}"); + } + } +} diff --git a/crates/ui-patterns/tests/it/preferences/mod.rs b/crates/ui-patterns/tests/it/preferences/mod.rs index cdc7de985e..a3f1735691 100644 --- a/crates/ui-patterns/tests/it/preferences/mod.rs +++ b/crates/ui-patterns/tests/it/preferences/mod.rs @@ -2,6 +2,7 @@ //! window's answers and the hex codec. pub(crate) mod classic; +pub(crate) mod help; pub(crate) mod live; pub(crate) mod model; pub(crate) mod page; diff --git a/crates/ui-widgets/tests/it/layout/field_help.rs b/crates/ui-widgets/tests/it/layout/field_help.rs new file mode 100644 index 0000000000..85bbff81f4 --- /dev/null +++ b/crates/ui-widgets/tests/it/layout/field_help.rs @@ -0,0 +1,117 @@ +//! A field's help line wraps in the control column it is drawn in, and the field is tall enough for every line it +//! wraps to. In a field group the rows above the widest label read a narrower label column while the group measures +//! them: a check box row with its label after it, and a row beside a shorter label, still show their whole help. + +use craft_ui::buttons::Button; +use craft_ui::choice::Checkbox; +use craft_ui::contract::{Bind, FieldLayout, LabelKind, Props as _, Show as _, ShowContainer as _, SideLabel}; +use craft_ui::form::{Field, FieldGroup, Help}; +use craft_ui::layout_components::Stack; +use craft_ui::runtime::env::Label; +use craft_ui::testing::{Fixture, trial}; +use egui::{Rect, Vec2}; + +/// Half a pixel at the scales the box runs. +const ROUNDING: f32 = 0.5; + +const WORDS: &str = "On the desktop, exports to files and packages are written in the background while you keep editing, \ + except 3D exports; off, you wait for every one of them to finish before you can edit again."; + +/// Help lines of every length from a short phrase to the whole of `WORDS`, cut at word ends. +fn helps() -> Vec { + WORDS.char_indices().filter(|(_, c)| *c == ' ').map(|(at, _)| WORDS[..at].to_owned()).filter(|help| help.len() > 40).collect() +} + +/// A help line painted with part of it outside the clip it paints under. +#[derive(Debug)] +#[allow(dead_code, reason = "read through the failure message")] +struct Cut { + help: String, + rows: usize, + rect: Rect, + clip: Rect, +} + +/// How the rows with help lines are labelled. +#[derive(Clone, Copy)] +struct Rows { + layout: FieldLayout, + /// The rows' labels are hidden. + hidden: bool, + /// A row with a short visible side label comes first, so the rows read a column narrower than the widest. + lead: bool, +} + +/// A field group whose rows, labelled as `rows` says, each show one of `helps()` above a last row with a long side +/// label: how many help lines it painted, how many wrapped, and the ones cut off. +fn cut_helps(rows: Rows) -> (usize, usize, Vec) { + let Rows { layout, hidden, lead } = rows; + let helps = helps(); + let shown = helps.clone(); + let mut fixture = Fixture::new(move |ui| { + FieldGroup::new("Export").show(ui, |ui, _| { + Stack::new().show(ui, |ui, _| { + if lead { + Field::new("Short").show(ui, |ui, _| { + Button::new("First").show(ui); + }); + } + for (at, help) in shown.iter().enumerate() { + let field = Field::new("Row").id_salt(at).help(Help::Text(Label::from(help.clone()))).layout(layout); + let field = if hidden { field.side(SideLabel::new().layout(layout).kind(LabelKind::Hidden)) } else { field }; + field.show(ui, |ui, _| { + if layout == FieldLayout::After { + Checkbox::new(Bind::given(true)).show(ui); + } else { + Button::new("Choose").show(ui); + } + }); + } + Field::new("The longest label of the group").show(ui, |ui, _| { + Button::new("Last").show(ui); + }); + }); + }); + }); + fixture.room(Vec2::new(720.0, 4000.0)).settle(); + let (mut seen, mut wrapped, mut cut) = (0, 0, Vec::new()); + for (clip, shape) in fixture.frame_clipped_shapes() { + let egui::Shape::Text(text) = shape else { continue }; + if !helps.iter().any(|help| help == text.galley.text()) { + continue; + } + seen += 1; + wrapped += usize::from(text.galley.rows.len() > 1); + let rect = text.galley.rect.translate(text.pos.to_vec2()); + if rect.max.y > clip.max.y + ROUNDING || rect.max.x > clip.max.x + ROUNDING { + cut.push(Cut { help: text.galley.text().to_owned(), rows: text.galley.rows.len(), rect, clip }); + } + } + (seen, wrapped, cut) +} + +fn assert_whole(rows: Rows) { + let (seen, wrapped, cut) = cut_helps(rows); + assert_eq!(seen, helps().len(), "every help line painted"); + assert!(wrapped > 0, "some help lines wrap in this room"); + assert!(cut.is_empty(), "help lines cut off: {cut:#?}"); +} + +#[trial] +fn a_help_line_after_a_check_box_above_the_widest_label_shows_every_line() { + assert_whole(Rows { layout: FieldLayout::After, hidden: false, lead: false }); + assert_whole(Rows { layout: FieldLayout::After, hidden: false, lead: true }); +} + +#[trial] +fn a_help_line_beside_a_shorter_label_than_the_widest_shows_every_line() { + assert_whole(Rows { layout: FieldLayout::Beside, hidden: false, lead: false }); +} + +/// A hidden side label still takes the column, so the control and its help start in the control column: before any +/// row reported the column, and past a column narrower than the widest. +#[trial] +fn a_help_line_beside_a_hidden_label_above_the_widest_label_shows_every_line() { + assert_whole(Rows { layout: FieldLayout::Beside, hidden: true, lead: false }); + assert_whole(Rows { layout: FieldLayout::Beside, hidden: true, lead: true }); +} diff --git a/crates/ui-widgets/tests/it/layout/mod.rs b/crates/ui-widgets/tests/it/layout/mod.rs index f2021638c3..20d2ff2317 100644 --- a/crates/ui-widgets/tests/it/layout/mod.rs +++ b/crates/ui-widgets/tests/it/layout/mod.rs @@ -1,5 +1,6 @@ pub(crate) mod app_measure; pub(crate) mod cross_fill; +pub(crate) mod field_help; pub(crate) mod fill_column; pub(crate) mod fill_height; pub(crate) mod fill_share; From e7d4d7e3e51ed7e6d231295fcc4e9139bfda0865 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 28 Nov 2026 19:46:38 -0800 Subject: [PATCH 08/44] form_dialogs: a Range row with Param::length shows its value in the shown unit Only Number rows read Param::length, so a Range row over points showed points in an inch or millimeter document. - SliderField::lengths makes its number field a length field: it shows and reads the value in the shown unit at that unit's step and decimals, while the binding, the range and the slider stay in the stored unit. - Range rows pass Param::length to their SliderField. A popup-slider range row builds a length field too, and a set step, which is in the stored unit, steps the field by the same length in the shown unit. --- .../src/patterns/form_dialogs/param.rs | 5 +-- .../src/patterns/form_dialogs/rows.rs | 31 ++++++++++++----- .../tests/it/form_dialogs/params.rs | 33 +++++++++++++++++++ crates/ui-widgets/src/form/slider_field.rs | 22 +++++++++++-- 4 files changed, 79 insertions(+), 12 deletions(-) diff --git a/crates/ui-patterns/src/patterns/form_dialogs/param.rs b/crates/ui-patterns/src/patterns/form_dialogs/param.rs index 2081ba1515..b337e630f4 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/param.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/param.rs @@ -634,7 +634,7 @@ pub(crate) struct RowOptions { resettable: bool, /// The label a footer row shows while on ([`Param::in_footer`]). footer_on: Option