initial commit

This commit is contained in:
2025-08-08 18:22:52 -04:00
parent eba8481bde
commit 56beeb80f3
31 changed files with 1223 additions and 1197 deletions

66
src/layout/mod.rs Normal file
View File

@@ -0,0 +1,66 @@
mod node;
pub use node::*;
use crate::primitive::{Color, Painter};
pub type UIColor = Color<u8>;
pub trait UINode: 'static {
fn draw(&self, painter: &mut Painter);
}
pub struct UI {
base: Box<dyn UINode>,
}
impl UI {
pub fn to_primitives(&self) -> Painter {
let mut painter = Painter::default();
self.base.draw(&mut painter);
painter
}
}
impl<N: UINode> From<N> for UI {
fn from(node: N) -> Self {
Self {
base: Box::new(node),
}
}
}
impl UINode for Box<dyn UINode> {
fn draw(&self, painter: &mut Painter) {
self.as_ref().draw(painter);
}
}
pub trait NodeArray<const LEN: usize> {
fn to_arr(self) -> [Box<dyn UINode>; LEN];
}
// I hate this language it's so bad why do I even use it
macro_rules! impl_node_arr {
($n:expr;$($T:tt)+) => {
impl<$($T: UINode,)*> NodeArray<$n> for ($($T,)*) {
fn to_arr(self) -> [Box<dyn UINode>; $n] {
#[allow(non_snake_case)]
let ($($T,)*) = self;
[$(Box::new($T),)*]
}
}
};
}
impl_node_arr!(1;A);
impl_node_arr!(2;A B);
impl_node_arr!(3;A B C);
impl_node_arr!(4;A B C D);
impl_node_arr!(5;A B C D E);
impl_node_arr!(6;A B C D E F);
impl_node_arr!(7;A B C D E F G);
impl_node_arr!(8;A B C D E F G H);
impl_node_arr!(9;A B C D E F G H I);
impl_node_arr!(10;A B C D E F G H I J);
impl_node_arr!(11;A B C D E F G H I J K);
impl_node_arr!(12;A B C D E F G H I J K L);