feat(ui-shell): shell slots take the host's version and replay as memoized views (FW-365 F3)

Every slot and the full-window page take a version function of the app
state, read at the slot's turn in the pass. While it holds and no input
reaches the slot, the slot's chrome pane and its content replay their
last run; None runs the slot in every pass. The body runs every pass.

The MemoProps derive leaves a type parameter that only covered_by fields
name unbound, so a view can hold the shell's &mut S. PaneEdge derives
MemoProps.
This commit is contained in:
aiongg committed 2026-11-27 03:31:12 +00:00
1 parent fb1285dbf9
commit c417cd3050
17 files changed
+841 -436

No files matched your search

+16 -13
View File
@@ -47,19 +47,22 @@ fn window(width: f32, pixels_per_point: f32) -> Fixture {
let mut fixture = Fixture::new(move |ui| {
let bar = Rc::clone(&bar);
AppShell::new(WindowKey::main())
.title_bar(move |ui, _, _: &mut ()| {
let bar = Rc::clone(&bar);
let layout = craft_window::Layout { left: vec![], right: vec![Caption::Minimize, Caption::Maximize, Caption::Close] };
TitleBar::new().frame(Frame::Integrated(Captions { family: CaptionFamily::Windows, layout })).show_titled(
ui,
Title::new(DOCUMENT),
move |ui, _| {
Picture::new("", 7, &brand).show(ui);
MenuBarUi::new(&bar).target(Target::Windows).mnemonics(&PREFERRED).help_search(true).show(ui);
},
|_, _| {},
);
})
.title_bar(
|_| None,
move |ui, _, _: &mut ()| {
let bar = Rc::clone(&bar);
let layout = craft_window::Layout { left: vec![], right: vec![Caption::Minimize, Caption::Maximize, Caption::Close] };
TitleBar::new().frame(Frame::Integrated(Captions { family: CaptionFamily::Windows, layout })).show_titled(
ui,
Title::new(DOCUMENT),
move |ui, _| {
Picture::new("", 7, &brand).show(ui);
MenuBarUi::new(&bar).target(Target::Windows).mnemonics(&PREFERRED).help_search(true).show(ui);
},
|_, _| {},
);
},
)
.body(|ui, _, _| {
ui.label("Document");
})
+1 -1
View File
@@ -173,7 +173,7 @@ impl EnvValue for craft_theme::ComponentSet {
impl super::StyleValue for craft_theme::ComponentSet {}
/// Where a shell pane sits.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, crate::contract::MemoProps)]
#[non_exhaustive]
pub enum PaneEdge {
/// What the edge panes leave.
+1 -1
View File
@@ -202,7 +202,7 @@ impl ShellApp for Gallery {
let in_theme = self.viewer.workspace == Workspace::Theme;
let shell = |ui: &mut Ui, viewer: &mut Viewer| {
AppShell::new(WindowKey::main())
.options_bar(true, |ui, _, viewer: &mut Viewer| options_bar(ui, viewer))
.options_bar(true, |_| None, |ui, _, viewer: &mut Viewer| options_bar(ui, viewer))
.body_label("Gallery")
.body(body)
.show(ui, viewer);
+3 -3
View File
@@ -80,9 +80,9 @@ impl<'a> EditorMock<'a> {
let window = WindowKey::new(format!("mock-{:x}-{}", ui.scope_id().value(), label.as_str()));
let shell = AppShell::embedded(window)
.screen_mode(screen_mode)
.title_bar_if(true, |ui, _, state: &mut MockState| title_bar(ui, state))
.options_bar(true, |ui, _, state: &mut MockState| options_bar(ui, state))
.status(true, |ui, _, state: &mut MockState| status_bar(ui, state))
.title_bar_if(true, |_| None, |ui, _, state: &mut MockState| title_bar(ui, state))
.options_bar(true, |_| None, |ui, _, state: &mut MockState| options_bar(ui, state))
.status(true, |_| None, |ui, _, state: &mut MockState| status_bar(ui, state))
.body_label(label)
.body(|ui, cx, state: &mut MockState| body(ui, cx, state));
match at {
+4 -3
View File
@@ -105,9 +105,10 @@ pub fn derive_plain_data(input: TokenStream) -> TokenStream {
/// `#[memo_props(address = "why")]` and feeds where it points. A field another field of the same variant stands for (a
/// closure a generation counter covers) carries `#[memo_props(covered_by = "<field>", reason = "why")]` and feeds
/// nothing; the named field must exist and feed the key itself. A type parameter is bound by `MemoProps`, except one
/// marked `#[memo_props(stateless)]`: the type of a callback held as `Stateless<E>`, which no fn item or closure
/// implements `MemoProps` for, is bound by `'static` only (`struct Bar<#[memo_props(stateless)] E> { english:
/// Stateless<E> }`). A type that is a handle to state written during the pass, or a context rebuilt each pass, carries
/// that only `covered_by` fields name, which feeds nothing and takes no bound (the app state `&mut S` a shell slot's view
/// holds), one that only `hash` fields name, bound by `Hash + Sync`, and one marked `#[memo_props(stateless)]`: the type
/// of a callback held as `Stateless<E>`, which no fn item or closure implements `MemoProps` for, is bound by `'static`
/// only (`struct Bar<#[memo_props(stateless)] E> { english: Stateless<E> }`). A type that is a handle to state written during the pass, or a context rebuilt each pass, carries
/// `#[memo_props(every_pass = "why")]`: it feeds no field, and a view whose key holds it runs in every pass.
#[proc_macro_derive(MemoProps, attributes(memo_props))]
pub fn derive_memo_props(input: TokenStream) -> TokenStream {
+4 -2
View File
@@ -91,7 +91,8 @@ fn is_static_ref(ty: &syn::Type) -> bool {
}
/// The field escapes of `MemoProps`: `hash` binds a type parameter only such fields name by what `MemoKey::feed_hash`
/// needs (a dock's panel type); `address` and `covered_by` fields are not checked and keep the trait's bound.
/// needs (a dock's panel type); a `covered_by` field feeds nothing, so a type parameter only such fields name takes no
/// bound (the app state a shell slot's view holds); `address` fields are not checked and keep the trait's bound.
struct MemoEscapes;
impl EscapeRule for MemoEscapes {
@@ -99,7 +100,8 @@ impl EscapeRule for MemoEscapes {
Ok(match feed_of(field)? {
Feed::Props => None,
Feed::Hash => Some(Some(quote!(::core::hash::Hash + ::core::marker::Sync))),
Feed::Address | Feed::Covered(_) => Some(None),
Feed::Covered(_) => Some(Some(TokenStream::new())),
Feed::Address => Some(None),
})
}
}
+4 -2
View File
@@ -46,7 +46,7 @@ pub(crate) struct Escape {
/// Which fields a derive does not check, and what a type parameter that only those fields name is bound by.
pub(crate) trait EscapeRule {
/// `None` when `field` is checked; else `Some(bound)`: what a type parameter that only escaped fields name is bound
/// by instead of the derive's trait (`None` keeps the trait).
/// by instead of the derive's trait (`None` keeps the trait, an empty bound leaves the parameter unbound).
fn escape(&self, field: &syn::Field) -> syn::Result<Option<Option<TokenStream>>>;
}
@@ -129,7 +129,9 @@ pub(crate) fn field_checks(
param.attrs.clear();
let ident = &param.ident;
let only_escaped = named_escaped.0.contains(ident) && !named.0.contains(ident);
let escape_bound = escaped_bounds.iter().find(|(named, _)| named == ident).map(|(_, bound)| bound);
// The first escaped field's bound that binds anything; an empty one (no bound) only when no other is given.
let bounds = || escaped_bounds.iter().filter(|(named, _)| named == ident).map(|(_, bound)| bound);
let escape_bound = bounds().find(|bound| !bound.is_empty()).or_else(|| bounds().next());
let bound = match (param_escape, escape_bound) {
(Some(ParamEscape { bound, .. }), _) if escaped => quote!(#bound),
(_, Some(bound)) if only_escaped => quote!(#bound),
+225 -75
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,134 @@ 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>,
}
/// 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 } = 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 !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]
@@ -201,6 +329,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>,
}
@@ -384,6 +513,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
@@ -447,7 +583,7 @@ 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.
page: Option<(CommandScope, SlotBody<'a, S>)>,
page: Option<(CommandScope, VersionFn<'a, S>, SlotBody<'a, S>)>,
}
impl<'a, S> AppShell<'a, S> {
@@ -491,24 +627,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,
@@ -516,13 +663,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,
@@ -530,43 +678,56 @@ 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
}
/// 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
}
@@ -776,16 +937,23 @@ 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_extent(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));
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)
crate::runtime::commands::note_page_root(&ctx, viewport, shown.output.response.id);
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);
@@ -799,54 +967,36 @@ impl<'a, S> AppShell<'a, S> {
if !*shown || if floats { !covering } else { 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))),
};
// 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
@@ -17,18 +17,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);
})
@@ -40,15 +55,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, _| {
@@ -70,19 +97,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);
})
@@ -112,18 +154,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()
}
@@ -192,10 +246,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);
})
+10 -6
View File
@@ -99,12 +99,16 @@ fn an_embedded_shell_out_of_sight_shows_nothing() {
let below = Rect::from_min_size(egui::pos2(view.min.x, view.max.y + view.height()), egui::vec2(view.width(), view.height()));
let mut open = true;
AppShell::embedded(WindowKey::new("out-of-sight"))
.top(Slot::new("ribbon").size(SlotSize::Content), |ui, _, _: &mut ()| {
if !ui.is_sizing_pass() {
count.set(count.get() + 1);
}
let _ = Button::new("Slot").show(ui);
})
.top(
Slot::new("ribbon").size(SlotSize::Content),
|_| None,
|ui, _, _: &mut ()| {
if !ui.is_sizing_pass() {
count.set(count.get() + 1);
}
let _ = Button::new("Slot").show(ui);
},
)
.body(|ui, _, _| {
let _ = Button::new("Hidden").show(ui);
Dialog::new("Out of sight").opened(Bind::bound(&mut open)).show(ui, |_, _| {});
+363 -210
View File
@@ -1,5 +1,5 @@
//! 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 whose content is a memoized view runs only when its props change. A full-window page hides the slots and the
//! versioned slot replays while its version holds and no input reaches it. A full-window page hides the slots and the
//! body, and its band keeps the window's ends and moves the window. What the body opens stops above the bottom slots.
use craft_host::target::{Os, ShellInfo};
@@ -7,7 +7,7 @@ use craft_theme::Size;
use craft_ui::bars::{Bar, BarKind};
use craft_ui::buttons::Button;
use craft_ui::choice::Checkbox;
use craft_ui::contract::{Bind, CommandSet, Entry, MemoProps, MemoView, Props as _, Role, Scroll, Show as _, ShowContainer as _, Sizing, Trigger};
use craft_ui::contract::{Bind, CommandSet, Entry, Props as _, Role, Scroll, Show as _, ShowContainer as _, Sizing, Trigger};
use craft_ui::dialog::Dialog;
use craft_ui::display::Text;
use craft_ui::layout_components::{Row, Stack};
@@ -16,13 +16,13 @@ use craft_ui::menu::{Menu, MenuItem};
use craft_ui::pickers::Select;
use craft_ui::runtime::InstallSpec;
use craft_ui::runtime::commands::{CommandScope, Commands as _};
use craft_ui::runtime::env::{Env, PageBandRoom, RevealEdge, ShellEntry, WindowKey};
use craft_ui::runtime::env::{PageBandRoom, RevealEdge, WindowKey};
use craft_ui::runtime::windows::{WindowHit, WindowHost};
use craft_ui::shell::{AppShell, Caption, CaptionFamily, Captions, Frame, MacInset, Slot, SlotSize, Title, TitleBar, slots};
use craft_ui::testing::in_audit_run;
use craft_ui::testing::pointer::{press, release};
use craft_ui::testing::pointer::{moved, press, release};
use craft_ui::testing::windows::NoWindows;
use craft_ui::testing::{Fixture, Frames, MemoRun, last_pass_memo_runs, trial};
use craft_ui::testing::{Fixture, Frames, last_pass_runs, trial};
use craft_ui_test_kit::windows::Windows;
use craft_window::policy::{Decision, Desktop, DesktopKind};
use egui::{Event, Key, Modifiers, Rect, Ui, Vec2, ViewportId};
@@ -48,22 +48,26 @@ fn a_bar_in_a_top_slot_fills_it_and_centres_its_members_on_one_line() {
let mut fixture = Fixture::new(move |ui| {
let (mut bar, mut member, mut nested) = (Rect::NOTHING, Rect::NOTHING, Rect::NOTHING);
let shown = AppShell::new(WindowKey::main())
.options_bar(true, |ui, _, _: &mut ()| {
bar = Bar::new("Options", BarKind::Options)
.show(ui, |ui, _| {
member = Button::new("Alpha").show(ui).rect;
Row::new().show(ui, |ui, _| {
nested = Button::new("Beta").show(ui).rect;
Stack::new().show(ui, |ui, _| {
Text::new("Above").show(ui);
Text::new("Below").show(ui);
.options_bar(
true,
|_| None,
|ui, _, _: &mut ()| {
bar = Bar::new("Options", BarKind::Options)
.show(ui, |ui, _| {
member = Button::new("Alpha").show(ui).rect;
Row::new().show(ui, |ui, _| {
nested = Button::new("Beta").show(ui).rect;
Stack::new().show(ui, |ui, _| {
Text::new("Above").show(ui);
Text::new("Below").show(ui);
});
});
});
})
.output
.response
.rect;
})
})
.output
.response
.rect;
},
)
.body(|_, _, _| {})
.show(ui, &mut ());
let slot = shown.regions.slots.iter().find(|(key, _)| *key == "options").map(|(_, rect)| *rect);
@@ -94,35 +98,39 @@ fn a_top_slot_sized_by_its_content_stacks_it_and_takes_its_height() {
let mut fixture = Fixture::new(move |ui| {
let (mut strip, mut row) = (Rect::NOTHING, Rect::NOTHING);
let shown = AppShell::new(WindowKey::main())
.top(Slot::new("ribbon").size(SlotSize::Content), |ui, _, _: &mut ()| {
let top = ui.cursor().min.y;
let strip_x = Row::new()
.show(ui, |ui, _| {
Button::new("Home").show(ui);
Button::new("Insert").show(ui);
})
.output
.rect
.x_range();
let strip_bottom = ui.min_rect().max.y;
let row_top = ui.cursor().min.y;
let row_x = Row::new()
.scroll(Scroll::horizontal())
.fill_width()
.show(ui, |ui, _| {
Stack::new().show(ui, |ui, _| {
for line in ["Paste", "Cut", "Copy", "Format Painter", "Clipboard"] {
Button::new(line).show(ui);
}
});
})
.output
.rect
.x_range();
let bottom = ui.min_rect().max.y;
strip = Rect::from_x_y_ranges(strip_x, top..=strip_bottom);
row = Rect::from_x_y_ranges(row_x, row_top..=bottom);
})
.top(
Slot::new("ribbon").size(SlotSize::Content),
|_| None,
|ui, _, _: &mut ()| {
let top = ui.cursor().min.y;
let strip_x = Row::new()
.show(ui, |ui, _| {
Button::new("Home").show(ui);
Button::new("Insert").show(ui);
})
.output
.rect
.x_range();
let strip_bottom = ui.min_rect().max.y;
let row_top = ui.cursor().min.y;
let row_x = Row::new()
.scroll(Scroll::horizontal())
.fill_width()
.show(ui, |ui, _| {
Stack::new().show(ui, |ui, _| {
for line in ["Paste", "Cut", "Copy", "Format Painter", "Clipboard"] {
Button::new(line).show(ui);
}
});
})
.output
.rect
.x_range();
let bottom = ui.min_rect().max.y;
strip = Rect::from_x_y_ranges(strip_x, top..=strip_bottom);
row = Rect::from_x_y_ranges(row_x, row_top..=bottom);
},
)
.body(|_, _, _| {})
.show(ui, &mut ());
if let Some(slot) = shown.regions.slots.iter().find(|(key, _)| *key == "ribbon").map(|(_, rect)| *rect) {
@@ -177,8 +185,8 @@ fn a_slot_sized_by_its_content_grows_to_a_child_that_fills_its_height() {
let (top_seen, bottom_seen, out) = (Rc::clone(&top), Rc::clone(&bottom), Rc::clone(&regions));
let mut fixture = Fixture::new(move |ui| {
let shown = AppShell::new(WindowKey::main())
.top(Slot::new("ribbon").size(SlotSize::Content), |ui, _, _: &mut ()| fill_column(ui, &TALL, &top_seen))
.bottom(Slot::new("findBar").size(SlotSize::Content), |ui, _, _: &mut ()| fill_column(ui, &TALL, &bottom_seen))
.top(Slot::new("ribbon").size(SlotSize::Content), |_| None, |ui, _, _: &mut ()| fill_column(ui, &TALL, &top_seen))
.bottom(Slot::new("findBar").size(SlotSize::Content), |_| None, |ui, _, _: &mut ()| fill_column(ui, &TALL, &bottom_seen))
.body(|_, _, _| {})
.show(ui, &mut ());
*out.borrow_mut() = Some(shown.regions);
@@ -215,10 +223,14 @@ fn a_content_slot_runs_its_content_once_per_settled_frame_and_grows_in_one_frame
let (count, column, out) = (Rc::clone(&runs), Rc::clone(&seen), Rc::clone(&regions));
let mut fixture = Fixture::new(move |ui| {
let shown = AppShell::new(WindowKey::main())
.top(Slot::new("ribbon").size(SlotSize::Content), |ui, _, _: &mut ()| {
count.set(count.get() + 1);
fill_column(ui, &TALL, &column);
})
.top(
Slot::new("ribbon").size(SlotSize::Content),
|_| None,
|ui, _, _: &mut ()| {
count.set(count.get() + 1);
fill_column(ui, &TALL, &column);
},
)
.body(|_, _, _| {})
.show(ui, &mut ());
*out.borrow_mut() = Some(shown.regions);
@@ -256,14 +268,22 @@ fn content_rails_sit_at_their_sides_and_settle_in_one_pass() {
(Rc::clone(&start), Rc::clone(&end), Rc::clone(&start_runs), Rc::clone(&end_runs), Rc::clone(&regions));
let mut fixture = Fixture::new(move |ui| {
let shown = AppShell::new(WindowKey::main())
.start(Slot::new("tools").size(SlotSize::Content), |ui, _, _: &mut ()| {
start_count.set(start_count.get() + 1);
fill_column(ui, &RAIL, &start_seen);
})
.end(Slot::new("inspector").size(SlotSize::Content), |ui, _, _: &mut ()| {
end_count.set(end_count.get() + 1);
fill_column(ui, &RAIL, &end_seen);
})
.start(
Slot::new("tools").size(SlotSize::Content),
|_| None,
|ui, _, _: &mut ()| {
start_count.set(start_count.get() + 1);
fill_column(ui, &RAIL, &start_seen);
},
)
.end(
Slot::new("inspector").size(SlotSize::Content),
|_| None,
|ui, _, _: &mut ()| {
end_count.set(end_count.get() + 1);
fill_column(ui, &RAIL, &end_seen);
},
)
.body(|_, _, _| {})
.show(ui, &mut ());
*out.borrow_mut() = Some(shown.regions);
@@ -304,15 +324,19 @@ fn a_content_slot_holding_a_scrolling_list_takes_the_list_height() {
let (seen, out) = (Rc::clone(&rows), Rc::clone(&regions));
let mut fixture = Fixture::new(move |ui| {
let shown = AppShell::new(WindowKey::main())
.top(Slot::new("findBar").size(SlotSize::Content), |ui, _, _: &mut ()| {
let mut buttons = Vec::new();
Stack::new().sizing(sizing).scroll(Scroll::vertical()).show(ui, |ui, _| {
for label in ["First", "Second", "Third"] {
buttons.push(Button::new(label).show(ui).rect);
}
});
*seen.borrow_mut() = buttons;
})
.top(
Slot::new("findBar").size(SlotSize::Content),
|_| None,
|ui, _, _: &mut ()| {
let mut buttons = Vec::new();
Stack::new().sizing(sizing).scroll(Scroll::vertical()).show(ui, |ui, _| {
for label in ["First", "Second", "Third"] {
buttons.push(Button::new(label).show(ui).rect);
}
});
*seen.borrow_mut() = buttons;
},
)
.body(|_, _, _| {})
.show(ui, &mut ());
*out.borrow_mut() = Some(shown.regions);
@@ -344,12 +368,16 @@ fn a_labelled_check_box_in_the_options_slot_sits_on_its_middle() {
let (mut check, mut button) = (Rect::NOTHING, Rect::NOTHING);
let mut on = true;
let shown = AppShell::new(WindowKey::main())
.options_bar(true, |ui, _, _: &mut ()| {
let _ = Bar::new("Options", BarKind::Options).show(ui, |ui, _| {
check = Checkbox::new(Bind::bound(&mut on)).label("Anti-alias").show(ui).response.rect;
button = Button::new("Select and Mask").show(ui).rect;
});
})
.options_bar(
true,
|_| None,
|ui, _, _: &mut ()| {
let _ = Bar::new("Options", BarKind::Options).show(ui, |ui, _| {
check = Checkbox::new(Bind::bound(&mut on)).label("Anti-alias").show(ui).response.rect;
button = Button::new("Select and Mask").show(ui).rect;
});
},
)
.body(|_, _, _| {})
.show(ui, &mut ());
if let Some(slot) = shown.regions.slots.iter().find(|(key, _)| *key == "options").map(|(_, rect)| *rect) {
@@ -371,24 +399,31 @@ fn a_title_bar_in_the_title_slot_shows_its_content_there() {
let mut fixture = Fixture::new(move |ui| {
let (mut bar, mut member) = (Rect::NOTHING, Rect::NOTHING);
let shown = AppShell::new(WindowKey::main())
.title_bar(|ui, _, _: &mut ()| {
bar = TitleBar::new()
.show_titled(
ui,
Title::new("S"),
|ui, _| {
member = Button::new("File").show(ui).rect;
},
|_, _| {},
)
.response
.rect;
})
.options_bar(true, |ui, _, _: &mut ()| {
let _ = Bar::new("Options", BarKind::Options).show(ui, |ui, _| {
Button::new("Alpha").show(ui);
});
})
.title_bar(
|_| None,
|ui, _, _: &mut ()| {
bar = TitleBar::new()
.show_titled(
ui,
Title::new("S"),
|ui, _| {
member = Button::new("File").show(ui).rect;
},
|_, _| {},
)
.response
.rect;
},
)
.options_bar(
true,
|_| None,
|ui, _, _: &mut ()| {
let _ = Bar::new("Options", BarKind::Options).show(ui, |ui, _| {
Button::new("Alpha").show(ui);
});
},
)
.body(|_, _, _| {})
.show(ui, &mut ());
if let Some(slot) = shown.regions.slots.iter().find(|(key, _)| *key == "title").map(|(_, rect)| *rect) {
@@ -402,115 +437,213 @@ fn a_title_bar_in_the_title_slot_shows_its_content_there() {
}
thread_local! {
/// The memoized slots that ran on this trial's thread, in order.
/// The versioned slots that ran on this trial's thread, in order.
static SLOT_RUNS: RefCell<Vec<&'static str>> = const { RefCell::new(Vec::new()) };
}
/// Takes the memoized slots that ran since the last call.
/// Counts a run of the slot `name`. An audit run is the replay audit's, not the pass's: the trials count none.
fn slot_ran(ui: &Ui, name: &'static str) {
if !in_audit_run(ui.ctx()) {
SLOT_RUNS.with(|runs| runs.borrow_mut().push(name));
}
}
/// Takes the versioned slots that ran since the last call.
fn slot_runs() -> Vec<&'static str> {
SLOT_RUNS.with(|runs| std::mem::take(&mut *runs.borrow_mut()))
}
/// What a memoized slot shows.
#[derive(MemoProps)]
struct SlotText {
name: &'static str,
text: String,
/// The shell regions that ran in the last pass.
fn regions_ran(ctx: &egui::Context) -> u32 {
last_pass_runs(ctx).iter().filter(|(ty, _)| ty.rsplit("::").next() == Some("ShellRegion")).map(|(_, runs)| runs).sum()
}
fn slot_text(props: &mut SlotText, ui: &mut Ui) {
// An audit run is the replay audit's, not the pass's: the trials count none.
if !in_audit_run(ui.ctx()) {
SLOT_RUNS.with(|runs| runs.borrow_mut().push(props.name));
}
Text::new(props.text.clone()).show(ui);
}
/// Slots whose content is a memoized view run only when their props change: at rest and for a click in the body they
/// replay, a new status runs the status slot alone (one real run, one measuring run), and a slot the app does not
/// memoize runs every pass.
/// Versioned slots replay while their version holds: at rest and with the pointer moving, pressing and releasing in
/// the body, no versioned slot runs, and of the shell's regions only the window's, the scope's, the body's and the
/// unversioned rail's run. The pointer over the status bar runs the status slot alone, a new status version runs it
/// alone, and the unversioned slot runs every pass.
#[trial]
fn memoized_slots_run_only_when_their_props_change() {
let (version, plain, body) = (Cell::new(1), Cell::new(0), Cell::new(Rect::NOTHING));
fn versioned_slots_run_only_when_their_version_changes() {
let (version, plain) = (Cell::new(1_u64), Cell::new(0));
let (body, status) = (Cell::new(Rect::NOTHING), Cell::new(Rect::NOTHING));
let frame = |frames: &mut Frames, events| {
plain.set(0);
frames.frame(events, |ui| {
let out = AppShell::new(WindowKey::main())
.options_bar(true, |ui, _, _: &mut ()| {
let _ = MemoView::new("options", SlotText { name: "options", text: "Options".to_owned() }, slot_text).show(ui);
})
.status(true, |ui, _, _| {
let _ = MemoView::new("status", SlotText { name: "status", text: format!("Ready {}", version.get()) }, slot_text).show(ui);
})
.start(Slot::new("tools"), |ui, _, _| {
plain.set(plain.get() + 1);
Text::new("Tools").show(ui);
})
.title_bar(
|_| Some(0),
|ui, _, _: &mut ()| {
slot_ran(ui, "title");
Text::new("Title").show(ui);
},
)
.options_bar(
true,
|_| Some(0),
|ui, _, _| {
slot_ran(ui, "options");
Text::new("Options").show(ui);
},
)
.status(
true,
|_| Some(version.get()),
|ui, _, _| {
slot_ran(ui, "status");
let _ = Bar::new("Status", BarKind::Status).show(ui, |ui, _| {
Text::new(format!("Ready {}", version.get())).show(ui);
});
},
)
.start(
Slot::new("tools"),
|_| None,
|ui, _, _| {
plain.set(plain.get() + 1);
Text::new("Tools").show(ui);
},
)
.body(|ui, _, _| {
Button::new("Body").show(ui);
})
.show(ui, &mut ());
body.set(out.regions.body);
status.set(out.regions.slots.iter().find(|(key, _)| *key == "status").map_or(Rect::NOTHING, |(_, rect)| *rect));
});
(slot_runs(), plain.get())
(slot_runs(), plain.get(), regions_ran(&frames.ctx))
};
let mut frames = Frames::new();
for _ in 0..30 {
frame(&mut frames, vec![]);
}
let (ran, plain_runs) = frame(&mut frames, vec![]);
assert_eq!(ran, Vec::<&str>::new(), "the memoized slots replay at rest");
assert!(plain_runs > 0, "the slot the app does not memoize runs every pass");
let (ran, plain_runs, regions) = frame(&mut frames, vec![]);
assert_eq!(ran, Vec::<&str>::new(), "the versioned slots replay at rest");
assert!(plain_runs > 0, "the unversioned slot runs every pass");
assert_eq!(regions, 4, "only the window's, the scope's, the body's and the unversioned rail's regions run");
let at = body.get().center();
for events in [vec![press(at)], vec![release(at)], vec![]] {
assert_eq!(frame(&mut frames, events.clone()).0, Vec::<&str>::new(), "a click in the body ({events:?}) leaves the slots replaying");
for events in [vec![moved(at)], vec![press(at)], vec![release(at)], vec![]] {
assert_eq!(frame(&mut frames, events.clone()).0, Vec::<&str>::new(), "the pointer in the body ({events:?}) leaves the slots replaying");
}
let (ran, ..) = frame(&mut frames, vec![moved(status.get().center())]);
assert!(!ran.is_empty() && ran.iter().all(|name| *name == "status"), "the pointer over the status bar runs it alone: {ran:?}");
frame(&mut frames, vec![moved(at)]);
frame(&mut frames, vec![]);
version.set(2);
// One real run, then one measuring run in the first sizing pass that measures the new content: the discard pass its
// new size asks for, whose real run replays the first. A container that measures before the real run of one pass
// makes the same two runs in the other order (ui-widgets body::memo_view, the stack measured first).
assert_eq!(
frame(&mut frames, vec![]).0,
vec!["status", "status"],
"a new status runs the status slot alone: one real run and one measuring run in the sizing pass that measures it"
);
assert!(
last_pass_memo_runs(&frames.ctx).iter().all(|(_, _, run)| *run == MemoRun::Replayed),
"the discard pass's real run replays every slot: {:?}",
last_pass_memo_runs(&frames.ctx)
);
let (ran, ..) = frame(&mut frames, vec![]);
assert!(!ran.is_empty() && ran.iter().all(|name| *name == "status"), "a new status version runs the status slot alone: {ran:?}");
assert_eq!(frame(&mut frames, vec![]).0, Vec::<&str>::new(), "and it replays at it");
}
/// What a slot that registers a revealed rect shows: the rect.
#[derive(MemoProps)]
struct Revealing {
at: Rect,
/// What the pass-order trial's slots share: a count the title slot's button raises, and the count the status slot
/// last showed.
#[derive(Default)]
struct Count {
count: u64,
shown: Option<u64>,
}
fn revealing(props: &mut Revealing, ui: &mut Ui) {
// An audit run is the replay audit's, not the pass's: the trials count none.
if !in_audit_run(ui.ctx()) {
SLOT_RUNS.with(|runs| runs.borrow_mut().push("revealing"));
}
if let Some(shell) = Env::of(ui).view().get::<ShellEntry>().0 {
shell.reveal_rect(ui.ctx(), RevealEdge::Start, props.at);
}
Text::new("Tools").show(ui);
}
/// A memoized view in a slot that registers a revealed rect registers it again when it replays: the shell reads the
/// same rects in a replayed pass as in the run.
/// A slot's version is read at its turn in the pass: a click on the title slot's button raises the count the status
/// slot's version holds, and the status bar shows the new count in the frame of the click.
#[trial]
fn a_replayed_view_in_a_slot_registers_its_revealed_rects() {
fn a_slot_shows_what_an_earlier_slot_changed_in_the_pass() {
let button = Cell::new(Rect::NOTHING);
let frame = |frames: &mut Frames, events, app: &mut Count| {
frames.frame(events, |ui| {
AppShell::new(WindowKey::main())
.title_bar(
|_| Some(0),
|ui, _, app: &mut Count| {
let shown = Button::new("Next").show(ui);
button.set(shown.rect);
if shown.clicks > 0 {
app.count += 1;
}
},
)
.status(
true,
|app| Some(app.count),
|ui, _, app| {
app.shown = Some(app.count);
Text::new(format!("Count {}", app.count)).show(ui);
},
)
.body(|_, _, _| {})
.show(ui, &mut *app);
});
};
let (mut frames, mut app) = (Frames::new(), Count::default());
for _ in 0..3 {
frame(&mut frames, vec![], &mut app);
}
assert_eq!(app.shown, Some(0), "the status bar shows the count");
let at = button.get().center();
frame(&mut frames, vec![press(at)], &mut app);
frame(&mut frames, vec![release(at)], &mut app);
assert_eq!(app.count, 1, "the click raised the count");
assert_eq!(app.shown, Some(1), "the status bar showed the new count in the frame of the click");
}
/// A versioned slot sized by its content keeps its extent while it replays, and a version that grows its content lays
/// the window out again in that frame.
#[trial]
fn a_versioned_content_slot_keeps_its_extent_while_it_replays() {
let (lines, body) = (Cell::new(1_usize), Cell::new(Rect::NOTHING));
let frame = |frames: &mut Frames| {
frames.frame(vec![], |ui| {
let out = AppShell::new(WindowKey::main())
.top(
Slot::new("ribbon").size(SlotSize::Content),
|_| Some(lines.get() as u64),
|ui, _, _: &mut ()| {
slot_ran(ui, "ribbon");
for line in 0..lines.get() {
Text::new(format!("Line {line}")).show(ui);
}
},
)
.body(|_, _, _| {})
.show(ui, &mut ());
body.set(out.regions.body);
});
(slot_runs(), body.get())
};
let mut frames = Frames::new();
for _ in 0..5 {
frame(&mut frames);
}
let (_, settled) = frame(&mut frames);
for _ in 0..5 {
let (ran, at) = frame(&mut frames);
assert_eq!(ran, Vec::<&str>::new(), "the slot replays");
assert_eq!(at, settled, "the body keeps its place under the replayed slot");
}
lines.set(3);
let (ran, grown) = frame(&mut frames);
assert!(ran.contains(&"ribbon"), "a new version runs the slot");
assert!(grown.top() > settled.top(), "the grown slot pushes the body down in the frame it grew: {grown:?} after {settled:?}");
}
/// A versioned slot that registers a revealed rect registers it again when it replays: the shell reads the same rects
/// in a replayed pass as in the run.
#[trial]
fn a_replayed_slot_registers_its_revealed_rects() {
let at = Rect::from_min_size(egui::pos2(0.0, 40.0), Vec2::new(40.0, 120.0));
let seen = RefCell::new(Vec::new());
let frame = |frames: &mut Frames| {
frames.frame(vec![], |ui| {
AppShell::new(WindowKey::main())
.start(Slot::new("tools"), |ui, _, _: &mut ()| {
let _ = MemoView::new("tools", Revealing { at }, revealing).show(ui);
})
.start(
Slot::new("tools"),
|_| Some(0),
|ui, bcx, _: &mut ()| {
slot_ran(ui, "revealing");
if let Some(shell) = bcx.shell() {
shell.reveal_rect(ui.ctx(), RevealEdge::Start, at);
}
Text::new("Tools").show(ui);
},
)
.body(|ui, bcx, _| {
*seen.borrow_mut() = bcx.shell().map(|shell| shell.revealed_rects(ui.ctx())).unwrap_or_default();
})
@@ -552,28 +685,40 @@ fn page_frame(windows: &Windows, runs: &mut PageRuns, dialog: bool, events: Vec<
*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);
})
.title_bar(
|_| None,
|ui, _, runs: &mut PageRuns| {
runs.slots += 1;
Text::new("Title").show(ui);
},
)
.start(
Slot::new("tools"),
|_| None,
|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);
});
}
})
.page(
true,
CommandScope::APP,
|_| None,
|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();
});
@@ -587,9 +732,14 @@ fn caption_widths(windows: &Windows, runs: &mut PageRuns, names: &[&str]) -> Vec
.body(|ui, _, _: &mut PageRuns| {
Text::new("Document").show(ui);
})
.page(true, CommandScope::APP, |ui, _, _: &mut PageRuns| {
Text::new("Print").show(ui);
})
.page(
true,
CommandScope::APP,
|_| None,
|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;
@@ -643,7 +793,7 @@ fn a_page_hides_the_slots_and_its_band_keeps_the_window_ends_and_moves_the_windo
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)]] {
for events in [vec![moved(free)], vec![press(free)], vec![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:?}");
@@ -678,12 +828,17 @@ fn a_page_takes_the_windows_keys_with_nothing_focused() {
.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);
})
.page(
true,
PAGE,
|_| None,
|ui, cx, _: &mut ()| {
while cx.take_command::<PageKeys>().is_some() {
printed.set(printed.get() + 1);
}
Text::new("Print").show(ui);
},
)
.show(ui, &mut ());
});
};
@@ -706,9 +861,13 @@ fn shell_with_status(body: fn(&mut Ui)) -> (Fixture, Rc<Cell<Rect>>) {
let seen = Rc::clone(&slot);
let mut fixture = Fixture::new(move |ui| {
let shown = AppShell::new(WindowKey::main())
.status(true, |ui, _, _: &mut ()| {
Text::new("Ready").show(ui);
})
.status(
true,
|_| None,
|ui, _, _: &mut ()| {
Text::new("Ready").show(ui);
},
)
.body(|ui, _, _| body(ui))
.show(ui, &mut ());
if let Some(rect) = shown.regions.slots.iter().find(|(key, _)| *key == slots::STATUS).map(|(_, rect)| *rect) {
@@ -767,26 +926,22 @@ fn popups_stop_above_the_bottom_slots_in_each_window() {
}
}
/// What a memoized options bar shows: one text button, as an app's tool options.
#[derive(MemoProps)]
struct MemoBar {
version: u64,
}
thread_local! {
/// The rect the memoized bar's button took when it last ran.
/// The rect the options bar's button took when it last ran.
static MEMO_BUTTON: Cell<Rect> = const { Cell::new(Rect::NOTHING) };
}
fn memo_bar(_: &mut MemoBar, ui: &mut Ui) {
/// An options bar of one text button, as an app's tool options.
fn memo_bar(ui: &mut Ui) {
let _ = Bar::new("Options", BarKind::Options).show(ui, |ui, _| {
let rect = Button::new("Straighten").show(ui).rect;
MEMO_BUTTON.with(|button| button.set(rect));
});
}
/// photocraft#16405: an options bar the app shows through a memoized view sits on the slot's line as one shown directly
/// does: its text button is drawn whole, centred in the slot, not cut off at the bottom.
/// photocraft#16405: an options bar in the shell's versioned options slot, which replays it as a memoized view, sits
/// on the slot's line as one shown directly does: its text button is drawn whole, centred in the slot, not cut off at
/// the bottom.
#[trial]
fn a_memoized_options_bar_centres_its_button_in_the_slot() {
for ppp in [1.0, 1.25, 1.5] {
@@ -794,9 +949,7 @@ fn a_memoized_options_bar_centres_its_button_in_the_slot() {
let out = Rc::clone(&seen);
let mut fixture = Fixture::new(move |ui| {
let shown = AppShell::new(WindowKey::main())
.options_bar(true, |ui, _, _: &mut ()| {
let _ = MemoView::new("options", MemoBar { version: 0 }, memo_bar).show(ui);
})
.options_bar(true, |_| Some(0), |ui, _, _: &mut ()| memo_bar(ui))
.body(|_, _, _| {})
.show(ui, &mut ());
if let Some(slot) = shown.regions.slots.iter().find(|(key, _)| *key == "options").map(|(_, rect)| *rect) {
+15 -10
View File
@@ -1,4 +1,5 @@
//! F6 through the app shell: the pane move visits the shell's slots in their order, then the body, then wraps.
//! F6 through the app shell: the pane move visits the shell's slots in their order, then the body, then wraps, with the
//! slots replaying their last run.
use craft_ui::buttons::Button;
use craft_ui::contract::Show as _;
@@ -14,8 +15,8 @@ use std::rc::Rc;
/// The key the trial gives the body pane beside the slot keys.
const BODY: &str = "body";
/// What the shell showed in its last pass: the id of the one button in each pane, and the slot keys in the order the
/// shell laid them out.
/// What the shell showed: the id of the one button in each pane, as the pane's last run showed it, and the slot keys in
/// the order the shell laid them out in its last pass.
#[derive(Default)]
struct Seen {
buttons: Vec<(&'static str, Id)>,
@@ -30,8 +31,8 @@ impl Seen {
}
}
/// A shell with a slot at every edge, added out of the shell's order (end before start, a bottom slot before a top
/// one), each holding one button, and a body holding one button.
/// A shell with a versioned slot at every edge, added out of the shell's order (end before start, a bottom slot before
/// a top one), each holding one button, and a body holding one button.
fn shell(seen: &Rc<RefCell<Seen>>) -> impl FnMut(&mut Ui) {
let seen = Rc::clone(seen);
move |ui: &mut Ui| {
@@ -41,14 +42,18 @@ fn shell(seen: &Rc<RefCell<Seen>>) -> impl FnMut(&mut Ui) {
buttons.borrow_mut().push((key, id));
};
let shown = AppShell::new(WindowKey::main())
.end(Slot::new("inspector"), |ui, _, _: &mut ()| button(ui, "inspector"))
.status(true, |ui, _, _| button(ui, "status"))
.start(Slot::new("tools"), |ui, _, _| button(ui, "tools"))
.options_bar(true, |ui, _, _| button(ui, "options"))
.end(Slot::new("inspector"), |_| Some(0), |ui, _, _: &mut ()| button(ui, "inspector"))
.status(true, |_| Some(0), |ui, _, _| button(ui, "status"))
.start(Slot::new("tools"), |_| Some(0), |ui, _, _| button(ui, "tools"))
.options_bar(true, |_| Some(0), |ui, _, _| button(ui, "options"))
.body(|ui, _, _| button(ui, BODY))
.show(ui, &mut ());
let mut seen = seen.borrow_mut();
seen.buttons = buttons.into_inner();
// A replayed slot shows the button of its last run, with that run's id.
for (key, id) in buttons.into_inner() {
seen.buttons.retain(|(kept, _)| *kept != key);
seen.buttons.push((key, id));
}
seen.order = shown.regions.slots.iter().map(|(key, _)| *key).collect();
}
}
@@ -34,10 +34,14 @@ impl Window {
let mut grip = Rect::NOTHING;
let out = AppShell::new(WindowKey::main())
.options_place(Bind::bound(&mut *place))
.options_bar(true, |ui, _, _: &mut ()| {
grip = BarGrip::new().show(ui).rect;
Text::new("Options").show(ui);
})
.options_bar(
true,
|_| None,
|ui, _, _: &mut ()| {
grip = BarGrip::new().show(ui).rect;
Text::new("Options").show(ui);
},
)
.body(|_, _, _| {})
.show(ui, &mut ());
let options = out.regions.slots.iter().find(|(key, _)| *key == "options").map(|(_, rect)| *rect);
+14 -6
View File
@@ -39,12 +39,20 @@ fn pass(windows: &mut Frames, mode: &mut ScreenMode, events: Vec<Event>) -> Seen
windows.frame(events, |ui| {
let out = AppShell::new(WindowKey::main())
.screen_mode(Bind::bound(&mut *mode))
.start(Slot::new("tools").reveal(), |ui, _, _: &mut ()| {
Text::new("Tools").show(ui);
})
.options_bar(false, |ui, _, _: &mut ()| {
Text::new("Options").show(ui);
})
.start(
Slot::new("tools").reveal(),
|_| Some(0),
|ui, _, _: &mut ()| {
Text::new("Tools").show(ui);
},
)
.options_bar(
false,
|_| Some(0),
|ui, _, _: &mut ()| {
Text::new("Options").show(ui);
},
)
.body(|ui, _, _| {
let canvas = ui.scope_id().with("document");
ui.interact(ui.max_rect(), canvas, Sense::click());
+14 -6
View File
@@ -203,12 +203,20 @@ fn focus_frame(frames: &mut Frames, mode: &mut ScreenMode, dropped: &mut bool, e
.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);
})
.top(
Slot::new("screen").screen_bar(),
|_| None,
|ui, _, _: &mut ()| {
Text::new("Screen").show(ui);
},
)
.top(
Slot::new("ribbon").drops(),
|_| None,
|ui, _, _: &mut ()| {
Text::new("Ribbon").show(ui);
},
)
.body(|ui, _, _| {
Text::new("Document").show(ui);
})
+26 -35
View File
@@ -32,7 +32,7 @@ fn sent(embedded: bool) -> (Vec<ViewportCommand>, Option<Caption>) {
let frame = |events: Vec<Event>| {
windows.frame(events, vec![], |ui| {
if embedded {
let _ = AppShell::embedded(WindowKey::new("preview")).title_bar(|ui, _, _: &mut ()| show_bar(ui)).show(ui, &mut ());
let _ = AppShell::embedded(WindowKey::new("preview")).title_bar(|_| None, |ui, _, _: &mut ()| show_bar(ui)).show(ui, &mut ());
} else {
show_bar(ui);
}
@@ -282,22 +282,25 @@ fn lights_right_bar(follows: bool, lights_right: bool) -> impl Fn(&str) -> Rect
windows.frame(vec![], vec![], |ui| {
let _ = AppShell::new(WindowKey::main())
.title_follows_lights(follows)
.title_bar(|ui, _, _: &mut ()| {
let _ = TitleBar::new()
.trailing(|ui, _| {
Button::new("Discord").show(ui);
Button::new("Preferences").show(ui);
})
.show(ui, |ui, _| {
Button::new("Home").show(ui);
let _ = DocumentTabs::new("Documents", &tabs)
.selected(0)
.trailing(|ui| {
Button::new("Open").show(ui);
})
.show(ui);
});
})
.title_bar(
|_| None,
|ui, _, _: &mut ()| {
let _ = TitleBar::new()
.trailing(|ui, _| {
Button::new("Discord").show(ui);
Button::new("Preferences").show(ui);
})
.show(ui, |ui, _| {
Button::new("Home").show(ui);
let _ = DocumentTabs::new("Documents", &tabs)
.selected(0)
.trailing(|ui| {
Button::new("Open").show(ui);
})
.show(ui);
});
},
)
.body(|_, _, _| {})
.show(ui, &mut ());
})
@@ -354,14 +357,8 @@ fn the_lights_room_follows_the_lights_without_mirroring_the_bar() {
assert!(rect("Preferences").right() >= width - 20.0, "Preferences {:?} at the right end", rect("Preferences"));
}
/// The props of a whole title bar an app shows through a memoized view.
#[derive(craft_ui::contract::MemoProps)]
struct WholeBar {
version: u64,
}
/// A Windows title bar with a brand button, a menu bar of an image editor's menus and the document title.
fn whole_bar(_: &mut WholeBar, ui: &mut Ui) {
fn whole_bar(ui: &mut Ui) {
use craft_ui::buttons::Button;
use craft_ui::contract::Show as _;
use craft_ui::menu::MenuItem;
@@ -397,7 +394,7 @@ fn cursors_over_the_bar(look: craft_ui::contract::MoveBandCursor) -> (Option<cra
let mut root = craft_ui::runtime::env::RootEnv::default();
root.values.set(look);
windows.root_env(root);
let show = |ui: &mut Ui| whole_bar(&mut WholeBar { version: 0 }, ui);
let show = whole_bar;
windows.frame(vec![], vec![], show);
let settled = windows.frame(vec![], vec![], show);
let tree = &settled.trees.iter().rev().find(|(viewport, _)| *viewport == ViewportId::ROOT).expect("the root pass ran").1;
@@ -424,22 +421,16 @@ fn a_move_band_shows_the_arrow_when_the_app_asks() {
assert_eq!(cursors_over_the_bar(MoveBandCursor::Arrow), (None, None), "the arrow over the band and the titles on it");
}
/// A whole title bar an app shows through a memoized view in the shell's title slot (1600 × 1000 px at 125 %) fills
/// the slot as the bar shown directly does: the captions end at the slot's end edge and the document title is drawn
/// whole after the last menu.
/// A whole title bar in the shell's versioned title slot, which replays it as a memoized view (1600 × 1000 px at
/// 125 %), fills the slot as the bar shown directly does: the captions end at the slot's end edge and the document
/// title is drawn whole after the last menu.
#[trial]
fn a_memoized_title_bar_fills_the_title_slot() {
use craft_host::target::Os;
use craft_ui::contract::MemoView;
let slot = Rc::new(Cell::new(Rect::NOTHING));
let seen = Rc::clone(&slot);
let mut fixture = Fixture::new(move |ui| {
let shown = AppShell::new(WindowKey::main())
.title_bar(|ui, _, _: &mut ()| {
let _ = MemoView::new("title bar", WholeBar { version: 0 }, whole_bar).show(ui);
})
.body(|_, _, _| {})
.show(ui, &mut ());
let shown = AppShell::new(WindowKey::main()).title_bar(|_| Some(0), |ui, _, _: &mut ()| whole_bar(ui)).body(|_, _, _| {}).show(ui, &mut ());
if let Some(rect) = shown.regions.slots.iter().find(|(key, _)| *key == "title").map(|(_, rect)| *rect) {
seen.set(rect);
}
+28 -12
View File
@@ -44,18 +44,34 @@ impl Window {
let mut mode = self.mode.get();
let out = AppShell::new(WindowKey::main())
.screen_mode(Bind::bound(&mut mode))
.title(Slot::new("title").reveal(), |ui, _, _| {
Text::new("Title").show(ui);
})
.start(Slot::new("tools").reveal(), |ui, _, _| {
Text::new("Tools").show(ui);
})
.end(Slot::new("inspector").reveal(), |ui, _, _| {
Text::new("Inspector").show(ui);
})
.bottom(Slot::new("status"), |ui, _, _| {
Text::new("Status").show(ui);
})
.title(
Slot::new("title").reveal(),
|_| None,
|ui, _, _| {
Text::new("Title").show(ui);
},
)
.start(
Slot::new("tools").reveal(),
|_| None,
|ui, _, _| {
Text::new("Tools").show(ui);
},
)
.end(
Slot::new("inspector").reveal(),
|_| None,
|ui, _, _| {
Text::new("Inspector").show(ui);
},
)
.bottom(
Slot::new("status"),
|_| None,
|ui, _, _| {
Text::new("Status").show(ui);
},
)
.body(|ui, _, _| {
Canvas::new("Document").show(ui, |_, _| ());
})