rename Widget to Render and CustomWidget to Widget

This commit is contained in:
🪞👃🪞 2024-12-04 21:24:38 +01:00
parent f018988567
commit bf3c7630a4
20 changed files with 144 additions and 144 deletions

View file

@ -150,7 +150,7 @@ fn query_ports(client: &Client, names: Vec<String>) -> BTreeMap<String, Port<Uno
//} //}
//} //}
//impl<E: Engine> Widget for JackDevice<E> { //impl<E: Engine> Render for JackDevice<E> {
//type Engine = E; //type Engine = E;
//fn min_size(&self, to: E::Size) -> Perhaps<E::Size> { //fn min_size(&self, to: E::Size) -> Perhaps<E::Size> {
//self.state.read().unwrap().layout(to) //self.state.read().unwrap().layout(to)

View file

@ -8,7 +8,7 @@ fn main () -> Usually<()> {
pub struct Demo<E: Engine> { pub struct Demo<E: Engine> {
index: usize, index: usize,
items: Vec<Box<dyn Widget<Engine = E>>> items: Vec<Box<dyn Render<Engine = E>>>
} }
impl Demo<Tui> { impl Demo<Tui> {
@ -35,7 +35,7 @@ impl Demo<Tui> {
impl Content for Demo<Tui> { impl Content for Demo<Tui> {
type Engine = Tui; type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> { fn content (&self) -> impl Render<Engine = Tui> {
let border_style = Style::default().fg(Color::Rgb(0,0,0)); let border_style = Style::default().fg(Color::Rgb(0,0,0));
Align::Center(Layers::new(move|add|{ Align::Center(Layers::new(move|add|{

View file

@ -40,14 +40,14 @@ pub trait Output<E: Engine> {
/// Mutable pointer to area /// Mutable pointer to area
fn area_mut (&mut self) -> &mut E::Area; fn area_mut (&mut self) -> &mut E::Area;
/// Render widget in area /// Render widget in area
fn render_in (&mut self, area: E::Area, widget: &dyn Widget<Engine = E>) -> Usually<()>; fn render_in (&mut self, area: E::Area, widget: &dyn Render<Engine = E>) -> Usually<()>;
} }
/// Cast to dynamic pointer /// Cast to dynamic pointer
pub fn widget <E: Engine, T: Widget<Engine = E>> (w: &T) -> &dyn Widget<Engine = E> { pub fn widget <E: Engine, T: Render<Engine = E>> (w: &T) -> &dyn Render<Engine = E> {
w as &dyn Widget<Engine = E> w as &dyn Render<Engine = E>
} }
/// A renderable component /// A renderable component
pub trait Widget: Send + Sync { pub trait Render: Send + Sync {
/// Engine for which this component is implemented /// Engine for which this component is implemented
type Engine: Engine; type Engine: Engine;
/// Minimum size to use /// Minimum size to use
@ -59,7 +59,7 @@ pub trait Widget: Send + Sync {
/// Draw to output render target /// Draw to output render target
fn render (&self,to: &mut <Self::Engine as Engine>::Output) -> Usually<()>; fn render (&self,to: &mut <Self::Engine as Engine>::Output) -> Usually<()>;
} }
impl<E: Engine> Widget for &dyn Widget<Engine = E> { impl<E: Engine> Render for &dyn Render<Engine = E> {
type Engine = E; type Engine = E;
fn min_size (&self, to: E::Size) -> Perhaps<E::Size> { fn min_size (&self, to: E::Size) -> Perhaps<E::Size> {
(*self).min_size(to) (*self).min_size(to)
@ -68,7 +68,7 @@ impl<E: Engine> Widget for &dyn Widget<Engine = E> {
(*self).render(to) (*self).render(to)
} }
} }
impl<E: Engine> Widget for &mut dyn Widget<Engine = E> { impl<E: Engine> Render for &mut dyn Render<Engine = E> {
type Engine = E; type Engine = E;
fn min_size (&self, to: E::Size) -> Perhaps<E::Size> { fn min_size (&self, to: E::Size) -> Perhaps<E::Size> {
(**self).min_size(to) (**self).min_size(to)
@ -77,7 +77,7 @@ impl<E: Engine> Widget for &mut dyn Widget<Engine = E> {
(**self).render(to) (**self).render(to)
} }
} }
impl<'a, E: Engine> Widget for Box<dyn Widget<Engine = E> + 'a> { impl<'a, E: Engine> Render for Box<dyn Render<Engine = E> + 'a> {
type Engine = E; type Engine = E;
fn min_size (&self, to: E::Size) -> Perhaps<E::Size> { fn min_size (&self, to: E::Size) -> Perhaps<E::Size> {
(**self).min_size(to) (**self).min_size(to)
@ -86,7 +86,7 @@ impl<'a, E: Engine> Widget for Box<dyn Widget<Engine = E> + 'a> {
(**self).render(to) (**self).render(to)
} }
} }
impl<E: Engine, W: Widget<Engine = E>> Widget for Arc<W> { impl<E: Engine, W: Render<Engine = E>> Render for Arc<W> {
type Engine = E; type Engine = E;
fn min_size (&self, to: E::Size) -> Perhaps<E::Size> { fn min_size (&self, to: E::Size) -> Perhaps<E::Size> {
self.as_ref().min_size(to) self.as_ref().min_size(to)
@ -95,7 +95,7 @@ impl<E: Engine, W: Widget<Engine = E>> Widget for Arc<W> {
self.as_ref().render(to) self.as_ref().render(to)
} }
} }
impl<E: Engine, W: Widget<Engine = E>> Widget for Mutex<W> { impl<E: Engine, W: Render<Engine = E>> Render for Mutex<W> {
type Engine = E; type Engine = E;
fn min_size (&self, to: E::Size) -> Perhaps<E::Size> { fn min_size (&self, to: E::Size) -> Perhaps<E::Size> {
self.lock().unwrap().min_size(to) self.lock().unwrap().min_size(to)
@ -104,7 +104,7 @@ impl<E: Engine, W: Widget<Engine = E>> Widget for Mutex<W> {
self.lock().unwrap().render(to) self.lock().unwrap().render(to)
} }
} }
impl<E: Engine, W: Widget<Engine = E>> Widget for RwLock<W> { impl<E: Engine, W: Render<Engine = E>> Render for RwLock<W> {
type Engine = E; type Engine = E;
fn min_size (&self, to: E::Size) -> Perhaps<E::Size> { fn min_size (&self, to: E::Size) -> Perhaps<E::Size> {
self.read().unwrap().min_size(to) self.read().unwrap().min_size(to)
@ -113,7 +113,7 @@ impl<E: Engine, W: Widget<Engine = E>> Widget for RwLock<W> {
self.read().unwrap().render(to) self.read().unwrap().render(to)
} }
} }
impl<E: Engine, W: Widget<Engine = E>> Widget for Option<W> { impl<E: Engine, W: Render<Engine = E>> Render for Option<W> {
type Engine = E; type Engine = E;
fn min_size (&self, to: E::Size) -> Perhaps<E::Size> { fn min_size (&self, to: E::Size) -> Perhaps<E::Size> {
Ok(self.as_ref().map(|widget|widget.min_size(to)).transpose()?.flatten()) Ok(self.as_ref().map(|widget|widget.min_size(to)).transpose()?.flatten())
@ -123,12 +123,12 @@ impl<E: Engine, W: Widget<Engine = E>> Widget for Option<W> {
} }
} }
/// Render either of two widgets depending on predicate /// Render either of two widgets depending on predicate
pub struct Either<E: Engine, A: Widget<Engine = E>, B: Widget<Engine = E>>( pub struct Either<E: Engine, A: Render<Engine = E>, B: Render<Engine = E>>(
pub bool, pub bool,
pub A, pub A,
pub B, pub B,
); );
impl<E: Engine, A: Widget<Engine = E>, B: Widget<Engine = E>> Widget for Either<E, A, B> { impl<E: Engine, A: Render<Engine = E>, B: Render<Engine = E>> Render for Either<E, A, B> {
type Engine = E; type Engine = E;
fn min_size (&self, to: E::Size) -> Perhaps<E::Size> { fn min_size (&self, to: E::Size) -> Perhaps<E::Size> {
if self.0 { self.1.min_size(to) } else { self.2.min_size(to) } if self.0 { self.1.min_size(to) } else { self.2.min_size(to) }
@ -137,8 +137,8 @@ impl<E: Engine, A: Widget<Engine = E>, B: Widget<Engine = E>> Widget for Either<
if self.0 { self.1.render(to) } else { self.2.render(to) } if self.0 { self.1.render(to) } else { self.2.render(to) }
} }
} }
/// A custom [Widget] defined by passing layout and render closures in place. /// A custom [Render] defined by passing layout and render closures in place.
pub struct CustomWidget< pub struct Widget<
E: Engine, E: Engine,
L: Send + Sync + Fn(E::Size)->Perhaps<E::Size>, L: Send + Sync + Fn(E::Size)->Perhaps<E::Size>,
R: Send + Sync + Fn(&mut E::Output)->Usually<()> R: Send + Sync + Fn(&mut E::Output)->Usually<()>
@ -147,7 +147,7 @@ impl<
E: Engine, E: Engine,
L: Send + Sync + Fn(E::Size)->Perhaps<E::Size>, L: Send + Sync + Fn(E::Size)->Perhaps<E::Size>,
R: Send + Sync + Fn(&mut E::Output)->Usually<()> R: Send + Sync + Fn(&mut E::Output)->Usually<()>
> CustomWidget<E, L, R> { > Widget<E, L, R> {
pub fn new (layout: L, render: R) -> Self { pub fn new (layout: L, render: R) -> Self {
Self(layout, render, Default::default()) Self(layout, render, Default::default())
} }
@ -156,7 +156,7 @@ impl<
E: Engine, E: Engine,
L: Send + Sync + Fn(E::Size)->Perhaps<E::Size>, L: Send + Sync + Fn(E::Size)->Perhaps<E::Size>,
R: Send + Sync + Fn(&mut E::Output)->Usually<()> R: Send + Sync + Fn(&mut E::Output)->Usually<()>
> Widget for CustomWidget<E, L, R> { > Render for Widget<E, L, R> {
type Engine = E; type Engine = E;
fn min_size (&self, to: E::Size) -> Perhaps<E::Size> { fn min_size (&self, to: E::Size) -> Perhaps<E::Size> {
self.0(to) self.0(to)
@ -165,13 +165,13 @@ impl<
self.1(to) self.1(to)
} }
} }
/// A [Widget] that contains other [Widget]s /// A [Render] that contains other [Render]s
pub trait Content: Send + Sync { pub trait Content: Send + Sync {
type Engine: Engine; type Engine: Engine;
fn content (&self) -> impl Widget<Engine = <Self as Content>::Engine>; fn content (&self) -> impl Render<Engine = <Self as Content>::Engine>;
} }
/// Every struct that has [Content] is a renderable [Widget]. /// Every struct that has [Content] is a renderable [Render].
impl<E: Engine, W: Content<Engine = E>> Widget for W { impl<E: Engine, W: Content<Engine = E>> Render for W {
type Engine = E; type Engine = E;
fn min_size (&self, to: E::Size) -> Perhaps<E::Size> { fn min_size (&self, to: E::Size) -> Perhaps<E::Size> {
self.content().min_size(to) self.content().min_size(to)
@ -221,12 +221,12 @@ impl<H, E: Engine> Handle<E> for Arc<RwLock<H>> where H: Handle<E> {
self.write().unwrap().handle(context) self.write().unwrap().handle(context)
} }
} }
/// A UI component that can render itself as a [Widget], and [Handle] input. /// A UI component that can render itself as a [Render], and [Handle] input.
pub trait Component<E: Engine>: Widget<Engine = E> + Handle<E> {} pub trait Component<E: Engine>: Render<Engine = E> + Handle<E> {}
/// Everything that implements [Widget] and [Handle] is a [Component]. /// Everything that implements [Render] and [Handle] is a [Component].
impl<E: Engine, C: Widget<Engine = E> + Handle<E>> Component<E> for C {} impl<E: Engine, C: Render<Engine = E> + Handle<E>> Component<E> for C {}
/// A UI component that has [Content] and can [Handle] input. /// A UI component that has [Content] and can [Handle] input.
pub trait ContentComponent<E: Engine>: Widget<Engine = E> + Handle<E> {} pub trait ContentComponent<E: Engine>: Render<Engine = E> + Handle<E> {}
/// Everything that implements [Content] and [Handle] is a [Component]. /// Everything that implements [Content] and [Handle] is a [Component].
impl<E: Engine, C: Content<Engine = E> + Handle<E>> ContentComponent<E> for C {} impl<E: Engine, C: Content<Engine = E> + Handle<E>> ContentComponent<E> for C {}
/// A component that can exit. /// A component that can exit.

View file

@ -126,7 +126,7 @@ impl<N: Coordinate> Area<N> for [N;4] {
#[inline] fn h (&self) -> N { self[3] } #[inline] fn h (&self) -> N { self[3] }
} }
pub trait Layout<E: Engine>: Widget<Engine = E> + Sized { pub trait Layout<E: Engine>: Render<Engine = E> + Sized {
fn align_center (self) -> Align<Self> { Align::Center(self) } fn align_center (self) -> Align<Self> { Align::Center(self) }
fn align_n (self) -> Align<Self> { Align::N(self) } fn align_n (self) -> Align<Self> { Align::N(self) }
fn align_s (self) -> Align<Self> { Align::S(self) } fn align_s (self) -> Align<Self> { Align::S(self) }
@ -169,21 +169,21 @@ pub trait Layout<E: Engine>: Widget<Engine = E> + Sized {
fn fill_y (self) -> Fill<E, Self> { Fill::Y(self) } fn fill_y (self) -> Fill<E, Self> { Fill::Y(self) }
fn fill_xy (self) -> Fill<E, Self> { Fill::XY(self) } fn fill_xy (self) -> Fill<E, Self> { Fill::XY(self) }
fn debug (self) -> DebugOverlay<E, Self> { DebugOverlay(self) } fn debug (self) -> DebugOverlay<E, Self> { DebugOverlay(self) }
fn split <W: Widget<Engine = E>> ( fn split <W: Render<Engine = E>> (
self, direction: Direction, amount: E::Unit, other: W self, direction: Direction, amount: E::Unit, other: W
) -> Split<E, Self, W> { Split::new(direction, amount, self, other) } ) -> Split<E, Self, W> { Split::new(direction, amount, self, other) }
fn split_flip <W: Widget<Engine = E>> ( fn split_flip <W: Render<Engine = E>> (
self, direction: Direction, amount: E::Unit, other: W self, direction: Direction, amount: E::Unit, other: W
) -> Split<E, W, Self> { Split::new(direction, amount, other, self) } ) -> Split<E, W, Self> { Split::new(direction, amount, other, self) }
} }
impl<E: Engine, W: Widget<Engine = E>> Layout<E> for W {} impl<E: Engine, W: Render<Engine = E>> Layout<E> for W {}
pub struct DebugOverlay<E: Engine, W: Widget<Engine = E>>(pub W); pub struct DebugOverlay<E: Engine, W: Render<Engine = E>>(pub W);
pub enum Fill<E: Engine, W: Widget<Engine = E>> { X(W), Y(W), XY(W) } pub enum Fill<E: Engine, W: Render<Engine = E>> { X(W), Y(W), XY(W) }
impl<E: Engine, W: Widget<Engine = E>> Fill<E, W> { impl<E: Engine, W: Render<Engine = E>> Fill<E, W> {
fn inner (&self) -> &W { fn inner (&self) -> &W {
match self { match self {
Self::X(inner) => &inner, Self::X(inner) => &inner,
@ -193,7 +193,7 @@ impl<E: Engine, W: Widget<Engine = E>> Fill<E, W> {
} }
} }
impl<E: Engine, W: Widget<Engine = E>> Widget for Fill<E, W> { impl<E: Engine, W: Render<Engine = E>> Render for Fill<E, W> {
type Engine = E; type Engine = E;
fn min_size (&self, to: E::Size) -> Perhaps<E::Size> { fn min_size (&self, to: E::Size) -> Perhaps<E::Size> {
let area = self.inner().min_size(to.into())?; let area = self.inner().min_size(to.into())?;
@ -214,12 +214,12 @@ impl<E: Engine, W: Widget<Engine = E>> Widget for Fill<E, W> {
pub struct Layers< pub struct Layers<
E: Engine, E: Engine,
F: Send + Sync + Fn(&mut dyn FnMut(&dyn Widget<Engine = E>)->Usually<()>)->Usually<()> F: Send + Sync + Fn(&mut dyn FnMut(&dyn Render<Engine = E>)->Usually<()>)->Usually<()>
>(pub F, PhantomData<E>); >(pub F, PhantomData<E>);
impl< impl<
E: Engine, E: Engine,
F: Send + Sync + Fn(&mut dyn FnMut(&dyn Widget<Engine = E>)->Usually<()>)->Usually<()> F: Send + Sync + Fn(&mut dyn FnMut(&dyn Render<Engine = E>)->Usually<()>)->Usually<()>
> Layers<E, F> { > Layers<E, F> {
#[inline] #[inline]
pub fn new (build: F) -> Self { pub fn new (build: F) -> Self {
@ -227,9 +227,9 @@ impl<
} }
} }
impl<E: Engine, F> Widget for Layers<E, F> impl<E: Engine, F> Render for Layers<E, F>
where where
F: Send + Sync + Fn(&mut dyn FnMut(&dyn Widget<Engine = E>)->Usually<()>)->Usually<()> F: Send + Sync + Fn(&mut dyn FnMut(&dyn Render<Engine = E>)->Usually<()>)->Usually<()>
{ {
type Engine = E; type Engine = E;
fn min_size (&self, area: E::Size) -> Perhaps<E::Size> { fn min_size (&self, area: E::Size) -> Perhaps<E::Size> {
@ -346,7 +346,7 @@ fn align<T, N: Coordinate, R: Area<N> + From<[N;4]>> (align: &Align<T>, outer: R
} }
} }
impl<E: Engine, T: Widget<Engine = E>> Widget for Align<T> { impl<E: Engine, T: Render<Engine = E>> Render for Align<T> {
type Engine = E; type Engine = E;
fn min_size (&self, outer_area: E::Size) -> Perhaps<E::Size> { fn min_size (&self, outer_area: E::Size) -> Perhaps<E::Size> {
self.inner().min_size(outer_area) self.inner().min_size(outer_area)
@ -380,7 +380,7 @@ impl<N: Coordinate, T> Fixed<N, T> {
match self { Self::X(_, i) => i, Self::Y(_, i) => i, Self::XY(_, _, i) => i, } match self { Self::X(_, i) => i, Self::Y(_, i) => i, Self::XY(_, _, i) => i, }
} }
} }
impl<E: Engine, T: Widget<Engine = E>> Widget for Fixed<E::Unit, T> { impl<E: Engine, T: Render<Engine = E>> Render for Fixed<E::Unit, T> {
type Engine = E; type Engine = E;
fn min_size (&self, to: E::Size) -> Perhaps<E::Size> { fn min_size (&self, to: E::Size) -> Perhaps<E::Size> {
Ok(match self { Ok(match self {
@ -416,7 +416,7 @@ impl<N: Coordinate, T> Min<N, T> {
match self { Self::X(_, i) => i, Self::Y(_, i) => i, Self::XY(_, _, i) => i, } match self { Self::X(_, i) => i, Self::Y(_, i) => i, Self::XY(_, _, i) => i, }
} }
} }
impl<E: Engine, T: Widget<Engine = E>> Widget for Min<E::Unit, T> { impl<E: Engine, T: Render<Engine = E>> Render for Min<E::Unit, T> {
type Engine = E; type Engine = E;
fn min_size (&self, to: E::Size) -> Perhaps<E::Size> { fn min_size (&self, to: E::Size) -> Perhaps<E::Size> {
Ok(self.inner().min_size(to)?.map(|to|match *self { Ok(self.inner().min_size(to)?.map(|to|match *self {
@ -449,7 +449,7 @@ impl<N: Coordinate, T> Max<N, T> {
} }
} }
impl<E: Engine, T: Widget<Engine = E>> Widget for Max<E:: Unit, T> { impl<E: Engine, T: Render<Engine = E>> Render for Max<E:: Unit, T> {
type Engine = E; type Engine = E;
fn min_size (&self, to: E::Size) -> Perhaps<E::Size> { fn min_size (&self, to: E::Size) -> Perhaps<E::Size> {
Ok(self.inner().min_size(to)?.map(|to|match *self { Ok(self.inner().min_size(to)?.map(|to|match *self {
@ -481,7 +481,7 @@ impl<N: Coordinate, T> Grow<N, T> {
} }
} }
impl<E: Engine, T: Widget<Engine = E>> Widget for Grow<E::Unit, T> { impl<E: Engine, T: Render<Engine = E>> Render for Grow<E::Unit, T> {
type Engine = E; type Engine = E;
fn min_size (&self, to: E::Size) -> Perhaps<E::Size> { fn min_size (&self, to: E::Size) -> Perhaps<E::Size> {
Ok(self.inner().min_size(to)?.map(|to|match *self { Ok(self.inner().min_size(to)?.map(|to|match *self {
@ -507,13 +507,13 @@ pub enum Shrink<N: Coordinate, T> {
XY(N, N, T), XY(N, N, T),
} }
impl<N: Coordinate, T: Widget> Shrink<N, T> { impl<N: Coordinate, T: Render> Shrink<N, T> {
fn inner (&self) -> &T { fn inner (&self) -> &T {
match self { Self::X(_, i) => i, Self::Y(_, i) => i, Self::XY(_, _, i) => i, } match self { Self::X(_, i) => i, Self::Y(_, i) => i, Self::XY(_, _, i) => i, }
} }
} }
impl<E: Engine, T: Widget<Engine = E>> Widget for Shrink<E::Unit, T> { impl<E: Engine, T: Render<Engine = E>> Render for Shrink<E::Unit, T> {
type Engine = E; type Engine = E;
fn min_size (&self, to: E::Size) -> Perhaps<E::Size> { fn min_size (&self, to: E::Size) -> Perhaps<E::Size> {
Ok(self.inner().min_size(to)?.map(|to|match *self { Ok(self.inner().min_size(to)?.map(|to|match *self {
@ -548,7 +548,7 @@ pub enum Inset<N: Coordinate, T> {
XY(N, N, T), XY(N, N, T),
} }
impl<N: Coordinate, T: Widget> Inset<N, T> { impl<N: Coordinate, T: Render> Inset<N, T> {
pub fn inner (&self) -> &T { pub fn inner (&self) -> &T {
match self { Self::X(_, i) => i, Self::Y(_, i) => i, Self::XY(_, _, i) => i, } match self { Self::X(_, i) => i, Self::Y(_, i) => i, Self::XY(_, _, i) => i, }
} }
@ -564,52 +564,52 @@ pub enum Outset<N: Coordinate, T> {
XY(N, N, T), XY(N, N, T),
} }
impl<N: Coordinate, T: Widget> Outset<N, T> { impl<N: Coordinate, T: Render> Outset<N, T> {
pub fn inner (&self) -> &T { pub fn inner (&self) -> &T {
match self { Self::X(_, i) => i, Self::Y(_, i) => i, Self::XY(_, _, i) => i, } match self { Self::X(_, i) => i, Self::Y(_, i) => i, Self::XY(_, _, i) => i, }
} }
} }
impl<E: Engine, T: Widget<Engine = E>> Widget for Inset<E::Unit, T> { impl<E: Engine, T: Render<Engine = E>> Render for Inset<E::Unit, T> {
type Engine = E; type Engine = E;
fn render (&self, to: &mut E::Output) -> Usually<()> { fn render (&self, to: &mut E::Output) -> Usually<()> {
match *self { match *self {
Self::X(x, ref inner) => Self::X(x, ref inner) =>
(inner as &dyn Widget<Engine = E>).shrink_x(x).push_x(x), (inner as &dyn Render<Engine = E>).shrink_x(x).push_x(x),
Self::Y(y, ref inner) => Self::Y(y, ref inner) =>
(inner as &dyn Widget<Engine = E>).shrink_y(y).push_y(y), (inner as &dyn Render<Engine = E>).shrink_y(y).push_y(y),
Self::XY(x, y, ref inner) => Self::XY(x, y, ref inner) =>
(inner as &dyn Widget<Engine = E>).shrink_xy(x, y).push_xy(x, y) (inner as &dyn Render<Engine = E>).shrink_xy(x, y).push_xy(x, y)
}.render(to) }.render(to)
} }
} }
impl<E: Engine, T: Widget<Engine = E>> Widget for Outset<E::Unit, T> { impl<E: Engine, T: Render<Engine = E>> Render for Outset<E::Unit, T> {
type Engine = E; type Engine = E;
fn min_size (&self, to: E::Size) -> Perhaps<E::Size> { fn min_size (&self, to: E::Size) -> Perhaps<E::Size> {
match *self { match *self {
Self::X(x, ref inner) => Self::X(x, ref inner) =>
(inner as &dyn Widget<Engine = E>).grow_x(x + x), (inner as &dyn Render<Engine = E>).grow_x(x + x),
Self::Y(y, ref inner) => Self::Y(y, ref inner) =>
(inner as &dyn Widget<Engine = E>).grow_y(y + y), (inner as &dyn Render<Engine = E>).grow_y(y + y),
Self::XY(x, y, ref inner) => Self::XY(x, y, ref inner) =>
(inner as &dyn Widget<Engine = E>).grow_xy(x + x, y + y), (inner as &dyn Render<Engine = E>).grow_xy(x + x, y + y),
}.min_size(to) }.min_size(to)
} }
fn render (&self, to: &mut E::Output) -> Usually<()> { fn render (&self, to: &mut E::Output) -> Usually<()> {
match *self { match *self {
Self::X(x, ref inner) => Self::X(x, ref inner) =>
(inner as &dyn Widget<Engine = E>).push_x(x), (inner as &dyn Render<Engine = E>).push_x(x),
Self::Y(y, ref inner) => Self::Y(y, ref inner) =>
(inner as &dyn Widget<Engine = E>).push_y(y), (inner as &dyn Render<Engine = E>).push_y(y),
Self::XY(x, y, ref inner) => Self::XY(x, y, ref inner) =>
(inner as &dyn Widget<Engine = E>).push_xy(x, y), (inner as &dyn Render<Engine = E>).push_xy(x, y),
}.render(to) }.render(to)
} }
} }
/// Move origin point of drawing area /// Move origin point of drawing area
pub enum Push<N: Coordinate, T: Widget> { pub enum Push<N: Coordinate, T: Render> {
/// Move origin to the right /// Move origin to the right
X(N, T), X(N, T),
/// Move origin downwards /// Move origin downwards
@ -618,7 +618,7 @@ pub enum Push<N: Coordinate, T: Widget> {
XY(N, N, T), XY(N, N, T),
} }
impl<N: Coordinate, T: Widget> Push<N, T> { impl<N: Coordinate, T: Render> Push<N, T> {
pub fn inner (&self) -> &T { pub fn inner (&self) -> &T {
match self { Self::X(_, i) => i, Self::Y(_, i) => i, Self::XY(_, _, i) => i, } match self { Self::X(_, i) => i, Self::Y(_, i) => i, Self::XY(_, _, i) => i, }
} }
@ -630,7 +630,7 @@ impl<N: Coordinate, T: Widget> Push<N, T> {
} }
} }
impl<E: Engine, T: Widget<Engine = E>> Widget for Push<E::Unit, T> { impl<E: Engine, T: Render<Engine = E>> Render for Push<E::Unit, T> {
type Engine = E; type Engine = E;
fn min_size (&self, to: E::Size) -> Perhaps<E::Size> { fn min_size (&self, to: E::Size) -> Perhaps<E::Size> {
self.inner().min_size(to) self.inner().min_size(to)
@ -647,7 +647,7 @@ impl<E: Engine, T: Widget<Engine = E>> Widget for Push<E::Unit, T> {
} }
/// Move origin point of drawing area /// Move origin point of drawing area
pub enum Pull<N: Coordinate, T: Widget> { pub enum Pull<N: Coordinate, T: Render> {
/// Move origin to the right /// Move origin to the right
X(N, T), X(N, T),
/// Move origin downwards /// Move origin downwards
@ -656,7 +656,7 @@ pub enum Pull<N: Coordinate, T: Widget> {
XY(N, N, T), XY(N, N, T),
} }
impl<N: Coordinate, T: Widget> Pull<N, T> { impl<N: Coordinate, T: Render> Pull<N, T> {
pub fn inner (&self) -> &T { pub fn inner (&self) -> &T {
match self { Self::X(_, i) => i, Self::Y(_, i) => i, Self::XY(_, _, i) => i, } match self { Self::X(_, i) => i, Self::Y(_, i) => i, Self::XY(_, _, i) => i, }
} }
@ -668,7 +668,7 @@ impl<N: Coordinate, T: Widget> Pull<N, T> {
} }
} }
impl<E: Engine, T: Widget<Engine = E>> Widget for Pull<E::Unit, T> { impl<E: Engine, T: Render<Engine = E>> Render for Pull<E::Unit, T> {
type Engine = E; type Engine = E;
fn min_size (&self, to: E::Size) -> Perhaps<E::Size> { fn min_size (&self, to: E::Size) -> Perhaps<E::Size> {
self.inner().min_size(to) self.inner().min_size(to)
@ -686,12 +686,12 @@ impl<E: Engine, T: Widget<Engine = E>> Widget for Pull<E::Unit, T> {
pub struct Stack< pub struct Stack<
E: Engine, E: Engine,
F: Send + Sync + Fn(&mut dyn FnMut(&dyn Widget<Engine = E>)->Usually<()>)->Usually<()> F: Send + Sync + Fn(&mut dyn FnMut(&dyn Render<Engine = E>)->Usually<()>)->Usually<()>
>(pub F, pub Direction, PhantomData<E>); >(pub F, pub Direction, PhantomData<E>);
impl< impl<
E: Engine, E: Engine,
F: Send + Sync + Fn(&mut dyn FnMut(&dyn Widget<Engine = E>)->Usually<()>)->Usually<()> F: Send + Sync + Fn(&mut dyn FnMut(&dyn Render<Engine = E>)->Usually<()>)->Usually<()>
> Stack<E, F> { > Stack<E, F> {
#[inline] pub fn new (direction: Direction, build: F) -> Self { #[inline] pub fn new (direction: Direction, build: F) -> Self {
Self(build, direction, Default::default()) Self(build, direction, Default::default())
@ -704,9 +704,9 @@ impl<
} }
} }
impl<E: Engine, F> Widget for Stack<E, F> impl<E: Engine, F> Render for Stack<E, F>
where where
F: Send + Sync + Fn(&mut dyn FnMut(&dyn Widget<Engine = E>)->Usually<()>)->Usually<()> F: Send + Sync + Fn(&mut dyn FnMut(&dyn Render<Engine = E>)->Usually<()>)->Usually<()>
{ {
type Engine = E; type Engine = E;
fn min_size (&self, to: E::Size) -> Perhaps<E::Size> { fn min_size (&self, to: E::Size) -> Perhaps<E::Size> {
@ -808,11 +808,11 @@ where
} }
/// A binary split with fixed proportion /// A binary split with fixed proportion
pub struct Split<E: Engine, A: Widget<Engine = E>, B: Widget<Engine = E>>( pub struct Split<E: Engine, A: Render<Engine = E>, B: Render<Engine = E>>(
pub Direction, pub E::Unit, A, B, PhantomData<E> pub Direction, pub E::Unit, A, B, PhantomData<E>
); );
impl<E: Engine, A: Widget<Engine = E>, B: Widget<Engine = E>> Split<E, A, B> { impl<E: Engine, A: Render<Engine = E>, B: Render<Engine = E>> Split<E, A, B> {
pub fn new (direction: Direction, proportion: E::Unit, a: A, b: B) -> Self { pub fn new (direction: Direction, proportion: E::Unit, a: A, b: B) -> Self {
Self(direction, proportion, a, b, Default::default()) Self(direction, proportion, a, b, Default::default())
} }
@ -830,7 +830,7 @@ impl<E: Engine, A: Widget<Engine = E>, B: Widget<Engine = E>> Split<E, A, B> {
} }
} }
impl<E: Engine, A: Widget<Engine = E>, B: Widget<Engine = E>> Widget for Split<E, A, B> { impl<E: Engine, A: Render<Engine = E>, B: Render<Engine = E>> Render for Split<E, A, B> {
type Engine = E; type Engine = E;
fn min_size (&self, to: E::Size) -> Perhaps<E::Size> { fn min_size (&self, to: E::Size) -> Perhaps<E::Size> {
Ok(Some(to)) Ok(Some(to))
@ -876,7 +876,7 @@ impl<E: Engine> Measure<E> {
pub fn format (&self) -> String { format!("{}x{}", self.w(), self.h()) } pub fn format (&self) -> String { format!("{}x{}", self.w(), self.h()) }
} }
impl<E: Engine> Widget for Measure<E> { impl<E: Engine> Render for Measure<E> {
type Engine = E; type Engine = E;
fn min_size (&self, _: E::Size) -> Perhaps<E::Size> { fn min_size (&self, _: E::Size) -> Perhaps<E::Size> {
Ok(Some([0u16.into(), 0u16.into()].into())) Ok(Some([0u16.into(), 0u16.into()].into()))
@ -891,5 +891,5 @@ impl<E: Engine> Widget for Measure<E> {
/// A scrollable area. /// A scrollable area.
pub struct Scroll< pub struct Scroll<
E: Engine, E: Engine,
F: Send + Sync + Fn(&mut dyn FnMut(&dyn Widget<Engine = E>)->Usually<()>)->Usually<()> F: Send + Sync + Fn(&mut dyn FnMut(&dyn Render<Engine = E>)->Usually<()>)->Usually<()>
>(pub F, pub Direction, pub u64, PhantomData<E>); >(pub F, pub Direction, pub u64, PhantomData<E>);

View file

@ -22,7 +22,7 @@ impl Engine for TestEngine {
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
struct TestArea(u16, u16); struct TestArea(u16, u16);
impl Widget for TestArea { impl Render for TestArea {
type Engine = TestEngine; type Engine = TestEngine;
fn min_size (&self, to: [u16;2]) -> Perhaps<[u16;2]> { fn min_size (&self, to: [u16;2]) -> Perhaps<[u16;2]> {
Ok(Some([to[0], to[1], self.0, self.1])) Ok(Some([to[0], to[1], self.0, self.1]))

View file

@ -165,7 +165,7 @@ impl Output<Tui> for TuiOutput {
#[inline] fn area_mut (&mut self) -> &mut [u16;4] { &mut self.area } #[inline] fn area_mut (&mut self) -> &mut [u16;4] { &mut self.area }
#[inline] fn render_in (&mut self, #[inline] fn render_in (&mut self,
area: [u16;4], area: [u16;4],
widget: &dyn Widget<Engine = Tui> widget: &dyn Render<Engine = Tui>
) -> Usually<()> { ) -> Usually<()> {
let last = self.area(); let last = self.area();
*self.area_mut() = area; *self.area_mut() = area;
@ -287,7 +287,7 @@ pub fn buffer_update (buf: &mut Buffer, area: [u16;4], callback: &impl Fn(&mut C
} }
} }
} }
impl Widget for &str { impl Render for &str {
type Engine = Tui; type Engine = Tui;
fn min_size (&self, _: [u16;2]) -> Perhaps<[u16;2]> { fn min_size (&self, _: [u16;2]) -> Perhaps<[u16;2]> {
// TODO: line breaks // TODO: line breaks
@ -299,7 +299,7 @@ impl Widget for &str {
Ok(to.blit(&self, x, y, None)) Ok(to.blit(&self, x, y, None))
} }
} }
impl Widget for String { impl Render for String {
type Engine = Tui; type Engine = Tui;
fn min_size (&self, _: [u16;2]) -> Perhaps<[u16;2]> { fn min_size (&self, _: [u16;2]) -> Perhaps<[u16;2]> {
// TODO: line breaks // TODO: line breaks
@ -311,7 +311,7 @@ impl Widget for String {
Ok(to.blit(&self, x, y, None)) Ok(to.blit(&self, x, y, None))
} }
} }
impl<T: Widget<Engine = Tui>> Widget for DebugOverlay<Tui, T> { impl<T: Render<Engine = Tui>> Render for DebugOverlay<Tui, T> {
type Engine = Tui; type Engine = Tui;
fn min_size (&self, to: [u16;2]) -> Perhaps<[u16;2]> { fn min_size (&self, to: [u16;2]) -> Perhaps<[u16;2]> {
self.0.min_size(to) self.0.min_size(to)
@ -322,8 +322,8 @@ impl<T: Widget<Engine = Tui>> Widget for DebugOverlay<Tui, T> {
Ok(to.blit(&format!("{w}x{h}+{x}+{y}"), x, y, Some(Style::default().green()))) Ok(to.blit(&format!("{w}x{h}+{x}+{y}"), x, y, Some(Style::default().green())))
} }
} }
pub struct Styled<T: Widget<Engine = Tui>>(pub Option<Style>, pub T); pub struct Styled<T: Render<Engine = Tui>>(pub Option<Style>, pub T);
impl Widget for Styled<&str> { impl Render for Styled<&str> {
type Engine = Tui; type Engine = Tui;
fn min_size (&self, _: [u16;2]) -> Perhaps<[u16;2]> { fn min_size (&self, _: [u16;2]) -> Perhaps<[u16;2]> {
Ok(Some([self.1.chars().count() as u16, 1])) Ok(Some([self.1.chars().count() as u16, 1]))
@ -335,41 +335,41 @@ impl Widget for Styled<&str> {
Ok(to.blit(&self.1, x, y, None)) Ok(to.blit(&self.1, x, y, None))
} }
} }
pub trait TuiStyle: Widget<Engine = Tui> + Sized { pub trait TuiStyle: Render<Engine = Tui> + Sized {
fn fg (self, color: Color) -> impl Widget<Engine = Tui> { fn fg (self, color: Color) -> impl Render<Engine = Tui> {
Layers::new(move |add|{ add(&Foreground(color))?; add(&self) }) Layers::new(move |add|{ add(&Foreground(color))?; add(&self) })
} }
fn bg (self, color: Color) -> impl Widget<Engine = Tui> { fn bg (self, color: Color) -> impl Render<Engine = Tui> {
Layers::new(move |add|{ add(&Background(color))?; add(&self) }) Layers::new(move |add|{ add(&Background(color))?; add(&self) })
} }
fn bold (self, on: bool) -> impl Widget<Engine = Tui> { fn bold (self, on: bool) -> impl Render<Engine = Tui> {
Layers::new(move |add|{ add(&Bold(on))?; add(&self) }) Layers::new(move |add|{ add(&Bold(on))?; add(&self) })
} }
fn border (self, style: impl BorderStyle) -> impl Widget<Engine = Tui> { fn border (self, style: impl BorderStyle) -> impl Render<Engine = Tui> {
Bordered(style, self) Bordered(style, self)
} }
} }
impl<W: Widget<Engine = Tui>> TuiStyle for W {} impl<W: Render<Engine = Tui>> TuiStyle for W {}
pub struct Bold(pub bool); pub struct Bold(pub bool);
impl Widget for Bold { impl Render for Bold {
type Engine = Tui; type Engine = Tui;
fn min_size (&self, _: [u16;2]) -> Perhaps<[u16;2]> { Ok(Some([0,0])) } fn min_size (&self, _: [u16;2]) -> Perhaps<[u16;2]> { Ok(Some([0,0])) }
fn render (&self, to: &mut TuiOutput) -> Usually<()> { Ok(to.fill_bold(to.area(), self.0)) } fn render (&self, to: &mut TuiOutput) -> Usually<()> { Ok(to.fill_bold(to.area(), self.0)) }
} }
pub struct Foreground(pub Color); pub struct Foreground(pub Color);
impl Widget for Foreground { impl Render for Foreground {
type Engine = Tui; type Engine = Tui;
fn min_size (&self, _: [u16;2]) -> Perhaps<[u16;2]> { Ok(Some([0,0])) } fn min_size (&self, _: [u16;2]) -> Perhaps<[u16;2]> { Ok(Some([0,0])) }
fn render (&self, to: &mut TuiOutput) -> Usually<()> { Ok(to.fill_fg(to.area(), self.0)) } fn render (&self, to: &mut TuiOutput) -> Usually<()> { Ok(to.fill_fg(to.area(), self.0)) }
} }
pub struct Background(pub Color); pub struct Background(pub Color);
impl Widget for Background { impl Render for Background {
type Engine = Tui; type Engine = Tui;
fn min_size (&self, _: [u16;2]) -> Perhaps<[u16;2]> { Ok(Some([0,0])) } fn min_size (&self, _: [u16;2]) -> Perhaps<[u16;2]> { Ok(Some([0,0])) }
fn render (&self, to: &mut TuiOutput) -> Usually<()> { Ok(to.fill_bg(to.area(), self.0)) } fn render (&self, to: &mut TuiOutput) -> Usually<()> { Ok(to.fill_bg(to.area(), self.0)) }
} }
pub struct Border<S: BorderStyle>(pub S); pub struct Border<S: BorderStyle>(pub S);
impl<S: BorderStyle> Widget for Border<S> { impl<S: BorderStyle> Render for Border<S> {
type Engine = Tui; type Engine = Tui;
fn min_size (&self, _: [u16;2]) -> Perhaps<[u16;2]> { fn min_size (&self, _: [u16;2]) -> Perhaps<[u16;2]> {
Ok(Some([0, 0])) Ok(Some([0, 0]))
@ -393,11 +393,11 @@ impl<S: BorderStyle> Widget for Border<S> {
Ok(()) Ok(())
} }
} }
pub struct Bordered<S: BorderStyle, W: Widget<Engine = Tui>>(pub S, pub W); pub struct Bordered<S: BorderStyle, W: Render<Engine = Tui>>(pub S, pub W);
impl<S: BorderStyle, W: Widget<Engine = Tui>> Content for Bordered<S, W> { impl<S: BorderStyle, W: Render<Engine = Tui>> Content for Bordered<S, W> {
type Engine = Tui; type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> { fn content (&self) -> impl Render<Engine = Tui> {
let content: &dyn Widget<Engine = Tui> = &self.1; let content: &dyn Render<Engine = Tui> = &self.1;
lay! { content.inset_xy(1, 1), Border(self.0) }.fill_xy() lay! { content.inset_xy(1, 1), Border(self.0) }.fill_xy()
} }
} }
@ -497,7 +497,7 @@ macro_rules! border {
} }
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct $T(pub Style); pub struct $T(pub Style);
impl Widget for $T { impl Render for $T {
type Engine = Tui; type Engine = Tui;
fn min_size (&self, _: [u16;2]) -> Perhaps<[u16;2]> { Ok(Some([0,0])) } fn min_size (&self, _: [u16;2]) -> Perhaps<[u16;2]> { Ok(Some([0,0])) }
fn render (&self, to: &mut TuiOutput) -> Usually<()> { self.draw(to) } fn render (&self, to: &mut TuiOutput) -> Usually<()> { self.draw(to) }

View file

@ -75,8 +75,8 @@ impl TuiTheme {
} }
pub trait FocusWrap<T> { pub trait FocusWrap<T> {
fn wrap <'a, W: Widget<Engine = Tui>> (self, focus: T, content: &'a W) fn wrap <'a, W: Render<Engine = Tui>> (self, focus: T, content: &'a W)
-> impl Widget<Engine = Tui> + 'a; -> impl Render<Engine = Tui> + 'a;
} }
pub fn to_focus_command (input: &TuiInput) -> Option<FocusCommand> { pub fn to_focus_command (input: &TuiInput) -> Option<FocusCommand> {
@ -139,12 +139,12 @@ pub fn to_focus_command (input: &TuiInput) -> Option<FocusCommand> {
} }
} }
pub trait StatusBar: Widget<Engine = Tui> { pub trait StatusBar: Render<Engine = Tui> {
type State; type State;
fn hotkey_fg () -> Color where Self: Sized; fn hotkey_fg () -> Color where Self: Sized;
fn update (&mut self, state: &Self::State) where Self: Sized; fn update (&mut self, state: &Self::State) where Self: Sized;
fn command (commands: &[[impl Widget<Engine = Tui>;3]]) fn command (commands: &[[impl Render<Engine = Tui>;3]])
-> impl Widget<Engine = Tui> + '_ -> impl Render<Engine = Tui> + '_
where where
Self: Sized Self: Sized
{ {
@ -161,7 +161,7 @@ pub trait StatusBar: Widget<Engine = Tui> {
}) })
} }
fn with <'a> (state: &'a Self::State, content: impl Widget<Engine=Tui>) -> impl Widget<Engine=Tui> fn with <'a> (state: &'a Self::State, content: impl Render<Engine=Tui>) -> impl Render<Engine=Tui>
where Self: Sized, &'a Self::State: Into<Self> where Self: Sized, &'a Self::State: Into<Self>
{ {
Split::up(1, state.into(), content) Split::up(1, state.into(), content)
@ -172,9 +172,9 @@ fn content_with_menu_and_status <'a, A, S, C> (
content: &'a A, content: &'a A,
menu_bar: &'a Option<MenuBar<Tui, S, C>>, menu_bar: &'a Option<MenuBar<Tui, S, C>>,
status_bar: &'a Option<impl StatusBar> status_bar: &'a Option<impl StatusBar>
) -> impl Widget<Engine = Tui> + 'a ) -> impl Render<Engine = Tui> + 'a
where where
A: Widget<Engine = Tui>, A: Render<Engine = Tui>,
S: Send + Sync + 'a, S: Send + Sync + 'a,
C: Command<S> C: Command<S>
{ {

View file

@ -95,7 +95,7 @@ pub struct TrackView<'a, E: Engine> {
pub entered: bool, pub entered: bool,
} }
impl<'a> Widget for TrackView<'a, Tui> { impl<'a> Render for TrackView<'a, Tui> {
type Engine = Tui; type Engine = Tui;
fn min_size (&self, area: [u16;2]) -> Perhaps<[u16;2]> { fn min_size (&self, area: [u16;2]) -> Perhaps<[u16;2]> {
todo!() todo!()
@ -132,7 +132,7 @@ impl<'a> Widget for TrackView<'a, Tui> {
impl Content for Mixer<Tui> { impl Content for Mixer<Tui> {
type Engine = Tui; type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> { fn content (&self) -> impl Render<Engine = Tui> {
Stack::right(|add| { Stack::right(|add| {
for channel in self.tracks.iter() { for channel in self.tracks.iter() {
add(channel)?; add(channel)?;
@ -144,7 +144,7 @@ impl Content for Mixer<Tui> {
impl Content for Track<Tui> { impl Content for Track<Tui> {
type Engine = Tui; type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> { fn content (&self) -> impl Render<Engine = Tui> {
TrackView { TrackView {
chain: Some(&self), chain: Some(&self),
direction: tek_core::Direction::Right, direction: tek_core::Direction::Right,

View file

@ -31,7 +31,7 @@ impl<E> Plugin<E> {
}) })
} }
} }
impl Widget for Plugin<Tui> { impl Render for Plugin<Tui> {
type Engine = Tui; type Engine = Tui;
fn min_size (&self, to: [u16;2]) -> Perhaps<[u16;2]> { fn min_size (&self, to: [u16;2]) -> Perhaps<[u16;2]> {
Ok(Some(to)) Ok(Some(to))

View file

@ -316,7 +316,7 @@ impl Sample {
} }
} }
impl Widget for SamplerView<Tui> { impl Render for SamplerView<Tui> {
type Engine = Tui; type Engine = Tui;
fn min_size (&self, to: [u16;2]) -> Perhaps<[u16;2]> { fn min_size (&self, to: [u16;2]) -> Perhaps<[u16;2]> {
todo!() todo!()
@ -371,7 +371,7 @@ fn draw_sample (
Ok(label1.len() + label2.len() + 4) Ok(label1.len() + label2.len() + 4)
} }
impl Widget for AddSampleModal { impl Render for AddSampleModal {
type Engine = Tui; type Engine = Tui;
fn min_size (&self, to: [u16;2]) -> Perhaps<[u16;2]> { fn min_size (&self, to: [u16;2]) -> Perhaps<[u16;2]> {
todo!() todo!()

View file

@ -154,7 +154,7 @@ impl StatusBar for ArrangerStatus {
impl Content for ArrangerStatus { impl Content for ArrangerStatus {
type Engine = Tui; type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> { fn content (&self) -> impl Render<Engine = Tui> {
let label = match self { let label = match self {
Self::Transport => "TRANSPORT", Self::Transport => "TRANSPORT",
Self::ArrangerMix => "PROJECT", Self::ArrangerMix => "PROJECT",

View file

@ -50,8 +50,8 @@ pub enum TransportFocus {
} }
impl FocusWrap<TransportFocus> for TransportFocus { impl FocusWrap<TransportFocus> for TransportFocus {
fn wrap <'a, W: Widget<Engine = Tui>> (self, focus: TransportFocus, content: &'a W) fn wrap <'a, W: Render<Engine = Tui>> (self, focus: TransportFocus, content: &'a W)
-> impl Widget<Engine = Tui> + 'a -> impl Render<Engine = Tui> + 'a
{ {
let focused = focus == self; let focused = focus == self;
let corners = focused.then_some(CORNERS); let corners = focused.then_some(CORNERS);
@ -61,8 +61,8 @@ impl FocusWrap<TransportFocus> for TransportFocus {
} }
impl FocusWrap<TransportFocus> for Option<TransportFocus> { impl FocusWrap<TransportFocus> for Option<TransportFocus> {
fn wrap <'a, W: Widget<Engine = Tui>> (self, focus: TransportFocus, content: &'a W) fn wrap <'a, W: Render<Engine = Tui>> (self, focus: TransportFocus, content: &'a W)
-> impl Widget<Engine = Tui> + 'a -> impl Render<Engine = Tui> + 'a
{ {
let focused = Some(focus) == self; let focused = Some(focus) == self;
let corners = focused.then_some(CORNERS); let corners = focused.then_some(CORNERS);
@ -97,7 +97,7 @@ impl StatusBar for TransportStatusBar {
impl Content for TransportStatusBar { impl Content for TransportStatusBar {
type Engine = Tui; type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> { fn content (&self) -> impl Render<Engine = Tui> {
todo!(); todo!();
"" ""
} }

View file

@ -3,7 +3,7 @@ use crate::*;
/// Layout for standalone arranger app. /// Layout for standalone arranger app.
impl Content for ArrangerTui { impl Content for ArrangerTui {
type Engine = Tui; type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> { fn content (&self) -> impl Render<Engine = Tui> {
let arranger_focused = self.arranger_focused(); let arranger_focused = self.arranger_focused();
Split::down( Split::down(
1, 1,
@ -90,7 +90,7 @@ fn track_widths (tracks: &[ArrangerTrack]) -> Vec<(usize, usize)> {
pub fn arranger_content_vertical ( pub fn arranger_content_vertical (
view: &ArrangerTui, view: &ArrangerTui,
factor: usize factor: usize
) -> impl Widget<Engine = Tui> + use<'_> { ) -> impl Render<Engine = Tui> + use<'_> {
let timebase = view.clock().timebase(); let timebase = view.clock().timebase();
let current = &view.clock().playhead; let current = &view.clock().playhead;
let tracks = view.tracks(); let tracks = view.tracks();
@ -107,7 +107,7 @@ pub fn arranger_content_vertical (
let cols: &[(usize, usize)] = cols.as_ref(); let cols: &[(usize, usize)] = cols.as_ref();
let any_size = |_|Ok(Some([0,0])); let any_size = |_|Ok(Some([0,0]));
// column separators // column separators
add(&CustomWidget::new(any_size, move|to: &mut TuiOutput|{ add(&Widget::new(any_size, move|to: &mut TuiOutput|{
let style = Some(Style::default().fg(sep_fg)); let style = Some(Style::default().fg(sep_fg));
Ok(for x in cols.iter().map(|col|col.1) { Ok(for x in cols.iter().map(|col|col.1) {
let x = scenes_w + to.area().x() + x as u16; let x = scenes_w + to.area().x() + x as u16;
@ -115,7 +115,7 @@ pub fn arranger_content_vertical (
}) })
}))?; }))?;
// row separators // row separators
add(&CustomWidget::new(any_size, move|to: &mut TuiOutput|{ add(&Widget::new(any_size, move|to: &mut TuiOutput|{
Ok(for y in rows.iter().map(|row|row.1) { Ok(for y in rows.iter().map(|row|row.1) {
let y = to.area().y() + (y / PPQ) as u16 + 1; let y = to.area().y() + (y / PPQ) as u16 + 1;
if y >= to.buffer.area.height { break } if y >= to.buffer.area.height { break }
@ -213,7 +213,7 @@ pub fn arranger_content_vertical (
// full grid with header and footer // full grid with header and footer
add(&col!(header, content))?; add(&col!(header, content))?;
// cursor // cursor
add(&CustomWidget::new(any_size, move|to: &mut TuiOutput|{ add(&Widget::new(any_size, move|to: &mut TuiOutput|{
let area = to.area(); let area = to.area();
let focused = view.arranger_focused(); let focused = view.arranger_focused();
let selected = view.selected; let selected = view.selected;
@ -276,14 +276,14 @@ pub fn arranger_content_vertical (
pub fn arranger_content_horizontal ( pub fn arranger_content_horizontal (
view: &ArrangerTui, view: &ArrangerTui,
) -> impl Widget<Engine = Tui> + use<'_> { ) -> impl Render<Engine = Tui> + use<'_> {
let focused = view.arranger_focused(); let focused = view.arranger_focused();
let _tracks = view.tracks(); let _tracks = view.tracks();
lay!( lay!(
focused.then_some(Background(TuiTheme::border_bg())), focused.then_some(Background(TuiTheme::border_bg())),
row!( row!(
// name // name
CustomWidget::new(|_|{todo!()}, |_: &mut TuiOutput|{ Widget::new(|_|{todo!()}, |_: &mut TuiOutput|{
todo!() todo!()
//let Self(tracks, selected) = self; //let Self(tracks, selected) = self;
//let yellow = Some(Style::default().yellow().bold().not_dim()); //let yellow = Some(Style::default().yellow().bold().not_dim());
@ -307,7 +307,7 @@ pub fn arranger_content_horizontal (
//Ok(Some(area)) //Ok(Some(area))
}), }),
// monitor // monitor
CustomWidget::new(|_|{todo!()}, |_: &mut TuiOutput|{ Widget::new(|_|{todo!()}, |_: &mut TuiOutput|{
todo!() todo!()
//let Self(tracks) = self; //let Self(tracks) = self;
//let mut area = to.area(); //let mut area = to.area();
@ -332,7 +332,7 @@ pub fn arranger_content_horizontal (
//Ok(Some(area)) //Ok(Some(area))
}), }),
// record // record
CustomWidget::new(|_|{todo!()}, |_: &mut TuiOutput|{ Widget::new(|_|{todo!()}, |_: &mut TuiOutput|{
todo!() todo!()
//let Self(tracks) = self; //let Self(tracks) = self;
//let mut area = to.area(); //let mut area = to.area();
@ -357,7 +357,7 @@ pub fn arranger_content_horizontal (
//Ok(Some(area)) //Ok(Some(area))
}), }),
// overdub // overdub
CustomWidget::new(|_|{todo!()}, |_: &mut TuiOutput|{ Widget::new(|_|{todo!()}, |_: &mut TuiOutput|{
todo!() todo!()
//let Self(tracks) = self; //let Self(tracks) = self;
//let mut area = to.area(); //let mut area = to.area();
@ -385,7 +385,7 @@ pub fn arranger_content_horizontal (
//Ok(Some(area)) //Ok(Some(area))
}), }),
// erase // erase
CustomWidget::new(|_|{todo!()}, |_: &mut TuiOutput|{ Widget::new(|_|{todo!()}, |_: &mut TuiOutput|{
todo!() todo!()
//let Self(tracks) = self; //let Self(tracks) = self;
//let mut area = to.area(); //let mut area = to.area();
@ -408,7 +408,7 @@ pub fn arranger_content_horizontal (
//Ok(Some(area)) //Ok(Some(area))
}), }),
// gain // gain
CustomWidget::new(|_|{todo!()}, |_: &mut TuiOutput|{ Widget::new(|_|{todo!()}, |_: &mut TuiOutput|{
todo!() todo!()
//let Self(tracks) = self; //let Self(tracks) = self;
//let mut area = to.area(); //let mut area = to.area();
@ -431,7 +431,7 @@ pub fn arranger_content_horizontal (
//Ok(Some(area)) //Ok(Some(area))
}), }),
// scenes // scenes
CustomWidget::new(|_|{todo!()}, |to: &mut TuiOutput|{ Widget::new(|_|{todo!()}, |to: &mut TuiOutput|{
let [x, y, _, height] = to.area(); let [x, y, _, height] = to.area();
let mut x2 = 0; let mut x2 = 0;
Ok(for (scene_index, scene) in view.scenes().iter().enumerate() { Ok(for (scene_index, scene) in view.scenes().iter().enumerate() {

View file

@ -2,7 +2,7 @@ use crate::*;
impl Content for FileBrowser { impl Content for FileBrowser {
type Engine = Tui; type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> { fn content (&self) -> impl Render<Engine = Tui> {
Stack::down(|add|{ Stack::down(|add|{
let mut i = 0; let mut i = 0;
for (_, name) in self.dirs.iter() { for (_, name) in self.dirs.iter() {

View file

@ -54,7 +54,7 @@ impl<'a, T: HasEditor> From<&'a T> for PhraseView<'a> {
impl<'a> Content for PhraseView<'a> { impl<'a> Content for PhraseView<'a> {
type Engine = Tui; type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> { fn content (&self) -> impl Render<Engine = Tui> {
let Self { let Self {
focused, focused,
entered, entered,
@ -104,13 +104,13 @@ impl<'a> Content for PhraseView<'a> {
lay!( lay!(
row!( row!(
CustomWidget::new(|to:[u16;2]|Ok(Some(to.clip_w(2))), move|to: &mut TuiOutput|{ Widget::new(|to:[u16;2]|Ok(Some(to.clip_w(2))), move|to: &mut TuiOutput|{
Ok(if to.area().h() >= 2 { Ok(if to.area().h() >= 2 {
view_mode.render_keys(to, *note_hi, *note_lo) view_mode.render_keys(to, *note_hi, *note_lo)
}) })
}).fill_y(), }).fill_y(),
lay!( lay!(
CustomWidget::new(|to|Ok(Some(to)), |to: &mut TuiOutput|{ Widget::new(|to|Ok(Some(to)), |to: &mut TuiOutput|{
size.set_wh(to.area.w(), to.area.h() as usize - 1); size.set_wh(to.area.w(), to.area.h() as usize - 1);
let draw = to.area().h() >= 2; let draw = to.area().h() >= 2;
Ok(if draw { Ok(if draw {
@ -119,7 +119,7 @@ impl<'a> Content for PhraseView<'a> {
) )
}) })
}).fill_x(), }).fill_x(),
CustomWidget::new(|to|Ok(Some(to)), move|to: &mut TuiOutput|{ Widget::new(|to|Ok(Some(to)), move|to: &mut TuiOutput|{
Ok(if *focused && *entered { Ok(if *focused && *entered {
view_mode.render_cursor( view_mode.render_cursor(
to, to,
@ -137,7 +137,7 @@ impl<'a> Content for PhraseView<'a> {
//} else { //} else {
//Color::Rgb(70, 80, 50) //Color::Rgb(70, 80, 50)
//}))), //}))),
CustomWidget::new(|to:[u16;2]|Ok(Some(to.clip_h(1))), move|to: &mut TuiOutput|{ Widget::new(|to:[u16;2]|Ok(Some(to.clip_h(1))), move|to: &mut TuiOutput|{
//let playhead_inactive = Style::default().fg(Color::Rgb(255,255,255)).bg(Color::Rgb(40,50,30)); //let playhead_inactive = Style::default().fg(Color::Rgb(255,255,255)).bg(Color::Rgb(40,50,30));
//let playhead_active = playhead_inactive.clone().yellow().bold().not_dim(); //let playhead_active = playhead_inactive.clone().yellow().bold().not_dim();
//if let Some(_) = phrase { //if let Some(_) = phrase {

View file

@ -2,7 +2,7 @@ use crate::*;
impl Content for PhraseLength { impl Content for PhraseLength {
type Engine = Tui; type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> { fn content (&self) -> impl Render<Engine = Tui> {
Layers::new(move|add|{ Layers::new(move|add|{
match self.focus { match self.focus {
None => add(&row!( None => add(&row!(

View file

@ -25,7 +25,7 @@ impl<'a, T: HasPhraseList> From<&'a T> for PhraseListView<'a> {
// TODO: Display phrases always in order of appearance // TODO: Display phrases always in order of appearance
impl<'a> Content for PhraseListView<'a> { impl<'a> Content for PhraseListView<'a> {
type Engine = Tui; type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> { fn content (&self) -> impl Render<Engine = Tui> {
let Self { title, focused, entered, phrases, index, mode } = self; let Self { title, focused, entered, phrases, index, mode } = self;
let content = Stack::down(move|add|match mode { let content = Stack::down(move|add|match mode {
Some(PhrasesMode::Import(_, ref browser)) => { Some(PhrasesMode::Import(_, ref browser)) => {

View file

@ -37,7 +37,7 @@ impl<'a> PhraseSelector<'a> {
// TODO: Display phrases always in order of appearance // TODO: Display phrases always in order of appearance
impl<'a> Content for PhraseSelector<'a> { impl<'a> Content for PhraseSelector<'a> {
type Engine = Tui; type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> { fn content (&self) -> impl Render<Engine = Tui> {
let Self { title, phrase, focused, entered } = self; let Self { title, phrase, focused, entered } = self;
let content = Layers::new(move|add|{ let content = Layers::new(move|add|{
if let Some((instant, Some(phrase))) = phrase { if let Some((instant, Some(phrase))) = phrase {

View file

@ -2,7 +2,7 @@ use crate::*;
impl Content for SequencerTui { impl Content for SequencerTui {
type Engine = Tui; type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> { fn content (&self) -> impl Render<Engine = Tui> {
lay!(self.size, SequencerStatusBar::with(self, col!( lay!(self.size, SequencerStatusBar::with(self, col!(
TransportView::from(self), TransportView::from(self),
Split::right(20, Split::right(20,
@ -27,7 +27,7 @@ impl Content for SequencerTui {
impl Content for SequencerStatusBar { impl Content for SequencerStatusBar {
type Engine = Tui; type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> { fn content (&self) -> impl Render<Engine = Tui> {
let orange = Color::Rgb(255,128,0); let orange = Color::Rgb(255,128,0);
let yellow = Color::Rgb(255,255,0); let yellow = Color::Rgb(255,255,0);
let black = Color::Rgb(0,0,0); let black = Color::Rgb(0,0,0);

View file

@ -1,6 +1,6 @@
use crate::*; use crate::*;
impl Widget for TransportTui { impl Render for TransportTui {
type Engine = Tui; type Engine = Tui;
fn min_size (&self, to: [u16;2]) -> Perhaps<[u16;2]> { fn min_size (&self, to: [u16;2]) -> Perhaps<[u16;2]> {
TransportView::from(self).min_size(to) TransportView::from(self).min_size(to)
@ -23,7 +23,7 @@ pub struct TransportView {
impl Content for TransportView { impl Content for TransportView {
type Engine = Tui; type Engine = Tui;
fn content (&self) -> impl Widget<Engine = Tui> { fn content (&self) -> impl Render<Engine = Tui> {
let Self { state, selected, focused, bpm, sync, quant, beat, msu, } = self; let Self { state, selected, focused, bpm, sync, quant, beat, msu, } = self;
row!( row!(
selected.wrap(TransportFocus::PlayPause, &Styled( selected.wrap(TransportFocus::PlayPause, &Styled(