use freya_engine::prelude::*;
use crate::{
Parse,
ParseError,
};
impl Parse for TextAlign {
fn parse(value: &str) -> Result<Self, ParseError> {
Ok(match value {
"center" => TextAlign::Center,
"justify" => TextAlign::Justify,
"start" => TextAlign::Start,
"end" => TextAlign::End,
"left" => TextAlign::Left,
"right" => TextAlign::Right,
_ => TextAlign::default(),
})
}
}
impl Parse for Slant {
fn parse(value: &str) -> Result<Self, ParseError> {
Ok(match value {
"upright" => Slant::Upright,
"italic" => Slant::Italic,
"oblique" => Slant::Oblique,
_ => Slant::Upright,
})
}
}
impl Parse for Width {
fn parse(value: &str) -> Result<Self, ParseError> {
Ok(match value {
"ultra-condensed" => Width::ULTRA_CONDENSED,
"extra-condensed" => Width::EXTRA_CONDENSED,
"condensed" => Width::CONDENSED,
"semi-condensed" => Width::SEMI_CONDENSED,
"normal" => Width::NORMAL,
"semi-expanded" => Width::SEMI_EXPANDED,
"expanded" => Width::EXPANDED,
"extra-expanded" => Width::EXTRA_EXPANDED,
"ultra-expanded" => Width::ULTRA_EXPANDED,
_ => Width::NORMAL,
})
}
}
impl Parse for Weight {
fn parse(value: &str) -> Result<Self, ParseError> {
Ok(match value {
"invisible" => Weight::INVISIBLE,
"thin" => Weight::THIN,
"extra-light" => Weight::EXTRA_LIGHT,
"light" => Weight::LIGHT,
"normal" => Weight::NORMAL,
"medium" => Weight::MEDIUM,
"semi-bold" => Weight::SEMI_BOLD,
"bold" => Weight::BOLD,
"extra-bold" => Weight::EXTRA_BOLD,
"black" => Weight::BLACK,
"extra-black" => Weight::EXTRA_BLACK,
"50" => Weight::INVISIBLE,
"100" => Weight::THIN,
"200" => Weight::EXTRA_LIGHT,
"300" => Weight::LIGHT,
"400" => Weight::NORMAL,
"500" => Weight::MEDIUM,
"600" => Weight::SEMI_BOLD,
"700" => Weight::BOLD,
"800" => Weight::EXTRA_BOLD,
"900" => Weight::BLACK,
"950" => Weight::EXTRA_BLACK,
_ => Weight::NORMAL,
})
}
}
#[derive(Default, Clone, Debug, PartialEq)]
pub enum TextOverflow {
#[default]
Clip,
Ellipsis,
Custom(String),
}
impl TextOverflow {
pub fn get_ellipsis(&self) -> Option<&str> {
match self {
Self::Clip => None,
Self::Ellipsis => Some("..."),
Self::Custom(custom) => Some(custom),
}
}
pub fn pretty(&self) -> String {
match self {
TextOverflow::Clip => "clip".to_string(),
TextOverflow::Ellipsis => "ellipsis".to_string(),
TextOverflow::Custom(text_overflow) => text_overflow.to_string(),
}
}
}
impl Parse for TextOverflow {
fn parse(value: &str) -> Result<Self, ParseError> {
Ok(match value {
"ellipsis" => TextOverflow::Ellipsis,
"clip" => TextOverflow::Clip,
value => TextOverflow::Custom(value.to_string()),
})
}
}