From 8068e8f4b85a8cb9c4bb342193911f814d90f0cc Mon Sep 17 00:00:00 2001 From: rugbymauri Date: Wed, 4 Nov 2026 18:21:39 +0000 Subject: [PATCH] Preferences: the theme strip's arrows page by a screenful of themes (#11434) (#11600) * claim: #11434 Signed-off-by: Maurizio Monticelli * Preferences: the theme arrows move by the themes that fit in view The previous and next arrows beside the theme cards in Preferences > Appearance moved the row by one card per click, although their hover text says "Previous themes" and "Next themes". With 26 themes and about six cards in view, reaching the last theme took some twenty clicks. The shared carousel now moves by the number of cards that fit at the current width, so one click shows the next screenful. The last page ends on the last card, the first page starts on the first, and the arrow at an end stays dimmed and inert. The step follows the window width, and the row still opens on the chosen theme. Fixes #11434 Signed-off-by: Maurizio Monticelli --------- Signed-off-by: Maurizio Monticelli --- crates/ui-egui/src/ui_kit/gallery.rs | 2 +- crates/ui-egui/src/ui_kit/layout_tests.rs | 62 ++++++++++++++++++- .../ui-egui/src/ui_kit/preferences_cards.rs | 5 +- docs/ui-kit.md | 2 +- 4 files changed, 65 insertions(+), 6 deletions(-) diff --git a/crates/ui-egui/src/ui_kit/gallery.rs b/crates/ui-egui/src/ui_kit/gallery.rs index 65ce3d0ab..8b309ef70 100644 --- a/crates/ui-egui/src/ui_kit/gallery.rs +++ b/crates/ui-egui/src/ui_kit/gallery.rs @@ -3061,7 +3061,7 @@ fn preset_card_help_icon_and_carousel_behave() { let help = help_icon(ui, "Help text"); assert!(help.rect.width() > 8.0 && help.rect.width() < 20.0); }); - // The next arrow moves the window by one and stays inert at the end. + // The next arrow moves the window by a page and stays inert at the end. let mut first = vec![]; let mut at = None; for pass in 0..6 { diff --git a/crates/ui-egui/src/ui_kit/layout_tests.rs b/crates/ui-egui/src/ui_kit/layout_tests.rs index c2adec68d..86d17fd1c 100644 --- a/crates/ui-egui/src/ui_kit/layout_tests.rs +++ b/crates/ui-egui/src/ui_kit/layout_tests.rs @@ -363,8 +363,66 @@ fn shared_picture_choices_return_clicks_and_respect_both_disabled_states() { } } +/// #11434: an arrow moves by the cards that fit, not by one, and the last page ends on the last card. #[test] -fn theme_carousel_moves_one_card_and_disables_its_ends_without_selecting() { +fn carousel_arrows_move_a_page_of_the_cards_that_fit_at_each_width() { + let count = 11; + for width in [280.0_f32, 480.0, 700.0] { + let ctx = crate::fonts::test_context(); + let shown = || -> Vec { (0..count).filter(|i| scenario::rect_of(&format!("page:item:{i}")).is_some()).collect() }; + let draw = |events: Vec| { + scenario::clear_handles(); + crate::test_support::frame( + &ctx, + egui::RawInput { + screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(width + 40.0, 400.0))), + events, + ..Default::default() + }, + |ui| { + ui.set_width(width); + scope(ui, |ui| { + carousel(ui, ("page_carousel", width as u32), count, 88.0, 96.0, |ui, i| { + let (r, _) = ui.allocate_exact_size(egui::vec2(88.0, 90.0), egui::Sense::hover()); + scenario::publish_rect(&format!("page:item:{i}"), r); + }); + }); + }, + ); + }; + let click = |label: &str| { + let at = scenario::handle_at(&format!("prefs:carousel:{}", crate::i18n::tr(label))).unwrap(); + draw(pointer(at, true)); + draw(pointer(at, false)); + draw(vec![]); + }; + draw(vec![]); + draw(vec![]); + let page = shown().len(); + assert!(page > 1 && page < count, "width {width}: {page} cards fit"); + assert_eq!(shown(), (0..page).collect::>()); + click("prefs.carousel_previous"); + assert_eq!(shown(), (0..page).collect::>(), "width {width}: previous is inert at the start"); + click("prefs.carousel_next"); + let second = page.min(count - page); + assert_eq!(shown(), (second..second + page).collect::>(), "width {width}: next shows the cards that were hidden"); + for _ in 0..count { + click("prefs.carousel_next"); + } + let last: Vec = (count - page..count).collect(); + assert_eq!(shown(), last, "width {width}: the last page ends on the last card"); + click("prefs.carousel_previous"); + let back = (count - page).saturating_sub(page); + assert_eq!(shown(), (back..back + page).collect::>(), "width {width}: previous shows the cards before"); + for _ in 0..count { + click("prefs.carousel_previous"); + } + assert_eq!(shown(), (0..page).collect::>(), "width {width}: previous stops at the first card"); + } +} + +#[test] +fn theme_carousel_moves_and_disables_its_ends_without_selecting() { let ctx = crate::fonts::test_context(); let sample = ThemeSample::from_tokens(&Tokens::light()); let draw = |ui: &mut Ui| { @@ -406,7 +464,7 @@ fn theme_carousel_moves_one_card_and_disables_its_ends_without_selecting() { assert_eq!(scenario::rect_of("test:theme:0").unwrap().left(), start, "previous is inert at the start"); click(&next); assert!(scenario::rect_of("test:theme:0").is_none()); - assert!((scenario::rect_of("test:theme:1").unwrap().left() - start).abs() < 1.0, "move exactly one item"); + assert!((scenario::rect_of("test:theme:1").unwrap().left() - start).abs() < 1.0, "the last page ends on the last card"); assert!(scenario::rect_of("test:theme:2").is_some()); click(&next); assert!((scenario::rect_of("test:theme:1").unwrap().left() - start).abs() < 1.0, "next is inert at the end"); diff --git a/crates/ui-egui/src/ui_kit/preferences_cards.rs b/crates/ui-egui/src/ui_kit/preferences_cards.rs index fffe60cb3..77b5f7ddc 100644 --- a/crates/ui-egui/src/ui_kit/preferences_cards.rs +++ b/crates/ui-egui/src/ui_kit/preferences_cards.rs @@ -404,6 +404,7 @@ pub(super) fn carousel_window(count: usize, offset: usize, available: f32, item_ } /// A row of items with a previous and a next arrow; an arrow is dimmed and inert at its end. +/// An arrow moves by the items that fit (#11434); the last page ends on the last item. /// `item` paints the item at an index into a column `item_width` wide and `item_height` high. pub(crate) fn carousel( ui: &mut Ui, @@ -425,7 +426,7 @@ pub(crate) fn carousel( ui.spacing_mut().item_spacing.x = gap; let can_back = first > 0; if carousel_arrow(ui, vec2(arrow, height), -1.0, can_back, crate::i18n::tr("prefs.carousel_previous")).clicked() { - next_offset = first.saturating_sub(1); + next_offset = first.saturating_sub(visible); } for index in first..first + visible { ui.allocate_ui_with_layout(vec2(dimension(item_width), height), egui::Layout::top_down(egui::Align::Min), |ui| { @@ -435,7 +436,7 @@ pub(crate) fn carousel( } let can_forward = first + visible < count; if carousel_arrow(ui, vec2(arrow, height), 1.0, can_forward, crate::i18n::tr("prefs.carousel_next")).clicked() { - next_offset = (first + 1).min(count.saturating_sub(visible)); + next_offset = (first + visible).min(count.saturating_sub(visible)); } }); ui.data_mut(|d| d.insert_temp(key, next_offset)); diff --git a/docs/ui-kit.md b/docs/ui-kit.md index e3ccb5562..e37b1533a 100644 --- a/docs/ui-kit.md +++ b/docs/ui-kit.md @@ -889,7 +889,7 @@ these shared pieces; the pages themselves arrive in later steps. Sizes follow | `preset_card(ui, name, word, selected, enabled, &icon, width)` | A 70 pt card with a 38 pt icon box (`icon` paints into it in the ink it is given), a name, one word and an accent check. Used for Performance, Quality and Custom. | as above, `pref_well` | | `help_icon(ui, text)` | The (i) after a label. Shows `text` as a tooltip and exposes it as the widget's label. | `form_dim`, `form_ink` | | `shortcut_binding(ui, chord, editable)` | Complete mono keycaps using the command-search painter; one focusable recorder target per binding, or a read-only label. Empty chords show dim Not assigned. `shortcut_binding_width` measures the same font and padding, including literal plus keys. Gallery: `shortcut_binding`. | `font_small/label`, `control_height`, `form_dim`, `form_primary`, `space_4/8/10`, `radius_sm` | -| `carousel(ui, id, count, item_width, item_height, item)` | A row of items between a previous and a next arrow (both labelled from the `prefs.carousel_*` messages). `carousel_window(count, offset, available, item_width, gap, arrow)` says which items show; the arrow at an end is dimmed (0.35) and inert. The first shown index is kept in the Ui's temporary memory under `id`. | `dialog_border`, `control_fill`, `hover`, `form_ink`, `radius_lg` | +| `carousel(ui, id, count, item_width, item_height, item)` | A row of items between a previous and a next arrow (both labelled from the `prefs.carousel_*` messages). `carousel_window(count, offset, available, item_width, gap, arrow)` says which items show; an arrow moves by the number of items that fit, the last page ends on the last item, and the arrow at an end is dimmed (0.35) and inert. The first shown index is kept in the Ui's temporary memory under `id`. | `dialog_border`, `control_fill`, `hover`, `form_ink`, `radius_lg` | `card_look(selected, enabled, hovered, focused)` holds the state rules (border width, fill, ink, weight, dimming, focus ring) apart from the painting so they can be tested.