Add action button component for rendering the search options

This commit is contained in:
Mikayla 2023-08-17 15:30:40 -07:00
parent f451e3423d
commit 8630557ece
No known key found for this signature in database
11 changed files with 223 additions and 35 deletions

View file

@ -7,6 +7,34 @@ use crate::{
ViewContext,
};
use super::Empty;
pub trait GeneralComponent {
fn render<V: View>(self, v: &mut V, cx: &mut ViewContext<V>) -> AnyElement<V>;
}
pub trait StyleableComponent {
type Style: Clone;
type Output: GeneralComponent;
fn with_style(self, style: Self::Style) -> Self::Output;
}
impl GeneralComponent for () {
fn render<V: View>(self, _: &mut V, _: &mut ViewContext<V>) -> AnyElement<V> {
Empty::new().into_any()
}
}
impl StyleableComponent for () {
type Style = ();
type Output = ();
fn with_style(self, _: Self::Style) -> Self::Output {
()
}
}
pub trait Component<V: View> {
fn render(self, v: &mut V, cx: &mut ViewContext<V>) -> AnyElement<V>;
@ -18,6 +46,12 @@ pub trait Component<V: View> {
}
}
impl<V: View, C: GeneralComponent> Component<V> for C {
fn render(self, v: &mut V, cx: &mut ViewContext<V>) -> AnyElement<V> {
self.render(v, cx)
}
}
pub struct ComponentAdapter<V, E> {
component: Option<E>,
phantom: PhantomData<V>,