ferroui_base/media/
font_style.rs1use std::fmt;
2use std::str::FromStr;
3
4use crate::utilities::FormatError;
5
6#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
8#[repr(i32)]
9pub enum FontStyle {
10 #[default]
12 Normal = 0,
13 Italic = 1,
15 Oblique = 2,
17}
18
19impl FontStyle {
20 const NAMES: [(&'static str, FontStyle); 3] =
21 [("Normal", FontStyle::Normal), ("Italic", FontStyle::Italic), ("Oblique", FontStyle::Oblique)];
22
23 pub fn try_parse_ignore_case(s: &str) -> Option<Self> {
25 Self::NAMES.iter().find(|(name, _)| name.eq_ignore_ascii_case(s)).map(|(_, value)| *value)
26 }
27}
28
29impl fmt::Display for FontStyle {
30 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31 fmt::Debug::fmt(self, f)
32 }
33}
34
35impl FromStr for FontStyle {
36 type Err = FormatError;
37
38 fn from_str(s: &str) -> Result<Self, Self::Err> {
39 Self::try_parse_ignore_case(s.trim())
40 .ok_or_else(|| FormatError::from_string(format!("Invalid font style: '{s}'.")))
41 }
42}