diff --git a/crates/menu/tests/it/title_bar.rs b/crates/menu/tests/it/title_bar.rs index 15543e8d97..8c1260f038 100644 --- a/crates/menu/tests/it/title_bar.rs +++ b/crates/menu/tests/it/title_bar.rs @@ -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"); }) diff --git a/crates/ui-contract/src/runtime/env/values.rs b/crates/ui-contract/src/runtime/env/values.rs index 38a1b88494..64263b8989 100644 --- a/crates/ui-contract/src/runtime/env/values.rs +++ b/crates/ui-contract/src/runtime/env/values.rs @@ -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. diff --git a/crates/ui-gallery/src/chrome/shell.rs b/crates/ui-gallery/src/chrome/shell.rs index f46c1aad30..7ccc434a91 100644 --- a/crates/ui-gallery/src/chrome/shell.rs +++ b/crates/ui-gallery/src/chrome/shell.rs @@ -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); diff --git a/crates/ui-gallery/src/mock/editor.rs b/crates/ui-gallery/src/mock/editor.rs index a2414aa89e..0855af602c 100644 --- a/crates/ui-gallery/src/mock/editor.rs +++ b/crates/ui-gallery/src/mock/editor.rs @@ -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 { diff --git a/crates/ui-macros/src/lib.rs b/crates/ui-macros/src/lib.rs index fdc5d6d350..b5c0c419ad 100644 --- a/crates/ui-macros/src/lib.rs +++ b/crates/ui-macros/src/lib.rs @@ -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 = "", 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`, which no fn item or closure -/// implements `MemoProps` for, is bound by `'static` only (`struct Bar<#[memo_props(stateless)] E> { english: -/// Stateless }`). 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`, which no fn item or closure implements `MemoProps` for, is bound by `'static` +/// only (`struct Bar<#[memo_props(stateless)] E> { english: Stateless }`). 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 { diff --git a/crates/ui-macros/src/memo.rs b/crates/ui-macros/src/memo.rs index cf5813ef3d..9ed0446dde 100644 --- a/crates/ui-macros/src/memo.rs +++ b/crates/ui-macros/src/memo.rs @@ -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), }) } } diff --git a/crates/ui-macros/src/plain.rs b/crates/ui-macros/src/plain.rs index db9f01288d..f4b8ebafd1 100644 --- a/crates/ui-macros/src/plain.rs +++ b/crates/ui-macros/src/plain.rs @@ -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>>; } @@ -129,7 +129,9 @@ pub(crate) fn field_checks( param.attrs.clear(); let ident = ¶m.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), diff --git a/crates/ui-shell/src/shell/app_shell.rs b/crates/ui-shell/src/shell/app_shell.rs index f2a27ca6f2..984c07aeca 100644 --- a/crates/ui-shell/src/shell/app_shell.rs +++ b/crates/ui-shell/src/shell/app_shell.rs @@ -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 Option + '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, + label: Option