space: prevent crash in Shrink

This commit is contained in:
🪞👃🪞 2024-09-20 23:28:38 +03:00
parent 9c948e580f
commit e9e99932d1

View file

@ -440,9 +440,18 @@ impl<E: Engine, T: Widget<Engine = E>> Widget for Shrink<E::Unit, T> {
type Engine = E; type Engine = E;
fn layout (&self, to: E::Size) -> Perhaps<E::Size> { fn layout (&self, to: E::Size) -> Perhaps<E::Size> {
Ok(self.inner().layout(to)?.map(|to|match *self { Ok(self.inner().layout(to)?.map(|to|match *self {
Self::X(w, _) => [to.w() - w, to.h()], Self::X(w, _) => [
Self::Y(h, _) => [to.w(), to.h() - h], if to.w() > w { to.w() - w } else { 0.into() },
Self::XY(w, h, _) => [to.w() - w, to.h() - h] 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())) }.into()))
} }
fn render (&self, to: &mut E::Output) -> Usually<()> { fn render (&self, to: &mut E::Output) -> Usually<()> {