You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.2 KiB
Rust
52 lines
1.2 KiB
Rust
use std::any::Any;
|
|
use std::marker::PhantomData;
|
|
use std::ops::{Deref, DerefMut};
|
|
|
|
use crate::backend::{Backend, Render, TargetBackend};
|
|
use crate::view::{Construct, SomeView, Template, View};
|
|
|
|
pub trait NewCustom<B: Backend = TargetBackend>: Sized {
|
|
type Params: Default;
|
|
|
|
fn new(params: Self::Params) -> Self;
|
|
}
|
|
|
|
pub trait NewCustomGroup<B: Backend = TargetBackend>: NewCustom<B> {
|
|
fn new_group<'a, I>(params: Self::Params, children: I) -> Self
|
|
where
|
|
I: IntoIterator<Item = &'a View<B>>;
|
|
}
|
|
|
|
pub trait GetTemplate<B: Backend = TargetBackend> {
|
|
fn get_template(&self) -> Template;
|
|
}
|
|
|
|
pub trait CustomComponent<B: Backend = TargetBackend>: Any + Send + GetTemplate {}
|
|
|
|
pub struct ComponentWrapper<C: CustomComponent<B>, B: Backend = TargetBackend> {
|
|
component: C,
|
|
_backend: PhantomData<B>,
|
|
}
|
|
|
|
impl<C, B> Deref for ComponentWrapper<C, B>
|
|
where
|
|
B: Backend,
|
|
C: CustomComponent<B>,
|
|
{
|
|
type Target = C;
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
&self.component
|
|
}
|
|
}
|
|
|
|
impl<C, B> DerefMut for ComponentWrapper<C, B>
|
|
where
|
|
B: Backend,
|
|
C: CustomComponent<B>,
|
|
{
|
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
&mut self.component
|
|
}
|
|
}
|