mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
wip: gotta remember that only dyn works now
This commit is contained in:
parent
49d2055147
commit
20afc397ea
3 changed files with 20 additions and 56 deletions
|
|
@ -80,7 +80,7 @@ pub trait Content {
|
|||
//()
|
||||
//}
|
||||
//}
|
||||
impl<E: Engine, W> Widget for W where W: Content<Engine = E> {
|
||||
impl<E: Engine, W: Content<Engine = E>> Widget for W {
|
||||
type Engine = E;
|
||||
fn layout (&self, to: E::Area) -> Perhaps<E::Area> {
|
||||
self.content().layout(to)
|
||||
|
|
|
|||
|
|
@ -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<E: Engine>: Render<E> {
|
||||
//fn layout (&self, area: E::Area) -> Perhaps<E::Area>;
|
||||
//}
|
||||
//impl<'a, E: Engine> Layout<E> for Box<dyn Layout<E> + 'a> {
|
||||
//fn layout (&self, area: E::Area) -> Perhaps<E::Area> {
|
||||
//(**self).layout(area)
|
||||
//}
|
||||
//}
|
||||
//impl<'a, E: Engine> Layout<E> for Box<dyn Component<E> + 'a> {
|
||||
//fn layout (&self, area: E::Area) -> Perhaps<E::Area> {
|
||||
//(**self).layout(area)
|
||||
//}
|
||||
//}
|
||||
//impl<E: Engine, T: Layout<E>> Layout<E> for &T {
|
||||
//fn layout (&self, area: E::Area) -> Perhaps<E::Area> {
|
||||
//(*self).layout(area)
|
||||
//}
|
||||
//}
|
||||
//impl<E: Engine, T: Layout<E>> Layout<E> for &mut T {
|
||||
//fn layout (&self, area: E::Area) -> Perhaps<E::Area> {
|
||||
//(**self).layout(area)
|
||||
//}
|
||||
//}
|
||||
//impl<E: Engine, T: Layout<E>> Layout<E> for Option<T> {
|
||||
//fn layout (&self, area: E::Area) -> Perhaps<E::Area> {
|
||||
//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<L> { 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<U: Number, T> { W(U, T), H(U, T), WH(U, U, T), }
|
||||
/// Enforce maximum size of drawing area
|
||||
pub enum Max<U: Number, T> { W(U, T), H(U, T), WH(U, U, T), }
|
||||
/// Expand drawing area
|
||||
pub enum Outset<U: Number, T> { W(U, T), H(U, T), WH(U, U, T), }
|
||||
/// Shrink drawing area
|
||||
pub enum Inset<U: Number, T> { W(U, T), H(U, T), WH(U, U, T), }
|
||||
/// Move origin point of drawing area
|
||||
pub enum Offset<U: Number, T> { X(U, T), Y(U, T), XY(U, U, T), }
|
||||
|
||||
impl<T> Align<T> {
|
||||
pub fn inner (&self) -> &T {
|
||||
|
|
@ -72,6 +19,9 @@ impl<T> Align<T> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Enforce minimum size of drawing area
|
||||
pub enum Min<U: Number, T> { W(U, T), H(U, T), WH(U, U, T), }
|
||||
|
||||
impl<E: Engine, T: Widget<Engine = E>> Widget for Min<E::Unit, T> {
|
||||
type Engine = E;
|
||||
fn layout (&self, area: E::Area) -> Perhaps<E::Area> {
|
||||
|
|
@ -103,6 +53,9 @@ impl<E: Engine, T: Widget<Engine = E>> Widget for Min<E::Unit, T> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Enforce maximum size of drawing area
|
||||
pub enum Max<U: Number, T> { W(U, T), H(U, T), WH(U, U, T), }
|
||||
|
||||
impl<E: Engine, T: Widget<Engine = E>> Widget for Max<E:: Unit, T> {
|
||||
type Engine = E;
|
||||
fn layout (&self, area: E::Area) -> Perhaps<E::Area> {
|
||||
|
|
@ -133,6 +86,9 @@ impl<E: Engine, T: Widget<Engine = E>> Widget for Max<E:: Unit, T> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Expand drawing area
|
||||
pub enum Outset<U: Number, T> { W(U, T), H(U, T), WH(U, U, T), }
|
||||
|
||||
impl<E: Engine, T: Widget<Engine = E>> Widget for Outset<E::Unit, T> {
|
||||
type Engine = E;
|
||||
fn layout (&self, area: E::Area) -> Perhaps<E::Area> {
|
||||
|
|
@ -161,6 +117,9 @@ impl<E: Engine, T: Widget<Engine = E>> Widget for Outset<E::Unit, T> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Shrink drawing area
|
||||
pub enum Inset<U: Number, T> { W(U, T), H(U, T), WH(U, U, T), }
|
||||
|
||||
impl<E: Engine, T: Widget<Engine = E>> Widget for Inset<E::Unit, T> {
|
||||
type Engine = E;
|
||||
fn layout (&self, area: E::Area) -> Perhaps<E::Area> {
|
||||
|
|
@ -189,6 +148,9 @@ impl<E: Engine, T: Widget<Engine = E>> Widget for Inset<E::Unit, T> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Move origin point of drawing area
|
||||
pub enum Offset<U: Number, T: Widget> { X(U, T), Y(U, T), XY(U, U, T), }
|
||||
|
||||
impl<E: Engine, T: Widget<Engine = E>> Widget for Offset<E::Unit, T> {
|
||||
type Engine = E;
|
||||
fn layout (&self, area: E::Area) -> Perhaps<E::Area> {
|
||||
|
|
|
|||
|
|
@ -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<Engine = Tui>);
|
||||
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<Engine = Tui>);
|
||||
let result = offset.render(to)?;
|
||||
areas.push(result);
|
||||
if let Some([_, _, width, height]) = result {
|
||||
w += width;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue