Picture Format: a resize alone brings the Picture Styles row to the new width

The ribbon now asks for one more frame when a tab's spare room changes by
more than half a point, so the row is sized for the new width even when no
input follows the resize. The test resizes 1440 to 1920 and back and checks
the harness settles.
This commit is contained in:
JonRC
2026-10-29 23:25:54 -03:00
parent 99bb0f0a62
commit 0da9cac9dc
2 changed files with 27 additions and 1 deletions
+11 -1
View File
@@ -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::<f32>(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
@@ -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");
}