use std::sync::Arc; use crate::{ state::DependencyHandler, widget::{Widget, WidgetLoad}, Screen, }; pub enum RsxElement { Element( Box WidgetLoad + Send + Sync>, Vec>, Rsx, ), } pub struct Rsx(pub Vec); impl Rsx { pub fn draw(self, screen: &Arc) { self.draw_parent(screen, None); } pub fn draw_parent(self, screen: &Arc, parent: Option>) { for rsx_elem in self.0 { match rsx_elem { RsxElement::Element(f, dep, child) => { let w = if let Some(parent) = &parent { let w = screen.draw_box(f); parent.0.lock().unwrap().draw_child(&w); w } else { screen.draw_box(f) }; for d in dep { w.dependency_box(d); } child.draw_parent(screen, Some(w.clone())); } } } } pub fn create_element WidgetLoad + Send + Sync + 'static>( &mut self, load: F, dependencies: Vec>, children: Rsx, ) { self.0 .push(RsxElement::Element(Box::new(load), dependencies, children)); } pub fn expand(&mut self, other: &mut Rsx) { self.0.append(&mut other.0); } }