Add explicit orthogonal span sizing

This commit is contained in:
iris-ai committed 2026-09-15 16:40:09 -04:00
1 parent 29c7881c8a
commit f437495309
7 files changed
+108 -8

No files matched your search

+2 -1
View File
@@ -190,9 +190,10 @@ fn describe(id: WidgetId, h: &Harness) -> String {
if let Some(w) = any.downcast_ref::<Span>() {
let sign = if w.dir.sign == Sign::Neg { "-" } else { "+" };
return format!(
"Span{{dir:{:?}{sign},gap:{},n:{}}}",
"Span{{dir:{:?}{sign},gap:{},ortho:{:?},n:{}}}",
w.dir.axis,
w.gap,
w.ortho,
w.children.len()
);
}
+33 -1
View File
@@ -20,6 +20,33 @@ fn a_span_gives_each_child_the_width_it_asked_for() {
assert_corners!(h, right, (100, 0), (400, 200));
}
#[test]
fn a_full_ortho_span_reports_relative_full() {
let mut h = Harness::new((400, 200));
let child = rect(Color::RED).height(40).add(&mut h.rsc);
let span = (child,)
.span(Dir::RIGHT)
.ortho(OrthoSize::Full)
.add(&mut h.rsc);
h.set_root(span);
assert_eq!(h.render.active[&span.id()].size.y, Len::rel(1.0));
}
#[test]
fn a_children_ortho_span_reports_its_tallest_fixed_child() {
let mut h = Harness::new((400, 200));
let short = rect(Color::RED).height(40).add(&mut h.rsc);
let tall = rect(Color::BLUE).height(70).add(&mut h.rsc);
let span = (short, tall)
.span(Dir::RIGHT)
.ortho(OrthoSize::Children)
.add(&mut h.rsc);
h.set_root(span);
assert_eq!(h.render.active[&span.id()].size.y, Len::px(70.0));
}
#[test]
fn resizing_relays_out_against_the_new_output() {
let mut h = Harness::new((400, 200));
@@ -158,7 +185,12 @@ fn a_box_with_a_fixed_length_can_be_stretched_on_its_other_axis() {
let inner = rect(Color::BLUE).add(&mut h.rsc);
let row = inner.pad(10).height(40).add(&mut h.rsc);
let filler = rect(Color::GREEN).add(&mut h.rsc);
let column = (row, filler).span(Dir::DOWN).add(&mut h.rsc);
// This column is an item in a row, so it takes the width left for it
// rather than asking for a full row-width in addition to the bar.
let column = (row, filler)
.span(Dir::DOWN)
.ortho(OrthoSize::Children)
.add(&mut h.rsc);
let bar = rect(Color::RED).width(100).add(&mut h.rsc);
h.set_root((bar, column).span(Dir::RIGHT));
assert_corners!(h, inner, (110, 10), (390, 30));
+19
View File
@@ -264,6 +264,25 @@ fn a_resize_does_not_redraw_what_the_shader_can_move() {
assert_corners!(h, leaf, (0, 0), (800, 100));
}
#[test]
fn a_full_ortho_span_moves_its_child_without_redrawing_it() {
let mut h = Harness::new((400, 200));
let (leaf, draws) = counted(&mut h, Size::LEFTOVER, false);
let span = (leaf,)
.span(Dir::RIGHT)
.ortho(OrthoSize::Full)
.add(&mut h.rsc);
h.set_root(span);
let settled = draws.get();
h.resize((400, 100));
h.frame();
assert_eq!(draws.get(), settled);
assert_corners!(h, leaf, (0, 0), (400, 100));
assert_eq!(h.render.active[&span.id()].size.y, Len::rel(1.0));
}
/// The output is the root of the box chain, so a resize is a box that changed
/// length like any other -- there is not a second rule for the window. A
/// drawing that holds for one length is drawn again whichever box moved.
+4
View File
@@ -116,6 +116,10 @@ impl Node {
children,
dir: dir(*down),
gap: *gap,
ortho: match down {
true => OrthoSize::Children,
false => OrthoSize::Full,
},
}
.add(&mut h.rsc);
spans.push(handle);
+3
View File
@@ -173,6 +173,7 @@ fn plant_pair(h: &mut Harness, swapped: bool) -> (Vec<WidgetId>, WeakWidget<Span
children,
dir: Dir::RIGHT,
gap: 0.0,
ortho: OrthoSize::Children,
}
.add(&mut h.rsc);
let span_handle = span;
@@ -230,6 +231,7 @@ fn plant_scrolled(h: &mut Harness, swapped: bool) -> (Vec<WidgetId>, [WeakWidget
children: inner_children,
dir: Dir::RIGHT,
gap: 0.0,
ortho: OrthoSize::Children,
}
.add(&mut h.rsc);
let block = rect(Color::RED).add(&mut h.rsc);
@@ -248,6 +250,7 @@ fn plant_scrolled(h: &mut Harness, swapped: bool) -> (Vec<WidgetId>, [WeakWidget
children: outer_children,
dir: Dir::RIGHT,
gap: 0.0,
ortho: OrthoSize::Children,
}
.add(&mut h.rsc);
let through = SetSize {