Merge pull request #9296 from dotCooCoo/fix/screen-formats-header-fits

Export for Screens: the Formats row's buttons end at the column's right edge and wrap when the column is narrow
This commit is contained in:
BFlat authored and GitHub committed 2026-11-26 21:58:33 +07:00
commit d0e84f6f20
2 files changed
+91 -4

No files matched your search

+3 -2
View File
@@ -374,9 +374,10 @@ pub(crate) fn rows(ui: &mut Ui, fields: &mut Map<String, Value>, mut menu: Optio
let one = rows.len() == 1;
let first = settings_format(&rows);
let shown = Stack::new().show(ui, |ui, _| {
Row::new().align(RowAlign::SpaceBetween).show(ui, |ui, _| {
// The buttons end at the right edge; a column too narrow for them puts them on more lines.
Row::new().fill_width().align(RowAlign::SpaceBetween).show(ui, |ui, _| {
Text::new(tl!("Formats:")).shade(Shade::Muted).show(ui);
Row::new().show(ui, |ui, _| {
Row::new().wrap(true).show(ui, |ui, _| {
for (id, label) in PLATFORMS {
if Button::new(tl!(label)).selected(preset == id).id_salt(id).show(ui).clicked() {
platform = Some(id);
+88 -2
View File
@@ -837,18 +837,25 @@ fn big_tiff_tags(bytes: &[u8]) -> Vec<(u16, u16, u32, u16)> {
}
/// Frames of the app's own window (`app.ui_ctx`, where its dialogs are) with the accessibility
/// tree, input events and a clock; each frame runs the dialog layer's pump after it.
/// tree, input events and a clock; each frame runs the dialog layer's pump after it. The window is
/// 1280 by 900 unless `sized` gives another size.
#[derive(Default)]
pub(super) struct Window {
time: f64,
size: Option<egui::Vec2>,
}
impl Window {
/// A window of `size` instead of the default 1280 by 900.
fn sized(size: egui::Vec2) -> Self {
Self { size: Some(size), ..Self::default() }
}
fn run(&mut self, app: &mut VectorcraftApp, events: Vec<egui::Event>) -> egui::FullOutput {
let ctx = app.ui_ctx.clone().expect("a test app has a window");
ctx.enable_accesskit();
self.time += 0.1;
let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1280.0, 900.0));
let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, self.size.unwrap_or(egui::vec2(1280.0, 900.0)));
let input = egui::RawInput { events, time: Some(self.time), screen_rect: Some(screen), ..Default::default() };
// The window's frame with the app's frame input, as the hosts run it: the controls' commands reach the app.
let out = crate::testing::part_frame(app, &ctx, input, |app, ui| app.ui(ui));
@@ -1429,3 +1436,82 @@ fn an_artboard_name_stays_with_its_document() {
assert_eq!(names(&app, 1), ["Artboard 1", "Artboard 2"]);
assert!(log.borrow().is_empty(), "renaming must not export");
}
/// In a window of the default size and in one of the app's least size, every control of the dialog stays between its
/// sides, the format rows stay in the right column, and in the default window the Formats heading's buttons end at
/// the column's right edge.
#[test]
fn the_format_rows_fit_the_right_column_at_the_default_and_least_window_sizes() {
let rows = json!([
{"scale": "1x", "suffix": "", "format": "png"},
{"scale": "2x", "suffix": "@2x-long-suffix", "format": "jpg", "quality": 100},
{"scale": "100w", "format": "pdf"},
]);
// The default window, then the least size the desktop app's window takes.
for (size, default) in [(egui::vec2(1280.0, 900.0), true), (egui::vec2(800.0, 500.0), false)] {
let (mut app, _) = app(2, false);
let mut w = Window::sized(size);
w.run(&mut app, vec![]);
open(&mut app);
set(&mut app, "formats", rows.clone());
w.run(&mut app, vec![]);
let out = w.run(&mut app, vec![]);
let nodes = out.platform_output.accesskit_update.map(|u| u.nodes).unwrap_or_default();
let rect = |n: &egui::accesskit::Node| {
n.bounds().map(|b| egui::Rect::from_min_max(egui::pos2(b.x0 as f32, b.y0 as f32), egui::pos2(b.x1 as f32, b.y1 as f32)))
};
let find = |label: &str, role: Role| {
nodes
.iter()
.find(|(_, n)| n.label() == Some(label) && n.role() == role)
.and_then(|(_, n)| rect(n))
.unwrap_or_else(|| panic!("no {role:?} {label:?}"))
};
let Some((dialog_id, dialog)) = nodes.iter().find(|(_, n)| n.role() == Role::Dialog) else { panic!("no dialog at {size:?}") };
let dialog = rect(dialog).expect("the dialog's bounds");
// The Export to: section spans the right column.
let column = find("Export to:", Role::Group);
let by_id: std::collections::HashMap<_, _> = nodes.iter().map(|(id, n)| (*id, n)).collect();
let mut under = vec![*dialog_id];
while let Some(id) = under.pop() {
let Some(n) = by_id.get(&id) else { continue };
under.extend(n.children().iter().copied());
if let Some(r) = rect(n) {
assert!(
r.left() >= dialog.left() - 0.5 && r.right() <= dialog.right() + 0.5,
"{:?} {:?} at {r:?} is outside the dialog at {dialog:?} in a {size:?} window",
n.role(),
n.label()
);
}
}
// Each control with how many of it the three rows show.
let format_rows = [
("Formats:", Role::Label, 1),
("iOS", Role::Button, 1),
("Android", Role::Button, 1),
("Format Presets", Role::Button, 1),
("Format Settings", Role::Button, 1),
("Scale", Role::ComboBox, 3),
("Suffix", Role::TextInput, 3),
("Format", Role::ComboBox, 3),
("Remove", Role::Button, 3),
("+ Add Scale", Role::Button, 1),
];
for (label, role, count) in format_rows {
let shown: Vec<_> = nodes.iter().filter(|(_, n)| n.label() == Some(label) && n.role() == role).collect();
assert_eq!(shown.len(), count, "{role:?} {label:?} in a {size:?} window");
for (_, n) in shown {
let r = rect(n).expect("bounds");
assert!(
r.left() >= column.left() - 0.5 && r.right() <= column.right() + 0.5,
"{label} at {r:?} is outside the column at {column:?} in a {size:?} window"
);
}
}
if default {
let gear = find("Format Settings", Role::Button);
assert!((gear.right() - column.right()).abs() <= 0.5, "the gear at {gear:?} ends at the column's edge {column:?}");
}
}
}