Refactored the frontend to work with static widgets #11

This commit is contained in:
2025-08-01 16:32:56 -05:00
parent 45db1fb774
commit 73e2c214ee
4 changed files with 39 additions and 14 deletions
+12 -12
View File
@@ -2,12 +2,12 @@ use std::sync::Arc;
use crate::{
state::DependencyHandler,
widget::{BoxedElement, Widget, WidgetLoad},
widget::{StaticWidget, Widget, WidgetLoad},
Screen,
};
pub enum RsxElement {
Element(BoxedElement, Vec<Box<dyn DependencyHandler>>, Rsx),
Element(Arc<StaticWidget>, Rsx),
DynElement(
Box<dyn FnMut() -> WidgetLoad + Send + Sync>,
@@ -41,18 +41,14 @@ impl Rsx {
child.draw_parent(screen, Some(w.clone()));
}
RsxElement::Element(f, dep, child) => {
let w = if let Some(parent) = &parent {
let w = screen.draw_box(f);
parent.get_elem().draw_child(&w);
w
} else {
screen.draw_box(f)
};
RsxElement::Element(ws, child) => {
let w = Arc::new(Widget::Static(ws));
screen.draw_widget(w.clone());
for d in dep {
w.dependency_box(d);
if let Some(parent) = &parent {
parent.get_elem().draw_child(&w);
}
child.draw_parent(screen, Some(w.clone()));
}
}
@@ -72,6 +68,10 @@ impl Rsx {
));
}
pub fn create_element_static(&mut self, element: Arc<StaticWidget>, children: Rsx) {
self.0.push(RsxElement::Element(element, children));
}
pub fn expand(&mut self, other: &mut Rsx) {
self.0.append(&mut other.0);
}