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.
This commit is contained in:
David Mann
2026-11-20 13:18:00 +01:00
parent 9e2ad8542f
commit 98d0b8ce4b
2 changed files with 30 additions and 7 deletions
@@ -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, _| {
@@ -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);