Skip to main content

egui_pop_core/
sections.rs

1//! Collapsible sections stacked in a panel: each a title band (a
2//! disclosure mark, a title, a count) over its own scrolling body, as a
3//! code editor's side bar stacks its views.
4//!
5//! <div class="warning">Experimental: may change in any release
6//! (docs/stability.md).</div>
7//!
8//! The stack is egui_stack's ([`egui_stack::sections`]), which holds the
9//! layout arithmetic ([`plan`]), the drag, the fold, the keyboard, the
10//! accessibility, the windowed rows and the wheel. egui-pop gives it its
11//! look, its words and its gestures:
12//!
13//! - A click on a band, or Space or Enter while it has the keyboard,
14//!   folds or opens its section; Left folds it and Right opens it. A
15//!   folded section keeps its band in place; open sections fill the
16//!   panel's height, so the bands of folded sections below the last open
17//!   one sit at the panel's bottom, unless the stack is sized by its
18//!   content ([`Sections::fill`]).
19//! - A section's height is set by hand, in points, or sized by the list:
20//!   those never set by hand share what the others leave, and the last
21//!   open section always takes what is left. Each keeps a least height
22//!   (two rows by default, [`Section::min_height`]) and scrolls its own
23//!   body.
24//! - The line above a band, between two open sections, is a boundary (the
25//!   first open section above is the one it resizes, past any folded
26//!   ones). It follows the pointer when dragged, or moves by a row with
27//!   Up and Down while it has the keyboard. Sections give way in turn, the nearest
28//!   first, never in proportion, and it stops once they are all at their
29//!   least ([`plan`]). A double click, or Enter, drops the heights set by
30//!   hand and any empty room.
31//! - In a panel too short, sections sized by the list give way first,
32//!   then those set by hand, from the bottom up; their stored heights
33//!   come back with the room, until the next drag aligns them on what is
34//!   shown. When even the least heights do not fit, the whole stack
35//!   scrolls, with a scrollbar then only (the kit's, seen at rest). Every
36//!   bar of the stack is drawn as `UiPop::scroll_area` draws one: the
37//!   theme's thumb and track, and `scroll-bar.margin-track`.
38//! - [`Sections::grab_titles`] (off by default) makes the titles drag too:
39//!   a press that moves resizes as the line above does, one that does not
40//!   folds, and a double click drops the heights set by hand.
41//! - The keys of `gesture.sections.pull` (Ctrl with a drag by default, Cmd
42//!   on macOS, read from the pointer map) move the sections below as a
43//!   block, heights kept: only the section above changes, and empty room
44//!   opens under the last. The empty room is kept, with the layout, until
45//!   a drag takes it back or a double click drops it.
46//! - [`Sections::keep_titles`] (off by default) leaves a title where it is
47//!   when its section folds or opens ([`plan::keep_title`]).
48//! - A body is scrolled by the stack ([`Stack::section`]), windowed over
49//!   rows of one height, so that only those in view are drawn
50//!   ([`Stack::rows`]), or left to an application's own view
51//!   ([`Stack::bare`]). A wheel pushing past the end of a body's scroll
52//!   stops there: neither the stack nor a parent moves.
53//! - What is folded, the heights set by hand and the empty room are
54//!   remembered with the window's layout (egui's persisted memory, under
55//!   the stack's name, egui_stack's key), and readable as a [`Layout`] an
56//!   application keeps with its own. A layout stored by egui-pop 0.4 and
57//!   earlier, under egui-pop's own key, moves to egui_stack's the first
58//!   time the stack is shown or its layout loaded.
59//!
60//! The kit draws the band (`section-band`, handler `section`), its mark
61//! (`section-disclosure`, the `disclosure-open` and `disclosure-closed`
62//! glyph roles) and its count (`section-count`, based on
63//! `indicator-badge`), as the kit's [`egui_stack::DockPainter`].
64//!
65//! **Named and observable.** A band is a button named by its title and
66//! count ("Live, 3"), expanded or not for assistive technology; a
67//! boundary is a splitter named after the section above it ("Resize
68//! Live", the strings provider's `egui-pop-section-resize`), its value
69//! the height of that section's body. [`laid_out`] gives each section as
70//! drawn on the last pass, with its height and whether that was set by
71//! hand (the debug bridge's `state` collector lists it too), so an agent
72//! reads the stack rather than pixels.
73//!
74//! ```
75//! use egui_pop_core::sections::{Section, Sections};
76//!
77//! let ctx = egui::Context::default();
78//! let mut out = ctx.run_ui(Default::default(), |ui| {
79//!     Sections::new("sessions").show(ui, |stack| {
80//!         stack.section(Section::new("live", "Live").count(2), |ui| {
81//!             ui.label("build");
82//!             ui.label("tests");
83//!         });
84//!         stack.section(Section::new("idle", "Idle").count(0).open(false), |ui| {
85//!             ui.weak("No idle session");
86//!         });
87//!     });
88//! });
89//! out.textures_delta.clear();
90//! let live = &egui_pop_core::sections::laid_out(&ctx, "sessions")[0];
91//! assert!(live.open && live.body.is_some());
92//! ```
93
94use std::collections::BTreeMap;
95
96use egui::{Context, Id, PointerButton, Ui};
97use egui_pop_model::keymap::Pointer;
98use egui_pop_model::pointer::{PointerMap, SCOPE_SECTIONS, gesture};
99use serde::{Deserialize, Serialize};
100
101pub use egui_stack::sections::plan::{self, DragMode};
102pub use egui_stack::sections::{Laid, Remembered, Section, Stack, laid_out, row_height};
103
104use crate::kit::Kit;
105use crate::pointer;
106use crate::state::Slot;
107use crate::strings::{self, SECTION_RESIZE};
108
109/// What a stack remembers, by section key: kept in egui's persisted
110/// memory under the stack's name, and readable and writable whole
111/// ([`Layout::load`], [`Layout::store`]) for an application that keeps
112/// it with its own layout. egui_stack's own
113/// ([`egui_stack::sections::Layout`]) converts to and from it.
114#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
115pub struct Layout {
116    pub sections: BTreeMap<String, Remembered>,
117    /// The empty room kept under the last section, in points.
118    #[serde(default)]
119    pub empty: f32,
120}
121
122impl Layout {
123    /// The layout a stack named `name` remembers, if any.
124    pub fn load(ctx: &Context, name: &str) -> Option<Layout> {
125        move_old_layout(ctx, name);
126        egui_stack::sections::Layout::load(ctx, name).map(Layout::from)
127    }
128
129    /// Makes it the layout of the stack named `name` (shown so from the
130    /// next pass).
131    pub fn store(&self, ctx: &Context, name: &str) {
132        // A layout given whole wins over one an older egui-pop left.
133        ctx.data_mut(|d| d.remove::<Layout>(old_memory_id(name)));
134        egui_stack::sections::Layout::from(self.clone()).store(ctx, name);
135    }
136
137    /// Whether a section is open, if the layout knows it.
138    pub fn is_open(&self, key: &str) -> Option<bool> {
139        self.sections.get(key).map(|s| s.open)
140    }
141
142    /// Opens or folds a section.
143    pub fn set_open(&mut self, key: &str, open: bool) {
144        self.sections
145            .entry(key.to_string())
146            .or_insert(Remembered { open, height: None })
147            .open = open;
148    }
149
150    /// A section's height set by hand, if it has one.
151    pub fn height(&self, key: &str) -> Option<f32> {
152        self.sections.get(key).and_then(|s| s.height)
153    }
154
155    /// Sets a section's height by hand, as a drag would, or gives it back
156    /// to the list. It opens as the stack first shows it when the layout
157    /// does not know it yet.
158    pub fn set_height(&mut self, key: &str, height: Option<f32>) {
159        match self.sections.get_mut(key) {
160            Some(s) => s.height = height,
161            None => {
162                self.sections
163                    .insert(key.to_string(), Remembered { open: true, height });
164            }
165        }
166    }
167
168    /// Drops every height set by hand and the empty room (a boundary's
169    /// double click): the sections share the panel again.
170    pub fn reset_heights(&mut self) {
171        for s in self.sections.values_mut() {
172            s.height = None;
173        }
174        self.empty = 0.0;
175    }
176}
177
178impl From<egui_stack::sections::Layout> for Layout {
179    fn from(layout: egui_stack::sections::Layout) -> Self {
180        Layout {
181            sections: layout.sections,
182            empty: layout.empty,
183        }
184    }
185}
186
187impl From<Layout> for egui_stack::sections::Layout {
188    fn from(layout: Layout) -> Self {
189        egui_stack::sections::Layout {
190            sections: layout.sections,
191            empty: layout.empty,
192        }
193    }
194}
195
196/// Where egui-pop 0.4 and earlier kept a stack's layout, as this crate's
197/// [`Layout`] (egui's persisted memory goes by the value's type too).
198fn old_memory_id(name: &str) -> Id {
199    Id::unique(("egui_pop.sections", name))
200}
201
202/// The stacks whose old layout was looked for, by name: once a run.
203const MOVED: Slot<()> = Slot::new("core.sections.moved");
204
205/// Moves the layout an older egui-pop stored for the stack named `name`
206/// to egui_stack's key, unless egui_stack already has one; looked for
207/// once a run.
208fn move_old_layout(ctx: &Context, name: &str) {
209    let moved = MOVED.keyed(name.to_string());
210    if moved.get(ctx).is_some() {
211        return;
212    }
213    moved.set(ctx, ());
214    let id = old_memory_id(name);
215    let Some(old) = ctx.data_mut(|d| d.get_persisted::<Layout>(id)) else {
216        return;
217    };
218    ctx.data_mut(|d| d.remove::<Layout>(id));
219    if egui_stack::sections::Layout::load(ctx, name).is_none() {
220        egui_stack::sections::Layout::from(old).store(ctx, name);
221    }
222}
223
224/// Each stack's sections as laid out on the last pass, by name: for the
225/// debug bridge, egui_stack's [`laid_out`] read once a pass.
226const LAID: Slot<Vec<Laid>> = Slot::summarised("core.sections.laid", laid_summary);
227
228/// Each section in a few words, for the debug bridge: all of them fit in
229/// a slot's summary, which `Debug` and the rectangles would not.
230#[allow(
231    clippy::ptr_arg,
232    reason = "a slot's summary takes a reference to its value"
233)]
234fn laid_summary(laid: &Vec<Laid>) -> String {
235    let parts: Vec<String> = laid
236        .iter()
237        .map(|s| {
238            let window = s
239                .window
240                .as_ref()
241                .map_or(String::new(), |w| format!(" rows {}..{}", w.start, w.end));
242            let part = match (s.open, s.by_hand) {
243                (false, _) => format!("{} folded", s.key),
244                (true, false) => format!("{} {:.0}{window}", s.key, s.height),
245                (true, true) => format!("{} {:.0} by hand{window}", s.key, s.height),
246            };
247            match s.drag {
248                Some(DragMode::Pull) => format!("{part} pulled"),
249                Some(_) => format!("{part} dragged"),
250                None => part,
251            }
252        })
253        .collect();
254    let mut text = parts.join(", ");
255    let empty: f32 = laid.iter().map(|s| s.empty).sum();
256    if empty > 0.5 {
257        text.push_str(&format!(", {empty:.0} empty"));
258    }
259    text
260}
261
262/// What the user did to a stack this pass.
263#[derive(Clone, Debug, Default, PartialEq)]
264pub struct SectionsResponse {
265    /// A section folded (`false`) or opened (`true`), by key.
266    pub toggled: Option<(String, bool)>,
267    /// A boundary moved, dragged or from the keyboard.
268    pub resized: bool,
269    /// A boundary was double-clicked, or Enter pressed on it: every
270    /// height set by hand dropped.
271    pub reset: bool,
272    /// The layout after the pass.
273    pub layout: Layout,
274}
275
276/// A stack of collapsible sections filling the room it is given (a
277/// panel's height), named for its memory and for agents.
278///
279/// Need (layout): collapsible sections in a panel.
280#[derive(Clone, Debug)]
281pub struct Sections {
282    name: String,
283    capitals: bool,
284    grab_titles: bool,
285    keep_titles: bool,
286    fill: bool,
287}
288
289impl Sections {
290    /// A stack named `name`, unique in the application: its layout is
291    /// remembered under it and [`laid_out`] reads it.
292    pub fn new(name: impl Into<String>) -> Self {
293        Sections {
294            name: name.into(),
295            capitals: true,
296            grab_titles: false,
297            keep_titles: false,
298            fill: true,
299        }
300    }
301
302    /// Whether the stack fills the room it is given (yes by default):
303    /// the last open section takes what the others leave, and the bands
304    /// of folded sections below it sit at the bottom. Off, it is sized by
305    /// its content: an open section sized by the list is never taller
306    /// than what its body lays out, the long ones share what is left, the
307    /// folded bands follow right under the last open section, and the
308    /// room left stays empty under the last band. A section set by hand
309    /// keeps its height, the last open one too: a drag down grows the
310    /// section above past its content, into that room, and a drag up
311    /// shrinks it to its least height; the content only places the
312    /// sections until a drag ([`egui_stack::sections::Sections::fill`]).
313    pub fn fill(mut self, fill: bool) -> Self {
314        self.fill = fill;
315        self
316    }
317
318    /// Whether titles are drawn in capitals (yes by default, as a code
319    /// editor's side bar does); their accessible names keep their case.
320    pub fn capitals(mut self, capitals: bool) -> Self {
321        self.capitals = capitals;
322        self
323    }
324
325    /// Whether a title drags as well as folds (no by default, as the line
326    /// above a band is what classic apps resize by, and a code editor's
327    /// headers reorder when dragged).
328    ///
329    /// A press that moves is a drag, by the same rules as a boundary's, the
330    /// title staying under the pointer; one that does not is a fold. A title
331    /// under a folded section resizes the first open one above, and with
332    /// nothing open above it does not move. A double click drops the heights
333    /// set by hand; as its first click has already folded, the section is
334    /// seen folded until the second. A band keeps its name and its role.
335    pub fn grab_titles(mut self, grab: bool) -> Self {
336        self.grab_titles = grab;
337        self
338    }
339
340    /// Whether a title stays where it is when its section folds or opens
341    /// (no by default, as a code editor's panes divide the room again, and
342    /// the title moves).
343    ///
344    /// Folding, the open sections above keep their shown height, as if set
345    /// by hand; those below move up, and with nothing below the room stays
346    /// empty. Opening, the section takes its room below its title, from the
347    /// sections below, then from the empty room. In a panel with no room for
348    /// it, those above still give way, and the title moves. A double click
349    /// gets the shares back.
350    pub fn keep_titles(mut self, keep: bool) -> Self {
351        self.keep_titles = keep;
352        self
353    }
354
355    /// Lays the sections `add` gives out in the room left in `ui`.
356    pub fn show<'a>(self, ui: &mut Ui, add: impl FnOnce(&mut Stack<'a>)) -> SectionsResponse {
357        let ctx = ui.ctx().clone();
358        move_old_layout(&ctx, &self.name);
359        let kit = Kit::of(&ctx);
360        let map = pointer::map(&ctx);
361        let mut labels = egui_stack::Labels::ENGLISH;
362        labels.resize_section =
363            strings::tr_args(&ctx, &SECTION_RESIZE, &[("section", "{section}")]).into();
364        // The stack's bar is seen as soon as it overflows, quiet, whatever
365        // the theme does for the bars of the bodies, which keep theirs.
366        let bodies = ui.spacing().scroll;
367        let mut stack = egui_stack::sections::Sections::new(self.name.clone())
368            .painter(&*kit)
369            .labels(labels)
370            .capitals(self.capitals)
371            .grab_titles(self.grab_titles)
372            .keep_titles(self.keep_titles)
373            .fill(self.fill)
374            .pull_when(move |modifiers, button| pulls(&map, modifiers, button))
375            .overflow_scroll(kit.scroll.seen_at_rest().style(&bodies))
376            // The bars as `UiPop::scroll_area` draws them: the kit's thumb
377            // and track in a `ScrollBar` scope, inset along the track.
378            .bar_style(bar_style(ui, &kit))
379            .bar_track_inset(kit.scroll.margin_track);
380        if kit.section_band.data.height > 0.0 {
381            stack = stack.band_height(kit.section_band.data.height);
382        }
383        let response = stack.show(ui, add);
384        LAID.keyed(self.name.clone())
385            .set(&ctx, laid_out(&ctx, &self.name));
386        SectionsResponse {
387            toggled: response.toggled,
388            resized: response.resized,
389            reset: response.reset,
390            layout: response.layout.into(),
391        }
392    }
393}
394
395/// One band standing alone, in the look of a section's: the disclosure
396/// mark, the title, the count, for a fold that is not a stack of
397/// sections (a card's "More (n)" row, a group in a form). A click, or
398/// Space or Enter while it has the keyboard, toggles it: the caller
399/// flips `open` when the response is `clicked()`. It is a button named
400/// by its title and count ("More, 3"), expanded or not for assistive
401/// technology. It takes the width available and a band's height.
402///
403/// ```no_run
404/// let ctx = egui::Context::default();
405/// let mut open = false;
406/// let mut out = ctx.run_ui(Default::default(), |ui| {
407///     if egui_pop_core::sections::band(ui, "more", "More", Some(3), open).clicked() {
408///         open = !open;
409///     }
410/// });
411/// ```
412pub fn band(
413    ui: &mut Ui,
414    id_salt: impl std::hash::Hash + std::fmt::Debug,
415    title: &str,
416    count: Option<u64>,
417    open: bool,
418) -> egui::Response {
419    use egui_stack::PartState;
420    let kit = Kit::of(ui.ctx());
421    let height = if kit.section_band.data.height > 0.0 {
422        kit.section_band.data.height
423    } else {
424        row_height(ui)
425    };
426    let id = ui.make_persistent_id(id_salt);
427    let (rect, _) = ui.allocate_exact_size(
428        egui::vec2(ui.available_width().max(height), height),
429        egui::Sense::hover(),
430    );
431    let response = ui.interact(rect, id, egui::Sense::click());
432    let name = match count {
433        Some(n) => format!("{title}, {n}"),
434        None => title.to_owned(),
435    };
436    let enabled = ui.is_enabled();
437    response.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, enabled, &name));
438    ui.ctx()
439        .accesskit_node_builder(id, |node| node.set_expanded(open));
440    if ui.is_rect_visible(rect) {
441        let state = PartState::NONE
442            .with(PartState::HOVERED, response.hovered())
443            .with(PartState::PRESSED, response.is_pointer_button_down_on())
444            .with(PartState::FOCUSED, response.has_focus());
445        kit.paint_section_band(
446            ui.painter(),
447            &crate::kit::dock::Band {
448                rect,
449                id,
450                title,
451                count,
452                open,
453                state,
454            },
455        );
456    }
457    response
458}
459
460/// The style a scroll bar is drawn in: the `Ui`'s, its widget visuals the
461/// kit's `ScrollBar` scope's (`UiPop::scroll_area`).
462fn bar_style(ui: &Ui, kit: &Kit) -> std::sync::Arc<egui::Style> {
463    let mut style = (**ui.style()).clone();
464    kit.scoped
465        .get(crate::kit::Stock::ScrollBar, crate::kit::Tone::Neutral)
466        .apply(
467            &mut style.visuals,
468            ui.is_enabled(),
469            ui.ctx().pixels_per_point(),
470        );
471    std::sync::Arc::new(style)
472}
473
474/// Whether these keys and this button make a drag pull, in the map in force.
475fn pulls(map: &PointerMap, modifiers: egui::Modifiers, button: PointerButton) -> bool {
476    let drag = Pointer::Drag(pointer::button(button));
477    map.command(SCOPE_SECTIONS, &pointer::chord(modifiers, drag)) == Some(&gesture::SECTIONS_PULL)
478}
479
480#[cfg(test)]
481mod tests {
482    use super::*;
483
484    #[test]
485    fn a_layout_with_the_old_shares_reads_as_sized_by_the_list() {
486        let old =
487            r#"{"sections":{"live":{"open":false,"share":2.5},"idle":{"open":true,"share":0.5}}}"#;
488        let layout: Layout = serde_json::from_str(old).unwrap();
489        assert_eq!(layout.is_open("live"), Some(false));
490        assert_eq!(layout.is_open("idle"), Some(true));
491        assert_eq!(layout.height("live"), None);
492        assert_eq!(layout.height("idle"), None);
493    }
494
495    #[test]
496    fn a_layout_keeps_its_heights_through_a_round_trip_and_drops_them_on_reset() {
497        let mut layout = Layout::default();
498        layout.set_open("live", false);
499        layout.set_height("live", Some(120.0));
500        layout.set_height("idle", Some(40.0));
501        let text = serde_json::to_string(&layout).unwrap();
502        let mut back: Layout = serde_json::from_str(&text).unwrap();
503        assert_eq!(back, layout);
504        back.reset_heights();
505        assert_eq!(back.height("live"), None);
506        assert_eq!(back.is_open("live"), Some(false), "the fold stays");
507    }
508
509    fn pass(ctx: &Context, add: impl FnMut(&mut Ui)) {
510        let input = egui::RawInput {
511            screen_rect: Some(egui::Rect::from_min_size(
512                egui::Pos2::ZERO,
513                egui::vec2(300.0, 400.0),
514            )),
515            ..Default::default()
516        };
517        let mut out = ctx.run_ui(input, add);
518        out.textures_delta.clear();
519    }
520
521    /// Three sections, `shut` folded, `log` windowed over 1000 rows.
522    fn three(ui: &mut Ui) {
523        Sections::new("stack").show(ui, |stack| {
524            stack.section(Section::new("live", "Live"), |ui| {
525                ui.label("build");
526            });
527            stack.rows(Section::new("log", "Log"), 1000, |ui, range| {
528                for i in range {
529                    ui.label(format!("Line {i}"));
530                }
531            });
532            stack.section(Section::new("shut", "Shut").open(false), |ui| {
533                ui.label("hidden");
534            });
535        });
536    }
537
538    #[test]
539    fn the_debug_summary_names_every_section_height() {
540        let ctx = Context::default();
541        let mut layout = Layout::default();
542        layout.set_height("live", Some(120.0));
543        layout.set_open("shut", false);
544        layout.store(&ctx, "stack");
545        pass(&ctx, three);
546        let laid = laid_out(&ctx, "stack");
547        let log = laid[1].height;
548        let window = laid[1].window.clone().expect("windowed");
549        assert_eq!(
550            laid_summary(&laid),
551            format!(
552                "live 120 by hand, log {log:.0} rows {}..{}, shut folded",
553                window.start, window.end
554            )
555        );
556        // The empty room under the last section, after a pull.
557        let mut layout = Layout::default();
558        layout.set_height("live", Some(120.0));
559        layout.set_height("log", Some(80.0));
560        layout.set_open("shut", false);
561        layout.empty = 60.0;
562        layout.store(&ctx, "stack");
563        pass(&ctx, three);
564        let text = laid_summary(&laid_out(&ctx, "stack"));
565        assert!(text.ends_with(", 60 empty"), "{text}");
566        // A drag under way names how it resizes.
567        let mut laid = laid_out(&ctx, "stack");
568        let mut pulled = laid.remove(0);
569        pulled.drag = Some(DragMode::Pull);
570        assert_eq!(laid_summary(&vec![pulled]), "live 120 by hand pulled");
571    }
572
573    #[test]
574    fn a_layout_stored_under_the_old_key_moves_to_egui_stack_s_on_first_load() {
575        let ctx = Context::default();
576        let mut old = Layout::default();
577        old.set_height("live", Some(150.0));
578        old.set_open("shut", false);
579        ctx.data_mut(|d| d.insert_persisted(old_memory_id("stack"), old.clone()));
580        assert_eq!(egui_stack::sections::Layout::load(&ctx, "stack"), None);
581
582        pass(&ctx, three);
583        let laid = laid_out(&ctx, "stack");
584        assert_eq!(laid[0].height, 150.0);
585        assert!(laid[0].by_hand);
586        assert!(!laid[2].open);
587        let moved = egui_stack::sections::Layout::load(&ctx, "stack").expect("moved");
588        assert_eq!(moved.height("live"), Some(150.0));
589        assert_eq!(moved.is_open("shut"), Some(false));
590        assert_eq!(
591            ctx.data_mut(|d| d.get_persisted::<Layout>(old_memory_id("stack"))),
592            None,
593            "the old key is dropped"
594        );
595    }
596
597    #[test]
598    fn a_layout_already_under_egui_stack_s_key_wins_over_the_old_one() {
599        let ctx = Context::default();
600        let mut old = Layout::default();
601        old.set_height("live", Some(150.0));
602        ctx.data_mut(|d| d.insert_persisted(old_memory_id("stack"), old));
603        let mut new = egui_stack::sections::Layout::default();
604        new.set_height("live", Some(90.0));
605        new.store(&ctx, "stack");
606
607        assert_eq!(
608            Layout::load(&ctx, "stack").and_then(|l| l.height("live")),
609            Some(90.0)
610        );
611        assert_eq!(
612            ctx.data_mut(|d| d.get_persisted::<Layout>(old_memory_id("stack"))),
613            None
614        );
615    }
616}