mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-23 02:51:42 +01:00
DocumentWindow: a level of its own; first_placed says the window is kept there (photocraft#16415)
DocumentWindow::level stands the window at a WindowLevel; with Palette a floating document stays above the app's main window while the app is active, drops below a blocking dialog and hides with the minimized main window. first_placed's doc says what it does: the window is kept at the rect while shown, so a caller whose user moves the window follows it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cdde34581e
commit
4ba7c7e215
2 files changed
+45
-2
No files matched your search
@@ -11,7 +11,7 @@ use crate::contract::{
|
||||
use crate::runtime::env::Label;
|
||||
use crate::runtime::memory::{Remember as _, sub};
|
||||
use crate::runtime::overlay::CloseReason;
|
||||
use crate::runtime::windows::{WindowAction, WindowHost, WindowSpec};
|
||||
use crate::runtime::windows::{WindowAction, WindowHost, WindowLevel, WindowSpec};
|
||||
use crate::sections::{HeaderAction, HeaderStrength, TitleRow};
|
||||
use crate::style::{ComponentStyle, StyleCx, SurfaceKind};
|
||||
use craft_behavior::placement::{capped, cascade, monitor_of};
|
||||
@@ -161,12 +161,30 @@ impl<'a> DocumentWindow<'a> {
|
||||
self
|
||||
}
|
||||
|
||||
/// Where the window opens, as its outer rect in desktop points. A saved placement comes first.
|
||||
/// Where the window is, as its outer rect in desktop points. A saved placement comes first. The window is kept
|
||||
/// at `rect` while the app shows it, so an app whose user moves the window keeps `rect` where the window went
|
||||
/// (its [`WindowHost::facts`]); else the window goes back at the next pass.
|
||||
#[must_use]
|
||||
pub fn first_placed(self, rect: Rect) -> Self {
|
||||
self.overlay(|overlay| overlay.placed(rect))
|
||||
}
|
||||
|
||||
/// Stands the window at `level` among the windows, in place of an ordinary window's. With
|
||||
/// [`WindowLevel::Palette`] a document window stays above the app's main window while the app is active, as a
|
||||
/// floating document does in the references, drops below a blocking dialog in another window, and hides while the
|
||||
/// main window is minimized.
|
||||
#[must_use]
|
||||
pub fn level(mut self, level: WindowLevel) -> Self {
|
||||
self.props = match std::mem::take(&mut self.props.mount) {
|
||||
Mount::Viewport { fallback, spec } => {
|
||||
let spec = spec.unwrap_or_else(WindowSpec::document).level(level);
|
||||
self.props.mount(Mount::Viewport { fallback, spec: Some(spec) })
|
||||
}
|
||||
other => self.props.mount(other),
|
||||
};
|
||||
self
|
||||
}
|
||||
|
||||
/// Whether the user can resize the window.
|
||||
#[must_use]
|
||||
pub fn resizable(self, on: bool) -> Self {
|
||||
|
||||
@@ -183,3 +183,28 @@ fn a_document_window_body_fills_the_windows_room_and_does_not_scroll() {
|
||||
assert!(height < MAX_EXTENT / 2.0, "{mount}: the body's height is the window's room, got {height}");
|
||||
}
|
||||
}
|
||||
|
||||
/// A document window at the palette level stands above the app's main window while the app is active (photocraft
|
||||
/// floating documents, as the references keep them); without a level it is an ordinary window.
|
||||
#[trial]
|
||||
fn a_document_window_at_the_palette_level_stands_above_the_main_window() {
|
||||
let level = |palette: bool| {
|
||||
let windows = Windows::new();
|
||||
windows.root_info(ViewportInfo { focused: Some(true), ..ViewportInfo::default() });
|
||||
let mut seen = None;
|
||||
for _ in 0..3 {
|
||||
let out = windows.frame(vec![], vec![], |ui| {
|
||||
windows.child_info(ViewportInfo { focused: Some(false), ..ViewportInfo::default() });
|
||||
let window = DocumentWindow::new("Landscape.psd");
|
||||
let window = if palette { window.level(craft_ui::runtime::windows::WindowLevel::Palette) } else { window };
|
||||
window.show(ui, |_, _| {});
|
||||
});
|
||||
if let Some((_, builder)) = out.builders.iter().find(|(_, builder)| builder.title.as_deref() == Some("Landscape.psd")) {
|
||||
seen = builder.window_level.or(seen);
|
||||
}
|
||||
}
|
||||
seen
|
||||
};
|
||||
assert_eq!(level(true), Some(egui::WindowLevel::AlwaysOnTop), "a palette-level document window stands above the main window");
|
||||
assert_ne!(level(false), Some(egui::WindowLevel::AlwaysOnTop), "an ordinary document window does not");
|
||||
}
|
||||
Reference in new issue
Block a user