From 5a7c56cdaa6c4de435f0f0c28d29c72b980348bd Mon Sep 17 00:00:00 2001 From: clover caruso Date: Fri, 2 Oct 2026 12:49:27 -0700 Subject: [PATCH] fix: a box laid out inverted paints empty instead of failing the frame A box with its bottom above its top failed the whole frame as an invalid primitive ("Canvas drawing failed: InvalidPrimitive"), as the rename field over a just-created section tab did. Such a box, or one smaller than its inset, now paints empty. Assisted-by: claude-opus-5.5 --- crates/ui/src/lib.rs | 10 ++++------ crates/ui/src/tests.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/crates/ui/src/lib.rs b/crates/ui/src/lib.rs index 433bc139cfc273e9d086473eabb55cb94ae579ed..d311832b75166bb07f98fd76601fb84916f0d42e 100644 --- a/crates/ui/src/lib.rs +++ b/crates/ui/src/lib.rs @@ -1589,12 +1589,10 @@ impl Ui { }); let border = blend(node.border, node.hover_border); let [left, top, right, bottom] = node.inset; - let painted = [ - rect[0] + left, - rect[1] + top, - rect[2] - right, - rect[3] - bottom, - ]; + // A box squeezed smaller than its inset, or than nothing as it eases shut, paints + // empty rather than inverted. + let [x, y] = [rect[0] + left, rect[1] + top]; + let painted = [x, y, (rect[2] - right).max(x), (rect[3] - bottom).max(y)]; let size = [painted[2] - painted[0], painted[3] - painted[1]]; if let Some(color) = node.shadow { let (own, menu); diff --git a/crates/ui/src/tests.rs b/crates/ui/src/tests.rs index 97f317480f7bc253eba8e4aff47b2cd2cbf40fb3..c561e4079ab66f3fc169ff4075e65095d5261d99 100644 --- a/crates/ui/src/tests.rs +++ b/crates/ui/src/tests.rs @@ -3127,3 +3127,30 @@ fn a_loose_dialog_fits_its_contents_to_the_window_and_its_side_stretches_to_its_ "row 10 at {row}, the list's top at {top}" ); } + +#[test] +fn a_box_squeezed_past_its_inset_paints_empty_not_inverted() { + let mut ui = Ui::new(Theme::light(), DOUBLE_CLICK); + frame(&mut ui, |ui| { + ui.leaf( + "row", + Spec { + size: [px(100.0), px(4.0)], + fill: Some([1.0; 4]), + gradient: Some([0.5, 0.5, 0.5, 1.0]), + inset: [0.0, 0.0, 0.0, 10.0], + ..Spec::default() + }, + ); + }); + let rect = ui.display.iter().find_map(|item| match item { + Display::Rect { rect, .. } => Some(*rect), + _ => None, + }); + let [left, top, right, bottom] = rect.expect("the row paints"); + assert!( + right >= left && bottom >= top, + "{:?}", + [left, top, right, bottom] + ); +} -- 2.54.0