reactivity base
This commit is contained in:
@@ -1,66 +1,8 @@
|
||||
mod node;
|
||||
pub use node::*;
|
||||
mod ui;
|
||||
mod widget;
|
||||
|
||||
use crate::primitive::{Color, Painter};
|
||||
pub use ui::*;
|
||||
pub use widget::*;
|
||||
|
||||
use crate::primitive::Color;
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user