Added rsx element fields #20
This commit is contained in:
+5
-5
@@ -19,7 +19,7 @@ pub fn app(screen: Arc<Screen>) -> Rsx {
|
||||
move |_, _: &crossterm::event::Event| {
|
||||
screen.close();
|
||||
}});
|
||||
FlexRow {
|
||||
FlexRow, gap: 1, {
|
||||
FlexCol {
|
||||
@Transform::new().padding(2, 2);
|
||||
@Style { foreground: None, background: Background::RoundedOutline(0x00ff00) };
|
||||
@@ -34,14 +34,14 @@ pub fn app(screen: Arc<Screen>) -> Rsx {
|
||||
}
|
||||
|
||||
// TODO: div with width full
|
||||
} (1)
|
||||
}
|
||||
|
||||
FlexCol {
|
||||
Div {
|
||||
static Div { // static only affects the element, not children
|
||||
%count
|
||||
"This will increment every second: {count}"
|
||||
}
|
||||
} (2)
|
||||
} (0)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,33 +6,33 @@ use crate::{
|
||||
};
|
||||
|
||||
pub struct FlexRow {
|
||||
gap: u16,
|
||||
pub gap: u16,
|
||||
children: Mutex<Vec<Arc<Widget>>>,
|
||||
size: (u16, u16),
|
||||
}
|
||||
|
||||
pub struct FlexCol {
|
||||
gap: u16,
|
||||
pub gap: u16,
|
||||
children: Mutex<Vec<Arc<Widget>>>,
|
||||
size: (u16, u16),
|
||||
}
|
||||
|
||||
impl FlexRow {
|
||||
pub fn new(gap: u16) -> Self {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
children: Mutex::new(Vec::new()),
|
||||
size: (0, 0),
|
||||
gap,
|
||||
gap: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FlexCol {
|
||||
pub fn new(gap: u16) -> Self {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
children: Mutex::new(Vec::new()),
|
||||
size: (0, 0),
|
||||
gap,
|
||||
gap: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-6
@@ -46,13 +46,11 @@ impl Rsx {
|
||||
for rsx_elem in self.0 {
|
||||
match rsx_elem {
|
||||
RsxElement::DynElement(f, dep, child) => {
|
||||
let w = if let Some(parent) = &parent {
|
||||
let w = screen.draw_box_dyn(f);
|
||||
let w = screen.draw_box_dyn(f);
|
||||
|
||||
if let Some(parent) = &parent {
|
||||
parent.get_elem().draw_child(&w);
|
||||
w
|
||||
} else {
|
||||
screen.draw_box_dyn(f)
|
||||
};
|
||||
}
|
||||
|
||||
for d in dep {
|
||||
w.dependency_box(d);
|
||||
|
||||
+14
-7
@@ -256,24 +256,31 @@ macro_rules! rsx_inner {
|
||||
};
|
||||
|
||||
// static
|
||||
($r:expr, $(@$comp:expr;)* static $name:path { $($inner:tt)* } ($($e:expr),*) $($rest:tt)*) => {
|
||||
let w = $crate::widget::StaticWidget::new(Box::new(<$name>::new($($e),*)));
|
||||
($r:expr, $(@$comp:expr;)* static $name:path, $($f:ident $(: $v:expr)?),+, { $($inner:tt)* } $($rest:tt)*) => {
|
||||
let w = $crate::widget::StaticWidget::new(Box::new({
|
||||
let mut elem = <$name>::new();
|
||||
$(elem.$f = $($v)?;)+
|
||||
elem
|
||||
}));
|
||||
$(w.component($comp);)*
|
||||
$r.create_element_static(w, $crate::frontend::Rsx(Vec::new()));
|
||||
$r.create_element_static(w, $crate::rsx!{ $($inner)* });
|
||||
$crate::rsx_inner! { $r, $($rest)* };
|
||||
};
|
||||
|
||||
// static
|
||||
($r:expr, $(@$comp:expr;)* static $name:path { $($inner:tt)* } $($rest:tt)*) => {
|
||||
let w = $crate::widget::StaticWidget::new(Box::new(<$name>::new()));
|
||||
$(w.component($comp);)*
|
||||
$r.create_element_static(w, $crate::frontend::Rsx(Vec::new()));
|
||||
$r.create_element_static(w, $crate::rsx!{ $($inner)* });
|
||||
$crate::rsx_inner! { $r, $($rest)* };
|
||||
};
|
||||
|
||||
($r:expr, $(@$comp:expr;)* $(%$dep:ident)* $name:path { $($inner:tt)* } ($($e:expr),*) $($rest:tt)*) => {
|
||||
($r:expr, $(@$comp:expr;)* $(%$dep:ident)* $name:path, $($f:ident $(: $v:expr)?),+, { $($inner:tt)* } $($rest:tt)*) => {
|
||||
$r.create_element({ $(let $dep = $dep.clone();)* move || {
|
||||
$crate::widget::WidgetLoad::new(<$name>::new($($e),*)) $(.component($comp))*
|
||||
$crate::widget::WidgetLoad::new({
|
||||
let mut elem = <$name>::new();
|
||||
$(elem.$f = $($v)?;)+
|
||||
elem
|
||||
}) $(.component($comp))*
|
||||
} }, vec![$(Box::new($dep.clone())),*], $crate::rsx!{ $($inner)* });
|
||||
$crate::rsx_inner! { $r, $($rest)* };
|
||||
};
|
||||
|
||||
+5
-2
@@ -173,13 +173,16 @@ impl Widget {
|
||||
|
||||
pub fn inject<F: FnMut(WidgetLoad) -> WidgetLoad + 'static + Send + Sync>(
|
||||
self: &Arc<Self>,
|
||||
f: F,
|
||||
mut f: F,
|
||||
) {
|
||||
match &**self {
|
||||
Widget::Dynamic(w) => {
|
||||
w.inject(f);
|
||||
}
|
||||
Widget::Static(_) => {}
|
||||
Widget::Static(w) => {
|
||||
let wl = WidgetLoad::new(String::new());
|
||||
w.1.lock().unwrap().extend(f(wl).1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user