mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-07 12:16:42 +01:00
test and fix behaviors of some of the layout components
This commit is contained in:
parent
aaedede796
commit
11ecf669a1
4 changed files with 137 additions and 56 deletions
|
|
@ -288,6 +288,9 @@ pub struct FillBg(pub Color);
|
|||
|
||||
impl Widget for FillBg {
|
||||
type Engine = Tui;
|
||||
fn layout (&self, [x,y,_,_]: [u16;4]) -> Perhaps<[u16;4]> {
|
||||
Ok(Some([x,y,0,0]))
|
||||
}
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
||||
to.fill_bg(to.area(), self.0);
|
||||
Ok(Some(to.area))
|
||||
|
|
@ -457,9 +460,8 @@ where
|
|||
if h >= to.h() {
|
||||
return Ok(())
|
||||
}
|
||||
if let Some([_, _, width, height]) = Offset::Y(
|
||||
h, component as &dyn Widget<Engine = Tui>
|
||||
).layout(to)? {
|
||||
let area = Offset::Y(h, component as &dyn Widget<Engine = Tui>).layout(to)?;
|
||||
if let Some([_, _, width, height]) = area {
|
||||
h += height;
|
||||
w = w.max(width)
|
||||
}
|
||||
|
|
@ -554,14 +556,14 @@ where
|
|||
impl<T: Widget<Engine = Tui>> Widget for Align<T> {
|
||||
type Engine = Tui;
|
||||
fn layout (&self, outer_area: [u16;4]) -> Perhaps<[u16;4]> {
|
||||
Ok(self.inner().layout(outer_area)?.map(|inner_area|match self {
|
||||
Self::Center(_) => {
|
||||
Ok(match self {
|
||||
Self::Center(_) => self.inner().layout(outer_area)?.map(|inner_area|{
|
||||
let [_, _, w, h] = inner_area.xywh();
|
||||
let offset_x = (outer_area.w() / 2).saturating_sub(w / 2);
|
||||
let offset_y = (outer_area.h() / 2).saturating_sub(h / 2);
|
||||
let result = [outer_area.x() + offset_x, outer_area.y() + offset_y, w, h];
|
||||
result
|
||||
},
|
||||
}),
|
||||
Self::NW(_) => { todo!() },
|
||||
Self::N(_) => { todo!() },
|
||||
Self::NE(_) => { todo!() },
|
||||
|
|
@ -570,7 +572,7 @@ impl<T: Widget<Engine = Tui>> Widget for Align<T> {
|
|||
Self::SW(_) => { todo!() },
|
||||
Self::S(_) => { todo!() },
|
||||
Self::SE(_) => { todo!() },
|
||||
}))
|
||||
})
|
||||
}
|
||||
fn render (&self, to: &mut Tui) -> Perhaps<[u16;4]> {
|
||||
self.layout(to.area())?
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue