mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 05:37:04 +00:00
chrome-w1: net change of 4 commits
- chrome-w1: written by an agent - chrome-w1: finished by an agent - chrome-w1: finished by an agent - chrome-w1: review fixes (review-1)
This commit is contained in:
+10
-8
@@ -128,14 +128,16 @@ struct Inner {
|
||||
page_band: Option<PageBandRoom>,
|
||||
}
|
||||
|
||||
/// The room of the page band while a full-window page shows.
|
||||
/// The room of the page band while a full-window page shows: the title-bar-high strip at the window's top and the room
|
||||
/// the window's ends take in it.
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub struct PageBandRoom {
|
||||
/// The band's rect.
|
||||
pub rect: Rect,
|
||||
/// Where the band starts along its axis.
|
||||
/// The width the window's start end takes (the traffic lights' inset or the caption buttons), from the band's
|
||||
/// reading start.
|
||||
pub start: f32,
|
||||
/// Where the band ends along its axis.
|
||||
/// The width the window's end end takes, from the band's reading end.
|
||||
pub end: f32,
|
||||
}
|
||||
|
||||
@@ -326,13 +328,13 @@ impl ShellCx {
|
||||
|
||||
/// The page band's room while a full-window page shows, else `None`.
|
||||
pub fn page_band(&self) -> Option<PageBandRoom> {
|
||||
todo!("ch.C5a")
|
||||
self.inner.page_band
|
||||
}
|
||||
|
||||
/// Sets the page band's room.
|
||||
pub fn with_page_band(self, room: Option<PageBandRoom>) -> Self {
|
||||
let _ = room;
|
||||
todo!("ch.C5a")
|
||||
/// The page band's room while a full-window page shows; `None` when no page shows or the window is full screen.
|
||||
pub fn with_page_band(mut self, room: Option<PageBandRoom>) -> Self {
|
||||
Arc::make_mut(&mut self.inner).page_band = room;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ use super::canvas_shell::slots as keys;
|
||||
use super::regions::{Claim, SlotSize, layout};
|
||||
use super::reveal::{Aim, Reveal, Tracking};
|
||||
use super::screen_mode::{ScreenMode, ScreenModeCommands, ScreenModeFollow, ScreenModeSet};
|
||||
use super::title_bar::PageBand;
|
||||
use super::words::ShellWords;
|
||||
use crate::contract::overlay::Resize;
|
||||
use crate::contract::{
|
||||
@@ -18,7 +19,7 @@ use crate::contract::{
|
||||
Role, ShellPane, ShowContainer as _, Sizing,
|
||||
};
|
||||
use crate::notices::ToastStack;
|
||||
use crate::runtime::commands::{CommandAccess as _, CommandSet as _};
|
||||
use crate::runtime::commands::{CommandAccess as _, CommandScope, CommandSet as _};
|
||||
use crate::runtime::egui::pass;
|
||||
use crate::runtime::env::{AppValues, BodyMode, Env, Label, RevealEdge, ShellCx, ShellEntry, ShellRegions, SlotKey, WindowKey};
|
||||
use crate::runtime::focus::FocusPolicy;
|
||||
@@ -28,7 +29,7 @@ use crate::runtime::pointer;
|
||||
use crate::runtime::windows::{WindowAction, WindowHost};
|
||||
use crate::shell::Slot;
|
||||
use crate::style::{ComponentStyle, StyleCx, SurfaceKind, UiTokens};
|
||||
use craft_behavior::{Metrics, Sense};
|
||||
use craft_behavior::{EditEvent, Metrics, Mixed, Sense};
|
||||
use egui::{Rect, Response, Ui};
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -92,6 +93,8 @@ pub struct ShellRegion {
|
||||
#[container]
|
||||
props: ContainerProps,
|
||||
shell: Option<ShellCx>,
|
||||
/// The screen modes of the shell, published to everything inside a scope region with the shell itself.
|
||||
mode_set: Option<ScreenModeSet>,
|
||||
/// Whether the region senses a press on its own surface, where no child or part takes it (`Sense::SURFACE`).
|
||||
#[prop(flag)]
|
||||
senses_surface: bool,
|
||||
@@ -104,7 +107,7 @@ impl ShellRegion {
|
||||
pub fn window() -> Self {
|
||||
let props =
|
||||
ContainerProps::new().mount(Mount::window(Resize::GRIPS)).surface(SurfaceKind::Background).command_scope(ScreenModeCommands::SCOPE);
|
||||
ShellRegion { common: Common::new(), props, shell: None, senses_surface: false }
|
||||
ShellRegion { common: Common::new(), props, shell: None, mode_set: None, senses_surface: false }
|
||||
}
|
||||
|
||||
/// The content of a shell shown inside a region of another window: it fills its room, answers the screen-mode
|
||||
@@ -112,13 +115,20 @@ impl ShellRegion {
|
||||
pub fn embedded() -> Self {
|
||||
let props =
|
||||
ContainerProps::new().sizing(crate::contract::Sizing::Fill).surface(SurfaceKind::Background).command_scope(ScreenModeCommands::SCOPE);
|
||||
ShellRegion { common: Common::new(), props, shell: None, senses_surface: false }
|
||||
ShellRegion { common: Common::new(), props, shell: None, mode_set: None, senses_surface: false }
|
||||
}
|
||||
|
||||
/// An inline region that fills its room and sets `shell` for everything inside it.
|
||||
pub fn scope(shell: ShellCx) -> Self {
|
||||
let props = ContainerProps::new().sizing(crate::contract::Sizing::Fill).command_scope(crate::runtime::commands::CommandScope::APP);
|
||||
ShellRegion { common: Common::new(), props, shell: Some(shell), senses_surface: false }
|
||||
ShellRegion { common: Common::new(), props, shell: Some(shell), mode_set: None, senses_surface: false }
|
||||
}
|
||||
|
||||
/// Sets the shell's screen modes for everything inside the region, beside its shell: a `ScreenModeButton` in a
|
||||
/// slot reads them with `Env::get`.
|
||||
fn with_mode_set(mut self, set: ScreenModeSet) -> Self {
|
||||
self.mode_set = Some(set);
|
||||
self
|
||||
}
|
||||
|
||||
/// A pane of the window; it fills the room its edge gives it. A top or bottom pane lays its content along its edge
|
||||
@@ -127,7 +137,7 @@ impl ShellRegion {
|
||||
pub fn pane(pane: ShellPane) -> Self {
|
||||
let layout = if matches!(pane.edge, PaneEdge::Top | PaneEdge::Bottom) { BodyLayout::row() } else { BodyLayout::stack() };
|
||||
let props = ContainerProps::new().mount(Mount::Pane(pane)).focus(FocusPolicy::PANE).layout(layout);
|
||||
ShellRegion { common: Common::new(), props, shell: None, senses_surface: false }
|
||||
ShellRegion { common: Common::new(), props, shell: None, mode_set: None, senses_surface: false }
|
||||
}
|
||||
|
||||
/// A bar or rail pane at an edge of the window: it paints the chrome surface over the whole pane and a divider
|
||||
@@ -160,6 +170,9 @@ impl Component for ShellRegion {
|
||||
if let Some(shell) = &self.shell {
|
||||
shell.put(values);
|
||||
}
|
||||
if let Some(set) = self.mode_set {
|
||||
values.set(set);
|
||||
}
|
||||
}
|
||||
|
||||
fn finish(self, cx: Cx<'_, Self>) -> ShellRegionOutput {
|
||||
@@ -203,6 +216,12 @@ impl<S> Placed<'_, S> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether `slot` covers the body instead of taking room from it: every slot of a body-only pass but the screen bar,
|
||||
/// which Focus and Immersive lay out above the body.
|
||||
fn covers(slot: &Slot, only: bool) -> bool {
|
||||
only && !slot.is_screen_bar()
|
||||
}
|
||||
|
||||
/// What the shell keeps between passes, in the root container's slot.
|
||||
#[derive(Clone, Debug, Default)]
|
||||
struct ShellState {
|
||||
@@ -217,6 +236,7 @@ struct Parts {
|
||||
revealed: bool,
|
||||
panels_hidden: bool,
|
||||
mode: ScreenMode,
|
||||
dropped: bool,
|
||||
}
|
||||
|
||||
/// What [`AppShell::show`] drew.
|
||||
@@ -234,6 +254,9 @@ pub struct AppShellOutput {
|
||||
pub panels_hidden: bool,
|
||||
/// The screen mode after this pass.
|
||||
pub screen_mode: ScreenMode,
|
||||
/// Whether the drop-down slot ([`Slot::drops`]) shows after this pass. A host that binds `dropped` with
|
||||
/// `Bind::given` writes it back, so a press in the body or a mode change that cleared it holds.
|
||||
pub dropped: bool,
|
||||
}
|
||||
|
||||
impl Outcome for AppShellOutput {
|
||||
@@ -315,6 +338,8 @@ pub struct AppShell<'a, S> {
|
||||
/// The body, shown in what the slots leave.
|
||||
#[prop(func = "FnMut(&mut Ui, &mut BodyCx<'_>, &mut S)")]
|
||||
body: Option<SlotBody<'a, S>>,
|
||||
/// The full-window page and its command scope, set while it shows.
|
||||
page: Option<(CommandScope, SlotBody<'a, S>)>,
|
||||
}
|
||||
|
||||
impl<'a, S> AppShell<'a, S> {
|
||||
@@ -336,6 +361,7 @@ impl<'a, S> AppShell<'a, S> {
|
||||
title: None,
|
||||
slots: Vec::new(),
|
||||
body: None,
|
||||
page: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -399,10 +425,14 @@ impl<'a, S> AppShell<'a, S> {
|
||||
self.place(PaneEdge::Start, slot, add)
|
||||
}
|
||||
|
||||
/// A page that, while `shown`, fills the window under a move band with the window's ends; dialogs run over it.
|
||||
pub fn page(mut self, shown: bool, add: impl FnMut(&mut Ui, &mut BodyCx<'_>, &mut S) + 'a) -> Self {
|
||||
let _ = (&mut self, shown, add);
|
||||
todo!("ch.C5")
|
||||
/// A page that, while `shown`, fills the window in place of the slots and the body (a backstage, a print page). A
|
||||
/// move band with the window's ends (the traffic lights' room or the caption buttons) lies over its top; the page
|
||||
/// reads the room they take with `ShellCx::page_band` and keeps its controls clear of the band. The page's region is
|
||||
/// the instance of `scope`; dialogs run over it, and with nothing focused the page takes keys beside the window's,
|
||||
/// so `scope`'s commands get their default keys.
|
||||
pub fn page(mut self, shown: bool, scope: CommandScope, add: impl FnMut(&mut Ui, &mut BodyCx<'_>, &mut S) + 'a) -> Self {
|
||||
self.page = shown.then(|| (scope, SlotBody::new(add)));
|
||||
self
|
||||
}
|
||||
|
||||
/// A slot at the reading end, inside the ones added before it.
|
||||
@@ -445,7 +475,7 @@ impl<'a, S> AppShell<'a, S> {
|
||||
content_room,
|
||||
mut screen_mode,
|
||||
mode_set,
|
||||
dropped: _dropped, // P3(chrome-w1): ch.C3
|
||||
mut dropped,
|
||||
allow_reveal,
|
||||
edge_reveal,
|
||||
document_tabs,
|
||||
@@ -454,6 +484,7 @@ impl<'a, S> AppShell<'a, S> {
|
||||
title,
|
||||
slots,
|
||||
mut body,
|
||||
mut page,
|
||||
} = self;
|
||||
let embedded = embedded || content_room.is_some();
|
||||
if let Some(title) = window_title
|
||||
@@ -483,37 +514,80 @@ impl<'a, S> AppShell<'a, S> {
|
||||
let mut kept = cx.keep::<ShellState>().clone();
|
||||
|
||||
let name: Arc<str> = words.screen_mode.as_str().into();
|
||||
let (mode, changed) = kept.screen.follow(&ctx, cx, screen_mode.reborrow(), name, !embedded, mode_set);
|
||||
let (mode, changed) = kept.screen.follow(&ctx, cx, screen_mode.reborrow(), Arc::clone(&name), !embedded, mode_set);
|
||||
if changed {
|
||||
kept.reveal.clear();
|
||||
}
|
||||
let dropped_before = matches!(dropped.reborrow().read(cx), Some(Mixed::Same(true)));
|
||||
// A mode change folds the drop-down slot away, whoever changed the mode.
|
||||
let mut is_dropped = dropped_before && !changed;
|
||||
|
||||
let host_only = mode.body_only();
|
||||
if let Some(root) = cx.command_chain().innermost(ScreenModeCommands::SCOPE.name()) {
|
||||
note_shell(&ctx, viewport, &window, root);
|
||||
}
|
||||
kept.reveal.apply(&take_chrome_toggles(&ctx, viewport, &window), host_only, allow_reveal);
|
||||
// A page takes no part in the reveal: the toggles are taken, so they are not replayed once it closes.
|
||||
let paged = page.is_some();
|
||||
let toggles = take_chrome_toggles(&ctx, viewport, &window);
|
||||
if !paged {
|
||||
kept.reveal.apply(&toggles, host_only, allow_reveal);
|
||||
}
|
||||
let only = kept.reveal.only(host_only);
|
||||
let pointer = pointer::frame(&ctx);
|
||||
let frozen = !pointer.buttons.is_empty() || any_open(&ctx, OpenFilter::Keys);
|
||||
let rtl = cx.env.direction().is_rtl();
|
||||
kept.reveal.track(Tracking::new(only, allow_reveal, edge_reveal), Aim::new(pointer.pos, frozen, cx.rect, rtl));
|
||||
if !paged {
|
||||
kept.reveal.track(Tracking::new(only, 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
|
||||
// cover the body.
|
||||
let visible: Vec<bool> =
|
||||
slots.iter().map(|placed| !bare && kept.reveal.shows(&placed.slot, placed.edge, only, allow_reveal, mode, false)).collect();
|
||||
// A pass with no title bar has no move band: the OS moves the window from nowhere in it.
|
||||
if !embedded && !slots.iter().zip(&visible).any(|(placed, shown)| placed.title && *shown) {
|
||||
// cover the body; the screen bar takes its room from it.
|
||||
let plan = |is_dropped: bool| {
|
||||
let visible: Vec<bool> = slots
|
||||
.iter()
|
||||
.map(|placed| !bare && !paged && kept.reveal.shows(&placed.slot, placed.edge, only, allow_reveal, mode, is_dropped))
|
||||
.collect();
|
||||
let claims: Vec<Claim> = slots
|
||||
.iter()
|
||||
.zip(&visible)
|
||||
.filter(|(_, shown)| **shown)
|
||||
.map(|(placed, _)| Claim {
|
||||
key: placed.slot.key(),
|
||||
edge: placed.edge,
|
||||
extent: placed.extent(&tokens),
|
||||
overlay: covers(&placed.slot, only),
|
||||
})
|
||||
.collect();
|
||||
let regions = layout(cx.rect, &claims, rtl);
|
||||
(visible, claims, regions)
|
||||
};
|
||||
let (mut visible, mut claims, mut regions) = plan(is_dropped);
|
||||
// A press in the body folds the drop-down slot away; a press in the slot itself, which lies over the body,
|
||||
// is the slot's own. Only the pass that receives the press sees it: a rerun pass of the frame has none.
|
||||
if is_dropped
|
||||
&& !paged
|
||||
&& let Some(press) = pointer.press
|
||||
&& regions.body.contains(press.origin)
|
||||
&& !slots
|
||||
.iter()
|
||||
.zip(&visible)
|
||||
.filter(|(placed, shown)| **shown && placed.slot.drops_down())
|
||||
.any(|(placed, _)| regions.slots.iter().any(|(key, rect)| *key == placed.slot.key() && rect.contains(press.origin)))
|
||||
{
|
||||
is_dropped = false;
|
||||
(visible, claims, regions) = plan(is_dropped);
|
||||
}
|
||||
if is_dropped != dropped_before {
|
||||
let event = EditEvent::set(Mixed::Same(dropped_before), is_dropped, Arc::from(""), None);
|
||||
let _ = dropped.reborrow().write(cx, &event);
|
||||
}
|
||||
let dropped_shown = slots.iter().zip(&visible).any(|(placed, shown)| *shown && placed.slot.drops_down());
|
||||
|
||||
// A pass with no title bar has no move band: the OS moves the window from nowhere in it. A page's band is
|
||||
// the move band of its pass, and a modal over the page keeps it through the window's caption regions.
|
||||
if !embedded && !paged && !slots.iter().zip(&visible).any(|(placed, shown)| placed.title && *shown) {
|
||||
super::title_bar::set_window_movable(&ctx, false);
|
||||
}
|
||||
let claims: Vec<Claim> = slots
|
||||
.iter()
|
||||
.zip(&visible)
|
||||
.filter(|(_, shown)| **shown)
|
||||
.map(|(placed, _)| Claim { key: placed.slot.key(), edge: placed.edge, extent: placed.extent(&tokens), overlay: only })
|
||||
.collect();
|
||||
let regions = layout(cx.rect, &claims, rtl);
|
||||
|
||||
let tabs = mode.tabs_visible() && document_tabs;
|
||||
let mut shell = ShellCx::new(window.clone(), if only { BodyMode::Only } else { BodyMode::Normal }, regions.clone())
|
||||
@@ -532,11 +606,14 @@ impl<'a, S> AppShell<'a, S> {
|
||||
for edge in [RevealEdge::Top, RevealEdge::Start, RevealEdge::End] {
|
||||
shell = shell.with_edge_reveal(edge, kept.reveal.edge(edge));
|
||||
}
|
||||
if paged {
|
||||
shell = shell.with_page_band(super::title_bar::page_band_room(cx, &tokens, cx.rect, !embedded));
|
||||
}
|
||||
let panels_hidden = kept.reveal.panels_hidden();
|
||||
|
||||
let rect_of = |key| regions.slots.iter().find(|(shown, _)| *shown == key).map_or(Rect::ZERO, |(_, rect)| *rect);
|
||||
let scope = shell.clone();
|
||||
let mut scope_region = ShellRegion::scope(shell).id_salt("shell");
|
||||
let mut scope_region = ShellRegion::scope(shell).with_mode_set(mode_set).id_salt("shell");
|
||||
if content_room.is_some() {
|
||||
scope_region = scope_region.sizing(Sizing::FillWidth);
|
||||
}
|
||||
@@ -544,9 +621,25 @@ impl<'a, S> AppShell<'a, S> {
|
||||
if unseen && !ui.is_sizing_pass() {
|
||||
return;
|
||||
}
|
||||
if let Some((scope, SlotBody(page))) = page.as_mut() {
|
||||
let pane = ShellPane::new("page");
|
||||
let pane = if content_room.is_some() { pane.at_content_height(regions.body) } else { pane.at(regions.body) };
|
||||
let mut region = ShellRegion::pane(pane).label(body_label.clone());
|
||||
region.props = region.props.command_scope(*scope);
|
||||
let shown = region.show(ui, |ui, bcx| page(ui, bcx, app));
|
||||
// With nothing focused the page takes keys beside the window's, as a modal's root does; the window's
|
||||
// shell record stays.
|
||||
// PLAN: assumed `commands::note_page_root(ctx: &Context, viewport: ViewportId, id: Id)` (chrome-w6)
|
||||
crate::runtime::commands::note_page_root(&ctx, viewport, shown.output.response.id);
|
||||
PageBand::new().show_over_page(ui);
|
||||
if let Some(dialogs) = WindowDialogs::existing(ui.ctx(), &window) {
|
||||
dialogs.run(ui);
|
||||
}
|
||||
return;
|
||||
}
|
||||
let mut show_slots = |ui: &mut Ui, covering: bool, app: &mut S| {
|
||||
for (placed, shown) in slots.iter_mut().zip(&visible) {
|
||||
if !*shown || only != covering {
|
||||
if !*shown || covers(&placed.slot, only) != covering {
|
||||
continue;
|
||||
}
|
||||
let extent = placed.extent(&tokens);
|
||||
@@ -568,13 +661,15 @@ impl<'a, S> AppShell<'a, S> {
|
||||
}
|
||||
};
|
||||
show_slots(ui, false, app);
|
||||
// Only a body-only shell paints behind its body (the scrim). Otherwise the body paints what it shows, and the gaps
|
||||
// between its parts (the dock's gutters) show the window's background.
|
||||
// Behind its body a shell paints the scrim where the user hid the chrome of a mode that shows it, else the
|
||||
// mode's surround (Focus's black). Otherwise the body paints what it shows, and the gaps between its parts
|
||||
// (the dock's gutters) show the window's background; Immersive's body fills the room with its own canvas.
|
||||
let pane = ShellPane::new("body");
|
||||
let pane = if content_room.is_some() { pane.at_content_height(regions.body) } else { pane.at(regions.body) };
|
||||
let mut center = ShellRegion::pane(pane).label(body_label.clone());
|
||||
if only {
|
||||
center = center.surface(SurfaceKind::Scrim);
|
||||
let surround = if only && !host_only { Some(SurfaceKind::Scrim) } else { mode.surround() };
|
||||
if let Some(surface) = surround {
|
||||
center = center.surface(surface);
|
||||
}
|
||||
let shown = center.show(ui, |ui, bcx| {
|
||||
if let Some(SlotBody(body)) = body.as_mut() {
|
||||
@@ -612,9 +707,14 @@ impl<'a, S> AppShell<'a, S> {
|
||||
.collect();
|
||||
edges.extend(scope.revealed_rects());
|
||||
kept.reveal.record(edges);
|
||||
let revealed = only && !regions.slots.is_empty();
|
||||
// The screen bar and the drop-down slot show by the mode, never by a reveal.
|
||||
let revealed = only
|
||||
&& slots
|
||||
.iter()
|
||||
.zip(&visible)
|
||||
.any(|(placed, shown)| *shown && !placed.slot.is_screen_bar() && !placed.slot.drops_down());
|
||||
*cx.keep::<ShellState>() = kept;
|
||||
Parts { regions, revealed, panels_hidden, mode }
|
||||
Parts { regions, revealed, panels_hidden, mode, dropped: dropped_shown }
|
||||
};
|
||||
let shown = match at {
|
||||
Some(rect) => root.show_at_taking_room(ui, rect, shell_body),
|
||||
@@ -628,6 +728,7 @@ impl<'a, S> AppShell<'a, S> {
|
||||
revealed: parts.revealed,
|
||||
panels_hidden: parts.panels_hidden,
|
||||
screen_mode: parts.mode,
|
||||
dropped: parts.dropped,
|
||||
},
|
||||
None => AppShellOutput {
|
||||
response,
|
||||
@@ -635,6 +736,7 @@ impl<'a, S> AppShell<'a, S> {
|
||||
revealed: false,
|
||||
panels_hidden: false,
|
||||
screen_mode: ScreenMode::default(),
|
||||
dropped: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,9 @@ use crate::contract::{Bind, Props as _, Show as _, ShowContainer as _};
|
||||
use crate::dialog::Dialog;
|
||||
use crate::display::Text;
|
||||
use crate::layout_components::Grid;
|
||||
use crate::runtime::commands::CommandScope;
|
||||
use crate::runtime::env::WindowKey;
|
||||
use crate::shell::{CanvasPanel, Slot};
|
||||
use crate::shell::{CanvasPanel, ScreenMode, ScreenModeButton, ScreenModeSet, Slot};
|
||||
use crate::testing::{Drive, StoryData, StoryOutput, stage, story};
|
||||
use craft_behavior::ColumnWidth;
|
||||
use egui::Ui;
|
||||
@@ -61,6 +62,72 @@ fn app_shell_canvas(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
.into()
|
||||
}
|
||||
|
||||
/// A document shell in `mode` of the Document set: a title bar and a tool rail that the mode hides, the screen bar
|
||||
/// with the screen-mode button, and a drop-down slot shown while `dropped` is set.
|
||||
fn document_shell(ui: &mut Ui, mode: ScreenMode, dropped: &mut bool) -> StoryOutput {
|
||||
let room = stage(ui);
|
||||
AppShell::embedded(WindowKey::new(format!("document-{mode:?}")))
|
||||
.mode_set(ScreenModeSet::Document)
|
||||
.screen_mode(Bind::given(mode))
|
||||
.dropped(Bind::bound(dropped))
|
||||
.title_bar(|ui, _, _| {
|
||||
Text::new("Title").show(ui);
|
||||
})
|
||||
.top(Slot::new("screen").screen_bar().label("Screen"), |ui, _, _| {
|
||||
Text::new("Page 1 of 3").show(ui);
|
||||
let _ = ScreenModeButton::new(mode).show(ui);
|
||||
})
|
||||
.top(Slot::new("ribbon").drops().label("Ribbon"), |ui, _, _| {
|
||||
Text::new("Ribbon").show(ui);
|
||||
})
|
||||
.start(Slot::new("tools").reveal().label("Tools"), |ui, _, _| {
|
||||
Text::new("Tools").show(ui);
|
||||
})
|
||||
.body(|ui, _, _| {
|
||||
Text::new("Document").show(ui);
|
||||
})
|
||||
.show_at(ui, room, &mut ())
|
||||
.into()
|
||||
}
|
||||
|
||||
/// Focus: the screen bar over the body on the black surround, with the drop-down slot shown until a press in the
|
||||
/// body folds it away.
|
||||
#[story(AppShell<'static, ()>, covers = [], drive = Drive::Never)]
|
||||
fn app_shell_focus(ui: &mut Ui, data: &mut StoryData) -> StoryOutput {
|
||||
let mut dropped = *data.value("dropped", true);
|
||||
let shown = document_shell(ui, ScreenMode::Focus, &mut dropped);
|
||||
*data.value("dropped", true) = dropped;
|
||||
shown
|
||||
}
|
||||
|
||||
/// Immersive: the screen bar over the body, which fills the room with its own canvas; no drop-down slot.
|
||||
#[story(AppShell<'static, ()>, covers = [], drive = Drive::Never)]
|
||||
fn app_shell_immersive(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
let mut dropped = false;
|
||||
document_shell(ui, ScreenMode::Immersive, &mut dropped)
|
||||
}
|
||||
|
||||
/// A full-window page in place of the slots and the body, with the band of the window's ends over its top.
|
||||
#[story(AppShell<'static, ()>, covers = [], drive = Drive::Never)]
|
||||
fn app_shell_page(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
let room = stage(ui);
|
||||
AppShell::embedded(WindowKey::new("page"))
|
||||
.title_bar(|ui, _, _| {
|
||||
Text::new("Title").show(ui);
|
||||
})
|
||||
.start(Slot::new("tools").reveal().label("Tools"), |ui, _, _| {
|
||||
Text::new("Tools").show(ui);
|
||||
})
|
||||
.body(|ui, _, _| {
|
||||
Text::new("Document").show(ui);
|
||||
})
|
||||
.page(true, CommandScope::APP, |ui, _, _| {
|
||||
Text::new("Print").show(ui);
|
||||
})
|
||||
.show_at(ui, room, &mut ())
|
||||
.into()
|
||||
}
|
||||
|
||||
#[story(ShellRegion, covers = [Default], drive = Drive::Never)]
|
||||
fn shell_region(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
ShellRegion::window()
|
||||
|
||||
@@ -52,6 +52,7 @@ impl<'a> RecentList<'a> {
|
||||
/// Shows the rows and reports what the user did.
|
||||
pub fn show(self, ui: &mut Ui) -> StartOutput {
|
||||
let _ = (self.recent, self.max_recent, self.empty, self.now, self.thumbnails, ui);
|
||||
|
||||
todo!("ch.C7")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,13 +56,15 @@ pub struct Slot {
|
||||
reveal: bool,
|
||||
label: Option<Label>,
|
||||
content: Option<u64>,
|
||||
screen_bar: bool,
|
||||
drops: bool,
|
||||
}
|
||||
|
||||
impl Slot {
|
||||
/// A slot with a key that is stable and unique in the window. It is visible and does not show in a reveal. Without a
|
||||
/// [`size`](Self::size) it takes the default of its edge: the title bar, options bar, status bar or rail width.
|
||||
pub fn new(key: SlotKey) -> Self {
|
||||
Self { key, size: None, visible: true, reveal: false, label: None, content: None }
|
||||
Self { key, size: None, visible: true, reveal: false, label: None, content: None, screen_bar: false, drops: false }
|
||||
}
|
||||
|
||||
/// The size along the slot's edge, in place of the default of the edge.
|
||||
@@ -90,14 +92,29 @@ impl Slot {
|
||||
self
|
||||
}
|
||||
|
||||
/// Marks the slot as the screen bar: it shows in Focus and Immersive and claims room as a non-overlay claim.
|
||||
pub fn screen_bar(self) -> Self {
|
||||
todo!("ch.C3")
|
||||
/// Marks the slot as the screen bar: it shows in Focus and Immersive, and only there, whatever its `visible` flag,
|
||||
/// and takes its room from the body although those modes show the body only. It needs no
|
||||
/// [`reveal`](Self::reveal).
|
||||
pub fn screen_bar(mut self) -> Self {
|
||||
self.screen_bar = true;
|
||||
self
|
||||
}
|
||||
|
||||
/// Marks the slot as the drop-down slot of Focus: it shows while the shell's `dropped` flag is set.
|
||||
pub fn drops(self) -> Self {
|
||||
todo!("ch.C3")
|
||||
/// Marks the slot as the drop-down slot of Focus: in Focus it shows while the shell's `dropped` flag is set and
|
||||
/// covers the body, leaving the body's rect as it is. A press in the body or a mode change clears the flag.
|
||||
pub fn drops(mut self) -> Self {
|
||||
self.drops = true;
|
||||
self
|
||||
}
|
||||
|
||||
/// Whether the slot is the screen bar ([`screen_bar`](Self::screen_bar)).
|
||||
pub fn is_screen_bar(&self) -> bool {
|
||||
self.screen_bar
|
||||
}
|
||||
|
||||
/// Whether the slot is the drop-down slot of Focus ([`drops`](Self::drops)).
|
||||
pub fn drops_down(&self) -> bool {
|
||||
self.drops
|
||||
}
|
||||
|
||||
/// The name of the slot's AccessKit region ("Options", "Tools", "Status").
|
||||
|
||||
@@ -157,10 +157,16 @@ impl Reveal {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether `slot` on `edge` shows: its `visible` flag in normal mode; in body-only mode, if it reveals and a Tab
|
||||
/// or edge reveal shows it.
|
||||
/// Whether `slot` on `edge` shows in `mode`. The screen bar shows in Focus and Immersive only; the drop-down slot in
|
||||
/// Focus while `dropped` is set. Any other slot: its `visible` flag in normal mode; in body-only mode, if it
|
||||
/// reveals and a Tab or edge reveal shows it.
|
||||
pub(crate) fn shows(&self, slot: &Slot, edge: PaneEdge, only: bool, allow_reveal: bool, mode: ScreenMode, dropped: bool) -> bool {
|
||||
let _ = (mode, dropped); // P3(chrome-w1): ch.C3
|
||||
if slot.is_screen_bar() {
|
||||
return mode.has_screen_bar();
|
||||
}
|
||||
if slot.drops_down() {
|
||||
return mode == ScreenMode::Focus && dropped;
|
||||
}
|
||||
if !only {
|
||||
return slot.is_visible();
|
||||
}
|
||||
|
||||
@@ -10,8 +10,9 @@ use craft_host::target::{Os, WindowState};
|
||||
use egui::Context;
|
||||
use std::sync::Arc;
|
||||
|
||||
/// The three screen modes. The shell keeps the current one in its `screen_mode` binding and maps it to the body mode,
|
||||
/// the document tabs and the scroll bars. Saved as `"standard"`, `"fullScreenWithMenuBar"` and `"fullScreen"`.
|
||||
/// The screen modes. The shell keeps the current one in its `screen_mode` binding and maps it to the body mode,
|
||||
/// the document tabs and the scroll bars; its [`ScreenModeSet`] says which of them the F key cycles through. Saved as
|
||||
/// `"standard"`, `"fullScreenWithMenuBar"`, `"fullScreen"`, `"focus"` and `"immersive"`.
|
||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
#[non_exhaustive]
|
||||
@@ -44,19 +45,28 @@ pub enum ScreenModeSet {
|
||||
impl ScreenModeSet {
|
||||
/// The modes the set cycles through, in order.
|
||||
pub fn modes(self) -> &'static [ScreenMode] {
|
||||
todo!("ch.C2")
|
||||
match self {
|
||||
ScreenModeSet::Panels => &[ScreenMode::Standard, ScreenMode::FullScreenWithMenuBar, ScreenMode::FullScreen],
|
||||
ScreenModeSet::Document => &[ScreenMode::Standard, ScreenMode::FullScreenWithMenuBar, ScreenMode::Focus, ScreenMode::Immersive],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ScreenMode {
|
||||
/// The surface around the body in this mode: `Some(Scrim)` for `Focus` only, `None` for every other mode.
|
||||
/// Immersive fills the room with the body's own canvas, so it paints nothing behind it.
|
||||
pub fn surround(self) -> Option<SurfaceKind> {
|
||||
todo!("ch.C2")
|
||||
(self == Self::Focus).then_some(SurfaceKind::Scrim)
|
||||
}
|
||||
|
||||
/// Whether the shell shows the body only.
|
||||
/// Whether the shell shows the body only: Full Screen, Focus and Immersive.
|
||||
pub fn body_only(self) -> bool {
|
||||
self == Self::FullScreen
|
||||
matches!(self, Self::FullScreen | Self::Focus | Self::Immersive)
|
||||
}
|
||||
|
||||
/// Whether the mode shows the screen bar: Focus and Immersive.
|
||||
pub(super) fn has_screen_bar(self) -> bool {
|
||||
matches!(self, Self::Focus | Self::Immersive)
|
||||
}
|
||||
|
||||
/// Whether the document tabs show.
|
||||
@@ -69,30 +79,29 @@ impl ScreenMode {
|
||||
self != Self::Standard
|
||||
}
|
||||
|
||||
/// The mode the F key selects: Standard, Full Screen With Menu Bar, Full Screen, Standard.
|
||||
/// The mode the F key selects: the one after this in `set`'s order, wrapping to the first. A mode outside the set
|
||||
/// steps to Standard.
|
||||
pub fn next(self, set: ScreenModeSet) -> Self {
|
||||
let _ = set; // P3(chrome-w1): ch.C2
|
||||
match self {
|
||||
Self::Standard => Self::FullScreenWithMenuBar,
|
||||
Self::FullScreenWithMenuBar => Self::FullScreen,
|
||||
Self::FullScreen => Self::Standard,
|
||||
Self::Focus | Self::Immersive => todo!("ch.C2"),
|
||||
}
|
||||
self.step(set, 1)
|
||||
}
|
||||
|
||||
/// The mode Shift+F selects.
|
||||
/// The mode Shift+F selects: the one before this in `set`'s order, wrapping to the last. A mode outside the set
|
||||
/// steps to Standard.
|
||||
pub fn previous(self, set: ScreenModeSet) -> Self {
|
||||
let _ = set; // P3(chrome-w1): ch.C2
|
||||
match self {
|
||||
Self::Standard => Self::FullScreen,
|
||||
Self::FullScreenWithMenuBar => Self::Standard,
|
||||
Self::FullScreen => Self::FullScreenWithMenuBar,
|
||||
Self::Focus | Self::Immersive => todo!("ch.C2"),
|
||||
self.step(set, set.modes().len().saturating_sub(1))
|
||||
}
|
||||
|
||||
/// The mode `by` places after this one in `set`'s order, wrapping.
|
||||
fn step(self, set: ScreenModeSet, by: usize) -> Self {
|
||||
let modes = set.modes();
|
||||
match modes.iter().position(|mode| *mode == self) {
|
||||
Some(at) => modes.get((at + by) % modes.len()).copied().unwrap_or_default(),
|
||||
None => Self::Standard,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The screen-mode commands of a window. The three modes are radio rows of View > Screen Mode; the cycle commands are
|
||||
/// The screen-mode commands of a window. The modes are radio rows of View > Screen Mode; the cycle commands are
|
||||
/// the F key and Shift+F. The window's shell takes them and writes its `screen_mode` binding.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, craft_ui_macros::CommandSet)]
|
||||
#[command(prefix = "screenMode", scope = "window")]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! `ScreenModeButton`: the status bar's screen mode button, a flyout of the three modes.
|
||||
//! `ScreenModeButton`: the status bar's screen mode button, a flyout of the shell's screen modes.
|
||||
|
||||
use super::screen_mode::{ScreenMode, ScreenModeCommands};
|
||||
use super::screen_mode::{ScreenMode, ScreenModeCommands, ScreenModeSet};
|
||||
use super::words::ShellWords;
|
||||
use crate::contract::{NoValue, Outcome, Props as _, Show as _};
|
||||
use crate::rails::{FlyoutButton, RailTool};
|
||||
@@ -10,8 +10,8 @@ use egui::{Response, Ui};
|
||||
#[cfg(feature = "testing")]
|
||||
mod stories;
|
||||
|
||||
/// A flyout button over the three screen modes, with `mode` marked: a click, Enter or Space cycles; a hold, a drag away
|
||||
/// or a right click lists the three modes without cycling. The face is the Cycle command's icon and tooltip; disabled
|
||||
/// A flyout button over the screen modes of the shell's set, with `mode` marked: a click, Enter or Space cycles; a
|
||||
/// hold, a drag away or a right click lists the modes without cycling. The face is the Cycle command's icon and tooltip; disabled
|
||||
/// while Cycle is disabled.
|
||||
#[must_use = "show the button with `show`"]
|
||||
#[derive(crate::contract::Pattern)]
|
||||
@@ -41,13 +41,15 @@ impl ScreenModeButton {
|
||||
ScreenModeButton { mode }
|
||||
}
|
||||
|
||||
/// Shows the button in `ui`. The rows are the radio commands of the three modes, so their marks and states come
|
||||
/// from the shell; the shell applies whichever command runs.
|
||||
/// Shows the button in `ui`. The rows are the radio commands of the modes of the shell's [`ScreenModeSet`], which
|
||||
/// the shell publishes to its regions (`Panels` outside a shell), so their marks and states come from the shell; the
|
||||
/// shell applies whichever command runs.
|
||||
pub fn show(self, ui: &mut Ui) -> ScreenModeButtonOutput {
|
||||
let modes = [ScreenMode::Standard, ScreenMode::FullScreenWithMenuBar, ScreenMode::FullScreen];
|
||||
let env = Env::of(ui);
|
||||
let modes = env.get::<ScreenModeSet>().modes();
|
||||
let tools: Vec<RailTool<ScreenMode>> = modes.iter().map(|mode| RailTool::new(*mode, ScreenModeCommands::of(*mode))).collect();
|
||||
// The shell's own word names the button when the Cycle command does not resolve.
|
||||
let name = Env::of(ui).words::<ShellWords>().screen_mode.clone();
|
||||
let name = env.words::<ShellWords>().screen_mode.clone();
|
||||
let out = FlyoutButton::new(&tools, &self.mode).label(name).hold_selects(false).click(ScreenModeCommands::Cycle).show(ui);
|
||||
ScreenModeButtonOutput { response: out.response }
|
||||
}
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
use super::ScreenModeButton;
|
||||
use crate::contract::Role;
|
||||
use crate::shell::ScreenMode;
|
||||
use crate::runtime::env::with_env;
|
||||
use crate::shell::{ScreenMode, ScreenModeSet};
|
||||
use crate::testing::{Drive, Fixture, StoryData, StoryOutput, story};
|
||||
use egui::Ui;
|
||||
|
||||
@@ -27,3 +28,17 @@ fn hold_button(fixture: &mut Fixture) {
|
||||
fn screen_mode_button_open(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
ScreenModeButton::new(ScreenMode::Standard).show(ui).into()
|
||||
}
|
||||
|
||||
/// The button in a document window's shell: its list holds Standard, Full Screen With Menu Bar, Focus and Immersive,
|
||||
/// open after a hold, with Focus marked.
|
||||
#[story(ScreenModeButton, covers = [], drive = Drive::Custom(hold_button))]
|
||||
fn screen_mode_button_document(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
with_env(
|
||||
ui,
|
||||
|overrides| {
|
||||
overrides.values.set(ScreenModeSet::Document);
|
||||
},
|
||||
|ui| ScreenModeButton::new(ScreenMode::Focus).show(ui),
|
||||
)
|
||||
.into()
|
||||
}
|
||||
|
||||
@@ -28,5 +28,6 @@ mod style;
|
||||
mod title;
|
||||
|
||||
pub use bar::{TitleBar, TitleBarOutput};
|
||||
pub(super) use page_band::{PageBand, room as page_band_room};
|
||||
pub use style::TitleBarStyle;
|
||||
pub use title::Title;
|
||||
|
||||
@@ -91,14 +91,106 @@ pub struct TitleBar<'a> {
|
||||
close: bool,
|
||||
}
|
||||
|
||||
/// The facts of the window a pass of the bar reads.
|
||||
struct Window {
|
||||
frame: Frame,
|
||||
maximized: bool,
|
||||
double_click: DoubleClick,
|
||||
ends: Ends,
|
||||
/// The facts of the window a pass of a bar or a page band reads.
|
||||
pub(super) struct Window {
|
||||
pub(super) frame: Frame,
|
||||
pub(super) maximized: bool,
|
||||
pub(super) double_click: DoubleClick,
|
||||
pub(super) ends: Ends,
|
||||
/// Whether the bar acts on the running window: false in an embedded shell.
|
||||
acts: bool,
|
||||
pub(super) acts: bool,
|
||||
/// The frame was given in place of the running window's (a story, a preview).
|
||||
pub(super) given: bool,
|
||||
/// The window the bar acts on is in OS full screen, where it has no ends.
|
||||
pub(super) full_screen: bool,
|
||||
}
|
||||
|
||||
/// The facts of the window a bar in `cx` draws: `frame` and `maximized` stand in for the running window's when given.
|
||||
/// In an embedded shell the bar acts on no window and reads it as a normal window.
|
||||
pub(super) fn window(cx: &BodyCx<'_>, frame: Option<Frame>, maximized: Option<bool>) -> Window {
|
||||
let acts = !cx.shell().is_some_and(|shell| shell.region().is_some());
|
||||
window_acting(cx, frame, maximized, acts)
|
||||
}
|
||||
|
||||
/// [`window`] for a bar that acts on the running window when `acts`, for a caller that knows it before the shell
|
||||
/// around it is set (the shell itself).
|
||||
pub(super) fn window_acting(cx: &BodyCx<'_>, frame: Option<Frame>, maximized: Option<bool>, acts: bool) -> Window {
|
||||
let ctx = cx.memory.ctx().clone();
|
||||
let shell = windows::shell_of(&ctx, pass::current_viewport(&ctx));
|
||||
let given = frame.is_some();
|
||||
let frame = frame.unwrap_or_else(|| WindowHost::of(&ctx).frame());
|
||||
let state = if acts { shell.window.state } else { WindowState::Normal };
|
||||
let full_screen = state == WindowState::Fullscreen;
|
||||
let rtl = cx.env.direction().is_rtl();
|
||||
let ends = Ends::of(&frame, !full_screen, rtl);
|
||||
Window {
|
||||
frame,
|
||||
maximized: maximized.unwrap_or(state == WindowState::Maximized),
|
||||
double_click: shell.double_click,
|
||||
ends,
|
||||
acts,
|
||||
given,
|
||||
full_screen,
|
||||
}
|
||||
}
|
||||
|
||||
/// Acts on a double click on the move band of the container `cx` runs in, once a pass: maximizes, restores or
|
||||
/// minimizes the window as the platform's setting says. A bar that acts on no window does nothing.
|
||||
pub(super) fn act_on_double_click(cx: &BodyCx<'_>, window: &Window) {
|
||||
if window.acts
|
||||
&& cx.band_double_pressed()
|
||||
&& let Some(action) = windows::double_click_action(&window.frame, window.double_click, window.maximized)
|
||||
{
|
||||
let ctx = cx.memory.ctx().clone();
|
||||
WindowHost::of(&ctx).act(pass::current_viewport(&ctx), action);
|
||||
}
|
||||
}
|
||||
|
||||
/// Shows one end's room and buttons, and acts on a click: Minimize and Maximize go to the window the bar acts on.
|
||||
/// Returns the caption clicked in this pass; the caller decides what Close means.
|
||||
pub(super) fn show_end(ui: &mut Ui, cx: &BodyCx<'_>, end: &End, window: &Window) -> Option<Caption> {
|
||||
let tokens = Env::of(ui).tokens.clone();
|
||||
let height = SlotSize::TitleBar.resolve(&tokens);
|
||||
let pad = tokens.tokens().space.pad.regular;
|
||||
// The running window's captions take the glyphs of the desktop's icon theme; a frame given in place of the
|
||||
// window's (a story, a preview) draws the family's own.
|
||||
let ctx = cx.memory.ctx().clone();
|
||||
let icons = if window.acts && !window.given { desktop_icons(&ctx) } else { None };
|
||||
let mut buttons: Vec<Placed<'_>> = end
|
||||
.captions
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(index, slot)| {
|
||||
let mut button = CaptionButton::new(slot.caption, window.ends.family).maximized(window.maximized);
|
||||
if let Some(icons) = &icons {
|
||||
button = button.icons(icons);
|
||||
}
|
||||
if let Some(edge) = slot.end {
|
||||
button = button.outermost(edge);
|
||||
}
|
||||
Placed::new(("caption", index), button)
|
||||
})
|
||||
.collect();
|
||||
arrange(ui, &Strip::padded(end, height, pad), &mut buttons);
|
||||
let (host, viewport) = (WindowHost::of(&ctx), pass::current_viewport(&ctx));
|
||||
let mut clicked = None;
|
||||
for (slot, placed) in end.captions.iter().zip(&buttons) {
|
||||
if !placed.response().is_some_and(Response::clicked) {
|
||||
continue;
|
||||
}
|
||||
clicked = Some(slot.caption);
|
||||
match slot.caption {
|
||||
Caption::Minimize | Caption::Maximize if !window.acts => {}
|
||||
Caption::Minimize => {
|
||||
host.act(viewport, WindowAction::Minimize);
|
||||
}
|
||||
Caption::Maximize => {
|
||||
host.act(viewport, WindowAction::SetMaximized(!window.maximized));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
clicked
|
||||
}
|
||||
|
||||
impl<'a> TitleBar<'a> {
|
||||
@@ -137,72 +229,27 @@ impl<'a> TitleBar<'a> {
|
||||
let native_hidden =
|
||||
!self.title_when_native && matches!(self.frame.clone().unwrap_or_else(|| WindowHost::of(ui.ctx()).frame()), Frame::Native);
|
||||
self.title = Some(title.clone());
|
||||
self.trailing(trailing)
|
||||
let mut activated = false;
|
||||
let mut out = self
|
||||
.trailing(trailing)
|
||||
.show(ui, |ui, cx| {
|
||||
leading(ui, cx);
|
||||
if !native_hidden {
|
||||
let rtl = cx.env.direction().is_rtl();
|
||||
let margin = cx.gap().unwrap_or_default();
|
||||
title.show_in_gap(ui, cx, cx.rect.width(), centre_line(cx, rtl), margin);
|
||||
activated = title.show_in_gap(ui, cx, cx.rect.width(), centre_line(cx, rtl), margin);
|
||||
}
|
||||
})
|
||||
.output
|
||||
.output;
|
||||
out.title_activated = activated;
|
||||
out
|
||||
}
|
||||
|
||||
fn window(&self, cx: &BodyCx<'_>) -> Window {
|
||||
let ctx = cx.memory.ctx().clone();
|
||||
let shell = windows::shell_of(&ctx, pass::current_viewport(&ctx));
|
||||
let frame = self.frame.clone().unwrap_or_else(|| WindowHost::of(&ctx).frame());
|
||||
let acts = !cx.shell().is_some_and(|shell| shell.region().is_some());
|
||||
let state = if acts { shell.window.state } else { WindowState::Normal };
|
||||
let rtl = cx.env.direction().is_rtl();
|
||||
let ends = Ends::of(&frame, state != WindowState::Fullscreen, rtl);
|
||||
Window { frame, maximized: self.maximized.unwrap_or(state == WindowState::Maximized), double_click: shell.double_click, ends, acts }
|
||||
}
|
||||
|
||||
/// Shows one end's room and buttons, and acts on a click: Minimize and Maximize go to the window the bar acts on,
|
||||
/// Close is reported.
|
||||
fn show_end(&mut self, ui: &mut Ui, cx: &BodyCx<'_>, end: &End, window: &Window) {
|
||||
let tokens = Env::of(ui).tokens.clone();
|
||||
let height = SlotSize::TitleBar.resolve(&tokens);
|
||||
let pad = tokens.tokens().space.pad.regular;
|
||||
// The running window's captions take the glyphs of the desktop's icon theme; a frame given in place of the
|
||||
// window's (a story, a preview) draws the family's own.
|
||||
let ctx = cx.memory.ctx().clone();
|
||||
let icons = if window.acts && self.frame.is_none() { desktop_icons(&ctx) } else { None };
|
||||
let mut buttons: Vec<Placed<'_>> = end
|
||||
.captions
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(index, slot)| {
|
||||
let mut button = CaptionButton::new(slot.caption, window.ends.family).maximized(window.maximized);
|
||||
if let Some(icons) = &icons {
|
||||
button = button.icons(icons);
|
||||
}
|
||||
if let Some(edge) = slot.end {
|
||||
button = button.outermost(edge);
|
||||
}
|
||||
Placed::new(("caption", index), button)
|
||||
})
|
||||
.collect();
|
||||
arrange(ui, &Strip::padded(end, height, pad), &mut buttons);
|
||||
let (host, viewport) = (WindowHost::of(&ctx), pass::current_viewport(&ctx));
|
||||
for (slot, placed) in end.captions.iter().zip(&buttons) {
|
||||
if !placed.response().is_some_and(Response::clicked) {
|
||||
continue;
|
||||
}
|
||||
self.clicked = Some(slot.caption);
|
||||
match slot.caption {
|
||||
Caption::Minimize | Caption::Maximize if !window.acts => {}
|
||||
Caption::Minimize => {
|
||||
host.act(viewport, WindowAction::Minimize);
|
||||
}
|
||||
Caption::Maximize => {
|
||||
host.act(viewport, WindowAction::SetMaximized(!window.maximized));
|
||||
}
|
||||
Caption::Close => self.close = true,
|
||||
_ => {}
|
||||
}
|
||||
/// Shows one end of the bar and records its clicked caption: Close is reported, never acted on.
|
||||
fn end_of(&mut self, ui: &mut Ui, cx: &BodyCx<'_>, end: &End, window: &Window) {
|
||||
if let Some(caption) = show_end(ui, cx, end, window) {
|
||||
self.clicked = Some(caption);
|
||||
self.close |= caption == Caption::Close;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -256,15 +303,9 @@ impl Container for TitleBar<'_> {
|
||||
/// The start end: the room for the traffic lights, or the captions at the start edge. A double click on the free
|
||||
/// band acts here, once a pass.
|
||||
fn header(&mut self, ui: &mut Ui, cx: &mut BodyCx<'_>) {
|
||||
let window = self.window(cx);
|
||||
if window.acts
|
||||
&& cx.band_double_pressed()
|
||||
&& let Some(action) = windows::double_click_action(&window.frame, window.double_click, window.maximized)
|
||||
{
|
||||
let ctx = cx.memory.ctx().clone();
|
||||
WindowHost::of(&ctx).act(pass::current_viewport(&ctx), action);
|
||||
}
|
||||
self.show_end(ui, cx, &window.ends.start, &window);
|
||||
let window = window(cx, self.frame.clone(), self.maximized);
|
||||
act_on_double_click(cx, &window);
|
||||
self.end_of(ui, cx, &window.ends.start, &window);
|
||||
}
|
||||
|
||||
/// The end end: the trailing content, then the room for the lights or the captions at the end edge.
|
||||
@@ -272,8 +313,8 @@ impl Container for TitleBar<'_> {
|
||||
if let Some(RegionBody(trailing)) = self.trailing.as_mut() {
|
||||
trailing(ui, cx);
|
||||
}
|
||||
let window = self.window(cx);
|
||||
self.show_end(ui, cx, &window.ends.end, &window);
|
||||
let window = window(cx, self.frame.clone(), self.maximized);
|
||||
self.end_of(ui, cx, &window.ends.end, &window);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,15 @@ fn title_bar_inset(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
TitleBar::new().frame(Frame::Inset(MacInset::default())).show_titled(ui, Title::new("Landscape.psd"), menu, tools).into()
|
||||
}
|
||||
|
||||
/// A title that is a button: it reads as text until hovered, and a click or Enter reports it in
|
||||
/// `TitleBarOutput::title_activated` (a document's rename and location popup).
|
||||
#[story(TitleBar<'static>, covers = [], drive = Drive::Never)]
|
||||
fn title_bar_action_title(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
let frame = captions(CaptionFamily::Windows, &[], &[Caption::Minimize, Caption::Maximize, Caption::Close]);
|
||||
let title = Title::unsaved("Landscape.psd").action("Rename or move the document");
|
||||
TitleBar::new().frame(frame).show_titled(ui, title, menu, tools).into()
|
||||
}
|
||||
|
||||
#[story(TitleBar<'static>, covers = [], drive = Drive::Never)]
|
||||
fn title_bar_native(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
|
||||
TitleBar::new().frame(Frame::Native).title_when_native().show_titled(ui, Title::new("Landscape.psd"), menu, tools).into()
|
||||
|
||||
@@ -1,5 +1,123 @@
|
||||
//! `PageBand`: the move band the shell's page shows over the window.
|
||||
|
||||
/// The band over a shown page that moves the window, with the window's ends.
|
||||
#[allow(dead_code)] // P3(chrome-w1): ch.C5
|
||||
pub(crate) struct PageBand;
|
||||
use super::bar::{Window, act_on_double_click, show_end, window, window_acting};
|
||||
use super::measure::End;
|
||||
use crate::contract::{
|
||||
BodyCx, BodyLayout, Common, Component, Container, ContainerProps, Cx, DragBand, EndRegion, HeaderRegion, Pad, Props as _, Role,
|
||||
ShowContainer as _,
|
||||
};
|
||||
use crate::runtime::egui::pass;
|
||||
use crate::runtime::env::{Env, PageBandRoom, ShellEntry};
|
||||
use crate::runtime::windows::{WindowAction, WindowHost};
|
||||
use crate::shell::{Caption, ShellWords};
|
||||
use crate::style::{ComponentStyle, StyleCx, UiTokens};
|
||||
use craft_behavior::{Metrics, Sense};
|
||||
use egui::{Rect, Response, Ui, vec2};
|
||||
|
||||
/// The room of the page band of a shell whose window fills `window` in this pass: the title-bar-high strip at its top,
|
||||
/// with the room the window's ends take at either end (the traffic lights' inset or the caption buttons; none for a
|
||||
/// native frame). `None` while the window is in OS full screen, where it has no ends and the OS moves nothing. `acts`
|
||||
/// is false for an embedded shell, whose band is a picture of a window's.
|
||||
pub(crate) fn room(cx: &BodyCx<'_>, tokens: &UiTokens, window: Rect, acts: bool) -> Option<PageBandRoom> {
|
||||
let facts = window_acting(cx, None, None, acts);
|
||||
if facts.full_screen {
|
||||
return None;
|
||||
}
|
||||
let height = crate::shell::SlotSize::TitleBar.resolve(tokens).min(window.height());
|
||||
let rect = Rect::from_min_size(window.min, vec2(window.width(), height));
|
||||
Some(PageBandRoom { rect, start: taken(&facts.ends.start), end: taken(&facts.ends.end) })
|
||||
}
|
||||
|
||||
/// The width one end takes: the lights' inset, then its caption buttons.
|
||||
fn taken(end: &End) -> f32 {
|
||||
end.inset + end.captions.iter().map(|slot| slot.rect.width()).sum::<f32>()
|
||||
}
|
||||
|
||||
/// The style of the page band: the page shows through it.
|
||||
#[derive(Clone, Debug, Default, PartialEq, ComponentStyle)]
|
||||
#[non_exhaustive]
|
||||
pub(crate) struct PageBandStyle {
|
||||
#[style(metrics)]
|
||||
metrics: Metrics,
|
||||
}
|
||||
|
||||
/// The band over a shown page that moves the window, with the window's ends: the traffic lights' room or the caption
|
||||
/// buttons. It has no title and no content of its own; the page under it reads the room of its ends with
|
||||
/// `ShellCx::page_band` and keeps its own controls clear of the free band. A double click acts as on the title bar.
|
||||
/// In an embedded shell it is a picture of a window: no move band and no window command.
|
||||
#[derive(crate::contract::Component, crate::contract::Props)]
|
||||
#[component(container)]
|
||||
pub(crate) struct PageBand {
|
||||
#[common]
|
||||
common: Common,
|
||||
#[container]
|
||||
props: ContainerProps,
|
||||
}
|
||||
|
||||
impl PageBand {
|
||||
/// A band with the window's ends at the room the shell gives it.
|
||||
pub(crate) fn new() -> Self {
|
||||
// No surface: the page shows through the band.
|
||||
let props = ContainerProps::new()
|
||||
.pad(Pad::None)
|
||||
.layout(BodyLayout::row())
|
||||
.header(HeaderRegion::new().band(DragBand::Move).inline(true))
|
||||
.end(EndRegion::new());
|
||||
PageBand { common: Common::new(), props }
|
||||
}
|
||||
|
||||
/// Shows the band at the room of the shell `ui` runs in ([`ShellCx::page_band`](crate::runtime::env::ShellCx::page_band));
|
||||
/// nothing when no page band is set.
|
||||
pub(crate) fn show_over_page(self, ui: &mut Ui) {
|
||||
let env = Env::of(ui);
|
||||
let Some(room) = env.get::<ShellEntry>().0.and_then(|shell| shell.page_band()) else { return };
|
||||
let label = env.words::<ShellWords>().title_bar.clone();
|
||||
let _ = self.label(label).show_at(ui, room.rect, |_, _| {});
|
||||
}
|
||||
|
||||
/// Shows one end of the band; its Close asks the window it acts on to close, through the close guard of a root
|
||||
/// window (`WindowAction::Close`), since the band has no output to report it through.
|
||||
fn end_of(ui: &mut Ui, cx: &BodyCx<'_>, end: &End, facts: &Window) {
|
||||
if show_end(ui, cx, end, facts) == Some(Caption::Close) && facts.acts {
|
||||
let ctx = cx.memory.ctx().clone();
|
||||
WindowHost::of(&ctx).act(pass::current_viewport(&ctx), WindowAction::Close);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Component for PageBand {
|
||||
const ROLE: Role = Role::GROUP;
|
||||
const PARTS: bool = false;
|
||||
const STOPS: bool = false;
|
||||
const OVERLAYS: bool = false;
|
||||
type Style = PageBandStyle;
|
||||
type Output = Response;
|
||||
|
||||
fn style(_: &StyleCx<'_>, _: PageBandStyleKey) -> PageBandStyle {
|
||||
PageBandStyle::default()
|
||||
}
|
||||
|
||||
fn sense(&self) -> Sense {
|
||||
Sense::empty()
|
||||
}
|
||||
|
||||
fn finish(self, cx: Cx<'_, Self>) -> Response {
|
||||
cx.response.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl Container for PageBand {
|
||||
/// The start end: the lights' room or the captions at the start edge. A double click on the free band acts here,
|
||||
/// once a pass.
|
||||
fn header(&mut self, ui: &mut Ui, cx: &mut BodyCx<'_>) {
|
||||
let facts = window(cx, None, None);
|
||||
act_on_double_click(cx, &facts);
|
||||
Self::end_of(ui, cx, &facts.ends.start, &facts);
|
||||
}
|
||||
|
||||
/// The end end: the lights' room or the captions at the end edge.
|
||||
fn end(&mut self, ui: &mut Ui, cx: &mut BodyCx<'_>) {
|
||||
let facts = window(cx, None, None);
|
||||
Self::end_of(ui, cx, &facts.ends.end, &facts);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
//! `Title`: the document title the bar shows in the free gap between its leading content and its trailing end.
|
||||
|
||||
use crate::contract::{BodyCx, Props as _, WordSetCx as _};
|
||||
use crate::buttons::Button;
|
||||
use crate::contract::{BodyCx, Props as _, WordSetCx as _, clicked};
|
||||
use crate::display::{Elide, Text};
|
||||
use crate::layout::{Placed, arrange};
|
||||
use crate::runtime::env::Label;
|
||||
use crate::shell::{ShellWords, slots};
|
||||
use craft_behavior::Arrangement;
|
||||
use craft_theme::Variant;
|
||||
use egui::{Rect, Ui, Vec2, vec2};
|
||||
|
||||
/// The title of the window's document, with the mark that says it has unsaved changes.
|
||||
@@ -18,24 +20,27 @@ use egui::{Rect, Ui, Vec2, vec2};
|
||||
pub struct Title {
|
||||
text: String,
|
||||
unsaved: bool,
|
||||
/// The tooltip of a title that is a button; `None` for a title that is text.
|
||||
action: Option<Label>,
|
||||
}
|
||||
|
||||
impl Title {
|
||||
/// A title for a document with no unsaved changes.
|
||||
pub fn new(text: impl Into<String>) -> Self {
|
||||
Title { text: text.into(), unsaved: false }
|
||||
Title { text: text.into(), unsaved: false, action: None }
|
||||
}
|
||||
|
||||
/// A title for a document with unsaved changes.
|
||||
pub fn unsaved(text: impl Into<String>) -> Self {
|
||||
Title { text: text.into(), unsaved: true }
|
||||
Title { text: text.into(), unsaved: true, action: None }
|
||||
}
|
||||
|
||||
/// Makes the title a focusable button named by the shown title, with `tooltip`. Without it the title is text.
|
||||
/// Makes the title a focusable button named by the shown title, with `tooltip`; the bar reports its activation in
|
||||
/// `TitleBarOutput::title_activated`. Without it the title is text.
|
||||
#[must_use]
|
||||
pub fn action(self, tooltip: impl Into<Label>) -> Self {
|
||||
let _ = (self, tooltip.into());
|
||||
todo!("ch.C6")
|
||||
pub fn action(mut self, tooltip: impl Into<Label>) -> Self {
|
||||
self.action = Some(tooltip.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// The text shown: the title, followed by an asterisk while the document has unsaved changes.
|
||||
@@ -60,15 +65,33 @@ impl Title {
|
||||
}
|
||||
|
||||
/// Shows the title in the rest of `ui`, which is the bar body's row after the leading content. `body_width` is the
|
||||
/// body's whole width and `centre` the window's centre line from the body's start edge.
|
||||
pub(super) fn show_in_gap(&self, ui: &mut Ui, cx: &BodyCx<'_>, body_width: f32, centre: f32, margin: f32) {
|
||||
/// body's whole width and `centre` the window's centre line from the body's start edge. Returns whether a title with
|
||||
/// an action was activated in this pass.
|
||||
pub(super) fn show_in_gap(&self, ui: &mut Ui, cx: &BodyCx<'_>, body_width: f32, centre: f32, margin: f32) -> bool {
|
||||
let words = cx.words::<ShellWords>();
|
||||
let mut text = Text::new(self.shown(&words)).elide(Elide::End);
|
||||
if self.unsaved {
|
||||
text = text.description(words.unsaved.as_str());
|
||||
}
|
||||
let gap = Gap { body_width, centre, margin };
|
||||
arrange(ui, &gap, &mut [Placed::new("title", text)]);
|
||||
let description = self.unsaved.then(|| words.unsaved.as_str().to_owned());
|
||||
match &self.action {
|
||||
Some(tooltip) => {
|
||||
// A ghost button has no fill until hovered, so the title reads as text; its label is cut with an
|
||||
// ellipsis when the gap is too narrow, as the text is.
|
||||
let mut button = Button::new(self.shown(&words)).variant(Variant::GHOST).tooltip(tooltip.clone());
|
||||
if let Some(description) = description {
|
||||
button = button.description(description);
|
||||
}
|
||||
let mut placed = [Placed::new("title", button)];
|
||||
arrange(ui, &gap, &mut placed);
|
||||
placed.first().and_then(Placed::response).is_some_and(clicked)
|
||||
}
|
||||
None => {
|
||||
let mut text = Text::new(self.shown(&words)).elide(Elide::End);
|
||||
if let Some(description) = description {
|
||||
text = text.description(description);
|
||||
}
|
||||
arrange(ui, &gap, &mut [Placed::new("title", text)]);
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,18 +1,28 @@
|
||||
//! The app shell's named slots: a bar in a top or bottom slot fills it
|
||||
//! with its members on the slot's middle, and a slot with a content version settles.
|
||||
//! with its members on the slot's middle, and a slot with a content version settles. A full-window page hides the
|
||||
//! slots and the body, and its band keeps the window's ends and moves the window.
|
||||
|
||||
use craft_host::target::ShellInfo;
|
||||
use craft_ui::bars::{Bar, BarKind};
|
||||
use craft_ui::buttons::Button;
|
||||
use craft_ui::contract::{Show as _, ShowContainer as _};
|
||||
use craft_ui::contract::{Bind, CommandSet, Props as _, Show as _, ShowContainer as _};
|
||||
use craft_ui::dialog::Dialog;
|
||||
use craft_ui::display::Text;
|
||||
use craft_ui::layout_components::{Row, Stack};
|
||||
use craft_ui::runtime::env::WindowKey;
|
||||
use craft_ui::shell::{AppShell, Title, TitleBar, slots};
|
||||
use craft_ui::runtime::InstallSpec;
|
||||
use craft_ui::runtime::commands::{CommandScope, Commands as _};
|
||||
use craft_ui::runtime::env::{PageBandRoom, WindowKey};
|
||||
use craft_ui::runtime::windows::{WindowHit, WindowHost};
|
||||
use craft_ui::shell::{AppShell, Caption, CaptionFamily, Captions, Frame, MacInset, Slot, Title, TitleBar, slots};
|
||||
use craft_ui::testing::pointer::{press, release};
|
||||
use craft_ui::testing::windows::NoWindows;
|
||||
use craft_ui::testing::{Fixture, Frames, trial};
|
||||
use egui::{Rect, Vec2};
|
||||
use craft_ui_test_kit::windows::Windows;
|
||||
use craft_window::policy::{Decision, Desktop, DesktopKind};
|
||||
use egui::{Event, Key, Modifiers, Rect, Vec2, ViewportId};
|
||||
use std::cell::Cell;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
/// What the options-bar trial saw: the slot, the bar, a member of the bar and a member of a row nested in it.
|
||||
#[derive(Clone, Copy)]
|
||||
@@ -137,3 +147,178 @@ fn a_slot_with_a_content_version_runs_only_when_its_version_changes() {
|
||||
assert!(frame(&mut frames, vec![]) > 0, "a new version runs the slot");
|
||||
assert_eq!(frame(&mut frames, vec![]), 0, "and it settles at it");
|
||||
}
|
||||
|
||||
/// What the page trial's shell ran in one frame, and the band room the page read.
|
||||
#[derive(Default)]
|
||||
struct PageRuns {
|
||||
band: Option<PageBandRoom>,
|
||||
page: usize,
|
||||
body: usize,
|
||||
slots: usize,
|
||||
shown: usize,
|
||||
}
|
||||
|
||||
/// A window whose frame is `frame`, as the running platform would decide it.
|
||||
fn framed(frame: Frame) -> Windows {
|
||||
let desktop = Desktop { kind: DesktopKind::Other, ssd: None, gtk_theme: None, icon_theme: None };
|
||||
Windows::with(InstallSpec::new(ShellInfo::default(), Arc::new(NoWindows)).frame(Decision { frame, overridden: None, desktop }))
|
||||
}
|
||||
|
||||
/// One frame with `events` of a window shell with a title bar, a rail and a body, and a page shown over them; with
|
||||
/// `dialog` the page has a modal dialog open. Returns the commands the frame sent to the root window.
|
||||
fn page_frame(windows: &Windows, runs: &mut PageRuns, dialog: bool, events: Vec<Event>) -> Vec<egui::ViewportCommand> {
|
||||
*runs = PageRuns::default();
|
||||
let out = windows.frame(events, vec![], |ui| {
|
||||
let out = AppShell::new(WindowKey::main())
|
||||
.title_bar(|ui, _, runs: &mut PageRuns| {
|
||||
runs.slots += 1;
|
||||
Text::new("Title").show(ui);
|
||||
})
|
||||
.start(Slot::new("tools"), |ui, _, runs: &mut PageRuns| {
|
||||
runs.slots += 1;
|
||||
Text::new("Tools").show(ui);
|
||||
})
|
||||
.body(|ui, _, runs: &mut PageRuns| {
|
||||
runs.body += 1;
|
||||
Text::new("Document").show(ui);
|
||||
})
|
||||
.page(true, CommandScope::APP, |ui, cx, runs: &mut PageRuns| {
|
||||
runs.page += 1;
|
||||
runs.band = cx.shell().and_then(|shell| shell.page_band());
|
||||
Text::new("Print").show(ui);
|
||||
if dialog {
|
||||
Dialog::new("Page setup").opened(Bind::given(true)).show(ui, |ui, _| {
|
||||
Text::new("Setup").show(ui);
|
||||
});
|
||||
}
|
||||
})
|
||||
.show(ui, &mut *runs);
|
||||
runs.shown = out.regions.slots.len();
|
||||
});
|
||||
out.commands.into_iter().filter(|(viewport, _)| *viewport == ViewportId::ROOT).map(|(_, command)| command).collect()
|
||||
}
|
||||
|
||||
/// The widths of the caption buttons the root window's last pass named, in the order of `names`.
|
||||
fn caption_widths(windows: &Windows, runs: &mut PageRuns, names: &[&str]) -> Vec<f32> {
|
||||
let out = windows.frame(vec![], vec![], |ui| {
|
||||
let _ = AppShell::new(WindowKey::main())
|
||||
.body(|ui, _, _: &mut PageRuns| {
|
||||
Text::new("Document").show(ui);
|
||||
})
|
||||
.page(true, CommandScope::APP, |ui, _, _: &mut PageRuns| {
|
||||
Text::new("Print").show(ui);
|
||||
})
|
||||
.show(ui, &mut *runs);
|
||||
});
|
||||
let tree = &out.trees.iter().rev().find(|(viewport, _)| *viewport == ViewportId::ROOT).expect("the root pass ran").1;
|
||||
let buttons = tree.with_role(craft_ui::contract::Role::BUTTON);
|
||||
names
|
||||
.iter()
|
||||
.map(|name| {
|
||||
buttons
|
||||
.iter()
|
||||
.find(|key| tree.name_of(**key) == Some(*name))
|
||||
.and_then(|key| tree.bounds_of(*key))
|
||||
.map_or(0.0, |rect| rect.width())
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// While a page shows, no slot and no body run and no slot is laid out. The band over the page keeps the window's
|
||||
/// ends: under an Inset frame its start room is the traffic lights' inset, under an Integrated frame its end room is
|
||||
/// the caption buttons it shows. Its free part moves the window, and a modal over the page gets a drag strip over it.
|
||||
#[trial]
|
||||
fn a_page_hides_the_slots_and_its_band_keeps_the_window_ends_and_moves_the_window() {
|
||||
let mut runs = PageRuns::default();
|
||||
|
||||
let inset = MacInset::default();
|
||||
let windows = framed(Frame::Inset(inset));
|
||||
for _ in 0..3 {
|
||||
page_frame(&windows, &mut runs, false, vec![]);
|
||||
}
|
||||
assert!(runs.page > 0, "the page runs");
|
||||
assert_eq!((runs.slots, runs.body, runs.shown), (0, 0, 0), "no slot and no body runs while the page shows");
|
||||
let band = runs.band.expect("the page reads its band");
|
||||
assert_eq!(band.rect.top(), 0.0, "the band lies at the window's top: {band:?}");
|
||||
assert_eq!((band.start, band.end), (inset.leading, 0.0), "under an Inset frame the start room is the lights' inset");
|
||||
|
||||
let layout = craft_window::Layout { left: vec![], right: vec![Caption::Minimize, Caption::Maximize, Caption::Close] };
|
||||
let windows = framed(Frame::Integrated(Captions { family: CaptionFamily::Windows, layout }));
|
||||
for _ in 0..3 {
|
||||
page_frame(&windows, &mut runs, false, vec![]);
|
||||
}
|
||||
let band = runs.band.expect("the page reads its band");
|
||||
let widths = caption_widths(&windows, &mut runs, &["Minimize", "Maximize", "Close"]);
|
||||
assert!(widths.iter().all(|width| *width > 0.0), "the band shows the window's caption buttons: {widths:?}");
|
||||
let captions: f32 = widths.iter().sum();
|
||||
assert_eq!(band.start, 0.0, "the start end holds nothing: {band:?}");
|
||||
assert!((band.end - captions).abs() <= 0.5, "the end room {} is the caption buttons' {captions}", band.end);
|
||||
|
||||
// The free band between the ends moves the window.
|
||||
let free = egui::pos2((band.rect.left() + band.start + band.rect.right() - band.end) / 2.0, band.rect.center().y);
|
||||
for _ in 0..2 {
|
||||
page_frame(&windows, &mut runs, false, vec![]);
|
||||
}
|
||||
let host = WindowHost::of(&windows.ctx);
|
||||
let regions = host.caption_regions(ViewportId::ROOT).expect("the band registered its parts");
|
||||
assert_eq!(regions.hit(free), Some(WindowHit::Move), "the free band is a drag area: {regions:?}");
|
||||
let bands = regions.moves.iter().filter(|area| band.rect.contains_rect(**area)).count();
|
||||
let to = free + egui::vec2(40.0, 0.0);
|
||||
let mut sent = Vec::new();
|
||||
for events in [vec![craft_ui::testing::pointer::moved(free)], vec![press(free)], vec![craft_ui::testing::pointer::moved(to)], vec![release(to)]]
|
||||
{
|
||||
sent.extend(page_frame(&windows, &mut runs, false, events));
|
||||
}
|
||||
assert!(sent.contains(&egui::ViewportCommand::StartDrag), "a drag of the free band moves the window: {sent:?}");
|
||||
|
||||
// The strips read the last complete pass: the first publishes the band's drag area, the next ones the strips.
|
||||
for _ in 0..4 {
|
||||
page_frame(&windows, &mut runs, true, vec![]);
|
||||
}
|
||||
let regions = host.caption_regions(ViewportId::ROOT).expect("the band registered its parts");
|
||||
let strips = regions.moves.iter().filter(|area| band.rect.contains_rect(**area)).count();
|
||||
assert!(strips > bands, "a modal over the page shows a drag strip over the band: {regions:?}");
|
||||
}
|
||||
|
||||
/// The commands of a page's own scope.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, CommandSet)]
|
||||
#[command(prefix = "trialPage", scope = "trialPage")]
|
||||
enum PageKeys {
|
||||
#[command(label = "Print", default = "Enter")]
|
||||
Print,
|
||||
}
|
||||
|
||||
const PAGE: CommandScope = <PageKeys as CommandSet>::SCOPE;
|
||||
|
||||
/// With nothing focused and a page shown, the page takes the window's keys as a modal's root does: Enter reaches the
|
||||
/// command scope on the page, once per press.
|
||||
#[trial]
|
||||
fn a_page_takes_the_windows_keys_with_nothing_focused() {
|
||||
let printed = Cell::new(0);
|
||||
let frame = |frames: &mut Frames, events: Vec<Event>| {
|
||||
frames.frame(events, |ui| {
|
||||
let _ = AppShell::new(WindowKey::main())
|
||||
.body(|ui, _, _: &mut ()| {
|
||||
Button::new("Body").show(ui);
|
||||
})
|
||||
.page(true, PAGE, |ui, cx, _: &mut ()| {
|
||||
while cx.take_command::<PageKeys>().is_some() {
|
||||
printed.set(printed.get() + 1);
|
||||
}
|
||||
Text::new("Print").show(ui);
|
||||
})
|
||||
.show(ui, &mut ());
|
||||
});
|
||||
};
|
||||
let mut frames = Frames::new();
|
||||
for _ in 0..3 {
|
||||
frame(&mut frames, vec![]);
|
||||
}
|
||||
let key = |pressed| Event::Key { key: Key::Enter, physical_key: None, pressed, repeat: false, modifiers: Modifiers::NONE };
|
||||
frame(&mut frames, vec![key(true)]);
|
||||
frame(&mut frames, vec![key(false)]);
|
||||
for _ in 0..3 {
|
||||
frame(&mut frames, vec![]);
|
||||
}
|
||||
assert_eq!(printed.get(), 1, "Enter with nothing focused runs the page's command once");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
//! Screen mode: the shell brings its OS window to the bound mode in one pass and follows the OS out of full screen, and
|
||||
//! its keys reach it with nothing focused and give way to a held key's scope.
|
||||
//! its keys reach it with nothing focused and give way to a held key's scope. Focus shows the screen bar and a
|
||||
//! drop-down slot, and the F key cycles within the shell's mode set.
|
||||
|
||||
use craft_host::target::{Os, ShellInfo};
|
||||
use craft_ui::contract::{Bind, CommandSet, Show as _};
|
||||
@@ -7,7 +8,8 @@ use craft_ui::display::Text;
|
||||
use craft_ui::runtime::InstallSpec;
|
||||
use craft_ui::runtime::env::WindowKey;
|
||||
use craft_ui::runtime::frame::take_output;
|
||||
use craft_ui::shell::{AppShell, ScreenMode};
|
||||
use craft_ui::shell::{AppShell, ScreenMode, ScreenModeSet, Slot};
|
||||
use craft_ui::testing::pointer::{moved, press, release};
|
||||
use craft_ui::testing::windows::FakeSystem;
|
||||
use craft_ui::testing::{Frames, trial};
|
||||
use craft_ui_test_kit::windows::{Out, Windows};
|
||||
@@ -174,3 +176,176 @@ fn a_held_keys_scope_takes_its_keys_before_the_window() {
|
||||
assert_eq!(mode, ScreenMode::FullScreenWithMenuBar, "F with F12 up cycles the screen mode");
|
||||
assert!(!fired.iter().any(|id| id == HeldKeys::Next.id()), "{fired:?}");
|
||||
}
|
||||
|
||||
/// What one frame of the Focus trial's shell laid out: the body, the screen bar and the drop-down slot when shown.
|
||||
#[derive(Clone, Copy, Debug, Default)]
|
||||
struct Laid {
|
||||
body: Rect,
|
||||
screen: Option<Rect>,
|
||||
drops: Option<Rect>,
|
||||
revealed: bool,
|
||||
dropped: bool,
|
||||
}
|
||||
|
||||
/// One frame with `events` of a document shell with a screen bar and a drop-down slot, its mode bound to `mode` and
|
||||
/// its drop-down flag to `dropped`; with `rerun` the frame runs a second pass. Returns the last pass's layout and the
|
||||
/// number of passes.
|
||||
fn focus_frame(frames: &mut Frames, mode: &mut ScreenMode, dropped: &mut bool, events: Vec<Event>, rerun: bool) -> (Laid, usize) {
|
||||
let mut laid = Laid::default();
|
||||
let passes = frames.frame(events, |ui| {
|
||||
let out = AppShell::new(WindowKey::main())
|
||||
.mode_set(ScreenModeSet::Document)
|
||||
.screen_mode(Bind::bound(&mut *mode))
|
||||
.dropped(Bind::bound(&mut *dropped))
|
||||
.top(Slot::new("screen").screen_bar(), |ui, _, _: &mut ()| {
|
||||
Text::new("Screen").show(ui);
|
||||
})
|
||||
.top(Slot::new("ribbon").drops(), |ui, _, _: &mut ()| {
|
||||
Text::new("Ribbon").show(ui);
|
||||
})
|
||||
.body(|ui, _, _| {
|
||||
Text::new("Document").show(ui);
|
||||
})
|
||||
.show(ui, &mut ());
|
||||
let rect_of = |key: &str| out.regions.slots.iter().find(|(shown, _)| *shown == key).map(|(_, rect)| *rect);
|
||||
laid = Laid { body: out.regions.body, screen: rect_of("screen"), drops: rect_of("ribbon"), revealed: out.revealed, dropped: out.dropped };
|
||||
if rerun && ui.ctx().current_pass_index() == 0 {
|
||||
ui.ctx().request_discard("the trial reruns the pass");
|
||||
}
|
||||
});
|
||||
(laid, passes)
|
||||
}
|
||||
|
||||
fn focus_settle(frames: &mut Frames, mode: &mut ScreenMode, dropped: &mut bool) -> Laid {
|
||||
let mut laid = Laid::default();
|
||||
for _ in 0..SETTLED_FRAMES {
|
||||
laid = focus_frame(frames, mode, dropped, vec![], false).0;
|
||||
}
|
||||
laid
|
||||
}
|
||||
|
||||
/// A press at `at` whose press frame runs two passes, then the release and a settle; the layout after it.
|
||||
fn press_at(frames: &mut Frames, mode: &mut ScreenMode, dropped: &mut bool, at: Pos2) -> Laid {
|
||||
focus_frame(frames, mode, dropped, vec![moved(at)], false);
|
||||
let (_, passes) = focus_frame(frames, mode, dropped, vec![press(at)], true);
|
||||
assert_eq!(passes, 2, "the press frame ran a second pass");
|
||||
focus_frame(frames, mode, dropped, vec![release(at)], false);
|
||||
focus_settle(frames, mode, dropped)
|
||||
}
|
||||
|
||||
/// Focus shows the screen bar above the body and takes its room; the drop-down slot shows while `dropped` is set and
|
||||
/// covers the body, leaving its rect as it is. A press in the slot keeps it; one press in the body clears the flag,
|
||||
/// whose frame's second pass, with no press of its own, leaves it cleared. A mode change clears it too. Neither slot
|
||||
/// counts as a reveal.
|
||||
#[trial]
|
||||
fn focus_shows_the_screen_bar_and_a_dropped_slot_covers_the_body_until_a_press_in_it() {
|
||||
let mut frames = Frames::new();
|
||||
let (mut mode, mut dropped) = (ScreenMode::Standard, false);
|
||||
let standard = focus_settle(&mut frames, &mut mode, &mut dropped);
|
||||
assert_eq!((standard.screen, standard.drops), (None, None), "Standard shows neither slot");
|
||||
|
||||
mode = ScreenMode::Focus;
|
||||
let focus = focus_settle(&mut frames, &mut mode, &mut dropped);
|
||||
let screen = focus.screen.expect("Focus shows the screen bar");
|
||||
assert_eq!(screen.top(), standard.body.top(), "the screen bar lies at the window's top");
|
||||
assert_eq!(focus.body.top(), screen.bottom(), "the body is laid out below the screen bar");
|
||||
assert_eq!((focus.drops, focus.revealed, focus.dropped), (None, false, false), "the drop-down slot waits for its flag");
|
||||
|
||||
dropped = true;
|
||||
let shown = focus_settle(&mut frames, &mut mode, &mut dropped);
|
||||
let drops = shown.drops.expect("the drop-down slot shows while its flag is set");
|
||||
assert_eq!(shown.body, focus.body, "the drop-down slot covers the body and leaves its rect");
|
||||
assert!(drops.intersects(shown.body) && drops.top() >= screen.bottom(), "it lies over the body, below the bar: {drops:?}");
|
||||
assert!(shown.dropped && !shown.revealed, "the shell reports the slot, and it is no reveal");
|
||||
|
||||
let kept = press_at(&mut frames, &mut mode, &mut dropped, drops.center());
|
||||
assert!(dropped && kept.drops.is_some(), "a press in the drop-down slot is the slot's own");
|
||||
|
||||
let below = Pos2::new(shown.body.center().x, shown.body.bottom() - 10.0);
|
||||
assert!(!drops.contains(below), "the trial presses in the body, clear of the slot");
|
||||
let cleared = press_at(&mut frames, &mut mode, &mut dropped, below);
|
||||
assert!(!dropped, "a press in the body clears the flag");
|
||||
assert_eq!((cleared.drops, cleared.dropped), (None, false), "and the slot folds away");
|
||||
assert_eq!(cleared.body, focus.body, "the body keeps its rect");
|
||||
|
||||
dropped = true;
|
||||
assert!(focus_settle(&mut frames, &mut mode, &mut dropped).drops.is_some(), "the slot shows again");
|
||||
mode = ScreenMode::Immersive;
|
||||
let immersive = focus_settle(&mut frames, &mut mode, &mut dropped);
|
||||
assert!(!dropped, "a mode change clears the flag");
|
||||
assert!(immersive.screen.is_some() && immersive.drops.is_none(), "Immersive keeps the screen bar: {immersive:?}");
|
||||
}
|
||||
|
||||
/// One frame with `events` of a shell whose screen mode is bound to `mode` and cycles within `set`; with `rerun` the
|
||||
/// frame runs a second pass.
|
||||
fn cycled(windows: &Windows, mode: &mut ScreenMode, set: ScreenModeSet, events: Vec<Event>, rerun: bool) -> Out {
|
||||
windows.frame(events, vec![], |ui| {
|
||||
AppShell::new(WindowKey::main())
|
||||
.mode_set(set)
|
||||
.screen_mode(Bind::bound(&mut *mode))
|
||||
.body(|ui, _, _| {
|
||||
Text::new("Document").show(ui);
|
||||
})
|
||||
.show(ui, &mut ());
|
||||
if rerun && ui.ctx().current_pass_index() == 0 {
|
||||
ui.ctx().request_discard("the trial reruns the pass");
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/// Presses and releases F with nothing focused, the press frame running two passes, then settles; the full screen
|
||||
/// and maximize commands those frames sent.
|
||||
fn press_f(windows: &Windows, mode: &mut ScreenMode, set: ScreenModeSet) -> Vec<ViewportCommand> {
|
||||
let mut sent = screen_commands(&cycled(windows, mode, set, vec![key(Key::F, true)], true));
|
||||
sent.extend(screen_commands(&cycled(windows, mode, set, vec![key(Key::F, false)], false)));
|
||||
for _ in 0..SETTLED_FRAMES {
|
||||
sent.extend(screen_commands(&cycled(windows, mode, set, vec![], false)));
|
||||
}
|
||||
sent
|
||||
}
|
||||
|
||||
/// F steps once per press through the shell's mode set and wraps: `Document` cycles Standard, Full Screen With Menu
|
||||
/// Bar, Focus, Immersive and back, `Panels` reaches Full Screen, and a mode outside the set steps to Standard. Entering
|
||||
/// Focus from Standard sends one full screen command; Focus to Immersive sends none.
|
||||
#[trial]
|
||||
fn the_cycle_follows_the_window_mode_set() {
|
||||
let windows = Windows::new();
|
||||
windows.root_info(root(false, false));
|
||||
let mut mode = ScreenMode::Standard;
|
||||
for _ in 0..SETTLED_FRAMES {
|
||||
cycled(&windows, &mut mode, ScreenModeSet::Document, vec![], false);
|
||||
}
|
||||
let mut seen = Vec::new();
|
||||
for _ in 0..4 {
|
||||
press_f(&windows, &mut mode, ScreenModeSet::Document);
|
||||
seen.push(mode);
|
||||
}
|
||||
assert_eq!(
|
||||
seen,
|
||||
[ScreenMode::FullScreenWithMenuBar, ScreenMode::Focus, ScreenMode::Immersive, ScreenMode::Standard],
|
||||
"F steps once per press through the Document set and wraps"
|
||||
);
|
||||
|
||||
press_f(&windows, &mut mode, ScreenModeSet::Panels);
|
||||
press_f(&windows, &mut mode, ScreenModeSet::Panels);
|
||||
assert_eq!(mode, ScreenMode::FullScreen, "the Panels set reaches Full Screen");
|
||||
press_f(&windows, &mut mode, ScreenModeSet::Document);
|
||||
assert_eq!(mode, ScreenMode::Standard, "a mode outside the Document set steps to Standard");
|
||||
|
||||
for _ in 0..SETTLED_FRAMES {
|
||||
cycled(&windows, &mut mode, ScreenModeSet::Document, vec![], false);
|
||||
}
|
||||
mode = ScreenMode::Focus;
|
||||
assert_eq!(
|
||||
screen_commands(&cycled(&windows, &mut mode, ScreenModeSet::Document, vec![], false)),
|
||||
[ViewportCommand::Fullscreen(true)],
|
||||
"Standard to Focus sends one full screen command"
|
||||
);
|
||||
windows.root_info(root(true, false));
|
||||
for _ in 0..SETTLED_FRAMES {
|
||||
cycled(&windows, &mut mode, ScreenModeSet::Document, vec![], false);
|
||||
}
|
||||
let sent = press_f(&windows, &mut mode, ScreenModeSet::Document);
|
||||
assert_eq!(mode, ScreenMode::Immersive, "F in Focus gives Immersive");
|
||||
assert!(sent.is_empty(), "Focus to Immersive stays in full screen and sends nothing: {sent:?}");
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
//! A title bar in an embedded shell is a picture of a window: it reports its captions and acts on no window.
|
||||
//! A title bar in an embedded shell is a picture of a window: it reports its captions and acts on no window. An action
|
||||
//! title is a button that reports its activation.
|
||||
|
||||
use craft_host::target::ShellInfo;
|
||||
use craft_ui::contract::Role;
|
||||
@@ -6,12 +7,13 @@ use craft_ui::runtime::InstallSpec;
|
||||
use craft_ui::runtime::env::WindowKey;
|
||||
use craft_ui::shell::{AppShell, Caption, CaptionFamily, Captions, Frame, Title, TitleBar};
|
||||
use craft_ui::testing::pointer::{moved, press, release};
|
||||
use craft_ui::testing::trial;
|
||||
use craft_ui::testing::windows::NoWindows;
|
||||
use craft_ui::testing::{Fixture, trial};
|
||||
use craft_ui_test_kit::windows::Windows;
|
||||
use craft_window::policy::{Decision, Desktop, DesktopKind};
|
||||
use egui::{Event, Pos2, Rect, Ui, ViewportCommand, ViewportId, ViewportInfo, vec2};
|
||||
use std::cell::Cell;
|
||||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
|
||||
/// The window commands a title bar sends for a click on its Maximize button, a drag of its free band and a double
|
||||
@@ -128,3 +130,58 @@ fn the_window_title_is_sent_once_per_change() {
|
||||
});
|
||||
assert!(titles(&out).is_empty(), "an embedded shell sends no title");
|
||||
}
|
||||
|
||||
/// What the action-title trial saw: the passes that reported an activation, and the bar's rect.
|
||||
#[derive(Clone, Copy, Default)]
|
||||
struct TitleSeen {
|
||||
activations: usize,
|
||||
bar: Rect,
|
||||
}
|
||||
|
||||
/// A settled title bar whose title `title` is an action; what each pass reported.
|
||||
fn titled(title: &'static str) -> (Fixture, Rc<Cell<TitleSeen>>) {
|
||||
let seen = Rc::new(Cell::new(TitleSeen::default()));
|
||||
let out = Rc::clone(&seen);
|
||||
let mut fixture = Fixture::new(move |ui| {
|
||||
// The title shows whatever frame the trial's host decides.
|
||||
let shown =
|
||||
TitleBar::new().title_when_native().show_titled(ui, Title::new(title).action("Rename the document"), |_, _| {}, |_, _| {});
|
||||
let mut now = out.get();
|
||||
now.bar = shown.response.rect;
|
||||
now.activations += usize::from(shown.title_activated);
|
||||
out.set(now);
|
||||
});
|
||||
fixture.room(vec2(600.0, 200.0)).settle();
|
||||
(fixture, seen)
|
||||
}
|
||||
|
||||
const LONG: &str = "A very long document title that cannot fit in the free gap of a title bar six hundred points wide, \
|
||||
so the bar cuts it with an ellipsis and keeps the whole of it for the tooltip and the name.psd";
|
||||
|
||||
/// An action title is a focusable button named by the shown title. A click and Enter each report it in the pass they
|
||||
/// land in and no later pass. The button sits on the window's centre line, and a title too long for the gap is cut to
|
||||
/// fit inside the bar.
|
||||
#[trial]
|
||||
fn an_action_title_is_a_button_and_reports_its_activation() {
|
||||
let (mut fixture, seen) = titled("Landscape.psd");
|
||||
let title = fixture.by_label("Landscape.psd").expect("the title is a named control");
|
||||
assert_eq!(fixture.tree().role_of(title.node), Some(Role::BUTTON), "the title is a button");
|
||||
let bar = seen.get().bar;
|
||||
assert!((title.rect.center().x - bar.center().x).abs() <= 1.0, "the title {:?} sits on the centre line of {bar:?}", title.rect);
|
||||
assert_eq!(seen.get().activations, 0, "nothing is activated before input");
|
||||
|
||||
fixture.click(&title).idle(3);
|
||||
assert_eq!(seen.get().activations, 1, "a click reports the title once, in its pass only");
|
||||
assert!(fixture.focused_stop().is_some(), "the click focuses the title");
|
||||
fixture.key(egui::Key::Enter, egui::Modifiers::NONE).idle(3);
|
||||
assert_eq!(seen.get().activations, 2, "Enter on the focused title reports it once");
|
||||
|
||||
let (fixture, seen) = titled(LONG);
|
||||
let title = fixture.by_label(LONG).expect("the long title is named in full");
|
||||
let bar = seen.get().bar;
|
||||
assert!(
|
||||
bar.contains_rect(title.rect) && title.rect.width() < bar.width(),
|
||||
"the long title {:?} is cut to fit inside the bar {bar:?}",
|
||||
title.rect
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user