#[repr(u16)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default, Hash, PartialOrd, Ord)]
pub enum FontWeight {
Thin = 100,
ExtraLight = 200,
Light = 300,
#[default]
Normal = 400,
Medium = 500,
SemiBold = 600,
Bold = 700,
ExtraBold = 800,
Black = 900,
}
impl FontWeight {
#[inline]
pub fn from_u16(value: u16) -> Self {
match value {
0..=150 => Self::Thin,
151..=250 => Self::ExtraLight,
251..=350 => Self::Light,
351..=450 => Self::Normal,
451..=550 => Self::Medium,
551..=650 => Self::SemiBold,
651..=750 => Self::Bold,
751..=850 => Self::ExtraBold,
_ => Self::Black,
}
}
#[inline]
pub const fn value(&self) -> u16 {
*self as u16
}
#[inline]
pub const fn name(&self) -> &'static str {
match self {
Self::Thin => "Thin",
Self::ExtraLight => "ExtraLight",
Self::Light => "Light",
Self::Normal => "Normal",
Self::Medium => "Medium",
Self::SemiBold => "SemiBold",
Self::Bold => "Bold",
Self::ExtraBold => "ExtraBold",
Self::Black => "Black",
}
}
#[inline]
pub const fn is_bold(&self) -> bool {
(*self as u16) >= 600
}
}
#[repr(u8)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default, Hash)]
pub enum FontStyle {
#[default]
Normal = 0,
Italic = 1,
Oblique = 2,
}
impl FontStyle {
#[inline]
pub fn from_u8(value: u8) -> Option<Self> {
match value {
0 => Some(Self::Normal),
1 => Some(Self::Italic),
2 => Some(Self::Oblique),
_ => None,
}
}
#[inline]
pub const fn name(&self) -> &'static str {
match self {
Self::Normal => "Normal",
Self::Italic => "Italic",
Self::Oblique => "Oblique",
}
}
#[inline]
pub const fn is_slanted(&self) -> bool {
!matches!(self, Self::Normal)
}
}
#[repr(u8)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default, Hash)]
pub enum TextAlign {
#[default]
Left = 0,
Center = 1,
Right = 2,
Justify = 3,
}
impl TextAlign {
#[inline]
pub fn from_u8(value: u8) -> Option<Self> {
match value {
0 => Some(Self::Left),
1 => Some(Self::Center),
2 => Some(Self::Right),
3 => Some(Self::Justify),
_ => None,
}
}
#[inline]
pub const fn name(&self) -> &'static str {
match self {
Self::Left => "Left",
Self::Center => "Center",
Self::Right => "Right",
Self::Justify => "Justify",
}
}
}
#[repr(u8)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default, Hash)]
pub enum TextBaseline {
Top = 0,
Middle = 1,
#[default]
Alphabetic = 2,
Bottom = 3,
Hanging = 4,
Ideographic = 5,
}
impl TextBaseline {
#[inline]
pub fn from_u8(value: u8) -> Option<Self> {
match value {
0 => Some(Self::Top),
1 => Some(Self::Middle),
2 => Some(Self::Alphabetic),
3 => Some(Self::Bottom),
4 => Some(Self::Hanging),
5 => Some(Self::Ideographic),
_ => None,
}
}
#[inline]
pub const fn name(&self) -> &'static str {
match self {
Self::Top => "Top",
Self::Middle => "Middle",
Self::Alphabetic => "Alphabetic",
Self::Bottom => "Bottom",
Self::Hanging => "Hanging",
Self::Ideographic => "Ideographic",
}
}
}
#[repr(transparent)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct TextDecoration(pub u8);
impl TextDecoration {
pub const NONE: Self = Self(0);
pub const UNDERLINE: Self = Self(1 << 0);
pub const OVERLINE: Self = Self(1 << 1);
pub const LINE_THROUGH: Self = Self(1 << 2);
#[inline]
pub const fn has(&self, deco: Self) -> bool {
(self.0 & deco.0) != 0
}
#[inline]
pub const fn with(&self, deco: Self) -> Self {
Self(self.0 | deco.0)
}
}