From 98d0b8ce4bef3893d93d3c920f70c32ba9c832b3 Mon Sep 17 00:00:00 2001 From: David Mann Date: Fri, 20 Nov 2026 13:18:00 +0100 Subject: [PATCH] New Document: keep Orientation beside Height reachable Orientation sat in a content-sized grid column that was measured empty, so its segments were clipped to nothing and a click did not turn the page. Height carried its own unit select as well, although one unit serves both sides. Height now shows its number alone in the shared unit and shares the row with Orientation in two equal columns, as Color Mode and Depth do. The orientation test also checks that both glyphs paint inside a visible clip, which would have caught this. --- .../form_dialogs/new_document/details.rs | 27 ++++++++++++++----- .../form_dialogs/new_document_orientation.rs | 10 +++++++ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/crates/ui-patterns/src/patterns/form_dialogs/new_document/details.rs b/crates/ui-patterns/src/patterns/form_dialogs/new_document/details.rs index 079787df2..8fc9a90d8 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/new_document/details.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/new_document/details.rs @@ -18,8 +18,8 @@ use crate::runtime::env::{Env, Label, Message, UnitKind}; use crate::runtime::focus::{self, FocusTarget}; use crate::runtime::words::CommonWords; use crate::style::TypeRole; -use crate::text::TextField; -use craft_behavior::{ColumnWidth, EditEvent, EditEvents, IconId, PixelSize}; +use crate::text::{NumberField, TextField}; +use craft_behavior::{ColumnWidth, EditEvent, EditEvents, IconId, NumberCodec, PixelSize}; use craft_theme::Srgba; use egui::Ui; @@ -141,22 +141,35 @@ pub(super) fn show(ui: &mut Ui, session: &mut Session, values: &mut DocumentOpti Side::Width => (session.size.width(), session.size.width_range()), Side::Height => (session.size.height(), session.size.height_range()), }; + if matches!(side, Side::Height) { + // One unit serves both sides, so its select sits on the Width row only and Height leaves that + // room to Orientation beside it. The field reads and steps in the shared unit. + let kind = session.size.unit(); + let units = Env::of(ui).units(); + let shown = NumberField::new(side.name(words).clone(), Bind::given(Some(value))) + .range(range) + .codec(NumberCodec::new(units.reader(Some(kind)), *kind.decimals().end())) + .step(kind.step()) + .sizing(Sizing::FillWidth) + .show(ui); + apply_number(session, &shown.edit.events, |size, value| size.set_height(value)); + return; + } let shown = UnitSelect::new(side.name(words).clone(), Bind::given(Some(value)), Bind::given(session.size.unit()), &size_units) .range(range) .unit_label(side.unit_name(words).clone()) .sizing(Sizing::FillWidth) .show(ui); - apply_number(session, &shown.edit.events, |size, value| match side { - Side::Width => size.set_width(value), - Side::Height => size.set_height(value), - }); + apply_number(session, &shown.edit.events, |size, value| size.set_width(value)); if let Some(kind) = shown.unit.value().copied() { session.size.set_unit(kind); } }); }; dimension(ui, session, Side::Width); - const HEIGHT_AND_ORIENTATION: [ColumnWidth; 2] = [ColumnWidth::fill(1.0), ColumnWidth::Content]; + // Two shares, as Color Mode and Depth: a content-sized column here was measured empty, which clipped Orientation + // out of reach. + const HEIGHT_AND_ORIENTATION: [ColumnWidth; 2] = [ColumnWidth::fill(1.0), ColumnWidth::fill(1.0)]; Grid::new(&HEIGHT_AND_ORIENTATION).fill().show(ui, |ui, _| { dimension(ui, session, Side::Height); Field::new(words.orientation.clone()).layout(FieldLayout::Above).id_salt("orientation").show(ui, |ui, _| { diff --git a/crates/ui-patterns/tests/it/form_dialogs/new_document_orientation.rs b/crates/ui-patterns/tests/it/form_dialogs/new_document_orientation.rs index 83c7ba853..6663f5b59 100644 --- a/crates/ui-patterns/tests/it/form_dialogs/new_document_orientation.rs +++ b/crates/ui-patterns/tests/it/form_dialogs/new_document_orientation.rs @@ -22,6 +22,16 @@ fn orientation_uses_icons_and_swaps_the_document_dimensions() { fixture.texts().iter().all(|text| text.text != "Portrait" && text.text != "Landscape"), "the orientation controls show page icons without painting their accessible names" ); + let shapes = fixture.frame_clipped_shapes(); + for name in ["Portrait", "Landscape"] { + let choice = fixture.by_label(name).expect("an orientation choice").rect; + let painted = shapes.iter().any(|(clip, shape)| { + let bounds = shape.visual_bounding_rect(); + choice.contains_rect(bounds) && bounds.area() < choice.area() && clip.contains_rect(bounds) + }); + assert!(painted, "the {name} glyph is painted where it can be seen"); + } + assert!(fixture.by_label("Height Unit").is_none(), "Width's unit select serves Height too"); let original = options.borrow().size; assert!(original.width > original.height);