mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-30 18:27:00 +01:00
viewport window: an ordinary app window with the OS frame (ViewportWindowKind::App)
ViewportWindow opened every modeless window as a tool window: a palette with no taskbar entry and the dialog's own title row. An app's second document window or presenter's view is an ordinary window of the app. ViewportWindowKind::App (q352 = A) opens WindowSpec::document() with the OS frame and opens_over_full_screen as before, and the dialog fills the window (Dialog::fills_os_window): no padding, and a header the OS title bar stands for (HeaderRegion::os_title). The body leaves such a header out, in its read step, where the container is a viewport mount in an OS window of its own whose frame the OS draws; a layer and an app-framed window keep it. The default kind and every other header are unchanged. Trial: the_os_title_bar_stands_for_a_header_only_in_an_os_framed_window (fails with the read-step filter off); story viewport_window_app. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
75665387c7
commit
6fcfb5fdc6
8 files changed
+146
-10
No files matched your search
@@ -154,6 +154,14 @@ impl<C: Container> ShapeHooks<C> for BodyHooks<'_> {
|
||||
|
||||
fn read(&mut self, comp: &mut C, stage: &mut MemoryStage, id: Id, env: &Env) {
|
||||
let ctx = stage.ctx().clone();
|
||||
// A header the OS title bar stands for is gone in a window whose frame the OS draws: every later step and
|
||||
// region reads the props without it.
|
||||
if let Mount::Viewport { spec, .. } = &self.props.mount
|
||||
&& self.props.header.is_some_and(|header| header.os_title)
|
||||
&& windows::os_title_bar(&ctx, id, spec.as_ref())
|
||||
{
|
||||
Arc::make_mut(&mut self.props).header = None;
|
||||
}
|
||||
let props = Arc::clone(&self.props);
|
||||
let props = &*props;
|
||||
let scroll = scroll_of(props);
|
||||
|
||||
@@ -379,6 +379,10 @@ pub struct HeaderRegion {
|
||||
pub inset: Pad,
|
||||
/// The space between a stacked header and the body, none by default.
|
||||
pub gap: Option<Gap>,
|
||||
/// Whether the OS title bar stands for the header: where the container is a viewport mount in an OS window of its
|
||||
/// own whose frame the OS draws (`WindowChrome::Native`), the title bar carries its title and close button, and
|
||||
/// the container has no header. As a layer, or in a window the app frames, it keeps the header.
|
||||
pub os_title: bool,
|
||||
}
|
||||
|
||||
impl HeaderRegion {
|
||||
@@ -394,9 +398,16 @@ impl HeaderRegion {
|
||||
fill: None,
|
||||
inset: Pad::None,
|
||||
gap: None,
|
||||
os_title: false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the OS title bar stands for the header (see [`HeaderRegion::os_title`]).
|
||||
pub const fn os_title(mut self, on: bool) -> Self {
|
||||
self.os_title = on;
|
||||
self
|
||||
}
|
||||
|
||||
/// The surface of a band behind the header.
|
||||
pub const fn fill(mut self, kind: SurfaceKind) -> Self {
|
||||
self.fill = Some(BandFill::Surface(kind));
|
||||
|
||||
@@ -480,6 +480,12 @@ pub(crate) fn mount_window(ctx: &Context, id: Id, spec: Option<&WindowSpec>) ->
|
||||
opens_over(ctx, opener)
|
||||
}
|
||||
|
||||
/// Whether the viewport mount `id` opening as `spec` shows in an OS window of its own whose frame, title bar included,
|
||||
/// the OS draws. A mount without a spec takes its frame by rank and is not counted.
|
||||
pub(crate) fn os_title_bar(ctx: &Context, id: Id, spec: Option<&WindowSpec>) -> bool {
|
||||
spec.is_some_and(|spec| spec::frame_of_spec(ctx, spec).0 == WindowChrome::Native) && mount_window(ctx, id, spec)
|
||||
}
|
||||
|
||||
/// Whether a viewport mount opened from `opener`'s window shows in an OS window of its own: the rule of
|
||||
/// [`mount_window`].
|
||||
fn opens_over(ctx: &Context, opener: ViewportId) -> bool {
|
||||
|
||||
@@ -1064,6 +1064,60 @@ fn a_viewport_mount_that_opens_over_full_screen_keeps_its_own_window() {
|
||||
}
|
||||
}
|
||||
|
||||
/// A container whose header the OS title bar stands for, recording whether its header ran.
|
||||
#[derive(craft_ui::contract::Component)]
|
||||
#[component(container)]
|
||||
struct Titled {
|
||||
#[common]
|
||||
common: Common,
|
||||
#[container]
|
||||
props: ContainerProps,
|
||||
header: Rc<Cell<bool>>,
|
||||
}
|
||||
|
||||
impl Component for Titled {
|
||||
const ROLE: Role = Role::GROUP;
|
||||
type Style = PlainStyle;
|
||||
type Output = Response;
|
||||
|
||||
fn style(_: &StyleCx<'_>, _: TitledStyleKey) -> PlainStyle {
|
||||
PlainStyle::min(Vec2::new(120.0, 60.0))
|
||||
}
|
||||
|
||||
fn finish(self, cx: Cx<'_, Self>) -> Response {
|
||||
cx.response.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl Container for Titled {
|
||||
fn header(&mut self, _: &mut egui::Ui, _: &mut craft_ui::contract::BodyCx<'_>) {
|
||||
self.header.set(true);
|
||||
}
|
||||
}
|
||||
|
||||
/// A header the OS title bar stands for is left out in an OS window of its own whose frame the OS draws, and kept in
|
||||
/// a window the app frames and in the layer that stands in for the window over a full-screen main window.
|
||||
#[trial]
|
||||
fn the_os_title_bar_stands_for_a_header_only_in_an_os_framed_window() {
|
||||
let header_ran = |windows: &Windows, chrome: WindowChrome| {
|
||||
let ran = Rc::new(Cell::new(false));
|
||||
for _ in 0..3 {
|
||||
ran.set(false);
|
||||
windows.frame(vec![], vec![], |ui| {
|
||||
let mount = Mount::viewport_with(Overlay::floating(), WindowSpec::document().chrome(chrome));
|
||||
let props = ContainerProps::new().mount(mount).header(craft_ui::contract::HeaderRegion::new().os_title(true));
|
||||
Titled { common: Common::new(), props, header: Rc::clone(&ran) }.label("Second").id_salt("second").show(ui, |_, _| {});
|
||||
});
|
||||
}
|
||||
ran.get()
|
||||
};
|
||||
assert!(!header_ran(&Windows::new(), WindowChrome::Native), "the OS title bar stands for the header");
|
||||
assert!(header_ran(&Windows::new(), WindowChrome::Integrated), "a window the app frames keeps the header");
|
||||
let layer = Windows::new();
|
||||
layer.root_info(ViewportInfo { fullscreen: Some(true), ..ViewportInfo::default() });
|
||||
assert!(header_ran(&layer, WindowChrome::Native), "the layer keeps the header");
|
||||
}
|
||||
|
||||
/// A window sized by its content sends no size before it has reported its place, so it never opens at what its body
|
||||
/// took in room the OS has not given; once it has reported, it takes its content's size.
|
||||
#[trial]
|
||||
|
||||
@@ -198,6 +198,16 @@ impl<'a> Dialog<'a> {
|
||||
Dialog { props: self.props.mount(mount), ..self }
|
||||
}
|
||||
|
||||
/// A window of the app rather than a dialog: the body fills the window edge to edge, unpadded, and where the dialog
|
||||
/// stands in an OS window of its own with the OS's frame, the OS title bar stands for its title row
|
||||
/// (`HeaderRegion::os_title`). As a layer it keeps the title row.
|
||||
#[must_use]
|
||||
pub fn fills_os_window(mut self) -> Self {
|
||||
self.props.pad = Pad::None;
|
||||
self.props.header = self.props.header.map(|header| header.os_title(true));
|
||||
self
|
||||
}
|
||||
|
||||
/// A tool window: no modal layer and no backdrop; its edits are the app's normal edits.
|
||||
#[must_use]
|
||||
pub fn modeless(self) -> Self {
|
||||
|
||||
@@ -45,7 +45,7 @@ pub use start::{
|
||||
FolderListing, PINNED_FILES_SHOWN, PinnedFile, PinnedFolder, StartAction, StartLayout, StartLink, StartLinkTarget, StartOutput,
|
||||
StartPinnedCommands, StartPlace, StartRecentCommands, StartScreen,
|
||||
};
|
||||
pub use viewport_window::{ViewportWindow, ViewportWindowOutput};
|
||||
pub use viewport_window::{ViewportWindow, ViewportWindowKind, ViewportWindowOutput};
|
||||
|
||||
// Caption buttons: the four families' button, its slot layout and the icon-theme glyphs.
|
||||
pub(crate) mod caption_button;
|
||||
|
||||
@@ -8,6 +8,7 @@ use crate::dialog::Dialog;
|
||||
use crate::runtime::env::Label;
|
||||
use crate::runtime::overlay::{Backdrop, CloseReason};
|
||||
use crate::runtime::windows::WindowSpec;
|
||||
use craft_host::target::WindowChrome;
|
||||
use egui::{Response, Ui};
|
||||
|
||||
/// What a window pass reports.
|
||||
@@ -30,6 +31,20 @@ impl Outcome for ViewportWindowOutput {
|
||||
}
|
||||
}
|
||||
|
||||
/// What kind of OS window a [`ViewportWindow`] opens.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
|
||||
#[non_exhaustive]
|
||||
pub enum ViewportWindowKind {
|
||||
/// By its rank: a dialog window for an app-modal one, else a tool window (a palette with its own title row and no
|
||||
/// taskbar entry).
|
||||
#[default]
|
||||
Tool,
|
||||
/// An ordinary window of the app, as its main window is: the OS frame with the title and close button, a taskbar
|
||||
/// entry, the normal level, and a body that fills the window edge to edge (a second document window, a
|
||||
/// presenter's view). As a layer, where windows are unavailable, it keeps its title row.
|
||||
App,
|
||||
}
|
||||
|
||||
/// A window of the app with a body the app fills.
|
||||
///
|
||||
/// The app calls [`show`](ViewportWindow::show) on every pass the window should exist and stops calling it to close
|
||||
@@ -41,6 +56,8 @@ impl Outcome for ViewportWindowOutput {
|
||||
/// [`opens_over_full_screen`](ViewportWindow::opens_over_full_screen) keeps it in an OS window of its own.
|
||||
/// - **App-modal.** By default the window blocks nothing. [`app_modal`](ViewportWindow::app_modal) makes the app's
|
||||
/// other windows ignore input while it is open, and a press on one raises this window.
|
||||
/// - **Kind.** By default the OS window is a tool or dialog window by its rank; [`kind`](ViewportWindow::kind)
|
||||
/// `ViewportWindowKind::App` makes it an ordinary window of the app with the OS frame.
|
||||
/// - **Keys.** Escape asks to close an app-modal window, unless a popup in it is open; a tool window ignores it.
|
||||
/// [`takes_unfocused_keys`](ViewportWindow::takes_unfocused_keys) gives a layer window the keys pressed with
|
||||
/// nothing focused.
|
||||
@@ -66,12 +83,23 @@ pub struct ViewportWindow {
|
||||
/// window that stands beside a full-screen one, as a presenter's window beside its show, usually on another display.
|
||||
#[prop(flag)]
|
||||
opens_over_full_screen: bool,
|
||||
/// What kind of OS window it opens: by its rank (the default), or an ordinary window of the app.
|
||||
#[prop]
|
||||
kind: ViewportWindowKind,
|
||||
}
|
||||
|
||||
impl ViewportWindow {
|
||||
/// A window titled `title` that blocks nothing.
|
||||
pub fn new(title: impl Into<Label>) -> Self {
|
||||
ViewportWindow { title: title.into(), modal: None, overlay: None, remember: None, takes_unfocused_keys: false, opens_over_full_screen: false }
|
||||
ViewportWindow {
|
||||
title: title.into(),
|
||||
modal: None,
|
||||
overlay: None,
|
||||
remember: None,
|
||||
takes_unfocused_keys: false,
|
||||
opens_over_full_screen: false,
|
||||
kind: ViewportWindowKind::Tool,
|
||||
}
|
||||
}
|
||||
|
||||
/// Changes the layer the window falls back to, which starts as the resizable dialog layer: the smallest and
|
||||
@@ -87,7 +115,7 @@ impl ViewportWindow {
|
||||
|
||||
/// Shows the window for this pass with `body` as its content.
|
||||
pub fn show(self, ui: &mut Ui, mut body: impl FnMut(&mut Ui, &mut BodyCx<'_>)) -> ViewportWindowOutput {
|
||||
let ViewportWindow { title, modal, overlay, remember, takes_unfocused_keys, opens_over_full_screen } = self;
|
||||
let ViewportWindow { title, modal, overlay, remember, takes_unfocused_keys, opens_over_full_screen, kind } = self;
|
||||
let mut dialog = Dialog::new(title).resizable(true);
|
||||
if let Some(change) = overlay {
|
||||
dialog = dialog.overlay(change);
|
||||
@@ -96,12 +124,17 @@ impl ViewportWindow {
|
||||
Some(backdrop) => dialog.backdrop(backdrop),
|
||||
None => dialog.modeless(),
|
||||
};
|
||||
dialog = if opens_over_full_screen {
|
||||
// The window a viewport mount opens by its rank: a dialog window for an app-modal one, else a tool window.
|
||||
let spec = if modal.is_some() { WindowSpec::dialog() } else { WindowSpec::tool() };
|
||||
dialog.viewport_with(spec.over_full_screen(true))
|
||||
} else {
|
||||
dialog.viewport()
|
||||
dialog = match kind {
|
||||
ViewportWindowKind::App => {
|
||||
let spec = WindowSpec::document().chrome(WindowChrome::Native).over_full_screen(opens_over_full_screen);
|
||||
dialog.fills_os_window().viewport_with(spec)
|
||||
}
|
||||
ViewportWindowKind::Tool if opens_over_full_screen => {
|
||||
// The window a viewport mount opens by its rank: a dialog window for an app-modal one, else a tool window.
|
||||
let spec = if modal.is_some() { WindowSpec::dialog() } else { WindowSpec::tool() };
|
||||
dialog.viewport_with(spec.over_full_screen(true))
|
||||
}
|
||||
ViewportWindowKind::Tool => dialog.viewport(),
|
||||
};
|
||||
if let Some(key) = remember {
|
||||
dialog = dialog.remember(key);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! Stories of `ViewportWindow`. Each window shows while the story's `open` value is on; closing it turns the value off.
|
||||
|
||||
use super::ViewportWindow;
|
||||
use super::{ViewportWindow, ViewportWindowKind};
|
||||
use crate::contract::Show as _;
|
||||
use crate::display::Text;
|
||||
use crate::runtime::overlay::Backdrop;
|
||||
@@ -33,6 +33,20 @@ fn viewport_window_over_full_screen(ui: &mut Ui, data: &mut StoryData) -> StoryO
|
||||
shown.into()
|
||||
}
|
||||
|
||||
/// An ordinary window of the app: the OS frame carries the title, and the body fills the window.
|
||||
#[story(ViewportWindow, covers = [], drive = Drive::Never)]
|
||||
fn viewport_window_app(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let open = data.value("open", true);
|
||||
if !*open {
|
||||
return StoryOutput::default();
|
||||
}
|
||||
let shown = ViewportWindow::new("Second Window").kind(ViewportWindowKind::App).show(ui, |ui, _| {
|
||||
let _ = Text::new("A window of the app beside its main window, with a taskbar entry.").show(ui);
|
||||
});
|
||||
*open = shown.close_requested.is_none();
|
||||
shown.into()
|
||||
}
|
||||
|
||||
#[story(ViewportWindow, covers = [], drive = Drive::Never)]
|
||||
fn viewport_window_app_modal(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let open = data.value("open", true);
|
||||
|
||||
Reference in new issue
Block a user