use std::rc::Rc;
use crate::{annotations::Annotations, props::ExtendingProps, Style};
#[cfg(feature = "gtk")]
pub use super::gtk_components::*;
pub type Component = Rc<dyn ComponentExt>;
pub trait ComponentExt {
fn visible(&self) -> bool;
fn height(&self) -> i32;
fn width(&self) -> i32;
fn set_visible(&self, visible: bool);
fn add_class(&self, class: &str);
fn classes(&self) -> Vec<String>;
fn remove_class(&self, class: &str);
fn set_styles(&self, styles: Vec<Style>);
fn inner(&self) -> Rc<dyn std::any::Any>;
fn props(&self) -> &dyn ExtendingProps;
fn annotations(&self) -> std::cell::Ref<'_, Annotations>;
fn annotations_mut(&self) -> std::cell::RefMut<'_, Annotations>;
fn try_annotations_mut(
&self,
) -> Result<std::cell::RefMut<'_, Annotations>, std::cell::BorrowMutError>;
fn children(&self) -> std::cell::Ref<Vec<Component>>;
fn children_mut(&self) -> std::cell::RefMut<Vec<Component>>;
fn into_any(self: Rc<Self>) -> Rc<dyn std::any::Any>;
}
pub trait ItemExt: std::fmt::Debug {
fn id(&self) -> String;
fn value(&self) -> String;
}
impl std::fmt::Debug for dyn ComponentExt {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Component")
.field("props", &self.props())
.finish()
}
}
pub trait ContainerExt {
fn append<W>(self: &Rc<Self>, child: Rc<W>)
where
W: ComponentExt + ?Sized;
fn remove<W>(self: &Rc<Self>, child: Rc<W>)
where
W: ComponentExt + ?Sized;
fn clear(self: &Rc<Self>);
}
pub trait Textual {
fn text(self: &Rc<Self>) -> String;
fn set_text(self: &Rc<Self>, text: &str);
}
pub trait Interactable
where
Self: Sized,
{
#[allow(unused_variables)]
fn on_click(self: &Rc<Self>, handler: impl Fn(&Rc<Self>) + 'static) {
}
#[allow(unused_variables)]
fn on_change(self: &Rc<Self>, handler: impl Fn(&Rc<Self>) + 'static) {
}
#[allow(unused_variables)]
fn on_swipe(self: &Rc<Self>, handler: impl Fn(&Rc<Self>, f64, f64) + 'static) {
}
#[allow(unused_variables)]
fn on_blur(self: &Rc<Self>, handler: impl Fn(&Rc<Self>) + 'static) {
}
}