diff --git a/crates/ui-shell/src/shell/screen_mode.rs b/crates/ui-shell/src/shell/screen_mode.rs index b63cbf725..5fb3defe7 100644 --- a/crates/ui-shell/src/shell/screen_mode.rs +++ b/crates/ui-shell/src/shell/screen_mode.rs @@ -122,7 +122,8 @@ pub(super) struct ScreenModeFollow { impl ScreenModeFollow { /// Reads the mode from `bind` and applies this pass's screen-mode commands. With `os`, follows the OS window and /// brings it to the mode; an embedded shell passes false and its mode only changes what its own region shows. - /// Writes the mode back under `name` when it changed. Returns the mode and whether it changed. + /// Writes the mode back under `name` when this pass changed it. Returns the mode and whether it differs from the mode + /// the last pass applied, whoever wrote it. pub(super) fn follow( &mut self, ctx: &Context, @@ -135,6 +136,7 @@ impl ScreenModeFollow { Some(Mixed::Same(held)) => held, _ => ScreenMode::default(), }; + let last = self.applied; let mut mode = before; while let Some((command, _)) = cx.take_command::() { mode = command.apply(mode); @@ -147,7 +149,7 @@ impl ScreenModeFollow { let event = EditEvent::set(Mixed::Same(before), mode, name, None); let _ = bind.write(cx, &event); } - (mode, mode != before) + (mode, mode != last) } /// Follows the OS window out of full screen and sends the actions that bring it to `mode`. Returns the mode the diff --git a/crates/ui-shell/tests/it/shell/reveal.rs b/crates/ui-shell/tests/it/shell/reveal.rs index 89601dde3..18a383451 100644 --- a/crates/ui-shell/tests/it/shell/reveal.rs +++ b/crates/ui-shell/tests/it/shell/reveal.rs @@ -2,17 +2,26 @@ use craft_ui::contract::{Bind, Show as _}; use craft_ui::display::Text; -use craft_ui::runtime::env::WindowKey; +use craft_ui::runtime::env::{RootEnv, WindowKey}; +use craft_ui::runtime::focus::{KeyUse, host_canvas}; use craft_ui::shell::{AppShell, ScreenMode}; -use craft_ui::testing::trial; -use craft_ui_test_kit::windows::Windows; -use egui::{Event, Key, Modifiers}; +use craft_ui::testing::{Frames, trial}; +use egui::{Event, Key, Modifiers, Sense}; -/// One frame of a shell with a tool rail, and an options bar its own flag hides. Returns how many slots show and -/// whether a reveal shows them. -fn shown(windows: &Windows, mode: &mut ScreenMode, events: Vec) -> (usize, bool) { +/// A window whose root lets a bare Tab toggle the chrome, as an app with a document canvas sets it. +fn window() -> Frames { + let mut frames = Frames::new(); + let mut root = RootEnv::default(); + root.tab_toggles_chrome = true; + frames.root(root); + frames +} + +/// One frame of a shell with a tool rail, an options bar its own flag hides and a document canvas in the body, with +/// nothing focused, so Tab reaches the shell. Returns how many slots show and whether a reveal shows them. +fn shown(windows: &mut Frames, mode: &mut ScreenMode, events: Vec) -> (usize, bool) { let mut result = (0, false); - windows.frame(events, vec![], |ui| { + windows.frame(events, |ui| { let out = AppShell::new(WindowKey::main()) .screen_mode(Bind::bound(&mut *mode)) .tools(true, |ui, _, _: &mut ()| { @@ -22,7 +31,9 @@ fn shown(windows: &Windows, mode: &mut ScreenMode, events: Vec) -> (usize Text::new("Options").show(ui); }) .body(|ui, _, _| { - Text::new("Document").show(ui); + 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 ()); result = (out.regions.slots.len(), out.revealed); @@ -30,7 +41,7 @@ fn shown(windows: &Windows, mode: &mut ScreenMode, events: Vec) -> (usize result } -fn settle(windows: &Windows, mode: &mut ScreenMode) -> (usize, bool) { +fn settle(windows: &mut Frames, mode: &mut ScreenMode) -> (usize, bool) { let mut last = (0, false); for _ in 0..3 { last = shown(windows, mode, vec![]); @@ -38,7 +49,7 @@ fn settle(windows: &Windows, mode: &mut ScreenMode) -> (usize, bool) { last } -fn tab(windows: &Windows, mode: &mut ScreenMode) -> (usize, bool) { +fn tab(windows: &mut Frames, mode: &mut ScreenMode) -> (usize, bool) { let key = |pressed| Event::Key { key: Key::Tab, physical_key: None, pressed, repeat: false, modifiers: Modifiers::NONE }; shown(windows, mode, vec![key(true)]); shown(windows, mode, vec![key(false)]); @@ -47,23 +58,27 @@ fn tab(windows: &Windows, mode: &mut ScreenMode) -> (usize, bool) { #[trial] fn tab_hides_and_shows_the_chrome_and_a_screen_mode_change_clears_it() { - let windows = Windows::new(); + let mut windows = window(); let mut mode = ScreenMode::Standard; - assert_eq!(settle(&windows, &mut mode), (1, false), "the rail shows; the options bar stays hidden by its flag"); - assert_eq!(tab(&windows, &mut mode).0, 0, "Tab hides the chrome"); - assert_eq!(tab(&windows, &mut mode).0, 1, "Tab shows it again, and the slot hidden by its flag stays hidden"); + assert_eq!(settle(&mut windows, &mut mode), (1, false), "the rail shows; the options bar stays hidden by its flag"); + assert_eq!(tab(&mut windows, &mut mode).0, 0, "Tab hides the chrome"); + assert_eq!(tab(&mut windows, &mut mode).0, 1, "Tab shows it again, and the slot hidden by its flag stays hidden"); mode = ScreenMode::FullScreen; - assert_eq!(settle(&windows, &mut mode), (0, false), "full screen shows the body only"); - assert_eq!(tab(&windows, &mut mode), (1, true), "Tab reveals the rail in body-only mode"); + assert_eq!(settle(&mut windows, &mut mode), (0, false), "full screen shows the body only"); + assert_eq!( + tab(&mut windows, &mut mode), + (2, true), + "Tab in body-only mode reveals every slot that reveals, the options bar its flag hides in normal mode included" + ); assert_eq!(mode, ScreenMode::FullScreen, "the reveal leaves the screen mode as it is"); - assert_eq!(tab(&windows, &mut mode), (0, false), "Tab ends the reveal"); + assert_eq!(tab(&mut windows, &mut mode), (0, false), "Tab ends the reveal"); - tab(&windows, &mut mode); + tab(&mut windows, &mut mode); mode = ScreenMode::Standard; - assert_eq!(settle(&windows, &mut mode), (1, false), "a screen-mode change ends a reveal"); + assert_eq!(settle(&mut windows, &mut mode), (1, false), "a screen-mode change ends a reveal"); - assert_eq!(tab(&windows, &mut mode).0, 0, "Tab hides the chrome"); + assert_eq!(tab(&mut windows, &mut mode).0, 0, "Tab hides the chrome"); mode = ScreenMode::FullScreenWithMenuBar; - assert_eq!(settle(&windows, &mut mode).0, 1, "a screen-mode change clears the user's hiding"); + assert_eq!(settle(&mut windows, &mut mode).0, 1, "a screen-mode change clears the user's hiding"); }