mirror of https://github.com/wayvr-org/wayvr.git
53 lines
1.1 KiB
Rust
53 lines
1.1 KiB
Rust
use crate::{
|
|
components::{Component, slider},
|
|
layout::WidgetID,
|
|
parser::{ParserContext, ParserFile, iter_attribs, parse_check_f32, process_component, style::parse_style},
|
|
};
|
|
|
|
pub fn parse_component_slider<'a, U1, U2>(
|
|
file: &'a ParserFile,
|
|
ctx: &mut ParserContext<U1, U2>,
|
|
node: roxmltree::Node<'a, 'a>,
|
|
parent_id: WidgetID,
|
|
) -> anyhow::Result<WidgetID> {
|
|
let mut min_value = 0.0;
|
|
let mut max_value = 1.0;
|
|
let mut initial_value = 0.5;
|
|
|
|
let attribs: Vec<_> = iter_attribs(file, ctx, &node, false).collect();
|
|
let style = parse_style(&attribs);
|
|
|
|
for (key, value) in attribs {
|
|
match key.as_ref() {
|
|
"min_value" => {
|
|
parse_check_f32(value.as_ref(), &mut min_value);
|
|
}
|
|
"max_value" => {
|
|
parse_check_f32(value.as_ref(), &mut max_value);
|
|
}
|
|
"value" => {
|
|
parse_check_f32(value.as_ref(), &mut initial_value);
|
|
}
|
|
_ => {}
|
|
}
|
|
}
|
|
|
|
let (new_id, component) = slider::construct(
|
|
ctx.layout,
|
|
ctx.listeners,
|
|
parent_id,
|
|
slider::Params {
|
|
style,
|
|
values: slider::ValuesMinMax {
|
|
min_value,
|
|
max_value,
|
|
value: initial_value,
|
|
},
|
|
},
|
|
)?;
|
|
|
|
process_component(file, ctx, node, Component(component));
|
|
|
|
Ok(new_id)
|
|
}
|