From e9e99932d15471eee757f9fe9d9946a2496aae9d Mon Sep 17 00:00:00 2001 From: unspeaker Date: Fri, 20 Sep 2024 23:28:38 +0300 Subject: [PATCH] space: prevent crash in Shrink --- crates/tek_core/src/space.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/crates/tek_core/src/space.rs b/crates/tek_core/src/space.rs index faf612b4..bd2700df 100644 --- a/crates/tek_core/src/space.rs +++ b/crates/tek_core/src/space.rs @@ -440,9 +440,18 @@ impl> Widget for Shrink { type Engine = E; fn layout (&self, to: E::Size) -> Perhaps { Ok(self.inner().layout(to)?.map(|to|match *self { - Self::X(w, _) => [to.w() - w, to.h()], - Self::Y(h, _) => [to.w(), to.h() - h], - Self::XY(w, h, _) => [to.w() - w, to.h() - h] + Self::X(w, _) => [ + if to.w() > w { to.w() - w } else { 0.into() }, + to.h() + ], + Self::Y(h, _) => [ + to.w(), + if to.h() > h { to.h() - h } else { 0.into() } + ], + Self::XY(w, h, _) => [ + if to.w() > w { to.w() - w } else { 0.into() }, + if to.h() > h { to.h() - h } else { 0.into() } + ] }.into())) } fn render (&self, to: &mut E::Output) -> Usually<()> {