fix (?) Inset; add arranger cursor description

This commit is contained in:
🪞👃🪞 2024-09-30 09:41:43 +03:00
parent 7df9cc930d
commit 3c8d9668fe
4 changed files with 137 additions and 151 deletions

View file

@ -101,6 +101,12 @@ pub trait Area<N: Number>: Copy {
_ => todo!(),
}
}
#[inline] fn push_x (&self, x: N) -> [N;4] { [self.x() + x, self.y(), self.w(), self.h()] }
#[inline] fn push_y (&self, y: N) -> [N;4] { [self.x(), self.y() + y, self.w(), self.h()] }
#[inline] fn shrink_x (&self, x: N) -> [N;4] { [self.x(), self.y(), self.w() - x, self.h()] }
#[inline] fn shrink_y (&self, y: N) -> [N;4] { [self.x(), self.y(), self.w(), self.h() - y] }
#[inline] fn set_w (&self, w: N) -> [N;4] { [self.x(), self.y(), w, self.h()] }
#[inline] fn set_h (&self, h: N) -> [N;4] { [self.x(), self.y(), self.w(), h] }
}
impl<N: Number> Area<N> for (N, N, N, N) {
@ -610,18 +616,14 @@ impl<N: Number, T: Widget> Outset<N, T> {
impl<E: Engine, T: Widget<Engine = E>> Widget for Inset<E::Unit, T> {
type Engine = E;
fn layout (&self, to: E::Size) -> Perhaps<E::Size> {
match *self {
Self::X(x, ref inner) => Shrink::X(x + x, inner as &dyn Widget<Engine = E>),
Self::Y(y, ref inner) => Shrink::Y(y + y, inner as &dyn Widget<Engine = E>),
Self::XY(x, y, ref inner) => Shrink::XY(x + x, y + y, inner as &dyn Widget<Engine = E>),
}.layout(to)
}
fn render (&self, to: &mut E::Output) -> Usually<()> {
match *self {
Self::X(x, ref inner) => Push::X(x, inner as &dyn Widget<Engine = E>),
Self::Y(y, ref inner) => Push::Y(y, inner as &dyn Widget<Engine = E>),
Self::XY(x, y, ref inner) => Push::XY(x, y, inner as &dyn Widget<Engine = E>),
Self::X(x, ref inner) =>
Push::X(x, Shrink::X(x, inner as &dyn Widget<Engine = E>)),
Self::Y(y, ref inner) =>
Push::Y(y, Shrink::Y(y, inner as &dyn Widget<Engine = E>)),
Self::XY(x, y, ref inner) =>
Push::XY(x, y, Shrink::XY(x, y, inner as &dyn Widget<Engine = E>)),
}.render(to)
}
}

View file

@ -464,12 +464,8 @@ pub struct Bordered<S: BorderStyle, W: Widget<Engine = Tui>>(pub S, pub W);
impl<S: BorderStyle, W: Widget<Engine = Tui>> Content for Bordered<S, W> {
type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> {
let style = self.0;
Layers::new(move|add|{
add(&Inset::XY(1, 1, &self.1 as &dyn Widget<Engine = Tui>))?;
add(&Border(style))?;
Ok(())
}).fill_xy()
let content: &dyn Widget<Engine = Tui> = &self.1;
lay! { content.inset_xy(1, 1), Border(self.0) }.fill_xy()
}
}