mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-25 18:02:45 +00:00
Lazy::show_or: a view that leaves its room takes none
next has been red since #2273 on two counts, both in the dock's settling
host view (3bcc5bec4):
- design-lint: contract/lazy.rs named `egui::LayerId` for the run's
layer. The run now holds the runtime's `Layer`, the type `Place` and
`replay::close` already use.
- hovering_a_tab_runs_only_its_group: the dock ran its host view in a
`scope_builder`, which takes room and item spacing in the Lazy's
child even when the host leaves the group to the dock. A replayed
group then sat 4 points lower in flow than a group that ran, so the
child's extent changed whenever a hovered group ran, layout memory
asked for a discard pass, and that pass ran every group (5 runs
where 1 is expected).
`show_or` now runs `add` in a child `Ui` that takes room only when it
returns `Some`, so `otherwise` takes the same place whether it runs or
replays.
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
use crate::layout::{flow_region, take_in_flow};
|
||||
use crate::runtime::egui::alloc;
|
||||
use crate::runtime::egui::areas::Layer;
|
||||
use crate::runtime::env::Env;
|
||||
use crate::runtime::focus;
|
||||
use crate::runtime::layout_memory;
|
||||
@@ -100,12 +101,23 @@ impl Lazy {
|
||||
/// again in the next pass rather than replay it. A dock group's host view is one: where the host leaves the group
|
||||
/// to the dock, the dock's group shows in its place and settles by its own rules. `None` when the child did not
|
||||
/// run: it replayed a run of `add`, or was out of view.
|
||||
///
|
||||
/// `add` runs in a `Ui` that takes room in the child only when it returns `Some`: an `add` that leaves its room
|
||||
/// leaves the child as it found it, so `otherwise` takes the same place whether it runs or replays, and the child's
|
||||
/// extent does not change between them (a change would cost the frame a discard pass).
|
||||
pub fn show_or<T, U>(self, ui: &mut Ui, add: impl FnOnce(&mut Ui) -> Option<T>, otherwise: impl FnOnce(&mut Ui) -> U) -> Option<Result<T, U>> {
|
||||
self.run(ui, |ui, run| match add(ui) {
|
||||
Some(shown) => Ok(shown),
|
||||
None => {
|
||||
run.unkept(ui.ctx());
|
||||
Err(otherwise(ui))
|
||||
self.run(ui, |ui, run| {
|
||||
let mut first = alloc::child(ui, UiBuilder::new().max_rect(flow_region(ui)).layout(*ui.layout()));
|
||||
match add(&mut first) {
|
||||
Some(shown) => {
|
||||
alloc::advance_past(ui, first.min_rect());
|
||||
Ok(shown)
|
||||
}
|
||||
None => {
|
||||
drop(first);
|
||||
run.unkept(ui.ctx());
|
||||
Err(otherwise(ui))
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -206,7 +218,7 @@ impl Lazy {
|
||||
struct Run {
|
||||
recording: bool,
|
||||
kept: bool,
|
||||
layer: egui::LayerId,
|
||||
layer: Layer,
|
||||
}
|
||||
|
||||
impl Run {
|
||||
|
||||
Reference in New Issue
Block a user