mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
Offset -> Plus; add Minus
This commit is contained in:
parent
dc03a664a4
commit
00da7de142
5 changed files with 176 additions and 77 deletions
|
|
@ -487,7 +487,7 @@ where
|
|||
if h >= to.h() {
|
||||
return Ok(())
|
||||
}
|
||||
let area = Offset::Y(h, component as &dyn Widget<Engine = Tui>).layout(to)?;
|
||||
let area = Plus::Y(h, component as &dyn Widget<Engine = Tui>).layout(to)?;
|
||||
if let Some([_, _, width, height]) = area {
|
||||
h += height;
|
||||
w = w.max(width)
|
||||
|
|
@ -500,7 +500,7 @@ where
|
|||
if w >= to.w() {
|
||||
return Ok(())
|
||||
}
|
||||
let area = Offset::X(w, component as &dyn Widget<Engine = Tui>).layout(to)?;
|
||||
let area = Plus::X(w, component as &dyn Widget<Engine = Tui>).layout(to)?;
|
||||
if let Some([_, _, width, height]) = area {
|
||||
w += width;
|
||||
h = h.max(height)
|
||||
|
|
@ -522,7 +522,7 @@ where
|
|||
if h >= area.h() {
|
||||
return Ok(())
|
||||
}
|
||||
let area = Offset::Y(h, component as &dyn Widget<Engine = Tui>).render(to)?;
|
||||
let area = Plus::Y(h, component as &dyn Widget<Engine = Tui>).render(to)?;
|
||||
if let Some([_, _, width, height]) = area {
|
||||
h += height;
|
||||
w = w.max(width)
|
||||
|
|
@ -535,7 +535,7 @@ where
|
|||
if w >= area.w() {
|
||||
return Ok(())
|
||||
}
|
||||
let area = Offset::X(w, component as &dyn Widget<Engine = Tui>).render(to)?;
|
||||
let area = Plus::X(w, component as &dyn Widget<Engine = Tui>).render(to)?;
|
||||
if let Some([_, _, width, height]) = area {
|
||||
w += width;
|
||||
h = h.max(height)
|
||||
|
|
@ -578,31 +578,45 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<T: Widget<Engine = Tui>> Widget for Inset<u16, T> {
|
||||
impl<T: Widget<Engine = Tui>> Content for Inset<u16, T> {
|
||||
type Engine = Tui;
|
||||
fn layout (&self, to: [u16;4]) -> Perhaps<[u16;4]> {
|
||||
Align::Center(match self {
|
||||
Self::X(x, inner) => Shrink::X(*x + *x, inner as &dyn Widget<Engine = Tui>),
|
||||
Self::Y(y, inner) => Shrink::X(*y + *y, inner as &dyn Widget<Engine = Tui>),
|
||||
Self::XY(x, y, inner) => Shrink::XY(*x, *y, inner as &dyn Widget<Engine = Tui>),
|
||||
}).layout(to)
|
||||
}
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
||||
Ok(self.layout(to.area())?.map(|a|to.render_in(a, self.inner())).transpose()?.flatten())
|
||||
fn content (&self) -> impl Widget<Engine = Tui> {
|
||||
match self {
|
||||
Self::X(x, inner) =>
|
||||
Plus::X(*x, Shrink::X(*x + *x, Align::X(inner as &dyn Widget<Engine = Tui>))),
|
||||
Self::Y(y, inner) =>
|
||||
Plus::Y(*y, Shrink::X(*y + *y, Align::Y(inner as &dyn Widget<Engine = Tui>))),
|
||||
Self::XY(x, y, inner) =>
|
||||
Plus::XY(*x, *y, Shrink::XY(*x, *y, Align::Center(inner as &dyn Widget<Engine = Tui>))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Widget<Engine = Tui>> Widget for Outset<u16, T> {
|
||||
//impl<T: Widget<Engine = Tui>> Widget for Inset<u16, T> {
|
||||
//type Engine = Tui;
|
||||
//fn layout (&self, to: [u16;4]) -> Perhaps<[u16;4]> {
|
||||
//match self {
|
||||
//Self::X(x, inner) => Shrink::X(*x + *x, Align::Center(inner as &dyn Widget<Engine = Tui>)),
|
||||
//Self::Y(y, inner) => Shrink::X(*y + *y, Align::Center(inner as &dyn Widget<Engine = Tui>)),
|
||||
//Self::XY(x, y, inner) => Shrink::XY(*x, *y, Align::Center(inner as &dyn Widget<Engine = Tui>)),
|
||||
//}.layout(to)
|
||||
//}
|
||||
//fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
||||
//Ok(self.layout(to.area())?.map(|a|to.render_in(a, self.inner())).transpose()?.flatten())
|
||||
//}
|
||||
//}
|
||||
|
||||
impl<T: Widget<Engine = Tui>> Content for Outset<u16, T> {
|
||||
type Engine = Tui;
|
||||
fn layout (&self, to: [u16;4]) -> Perhaps<[u16;4]> {
|
||||
Align::Center(match self {
|
||||
Self::X(x, inner) => Grow::X(*x + *x, inner as &dyn Widget<Engine = Tui>),
|
||||
Self::Y(y, inner) => Grow::X(*y + *y, inner as &dyn Widget<Engine = Tui>),
|
||||
Self::XY(x, y, inner) => Grow::XY(*x, *y, inner as &dyn Widget<Engine = Tui>),
|
||||
}).layout(to)
|
||||
}
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
||||
Ok(self.layout(to.area())?.map(|a|to.render_in(a, self.inner())).transpose()?.flatten())
|
||||
fn content (&self) -> impl Widget<Engine = Tui> {
|
||||
match *self {
|
||||
Self::X(x, ref inner) =>
|
||||
Grow::X(x + x, inner as &dyn Widget<Engine = Tui>),
|
||||
Self::Y(y, ref inner) =>
|
||||
Grow::Y(y + y, inner as &dyn Widget<Engine = Tui>),
|
||||
Self::XY(x, y, ref inner) =>
|
||||
Grow::XY(x, y, inner as &dyn Widget<Engine = Tui>),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue