wgui: move parser.rs into a separate directory

This commit is contained in:
Aleksander
2025-06-18 20:07:13 +02:00
parent 021f98973d
commit b9e462f88b
7 changed files with 1013 additions and 975 deletions
+57
View File
@@ -0,0 +1,57 @@
use crate::{
layout::WidgetID,
parser::{
ParserContext, ParserFile, iter_attribs, parse_children, parse_universal,
style::style_from_node,
},
renderer_vk::text::custom_glyph::{CustomGlyphContent, CustomGlyphData},
widget::sprite::{SpriteBox, SpriteBoxParams},
};
pub fn parse_widget_sprite<'a>(
file: &'a ParserFile,
ctx: &mut ParserContext,
node: roxmltree::Node<'a, 'a>,
parent_id: WidgetID,
) -> anyhow::Result<()> {
let mut params = SpriteBoxParams::default();
let attribs: Vec<_> = iter_attribs(file, ctx, &node).collect();
let mut glyph = None;
for (key, value) in attribs {
match key.as_ref() {
"src" => {
glyph = match CustomGlyphContent::from_assets(&mut ctx.layout.assets, &value) {
Ok(glyph) => Some(glyph),
Err(e) => {
log::warn!("failed to load {}: {}", value, e);
None
}
}
}
"src_ext" => {
if std::fs::exists(value.as_ref()).unwrap_or(false) {
glyph = CustomGlyphContent::from_file(&value).ok();
}
}
_ => {}
}
}
if let Some(glyph) = glyph {
params.glyph_data = Some(CustomGlyphData::new(glyph));
} else {
log::warn!("No source for sprite node!");
};
let style = style_from_node(file, ctx, node);
let (new_id, _) = ctx
.layout
.add_child(parent_id, SpriteBox::create(params)?, style)?;
parse_universal(file, ctx, node, new_id)?;
parse_children(file, ctx, node, new_id)?;
Ok(())
}