From 70440643aa5ef6730c657956dd3fc58fff87f581 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sat, 28 Nov 2026 10:11:44 +0000 Subject: [PATCH] thumbs: production's pane look; a requested section menu hangs from its header Section headers read "Name (count)" behind the framework's disclosure, and fold the section as the Slide Sorter does, with the sorter's fold state. Every slide is framed and the selection ring is rounded (PictureEdge:: Framed); the animation mark is the small filled star. A section menu the control protocol asks for hangs from the header the grid now reports. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/control.rs | 2 +- crates/ui-egui/src/panels/thumbs.rs | 79 +++++++++++++++++++++++++++-- 2 files changed, 75 insertions(+), 6 deletions(-) diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rs index 3c673cc62..f1ef39c26 100644 --- a/crates/ui-egui/src/control.rs +++ b/crates/ui-egui/src/control.rs @@ -1053,7 +1053,7 @@ mod tests { |platform| platform.control = Some(ControlChannel::new(receiver)), ); harness.run_steps(3); - let mut input = |harness: &mut egui_kittest::Harness<'static, SlideApp>, params: Value| -> Result> { + let input = |harness: &mut egui_kittest::Harness<'static, SlideApp>, params: Value| -> Result> { let (request, reply) = ControlRequest::new("ui.key", params); sender.send(request).map_err(|_| "control channel closed")?; for _ in 0..30 { diff --git a/crates/ui-egui/src/panels/thumbs.rs b/crates/ui-egui/src/panels/thumbs.rs index 7f28980ea..e5712dd35 100644 --- a/crates/ui-egui/src/panels/thumbs.rs +++ b/crates/ui-egui/src/panels/thumbs.rs @@ -12,7 +12,7 @@ use craft::ui::list::{List, ListRow, ThumbAspect, ThumbSize}; use craft::ui::menu::{Menu, MenuItem}; use craft::ui::runtime::commands::{CommandRef, CommandState, Commands as _, EditCommands}; use craft::ui::runtime::env::Env; -use craft::ui::tile_grid::{CaptionPlace, ColumnRule, GridEvent, TailRow, Tile, TileGrid, TileGroup, TileMark}; +use craft::ui::tile_grid::{CaptionPlace, ColumnRule, GridEvent, PictureEdge, TailRow, Tile, TileGrid, TileGroup, TileMark}; use deckcraft_engine::Target; use egui::{Response, Ui}; use serde_json::json; @@ -42,6 +42,7 @@ craft::ui::words! { hide_slide: plain = "Hide Slide"; master: template "panels.slideMaster" = "{name} Slide Master"; slide: template "panels.slideNumber" = "Slide {number}"; + section: template "panels.sectionCount" = "{name} ({count})"; } } @@ -68,13 +69,18 @@ pub(crate) fn body(app: &mut SlideApp, ui: &mut Ui, cx: &mut BodyCx<'_>) { } } let sections: Vec<_> = starts.into_iter().collect(); + // A section folds here as it does in the Slide Sorter: one fold state, kept by its first slide. + let fold = |si: usize| doc.sections[si].slides.first().map(|id| (uid, id.0)); let groups: Vec<_> = sections .iter() .enumerate() .map(|(gi, &(at, si))| { let end = sections.get(gi + 1).map_or(doc.slides.len(), |(at, _)| *at); let section = &doc.sections[si]; - TileGroup::new(SECTION_KEYS + si as u64, at, end - at, section.name.clone()).detail(cx.format().integer(section.slides.len() as u64)) + let count = cx.format().integer(section.slides.len() as u64); + let title = words.section.fill(&[("name", section.name.as_str()), ("count", count.as_str())]); + let open = fold(si).is_none_or(|key| !app.sorter.collapsed.contains(&key)); + TileGroup::new(SECTION_KEYS + si as u64, at, end - at, title).open(open) }) .collect(); let tail = [TailRow::new(NEW_SLIDE, words.new_slide.clone())]; @@ -87,7 +93,9 @@ pub(crate) fn body(app: &mut SlideApp, ui: &mut Ui, cx: &mut BodyCx<'_>) { .column_rule(ColumnRule::FillRow) .caption(CaptionPlace::Start) .aspect((doc.slide_size.width / doc.slide_size.height) as f32) + .picture_edge(PictureEdge::Framed) .groups(&groups) + .collapsible() .tail(&tail) .selection(Bind::given(selection.clone())) .reorder(ReorderRule::new()); @@ -105,7 +113,7 @@ pub(crate) fn body(app: &mut SlideApp, ui: &mut Ui, cx: &mut BodyCx<'_>) { tile = tile.hidden(); } if !slide.animations.is_empty() || slide.transition.as_ref().is_some_and(|transition| transition.kind != "none") { - tile = tile.mark(TileMark::new(IconId::new("star"), words.has_animation.clone())); + tile = tile.mark(TileMark::new(IconId::new("star_filled"), words.has_animation.clone())); } tile }); @@ -134,7 +142,7 @@ pub(crate) fn body(app: &mut SlideApp, ui: &mut Ui, cx: &mut BodyCx<'_>) { // a click with no drag changes nothing. if let Some(movement) = edit.value() { // The outline includes headers; slide.move counts only the slides left after removing every moved key. - let grid = TileGrid::new(words.slides.clone()).groups(&groups).tail(&tail); + let grid = TileGrid::new(words.slides.clone()).groups(&groups).collapsible().tail(&tail); if let Some(movement) = grid.tile_reorder(&source, movement) { let _ = app.run("slide.move", json!({"ids": movement.keys, "to": movement.to})); } @@ -159,15 +167,27 @@ pub(crate) fn body(app: &mut SlideApp, ui: &mut Ui, cx: &mut BodyCx<'_>) { app.pane_menu = Some(("thumbs-section".into(), *si as u64)); } } + GridEvent::GroupOpen { group, open } => { + if let Some(key) = sections.get(group).and_then(|(_, si)| fold(*si)) { + if open { + app.sorter.collapsed.remove(&key); + } else { + app.sorter.collapsed.insert(key); + } + } + } _ => {} } } // Requests use the control protocol's parts (`ui.contextMenu`): a slide by its index, a section by its index. A // requested menu hangs from its row, as the context-menu key's does; a right click's hangs at the pointer. let row = |key: u64| out.response.shown.iter().find(|row| row.key == key).map(|row| Anchor::Rect(row.rect)); + let header = |si: usize| { + out.headers.iter().find(|(group, _)| sections.get(*group).is_some_and(|(_, held)| *held == si)).map(|(_, rect)| Anchor::Rect(*rect)) + }; let request = app.pane_menu.clone(); if let Some((_, key)) = request.as_ref().filter(|(kind, _)| kind == "thumbs-section") { - section_menu(ui, app, *key as usize, &out.response.response, row(SECTION_KEYS + key)); + section_menu(ui, app, *key as usize, &out.response.response, header(*key as usize)); } else if let Some(key) = request .as_ref() .filter(|(kind, _)| kind == "thumbs") @@ -409,6 +429,38 @@ mod tests { Ok(()) } + /// A section's disclosure folds its slides out of the pane and back, and the Slide Sorter keeps the same fold. + #[test] + fn a_section_folds_here_and_in_the_sorter() -> Result<(), String> { + let mut session = slides(4)?; + for (at, name) in [(0, "Opening"), (2, "Closing")] { + session.execute("section.add", &json!({"at": at, "name": name})).map_err(|error| error.to_string())?; + } + let mut h = editor(session, 1600.0); + let header = h + .query_all_by_role(Role::Heading) + .find(|node| node.accesskit_node().label().is_some_and(|label| label.starts_with("Closing"))) + .ok_or("the second section's header")? + .rect(); + let toggle = |h: &mut Harness<'static, Framed>| { + let at = Pos2::new(header.left() + header.height() / 2.0, header.center().y); + h.hover_at(at); + h.run_steps(1); + for pressed in [true, false] { + h.event(Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: Modifiers::NONE }); + h.run_steps(1); + } + h.run_steps(3); + }; + let shown = |h: &Harness<'static, Framed>, number: usize| h.query_by_role_and_label(Role::ListItem, &number.to_string()).is_some(); + toggle(&mut h); + assert!(shown(&h, 2) && !shown(&h, 3) && !shown(&h, 4), "folding hides only that section's slides"); + assert!(!h.state().sorter.collapsed.is_empty(), "the sorter keeps the fold"); + toggle(&mut h); + assert!(shown(&h, 3) && shown(&h, 4), "unfolding shows them again"); + Ok(()) + } + /// A slide menu the control protocol asks for hangs from that slide's tile, as the context-menu key's does, not /// from the whole pane. #[test] @@ -422,6 +474,23 @@ mod tests { Ok(()) } + /// A section menu the control protocol asks for hangs from that section's header, not from the whole pane. + #[test] + fn a_requested_section_menu_hangs_from_its_header() -> Result<(), String> { + let mut session = slides(4)?; + for (at, name) in [(0, "Opening"), (2, "Closing")] { + session.execute("section.add", &json!({"at": at, "name": name})).map_err(|error| error.to_string())?; + } + let mut h = editor(session, 900.0); + let at = deck(&h)?.doc.sections.iter().position(|section| section.name == "Closing").ok_or("the second section")?; + h.state_mut().pane_menu = Some(("thumbs-section".into(), at as u64)); + h.run_steps(4); + let menu = h.get_by_role_and_label(Role::Menu, ThumbWords::english().section_menu.as_str()).rect(); + let (above, below) = (tile(&h, 2), tile(&h, 3)); + assert!(menu.top() >= above.bottom() && menu.top() < below.bottom(), "the menu {menu:?} opens at the header between {above:?} and {below:?}"); + Ok(()) + } + /// A header counts in the grid's destination, but never in the engine's slide order. #[test] fn slides_move_dest_counts_without_the_moved_slides() -> Result<(), String> {