diff --git a/engine/src/output.rs b/engine/src/output.rs index 4559a747..0b84022f 100644 --- a/engine/src/output.rs +++ b/engine/src/output.rs @@ -114,369 +114,3 @@ impl, F: Fn()->T + Send + Sync> Content for Thunk> Render for &R {} - -//pub trait Render: Send + Sync { - //fn render (&self, _: &mut E::Output); -//} - -//impl> Render for L { - //fn render (&self, to: &mut E::Output) { - //if let Some(content) = self.layout() { - //content.render(to) - //} - //} -//} - -//impl> Layout for &L {} - -///// Something that can be represented by a renderable component. -//pub trait Content: Send + Sync { - //fn content (&self) -> Option>; -//} -//impl> Content for &C { - //fn content (&self) -> Option> { - //(*self).content() - //} -//} - -///// Something that writes to an [Output]. -//pub trait Render: Send + Sync { - ///// Minimum size to use - //fn min_size (&self, _: E::Size) -> Perhaps { - //Ok(None) - //} - ///// Draw to output render target - //fn render (&self, _: &mut E::Output) -> Usually<()> { - //Ok(()) - //} -//} -//impl Render for &dyn Render { - //fn min_size (&self, to: E::Size) -> Perhaps { (*self).min_size(to) } - //fn render (&self, to: &mut E::Output) -> Usually<()> { (*self).render(to) } -//} -//impl> Render for &R { - //fn min_size (&self, to: E::Size) -> Perhaps { (*self).min_size(to) } - //fn render (&self, to: &mut E::Output) -> Usually<()> { (*self).render(to) } -//} -//impl> Render for Option { - //fn min_size (&self, to: E::Size) -> Perhaps { - //if let Some(content) = self { - //content.min_size(to) - //} else { - //Ok(None) - //} - //} - //fn render (&self, to: &mut E::Output) -> Usually<()> { - //if let Some(content) = self { - //content.render(to)?; - //} - //Ok(()) - //} -//} - -///// Define custom content for a struct. -///// -///// This code wires the `Content` and `Render` traits together, -///// since the only way to have the cake and eat it too is by -///// implementing both traits for a given renderable. -//#[macro_export] macro_rules! render { - - //// Implement from [Content] for all [Engine]s - //(|$self:ident:$Struct:ident$(<$($L:lifetime),*E$(,$T:ident$(:$U:path)?)*$(,)?>)?|$cb:expr) => { - //impl Content for $Struct $(<$($L,)* E, $($T),*>)? { - //fn content (&$self) -> Option> { Some($cb) } - //} - //impl Render for $Struct $(<$($L,)* E, $($T),*>)? { - //fn min_size (&self, to: E::Size) -> Perhaps { - //self.content().unwrap().min_size(to) - //} - //fn render (&self, to: &mut E::Output) -> Usually<()> { - //self.content().unwrap().render(to) - //} - //} - //}; - - //// Implement from [min_size] and [render] callbacks for all engines - //($Struct:ident$(<$($L:lifetime),*E$(,$T:ident$(:$U:path)?)*$(,)?>)? - //|$self1:ident, $to1:ident|$min_size:expr, - //|$self2:ident, $to2:ident|$render:expr) => - //{ - //impl Content for $Struct $(<$($L,)* E, $($T),*>)? { - //fn content (&self) -> Option> { Some(self) } - //} - //impl Render for $Struct $(<$($L,)* E, $($T),*>)? { - //fn min_size (&$self1, $to1: E::Size) -> Perhaps { $min_size } - //fn render (&$self2, $to2: &mut E::Output) -> Usually<()> { $render } - //} - //}; - - //// Implement from [Content] for a particular [Engine] - //(<$E:ty>|$self:ident:$Struct:ident$(< - //$($($L:lifetime),+)? - //$($($T:ident$(:$U:path)?),+)? - //>)?|$cb:expr) => { - //impl $(< - //$($($L),+)? - //$($($T$(:$U)?),+)? - //>)? Content<$E> for $Struct $(< - //$($($L),+)? - //$($($T),+)? - //>)? { - //fn content (&$self) -> Option> { - //Some($cb) - //} - //} - //impl $(< - //$($($L),+)? - //$($($T$(:$U)?),+)? - //>)? Render<$E> for $Struct $(< - //$($($L),+)? - //$($($T),+)? - //>)? { - //fn min_size (&self, to: <$E as Engine>::Size) -> Perhaps<<$E as Engine>::Size> { - //self.content().map(|content|content.min_size(to)).unwrap_or(Ok(None)) - //} - //fn render (&self, to: &mut <$E as Engine>::Output) -> Usually<()> { - //self.content().map(|content|content.render(to)).unwrap_or(Ok(())) - //} - //} - //}; - - //// Implement from [min_size] and [render] callbacks for a particular [Engine] - //(<$E:ty>($self:ident:$Struct:ident$(<$($L:lifetime),*$(,$T:ident$(:$U:path)?)*$(,)?>)?) - //|$to1:ident|$min_size:expr, |$to2:ident|$render:expr) => - //{ - //impl $(< - //$($L),* $($($T$(:$U)?),+)? - //>)? Content<$E> for $Struct $(< - //$($L),* $($($T),+)? - //>)? { - //fn content (&self) -> Option> { Some(self) } - //} - //impl $(< - //$($L),* $($($T$(:$U)?),+)? - //>)? Render<$E> for $Struct $(< - //$($L),* $($($T),+)? - //>)? { - //fn min_size (&$self, $to1: <$E as Engine>::Size) -> Perhaps<<$E as Engine>::Size> { - //$min_size - //} - //fn render (&$self, $to2: &mut <$E as Engine>::Output) -> Usually<()> { - //$render - //} - //} - //} - -//} - -////impl> Content for &mut C {} -////impl> Content for Option {} -////impl> Content for Arc {} -////impl> Content for Mutex {} -////impl> Content for RwLock {} - -////impl> Render for C {} - -////impl> Render for C { - /////// Minimum size to use - ////fn min_size (&self, to: E::Size) -> Perhaps { - ////self.content().map(|content|content.min_size(to)) - ////.unwrap_or(Ok(None)) - ////} - /////// Draw to output render target - ////fn render (&self, to: &mut E::Output) -> Usually<()> { - ////self.content().map(|content|content.render(to)) - ////.unwrap_or(Ok(())) - ////} -////} - -//[>*** - - -//impl + Send + Sync> Content for R {} - -////impl> Content for R { - ////fn content (&self) -> Option> { - ////Some(self) - ////} -////} - -///// All implementors of [Content] can be [Render]ed. -//impl> Render for C { - ///// Minimum size to use - //fn min_size (&self, to: E::Size) -> Perhaps { - //self.content().map(|content|content.min_size(to)) - //.unwrap_or(Ok(None)) - //} - ///// Draw to output render target - //fn render (&self, to: &mut E::Output) -> Usually<()> { - //self.content().map(|content|content.render(to)) - //.unwrap_or(Ok(())) - //} -//} - -////impl> Content for &C { - ////fn content (&self) -> Option> { - ////Some(self) - ////} -////} - -////impl> Content for Option { - ////fn content (&self) -> Option> { - ////Some(self) - ////} -////} - - -//impl> Render for &R { - //fn min_size (&self, to: E::Size) -> Perhaps { - //(*self).min_size(to) - //} - //fn render (&self, to: &mut E::Output) -> Usually<()> { - //(*self).render(to) - //} -//} - -//impl> Render for Option { - //fn min_size (&self, to: E::Size) -> Perhaps { - //self.map(|content|content.min_size(to)) - //.unwrap_or(Ok(None)) - //} - //fn render (&self, to: &mut E::Output) -> Usually<()> { - //self.map(|content|content.render(to)) - //.unwrap_or(Ok(())) - //} -//} - -////impl Render for &dyn Render { - ////fn min_size (&self, to: E::Size) -> Perhaps { - ////(*self).min_size(to) - ////} - ////fn render (&self, to: &mut E::Output) -> Usually<()> { - ////(*self).render(to) - ////} -////} - -////impl Render for &mut dyn Render { - ////fn min_size (&self, to: E::Size) -> Perhaps { - ////(*self).min_size(to) - ////} - ////fn render (&self, to: &mut E::Output) -> Usually<()> { - ////(*self).render(to) - ////} -////} - -////impl Render for Box + '_> { - ////fn min_size (&self, to: E::Size) -> Perhaps { - ////(**self).min_size(to) - ////} - ////fn render (&self, to: &mut E::Output) -> Usually<()> { - ////(**self).render(to) - ////} -////} - -////impl> Render for Arc { - ////fn min_size (&self, to: E::Size) -> Perhaps { - ////self.as_ref().min_size(to) - ////} - ////fn render (&self, to: &mut E::Output) -> Usually<()> { - ////self.as_ref().render(to) - ////} -////} - -////impl> Render for Mutex { - ////fn min_size (&self, to: E::Size) -> Perhaps { - ////self.lock().unwrap().min_size(to) - ////} - ////fn render (&self, to: &mut E::Output) -> Usually<()> { - ////self.lock().unwrap().render(to) - ////} -////} - -////impl> Render for RwLock { - ////fn min_size (&self, to: E::Size) -> Perhaps { - ////self.read().unwrap().min_size(to) - ////} - ////fn render (&self, to: &mut E::Output) -> Usually<()> { - ////self.read().unwrap().render(to) - ////} -////} - -////impl> Render for Option { - ////fn min_size (&self, to: E::Size) -> Perhaps { - ////Ok(self.as_ref().map(|widget|widget.min_size(to)).transpose()?.flatten()) - ////} - ////fn render (&self, to: &mut E::Output) -> Usually<()> { - ////self.as_ref().map(|widget|widget.render(to)).unwrap_or(Ok(())) - ////} -////} - -///// Cast to dynamic pointer -//pub fn widget (w: &T) -> &dyn Render - //where E: Engine, T: Render -//{ - //w as &dyn Render -//} - -///// Ad-hoc widget with custom rendering. -//pub fn render (render: F) -> impl Render - //where E: Engine, F: Fn(&mut E::Output)->Usually<()>+Send+Sync -//{ - //Widget::new(|_|Ok(Some([0.into(),0.into()].into())), render) -//} - -///// 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<()> -//>(L, R, PhantomData); - -//impl< - //E: Engine, - //L: Send + Sync + Fn(E::Size)->Perhaps, - //R: Send + Sync + Fn(&mut E::Output)->Usually<()> -//> Widget { - //pub fn new (layout: L, render: R) -> Self { - //Self(layout, render, Default::default()) - //} -//} - -//impl< - //E: Engine, - //L: Send + Sync + Fn(E::Size)->Perhaps, - //R: Send + Sync + Fn(&mut E::Output)->Usually<()> -//> Render for Widget { - //fn min_size (&self, to: E::Size) -> Perhaps { - //self.0(to) - //} - //fn render (&self, to: &mut E::Output) -> Usually<()> { - //self.1(to) - //} -//} - -///// Has static methods for conditional rendering, -///// in unary and binary forms. -//pub struct Cond; - -//impl Cond { - ///// Render `item` when `cond` is true. - //pub fn when > (cond: bool, item: A) -> When { - //When(cond, item, Default::default()) - //} - ///// Render `item` if `cond` is true, otherwise render `other`. - //pub fn either , B: Render> (cond: bool, item: A, other: B) -> Either { - //Either(cond, item, other, Default::default()) - //} -//} - -///// Renders `self.1` when `self.0` is true. -//pub struct When>(bool, A, PhantomData); - -///// Renders `self.1` when `self.0` is true, otherwise renders `self.2` -//pub struct Either, B: Render>(bool, A, B, PhantomData); - - -//**/