diff --git a/crates/ui-contract/src/contract/body/regions.rs b/crates/ui-contract/src/contract/body/regions.rs index 24c1ff5c3..810189cf3 100644 --- a/crates/ui-contract/src/contract/body/regions.rs +++ b/crates/ui-contract/src/contract/body/regions.rs @@ -610,7 +610,11 @@ fn own_labels(ui: &mut Ui, id: Id, (room, seed): (f32, Option), foun group.offer(room); body(ui) }); - (found.extent, found.unsettled) = (scoped.extent, scoped.unsettled); + found.extent = scoped.extent; + // A later sweep of the same run may take a row's measure from the earlier sweep without reading the column again + // (a stack's sweep at the width its first sweep found): that measure is still the one taken at the narrower + // column, so the rows run again whenever any sweep found one. + found.unsettled = scoped.unsettled.or(found.unsettled.take()); result } diff --git a/crates/ui-patterns/tests/it/form_dialogs/hosted.rs b/crates/ui-patterns/tests/it/form_dialogs/hosted.rs index 91004c210..b2adec9e8 100644 --- a/crates/ui-patterns/tests/it/form_dialogs/hosted.rs +++ b/crates/ui-patterns/tests/it/form_dialogs/hosted.rs @@ -464,3 +464,60 @@ fn image_size_alt_digits_pick_resample_without_typing_into_a_field() { alt_digit(&mut fixture, Key::Num7, "7", alt); assert_eq!(resample(&host), Some(json!("nearestNeighbor")), "Alt+7 picks a listed method"); } + +/// Image Size's and Canvas Size's Width and Height rows (a stack of fields beside the link) show as they measured, at +/// 1x and 1.25x (#15483, #15538): each label sits beside its field, each field and unit select is as tall as a direct +/// row's control (`reference`), and Height's label starts under Width's controls. +#[trial] +fn sizing_dialogs_show_width_and_height_beside_their_labels_at_full_height() { + for scale in [1.0, 1.25] { + let opens: [(fn(&mut DialogHost), &str); 2] = [ + ( + |host| { + host.open(image_size()); + }, + "Resolution", + ), + ( + |host| { + host.open(canvas_size()); + }, + "Canvas extension color", + ), + ]; + for (open, reference) in opens { + let host = Rc::new(RefCell::new(DialogHost::new())); + let mut fixture = fixture(&host); + fixture.pixels_per_point(scale); + open(&mut host.borrow_mut()); + fixture.settle(); + let rect = |name: &str| fixture.by_label(name).unwrap_or_else(|| panic!("{name} is shown")).rect; + let label_of = |name: &str| { + // The field's label names the unit select's group, the number field's parent. + let tree = fixture.tree(); + let mut node = fixture.by_label(name).unwrap_or_else(|| panic!("{name} is shown")).node; + let label = loop { + if let Some(label) = tree.labelled_by_key(node).into_iter().next() { + break label; + } + node = tree.parent_of_key(node).unwrap_or_else(|| panic!("{name} is labelled")); + }; + tree.bounds_of(label).unwrap_or_else(|| panic!("{name}'s label is shown")) + }; + let full = rect(reference).height(); + for name in ["Width", "Height"] { + let (label, field) = (label_of(name), rect(name)); + for part in [field, rect(&format!("{name} unit"))] { + assert!(part.height() >= full - 0.5, "{name}'s controls are a full row tall at {scale}x ({reference}): {part:?} {full}"); + } + assert!(label.max.x <= field.min.x + 0.5, "{name}'s label sits before its field at {scale}x ({reference}): {label:?} {field:?}"); + assert!( + label.min.y < field.max.y && label.max.y > field.min.y, + "{name}'s label is on its field's line at {scale}x: {label:?} {field:?}" + ); + } + let (width, height) = (rect("Width").union(rect("Width unit")), label_of("Height")); + assert!(height.min.y >= width.max.y - 0.5, "Height's row starts under Width's at {scale}x ({reference}): {height:?} {width:?}"); + } + } +} diff --git a/crates/ui-widgets/tests/it/label/reach.rs b/crates/ui-widgets/tests/it/label/reach.rs index 9ba55faf3..6d03c7651 100644 --- a/crates/ui-widgets/tests/it/label/reach.rs +++ b/crates/ui-widgets/tests/it/label/reach.rs @@ -8,10 +8,11 @@ use craft_ui::buttons::Button; use craft_ui::contract::{Bind, ContainerProps, Entry, LabelScheme, Props as _, Show as _, ShowContainer as _, SideLabel, Sizing}; use craft_ui::form::{Field, FieldGroup}; use craft_ui::layout_components::{Row, Stack}; +use craft_ui::pickers::UnitSelect; use craft_ui::runtime::env::UnitKind; use craft_ui::testing::{Fixture, Frames, last_pass_measuring_runs, trial}; -use craft_ui::text::{NumberField, NumberPick}; -use egui::Rect; +use craft_ui::text::{NumberField, NumberPick, link_toggle}; +use egui::{Rect, Vec2}; use std::cell::RefCell; /// How far two edges may differ and still line up, in points. @@ -194,3 +195,56 @@ fn a_field_before_the_groups_widest_value_shows_at_its_width() { let runs = last_pass_measuring_runs(fixture.ctx()); assert!(runs.is_empty(), "a settled frame takes the kept measurements: {runs:?}"); } + +/// A field `caption` holding a unit select, its select named "`caption` unit". +fn unit(ui: &mut egui::Ui, caption: &'static str, units: &[Entry]) { + Field::new(caption).show(ui, |ui, _| { + UnitSelect::new(caption, Bind::given(Some(8.0)), Bind::given(UnitKind::Pixels), units).unit_label(format!("{caption} unit")).show(ui); + }); +} + +/// In a content-sized form, the labelled rows of a stack inside a row (Image Size's Width and Height beside their +/// link) take the placement their measure took, at the form's final label column: each label sits beside its +/// controls, each control is as tall as a direct row's, and the next row starts under the one before. At 1x and 1.25x. +#[trial] +fn a_stack_of_labelled_rows_in_a_row_lays_out_as_it_measured() { + for scale in [1.0, 1.25] { + let units = [Entry::new(UnitKind::Pixels, "Pixels"), Entry::new(UnitKind::Percent, "Percent")]; + let mut fixture = Fixture::new(move |ui| { + Row::new().show(ui, |ui, _| { + FieldGroup::new("Image size").show(ui, |ui, _| { + number(ui, "Size"); + Row::new().show(ui, |ui, _| { + Stack::new().show(ui, |ui, _| { + unit(ui, "Width", &units); + unit(ui, "Height", &units); + }); + link_toggle("Link", Bind::given(true)).show(ui); + }); + unit(ui, "Resolution", &units); + number(ui, "Canvas extension color"); + }); + }); + }); + fixture.room(Vec2::new(1400.0, 1000.0)).pixels_per_point(scale); + fixture.settle(); + let reference = control(&fixture, "Resolution"); + let mut above = f32::NEG_INFINITY; + for name in ["Width", "Height", "Resolution"] { + let (label, field, select) = (caption(&fixture, name), control(&fixture, name), control(&fixture, &format!("{name} unit"))); + for part in [field, select] { + assert!(part.height() >= reference.height() - SLACK, "{name}'s controls are a full row tall at {scale}x: {part:?} {reference:?}"); + } + assert!(label.max.x <= field.min.x + SLACK, "{name}'s label sits before its field at {scale}x: {label:?} {field:?}"); + assert!( + label.min.y < field.max.y && label.max.y > field.min.y, + "{name}'s label sits on its field's line at {scale}x: {label:?} {field:?}" + ); + assert!(label.min.y >= above - SLACK, "{name}'s row starts under the row before at {scale}x: {label:?} {above}"); + above = field.max.y.max(select.max.y); + } + let link = fixture.by_label("Link").expect("the link toggle is shown").rect; + let select = control(&fixture, "Width unit"); + assert!(link.min.x >= select.max.x - SLACK, "the link starts clear of the selects at {scale}x: {link:?} {select:?}"); + } +}