Merge remote-tracking branch 'origin/main' into next-dash-interface

[skip ci]
This commit is contained in:
Aleksander
2025-12-23 19:24:08 +01:00
46 changed files with 1858 additions and 606 deletions

View File

@@ -1,13 +1,13 @@
use crate::{
assets::AssetPath,
components::{button, tooltip, Component},
components::{Component, button, tooltip},
drawing::Color,
i18n::Translation,
layout::WidgetID,
parser::{
parse_check_f32, parse_check_i32, parse_children, parse_f32, print_invalid_attrib, process_component,
AttribPair, ParserContext, ParserFile, parse_check_f32, parse_check_i32, parse_children, parse_f32,
print_invalid_attrib, process_component,
style::{parse_color_opt, parse_round, parse_style, parse_text_style},
AttribPair, ParserContext, ParserFile,
},
widget::util::WLength,
};

View File

@@ -3,6 +3,7 @@ mod component_checkbox;
mod component_slider;
mod style;
mod widget_div;
mod widget_image;
mod widget_label;
mod widget_rectangle;
mod widget_sprite;
@@ -15,8 +16,8 @@ use crate::{
layout::{Layout, LayoutParams, LayoutState, Widget, WidgetID, WidgetMap, WidgetPair},
parser::{
component_button::parse_component_button, component_checkbox::parse_component_checkbox,
component_slider::parse_component_slider, widget_div::parse_widget_div, widget_label::parse_widget_label,
widget_rectangle::parse_widget_rectangle, widget_sprite::parse_widget_sprite,
component_slider::parse_component_slider, widget_div::parse_widget_div, widget_image::parse_widget_image,
widget_label::parse_widget_label, widget_rectangle::parse_widget_rectangle, widget_sprite::parse_widget_sprite,
},
widget::ConstructEssentials,
};
@@ -898,6 +899,9 @@ fn parse_child<'a>(
"sprite" => {
new_widget_id = Some(parse_widget_sprite(file, ctx, child_node, parent_id, &attribs)?);
}
"image" => {
new_widget_id = Some(parse_widget_image(file, ctx, child_node, parent_id, &attribs)?);
}
"Button" => {
new_widget_id = Some(parse_component_button(file, ctx, child_node, parent_id, &attribs)?);
}

View File

@@ -0,0 +1,77 @@
use crate::{
assets::AssetPath,
layout::WidgetID,
parser::{
AttribPair, ParserContext, ParserFile, parse_children, parse_widget_universal, print_invalid_attrib,
style::{parse_color, parse_round, parse_style},
},
renderer_vk::text::custom_glyph::{CustomGlyphContent, CustomGlyphData},
widget::image::{WidgetImage, WidgetImageParams},
};
pub fn parse_widget_image<'a>(
file: &ParserFile,
ctx: &mut ParserContext,
node: roxmltree::Node<'a, 'a>,
parent_id: WidgetID,
attribs: &[AttribPair],
) -> anyhow::Result<WidgetID> {
let mut params = WidgetImageParams::default();
let style = parse_style(attribs);
let mut glyph = None;
for pair in attribs {
let (key, value) = (pair.attrib.as_ref(), pair.value.as_ref());
match key {
"src" | "src_ext" | "src_builtin" | "src_internal" => {
let asset_path = match key {
"src" => AssetPath::FileOrBuiltIn(value),
"src_ext" => AssetPath::File(value),
"src_builtin" => AssetPath::BuiltIn(value),
"src_internal" => AssetPath::WguiInternal(value),
_ => unreachable!(),
};
if !value.is_empty() {
glyph = match CustomGlyphContent::from_assets(&mut ctx.layout.state.globals, asset_path) {
Ok(glyph) => Some(glyph),
Err(e) => {
log::warn!("failed to load {value}: {e}");
None
}
}
}
}
"round" => {
parse_round(
value,
&mut params.round,
ctx.doc_params.globals.get().defaults.rounding_mult,
);
}
"border" => {
params.border = value.parse().unwrap_or_else(|_| {
print_invalid_attrib(key, value);
0.0
});
}
"border_color" => {
parse_color(value, &mut params.border_color);
}
_ => {}
}
}
if let Some(glyph) = glyph {
params.glyph_data = Some(CustomGlyphData::new(glyph));
} else {
log::warn!("No source for image node!");
}
let (widget, _) = ctx.layout.add_child(parent_id, WidgetImage::create(params), style)?;
parse_widget_universal(ctx, &widget, attribs);
parse_children(file, ctx, node, widget.id)?;
Ok(widget.id)
}