mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 02:09:00 +00:00
Palette windows follow the app's modal and minimized state
A palette window stands as an ordinary window while an app-modal layer in another window blocks it, and the modal's window is raised above it once, by toggling its level (egui-winit ignores Focus for a focused window, and on Windows a palette made non-topmost stands in front of the main window otherwise). The palette goes back above the app's windows when the modal closes (#15525). A palette window is hidden while the main window is minimized and shown again when it is restored, on Windows and Linux; on macOS the app stays active with its main window minimized, and palettes stay (#15860). One function, WindowLevel::standing, decides a window's level and visibility from the app's state (focus, app-modal window, minimized main window), which follow_activity records once per frame. The raise is WindowAction::Raise. Supersedes craft-libs#2267, whose design and trial this takes over. Co-authored-by: Jere Salonen <hi@jere.co>
This commit is contained in:
@@ -74,9 +74,9 @@ pub(crate) fn show_immediate<T>(ctx: &Context, id: ViewportId, spec: &Spec<'_>,
|
||||
ctx.show_viewport_immediate(id, builder, |ui, _| body(ui))
|
||||
}
|
||||
|
||||
/// Makes the hidden viewport `id` visible.
|
||||
pub(crate) fn show(ctx: &Context, id: ViewportId) {
|
||||
ctx.send_viewport_cmd_to(id, egui::ViewportCommand::Visible(true));
|
||||
/// Shows or hides the window of viewport `id`.
|
||||
pub(crate) fn set_visible(ctx: &Context, id: ViewportId, visible: bool) {
|
||||
ctx.send_viewport_cmd_to(id, egui::ViewportCommand::Visible(visible));
|
||||
}
|
||||
|
||||
/// The viewport id of the container `id`.
|
||||
@@ -168,6 +168,16 @@ pub(crate) fn raise(ctx: &Context, viewport: ViewportId) {
|
||||
ctx.request_repaint_of(viewport);
|
||||
}
|
||||
|
||||
/// Brings `viewport`'s window in front of the app's other windows without giving it focus, by standing it above every
|
||||
/// window and then back at `level`, its own level. egui-winit ignores `Focus` for a window that has focus, and the
|
||||
/// window holding a modal usually has it; on Windows the level change also puts the window in front of the ordinary
|
||||
/// windows that were made ordinary before it. A Wayland compositor gives clients no stacking control.
|
||||
pub(crate) fn raise_above(ctx: &Context, viewport: ViewportId, level: WindowLevel) {
|
||||
command(ctx, viewport, ViewportCommand::WindowLevel(WindowLevel::AlwaysOnTop));
|
||||
command(ctx, viewport, ViewportCommand::WindowLevel(level));
|
||||
ctx.request_repaint_of(viewport);
|
||||
}
|
||||
|
||||
/// Cancels an OS close request of the running viewport so the owner can decide.
|
||||
pub(crate) fn cancel_close(ctx: &Context) {
|
||||
ctx.send_viewport_cmd(ViewportCommand::CancelClose);
|
||||
|
||||
@@ -810,7 +810,7 @@ pub(crate) fn end_pass(ctx: &Context) {
|
||||
}
|
||||
|
||||
fn modal_in_other_viewports(ctx: &Context, running: ViewportId) -> bool {
|
||||
pass::live_viewports(ctx).into_iter().filter(|viewport| *viewport != running).any(|viewport| with_persist(ctx, viewport, |persist| persist.modal))
|
||||
modal_viewport(ctx, running).is_some()
|
||||
}
|
||||
|
||||
/// Whether a modal layer is open in a viewport other than `viewport`: the global open-modal fact the input hook
|
||||
@@ -886,9 +886,19 @@ pub(crate) fn beneath(ctx: &Context, layer: Id) -> (bool, Option<Id>) {
|
||||
(root.is_some() || modal_in_other_viewports(ctx, viewport), root)
|
||||
}
|
||||
|
||||
/// The live viewports with a modal layer open as of their last finished pass.
|
||||
fn modal_viewports(ctx: &Context) -> impl Iterator<Item = ViewportId> + '_ {
|
||||
pass::live_viewports(ctx).into_iter().filter(|viewport| with_persist(ctx, *viewport, |persist| persist.modal))
|
||||
}
|
||||
|
||||
/// A viewport other than `viewport` that has a modal layer open: the window a blocked press raises.
|
||||
pub(crate) fn modal_viewport(ctx: &Context, viewport: ViewportId) -> Option<ViewportId> {
|
||||
pass::live_viewports(ctx).into_iter().filter(|other| *other != viewport).find(|other| with_persist(ctx, *other, |persist| persist.modal))
|
||||
modal_viewports(ctx).find(|other| *other != viewport)
|
||||
}
|
||||
|
||||
/// A viewport that has a modal layer open: the window that blocks the app's other windows.
|
||||
pub(crate) fn app_modal_viewport(ctx: &Context) -> Option<ViewportId> {
|
||||
modal_viewports(ctx).next()
|
||||
}
|
||||
|
||||
/// Whether a layer of key class `class` that is not fading out was shown last frame and the screen point `at` lies in
|
||||
|
||||
@@ -48,7 +48,7 @@ pub use shell::shell_of;
|
||||
use shell::{refresh, window_info};
|
||||
#[cfg(feature = "testing")]
|
||||
pub(crate) use shell::{set_chrome, set_os};
|
||||
use spec::chrome_of;
|
||||
use spec::{AppState, chrome_of};
|
||||
pub use spec::{WindowLevel, WindowSpec};
|
||||
pub(crate) use viewport::{ViewportOpen, show_viewport, take_close_request, unplaced};
|
||||
|
||||
@@ -86,8 +86,12 @@ pub(crate) struct Shared {
|
||||
desktop: Option<Desktop>,
|
||||
/// Whether the root window had focus in the last root pass.
|
||||
root_focused: bool,
|
||||
/// Whether no window of the app had focus when the last frame's windows had all reported.
|
||||
away: bool,
|
||||
/// The app's state when the last frame's windows had all reported, which its palettes follow.
|
||||
app: AppState,
|
||||
/// Whether a palette window stood lowered under an app-modal layer in this frame.
|
||||
lowered: bool,
|
||||
/// Where the raise of the modal's window above the palettes it lowered stands.
|
||||
raise: Raise,
|
||||
/// The app's windows from the one focused longest ago to the one focused last: the stacking order of
|
||||
/// overlapping windows.
|
||||
stacking: Vec<ViewportId>,
|
||||
@@ -105,8 +109,10 @@ pub(crate) struct Record {
|
||||
chrome: Option<WindowChrome>,
|
||||
/// The caption buttons the app draws in this window.
|
||||
captions: Option<Captions>,
|
||||
/// The level the window was opened with or last set to; a palette's egui level follows the app's activity.
|
||||
/// The level the window was opened with or last set to; a palette's egui level follows the app's state.
|
||||
level: Option<WindowLevel>,
|
||||
/// Whether the window is hidden because the app's state hides it (a palette while the main window is minimized).
|
||||
hidden: bool,
|
||||
/// H4: whether the primary button is down as the viewport's events left the input hook.
|
||||
primary_down: bool,
|
||||
/// Whether the user can resize the window; unknown for a window not opened by `show_viewport`.
|
||||
@@ -148,6 +154,20 @@ pub(crate) struct Record {
|
||||
min_size: Option<Vec2>,
|
||||
}
|
||||
|
||||
/// The raise of the window holding an app-modal layer above the palettes the modal lowered. The raise goes out in the
|
||||
/// frame after a palette was built lowered: a raise in the same frame may reach the OS before the palette's new level
|
||||
/// does, and the palette, made an ordinary window after it, would stand in front again.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
enum Raise {
|
||||
/// No palette has stood lowered under the open modal yet, or no modal is open.
|
||||
#[default]
|
||||
Waiting,
|
||||
/// A palette stood lowered in the last frame: the modal's window is raised in this one.
|
||||
Due,
|
||||
/// The modal's window was raised.
|
||||
Done,
|
||||
}
|
||||
|
||||
/// Passes between searches for an OS window that was not found.
|
||||
const SEARCH_EVERY: u64 = 20;
|
||||
|
||||
@@ -465,12 +485,14 @@ fn flush_store(ctx: &Context) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Keeps the app's activity and the stacking order of its windows current from the windows' focus. A palette's
|
||||
/// window level follows the activity: the mounts build their viewports with the level of the moment, and a change
|
||||
/// Keeps the app's state and the stacking order of its windows current from the windows' facts. A palette's window
|
||||
/// level and visibility follow the state: the mounts build their viewports with the state of the moment, and a change
|
||||
/// asks for the next frame. Runs at the end of the root pass, inside which every child window's pass of the frame
|
||||
/// has run, so each window's focus is the one its own pass reported after its input batch. The root input's list of
|
||||
/// windows holds each child as of its previous pass, so it is not read for focus. The app is inactive when no
|
||||
/// window reports focus: the batch that took focus from one window gave it to no other.
|
||||
///
|
||||
/// Once a palette has stood lowered under an app-modal layer, the modal's window is raised above it, once per modal.
|
||||
fn follow_activity(ctx: &Context) {
|
||||
let windows = viewports::reported(ctx);
|
||||
let focused: Vec<ViewportId> = windows
|
||||
@@ -478,13 +500,27 @@ fn follow_activity(ctx: &Context) {
|
||||
.map(|(viewport, _)| *viewport)
|
||||
.filter(|viewport| PerViewport::<Record>::with(ctx, *viewport, |record| record.facts.is_some_and(|facts| facts.focused)))
|
||||
.collect();
|
||||
let changed = shared(ctx, |shared| {
|
||||
let modal = overlay::app_modal_viewport(ctx);
|
||||
let minimized = viewports::current(ctx).minimized;
|
||||
let (repaint, raise) = shared(ctx, |shared| {
|
||||
shared.stacking.retain(|viewport| windows.iter().any(|(open, _)| open == viewport) && !focused.contains(viewport));
|
||||
shared.stacking.extend(&focused);
|
||||
let away = focused.is_empty();
|
||||
std::mem::replace(&mut shared.away, away) != away
|
||||
let app = AppState { away: focused.is_empty(), modal, minimized };
|
||||
let lowered = std::mem::take(&mut shared.lowered);
|
||||
let (step, raise) = match shared.raise {
|
||||
_ if app.modal != shared.app.modal => (Raise::Waiting, None),
|
||||
Raise::Waiting if lowered => (Raise::Due, None),
|
||||
Raise::Due => (Raise::Done, app.modal),
|
||||
step => (step, None),
|
||||
};
|
||||
shared.raise = step;
|
||||
let changed = std::mem::replace(&mut shared.app, app) != app;
|
||||
(changed || step == Raise::Due, raise)
|
||||
});
|
||||
if changed {
|
||||
if let Some(modal) = raise {
|
||||
act(ctx, modal, WindowAction::Raise);
|
||||
}
|
||||
if repaint {
|
||||
ctx.request_repaint();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use super::host::scale_of;
|
||||
#[cfg(doc)]
|
||||
use super::logic;
|
||||
use super::shell::{base_shell, os_of, window_info};
|
||||
use super::spec::WindowLevel;
|
||||
use super::spec::{Standing, WindowLevel};
|
||||
use super::{HandOff, Record, SEARCH_EVERY, shared};
|
||||
use crate::runtime::egui::{pass, viewports};
|
||||
use crate::runtime::frame::{PerViewport, Stored};
|
||||
@@ -40,6 +40,9 @@ pub enum WindowAction {
|
||||
SetMaximized(bool),
|
||||
/// Raises the window and gives it OS focus.
|
||||
Focus,
|
||||
/// Brings the window in front of the app's other windows without giving it focus, as the window holding an
|
||||
/// app-modal layer comes in front of the palettes the modal lowered.
|
||||
Raise,
|
||||
/// The OS starts moving the window with the pointer.
|
||||
StartMove,
|
||||
/// The OS starts resizing the window from `edge`.
|
||||
@@ -100,7 +103,8 @@ pub fn act(ctx: &Context, viewport: ViewportId, action: WindowAction) -> bool {
|
||||
| WindowAction::Restore
|
||||
| WindowAction::SetMinInnerSize(_)
|
||||
| WindowAction::SetLevel(_)
|
||||
| WindowAction::SetTitle(_) => commands,
|
||||
| WindowAction::SetTitle(_)
|
||||
| WindowAction::Raise => commands,
|
||||
WindowAction::SetOpacity(_) => false,
|
||||
};
|
||||
if !allowed {
|
||||
@@ -109,6 +113,7 @@ pub fn act(ctx: &Context, viewport: ViewportId, action: WindowAction) -> bool {
|
||||
match action {
|
||||
WindowAction::Close => viewports::close(ctx, viewport),
|
||||
WindowAction::Focus => viewports::raise(ctx, viewport),
|
||||
WindowAction::Raise => viewports::raise_above(ctx, viewport, standing(ctx, viewport, level_of(ctx, viewport)).level),
|
||||
WindowAction::Minimize => viewports::command(ctx, viewport, egui::ViewportCommand::Minimized(true)),
|
||||
WindowAction::ToggleMaximize => viewports::command(ctx, viewport, egui::ViewportCommand::Maximized(window.state != WindowState::Maximized)),
|
||||
WindowAction::ToggleFullscreen => {
|
||||
@@ -147,8 +152,7 @@ pub fn act(ctx: &Context, viewport: ViewportId, action: WindowAction) -> bool {
|
||||
if opened {
|
||||
ctx.request_repaint_of(viewport);
|
||||
} else {
|
||||
let active = !shared(ctx, |shared| shared.away);
|
||||
viewports::command(ctx, viewport, egui::ViewportCommand::WindowLevel(level.for_egui(active, os_of(ctx))));
|
||||
viewports::command(ctx, viewport, egui::ViewportCommand::WindowLevel(standing(ctx, viewport, level).level));
|
||||
}
|
||||
}
|
||||
WindowAction::SetTitle(title) => {
|
||||
@@ -172,6 +176,16 @@ pub fn act(ctx: &Context, viewport: ViewportId, action: WindowAction) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
/// The level `viewport`'s window was opened with or last set to.
|
||||
fn level_of(ctx: &Context, viewport: ViewportId) -> WindowLevel {
|
||||
PerViewport::<Record>::with(ctx, viewport, |record| record.level.unwrap_or_default())
|
||||
}
|
||||
|
||||
/// How `viewport`'s window at `level` stands in the app's current state.
|
||||
fn standing(ctx: &Context, viewport: ViewportId, level: WindowLevel) -> Standing {
|
||||
level.standing(viewport, shared(ctx, |shared| shared.app), os_of(ctx))
|
||||
}
|
||||
|
||||
/// Applies `opacity` to the OS window. A faded window is told again in every pass, because the window system's own
|
||||
/// style changes can drop the layered style; an opaque one only when it was faded. Returns whether the platform applied
|
||||
/// it now.
|
||||
|
||||
@@ -4,7 +4,7 @@ use super::shared;
|
||||
use super::shell::{base_shell, os_of};
|
||||
use craft_host::target::{Os, WindowChrome, WindowKind};
|
||||
use craft_window::policy::{CaptionFamily, Captions, Frame, MacInset, tool_frame};
|
||||
use egui::Context;
|
||||
use egui::{Context, ViewportId};
|
||||
|
||||
/// Where a window stands in the stack of windows.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
@@ -13,26 +13,53 @@ pub enum WindowLevel {
|
||||
/// An ordinary window.
|
||||
#[default]
|
||||
Normal,
|
||||
/// A palette: above the app's other windows while the app is active, and an ordinary window (behind other
|
||||
/// apps' windows on Windows) once none of the app's windows has focus, so it stays shown without covering
|
||||
/// other apps.
|
||||
/// A palette: above the app's other windows while the app is active, an ordinary window while an app-modal layer
|
||||
/// in another window blocks it, and an ordinary window (behind other apps' windows on Windows) once none of the
|
||||
/// app's windows has focus, so it stays shown without covering other apps or the modal. Hidden while the main
|
||||
/// window is minimized, except on macOS, where the app stays active and its palettes stay.
|
||||
Palette,
|
||||
/// Above every other window.
|
||||
AlwaysOnTop,
|
||||
}
|
||||
|
||||
/// The app's state that its palettes follow, as its windows reported it in the last frame.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
pub(super) struct AppState {
|
||||
/// No window of the app has focus.
|
||||
pub away: bool,
|
||||
/// The window that holds an app-modal layer, which blocks the app's other windows.
|
||||
pub modal: Option<ViewportId>,
|
||||
/// The main window is minimized.
|
||||
pub minimized: bool,
|
||||
}
|
||||
|
||||
/// How a window stands among the windows.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub(super) struct Standing {
|
||||
/// The level egui is given.
|
||||
pub level: egui::WindowLevel,
|
||||
/// Whether the window is shown.
|
||||
pub shown: bool,
|
||||
/// Whether the window stands as an ordinary window because an app-modal layer in another window blocks it.
|
||||
pub lowered: bool,
|
||||
}
|
||||
|
||||
impl WindowLevel {
|
||||
/// The level egui is given while the app is `active` or not, on `os`. An inactive app's palette goes behind
|
||||
/// other apps' windows: on Windows `Normal` puts a window in front of every window that is not topmost, the
|
||||
/// activated app's included, so the palette goes to the bottom.
|
||||
pub(super) fn for_egui(self, active: bool, os: Os) -> egui::WindowLevel {
|
||||
match self {
|
||||
/// How `viewport`'s window at this level stands while the app is in `app`, on `os`. An inactive app's palette goes
|
||||
/// behind other apps' windows: on Windows `Normal` puts a window in front of every window that is not topmost, the
|
||||
/// activated app's included, so the palette goes to the bottom. A palette blocked by a modal stands as an ordinary
|
||||
/// window, so the modal's window can be raised above it.
|
||||
pub(super) fn standing(self, viewport: ViewportId, app: AppState, os: Os) -> Standing {
|
||||
let palette = self == WindowLevel::Palette;
|
||||
let lowered = palette && !app.away && app.modal.is_some_and(|modal| modal != viewport);
|
||||
let level = match self {
|
||||
WindowLevel::Normal => egui::WindowLevel::Normal,
|
||||
WindowLevel::AlwaysOnTop => egui::WindowLevel::AlwaysOnTop,
|
||||
WindowLevel::Palette if active => egui::WindowLevel::AlwaysOnTop,
|
||||
WindowLevel::Palette if os == Os::Windows => egui::WindowLevel::AlwaysOnBottom,
|
||||
WindowLevel::Palette => egui::WindowLevel::Normal,
|
||||
}
|
||||
WindowLevel::Palette if app.away && os == Os::Windows => egui::WindowLevel::AlwaysOnBottom,
|
||||
WindowLevel::Palette if app.away || lowered => egui::WindowLevel::Normal,
|
||||
WindowLevel::Palette => egui::WindowLevel::AlwaysOnTop,
|
||||
};
|
||||
Standing { level, shown: !(palette && app.minimized && os != Os::Mac), lowered }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,10 +54,10 @@ pub(crate) fn show_viewport(ctx: &Context, open: &ViewportOpen<'_>, mut body: im
|
||||
keep_placed(ctx, viewport, pos, size.filter(|_| open.follows_size));
|
||||
}
|
||||
let spec = open.spec;
|
||||
let active = !shared(ctx, |shared| shared.away);
|
||||
let state = shared(ctx, |shared| shared.app);
|
||||
let os = os_of(ctx);
|
||||
let (chrome, captions) = frame_of_spec(ctx, spec);
|
||||
let level = PerViewport::<Record>::with(ctx, viewport, |record| {
|
||||
let standing = PerViewport::<Record>::with(ctx, viewport, |record| {
|
||||
record.kind = Some(spec.kind);
|
||||
record.chrome = Some(chrome);
|
||||
record.captions = captions.clone();
|
||||
@@ -73,8 +73,11 @@ pub(crate) fn show_viewport(ctx: &Context, open: &ViewportOpen<'_>, mut body: im
|
||||
record.searched = None;
|
||||
}
|
||||
}
|
||||
record.level.get_or_insert(spec.level).for_egui(active, os)
|
||||
record.level.get_or_insert(spec.level).standing(viewport, state, os)
|
||||
});
|
||||
if standing.lowered {
|
||||
shared(ctx, |shared| shared.lowered = true);
|
||||
}
|
||||
let app = app_id(ctx);
|
||||
let opens = viewports::Spec {
|
||||
title: open.title,
|
||||
@@ -88,7 +91,7 @@ pub(crate) fn show_viewport(ctx: &Context, open: &ViewportOpen<'_>, mut body: im
|
||||
// egui sends a limit only when it has one: an open window always carries its maximum, unbounded when the
|
||||
// caller has none, so a lifted maximum reaches the OS.
|
||||
max_size: open.limits.1.or(opened.then_some(Vec2::INFINITY)),
|
||||
level,
|
||||
level: standing.level,
|
||||
resizable: open.resizable,
|
||||
taskbar: spec.taskbar,
|
||||
hidden: PerViewport::<Record>::with(ctx, viewport, |record| record.awaiting_first_paint),
|
||||
@@ -115,8 +118,18 @@ pub(crate) fn show_viewport(ctx: &Context, open: &ViewportOpen<'_>, mut body: im
|
||||
record_placement(&ctx, viewport, key, &at_known(&ctx, viewport, viewports::current(&ctx)));
|
||||
}
|
||||
});
|
||||
if PerViewport::<Record>::with(ctx, viewport, |record| std::mem::take(&mut record.awaiting_first_paint)) {
|
||||
viewports::show(ctx, viewport);
|
||||
// A window opened hidden appears once its first pass ran; a window the app's state hides goes and comes back with
|
||||
// it. The builder's visibility only opens the window: egui sends no change of it once the window is open.
|
||||
let hidden = !standing.shown;
|
||||
let (reveal, changed) = PerViewport::<Record>::with(ctx, viewport, |record| {
|
||||
let first = std::mem::take(&mut record.awaiting_first_paint);
|
||||
let changed = std::mem::replace(&mut record.hidden, hidden) != hidden;
|
||||
(first || changed, changed)
|
||||
});
|
||||
if hidden && changed {
|
||||
viewports::set_visible(ctx, viewport, false);
|
||||
} else if !hidden && reveal {
|
||||
viewports::set_visible(ctx, viewport, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
//! `runtime::windows`: the input hook per viewport, window info per viewport, the press release after an OS
|
||||
//! resize (H4), the raise of a modal's window, the mount of a full-window container (in a window of its own, or in a
|
||||
//! full-screen or Wayland-maximized main window), the size of a content-sized window, the app id of child windows,
|
||||
//! injected keys across a focus loss, non-finite injected points, a repeated injected press, the window that has the
|
||||
//! keys, and `act`.
|
||||
//! full-screen or Wayland-maximized main window), the size of a content-sized window, the app id of child windows, a
|
||||
//! palette's level under a modal and its visibility while the main window is minimized, injected keys across a focus
|
||||
//! loss, non-finite injected points, a repeated injected press, the window that has the keys, and `act`.
|
||||
|
||||
use craft_behavior::{Cursor, CursorIcon, PointerButton};
|
||||
use craft_host::target::{Backend, Caps, Os, ShellInfo, WindowChrome, WindowInfo, WindowKind};
|
||||
@@ -302,6 +302,81 @@ fn a_palette_drops_its_level_while_the_app_is_inactive() {
|
||||
assert_eq!(frame(true, false), on_top, "the frame after the main window took focus again");
|
||||
}
|
||||
|
||||
/// A palette stands as an ordinary window while an app-modal layer in the main window blocks it, so the modal is never
|
||||
/// behind a palette: the frame after the modal opens builds the palette's window at the ordinary level, a later frame
|
||||
/// raises the main window above it once, by its level (egui ignores `Focus` for a window that has focus), and the
|
||||
/// palette stands above the app's windows again once the modal closes.
|
||||
#[trial]
|
||||
fn a_palette_stands_behind_the_window_that_holds_a_modal() {
|
||||
let windows = Windows::new();
|
||||
windows.root_info(ViewportInfo { focused: Some(true), ..ViewportInfo::default() });
|
||||
let frame = |modal: bool| {
|
||||
let out = windows.frame(vec![], vec![], |ui| {
|
||||
windows.child_info(ViewportInfo { focused: Some(false), ..ViewportInfo::default() });
|
||||
Palette::new("tool", Some(WindowSpec::tool())).show(ui, |_, _| {});
|
||||
if modal {
|
||||
let props = ContainerProps::new().mount(Mount::Layer(Overlay::modal()));
|
||||
Modal { common: Common::new(), props }.id_salt("save prompt").show(ui, |_, _| {});
|
||||
}
|
||||
});
|
||||
let raise: Vec<ViewportCommand> = out
|
||||
.commands
|
||||
.iter()
|
||||
.filter(|(id, command)| *id == ViewportId::ROOT && matches!(command, ViewportCommand::WindowLevel(_) | ViewportCommand::Focus))
|
||||
.map(|(_, command)| command.clone())
|
||||
.collect();
|
||||
(builder_titled(&out, "tool").1.window_level, raise)
|
||||
};
|
||||
let (on_top, normal) = (Some(egui::WindowLevel::AlwaysOnTop), Some(egui::WindowLevel::Normal));
|
||||
assert_eq!(frame(false), (on_top, vec![]), "no modal: the palette stands above the main window");
|
||||
let frames: Vec<_> = (0..4).map(|_| frame(true)).collect();
|
||||
assert_eq!(frames.last().map(|(level, _)| *level), Some(normal), "the modal open: the palette is an ordinary window");
|
||||
let raises: Vec<usize> = frames.iter().enumerate().filter(|(_, (_, raise))| !raise.is_empty()).map(|(at, _)| at).collect();
|
||||
let lowered = frames.iter().position(|(level, _)| *level == normal);
|
||||
assert_eq!(raises.len(), 1, "the main window is raised once: {frames:?}");
|
||||
assert!(lowered.is_some_and(|lowered| raises[0] > lowered), "the raise follows the frame that lowered the palette: {frames:?}");
|
||||
let level = |level| ViewportCommand::WindowLevel(level);
|
||||
assert_eq!(
|
||||
frames[raises[0]].1,
|
||||
vec![level(egui::WindowLevel::AlwaysOnTop), level(egui::WindowLevel::Normal)],
|
||||
"the raise stands the main window above every window and back, without focus"
|
||||
);
|
||||
frame(false);
|
||||
assert_eq!(frame(false), (on_top, vec![]), "the modal closed: the palette stands above again");
|
||||
}
|
||||
|
||||
/// A palette's window is hidden while the main window is minimized and shown again at its place when the main window
|
||||
/// is restored, on Windows and Linux; a document window stays. On macOS a minimized main window leaves the app active,
|
||||
/// and its palettes stay.
|
||||
#[trial]
|
||||
fn palettes_hide_while_the_main_window_is_minimized() {
|
||||
for os in [Os::Windows, Os::Linux, Os::Mac] {
|
||||
let windows = Windows::with(InstallSpec::new(ShellInfo::default().os(os).caps(Caps::native(os)), Arc::new(FakeSystem::new())));
|
||||
let frame = |minimized: bool| {
|
||||
windows.root_info(ViewportInfo { minimized: Some(minimized), ..ViewportInfo::default() });
|
||||
windows.frame(vec![], vec![], |ui| {
|
||||
Palette::new("tool", Some(WindowSpec::tool())).show(ui, |_, _| {});
|
||||
Palette::new("doc", Some(WindowSpec::document())).show(ui, |_, _| {});
|
||||
})
|
||||
};
|
||||
let first = frame(false);
|
||||
let (tool, doc) = (builder_titled(&first, "tool").0, builder_titled(&first, "doc").0);
|
||||
frame(false);
|
||||
let commands = |minimized: bool| -> Vec<(ViewportId, ViewportCommand)> { (0..3).flat_map(|_| frame(minimized).commands).collect() };
|
||||
let sent = |commands: &[(ViewportId, ViewportCommand)], to: ViewportId| -> Vec<ViewportCommand> {
|
||||
commands.iter().filter(|(id, _)| *id == to).map(|(_, command)| command.clone()).collect()
|
||||
};
|
||||
let (minimized, restored) = (commands(true), commands(false));
|
||||
let hides = os != Os::Mac;
|
||||
let visible = |on: bool| if hides { vec![ViewportCommand::Visible(on)] } else { vec![] };
|
||||
let (tool_minimized, doc_minimized) = (sent(&minimized, tool), sent(&minimized, doc));
|
||||
let (tool_restored, doc_restored) = (sent(&restored, tool), sent(&restored, doc));
|
||||
assert_eq!(tool_minimized, visible(false), "{os:?}: the main window minimized: the palette is hidden, and nothing else is sent");
|
||||
assert_eq!(tool_restored, visible(true), "{os:?}: the main window restored: the palette is shown where it was");
|
||||
assert_eq!((doc_minimized, doc_restored), (vec![], vec![]), "{os:?}: a document window is left as it is");
|
||||
}
|
||||
}
|
||||
|
||||
/// A full-window container mounted in its own window opens a resizable OS window titled as the container where
|
||||
/// viewports are available, and covers the main window's content where they are not.
|
||||
#[trial]
|
||||
|
||||
Reference in New Issue
Block a user