From f923daba0f95bb0d0efe05ed1ed74d464bf17f9a Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sat, 28 Nov 2026 06:03:29 +0000 Subject: [PATCH] ui: collections in scrolling menu and dialog bodies take their natural height The framework asserts that a collection inside a body scrolling along its rows takes its natural height or caps its rows (16.3); four did neither and stopped the pass when their menu or dialog opened: - Home > New Slide / Layout: the "Slide layouts" gallery; - Shape Format > Shape Styles: the "Quick Styles" gallery; - Design > Background Styles: the "Background Styles" gallery; - Insert > Symbol: the dialog's IconPicker. Production drew each as a plain grid with no scroll area of its own, letting the menu or dialog hold all of it, so each takes the natural height. IconPicker offers neither natural height nor a row cap, so the Symbol palette is now a grouped TileGrid with the natural height. collection_scroll_tests opens every ribbon menu (standard and contextual tabs), every dialog, every task pane and every File page and draws each, so a collection put back into a scrolling body fails a test. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/collection_scroll_tests.rs | 143 ++++++++++++++++++ crates/ui-egui/src/dialogs.rs | 2 +- crates/ui-egui/src/dialogs/symbol.rs | 77 ++++++---- crates/ui-egui/src/lib.rs | 2 + crates/ui-egui/src/ribbon/design.rs | 3 +- crates/ui-egui/src/ribbon/galleries.rs | 2 + 6 files changed, 196 insertions(+), 33 deletions(-) create mode 100644 crates/ui-egui/src/collection_scroll_tests.rs diff --git a/crates/ui-egui/src/collection_scroll_tests.rs b/crates/ui-egui/src/collection_scroll_tests.rs new file mode 100644 index 000000000..55edf3030 --- /dev/null +++ b/crates/ui-egui/src/collection_scroll_tests.rs @@ -0,0 +1,143 @@ +//! A collection owns its scroll (16.3): one shown in a body that scrolls along its rows must take its natural height +//! or cap its rows, else the framework's debug assertion stops the pass. This opens every ribbon menu, every dialog, +//! every task pane and every File page over a deck whose selection brings up the contextual tabs, and draws each, so a +//! collection put back into a scrolling body fails here. + +use deckcraft_engine::Session; +use deckcraft_model::ShapeId; +use egui::accesskit::Role; +use egui_kittest::Harness; +use egui_kittest::kittest::{NodeT, Queryable}; +use serde_json::{Value, json}; + +use crate::{Services, SlideApp}; + +/// The sample deck with a shape, a picture, a table and a diagram added, each alone on a new slide, in that order; +/// returns their ids. +fn harness() -> (Harness<'static, SlideApp>, Vec) { + let mut s = Session::new(); + deckcraft_engine::sample::open_sample(&mut s).unwrap(); + let png = deckcraft_render::Image { width: 2, height: 2, pixels: [255, 0, 0, 255].repeat(4) }.to_png(); + let mut slides = Vec::new(); + for (cmd, params) in [ + ("shape.insert", json!({"preset": "rect", "rect": [100.0, 100.0, 200.0, 120.0]})), + ("insert.picture", json!({"data": deckcraft_engine::cmd::base64_encode(&png), "name": "a.png", "rect": [100, 100, 400, 200]})), + ("insert.table", json!({"rows": 2, "cols": 2, "rect": [80, 80, 600, 160]})), + ("insert.smartArt", json!({"kind": "process", "items": ["Plan", "Build", "Ship"]})), + ] { + s.execute("slide.new", &json!({"layout": "blank"})).unwrap(); + s.execute(cmd, ¶ms).unwrap(); + slides.push(s.active().unwrap().doc.slides[s.active().unwrap().selection.slide].shapes[0].id); + } + let builder = Harness::builder().with_size(egui::vec2(1800.0, 1000.0)).with_step_dt(1.0 / 60.0); + let mut h = crate::test_harness::harness_with(s, Services::default(), builder, |_| {}); + // The trial is about layout; a build without the craft-fonts input lacks some symbols' faces, and font coverage + // has its own tests. + h.ctx.set_missing_glyph_policy(egui::MissingGlyphPolicy::Tofu); + h.run_steps(3); + (h, slides) +} + +/// Goes to the slide holding `id` and selects it; the ribbon's main actions may have added slides since. +fn select(h: &mut Harness<'_, SlideApp>, id: ShapeId) { + let session = &mut h.state_mut().session; + let slide = session.active().unwrap().doc.slides.iter().position(|slide| slide.shapes.iter().any(|shape| shape.id == id)).unwrap(); + session.execute("slide.go", &json!({"index": slide})).unwrap(); + session.execute("selection.select", &json!({"ids": [id.0]})).unwrap(); + h.run_steps(2); +} + +fn dialog(h: &mut Harness<'_, SlideApp>, method: &str, params: Value) -> Result { + let ctx = h.ctx.clone(); + crate::dialogs::control(h.state_mut(), &ctx, method, ¶ms).unwrap_or_else(|| Err(format!("{method} is not a dialog method"))) +} + +fn close_dialogs(h: &mut Harness<'_, SlideApp>) { + while crate::dialogs::top_dialog(&h.ctx).is_some() { + dialog(h, "ui.dialog.close", json!({})).unwrap(); + h.run_steps(2); + } +} + +/// Names, in a failure, the surface that was being drawn when the pass panicked. +struct Opening(String); + +impl Drop for Opening { + fn drop(&mut self) { + if std::thread::panicking() { + eprintln!("the panic came while showing {}", self.0); + } + } +} + +/// Opens each enabled menu button of the shown ribbon tab and draws its menu, closing it again. +fn open_tab_menus(h: &mut Harness<'_, SlideApp>, tab: &str) -> usize { + let shown = Opening(format!("the {tab} tab")); + h.state_mut().ui.tab = tab.into(); + h.run_steps(3); + drop(shown); + let buttons: Vec = h + .query_all_by_role(Role::Button) + .filter(|node| { + let node = node.accesskit_node(); + node.has_popup().is_some() && !node.is_disabled() + }) + .filter_map(|node| node.accesskit_node().label()) + .collect(); + for label in &buttons { + // A label shared by two buttons opens the first; the menus of both come from the same code. + let Some(button) = h.query_all_by_role_and_label(Role::Button, label).next() else { continue }; + let _opening = Opening(format!("{tab} ▸ {label}")); + button.click(); + h.run_steps(3); + h.key_press(egui::Key::Escape); + h.run_steps(2); + close_dialogs(h); + h.state_mut().ui.tab = tab.into(); + h.run_steps(1); + } + buttons.len() +} + +#[test] +fn no_collection_shares_a_scrolling_body() { + let (mut h, shapes) = harness(); + let mut menus = 0; + for tab in ["Home", "Insert", "Draw", "Design", "Transitions", "Animations", "Slide Show", "Record", "Review", "View"] { + menus += open_tab_menus(&mut h, tab); + } + for (shape, tabs) in shapes.iter().zip([&["Shape Format"][..], &["Picture Format"], &["Table Design", "Layout"], &["SmartArt Design"]]) { + select(&mut h, *shape); + for tab in tabs { + menus += open_tab_menus(&mut h, tab); + } + } + assert!(menus > 0, "the ribbon exposes menu buttons"); + + select(&mut h, shapes[0]); + for (id, _) in crate::dialogs::FORMS { + let _opening = Opening(format!("the {id} dialog")); + dialog(&mut h, "ui.dialog.open", json!({"id": id})).unwrap_or_else(|error| panic!("{id}: {error}")); + h.run_steps(3); + close_dialogs(&mut h); + } + for id in ["paragraph", "tabs", "hyperlink", "customShow", "spelling", "accessibility", "find", "about", "preferences", "autocorrect"] { + let _opening = Opening(format!("the {id} dialog")); + dialog(&mut h, "ui.dialog.open", json!({"id": id})).unwrap_or_else(|error| panic!("{id}: {error}")); + h.run_steps(3); + close_dialogs(&mut h); + } + + for pane in ["format", "background", "animation", "selection", "comments", "designer", "smartart", "thesaurus", "revisions"] { + let _opening = Opening(format!("the {pane} pane")); + h.state_mut().run("view.pane", json!({"pane": pane})).unwrap(); + h.run_steps(3); + } + h.state_mut().run("view.pane", json!({"pane": null})).unwrap(); + + for page in crate::backstage::Page::ALL { + let _opening = Opening(format!("the File ▸ {} page", page.id())); + h.state_mut().open_backstage(page); + h.run_steps(3); + } +} diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index 7c14ac59b..9cecd790b 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -135,7 +135,7 @@ impl FormSpec { } } -const FORMS: &[(&str, FormSpec)] = &[ +pub(crate) const FORMS: &[(&str, FormSpec)] = &[ ("table", FormSpec::new(insert_forms::table::open, insert_forms::table::finish, false)), ("comment", FormSpec::new(insert_forms::comment::open, insert_forms::comment::finish, false)), ("outline", FormSpec::new(insert_forms::outline::open, insert_forms::outline::finish, false)), diff --git a/crates/ui-egui/src/dialogs/symbol.rs b/crates/ui-egui/src/dialogs/symbol.rs index ac5e77aee..2e123774f 100644 --- a/crates/ui-egui/src/dialogs/symbol.rs +++ b/crates/ui-egui/src/dialogs/symbol.rs @@ -1,49 +1,33 @@ -use craft::ui::contract::Bind; +use craft::behavior::keyed; +use craft::ui::contract::{ActivateOn, Bind, CollectionEvent, SelectMode, ShowCollection as _}; use craft::ui::dialog::DialogHost; use craft::ui::patterns::form_dialogs::{DialogFields, HostedParamDialog, Param, ParamDialog, ParamLayout, ParamResult}; -use craft::ui::pickers::{IconPicker, IconPickerGroup, IconPickerGroups, IconPickerItem, IconPickerSearch}; +use craft::ui::tile_grid::{CaptionPlace, Tile, TileGrid, TileGroup}; use egui::Context; use serde_json::{Value, json}; use crate::SlideApp; +const GROUPS: [(&str, &str); 6] = [ + ("Punctuation", "–—‘’“”…•·§¶†‡‰′″‹›«»¡¿"), + ("Currency", "$€£¥¢₹₩₽₺₿"), + ("Math", "±×÷≠≈≤≥∞√∑∏∫∂∆∇∈∉∩∪⊂⊃∀∃¬∧∨⇒⇔°′"), + ("Greek", "αβγδεζηθικλμνξοπρστυφχψωΓΔΘΛΞΠΣΦΨΩ"), + ("Arrows", "←↑→↓↔↕⇐⇑⇒⇓↖↗↘↙⟵⟶"), + ("Shapes", "■□▪▫▲△▶▷▼▽◀◁◆◇○●◎★☆✓✔✗✘♠♣♥♦"), +]; + /// Opens a modeless symbol palette that inserts at the text caret. pub(crate) fn open(_app: &SlideApp, ctx: &Context, _params: &Value) -> HostedParamDialog { - let groups: Vec<_> = [ - ("Punctuation", "–—‘’“”…•·§¶†‡‰′″‹›«»¡¿"), - ("Currency", "$€£¥¢₹₩₽₺₿"), - ("Math", "±×÷≠≈≤≥∞√∑∏∫∂∆∇∈∉∩∪⊂⊃∀∃¬∧∨⇒⇔°′"), - ("Greek", "αβγδεζηθικλμνξοπρστυφχψωΓΔΘΛΞΠΣΦΨΩ"), - ("Arrows", "←↑→↓↔↕⇐⇑⇒⇓↖↗↘↙⟵⟶"), - ("Shapes", "■□▪▫▲△▶▷▼▽◀◁◆◇○●◎★☆✓✔✗✘♠♣♥♦"), - ] - .into_iter() - .map(|(name, characters)| { - IconPickerGroup::new( - name, - characters - .chars() - .map(|character| { - let glyph = character.to_string(); - IconPickerItem::new(glyph.clone(), glyph.clone()).glyph(glyph) - }) - .collect(), - ) - }) - .collect(); HostedParamDialog::new(ctx, "symbol", DialogFields::new(), move |fields| { - let groups = groups.clone(); let params = vec![ Param::read_only_text("instructions", "", "Click a symbol to insert it at the insertion point.").full_width(), Param::custom("symbol", "Symbols", move |ui, _, cx| { - let out = IconPicker::new("Symbols", Bind::given(None::), &groups) - .group_display(IconPickerGroups::Headings) - .search(IconPickerSearch::None) - .show(ui); - if let Some(symbol) = out.picked { + let (response, picked) = palette(ui); + if let Some(symbol) = picked { cx.request_action(symbol); } - out.response + response }) .full_width(), ]; @@ -56,6 +40,37 @@ pub(crate) fn open(_app: &SlideApp, ctx: &Context, _params: &Value) -> HostedPar .modeless() } +/// Shows every group's symbols under its heading, at the grid's full height: the dialog's body scrolls them, as the +/// palette is a document row of that body. Returns the grid's response and the symbol clicked this pass. +fn palette(ui: &mut egui::Ui) -> (egui::Response, Option) { + let mut symbols = Vec::new(); + let mut named = Vec::new(); + for (name, characters) in GROUPS { + let start = symbols.len(); + symbols.extend(characters.chars().map(String::from)); + named.push((start, symbols.len() - start, name)); + } + // The heading rows are keyed after the cells, whose keys are their positions. + let groups: Vec> = + named.iter().enumerate().map(|(at, (start, count, name))| TileGroup::new(symbols.len() + at, *start, *count, *name)).collect(); + let cells: Vec = (0..symbols.len()).collect(); + let source = keyed(&cells, |at| *at).with_text(|at| symbols[*at].clone().into()); + let out = TileGrid::::new("Symbols") + .natural_height(true) + .select(SelectMode::Single) + .activate(ActivateOn::Click) + .caption(CaptionPlace::None) + .content_cells() + .slow_click_rename(false) + .groups(&groups) + .show_items(ui, &source, &mut |at, _| Tile::new(symbols[*at].clone()).glyph(symbols[*at].clone())); + let picked = out.response.events.iter().find_map(|event| match event { + CollectionEvent::Activate(at) => symbols.get(*at).cloned(), + _ => None, + }); + (out.response.response, picked) +} + /// Completes the palette's Close action without editing text. pub(crate) fn finish(_app: &mut SlideApp, _result: &ParamResult, _host: &mut DialogHost) -> Result<(), String> { Ok(()) diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 269665214..7483adeab 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -243,6 +243,8 @@ mod animpane_tests; #[cfg(test)] mod browsetheme_tests; #[cfg(test)] +mod collection_scroll_tests; +#[cfg(test)] mod compare_tests; #[cfg(test)] #[path = "datetime_tests.rs"] diff --git a/crates/ui-egui/src/ribbon/design.rs b/crates/ui-egui/src/ribbon/design.rs index 0486aa02b..c0bd2ad9b 100644 --- a/crates/ui-egui/src/ribbon/design.rs +++ b/crates/ui-egui/src/ribbon/design.rs @@ -132,7 +132,8 @@ pub(crate) fn design(app: &mut SlideApp, row: &mut RibbonRow<'_>) { deckcraft_color::SchemeSlot::Dk2, deckcraft_color::SchemeSlot::Dk1, ]; - if let Some(index) = grid_pick(ui, TileGrid::new("Background Styles").card_columns(4).caption(CaptionPlace::None), 12, None, |i| { + let grid = TileGrid::new("Background Styles").natural_height(true).card_columns(4).caption(CaptionPlace::None); + if let Some(index) = grid_pick(ui, grid, 12, None, |i| { let base = theme::to_color32(scheme.get(slots[i % 4])); let shade = match i / 4 { 0 => base, diff --git a/crates/ui-egui/src/ribbon/galleries.rs b/crates/ui-egui/src/ribbon/galleries.rs index f3b9d89a5..f594f0fff 100644 --- a/crates/ui-egui/src/ribbon/galleries.rs +++ b/crates/ui-egui/src/ribbon/galleries.rs @@ -412,6 +412,7 @@ pub(super) fn quick_styles(app: &mut SlideApp, ui: &mut Ui, cx: &mut BodyCx<'_>) let indices: Vec = (0..6 * slots.len()).collect(); let source = craft::behavior::keyed(&indices, |index| *index); let out = TileGrid::new("Quick Styles") + .natural_height(true) .card_columns(slots.len()) .aspect(QUICK_STYLE_ASPECT) .caption(CaptionPlace::None) @@ -469,6 +470,7 @@ pub(crate) fn layout_gallery(app: &mut SlideApp, ui: &mut Ui, cx: &mut BodyCx<'_ let source = craft::behavior::keyed(layouts, |layout| layout.id).with_text(|layout| layout.name.as_str().into()); let out = TileGrid::new("Slide layouts") .id_salt(cmd) + .natural_height(true) .card_columns(4) .aspect(LAYOUT_TILE_ASPECT) .caption(CaptionPlace::Below)