mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-26 04:27:49 +00:00
A story runs in its view's shell, in one body
The card runs each story in one Stack inside the view's embedded shell, without a shell of its own per story. The shell counts the dialogs shown in a pass (ShellCx::dialogs_shown), and the card reads the count around its story, so a story's dialog opens over the view. AppShellOutput loses its dialog flag, which only the card read. story-render shows a story in an embedded shell of its own. testing::last_pass_runs counts a pass's runs by component type; the Overview trial asserts that the shell regions don't grow with the stories in view.
This commit is contained in:
@@ -4,8 +4,8 @@
|
||||
//! `new-<Name>--<story>.png` for every story of the component, `new-<Name>.png` for the story its Overview card
|
||||
//! shows (its first), `stories.tsv` and `components.tsv`. Each story runs in a card's story body (`StoryBody`) in a
|
||||
//! fresh context, in ArtCraft Dark at 2 pixels per point with the interface fonts, and its image is cropped to the
|
||||
//! story's surface and the layers it opened. A story whose dialog the card holds behind its button is shown with the
|
||||
//! dialog open.
|
||||
//! story's surface and the layers it opened. A story runs in an embedded shell, over which its dialogs open, and a story
|
||||
//! whose dialog the card holds behind its button is shown with the dialog open.
|
||||
//!
|
||||
//! The bin links the framework and only the domain crates its features name (`--features color` for craft-color's
|
||||
//! components; `--features apps` for every crate, as the gallery links them), so a change in one crate rebuilds that
|
||||
@@ -17,7 +17,8 @@
|
||||
|
||||
use craft_ui::contract::{Pad, Surface};
|
||||
use craft_ui::fonts::{I18nScripts, UiFonts};
|
||||
use craft_ui::runtime::env::RootEnv;
|
||||
use craft_ui::runtime::env::{RootEnv, WindowKey};
|
||||
use craft_ui::shell::AppShell;
|
||||
use craft_ui::testing::snapshot::{Renderer, RgbaImage, layer_rects};
|
||||
use craft_ui::testing::{Frames, StoryRegistration};
|
||||
use craft_ui_gallery::WINDOW;
|
||||
@@ -131,7 +132,10 @@ fn settle(frames: &mut Frames, body: &StoryBody, width: f32, state: &mut CardSta
|
||||
let region = Rect::from_min_size(Pos2::ZERO, Vec2::new(width, Vec2::from(WINDOW).y));
|
||||
let mut frame = |frames: &mut Frames| {
|
||||
frames.frame(Vec::new(), |ui| {
|
||||
*shown = craft_ui::testing::layout::in_region(ui, region, |ui| body.show(ui, state));
|
||||
// The story's dialogs open over the shell around it, as over a gallery view.
|
||||
craft_ui::testing::layout::in_region(ui, region, |ui| {
|
||||
AppShell::embedded(WindowKey::new("story-render")).body(|ui, _, _: &mut ()| *shown = body.show(ui, state)).show(ui, &mut ())
|
||||
});
|
||||
});
|
||||
};
|
||||
for _ in 0..4 {
|
||||
|
||||
@@ -80,7 +80,7 @@ pub(super) fn host(props: &ContainerProps, at: &HostCx<'_>, open: bool, title: &
|
||||
}
|
||||
|
||||
/// Whether a shown container of `mount` is a dialog, a modal or a window for the shell it shows in
|
||||
/// (`ShellCx::dialog_shown`): an OS window or its fallback, a full-window layer, or a layer with a dialog's focus
|
||||
/// (`ShellCx::dialogs_shown`): an OS window or its fallback, a full-window layer, or a layer with a dialog's focus
|
||||
/// scope, modal or not. Menus, list boxes, popovers, tooltips and floating panes are not.
|
||||
fn opens_dialog(mount: &Mount) -> bool {
|
||||
match mount {
|
||||
|
||||
@@ -894,6 +894,7 @@ fn run_in_host<C: Component>(p: &mut Pass<'_, '_, C>, ui: &mut Ui, host_at: Opti
|
||||
|
||||
fn run<C: Component>(mut comp: C, ui: &mut Ui, at: ShowAt, tip: Option<TipFn<'_>>, hooks: &mut dyn ShapeHooks<C>) -> C::Output {
|
||||
let ctx = ui.ctx().clone();
|
||||
crate::runtime::measure::count_run::<C>(&ctx);
|
||||
// Slots the last end hook evicted drop here, outside every lock and hook.
|
||||
memory::dispose_evicted(&ctx);
|
||||
let shape = hooks.shape();
|
||||
|
||||
+11
-9
@@ -4,7 +4,7 @@
|
||||
use super::{AppValues, EnvValue};
|
||||
use egui::Rect;
|
||||
use std::fmt;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::atomic::{AtomicU32, Ordering};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
/// The stable key of a slot.
|
||||
@@ -138,9 +138,10 @@ impl PartialEq for RevealedRects {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the body showed a dialog, modal or window on this pass. The record is shared by the clones of one `ShellCx`.
|
||||
/// How many dialogs, modals and windows the body showed on this pass. The record is shared by the clones of one
|
||||
/// `ShellCx`.
|
||||
#[derive(Clone, Debug, Default)]
|
||||
struct DialogRecord(Arc<AtomicBool>);
|
||||
struct DialogRecord(Arc<AtomicU32>);
|
||||
|
||||
impl PartialEq for DialogRecord {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
@@ -271,14 +272,15 @@ impl ShellCx {
|
||||
/// container mount records itself here, measuring runs included.
|
||||
#[doc(hidden)]
|
||||
pub fn note_dialog(&self) {
|
||||
self.inner.dialog.0.store(true, Ordering::Relaxed);
|
||||
self.inner.dialog.0.fetch_add(1, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
/// Whether a container in this shell showed on this pass as a dialog (a layer with a dialog's focus scope, modal or
|
||||
/// not), a full-window layer or an OS window: open, or closed and still fading out. Menus, list boxes, popovers and
|
||||
/// tooltips do not count. A host reads it after the body ran. A measure of the body records open containers only
|
||||
/// (it runs no fades), so a host that reads it there knows before the first paint.
|
||||
pub fn dialog_shown(&self) -> bool {
|
||||
/// How many times a container in this shell showed on this pass as a dialog (a layer with a dialog's focus scope,
|
||||
/// modal or not), a full-window layer or an OS window: open, or closed and still fading out. Menus, list boxes,
|
||||
/// popovers and tooltips do not count. A host reads it after the body ran, or before and after a part of the body
|
||||
/// to learn whether that part showed one. A measure of the body records open containers only (it runs no fades), so
|
||||
/// a host that reads it there knows before the first paint.
|
||||
pub fn dialogs_shown(&self) -> u32 {
|
||||
self.inner.dialog.0.load(Ordering::Relaxed)
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,14 @@ struct BodyRuns {
|
||||
runs: Vec<(Id, u32)>,
|
||||
}
|
||||
|
||||
/// The runs of each component type, with the pass that counted them.
|
||||
#[cfg(feature = "testing")]
|
||||
#[derive(Default)]
|
||||
struct TypeRuns {
|
||||
pass: u64,
|
||||
runs: Vec<(&'static str, u32)>,
|
||||
}
|
||||
|
||||
/// The collections whose widest row was built and measured, with the pass that counted them.
|
||||
#[cfg(feature = "testing")]
|
||||
#[derive(Default)]
|
||||
@@ -134,6 +142,35 @@ pub fn body_runs(ctx: &Context) -> Vec<(Id, u32)> {
|
||||
store::with::<BodyRuns, _>(ctx, |log| log.runs.clone())
|
||||
}
|
||||
|
||||
/// Counts a run of a component of type `C` in this pass, measuring or real. Counts nothing without `testing`.
|
||||
#[inline]
|
||||
pub(crate) fn count_run<C>(ctx: &Context) {
|
||||
#[cfg(feature = "testing")]
|
||||
{
|
||||
let name = std::any::type_name::<C>();
|
||||
let pass = ctx.cumulative_pass_nr();
|
||||
store::with::<TypeRuns, _>(ctx, |log| {
|
||||
if log.pass != pass {
|
||||
*log = TypeRuns { pass, runs: Vec::new() };
|
||||
}
|
||||
match log.runs.iter_mut().find(|(ty, _)| *ty == name) {
|
||||
Some((_, count)) => *count += 1,
|
||||
None => log.runs.push((name, 1)),
|
||||
}
|
||||
});
|
||||
}
|
||||
#[cfg(not(feature = "testing"))]
|
||||
let _ = ctx;
|
||||
}
|
||||
|
||||
/// The component types that ran in the last pass, by type name, and how many runs each, measuring runs included;
|
||||
/// empty when that pass ran none.
|
||||
#[cfg(feature = "testing")]
|
||||
pub fn last_pass_runs(ctx: &Context) -> Vec<(&'static str, u32)> {
|
||||
let last = ctx.cumulative_pass_nr().saturating_sub(1);
|
||||
store::with::<TypeRuns, _>(ctx, |log| if log.pass == last { log.runs.clone() } else { Vec::new() })
|
||||
}
|
||||
|
||||
/// Counts a build and measure of the rows of the collection `id` for its widest row in this pass.
|
||||
#[cfg(feature = "testing")]
|
||||
pub(crate) fn count_widest(ctx: &Context, id: Id) {
|
||||
|
||||
@@ -38,8 +38,8 @@ pub use crate::contract::{Exemption, PatternKind, PatternProbe, Probe, Registrat
|
||||
#[cfg(feature = "testing")]
|
||||
pub use crate::runtime::layout_memory::forget_kept as forget_measurements;
|
||||
pub use crate::runtime::measure::{
|
||||
active as is_measuring, body_runs as measuring_runs, last_pass_body_runs as last_pass_measuring_runs, run as measuring_run, take_effects,
|
||||
widest_runs,
|
||||
active as is_measuring, body_runs as measuring_runs, last_pass_body_runs as last_pass_measuring_runs, last_pass_runs, run as measuring_run,
|
||||
take_effects, widest_runs,
|
||||
};
|
||||
pub use craft_ui_macros::{story, trial};
|
||||
pub use fixture::{Fixture, Impure, Room, Target};
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
//! One card: stories live on their surface under a header with the component's name and, while a story differs from
|
||||
//! its start, Reset; the Open command of an Overview card opens the component's tab. A card of several stories lays
|
||||
//! them out as the component's catalog entry says, each under its caption. Each story runs in an embedded shell, so
|
||||
//! its dialogs open inside the card. [`StoryBody`] is the story part alone, which the story renderer (`story-render`) shows too.
|
||||
//! them out as the component's catalog entry says, each under its caption. A story runs in the shell of the view the card
|
||||
//! is in, so its dialogs open over that view, as an app's do. [`StoryBody`] is the story part alone, which the story
|
||||
//! renderer (`story-render`) shows too.
|
||||
|
||||
use crate::viewer::{CardState, Cells, DialogState};
|
||||
use craft_behavior::{ColumnWidth, IconId};
|
||||
@@ -12,16 +13,15 @@ use craft_ui::contract::Show as _;
|
||||
use craft_ui::contract::{CommandSet, Commands as _, Gap, Pad, Props as _, ShowContainer as _, Sizing, StoryLayout, Surface, ThemeScope};
|
||||
use craft_ui::display::{Shade, Text};
|
||||
use craft_ui::layout_components::{Grid, Stack};
|
||||
use craft_ui::runtime::env::{WindowKey, with_env};
|
||||
use craft_ui::runtime::env::with_env;
|
||||
use craft_ui::runtime::layout_memory;
|
||||
use craft_ui::sections::{HeaderCommand, HeaderStrength, Panel};
|
||||
use craft_ui::shell::AppShell;
|
||||
use craft_ui::style::SurfaceKind;
|
||||
use craft_ui::testing::{StoryData, StoryOutput, StoryRegistration};
|
||||
|
||||
/// A story's show function.
|
||||
type StoryFn = fn(&mut Ui, &mut StoryData) -> StoryOutput;
|
||||
use egui::{Id, Rect, Ui, vec2};
|
||||
use egui::{Id, Rect, Ui};
|
||||
|
||||
/// The header commands of a card.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, CommandSet)]
|
||||
@@ -182,7 +182,7 @@ impl Card<'_> {
|
||||
for story in self.stories {
|
||||
Text::new(story.caption.to_owned()).show(ui);
|
||||
let body = self.story_body(story, None);
|
||||
Stack::new().fill_width().show(ui, |ui, _| body.show(ui, cells.entry(story.index).or_default()));
|
||||
body.show(ui, cells.entry(story.index).or_default());
|
||||
Text::new(body.value_text(ui).unwrap_or_default()).shade(Shade::Muted).show(ui);
|
||||
}
|
||||
});
|
||||
@@ -193,7 +193,7 @@ impl Card<'_> {
|
||||
let columns = fit.clamp(1, usize::from(most).clamp(1, COLUMNS.len()));
|
||||
Grid::new(&COLUMNS[..columns]).gap(Gap::Item).fill_width().show(ui, |ui, _| {
|
||||
for story in self.stories {
|
||||
Stack::new().fill_width().show(ui, |ui, _| self.body(ui, story, Some(story.caption), cells));
|
||||
self.body(ui, story, Some(story.caption), cells);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -249,8 +249,7 @@ pub struct StoryBody {
|
||||
#[derive(Clone, Debug, Default)]
|
||||
#[non_exhaustive]
|
||||
pub struct BodyShown {
|
||||
/// Where the story shows in flow: its surface, or the whole room for a story that takes no room in flow; `None`
|
||||
/// for a story that shows only a dialog.
|
||||
/// Where the story shows in flow: its surface; `None` while the button that opens the story's dialog shows.
|
||||
pub flow: Option<Rect>,
|
||||
}
|
||||
|
||||
@@ -260,17 +259,16 @@ impl StoryBody {
|
||||
StoryBody { key: key.into(), story, surface, room, look: Look::default(), gated: false, panel_pad, caption: None }
|
||||
}
|
||||
|
||||
/// The story on its surface, in an embedded shell of its own so its dialogs stay in the card. The shell is as tall
|
||||
/// as the story's content, or the whole room for a story that shows a dialog.
|
||||
/// The story on its surface, in the shell around the body: its dialogs open over the shell's view.
|
||||
///
|
||||
/// A story that opens a dialog, a modal or a window starts closed behind a button, and nothing of what it opens
|
||||
/// paints before the button is pressed. The card's shell records what the story shows (`ShellCx::dialog_shown`). A
|
||||
/// story that has not painted yet runs only in a pass that can still be discarded, and when the shell's record
|
||||
/// changes what the card shows, the card discards the pass, so nothing of that pass paints. The button turns the
|
||||
/// story's `open` value on and runs it, which opens the real thing (an OS window where the component uses one).
|
||||
/// Once nothing shows any more, the exit fade included, the card shows the button again.
|
||||
/// paints before the button is pressed. The shell counts what shows as a dialog (`ShellCx::dialogs_shown`), and the
|
||||
/// body reads the count before and after its story. A story that has not painted yet runs only in a pass that can
|
||||
/// still be discarded, and when the count changes what the card shows, the card discards the pass, so nothing of
|
||||
/// that pass paints. The button turns the story's `open` value on and runs it, which opens the real thing (an OS
|
||||
/// window where the component uses one). Once nothing shows any more, the exit fade included, the card shows the
|
||||
/// button again.
|
||||
pub fn show(&self, ui: &mut Ui, state: &mut CardState) -> BodyShown {
|
||||
let window = WindowKey::new(format!("card-{}-{}", self.key, state.resets));
|
||||
let host = Host {
|
||||
caption: self.caption.as_deref(),
|
||||
id: craft_ui::testing::memory::global("gallery.card.story", (&self.key, state.resets)),
|
||||
@@ -289,51 +287,44 @@ impl StoryBody {
|
||||
ui.ctx().request_repaint();
|
||||
state.show_dialog();
|
||||
}
|
||||
// A story that has not painted yet runs only in a pass that can still be discarded: what its shell's record
|
||||
// finds open would paint otherwise. The next frame's first pass runs it.
|
||||
// A story that has not painted yet runs only in a pass that can still be discarded: what the shell's count finds
|
||||
// open would paint otherwise. The next frame's first pass runs it.
|
||||
let runs = state.dialog.painted || craft_ui::runtime::frame::discardable(ui.ctx());
|
||||
let ran = std::cell::Cell::new(false);
|
||||
let flow = std::cell::Cell::new(None);
|
||||
// Whether the story ran for real in this pass (not in a measuring run, nor in place of a kept measurement), and
|
||||
// whether a dialog of it showed then.
|
||||
let ran = std::cell::Cell::new(None);
|
||||
let value_key = self.value_key();
|
||||
let shell = AppShell::embedded(window).body(|ui, _, data: &mut StoryData| {
|
||||
if runs {
|
||||
ran.set(!ui.is_sizing_pass());
|
||||
let surface = host.stack().show(ui, |ui, _| host.content(ui, show, data));
|
||||
flow.set(Some(surface.output.rect));
|
||||
if let Some(output) = &surface.inner {
|
||||
layout_memory::emit_text(ui.ctx(), value_key, output.value_text.as_deref());
|
||||
}
|
||||
let data = &mut state.data;
|
||||
let surface = host.stack().show(ui, |ui, cx| {
|
||||
if !runs {
|
||||
return;
|
||||
}
|
||||
let shell = cx.shell();
|
||||
let before = shell.as_ref().map_or(0, |shell| shell.dialogs_shown());
|
||||
let output = host.content(ui, show, data);
|
||||
if !ui.is_sizing_pass() {
|
||||
ran.set(Some(shell.is_some_and(|shell| shell.dialogs_shown() > before)));
|
||||
}
|
||||
layout_memory::emit_text(ui.ctx(), value_key, output.value_text.as_deref());
|
||||
});
|
||||
// A story that shows a dialog gets the whole room for it.
|
||||
let dialog_room = state.dialog.known;
|
||||
let shown = if dialog_room {
|
||||
let rect = Rect::from_min_size(ui.available_rect_before_wrap().min, vec2(ui.available_width(), self.room));
|
||||
shell.show_at(ui, rect, &mut state.data)
|
||||
} else {
|
||||
shell.content_height(self.room).show(ui, &mut state.data)
|
||||
};
|
||||
if !runs {
|
||||
ui.ctx().request_repaint();
|
||||
}
|
||||
// The shell runs its body only in real runs (not in the card's own measuring runs, nor scrolled out of sight), so
|
||||
// its record counts only when the story ran.
|
||||
if ran.get() {
|
||||
if let Some(shown) = ran.get() {
|
||||
let dialog = &mut state.dialog;
|
||||
if shown.dialog && !dialog.painted {
|
||||
if shown && !dialog.painted {
|
||||
close_at_start(state);
|
||||
craft_ui::runtime::frame::discard_pass(ui.ctx(), "gallery: a card's story showed a dialog before it painted");
|
||||
} else if dialog.known && !dialog.hidden && dialog.shown && !shown.dialog {
|
||||
} else if dialog.known && !dialog.hidden && dialog.shown && !shown {
|
||||
*dialog = DialogState { known: true, hidden: true, shown: false, painted: true };
|
||||
craft_ui::runtime::frame::discard_pass(ui.ctx(), "gallery: a card's dialog closed");
|
||||
} else {
|
||||
dialog.shown |= dialog.known && shown.dialog;
|
||||
dialog.shown |= dialog.known && shown;
|
||||
dialog.painted = true;
|
||||
}
|
||||
}
|
||||
state.note_start();
|
||||
let flow = if dialog_room { None } else { flow.get() };
|
||||
BodyShown { flow }
|
||||
BodyShown { flow: Some(surface.output.rect) }
|
||||
}
|
||||
|
||||
/// The shown value as the story's component words it ([`StoryOutput::value_text`]), as this pass's run of the
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use craft_settings::{Location, OpenOptions, SettingsStore};
|
||||
use craft_ui::runtime::access::Role;
|
||||
use craft_ui::shell::app::ShellApp;
|
||||
use craft_ui::testing::{Fixture, last_pass_measuring_runs, pointer, trial};
|
||||
use craft_ui::testing::{Fixture, last_pass_measuring_runs, last_pass_runs, pointer, trial};
|
||||
use craft_ui_gallery::chrome::{Gallery, Persisted};
|
||||
use craft_ui_gallery::viewer::{Catalog, GallerySettings, by_level};
|
||||
use egui::Vec2;
|
||||
@@ -42,8 +42,7 @@ fn each_level_of_the_overview_first_runs_the_cards_in_view() {
|
||||
}
|
||||
}
|
||||
|
||||
/// A settled Overview pass runs each story once, in its card's shell: no card or story runs a measuring run while its
|
||||
/// inputs hold.
|
||||
/// A settled Overview pass runs each story once: no card or story runs a measuring run while its inputs hold.
|
||||
#[trial]
|
||||
fn a_settled_overview_pass_runs_no_measuring_run() {
|
||||
let mut gallery = gallery_at("Composites");
|
||||
@@ -53,6 +52,23 @@ fn a_settled_overview_pass_runs_no_measuring_run() {
|
||||
assert!(runs.is_empty(), "a settled pass measured {} bodies: {runs:?}", runs.len());
|
||||
}
|
||||
|
||||
/// The `ShellRegion` runs of a settled Overview pass: the regions of the window's and the view's shells.
|
||||
fn shell_runs(level: &str, filter: &str) -> u32 {
|
||||
let mut gallery = gallery_filtered(level, filter);
|
||||
let mut fixture = Fixture::new(move |ui| gallery.ui(ui));
|
||||
fixture.room(Vec2::new(1400.0, 900.0)).settle().idle(1);
|
||||
last_pass_runs(fixture.ctx()).iter().filter(|(ty, _)| ty.ends_with("::ShellRegion")).map(|(_, runs)| runs).sum()
|
||||
}
|
||||
|
||||
/// A story runs in the view's shell, not in one of its own: a settled Overview pass runs as many shell regions with
|
||||
/// every card of a level in view as with one card.
|
||||
#[trial]
|
||||
fn a_settled_overview_pass_runs_no_shell_per_story() {
|
||||
let (all, one) = (shell_runs("Controls", ""), shell_runs("Controls", "Slider"));
|
||||
assert!(all > 0, "the window's shell runs its regions");
|
||||
assert_eq!(all, one, "the shell regions grow with the stories in view: {one} with the Slider cards, {all} with the level");
|
||||
}
|
||||
|
||||
/// A card in form rows shows each story's value text beside it, as the story's run found it: a settled frame of the
|
||||
/// Slider card, whose bodies take their kept measurements in place of running the stories, runs one pass.
|
||||
#[trial]
|
||||
@@ -77,45 +93,56 @@ fn painted(fixture: &Fixture, text: &str) -> bool {
|
||||
}
|
||||
|
||||
fn openers(fixture: &Fixture) -> usize {
|
||||
fixture.texts().iter().filter(|run| run.text == "Show dialog").count()
|
||||
painted_times(fixture, "Show dialog")
|
||||
}
|
||||
|
||||
/// A dialog in an embedded shell of the story's own is out of the story's measure; the card still starts it closed
|
||||
/// before anything of it paints, opens it by the button, and shows the button again once the story closed both.
|
||||
fn painted_times(fixture: &Fixture, text: &str) -> usize {
|
||||
fixture.texts().iter().filter(|run| run.text == text).count()
|
||||
}
|
||||
|
||||
/// The level the component listed as `name` is on.
|
||||
fn level_of(name: &str) -> &'static str {
|
||||
let catalog = Catalog::linked();
|
||||
by_level(&catalog, "")
|
||||
.into_iter()
|
||||
.find(|(_, cards)| cards.iter().any(|component| component.name == name))
|
||||
.map(|(level, _)| level.title())
|
||||
.unwrap_or_else(|| panic!("{name} is on a level"))
|
||||
}
|
||||
|
||||
/// A story's dialog opens over the view, in the view's shell: the card starts it closed before anything of it paints,
|
||||
/// opens it by the button, and shows the button again once the dialog closed.
|
||||
#[trial]
|
||||
fn dialogs_in_a_storys_own_shell_start_closed_and_close_back_to_the_opener() {
|
||||
fn a_storys_dialog_starts_closed_opens_over_the_view_and_closes_back_to_the_opener() {
|
||||
let (mut store, report) = SettingsStore::<GallerySettings>::open_with(OpenOptions::new(Location::Memory));
|
||||
let mut settings = store.get().clone();
|
||||
settings.level = "Shells".to_owned();
|
||||
settings.filter = "AppShell".to_owned();
|
||||
settings.stories.insert(type_of("AppShell").to_owned(), "app_shell_dialogs_in_regions".to_owned());
|
||||
settings.level = level_of("Dialog").to_owned();
|
||||
settings.filter = "Dialog".to_owned();
|
||||
settings.stories.insert(type_of("Dialog").to_owned(), "dialog".to_owned());
|
||||
store.set(settings);
|
||||
let mut gallery = Gallery::new(Catalog::linked(), Persisted::new(store, &report));
|
||||
let mut fixture = Fixture::new(move |ui| gallery.ui(ui));
|
||||
fixture.room(Vec2::new(1400.0, 900.0)).idle(1);
|
||||
let over = fixture.by_label("Open").expect("the card's Open").rect.center();
|
||||
let high = fixture.shown().height() / 5.0;
|
||||
assert_eq!(openers(&fixture), 1, "the picked story shows its opener");
|
||||
assert!(!painted(&fixture, "Snap to grid"), "nothing of the dialogs paints before the opener is pressed");
|
||||
let opener = fixture.by_label("Show dialog").expect("the opener");
|
||||
fixture.room(Vec2::new(1400.0, 900.0)).settle();
|
||||
// Other cards of the filter show the same body in flow.
|
||||
let (closed, inline) = (openers(&fixture), painted_times(&fixture, "Snap to grid"));
|
||||
assert!(closed >= 1, "the picked story shows its opener");
|
||||
// The Dialog card's opener: the first under the card's title, in its column.
|
||||
let title = fixture.texts().into_iter().find(|run| run.text == "Dialog").expect("the Dialog card's title").rect;
|
||||
let opener = fixture
|
||||
.by_role(Role::BUTTON)
|
||||
.into_iter()
|
||||
.filter(|button| fixture.tree().name_of(button.node) == Some("Show dialog"))
|
||||
.filter(|button| button.rect.top() > title.top() && button.rect.left() < title.right() && button.rect.right() > title.left() - 40.0)
|
||||
.min_by(|a, b| a.rect.top().total_cmp(&b.rect.top()))
|
||||
.expect("the Dialog card's opener");
|
||||
fixture.click(&opener).settle();
|
||||
assert!(painted(&fixture, "Snap to grid"), "the opener opens the dialogs");
|
||||
assert_eq!(openers(&fixture), 0, "the opener gives way to the story");
|
||||
// The story now takes a view's height under the opener's place: the wheel brings its dialogs up into view.
|
||||
for _ in 0..60 {
|
||||
if fixture.by_label("Close").is_some_and(|close| close.rect.top() < 2.0 * high) {
|
||||
break;
|
||||
}
|
||||
fixture.frame(vec![pointer::moved(over)]).frame(vec![pointer::wheel(-120.0)]).idle(1);
|
||||
}
|
||||
for _ in 0..2 {
|
||||
let close = fixture.by_label("Close").expect("a dialog's close button");
|
||||
fixture.click(&close).settle();
|
||||
// The exit fade runs on the fixture's clock.
|
||||
fixture.advance(1.0).settle();
|
||||
}
|
||||
assert!(!painted(&fixture, "Snap to grid"), "both dialogs closed");
|
||||
assert_eq!(openers(&fixture), 1, "closing the story's dialogs brings the opener back");
|
||||
assert_eq!(painted_times(&fixture, "Snap to grid"), inline + 1, "the opener opens the dialog");
|
||||
assert_eq!(openers(&fixture), closed - 1, "the opener gives way to the story");
|
||||
fixture.key(egui::Key::Escape, egui::Modifiers::NONE).settle();
|
||||
// The exit fade runs on the fixture's clock.
|
||||
fixture.advance(1.0).settle();
|
||||
assert_eq!(painted_times(&fixture, "Snap to grid"), inline, "the dialog closed");
|
||||
assert_eq!(openers(&fixture), closed, "closing the story's dialog brings the opener back");
|
||||
}
|
||||
|
||||
/// Regression: the wheel over a canvas card went to its story and the Overview stopped scrolling; inside a
|
||||
|
||||
@@ -201,7 +201,6 @@ struct Parts {
|
||||
revealed: bool,
|
||||
panels_hidden: bool,
|
||||
mode: ScreenMode,
|
||||
dialog: bool,
|
||||
}
|
||||
|
||||
/// What [`AppShell::show`] drew.
|
||||
@@ -219,12 +218,6 @@ pub struct AppShellOutput {
|
||||
pub panels_hidden: bool,
|
||||
/// The screen mode after this pass.
|
||||
pub screen_mode: ScreenMode,
|
||||
/// For an embedded shell: its body or its dialog host showed a container on this pass as a dialog, a modal, a
|
||||
/// full-window layer or an OS window, open or still fading out (`ShellCx::dialog_shown`), its own or one of an
|
||||
/// embedded shell inside it. Menus, popovers and tooltips do not count. A host that keeps such content closed until
|
||||
/// asked reads it from a measure of the body under a `ShellCx` of its own, before the first paint, and here for
|
||||
/// what the measure cannot reach: the body of an embedded shell inside, which runs in real runs only.
|
||||
pub dialog: bool,
|
||||
}
|
||||
|
||||
impl Outcome for AppShellOutput {
|
||||
@@ -558,14 +551,12 @@ impl<'a, S> AppShell<'a, S> {
|
||||
}
|
||||
});
|
||||
// What shows here counts for the shell around this one too, so a host reads it from its own shell.
|
||||
let opened = scope.dialog_shown();
|
||||
if opened
|
||||
if scope.dialogs_shown() > 0
|
||||
&& !ui.is_sizing_pass()
|
||||
&& let Some(outer) = &outer
|
||||
{
|
||||
outer.note_dialog();
|
||||
}
|
||||
let dialog = embedded && opened;
|
||||
|
||||
ToastStack::show(ui);
|
||||
|
||||
@@ -580,7 +571,7 @@ impl<'a, S> AppShell<'a, S> {
|
||||
kept.reveal.record(edges);
|
||||
let revealed = only && !regions.slots.is_empty();
|
||||
*cx.keep::<ShellState>() = kept;
|
||||
Parts { regions, revealed, panels_hidden, mode, dialog }
|
||||
Parts { regions, revealed, panels_hidden, mode }
|
||||
};
|
||||
let shown = match at {
|
||||
Some(rect) => root.show_at_taking_room(ui, rect, shell_body),
|
||||
@@ -594,7 +585,6 @@ impl<'a, S> AppShell<'a, S> {
|
||||
revealed: parts.revealed,
|
||||
panels_hidden: parts.panels_hidden,
|
||||
screen_mode: parts.mode,
|
||||
dialog: parts.dialog,
|
||||
},
|
||||
None => AppShellOutput {
|
||||
response,
|
||||
@@ -602,7 +592,6 @@ impl<'a, S> AppShell<'a, S> {
|
||||
revealed: false,
|
||||
panels_hidden: false,
|
||||
screen_mode: ScreenMode::default(),
|
||||
dialog: false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user