From 09ea4f3096dea2ac44e7ef630cd791c6474153f2 Mon Sep 17 00:00:00 2001 From: Aleksander Date: Wed, 18 Jun 2025 21:30:32 +0200 Subject: [PATCH] wgui: parser: template injection support --- wgui/src/layout.rs | 11 ++- wgui/src/parser/mod.rs | 114 ++++++++++++++++++------- wlx-overlay-s/src/assets/key.xml | 20 ++++- wlx-overlay-s/src/overlays/keyboard.rs | 46 +++++----- 4 files changed, 134 insertions(+), 57 deletions(-) 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