Add GrowDirection to xml values
This commit is contained in:
parent
2f7ad1fc76
commit
4bb62bcfe8
2 changed files with 35 additions and 13 deletions
|
@ -11,7 +11,9 @@ use std::{
|
||||||
sync::{Arc, RwLock, Weak},
|
sync::{Arc, RwLock, Weak},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::validator::{cow_to_fill_type, cow_to_str, cow_to_text_alignment, str_into};
|
use super::validator::{
|
||||||
|
cow_to_fill_type, cow_to_grow_direction, cow_to_str, cow_to_text_alignment, str_into,
|
||||||
|
};
|
||||||
|
|
||||||
pub struct ProgressBarInfo {
|
pub struct ProgressBarInfo {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
|
@ -39,7 +41,7 @@ impl ProgressBarInfo {
|
||||||
attributes: quick_xml::events::attributes::Attributes<'a>,
|
attributes: quick_xml::events::attributes::Attributes<'a>,
|
||||||
grid: &Arc<GridInfo>,
|
grid: &Arc<GridInfo>,
|
||||||
) -> Result<ProgressBarInfo> {
|
) -> Result<ProgressBarInfo> {
|
||||||
let mut label_info = ProgressBarInfo {
|
let mut progress_bar_info = ProgressBarInfo {
|
||||||
id: String::new(),
|
id: String::new(),
|
||||||
|
|
||||||
x_slot: Mandatory::default(),
|
x_slot: Mandatory::default(),
|
||||||
|
@ -64,20 +66,27 @@ impl ProgressBarInfo {
|
||||||
let attribute = attribute_res?;
|
let attribute = attribute_res?;
|
||||||
|
|
||||||
match attribute.key.into_inner() {
|
match attribute.key.into_inner() {
|
||||||
b"id" => label_info.id = cow_to_str(attribute.value),
|
b"id" => progress_bar_info.id = cow_to_str(attribute.value),
|
||||||
b"x_slot" => label_info.x_slot.set(str_into(attribute.value)?),
|
b"x_slot" => progress_bar_info.x_slot.set(str_into(attribute.value)?),
|
||||||
b"y_slot" => label_info.y_slot.set(str_into(attribute.value)?),
|
b"y_slot" => progress_bar_info.y_slot.set(str_into(attribute.value)?),
|
||||||
b"x_size" => label_info.x_dim = str_into(attribute.value)?,
|
b"x_size" => progress_bar_info.x_dim = str_into(attribute.value)?,
|
||||||
b"y_size" => label_info.y_dim = str_into(attribute.value)?,
|
b"y_size" => progress_bar_info.y_dim = str_into(attribute.value)?,
|
||||||
b"background" => label_info.background = Some(cow_to_fill_type(attribute.value)),
|
b"background" => {
|
||||||
b"foreground" => label_info.foreground = Some(cow_to_fill_type(attribute.value)),
|
progress_bar_info.background = Some(cow_to_fill_type(attribute.value))
|
||||||
|
}
|
||||||
|
b"foreground" => {
|
||||||
|
progress_bar_info.foreground = Some(cow_to_fill_type(attribute.value))
|
||||||
|
}
|
||||||
|
b"direction" => {
|
||||||
|
progress_bar_info.direction = Some(cow_to_grow_direction(attribute.value)?)
|
||||||
|
}
|
||||||
b"text_color" => {
|
b"text_color" => {
|
||||||
let text = cow_to_str(attribute.value);
|
let text = cow_to_str(attribute.value);
|
||||||
label_info.text_color = Color::try_from(text.as_str())?;
|
progress_bar_info.text_color = Color::try_from(text.as_str())?;
|
||||||
}
|
}
|
||||||
b"text_ratio" => label_info.text_ratio = Some(str_into(attribute.value)?),
|
b"text_ratio" => progress_bar_info.text_ratio = Some(str_into(attribute.value)?),
|
||||||
b"text_alignment" => {
|
b"text_alignment" => {
|
||||||
label_info.text_alignment = cow_to_text_alignment(attribute.value)?
|
progress_bar_info.text_alignment = cow_to_text_alignment(attribute.value)?
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
return Err(anyhow::Error::msg(format!(
|
return Err(anyhow::Error::msg(format!(
|
||||||
|
@ -88,6 +97,6 @@ impl ProgressBarInfo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(label_info)
|
Ok(progress_bar_info)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -537,6 +537,19 @@ pub fn cow_to_text_alignment<'a>(cow: Cow<'a, [u8]>) -> Result<TextAlignment> {
|
||||||
TextAlignment::try_from(text)
|
TextAlignment::try_from(text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn cow_to_grow_direction<'a>(cow: Cow<'a, [u8]>) -> Result<GrowDirection> {
|
||||||
|
let text = cow_to_str(cow);
|
||||||
|
|
||||||
|
match text.as_str() {
|
||||||
|
"left_to_right" => Ok(GrowDirection::LeftToRight),
|
||||||
|
"bottom_to_top" => Ok(GrowDirection::BottomToTop),
|
||||||
|
_ => Err(anyhow::Error::msg(format!(
|
||||||
|
"failed parsing grow direction: {}",
|
||||||
|
text
|
||||||
|
))),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn str_to_vert_align<'a>(cow: Cow<'a, [u8]>) -> Result<VerticalAlign> {
|
pub fn str_to_vert_align<'a>(cow: Cow<'a, [u8]>) -> Result<VerticalAlign> {
|
||||||
let string = cow_to_str(cow);
|
let string = cow_to_str(cow);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue