Merge craft-libs main 07a8c471ed into the port (skeleton: conflict markers left in for the area merges)

Cargo.toml takes main's egui pin (932a73b2) and vendor list; Cargo.lock is main's, resolved again after the combine.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Dylan M. TaylorandClaude Opus 5.5 committed 2026-11-29 04:24:10 +00:00
commit a3bd3e5e07
1709 files changed
+179384 -10423

No files matched your search

+2 -2
View File
@@ -38,12 +38,12 @@ pub struct AppSpec {
impl AppSpec {
/// A spec for `app_id` titled `title`, with the running build's shell on the backend winit opens by default (the one
/// `run` opens its windows on) and an in-memory placement store.
/// `run` opens its windows on) and the desktop's title-bar double click, and an in-memory placement store.
pub fn new(app_id: impl Into<String>, title: impl Into<String>, defaults: Defaults) -> Self {
AppSpec {
title: title.into(),
app_id: app_id.into(),
shell_info: ShellInfo::default().backend(Backend::from_env()),
shell_info: ShellInfo::default().backend(Backend::from_env()).double_click(craft_window::desktop::double_click()),
defaults,
placement: Arc::new(Mutex::new(Store::in_memory())),
window_system: Arc::new(SystemWindows),
+278 -86
View File
@@ -16,8 +16,8 @@ use super::title_bar::PageBand;
use super::words::ShellWords;
use crate::contract::overlay::{PopupRegion, Resize};
use crate::contract::{
Bind, BodyCx, BodyLayout, Common, Component, Container, ContainerProps, Cx, DropZone, Mount, NoValue, Outcome, Overlay, PaneEdge, Props as _,
Remember as _, Role, ShellPane, ShowContainer as _, Sizing,
Bind, BodyCx, BodyLayout, Common, Component, Container, ContainerProps, Cx, DropZone, MemoView, Mount, NoValue, Outcome, Overlay, PaneEdge,
Props as _, Remember as _, Role, ShellPane, ShowContainer as _, Sizing,
};
use crate::layout_components::Stack;
use crate::notices::ToastStack;
@@ -34,7 +34,7 @@ use crate::runtime::windows::{WindowAction, WindowHost};
use crate::shell::Slot;
use crate::style::{ComponentStyle, StyleCx, SurfaceKind, UiTokens};
use craft_behavior::{EditEvent, Metrics, Mixed, Sense};
use egui::{Context, Rect, Response, Ui, ViewportId, pos2};
use egui::{Context, Rect, Response, Ui, UiBuilder, ViewportId, pos2};
use std::sync::Arc;
/// The closure that fills a region.
@@ -63,6 +63,140 @@ impl<'a, S> SlotBody<'a, S> {
}
}
/// The host's version of what a slot or the page shows, read from the app state at the slot's turn in the pass; `None`
/// runs the slot in every pass.
type VersionFn<'a, S> = Box<dyn Fn(&S) -> Option<u64> + 'a>;
/// Where and how one slot shows: everything its pane and its content take from the shell besides the app.
#[derive(Clone, crate::contract::MemoProps)]
struct SlotPlace {
key: SlotKey,
edge: PaneEdge,
/// The slot's extent along its edge, as it was laid out.
extent: f32,
/// The pane's rect, or for a slot sized by its content the room it can grow into.
room: Rect,
/// The slot is as large as its content ([`SlotSize::Content`]).
by_content: bool,
/// The title slot mirrors with the traffic lights at the right end.
mirrored: bool,
/// The floating options bar's top-left corner: the bar is a movable layer over the body, bounded by `room`.
floating: Option<egui::Pos2>,
label: Option<Label>,
/// The region the popups opened in a bottom slot stay inside: above the bottom slots outside it, so a status bar's
/// menu opens right above its control.
popups: Option<Rect>,
}
/// A versioned slot as a memoized view: its pane and its content replay while the host's version holds and no input
/// reaches the slot.
#[derive(crate::contract::MemoProps)]
struct SlotView<'v, 'a, S> {
version: u64,
place: SlotPlace,
#[memo_props(covered_by = "version", reason = "the host's version holds everything the slot shows of the app")]
add: &'v mut SlotFn<'a, S>,
#[memo_props(covered_by = "version", reason = "the host's version holds everything the slot shows of the app")]
app: &'v mut S,
}
fn slot_view<S>(view: &mut SlotView<'_, '_, S>, ui: &mut Ui) -> (Rect, bool) {
let drawn = show_slot(ui, &view.place, view.add, view.app);
// A pane takes no room in flow; the run covers it, so the pointer over the slot, and nowhere else, runs it. A
// floating bar's layer is its own.
if view.place.floating.is_none() {
ui.expand_to_include_rect(drawn.0);
}
drawn
}
/// Shows one slot at `place`: its chrome pane with `add` in it, or the floating options bar's layer. Returns the pane's
/// or the layer's rect, and whether it came from a real run (a sizing pass's run is not what shows).
fn show_slot<S>(ui: &mut Ui, place: &SlotPlace, add: &mut SlotFn<'_, S>, app: &mut S) -> (Rect, bool) {
let SlotPlace { key, edge, extent, room, by_content, mirrored, floating, label, popups } = place.clone();
if let Some(corner) = floating {
let overlay = Overlay::floating().modeless().bounds(room).placed_at(corner).body_scroll(false);
let layer = FloatingBar::new(overlay, label).id_salt(("slot", key)).show(ui, |ui, bcx| add(ui, bcx, app));
return (layer.output.response.rect, !ui.is_sizing_pass());
}
// A slot sized by its content is as large as its content from its outer edge, in the room it can grow into; any
// other slot takes its extent and fills its rect.
let pane = ShellPane::new(key).edge(edge);
let pane = if by_content { pane.at_content_extent(room) } else { pane.extent(extent).at(room) };
// Every slot is a chrome pane: it paints the surface under its bar or rail and the rule toward the body.
let mut region = ShellRegion::chrome(pane).id_salt(("slot", key));
// A slot sized by its content stacks it from the slot's outer edge: a top pane's own layout centres one line in its
// height, which would lay a strip and the row under it side by side.
if by_content {
region.props = region.props.layout(BodyLayout::stack());
}
if let Some(label) = label {
region = region.label(label);
}
if let Some(popups) = popups {
region = region.popups(popups);
}
if !by_content {
let shown = region.show(ui, |ui, bcx| in_lights_flow(ui, mirrored, |ui| add(ui, bcx, app)));
return (shown.output.response.rect, !ui.is_sizing_pass());
}
// A top or bottom slot's content fills its width and is as tall as it is; a rail's is as wide as it is. Only the
// slot's own real run counts: a run in a sizing pass (the scope's measuring run, which alone runs for a shell out of
// sight) is not what shows.
let along_x = matches!(edge, PaneEdge::Start | PaneEdge::End);
let shown = region.show(ui, |ui, bcx| {
let stack = if along_x { Stack::new() } else { Stack::new().fill_width() };
stack.show(ui, |ui, _| in_lights_flow(ui, mirrored, |ui| add(ui, bcx, app)));
!ui.is_sizing_pass()
});
(shown.output.response.rect, shown.inner == Some(true))
}
/// Shows a slot at `place`, held to its room: as a memoized view while the host's `version` is given, else run in
/// this pass.
fn shown_slot<S>(ui: &mut Ui, place: SlotPlace, version: Option<u64>, add: &mut SlotFn<'_, S>, app: &mut S) -> (Rect, bool) {
let room = place.room;
ui.scope_builder(UiBuilder::new().max_rect(room), |ui| match version {
Some(version) => {
let key = place.key;
MemoView::new(("slot", key), SlotView { version, place, add, app }, slot_view::<S>).show(ui).unwrap_or((room, false))
}
None => show_slot(ui, &place, add, app),
})
.inner
}
/// The full-window page as a memoized view: it replays while the host's version holds and no input reaches it.
#[derive(crate::contract::MemoProps)]
struct PageView<'v, 'a, S> {
version: u64,
/// The page's room: the window less nothing, or its body's for a shell as tall as its content.
room: Rect,
content_extent: bool,
#[memo_props(hash = "a command scope is a name")]
scope: CommandScope,
label: Label,
#[memo_props(covered_by = "version", reason = "the host's version holds everything the page shows of the app")]
add: &'v mut SlotFn<'a, S>,
#[memo_props(covered_by = "version", reason = "the host's version holds everything the page shows of the app")]
app: &'v mut S,
}
fn page_view<S>(view: &mut PageView<'_, '_, S>, ui: &mut Ui) -> egui::Id {
let id = show_page(ui, view.room, view.content_extent, view.scope, view.label.clone(), view.add, view.app);
ui.expand_to_include_rect(view.room);
id
}
/// Shows the page's region at `room` with `add` in it; returns the region's id, the root of the page's keys.
fn show_page<S>(ui: &mut Ui, room: Rect, content_extent: bool, scope: CommandScope, label: Label, add: &mut SlotFn<'_, S>, app: &mut S) -> egui::Id {
let pane = ShellPane::new("page");
let pane = if content_extent { pane.at_content_extent(room) } else { pane.at(room) };
let mut region = ShellRegion::pane(pane).label(label);
region.props = region.props.command_scope(scope);
region.show(ui, |ui, bcx| add(ui, bcx, app)).output.response.id
}
/// The style of a shell region: the surface comes from the container.
#[derive(Clone, Debug, Default, PartialEq, ComponentStyle)]
#[non_exhaustive]
@@ -96,8 +230,11 @@ pub struct ShellRegion {
common: Common,
#[container]
props: ContainerProps,
/// The shell the scope carries to its slots, and the rect popups opened inside it are contained in.
shell: Option<(ShellCx, Option<Rect>)>,
/// The shell the scope carries to its slots.
shell: Option<ShellCx>,
/// The region popups opened inside it are contained in, and the popups opened from those: a scope's, or a bottom
/// slot's. `None` keeps the inherited region.
popups: Option<PopupRegion>,
/// Sets the shell's screen modes for everything inside the region, beside its shell: a `ScreenModeButton` in a
/// slot reads them with `Env::get`.
#[prop(name = "with_mode_set", vis = "")]
@@ -114,7 +251,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, mode_set: None, senses_surface: false }
ShellRegion { common: Common::new(), props, shell: None, popups: 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
@@ -122,20 +259,19 @@ 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, mode_set: None, senses_surface: false }
ShellRegion { common: Common::new(), props, shell: None, popups: 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, None)), mode_set: None, senses_surface: false }
let popups = Some(PopupRegion::new(None));
ShellRegion { common: Common::new(), props, shell: Some(shell), popups, mode_set: None, senses_surface: false }
}
/// The scope's popups, and the popups opened from them, stay inside `rect`.
/// The region's popups, and the popups opened from them, stay inside `rect`.
fn popups(mut self, rect: Rect) -> Self {
if let Some((_, popups)) = &mut self.shell {
*popups = Some(rect);
}
self.popups = Some(PopupRegion::new(Some(rect)));
self
}
@@ -145,7 +281,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, mode_set: None, senses_surface: false }
ShellRegion { common: Common::new(), props, shell: None, popups: 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
@@ -175,9 +311,11 @@ impl Component for ShellRegion {
}
fn content_env(&self, _: &Cx<'_, Self>, values: &mut AppValues) {
if let Some((shell, popups)) = &self.shell {
if let Some(shell) = &self.shell {
shell.put(values);
values.set(PopupRegion::new(*popups));
}
if let Some(popups) = self.popups {
values.set(popups);
}
if let Some(set) = self.mode_set {
values.set(set);
@@ -201,6 +339,7 @@ struct Placed<'a, S> {
options: bool,
/// The slot's name in the shell's words, for a slot of the canvas preset.
named: Option<fn(&ShellWords) -> Label>,
version: VersionFn<'a, S>,
add: SlotFn<'a, S>,
}
@@ -398,6 +537,13 @@ impl Outcome for AppShellOutput {
/// - **App state.** `S` is the state the slots and the body edit; [`show`](Self::show) hands each of them `&mut S` in
/// turn, so a title bar, a rail and a body that edit one document share it without interior mutability. An app with
/// no shared state uses `S = ()`.
/// - **Versions.** Every slot, and the page, comes with the host's version of what it shows: a function of `S` the
/// shell calls at the slot's turn in the pass, so it sees what the slots before it changed. While the version is the
/// same and no input reaches the slot, the slot's pane and content replay their last run instead of running: the
/// version must cover all the app data the slot shows that can change while no input reaches it. The framework's own
/// inputs (the slot's rect, the screen mode and reveal, the language, the theme, bound values and command states it
/// reads) reach the replay test themselves. A version of `None` runs the slot in every pass. The body runs in every
/// pass.
/// - **Dialogs.** The window owns one dialog host, shared by every body in it (`ShellDialogsCx::dialogs`). The shell runs it
/// after the body in each pass, so dialogs show over the window.
/// - **Embedded.** [`embedded`](Self::embedded) shows a shell inside a region of another window. Its screen modes
@@ -461,8 +607,12 @@ pub struct AppShell<'a, S> {
#[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.
<<<<<<< HEAD
page: Option<(CommandScope, SlotBody<'a, S>)>,
page_kind: PageKind,
=======
page: Option<(CommandScope, VersionFn<'a, S>, SlotBody<'a, S>)>,
>>>>>>> 07a8c471ed
}
impl<'a, S> AppShell<'a, S> {
@@ -507,24 +657,35 @@ impl<'a, S> AppShell<'a, S> {
/// The title bar slot, the first top slot, keyed `"title"`: visible, and revealing in body-only mode. The title bar
/// types fill it.
pub fn title_bar(self, add: impl FnMut(&mut Ui, &mut BodyCx<'_>, &mut S) + 'a) -> Self {
self.title(Slot::new(keys::TITLE).reveal(), add)
pub fn title_bar(self, version: impl Fn(&S) -> Option<u64> + 'a, add: impl FnMut(&mut Ui, &mut BodyCx<'_>, &mut S) + 'a) -> Self {
self.title(Slot::new(keys::TITLE).reveal(), version, add)
}
/// The title slot with a slot of your own, for a title that follows the host's menu bar flag.
pub fn title(mut self, slot: Slot, add: impl FnMut(&mut Ui, &mut BodyCx<'_>, &mut S) + 'a) -> Self {
self.title = Some(Placed { slot, edge: PaneEdge::Top, title: true, options: false, named: None, add: Box::new(add) });
pub fn title(mut self, slot: Slot, version: impl Fn(&S) -> Option<u64> + 'a, add: impl FnMut(&mut Ui, &mut BodyCx<'_>, &mut S) + 'a) -> Self {
self.title =
Some(Placed { slot, edge: PaneEdge::Top, title: true, options: false, named: None, version: Box::new(version), add: Box::new(add) });
self
}
/// The title bar slot with the host's menu bar flag: `visible` shows it, and it reveals in body-only mode only when
/// it is on.
pub fn title_bar_if(self, visible: bool, add: impl FnMut(&mut Ui, &mut BodyCx<'_>, &mut S) + 'a) -> Self {
self.title(Slot::new(keys::TITLE).visible(visible).reveal_if(visible), add)
pub fn title_bar_if(
self,
visible: bool,
version: impl Fn(&S) -> Option<u64> + 'a,
add: impl FnMut(&mut Ui, &mut BodyCx<'_>, &mut S) + 'a,
) -> Self {
self.title(Slot::new(keys::TITLE).visible(visible).reveal_if(visible), version, add)
}
/// The options bar, a top slot keyed `"options"` that reveals in body-only mode.
pub fn options_bar(mut self, visible: bool, add: impl FnMut(&mut Ui, &mut BodyCx<'_>, &mut S) + 'a) -> Self {
pub fn options_bar(
mut self,
visible: bool,
version: impl Fn(&S) -> Option<u64> + 'a,
add: impl FnMut(&mut Ui, &mut BodyCx<'_>, &mut S) + 'a,
) -> Self {
let slot = Slot::new(keys::OPTIONS).visible(visible).reveal();
self.slots.push(Placed {
slot,
@@ -532,13 +693,14 @@ impl<'a, S> AppShell<'a, S> {
title: false,
options: true,
named: Some(|words| words.options.clone()),
version: Box::new(version),
add: Box::new(add),
});
self
}
/// The status bar, a bottom slot keyed `"status"` that never reveals.
pub fn status(mut self, visible: bool, add: impl FnMut(&mut Ui, &mut BodyCx<'_>, &mut S) + 'a) -> Self {
pub fn status(mut self, visible: bool, version: impl Fn(&S) -> Option<u64> + 'a, add: impl FnMut(&mut Ui, &mut BodyCx<'_>, &mut S) + 'a) -> Self {
let slot = Slot::new(keys::STATUS).visible(visible);
self.slots.push(Placed {
slot,
@@ -546,33 +708,40 @@ impl<'a, S> AppShell<'a, S> {
title: false,
options: false,
named: Some(|words| words.status.clone()),
version: Box::new(version),
add: Box::new(add),
});
self
}
/// A top slot, below the ones added before it.
pub fn top(self, slot: Slot, add: impl FnMut(&mut Ui, &mut BodyCx<'_>, &mut S) + 'a) -> Self {
self.place(PaneEdge::Top, slot, add)
pub fn top(self, slot: Slot, version: impl Fn(&S) -> Option<u64> + 'a, add: impl FnMut(&mut Ui, &mut BodyCx<'_>, &mut S) + 'a) -> Self {
self.place(PaneEdge::Top, slot, version, add)
}
/// A bottom slot, above the ones added before it.
pub fn bottom(self, slot: Slot, add: impl FnMut(&mut Ui, &mut BodyCx<'_>, &mut S) + 'a) -> Self {
self.place(PaneEdge::Bottom, slot, add)
pub fn bottom(self, slot: Slot, version: impl Fn(&S) -> Option<u64> + 'a, add: impl FnMut(&mut Ui, &mut BodyCx<'_>, &mut S) + 'a) -> Self {
self.place(PaneEdge::Bottom, slot, version, add)
}
/// A slot at the reading start, inside the ones added before it.
pub fn start(self, slot: Slot, add: impl FnMut(&mut Ui, &mut BodyCx<'_>, &mut S) + 'a) -> Self {
self.place(PaneEdge::Start, slot, add)
pub fn start(self, slot: Slot, version: impl Fn(&S) -> Option<u64> + 'a, add: impl FnMut(&mut Ui, &mut BodyCx<'_>, &mut S) + 'a) -> Self {
self.place(PaneEdge::Start, slot, version, add)
}
/// 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)));
/// so `scope`'s commands get their default keys. `version` is read as a slot's is.
pub fn page(
mut self,
shown: bool,
scope: CommandScope,
version: impl Fn(&S) -> Option<u64> + 'a,
add: impl FnMut(&mut Ui, &mut BodyCx<'_>, &mut S) + 'a,
) -> Self {
self.page = shown.then(|| (scope, Box::new(version) as VersionFn<'a, S>, SlotBody::new(add)));
self
}
@@ -583,12 +752,18 @@ impl<'a, S> AppShell<'a, S> {
}
/// A slot at the reading end, inside the ones added before it.
pub fn end(self, slot: Slot, add: impl FnMut(&mut Ui, &mut BodyCx<'_>, &mut S) + 'a) -> Self {
self.place(PaneEdge::End, slot, add)
pub fn end(self, slot: Slot, version: impl Fn(&S) -> Option<u64> + 'a, add: impl FnMut(&mut Ui, &mut BodyCx<'_>, &mut S) + 'a) -> Self {
self.place(PaneEdge::End, slot, version, add)
}
fn place(mut self, edge: PaneEdge, slot: Slot, add: impl FnMut(&mut Ui, &mut BodyCx<'_>, &mut S) + 'a) -> Self {
self.slots.push(Placed { slot, edge, title: false, options: false, named: None, add: Box::new(add) });
fn place(
mut self,
edge: PaneEdge,
slot: Slot,
version: impl Fn(&S) -> Option<u64> + 'a,
add: impl FnMut(&mut Ui, &mut BodyCx<'_>, &mut S) + 'a,
) -> Self {
self.slots.push(Placed { slot, edge, title: false, options: false, named: None, version: Box::new(version), add: Box::new(add) });
self
}
@@ -772,14 +947,22 @@ impl<'a, S> AppShell<'a, S> {
if covers_title {
shell = shell.with_page_band(super::title_bar::page_band_room(cx, &tokens, cx.rect, !embedded));
}
// Popups stay above every bottom slot the pass shows, the covering ones included: they are painted there.
// Popups stay above every bottom slot the pass shows, the covering ones included: they are painted there. A
// bottom slot's own popups stay above only the bottom slots outside it, the ones claimed before it.
let shell_rect = if embedded { region } else { cx.rect };
let floor = claims
.iter()
.filter(|claim| claim.edge == PaneEdge::Bottom)
.filter_map(|claim| regions.slots.iter().find(|(key, _)| *key == claim.key).map(|(_, rect)| rect.top()))
.fold(shell_rect.bottom(), f32::min);
let popups = Rect::from_min_max(shell_rect.min, pos2(shell_rect.right(), floor.max(shell_rect.top())));
let popups_above = |outside: &[Claim]| {
let floor = outside
.iter()
.filter(|claim| claim.edge == PaneEdge::Bottom)
.filter_map(|claim| regions.slots.iter().find(|(key, _)| *key == claim.key).map(|(_, rect)| rect.top()))
.fold(shell_rect.bottom(), f32::min);
Rect::from_min_max(shell_rect.min, pos2(shell_rect.right(), floor.max(shell_rect.top())))
};
let popups = popups_above(&claims);
let slot_popups = |key: SlotKey| {
let at = claims.iter().position(|claim| claim.key == key && claim.edge == PaneEdge::Bottom)?;
Some(popups_above(&claims[..at]))
};
let bar_extent = slots.iter().find(|placed| placed.options).map(|placed| placed.extent(&tokens, &kept.measured));
let mut landed = None;
let mut floated: Vec<(RevealEdge, Rect)> = Vec::new();
@@ -806,6 +989,32 @@ impl<'a, S> AppShell<'a, S> {
if unseen && !ui.is_sizing_pass() {
return;
}
<<<<<<< HEAD
=======
if let Some((scope, version, SlotBody(page))) = page.as_mut() {
let (room, content_extent, label) = (regions.body, content_room.is_some(), body_label.clone());
let root = ui
.scope_builder(UiBuilder::new().max_rect(room), |ui| match version(&*app) {
Some(version) => {
let view = PageView { version, room, content_extent, scope: *scope, label, add: page, app: &mut *app };
MemoView::new("page", view, page_view::<S>).show(ui)
}
None => Some(show_page(ui, room, content_extent, *scope, label, page, app)),
})
.inner;
// 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)
if let Some(root) = root {
crate::runtime::commands::note_page_root(&ctx, viewport, root);
}
PageBand::new().show_over_page(ui);
if let Some(dialogs) = WindowDialogs::existing(ui.ctx(), &window) {
dialogs.run(ui);
}
return;
}
>>>>>>> 07a8c471ed
let mut show_slots = |ui: &mut Ui, covering: bool, app: &mut S| {
for (placed, shown) in slots.iter_mut().zip(&visible) {
let floats = floating && placed.options;
@@ -813,54 +1022,37 @@ impl<'a, S> AppShell<'a, S> {
if !*shown || if floats { !covering } else { (!paged && covers(&placed.slot, only)) != covering } {
continue;
}
let mirrored = placed.title && mirror_title;
let by_content = placed.sized_by_content();
let along_x = placed.along_x();
let extent = placed.extent(&tokens, &measured_before);
let Placed { slot, edge, named, add, .. } = placed;
let label = slot.name().cloned().or_else(|| named.map(|name| name(&words)));
let key = placed.slot.key();
let place = SlotPlace {
key,
edge: placed.edge,
extent: placed.extent(&tokens, &measured_before),
room: if floats {
regions.body
} else if by_content {
grow_room(key)
} else {
rect_of(key)
},
by_content,
mirrored: placed.title && mirror_title,
floating: floats.then(|| held.corner(regions.body, tokens.space.gap.section)),
label: placed.slot.name().cloned().or_else(|| placed.named.map(|name| name(&words))),
popups: slot_popups(key),
};
// Read at the slot's turn, so it holds what the slots before it changed in this pass.
let version = (placed.version)(&*app);
let (rect, real) = shown_slot(ui, place, version, &mut placed.add, app);
if floats {
let corner = held.corner(regions.body, tokens.space.gap.section);
let overlay = Overlay::floating().modeless().bounds(regions.body).placed_at(corner).body_scroll(false);
let layer = FloatingBar::new(overlay, label).id_salt(("slot", slot.key())).show(ui, |ui, bcx| add(ui, bcx, app));
floated.extend(edge.reveal_edge().map(|edge| (edge, layer.output.response.rect)));
floated.extend(placed.edge.reveal_edge().map(|edge| (edge, rect)));
continue;
}
// A slot sized by its content is as large as its content from its outer edge, in the room it
// can grow into; any other slot takes its extent and fills its rect.
let pane = ShellPane::new(slot.key()).edge(*edge);
let pane =
if by_content { pane.at_content_extent(grow_room(slot.key())) } else { pane.extent(extent).at(rect_of(slot.key())) };
// Every slot is a chrome pane: it paints the surface under its bar or rail and the rule toward
// the body.
let mut region = ShellRegion::chrome(pane).id_salt(("slot", slot.key()));
// A slot sized by its content stacks it from the slot's outer edge: a top pane's own layout
// centres one line in its height, which would lay a strip and the row under it side by side.
if by_content {
region.props = region.props.layout(BodyLayout::stack());
}
if let Some(label) = label {
region = region.label(label);
}
let key = slot.key();
// The slot runs every pass; the app memoizes inside it.
if !by_content {
region.show(ui, |ui, bcx| in_lights_flow(ui, mirrored, |ui| add(ui, bcx, app)));
continue;
}
// The slot's extent along its edge is the pane's: its content's, with what the pane keeps
// around its body (its rule). A top or bottom slot's content fills its width and is as tall
// as it is; a rail's is as wide as it is. Only the slot's own real run records it: a run in a
// sizing pass (the scope's measuring run, which alone runs for a shell out of sight) is not
// what shows.
let shown = region.show(ui, |ui, bcx| {
let stack = if along_x { Stack::new() } else { Stack::new().fill_width() };
stack.show(ui, |ui, _| in_lights_flow(ui, mirrored, |ui| add(ui, bcx, app)));
!ui.is_sizing_pass()
});
let pane = shown.output.response.rect;
let took = if along_x { pane.width() } else { pane.height() };
if shown.inner == Some(true) && took.is_finite() && took > 0.0 {
// The slot's extent along its edge is the pane's: its content's, with what the pane keeps around
// its body (its rule). Only the slot's own real run records it.
let took = if along_x { rect.width() } else { rect.height() };
if by_content && real && took.is_finite() && took > 0.0 {
measured_now.push((key, took));
}
}
+105 -47
View File
@@ -18,18 +18,33 @@ use egui::Ui;
fn app_shell(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
let room = stage(ui);
AppShell::new(WindowKey::main())
.title_bar(|ui, _, _| {
Text::new("Title").show(ui);
})
.top(Slot::new("options").reveal().label("Options"), |ui, _, _| {
Text::new("Options").show(ui);
})
.bottom(Slot::new("status").label("Status"), |ui, _, _| {
Text::new("Status").show(ui);
})
.start(Slot::new("tools").reveal().label("Tools"), |ui, _, _| {
Text::new("Tools").show(ui);
})
.title_bar(
|_| Some(0),
|ui, _, _| {
Text::new("Title").show(ui);
},
)
.top(
Slot::new("options").reveal().label("Options"),
|_| Some(0),
|ui, _, _| {
Text::new("Options").show(ui);
},
)
.bottom(
Slot::new("status").label("Status"),
|_| Some(0),
|ui, _, _| {
Text::new("Status").show(ui);
},
)
.start(
Slot::new("tools").reveal().label("Tools"),
|_| Some(0),
|ui, _, _| {
Text::new("Tools").show(ui);
},
)
.body(|ui, _, _| {
Text::new("Document").show(ui);
})
@@ -41,15 +56,27 @@ fn app_shell(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
fn app_shell_canvas(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
let room = stage(ui);
AppShell::new(WindowKey::main())
.title_bar_if(true, |ui, _, _| {
Text::new("Title").show(ui);
})
.options_bar(true, |ui, _, _| {
Text::new("Options").show(ui);
})
.status(true, |ui, _, _| {
Text::new("Status").show(ui);
})
.title_bar_if(
true,
|_| Some(0),
|ui, _, _| {
Text::new("Title").show(ui);
},
)
.options_bar(
true,
|_| Some(0),
|ui, _, _| {
Text::new("Options").show(ui);
},
)
.status(
true,
|_| Some(0),
|ui, _, _| {
Text::new("Status").show(ui);
},
)
.body(|ui, _, _| {
CanvasPanel::new()
.tabs(|ui, _| {
@@ -71,19 +98,34 @@ fn document_shell(ui: &mut Ui, mode: ScreenMode, dropped: &mut bool) -> StoryOut
.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);
})
.title_bar(
|_| Some(0),
|ui, _, _| {
Text::new("Title").show(ui);
},
)
.top(
Slot::new("screen").screen_bar().label("Screen"),
|_| Some(0),
|ui, _, _| {
Text::new("Page 1 of 3").show(ui);
let _ = ScreenModeButton::new(mode).show(ui);
},
)
.top(
Slot::new("ribbon").drops().label("Ribbon"),
|_| Some(0),
|ui, _, _| {
Text::new("Ribbon").show(ui);
},
)
.start(
Slot::new("tools").reveal().label("Tools"),
|_| Some(0),
|ui, _, _| {
Text::new("Tools").show(ui);
},
)
.body(|ui, _, _| {
Text::new("Document").show(ui);
})
@@ -113,18 +155,30 @@ fn app_shell_immersive(ui: &mut Ui, _: &mut StoryData) -> StoryOutput {
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);
})
.title_bar(
|_| Some(0),
|ui, _, _| {
Text::new("Title").show(ui);
},
)
.start(
Slot::new("tools").reveal().label("Tools"),
|_| Some(0),
|ui, _, _| {
Text::new("Tools").show(ui);
},
)
.body(|ui, _, _| {
Text::new("Document").show(ui);
})
.page(true, CommandScope::APP, |ui, _, _| {
Text::new("Print").show(ui);
})
.page(
true,
CommandScope::APP,
|_| Some(0),
|ui, _, _| {
Text::new("Print").show(ui);
},
)
.show_at(ui, room, &mut ())
.into()
}
@@ -193,10 +247,14 @@ fn options_shell(ui: &mut Ui, data: &mut StoryData, key: &'static str, home: Opt
let mut place = *data.value(key, home);
let shown = AppShell::embedded(WindowKey::new(key.to_owned()))
.options_place(Bind::bound(&mut place))
.options_bar(true, |ui, _, _| {
BarGrip::new().show(ui);
Text::new("Options").show(ui);
})
.options_bar(
true,
|_| Some(0),
|ui, _, _| {
BarGrip::new().show(ui);
Text::new("Options").show(ui);
},
)
.body(|ui, _, _| {
Text::new("Document").show(ui);
})
+20 -8
View File
@@ -1156,10 +1156,12 @@ fn greeting_body(
if !templates.is_empty() {
templates_grid(page, ui, templates);
}
if let Some(label) = more_templates
&& clicked(&Link::new(label.clone()).id_salt("more-templates").show(ui))
{
page.push(StartAction::MoreTemplates);
if let Some(label) = more_templates {
// The theme holds link text to the text minimum on the panel surface, not on the surround.
let panel = Stack::new().id_salt("more-templates-panel").surface(SurfaceKind::Panel).pad(Pad::Control);
if panel.show(ui, |ui, _| clicked(&Link::new(label.clone()).id_salt("more-templates").show(ui))).inner == Some(true) {
page.push(StartAction::MoreTemplates);
}
}
let mut list = RecentList::new(recent).max_recent(max_recent).now(page.now);
if let Some((thumbnails, source)) = page.thumbnails {
@@ -1215,7 +1217,8 @@ fn column_heading(page: &Page<'_>, ui: &mut Ui, title: Option<&Label>, subtitle:
/// The links of a Column page under their heading, each centred: the call to action ([`StartLink::primary`]) as a
/// pill with its icon, the others as links without their icons, each run of them in rows `size.page.link` high a
/// page link gap apart. A URL opens in the browser (the URL is its tooltip); a command fires as a pointer activation.
/// page link gap apart, on the panel surface. A URL opens in the browser (the URL is its tooltip); a command fires as a
/// pointer activation.
fn column_links(page: &Page<'_>, ui: &mut Ui, title: Option<&Label>, links: &[StartLink]) {
if links.is_empty() {
return;
@@ -1230,7 +1233,9 @@ fn column_links(page: &Page<'_>, ui: &mut Ui, title: Option<&Label>, links: &[St
if run[0].primary {
column_link(ui, cx, at, &run[0]);
} else {
let _ = Stack::new().gap(Gap::PageLink).fill_width().show(ui, |ui, cx| {
// The theme holds link text to the text minimum on the panel surface, not on the page.
let panel = Stack::new().id_salt(("start-link-panel", at)).surface(SurfaceKind::Panel).pad(Pad::Control).gap(Gap::PageLink);
let _ = panel.fill_width().show(ui, |ui, cx| {
for (offset, link) in run.iter().enumerate() {
column_link(ui, cx, at + offset, link);
}
@@ -1289,9 +1294,16 @@ fn new_and_open(page: &Page<'_>, ui: &mut Ui, sizing: Sizing) {
}
}
/// The links, one under another: a URL opens through its `Link` (the URL is its tooltip), a command fires as a
/// pointer activation.
/// The links, one under another on the panel surface: a URL opens through its `Link` (the URL is its tooltip), a
/// command fires as a pointer activation.
fn link_items(ui: &mut Ui, links: &[StartLink], home: bool) {
// The theme holds link text to the text minimum on the panel surface, not on the surround.
let panel = Stack::new().id_salt("start-link-panel").surface(SurfaceKind::Panel).pad(Pad::Control).gap(Gap::Tight);
let _ = panel.show(ui, |ui, _| link_rows(ui, links, home));
}
/// The rows of `link_items`.
fn link_rows(ui: &mut Ui, links: &[StartLink], home: bool) {
for (at, link) in links.iter().enumerate() {
match &link.target {
StartLinkTarget::Url(url) => {
+2 -1
View File
@@ -7,7 +7,8 @@ use egui::Context;
/// Whether the OS may move the running viewport's window from where the pointer is in this pass: what the move bands
/// of the pass wrote (the body step writes it for every move band of an OS window, `true` only where a press would go
/// to the band), else what the app wrote with [`set_window_movable`], else true. The runtime sets macOS's
/// `NSWindow.movable` from it at the end of each window's pass.
/// `NSWindow.movable` from it at the end of each window's pass. Read between passes, it answers for the window's last
/// pass.
pub fn window_movable(ctx: &Context) -> bool {
viewports::movable(ctx)
}
+7 -5
View File
@@ -61,9 +61,11 @@ impl Outcome for TitleBarOutput {
/// [`title_when_native`](TitleBar::title_when_native), the title.
/// - **Inset (macOS).** The content starts after the traffic lights. A double click follows the system setting.
/// - **Integrated.** The caption buttons of the window's layout sit at the two ends, flush with the window's edges.
/// A double click maximizes or restores.
/// A double click follows the desktop's setting (GNOME's `action-double-click-titlebar`), and elsewhere
/// maximizes or restores.
///
/// An end with no caption buttons or lights keeps the content `space.pad.regular` off the window's edge.
/// An end with no caption buttons or lights keeps the content `space.pad.regular` off the window's edge. The leading
/// controls, and the trailing controls of a fitted bar, stand `space.gap.item` apart.
///
/// In full screen the bar shows no captions and reserves no room. The free area is the container's move band:
/// pressing and dragging it moves the window, and a double click acts as above.
@@ -207,7 +209,7 @@ impl<'a> TitleBar<'a> {
.surface(SurfaceKind::Chrome)
.pad(Pad::None)
.sizing(Sizing::FillWidth)
.body_gap(Gap::Row)
.body_gap(Gap::Item)
.layout(BodyLayout::row())
.header(HeaderRegion::new().band(DragBand::Move).inline(true))
.end(EndRegion::new());
@@ -263,9 +265,9 @@ impl<'a> TitleBar<'a> {
mut trailing: impl FnMut(&mut Ui, &mut BodyCx<'_>) + 'a,
) -> TitleBarOutput {
self.props = self.props.end(EndRegion::new().fit(true));
// The ranked members fit as units of the first row in the end region.
// The ranked members fit as units of the first row in the end region, `space.gap.item` apart.
self.trailing(move |ui: &mut Ui, cx: &mut BodyCx<'_>| {
let _ = Row::new().show(ui, |ui, _| trailing(ui, cx));
let _ = Row::new().gap(Gap::Item).show(ui, |ui, _| trailing(ui, cx));
})
.show(ui, leading)
.output