diff --git a/wgui/src/layout.rs b/wgui/src/layout.rs index 861c038..28775ad 100644 --- a/wgui/src/layout.rs +++ b/wgui/src/layout.rs @@ -65,15 +65,20 @@ fn add_child_internal( } impl Layout { + pub fn get_node(&self, widget_id: WidgetID) -> anyhow::Result { + let Some(node) = self.widget_node_map.get(&widget_id).cloned() else { + anyhow::bail!("invalid parent widget"); + }; + Ok(node) + } + pub fn add_child( &mut self, parent_widget_id: WidgetID, widget: WidgetState, style: taffy::Style, ) -> anyhow::Result<(WidgetID, taffy::NodeId)> { - let Some(parent_node) = self.widget_node_map.get(&parent_widget_id).cloned() else { - anyhow::bail!("invalid parent widget"); - }; + let parent_node = self.get_node(parent_widget_id)?; self.needs_redraw = true; diff --git a/wgui/src/parser/mod.rs b/wgui/src/parser/mod.rs index fd596ce..04e73f6 100644 --- a/wgui/src/parser/mod.rs +++ b/wgui/src/parser/mod.rs @@ -15,7 +15,6 @@ use crate::{ }; use ouroboros::self_referencing; use std::{ - cell::RefCell, collections::HashMap, path::{Path, PathBuf}, rc::Rc, @@ -32,20 +31,21 @@ struct XmlDocument { doc: roxmltree::Document<'this>, } -struct Template { +pub struct Template { node_document: Rc, node: roxmltree::NodeId, // belongs to node_document which could be included in another file } -struct ParserFile<'a> { +struct ParserFile { path: PathBuf, document: Rc, - ctx: Rc>>, template_parameters: HashMap, Rc>, } pub struct ParserResult { - ids: HashMap, WidgetID>, + pub ids: HashMap, WidgetID>, + pub templates: HashMap, Rc