use crate::{Axis, LayoutLen, Painter, Size}; use std::any::Any; mod data; mod handle; mod like; mod tag; mod view; mod widgets; pub use data::*; pub use handle::*; pub use like::*; pub use tag::*; pub use view::*; pub use widgets::*; #[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] pub enum ChildOrder { /// The order in which the parent drew its children. #[default] Draw, /// Ascending visual position on one screen axis. Equal positions keep /// draw order; the resolved coordinates are sorted only when queried. Axis(Axis), } pub trait Widget: Any { fn draw(&mut self, painter: &mut Painter); fn size_hint(&self, _axis: Axis) -> Option { None } fn is_size_independent(&self) -> bool { false } fn requires_exact_region(&self) -> bool { false } fn access_role(&self) -> accesskit::Role { accesskit::Role::Unknown } fn child_order(&self) -> ChildOrder { ChildOrder::Draw } } impl Widget for () { fn draw(&mut self, painter: &mut Painter) { painter.set_size(Size::ZERO); } fn is_size_independent(&self) -> bool { true } fn size_hint(&self, _axis: Axis) -> Option { Some(LayoutLen::ZERO) } } impl dyn Widget { pub fn as_any(&self) -> &dyn Any { self } pub fn as_any_mut(&mut self) -> &mut dyn Any { self } } pub trait WidgetFn: FnOnce(&mut State) -> W {} impl W> WidgetFn for F {} pub struct WidgetArr { pub arr: [StrongWidget; LEN], } impl WidgetArr { pub fn new(arr: [StrongWidget; LEN]) -> Self { Self { arr } } } pub trait WidgetOption { fn get(self, state: &mut State) -> Option; } impl WidgetOption for () { fn get(self, _: &mut State) -> Option { None } } impl Option> WidgetOption for F { fn get(self, state: &mut State) -> Option { self(state) } }