attribs rework
This commit is contained in:
@@ -2,9 +2,9 @@ use crate::{
|
||||
drawing::GradientMode,
|
||||
layout::WidgetID,
|
||||
parser::{
|
||||
ParserContext, ParserFile, iter_attribs, parse_children, parse_widget_universal,
|
||||
print_invalid_attrib,
|
||||
parse_children, parse_widget_universal, print_invalid_attrib,
|
||||
style::{parse_color, parse_round, parse_style},
|
||||
AttribPair, ParserContext, ParserFile,
|
||||
},
|
||||
widget::rectangle::{WidgetRectangle, WidgetRectangleParams},
|
||||
};
|
||||
@@ -14,42 +14,43 @@ pub fn parse_widget_rectangle<'a, U1, U2>(
|
||||
ctx: &mut ParserContext<U1, U2>,
|
||||
node: roxmltree::Node<'a, 'a>,
|
||||
parent_id: WidgetID,
|
||||
attribs: &[AttribPair],
|
||||
) -> anyhow::Result<WidgetID> {
|
||||
let mut params = WidgetRectangleParams::default();
|
||||
let attribs: Vec<_> = iter_attribs(file, ctx, &node, false).collect();
|
||||
let style = parse_style(&attribs);
|
||||
|
||||
for (key, value) in attribs {
|
||||
match &*key {
|
||||
for pair in attribs {
|
||||
let (key, value) = (pair.attrib.as_ref(), pair.value.as_ref());
|
||||
match key {
|
||||
"color" => {
|
||||
parse_color(&value, &mut params.color);
|
||||
parse_color(value, &mut params.color);
|
||||
}
|
||||
"color2" => {
|
||||
parse_color(&value, &mut params.color2);
|
||||
parse_color(value, &mut params.color2);
|
||||
}
|
||||
"gradient" => {
|
||||
params.gradient = match &*value {
|
||||
params.gradient = match value {
|
||||
"horizontal" => GradientMode::Horizontal,
|
||||
"vertical" => GradientMode::Vertical,
|
||||
"radial" => GradientMode::Radial,
|
||||
"none" => GradientMode::None,
|
||||
_ => {
|
||||
print_invalid_attrib(&key, &value);
|
||||
print_invalid_attrib(key, value);
|
||||
GradientMode::None
|
||||
}
|
||||
}
|
||||
}
|
||||
"round" => {
|
||||
parse_round(&value, &mut params.round);
|
||||
parse_round(value, &mut params.round);
|
||||
}
|
||||
"border" => {
|
||||
params.border = value.parse().unwrap_or_else(|_| {
|
||||
print_invalid_attrib(&key, &value);
|
||||
print_invalid_attrib(key, value);
|
||||
0.0
|
||||
});
|
||||
}
|
||||
"border_color" => {
|
||||
parse_color(&value, &mut params.border_color);
|
||||
parse_color(value, &mut params.border_color);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
@@ -59,7 +60,7 @@ pub fn parse_widget_rectangle<'a, U1, U2>(
|
||||
.layout
|
||||
.add_child(parent_id, WidgetRectangle::create(params), style)?;
|
||||
|
||||
parse_widget_universal(file, ctx, node, new_id);
|
||||
parse_widget_universal(ctx, new_id, attribs);
|
||||
parse_children(file, ctx, node, new_id)?;
|
||||
|
||||
Ok(new_id)
|
||||
|
||||
Reference in New Issue
Block a user