use crate::{
graphics::{Shape, Size},
ToAny,
};
mod button;
mod container;
mod image;
mod label;
mod layout;
mod toolbar;
pub use button::Button;
pub use container::Container;
pub use image::Image;
pub use label::Label;
pub use layout::Layout;
pub use toolbar::ToolBar;
pub trait Widget: DebugWidget + ToAny {
fn shape(&self, size: Option<Size>) -> Shape;
}
pub trait DebugWidget: std::fmt::Debug {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}
#[macro_export]
macro_rules! dynamic_widget {
($t:ty) => {
impl ToAny for $t {
fn as_any(&self) -> &dyn std::any::Any {
self
}
}
impl From<$t> for Box<dyn Widget> {
fn from(value: $t) -> Self {
Box::new(value)
}
}
impl DebugWidget for $t {}
};
}
#[macro_export]
macro_rules! dynamic_controller {
($t:ty) => {
impl<'a, T: Widget + 'static> ToAny for $t {
fn as_any(&self) -> &dyn std::any::Any {
self.widget.as_any()
}
}
impl<'a, T: Widget + 'static> From<$t> for Box<dyn Widget> {
fn from(value: $t) -> Self {
Box::new(value)
}
}
impl<'a, T: Widget> DebugWidget for $t {}
};
}
#[macro_export]
macro_rules! widgets {
() => {
vec![]
};
($first:expr $(, $widget:expr) *,) => {
widgets![$first, $($widget),*]
};
($first:expr $(, $widget:expr) *) => {
{
let widgets: Vec<Box<dyn Widget>> = vec![
$first.into(),
$($widget.into()),*
];
widgets
}
};
}