From bf3c7630a44acbc990ded2f057ed36fc8a6d3c89 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Wed, 4 Dec 2024 21:24:38 +0100 Subject: [PATCH] rename Widget to Render and CustomWidget to Widget --- crates/tek_api/src/lib.rs | 2 +- crates/tek_core/examples/demo.rs | 4 +- crates/tek_core/src/engine.rs | 52 +++++----- crates/tek_core/src/space.rs | 94 +++++++++---------- crates/tek_core/src/test.rs | 2 +- crates/tek_core/src/tui.rs | 42 ++++----- crates/tek_tui/src/lib.rs | 16 ++-- crates/tek_tui/src/todo_tui_mixer.rs | 6 +- crates/tek_tui/src/todo_tui_plugin.rs | 2 +- crates/tek_tui/src/todo_tui_sampler.rs | 4 +- crates/tek_tui/src/tui_app_arranger.rs | 2 +- crates/tek_tui/src/tui_app_transport.rs | 10 +- crates/tek_tui/src/tui_view_arranger.rs | 26 ++--- crates/tek_tui/src/tui_view_file_browser.rs | 2 +- crates/tek_tui/src/tui_view_phrase_editor.rs | 10 +- crates/tek_tui/src/tui_view_phrase_length.rs | 2 +- crates/tek_tui/src/tui_view_phrase_list.rs | 2 +- .../tek_tui/src/tui_view_phrase_selector.rs | 2 +- crates/tek_tui/src/tui_view_sequencer.rs | 4 +- crates/tek_tui/src/tui_view_transport.rs | 4 +- 20 files changed, 144 insertions(+), 144 deletions(-) diff --git a/crates/tek_api/src/lib.rs b/crates/tek_api/src/lib.rs index 9f39f83e..a75ddf26 100644 --- a/crates/tek_api/src/lib.rs +++ b/crates/tek_api/src/lib.rs @@ -150,7 +150,7 @@ fn query_ports(client: &Client, names: Vec) -> BTreeMap Widget for JackDevice { +//impl Render for JackDevice { //type Engine = E; //fn min_size(&self, to: E::Size) -> Perhaps { //self.state.read().unwrap().layout(to) diff --git a/crates/tek_core/examples/demo.rs b/crates/tek_core/examples/demo.rs index 6e8963d2..6ee99acf 100644 --- a/crates/tek_core/examples/demo.rs +++ b/crates/tek_core/examples/demo.rs @@ -8,7 +8,7 @@ fn main () -> Usually<()> { pub struct Demo { index: usize, - items: Vec>> + items: Vec>> } impl Demo { @@ -35,7 +35,7 @@ impl Demo { impl Content for Demo { type Engine = Tui; - fn content (&self) -> impl Widget { + fn content (&self) -> impl Render { let border_style = Style::default().fg(Color::Rgb(0,0,0)); Align::Center(Layers::new(move|add|{ diff --git a/crates/tek_core/src/engine.rs b/crates/tek_core/src/engine.rs index d762128b..03c6983f 100644 --- a/crates/tek_core/src/engine.rs +++ b/crates/tek_core/src/engine.rs @@ -40,14 +40,14 @@ pub trait Output { /// Mutable pointer to area fn area_mut (&mut self) -> &mut E::Area; /// Render widget in area - fn render_in (&mut self, area: E::Area, widget: &dyn Widget) -> Usually<()>; + fn render_in (&mut self, area: E::Area, widget: &dyn Render) -> Usually<()>; } /// Cast to dynamic pointer -pub fn widget > (w: &T) -> &dyn Widget { - w as &dyn Widget +pub fn widget > (w: &T) -> &dyn Render { + w as &dyn Render } /// A renderable component -pub trait Widget: Send + Sync { +pub trait Render: Send + Sync { /// Engine for which this component is implemented type Engine: Engine; /// Minimum size to use @@ -59,7 +59,7 @@ pub trait Widget: Send + Sync { /// Draw to output render target fn render (&self,to: &mut ::Output) -> Usually<()>; } -impl Widget for &dyn Widget { +impl Render for &dyn Render { type Engine = E; fn min_size (&self, to: E::Size) -> Perhaps { (*self).min_size(to) @@ -68,7 +68,7 @@ impl Widget for &dyn Widget { (*self).render(to) } } -impl Widget for &mut dyn Widget { +impl Render for &mut dyn Render { type Engine = E; fn min_size (&self, to: E::Size) -> Perhaps { (**self).min_size(to) @@ -77,7 +77,7 @@ impl Widget for &mut dyn Widget { (**self).render(to) } } -impl<'a, E: Engine> Widget for Box + 'a> { +impl<'a, E: Engine> Render for Box + 'a> { type Engine = E; fn min_size (&self, to: E::Size) -> Perhaps { (**self).min_size(to) @@ -86,7 +86,7 @@ impl<'a, E: Engine> Widget for Box + 'a> { (**self).render(to) } } -impl> Widget for Arc { +impl> Render for Arc { type Engine = E; fn min_size (&self, to: E::Size) -> Perhaps { self.as_ref().min_size(to) @@ -95,7 +95,7 @@ impl> Widget for Arc { self.as_ref().render(to) } } -impl> Widget for Mutex { +impl> Render for Mutex { type Engine = E; fn min_size (&self, to: E::Size) -> Perhaps { self.lock().unwrap().min_size(to) @@ -104,7 +104,7 @@ impl> Widget for Mutex { self.lock().unwrap().render(to) } } -impl> Widget for RwLock { +impl> Render for RwLock { type Engine = E; fn min_size (&self, to: E::Size) -> Perhaps { self.read().unwrap().min_size(to) @@ -113,7 +113,7 @@ impl> Widget for RwLock { self.read().unwrap().render(to) } } -impl> Widget for Option { +impl> Render for Option { type Engine = E; fn min_size (&self, to: E::Size) -> Perhaps { Ok(self.as_ref().map(|widget|widget.min_size(to)).transpose()?.flatten()) @@ -123,12 +123,12 @@ impl> Widget for Option { } } /// Render either of two widgets depending on predicate -pub struct Either, B: Widget>( +pub struct Either, B: Render>( pub bool, pub A, pub B, ); -impl, B: Widget> Widget for Either { +impl, B: Render> Render for Either { type Engine = E; fn min_size (&self, to: E::Size) -> Perhaps { if self.0 { self.1.min_size(to) } else { self.2.min_size(to) } @@ -137,8 +137,8 @@ impl, B: Widget> Widget for Either< if self.0 { self.1.render(to) } else { self.2.render(to) } } } -/// A custom [Widget] defined by passing layout and render closures in place. -pub struct CustomWidget< +/// A custom [Render] defined by passing layout and render closures in place. +pub struct Widget< E: Engine, L: Send + Sync + Fn(E::Size)->Perhaps, R: Send + Sync + Fn(&mut E::Output)->Usually<()> @@ -147,7 +147,7 @@ impl< E: Engine, L: Send + Sync + Fn(E::Size)->Perhaps, R: Send + Sync + Fn(&mut E::Output)->Usually<()> -> CustomWidget { +> Widget { pub fn new (layout: L, render: R) -> Self { Self(layout, render, Default::default()) } @@ -156,7 +156,7 @@ impl< E: Engine, L: Send + Sync + Fn(E::Size)->Perhaps, R: Send + Sync + Fn(&mut E::Output)->Usually<()> -> Widget for CustomWidget { +> Render for Widget { type Engine = E; fn min_size (&self, to: E::Size) -> Perhaps { self.0(to) @@ -165,13 +165,13 @@ impl< self.1(to) } } -/// A [Widget] that contains other [Widget]s +/// A [Render] that contains other [Render]s pub trait Content: Send + Sync { type Engine: Engine; - fn content (&self) -> impl Widget::Engine>; + fn content (&self) -> impl Render::Engine>; } -/// Every struct that has [Content] is a renderable [Widget]. -impl> Widget for W { +/// Every struct that has [Content] is a renderable [Render]. +impl> Render for W { type Engine = E; fn min_size (&self, to: E::Size) -> Perhaps { self.content().min_size(to) @@ -221,12 +221,12 @@ impl Handle for Arc> where H: Handle { self.write().unwrap().handle(context) } } -/// A UI component that can render itself as a [Widget], and [Handle] input. -pub trait Component: Widget + Handle {} -/// Everything that implements [Widget] and [Handle] is a [Component]. -impl + Handle> Component for C {} +/// A UI component that can render itself as a [Render], and [Handle] input. +pub trait Component: Render + Handle {} +/// Everything that implements [Render] and [Handle] is a [Component]. +impl + Handle> Component for C {} /// A UI component that has [Content] and can [Handle] input. -pub trait ContentComponent: Widget + Handle {} +pub trait ContentComponent: Render + Handle {} /// Everything that implements [Content] and [Handle] is a [Component]. impl + Handle> ContentComponent for C {} /// A component that can exit. diff --git a/crates/tek_core/src/space.rs b/crates/tek_core/src/space.rs index 07e76ea1..0bb27802 100644 --- a/crates/tek_core/src/space.rs +++ b/crates/tek_core/src/space.rs @@ -126,7 +126,7 @@ impl Area for [N;4] { #[inline] fn h (&self) -> N { self[3] } } -pub trait Layout: Widget + Sized { +pub trait Layout: Render + Sized { fn align_center (self) -> Align { Align::Center(self) } fn align_n (self) -> Align { Align::N(self) } fn align_s (self) -> Align { Align::S(self) } @@ -169,21 +169,21 @@ pub trait Layout: Widget + Sized { fn fill_y (self) -> Fill { Fill::Y(self) } fn fill_xy (self) -> Fill { Fill::XY(self) } fn debug (self) -> DebugOverlay { DebugOverlay(self) } - fn split > ( + fn split > ( self, direction: Direction, amount: E::Unit, other: W ) -> Split { Split::new(direction, amount, self, other) } - fn split_flip > ( + fn split_flip > ( self, direction: Direction, amount: E::Unit, other: W ) -> Split { Split::new(direction, amount, other, self) } } -impl> Layout for W {} +impl> Layout for W {} -pub struct DebugOverlay>(pub W); +pub struct DebugOverlay>(pub W); -pub enum Fill> { X(W), Y(W), XY(W) } +pub enum Fill> { X(W), Y(W), XY(W) } -impl> Fill { +impl> Fill { fn inner (&self) -> &W { match self { Self::X(inner) => &inner, @@ -193,7 +193,7 @@ impl> Fill { } } -impl> Widget for Fill { +impl> Render for Fill { type Engine = E; fn min_size (&self, to: E::Size) -> Perhaps { let area = self.inner().min_size(to.into())?; @@ -214,12 +214,12 @@ impl> Widget for Fill { pub struct Layers< E: Engine, - F: Send + Sync + Fn(&mut dyn FnMut(&dyn Widget)->Usually<()>)->Usually<()> + F: Send + Sync + Fn(&mut dyn FnMut(&dyn Render)->Usually<()>)->Usually<()> >(pub F, PhantomData); impl< E: Engine, - F: Send + Sync + Fn(&mut dyn FnMut(&dyn Widget)->Usually<()>)->Usually<()> + F: Send + Sync + Fn(&mut dyn FnMut(&dyn Render)->Usually<()>)->Usually<()> > Layers { #[inline] pub fn new (build: F) -> Self { @@ -227,9 +227,9 @@ impl< } } -impl Widget for Layers +impl Render for Layers where - F: Send + Sync + Fn(&mut dyn FnMut(&dyn Widget)->Usually<()>)->Usually<()> + F: Send + Sync + Fn(&mut dyn FnMut(&dyn Render)->Usually<()>)->Usually<()> { type Engine = E; fn min_size (&self, area: E::Size) -> Perhaps { @@ -346,7 +346,7 @@ fn align + From<[N;4]>> (align: &Align, outer: R } } -impl> Widget for Align { +impl> Render for Align { type Engine = E; fn min_size (&self, outer_area: E::Size) -> Perhaps { self.inner().min_size(outer_area) @@ -380,7 +380,7 @@ impl Fixed { match self { Self::X(_, i) => i, Self::Y(_, i) => i, Self::XY(_, _, i) => i, } } } -impl> Widget for Fixed { +impl> Render for Fixed { type Engine = E; fn min_size (&self, to: E::Size) -> Perhaps { Ok(match self { @@ -416,7 +416,7 @@ impl Min { match self { Self::X(_, i) => i, Self::Y(_, i) => i, Self::XY(_, _, i) => i, } } } -impl> Widget for Min { +impl> Render for Min { type Engine = E; fn min_size (&self, to: E::Size) -> Perhaps { Ok(self.inner().min_size(to)?.map(|to|match *self { @@ -449,7 +449,7 @@ impl Max { } } -impl> Widget for Max { +impl> Render for Max { type Engine = E; fn min_size (&self, to: E::Size) -> Perhaps { Ok(self.inner().min_size(to)?.map(|to|match *self { @@ -481,7 +481,7 @@ impl Grow { } } -impl> Widget for Grow { +impl> Render for Grow { type Engine = E; fn min_size (&self, to: E::Size) -> Perhaps { Ok(self.inner().min_size(to)?.map(|to|match *self { @@ -507,13 +507,13 @@ pub enum Shrink { XY(N, N, T), } -impl Shrink { +impl Shrink { fn inner (&self) -> &T { match self { Self::X(_, i) => i, Self::Y(_, i) => i, Self::XY(_, _, i) => i, } } } -impl> Widget for Shrink { +impl> Render for Shrink { type Engine = E; fn min_size (&self, to: E::Size) -> Perhaps { Ok(self.inner().min_size(to)?.map(|to|match *self { @@ -548,7 +548,7 @@ pub enum Inset { XY(N, N, T), } -impl Inset { +impl Inset { pub fn inner (&self) -> &T { match self { Self::X(_, i) => i, Self::Y(_, i) => i, Self::XY(_, _, i) => i, } } @@ -564,52 +564,52 @@ pub enum Outset { XY(N, N, T), } -impl Outset { +impl Outset { pub fn inner (&self) -> &T { match self { Self::X(_, i) => i, Self::Y(_, i) => i, Self::XY(_, _, i) => i, } } } -impl> Widget for Inset { +impl> Render for Inset { type Engine = E; fn render (&self, to: &mut E::Output) -> Usually<()> { match *self { Self::X(x, ref inner) => - (inner as &dyn Widget).shrink_x(x).push_x(x), + (inner as &dyn Render).shrink_x(x).push_x(x), Self::Y(y, ref inner) => - (inner as &dyn Widget).shrink_y(y).push_y(y), + (inner as &dyn Render).shrink_y(y).push_y(y), Self::XY(x, y, ref inner) => - (inner as &dyn Widget).shrink_xy(x, y).push_xy(x, y) + (inner as &dyn Render).shrink_xy(x, y).push_xy(x, y) }.render(to) } } -impl> Widget for Outset { +impl> Render for Outset { type Engine = E; fn min_size (&self, to: E::Size) -> Perhaps { match *self { Self::X(x, ref inner) => - (inner as &dyn Widget).grow_x(x + x), + (inner as &dyn Render).grow_x(x + x), Self::Y(y, ref inner) => - (inner as &dyn Widget).grow_y(y + y), + (inner as &dyn Render).grow_y(y + y), Self::XY(x, y, ref inner) => - (inner as &dyn Widget).grow_xy(x + x, y + y), + (inner as &dyn Render).grow_xy(x + x, y + y), }.min_size(to) } fn render (&self, to: &mut E::Output) -> Usually<()> { match *self { Self::X(x, ref inner) => - (inner as &dyn Widget).push_x(x), + (inner as &dyn Render).push_x(x), Self::Y(y, ref inner) => - (inner as &dyn Widget).push_y(y), + (inner as &dyn Render).push_y(y), Self::XY(x, y, ref inner) => - (inner as &dyn Widget).push_xy(x, y), + (inner as &dyn Render).push_xy(x, y), }.render(to) } } /// Move origin point of drawing area -pub enum Push { +pub enum Push { /// Move origin to the right X(N, T), /// Move origin downwards @@ -618,7 +618,7 @@ pub enum Push { XY(N, N, T), } -impl Push { +impl Push { pub fn inner (&self) -> &T { match self { Self::X(_, i) => i, Self::Y(_, i) => i, Self::XY(_, _, i) => i, } } @@ -630,7 +630,7 @@ impl Push { } } -impl> Widget for Push { +impl> Render for Push { type Engine = E; fn min_size (&self, to: E::Size) -> Perhaps { self.inner().min_size(to) @@ -647,7 +647,7 @@ impl> Widget for Push { } /// Move origin point of drawing area -pub enum Pull { +pub enum Pull { /// Move origin to the right X(N, T), /// Move origin downwards @@ -656,7 +656,7 @@ pub enum Pull { XY(N, N, T), } -impl Pull { +impl Pull { pub fn inner (&self) -> &T { match self { Self::X(_, i) => i, Self::Y(_, i) => i, Self::XY(_, _, i) => i, } } @@ -668,7 +668,7 @@ impl Pull { } } -impl> Widget for Pull { +impl> Render for Pull { type Engine = E; fn min_size (&self, to: E::Size) -> Perhaps { self.inner().min_size(to) @@ -686,12 +686,12 @@ impl> Widget for Pull { pub struct Stack< E: Engine, - F: Send + Sync + Fn(&mut dyn FnMut(&dyn Widget)->Usually<()>)->Usually<()> + F: Send + Sync + Fn(&mut dyn FnMut(&dyn Render)->Usually<()>)->Usually<()> >(pub F, pub Direction, PhantomData); impl< E: Engine, - F: Send + Sync + Fn(&mut dyn FnMut(&dyn Widget)->Usually<()>)->Usually<()> + F: Send + Sync + Fn(&mut dyn FnMut(&dyn Render)->Usually<()>)->Usually<()> > Stack { #[inline] pub fn new (direction: Direction, build: F) -> Self { Self(build, direction, Default::default()) @@ -704,9 +704,9 @@ impl< } } -impl Widget for Stack +impl Render for Stack where - F: Send + Sync + Fn(&mut dyn FnMut(&dyn Widget)->Usually<()>)->Usually<()> + F: Send + Sync + Fn(&mut dyn FnMut(&dyn Render)->Usually<()>)->Usually<()> { type Engine = E; fn min_size (&self, to: E::Size) -> Perhaps { @@ -808,11 +808,11 @@ where } /// A binary split with fixed proportion -pub struct Split, B: Widget>( +pub struct Split, B: Render>( pub Direction, pub E::Unit, A, B, PhantomData ); -impl, B: Widget> Split { +impl, B: Render> Split { pub fn new (direction: Direction, proportion: E::Unit, a: A, b: B) -> Self { Self(direction, proportion, a, b, Default::default()) } @@ -830,7 +830,7 @@ impl, B: Widget> Split { } } -impl, B: Widget> Widget for Split { +impl, B: Render> Render for Split { type Engine = E; fn min_size (&self, to: E::Size) -> Perhaps { Ok(Some(to)) @@ -876,7 +876,7 @@ impl Measure { pub fn format (&self) -> String { format!("{}x{}", self.w(), self.h()) } } -impl Widget for Measure { +impl Render for Measure { type Engine = E; fn min_size (&self, _: E::Size) -> Perhaps { Ok(Some([0u16.into(), 0u16.into()].into())) @@ -891,5 +891,5 @@ impl Widget for Measure { /// A scrollable area. pub struct Scroll< E: Engine, - F: Send + Sync + Fn(&mut dyn FnMut(&dyn Widget)->Usually<()>)->Usually<()> + F: Send + Sync + Fn(&mut dyn FnMut(&dyn Render)->Usually<()>)->Usually<()> >(pub F, pub Direction, pub u64, PhantomData); diff --git a/crates/tek_core/src/test.rs b/crates/tek_core/src/test.rs index 4b8a0244..fe6a77b2 100644 --- a/crates/tek_core/src/test.rs +++ b/crates/tek_core/src/test.rs @@ -22,7 +22,7 @@ impl Engine for TestEngine { #[derive(Copy, Clone)] struct TestArea(u16, u16); -impl Widget for TestArea { +impl Render for TestArea { type Engine = TestEngine; fn min_size (&self, to: [u16;2]) -> Perhaps<[u16;2]> { Ok(Some([to[0], to[1], self.0, self.1])) diff --git a/crates/tek_core/src/tui.rs b/crates/tek_core/src/tui.rs index d92fab08..2e01ad69 100644 --- a/crates/tek_core/src/tui.rs +++ b/crates/tek_core/src/tui.rs @@ -165,7 +165,7 @@ impl Output for TuiOutput { #[inline] fn area_mut (&mut self) -> &mut [u16;4] { &mut self.area } #[inline] fn render_in (&mut self, area: [u16;4], - widget: &dyn Widget + widget: &dyn Render ) -> Usually<()> { let last = self.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; fn min_size (&self, _: [u16;2]) -> Perhaps<[u16;2]> { // TODO: line breaks @@ -299,7 +299,7 @@ impl Widget for &str { Ok(to.blit(&self, x, y, None)) } } -impl Widget for String { +impl Render for String { type Engine = Tui; fn min_size (&self, _: [u16;2]) -> Perhaps<[u16;2]> { // TODO: line breaks @@ -311,7 +311,7 @@ impl Widget for String { Ok(to.blit(&self, x, y, None)) } } -impl> Widget for DebugOverlay { +impl> Render for DebugOverlay { type Engine = Tui; fn min_size (&self, to: [u16;2]) -> Perhaps<[u16;2]> { self.0.min_size(to) @@ -322,8 +322,8 @@ impl> Widget for DebugOverlay { Ok(to.blit(&format!("{w}x{h}+{x}+{y}"), x, y, Some(Style::default().green()))) } } -pub struct Styled>(pub Option