mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 23:50:17 +00:00
Framework follow-ups F-16, F-17 (L-220, lead): #[container] forwards least_width; SyncedViews::halves takes a half that may show nothing (Option<PageViewOutput>)
This commit is contained in:
@@ -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<PageViewOutput>,
|
||||
) -> 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
|
||||
});
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user