mod custom;
mod div;
mod text;
pub use custom::*;
pub use div::*;
use embedded_graphics::{
draw_target::DrawTarget, geometry::Size, pixelcolor::PixelColor, primitives::Rectangle,
};
pub use text::*;
use crate::{NodeIndex, Theme};
#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum BuildError {
#[error("node capacity exceeded")]
NodeCapacity,
#[error("text capacity exceeded")]
TextCapacity,
}
pub trait ElementBuilder {
fn try_build(self) -> Result<NodeIndex, BuildError>;
}
pub trait ParentElement {
fn extend<E: ElementBuilder>(&mut self, elements: impl IntoIterator<Item = E>);
fn child<E: ElementBuilder>(mut self, child: E) -> Self
where
Self: Sized,
{
self.extend(core::iter::once(child));
self
}
fn children<E: ElementBuilder>(mut self, children: impl IntoIterator<Item = E>) -> Self
where
Self: Sized,
{
self.extend(children);
self
}
}
pub trait CustomElement<C: PixelColor> {
fn intrinsic_size(&self) -> Size;
fn draw<D>(&self, bounds: &Rectangle, theme: &Theme<C>, target: &mut D) -> Result<(), D::Error>
where
D: DrawTarget<Color = C>;
}
pub enum NoCustomElement {}
impl<C: PixelColor> CustomElement<C> for NoCustomElement {
fn intrinsic_size(&self) -> Size {
match *self {}
}
fn draw<D>(
&self,
_bounds: &Rectangle,
_theme: &Theme<C>,
_target: &mut D,
) -> Result<(), D::Error>
where
D: DrawTarget<Color = C>,
{
match *self {}
}
}