From b4f7d20598657fc63a98eef80a00101b9d4f8cc2 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Fri, 4 Dec 2026 17:44:33 -0800 Subject: [PATCH] Libraries: a library taller than the panel scrolls The panel's items sat in a stack that filled the panel's room without scrolling, so the wheel, touchpad and scroll bar did nothing and items past the bottom edge could not be reached, in both the list and the thumbnail view. The stack now scrolls vertically under the library picker and search field, and the footer stays in place. --- crates/ui-egui/src/panels/libraries.rs | 9 ++++--- crates/ui-egui/src/panels/libraries/tests.rs | 28 ++++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/crates/ui-egui/src/panels/libraries.rs b/crates/ui-egui/src/panels/libraries.rs index d9e2f9b70d..d69bf844fd 100644 --- a/crates/ui-egui/src/panels/libraries.rs +++ b/crates/ui-egui/src/panels/libraries.rs @@ -20,7 +20,7 @@ use craft::keymap::CommandRef; use craft::theme::variant::Tone; use craft::ui::choice::Segmented; use craft::ui::contract::{ - ActivateOn, Bind, BodyCx, CollectionEvent, DropAt, DropKind, DropPlace, Entry, ListDrag, Props as _, ReorderRule, SelectMode, Show as _, + ActivateOn, Bind, BodyCx, CollectionEvent, DropAt, DropKind, DropPlace, Entry, ListDrag, Props as _, ReorderRule, Scroll, SelectMode, Show as _, ShowCollection as _, ShowContainer as _, Sizing, Trigger, }; use craft::ui::display::{Divider, Shade, Text}; @@ -349,13 +349,14 @@ impl<'a> View<'a> { } } - /// The list: the ungrouped items, then the groups as sections. A drop anywhere on it away from - /// the items and groups takes an item out of its group, or adds art or a swatch ungrouped. + /// The list: the ungrouped items, then the groups as sections, scrolling under the header when + /// they are taller than the panel. A drop anywhere on it away from the items and groups takes an + /// item out of its group, or adds art or a swatch ungrouped. fn show(&self, ui: &mut Ui, closed: &mut HashSet<(String, String)>, acts: &RefCell>) { let membership = Arc::clone(&self.membership); let list = DropAction::new(move |drag: &PanelDrag| membership.landing(drag, None).is_some()) .sizing(Sizing::Fill) - .show(ui, |ui, _| Stack::new().fill().show(ui, |ui, cx| self.contents(ui, cx, closed, acts))); + .show(ui, |ui, _| Stack::new().fill().scroll(Scroll::vertical()).show(ui, |ui, cx| self.contents(ui, cx, closed, acts))); if let Some(drag) = &list.output.dropped && let Some(act) = self.membership.landing(drag, None) { diff --git a/crates/ui-egui/src/panels/libraries/tests.rs b/crates/ui-egui/src/panels/libraries/tests.rs index b9877b53ca..cfc1cd3a68 100644 --- a/crates/ui-egui/src/panels/libraries/tests.rs +++ b/crates/ui-egui/src/panels/libraries/tests.rs @@ -679,6 +679,34 @@ fn a_shrunk_thumbnail_keeps_its_color_beside_clear_pixels() { } } +/// A library longer than the panel scrolls: the wheel over the items brings the last one into view, in the list view +/// and in the thumbnail view, while the footer's New Group stays in view. +#[test] +fn a_long_library_scrolls_with_the_wheel() { + for list in [false, true] { + let mut app = app(); + app.run("library.create", json!({"name": "Brand"})).unwrap(); + for i in 0..400 { + app.run("library.add", json!({"kind": "fillColor", "color": format!("#{:06x}", i * 0x9731), "name": format!("Swatch {i}")})).unwrap(); + } + app.ui.libraries_list_view = list; + let mut panel = Harness::new(app, show); + panel.room(egui::vec2(300.0, 400.0)); + panel.frame(); + panel.frame(); + assert!(panel.in_view("Swatch 0"), "the first item shows (list view {list})"); + assert!(!panel.in_view("Swatch 399"), "the last item starts out of view (list view {list})"); + let at = panel.rect("Swatch 0").center(); + for _ in 0..40 { + panel.scroll_at(at, -400.0); + } + panel.frame(); + assert!(panel.in_view("Swatch 399"), "the wheel scrolls the last item into view (list view {list})"); + assert!(!panel.in_view("Swatch 0"), "the first item scrolls out of view (list view {list})"); + assert!(panel.in_view("New Group"), "the footer stays in view (list view {list})"); + } +} + /// Graphic thumbnails decoded while the panel draws one frame. fn decoded(panel: &mut Harness) -> usize { super::counters::DECODED.with(|c| c.set(0));