From 49d2055147f219e16e0427b70601721c388a6f76 Mon Sep 17 00:00:00 2001 From: unspeaker Date: Mon, 9 Sep 2024 17:49:50 +0300 Subject: [PATCH] wip: fix implicit static --- crates/tek_core/src/audio.rs | 8 ++------ crates/tek_core/src/audio/device.rs | 6 +++++- crates/tek_core/src/engine/collect.rs | 2 +- crates/tek_core/src/engine/component.rs | 24 +++++++----------------- crates/tek_core/src/engine/exit.rs | 10 ++++++++++ crates/tek_core/src/tui/tui_layout.rs | 4 ++-- 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/crates/tek_core/src/audio.rs b/crates/tek_core/src/audio.rs index 2a86027e..79c78fe8 100644 --- a/crates/tek_core/src/audio.rs +++ b/crates/tek_core/src/audio.rs @@ -1,11 +1,7 @@ use jack::*; use crate::*; -submod! { - device - event - ports -} +submod! { device event ports } /// A UI component that may be associated with a JACK client by the `Jack` factory. pub trait Device: Component + Process { @@ -16,7 +12,7 @@ pub trait Device: Component + Process { } /// All things that implement the required traits can be treated as `Device`. -impl + Process> Device for W {} +impl + Process> Device for W {} //impl<'a, E: Engine> Render for Box + 'a> { //fn render (&self, to: &mut E) -> Perhaps { diff --git a/crates/tek_core/src/audio/device.rs b/crates/tek_core/src/audio/device.rs index ffe292a4..d34f24b1 100644 --- a/crates/tek_core/src/audio/device.rs +++ b/crates/tek_core/src/audio/device.rs @@ -17,7 +17,11 @@ impl std::fmt::Debug for JackDevice { } } impl Widget for JackDevice { - fn render (&self, to: &mut E) -> Perhaps { + type Engine = E; + fn layout (&self, to: E::Area) -> Perhaps { + self.state.read().unwrap().layout(to) + } + fn render (&self, to: &mut E) -> Perhaps { self.state.read().unwrap().render(to) } } diff --git a/crates/tek_core/src/engine/collect.rs b/crates/tek_core/src/engine/collect.rs index 45b57d2b..1d912773 100644 --- a/crates/tek_core/src/engine/collect.rs +++ b/crates/tek_core/src/engine/collect.rs @@ -13,7 +13,7 @@ impl<'a, E: Engine> Widget for Collected<'a, E> { Self::Ref(inner) => (*inner).layout(area), } } - fn render (&self, to: &mut E) -> Perhaps { + fn render (&self, to: &mut E) -> Perhaps { match self { Self::Box(inner) => (*inner).render(to), Self::Ref(inner) => (*inner).render(to), diff --git a/crates/tek_core/src/engine/component.rs b/crates/tek_core/src/engine/component.rs index ceb1ed5f..33b2e633 100644 --- a/crates/tek_core/src/engine/component.rs +++ b/crates/tek_core/src/engine/component.rs @@ -1,21 +1,5 @@ use crate::*; -/// A UI component. -pub trait Component: Widget + Handle {} - -/// Everything that implements [Render] and [Handle] is a [Component]. -impl + Handle> Component for C {} - -/// Marker trait for [Component]s that can [Exit] -pub trait ExitableComponent: Exit + Component where E: Engine { - /// Perform type erasure for collecting heterogeneous components. - fn boxed (self) -> Box> where Self: Sized + 'static { - Box::new(self) - } -} - -impl + Exit> ExitableComponent for C {} - pub trait Widget { type Engine: Engine; fn layout (&self, to: <::Engine as Engine>::Area) -> @@ -23,7 +7,7 @@ pub trait Widget { fn render (&self, to: &mut Self::Engine) -> Perhaps<<::Engine as Engine>::Area>; } -impl Widget for Box> { +impl<'a, E: Engine> Widget for Box + 'a> { type Engine = E; fn layout (&self, to: E::Area) -> Perhaps { (**self).layout(to) @@ -105,3 +89,9 @@ impl Widget for W where W: Content { self.content().render(to) } } + +/// A UI component. +pub trait Component: Widget + Handle {} + +/// Everything that implements [Render] and [Handle] is a [Component]. +impl + Handle> Component for C {} diff --git a/crates/tek_core/src/engine/exit.rs b/crates/tek_core/src/engine/exit.rs index 6f273dbb..ee9eaa5b 100644 --- a/crates/tek_core/src/engine/exit.rs +++ b/crates/tek_core/src/engine/exit.rs @@ -20,3 +20,13 @@ pub trait Exit: Send { } } } + +/// Marker trait for [Component]s that can [Exit] +pub trait ExitableComponent: Exit + Component where E: Engine { + /// Perform type erasure for collecting heterogeneous components. + fn boxed (self) -> Box> where Self: Sized + 'static { + Box::new(self) + } +} + +impl + Exit> ExitableComponent for C {} diff --git a/crates/tek_core/src/tui/tui_layout.rs b/crates/tek_core/src/tui/tui_layout.rs index a49b6b24..3c55c11b 100644 --- a/crates/tek_core/src/tui/tui_layout.rs +++ b/crates/tek_core/src/tui/tui_layout.rs @@ -14,8 +14,8 @@ impl<'a> Widget for Split<'a, Tui> { impl<'a> Split<'a, Tui> { pub fn render_areas (&self, to: &mut Tui) -> Usually<([u16;4], Vec>)> { let area = to.area(); - let mut w = 0u16; - let mut h = 0u16; + let mut w = 0; + let mut h = 0; let mut areas = vec![]; Ok((match self.direction { Direction::Down => {