diff --git a/crates/pages/src/ui/sync_views.rs b/crates/pages/src/ui/sync_views.rs index 0ae026a2da..e7fca8d0bc 100644 --- a/crates/pages/src/ui/sync_views.rs +++ b/crates/pages/src/ui/sync_views.rs @@ -61,7 +61,8 @@ impl Outcome for SyncedViewsOutput { } /// The pair, built per pass: the app draws each half with its own [`PageView`](super::view::PageView) inside the -/// closure, which gets the half's rect, its state and which half it is; the pair keeps the states together. +/// closure, which gets the half's rect, its state and which half it is, and returns the half's page view output +/// (`None` for a half with no pages to show: a closed or empty document); the pair keeps the states together. /// /// ```ignore /// SyncedViews::new("Compare", &mut pair).halves(ui, (&mut old_state, &mut new_state), |ui, rect, state, half| { @@ -79,7 +80,7 @@ impl Outcome for SyncedViewsOutput { /// if let Some(view) = reply.and_then(|reply| reply.view) { /// out.adopt(state, &view); /// } -/// out +/// Some(out) /// }); /// ``` #[derive(craft_ui::contract::Pattern)] @@ -109,7 +110,7 @@ impl<'a> SyncedViews<'a> { self, ui: &mut Ui, states: (&mut PageViewState, &mut PageViewState), - mut half: impl FnMut(&mut Ui, Rect, &mut PageViewState, Lead) -> PageViewOutput, + mut half: impl FnMut(&mut Ui, Rect, &mut PageViewState, Lead) -> Option, ) -> SyncedViewsOutput { let SyncedViews { label, state, captions } = self; let (left, right) = states; @@ -148,7 +149,7 @@ impl<'a> SyncedViews<'a> { } _ => rect, }; - views[pane] = Some(if this == lead { + views[pane] = if this == lead { half(ui, rect, leader, this) } else { let mut copy = follower.clone(); @@ -157,7 +158,7 @@ impl<'a> SyncedViews<'a> { let output = half(ui, rect, &mut copy, this); followed = Some((copy, offset, current)); output - }); + }; } followed }); diff --git a/crates/pages/src/ui/sync_views/stories.rs b/crates/pages/src/ui/sync_views/stories.rs index 44fddb27f4..e12fbd8cd3 100644 --- a/crates/pages/src/ui/sync_views/stories.rs +++ b/crates/pages/src/ui/sync_views/stories.rs @@ -18,7 +18,7 @@ fn pair(ui: &mut Ui, data: &mut StoryData, captions: Option<(&'static str, &'sta } let out = views.halves(ui, (left, right), |ui, rect, state, half| { let label = if half == Lead::Left { "Old pages" } else { "New pages" }; - PageView::new(label, &pages, state, PAPER).show_at(ui, rect, |_, _| ()) + Some(PageView::new(label, &pages, state, PAPER).show_at(ui, rect, |_, _| ())) }); out.edit.response.into() } diff --git a/crates/pages/tests/it/sync_views.rs b/crates/pages/tests/it/sync_views.rs index 3cdc3cfa37..e1fad24a44 100644 --- a/crates/pages/tests/it/sync_views.rs +++ b/crates/pages/tests/it/sync_views.rs @@ -23,7 +23,7 @@ fn captioned_pair(direction: Direction) -> (Fixture, Views) { SyncedViews::new("Compare", &mut pair).captions("Old", "New").halves(ui, (&mut left, &mut right), |ui, rect, state, half| { rects[usize::from(half == Lead::Right)] = Some(rect); let label = if half == Lead::Left { "Old pages" } else { "New pages" }; - PageView::new(label, &pages, state, PAPER).show_at(ui, rect, |_, _| ()) + Some(PageView::new(label, &pages, state, PAPER).show_at(ui, rect, |_, _| ())) }); *seen.borrow_mut() = rects; }); diff --git a/crates/ui-macros/src/props.rs b/crates/ui-macros/src/props.rs index e7867b0ee6..ef3320c33f 100644 --- a/crates/ui-macros/src/props.rs +++ b/crates/ui-macros/src/props.rs @@ -224,6 +224,7 @@ const CONTAINER: &[Forwarded] = &[ ("end", "$ui::contract::EndRegion", "The region at the line's end edge, outside the body scroll."), ("position", "$ui::contract::SetPosition", "The component's place in its set, for assistive technology."), ("collection_body", "", "The body holds one collection that owns the scroll: a layer's own body scroll is off."), + ("least_width", "$ui::contract::LeastWidth", "The least width of the content, from a size role."), ]; /// The builders a `#[container(a, b)]` field names; a bare `#[collection]` or `#[container]` forwards them all.