diff --git a/crates/tek_core/src/engine/component.rs b/crates/tek_core/src/engine/component.rs index 33b2e633..adb76b43 100644 --- a/crates/tek_core/src/engine/component.rs +++ b/crates/tek_core/src/engine/component.rs @@ -80,7 +80,7 @@ pub trait Content { //() //} //} -impl Widget for W where W: Content { +impl> Widget for W { type Engine = E; fn layout (&self, to: E::Area) -> Perhaps { self.content().layout(to) diff --git a/crates/tek_core/src/engine/layout.rs b/crates/tek_core/src/engine/layout.rs index a89a8a43..28930a55 100644 --- a/crates/tek_core/src/engine/layout.rs +++ b/crates/tek_core/src/engine/layout.rs @@ -1,60 +1,7 @@ use crate::*; -// TODO: Convert to component -// pub enum Align { Center, NW, N, NE, E, SE, S, SW, W, } -//pub fn center_box (area: [u16;4], w: u16, h: u16) -> [u16;4] { - //let width = w.min(area.w() * 3 / 5); - //let height = h.min(area.w() * 3 / 5); - //let x = area.x() + (area.w() - width) / 2; - //let y = area.y() + (area.h() - height) / 2; - //[x, y, width, height] -//} - -///// Trait for structs that compute drawing area before rendering -//pub trait Layout: Render { - //fn layout (&self, area: E::Area) -> Perhaps; -//} -//impl<'a, E: Engine> Layout for Box + 'a> { - //fn layout (&self, area: E::Area) -> Perhaps { - //(**self).layout(area) - //} -//} -//impl<'a, E: Engine> Layout for Box + 'a> { - //fn layout (&self, area: E::Area) -> Perhaps { - //(**self).layout(area) - //} -//} -//impl> Layout for &T { - //fn layout (&self, area: E::Area) -> Perhaps { - //(*self).layout(area) - //} -//} -//impl> Layout for &mut T { - //fn layout (&self, area: E::Area) -> Perhaps { - //(**self).layout(area) - //} -//} -//impl> Layout for Option { - //fn layout (&self, area: E::Area) -> Perhaps { - //match self { - //Some(layout) => layout.layout(area), - //None => Ok(None) - //} - //} -//} - /// Override X and Y coordinates, aligning to corner, side, or center of area pub enum Align { Center(L), NW(L), N(L), NE(L), W(L), E(L), SW(L), S(L), SE(L) } -/// Enforce minimum size of drawing area -pub enum Min { W(U, T), H(U, T), WH(U, U, T), } -/// Enforce maximum size of drawing area -pub enum Max { W(U, T), H(U, T), WH(U, U, T), } -/// Expand drawing area -pub enum Outset { W(U, T), H(U, T), WH(U, U, T), } -/// Shrink drawing area -pub enum Inset { W(U, T), H(U, T), WH(U, U, T), } -/// Move origin point of drawing area -pub enum Offset { X(U, T), Y(U, T), XY(U, U, T), } impl Align { pub fn inner (&self) -> &T { @@ -72,6 +19,9 @@ impl Align { } } +/// Enforce minimum size of drawing area +pub enum Min { W(U, T), H(U, T), WH(U, U, T), } + impl> Widget for Min { type Engine = E; fn layout (&self, area: E::Area) -> Perhaps { @@ -103,6 +53,9 @@ impl> Widget for Min { } } +/// Enforce maximum size of drawing area +pub enum Max { W(U, T), H(U, T), WH(U, U, T), } + impl> Widget for Max { type Engine = E; fn layout (&self, area: E::Area) -> Perhaps { @@ -133,6 +86,9 @@ impl> Widget for Max { } } +/// Expand drawing area +pub enum Outset { W(U, T), H(U, T), WH(U, U, T), } + impl> Widget for Outset { type Engine = E; fn layout (&self, area: E::Area) -> Perhaps { @@ -161,6 +117,9 @@ impl> Widget for Outset { } } +/// Shrink drawing area +pub enum Inset { W(U, T), H(U, T), WH(U, U, T), } + impl> Widget for Inset { type Engine = E; fn layout (&self, area: E::Area) -> Perhaps { @@ -189,6 +148,9 @@ impl> Widget for Inset { } } +/// Move origin point of drawing area +pub enum Offset { X(U, T), Y(U, T), XY(U, U, T), } + impl> Widget for Offset { type Engine = E; fn layout (&self, area: E::Area) -> Perhaps { diff --git a/crates/tek_core/src/tui/tui_layout.rs b/crates/tek_core/src/tui/tui_layout.rs index 3c55c11b..6a33a606 100644 --- a/crates/tek_core/src/tui/tui_layout.rs +++ b/crates/tek_core/src/tui/tui_layout.rs @@ -23,7 +23,8 @@ impl<'a> Split<'a, Tui> { if h >= area.h() { break } - let result = Offset::Y(h, component).render(to)?; + let offset = Offset::Y(h, component as &dyn Widget); + let result = offset.render(to)?; areas.push(result); if let Some([_, _, width, height]) = result { h += height; @@ -37,7 +38,8 @@ impl<'a> Split<'a, Tui> { if w >= area.x() { break } - let result = Offset::X(w, component).render(to)?; + let offset = Offset::X(w, component as &dyn Widget); + let result = offset.render(to)?; areas.push(result); if let Some([_, _, width, height]) = result { w += width;