wip: fix implicit static

This commit is contained in:
🪞👃🪞 2024-09-09 17:49:50 +03:00
parent eeb323b742
commit 49d2055147
6 changed files with 27 additions and 27 deletions

View file

@ -1,11 +1,7 @@
use jack::*; use jack::*;
use crate::*; use crate::*;
submod! { submod! { device event ports }
device
event
ports
}
/// A UI component that may be associated with a JACK client by the `Jack` factory. /// A UI component that may be associated with a JACK client by the `Jack` factory.
pub trait Device<E: Engine>: Component<E> + Process { pub trait Device<E: Engine>: Component<E> + Process {
@ -16,7 +12,7 @@ pub trait Device<E: Engine>: Component<E> + Process {
} }
/// All things that implement the required traits can be treated as `Device`. /// All things that implement the required traits can be treated as `Device`.
impl<E: Engine, W: Widget<Engine = E> + Process> Device<E> for W {} impl<E: Engine, W: Component<E> + Process> Device<E> for W {}
//impl<'a, E: Engine> Render<E> for Box<dyn Device<E> + 'a> { //impl<'a, E: Engine> Render<E> for Box<dyn Device<E> + 'a> {
//fn render (&self, to: &mut E) -> Perhaps<E::Rendered> { //fn render (&self, to: &mut E) -> Perhaps<E::Rendered> {

View file

@ -17,7 +17,11 @@ impl<E: Engine> std::fmt::Debug for JackDevice<E> {
} }
} }
impl<E: Engine> Widget for JackDevice<E> { impl<E: Engine> Widget for JackDevice<E> {
fn render (&self, to: &mut E) -> Perhaps<E::Rendered> { type Engine = E;
fn layout (&self, to: E::Area) -> Perhaps<E::Area> {
self.state.read().unwrap().layout(to)
}
fn render (&self, to: &mut E) -> Perhaps<E::Area> {
self.state.read().unwrap().render(to) self.state.read().unwrap().render(to)
} }
} }

View file

@ -13,7 +13,7 @@ impl<'a, E: Engine> Widget for Collected<'a, E> {
Self::Ref(inner) => (*inner).layout(area), Self::Ref(inner) => (*inner).layout(area),
} }
} }
fn render (&self, to: &mut E) -> Perhaps<E::Rendered> { fn render (&self, to: &mut E) -> Perhaps<E::Area> {
match self { match self {
Self::Box(inner) => (*inner).render(to), Self::Box(inner) => (*inner).render(to),
Self::Ref(inner) => (*inner).render(to), Self::Ref(inner) => (*inner).render(to),

View file

@ -1,21 +1,5 @@
use crate::*; use crate::*;
/// A UI component.
pub trait Component<E: Engine>: Widget<Engine = E> + Handle<E> {}
/// Everything that implements [Render] and [Handle] is a [Component].
impl<E: Engine, C: Widget<Engine = E> + Handle<E>> Component<E> for C {}
/// Marker trait for [Component]s that can [Exit]
pub trait ExitableComponent<E>: Exit + Component<E> where E: Engine {
/// Perform type erasure for collecting heterogeneous components.
fn boxed (self) -> Box<dyn ExitableComponent<E>> where Self: Sized + 'static {
Box::new(self)
}
}
impl<E: Engine, C: Component<E> + Exit> ExitableComponent<E> for C {}
pub trait Widget { pub trait Widget {
type Engine: Engine; type Engine: Engine;
fn layout (&self, to: <<Self as Widget>::Engine as Engine>::Area) -> fn layout (&self, to: <<Self as Widget>::Engine as Engine>::Area) ->
@ -23,7 +7,7 @@ pub trait Widget {
fn render (&self, to: &mut Self::Engine) -> fn render (&self, to: &mut Self::Engine) ->
Perhaps<<<Self as Widget>::Engine as Engine>::Area>; Perhaps<<<Self as Widget>::Engine as Engine>::Area>;
} }
impl<E: Engine> Widget for Box<dyn Widget<Engine = E>> { impl<'a, E: Engine> Widget for Box<dyn Widget<Engine = E> + 'a> {
type Engine = E; type Engine = E;
fn layout (&self, to: E::Area) -> Perhaps<E::Area> { fn layout (&self, to: E::Area) -> Perhaps<E::Area> {
(**self).layout(to) (**self).layout(to)
@ -105,3 +89,9 @@ impl<E: Engine, W> Widget for W where W: Content<Engine = E> {
self.content().render(to) self.content().render(to)
} }
} }
/// A UI component.
pub trait Component<E: Engine>: Widget<Engine = E> + Handle<E> {}
/// Everything that implements [Render] and [Handle] is a [Component].
impl<E: Engine, C: Widget<Engine = E> + Handle<E>> Component<E> for C {}

View file

@ -20,3 +20,13 @@ pub trait Exit: Send {
} }
} }
} }
/// Marker trait for [Component]s that can [Exit]
pub trait ExitableComponent<E>: Exit + Component<E> where E: Engine {
/// Perform type erasure for collecting heterogeneous components.
fn boxed (self) -> Box<dyn ExitableComponent<E>> where Self: Sized + 'static {
Box::new(self)
}
}
impl<E: Engine, C: Component<E> + Exit> ExitableComponent<E> for C {}

View file

@ -14,8 +14,8 @@ impl<'a> Widget for Split<'a, Tui> {
impl<'a> Split<'a, Tui> { impl<'a> Split<'a, Tui> {
pub fn render_areas (&self, to: &mut Tui) -> Usually<([u16;4], Vec<Option<[u16;4]>>)> { pub fn render_areas (&self, to: &mut Tui) -> Usually<([u16;4], Vec<Option<[u16;4]>>)> {
let area = to.area(); let area = to.area();
let mut w = 0u16; let mut w = 0;
let mut h = 0u16; let mut h = 0;
let mut areas = vec![]; let mut areas = vec![];
Ok((match self.direction { Ok((match self.direction {
Direction::Down => { Direction::Down => {