diff --git a/crates/ui-egui/src/ribbon.rs b/crates/ui-egui/src/ribbon.rs index a284eacc..36f47b27 100644 --- a/crates/ui-egui/src/ribbon.rs +++ b/crates/ui-egui/src/ribbon.rs @@ -237,7 +237,17 @@ pub fn show(app: &mut SlideApp, ui: &mut Ui) { }); }); let r = scroll.inner_rect; - ui.ctx().data_mut(|d| d.insert_temp(spare_room_id(&tab), r.width() - scroll.content_size.x)); + // A gallery sized from this reads it on the next frame, so a change (a resize, a tab + // shown for the first time) asks for one; within half a point it is the same layout. + let spare = r.width() - scroll.content_size.x; + let moved = ui.ctx().data_mut(|d| { + let was = d.get_temp::(spare_room_id(&tab)); + d.insert_temp(spare_room_id(&tab), spare); + was.is_none_or(|was| (was - spare).abs() > 0.5) + }); + if moved { + ui.ctx().request_repaint(); + } let overflow = (scroll.content_size.x - r.width()).max(0.0); let offset = scroll.state.clamped_offset().x; // Record the rendered offset for `InputTarget`: the same window point hits a different diff --git a/crates/ui-egui/src/ribbon/picture_styles_tests.rs b/crates/ui-egui/src/ribbon/picture_styles_tests.rs index 75cf6648..82772c5c 100644 --- a/crates/ui-egui/src/ribbon/picture_styles_tests.rs +++ b/crates/ui-egui/src/ribbon/picture_styles_tests.rs @@ -89,3 +89,19 @@ fn more_picture_styles_lists_every_style_and_applies_the_one_clicked() { assert_eq!(doc.history.undo.len(), undo + 1, "one undo step"); assert!(h.query_by_label(last).is_none(), "the menu closes after a pick"); } + +#[test] +fn a_resize_alone_settles_the_styles_row() { + // No pointer event follows the resize, so only the ribbon's own repaint request can bring the + // row to the new width. + let (mut h, _) = picture_format(1440.0); + h.run_ok(); + assert_eq!(inline_styles(&h), 2); + h.set_size(egui::vec2(1920.0, 900.0)); + assert!(h.run_ok().is_some(), "the ribbon keeps asking for frames after a resize"); + assert_eq!(inline_styles(&h), 8, "the row still has the 1440 px count after growing to 1920 px"); + assert!(h.query_by_label("Scroll ribbon right").is_none()); + h.set_size(egui::vec2(1440.0, 900.0)); + h.run_ok(); + assert_eq!(inline_styles(&h), 2, "the row still has the 1920 px count after shrinking to 1440 px"); +}