From 1733a3d6b37e001044d7dba3ea8254db402f3b06 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 28 Nov 2026 14:40:44 -0800 Subject: [PATCH 1/2] New Document: details stay in rows in small windows A narrow Preset Details column (an 800 by 600 or 900 by 700 window) now shows Height and Artboards side by side with Orientation under them, so Orientation's two buttons stay side by side instead of stacking, and the Bleed fields in two rows, Top and Bottom above Left and Right, with the link button after Right. A column at least 11 control heights wide keeps the one-row layout. --- crates/ui-egui/src/dialogs/new_document.rs | 126 ++++++++++++++++----- 1 file changed, 95 insertions(+), 31 deletions(-) diff --git a/crates/ui-egui/src/dialogs/new_document.rs b/crates/ui-egui/src/dialogs/new_document.rs index f3d056a219..f2007ed5d2 100644 --- a/crates/ui-egui/src/dialogs/new_document.rs +++ b/crates/ui-egui/src/dialogs/new_document.rs @@ -26,6 +26,7 @@ use craft::ui::choice::{Checkbox, Segmented}; use craft::ui::contract::{Bind, Entry, FieldLayout, Gap, Props as _, Show as _, ShowContainer as _, SideLabel, Sizing, clicked}; use craft::ui::display::{Shade, Text}; use craft::ui::form::Field; +use craft::ui::layout::CellAlign; use craft::ui::layout_components::{Grid, Row, Stack}; use craft::ui::patterns::form_dialogs::{ CardCx, CardSource, DetailsCx, DocumentCard, DocumentSettings, HostedNewDocument, NewDocumentDialog, Orientation, PresetCategory, @@ -299,10 +300,8 @@ impl DocumentSettings for VcNewDocument { } }); }); - // Three shares: the grid stacks the three fields when the column has no room for them side by side, so - // Artboards is never cut off at its right edge. - Grid::new(&THIRDS).fill().show(ui, |ui, _| { - Field::new(height.clone()).layout(FieldLayout::Above).id_salt("height").show(ui, |ui, _| size_field(ui, &height, &mut s.height, lengths)); + let compact = compact_details(ui); + let mut orientation_field = |ui: &mut egui::Ui| { Field::new(orientation.clone()).layout(FieldLayout::Above).id_salt("orientation").show(ui, |ui, _| { let entries = [ Entry::new(Orientation::Portrait, portrait.clone()).icon(IconId::new("orientation_portrait")), @@ -310,6 +309,15 @@ impl DocumentSettings for VcNewDocument { ]; picked = Segmented::new(orientation.clone(), Bind::given(current), &entries).show(ui).events.committed().cloned(); }); + }; + // A wide column holds Height, Orientation and Artboards in one row. A narrow one holds Height and Artboards in + // two equal shares and Orientation under them, so its two buttons stay side by side. + let columns: &'static [ColumnWidth] = if compact { &HALVES } else { &THIRDS }; + Grid::new(columns).fill().cells(CellAlign::Top).show(ui, |ui, _| { + Field::new(height.clone()).layout(FieldLayout::Above).id_salt("height").show(ui, |ui, _| size_field(ui, &height, &mut s.height, lengths)); + if !compact { + orientation_field(ui); + } Field::new(artboards.clone()).layout(FieldLayout::Above).id_salt("artboards").show(ui, |ui, _| { let field = NumberField::new(artboards.clone(), Bind::given(Some(f64::from(s.artboards)))) .range(1.0..=f64::from(MAX_ARTBOARDS)) @@ -321,6 +329,9 @@ impl DocumentSettings for VcNewDocument { } }); }); + if compact { + orientation_field(ui); + } if let Some(o) = picked && o != current { @@ -329,7 +340,7 @@ impl DocumentSettings for VcNewDocument { } let bleed = text(tl!("Bleed")); - Field::new(bleed.clone()).layout(FieldLayout::Above).id_salt("bleed").show(ui, |ui, _| bleed_row(ui, s, &mut memory, lengths)); + Field::new(bleed.clone()).layout(FieldLayout::Above).id_salt("bleed").show(ui, |ui, _| bleed_row(ui, s, &mut memory, lengths, compact)); Field::new(background.clone()).layout(FieldLayout::Above).id_salt("background").show(ui, |ui, _| { let entries: Vec> = BACKGROUNDS.iter().map(|(b, name)| Entry::new(*b, text(tl!(name)))).collect(); @@ -419,36 +430,55 @@ fn pixels_per_inch() -> f64 { 72.0 / Unit::Pixels.to_pt(1.0) } -/// The four Bleed fields in one row, each under its side's name, and the link button at the end; linked, an edit to -/// one side sets all four, and turning the link on sets all four to Top's. Each field is as wide as the widest bleed it -/// takes, and the row wraps when the column has no room for all of them. -fn bleed_row(ui: &mut egui::Ui, s: &mut DocSettings, memory: &mut Memory, lengths: LengthUnits) { +/// The four Bleed fields, each under its side's name, and the link button at the end; linked, an edit to one side sets +/// all four, and turning the link on sets all four to Top's. Each field is as wide as the widest bleed it takes. A wide +/// column holds them in one row. A narrow (`compact`) column holds them in two rows, Top and Bottom above Left and +/// Right, with the link button after Right. +fn bleed_row(ui: &mut egui::Ui, s: &mut DocSettings, memory: &mut Memory, lengths: LengthUnits, compact: bool) { let mut linked = !memory.bleed_split; let link = LinkMode::Equal.label(&Env::of(ui).words::()); let sides = [text(tl!("Top")), text(tl!("Bottom")), text(tl!("Left")), text(tl!("Right"))]; let mut edited = None; - Row::new().wrap(true).show(ui, |ui, _| { - for (i, side) in sides.iter().enumerate() { - // A drag on the side's name scrubs its field. - let field = Field::new(side.clone()).layout(FieldLayout::Above).side(SideLabel::new().scrub(true)).sizing(Sizing::Content); - field.id_salt(("bleed", i)).show(ui, |ui, _| { - let field = NumberField::length(side.clone(), Bind::given(Some(s.bleed[i])), lengths) - .range(0.0..=vectorcraft_doc::setup::MAX_BLEED) - .scrub_by_label() - .sizing(Sizing::Content); - if let Some(v) = field.show(ui).edit.events.committed().copied().flatten().filter(|v| v.is_finite()) { - edited = Some((i, v.clamp(0.0, vectorcraft_doc::setup::MAX_BLEED))); - } - }); - } - // Turning the link on sets every side to Top's bleed. - if let Some(on) = link_toggle(link.clone(), Bind::given(linked)).id_salt("bleed-link").show(ui).value().copied() { - linked = on; - if on { - s.bleed = [s.bleed[0]; 4]; + let mut side_field = |ui: &mut egui::Ui, i: usize| { + // A drag on the side's name scrubs its field. + let field = Field::new(sides[i].clone()).layout(FieldLayout::Above).side(SideLabel::new().scrub(true)).sizing(Sizing::Content); + field.id_salt(("bleed", i)).show(ui, |ui, _| { + let field = NumberField::length(sides[i].clone(), Bind::given(Some(s.bleed[i])), lengths) + .range(0.0..=vectorcraft_doc::setup::MAX_BLEED) + .scrub_by_label() + .sizing(Sizing::Content); + if let Some(v) = field.show(ui).edit.events.committed().copied().flatten().filter(|v| v.is_finite()) { + edited = Some((i, v.clamp(0.0, vectorcraft_doc::setup::MAX_BLEED))); } + }); + }; + let mut turned_on = None; + // Turning the link on sets every side to Top's bleed. + let mut link_button = |ui: &mut egui::Ui| { + if let Some(on) = link_toggle(link.clone(), Bind::given(linked)).id_salt("bleed-link").show(ui).value().copied() { + turned_on = Some(on); } - }); + }; + if compact { + Stack::new().show(ui, |ui, _| { + Row::new().show(ui, |ui, _| (0..2).for_each(|i| side_field(ui, i))); + Row::new().show(ui, |ui, _| { + (2..4).for_each(|i| side_field(ui, i)); + link_button(ui); + }); + }); + } else { + Row::new().wrap(true).show(ui, |ui, _| { + (0..sides.len()).for_each(|i| side_field(ui, i)); + link_button(ui); + }); + } + if let Some(on) = turned_on { + linked = on; + if on { + s.bleed = [s.bleed[0]; 4]; + } + } if let Some((i, v)) = edited { if linked { s.bleed = follow_equal(s.bleed, i, v); @@ -459,10 +489,21 @@ fn bleed_row(ui: &mut egui::Ui, s: &mut DocSettings, memory: &mut Memory, length memory.bleed_split = !linked; } -/// The Height, Orientation and Artboards row. Orientation's share keeps its two buttons side by side in a 900-point -/// window. +/// The Height, Orientation and Artboards row of a wide details column. const THIRDS: [ColumnWidth; 3] = [ColumnWidth::fill(1.0), ColumnWidth::fill(1.4), ColumnWidth::fill(1.0)]; +/// The Height and Artboards row of a narrow details column. +const HALVES: [ColumnWidth; 2] = [ColumnWidth::fill(1.0), ColumnWidth::fill(1.0)]; + +/// The least width of a wide details column, in control heights: the four Bleed fields and the link button in one row, +/// and Orientation's two buttons side by side between Height and Artboards. +const WIDE_DETAILS: f32 = 11.0; + +/// Whether the details column is narrower than [`WIDE_DETAILS`] control heights. +fn compact_details(ui: &egui::Ui) -> bool { + ui.available_width() < WIDE_DETAILS * Env::of(ui).tokens.size.control.md +} + /// A side of the page in points, shown in the chosen units. fn size_field(ui: &mut egui::Ui, name: &Label, points: &mut f64, lengths: LengthUnits) { let field = NumberField::length(name.clone(), Bind::given(Some(*points)), lengths).range(MIN_SIDE..=MAX_SIDE).sizing(Sizing::FillWidth); @@ -1514,4 +1555,27 @@ mod tests { assert!(portrait.y0 == landscape.y0 && portrait.x1 <= landscape.x0, "{width}x{height}: Portrait and Landscape side by side"); } } + + /// In small windows Height and Artboards share a row, Orientation's two buttons stand side by side under them, and + /// the Bleed fields form two rows of two, Top and Bottom above Left and Right, with the link button after Right; + /// before, at 800 by 600 Orientation's buttons stood one above the other between Height and Artboards. + #[test] + fn new_document_details_stay_in_rows_in_small_windows() { + use egui::accesskit::Role; + for (width, height) in [(800.0, 600.0), (640.0, 500.0), (900.0, 700.0)] { + let nodes = dialog_nodes(width, height); + let at = format!("{width}x{height}"); + let dialog = nodes.iter().find(|(r, _, _)| *r == Role::Dialog).map(|(_, _, b)| *b).expect("the dialog"); + let (portrait, landscape) = (node(&nodes, "Portrait", Role::RadioButton), node(&nodes, "Landscape", Role::RadioButton)); + assert!(portrait.y0 == landscape.y0 && portrait.x1 <= landscape.x0, "{at}: Portrait {portrait:?} beside Landscape {landscape:?}"); + let (h, a) = (node(&nodes, "Height", Role::SpinButton), node(&nodes, "Artboards", Role::SpinButton)); + assert!(h.y0 == a.y0 && h.x1 <= a.x0, "{at}: Height {h:?} and Artboards {a:?} share a row"); + assert!(a.y1 <= portrait.y0 || landscape.x1 <= a.x0, "{at}: Orientation {landscape:?} stays clear of Artboards {a:?}"); + let [top, bottom, left, right] = ["Top", "Bottom", "Left", "Right"].map(|side| node(&nodes, side, Role::SpinButton)); + assert!(top.y0 == bottom.y0 && left.y0 == right.y0 && top.y1 <= left.y0, "{at}: two Bleed rows: {top:?} {bottom:?} {left:?} {right:?}"); + assert!(top.x0 == left.x0 && bottom.x0 == right.x0 && top.x1 <= bottom.x0, "{at}: two Bleed columns: {top:?} {bottom:?} {left:?} {right:?}"); + let link = node(&nodes, "Make all settings the same", Role::Button); + assert!(right.x1 <= link.x0 && link.x1 <= dialog.x1, "{at}: the link button {link:?} follows Right {right:?} inside {dialog:?}"); + } + } } From bb55ab3963f780a03b4b6d3a245e244514432259 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 28 Nov 2026 14:54:58 -0800 Subject: [PATCH 2/2] New Document: format the small-window layout test --- crates/ui-egui/src/dialogs/new_document.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/dialogs/new_document.rs b/crates/ui-egui/src/dialogs/new_document.rs index f2007ed5d2..8e770d3da7 100644 --- a/crates/ui-egui/src/dialogs/new_document.rs +++ b/crates/ui-egui/src/dialogs/new_document.rs @@ -1573,7 +1573,10 @@ mod tests { assert!(a.y1 <= portrait.y0 || landscape.x1 <= a.x0, "{at}: Orientation {landscape:?} stays clear of Artboards {a:?}"); let [top, bottom, left, right] = ["Top", "Bottom", "Left", "Right"].map(|side| node(&nodes, side, Role::SpinButton)); assert!(top.y0 == bottom.y0 && left.y0 == right.y0 && top.y1 <= left.y0, "{at}: two Bleed rows: {top:?} {bottom:?} {left:?} {right:?}"); - assert!(top.x0 == left.x0 && bottom.x0 == right.x0 && top.x1 <= bottom.x0, "{at}: two Bleed columns: {top:?} {bottom:?} {left:?} {right:?}"); + assert!( + top.x0 == left.x0 && bottom.x0 == right.x0 && top.x1 <= bottom.x0, + "{at}: two Bleed columns: {top:?} {bottom:?} {left:?} {right:?}" + ); let link = node(&nodes, "Make all settings the same", Role::Button); assert!(right.x1 <= link.x0 && link.x1 <= dialog.x1, "{at}: the link button {link:?} follows Right {right:?} inside {dialog:?}"); }