use super::*;
impl Default for TextStyle {
#[inline(always)]
fn default() -> Self {
Self {
family: FontFamily::Sans,
font_size: 14.0,
weight: FontWeight::Normal,
line_height: 1.4,
letter_spacing: 0.0,
align: TextAlign::Left,
overflow: TextOverflow::Wrap,
color: COLOR_BLACK,
italic: false,
underline: false,
strikethrough: false,
text_select: None,
selection_color: None,
}
}
}
impl TextStyle {
#[must_use]
#[inline(always)]
pub const fn text_select_mode(&self) -> Option<TextSelectMode> {
let Self { text_select, .. } = *self;
text_select
}
#[must_use]
#[inline(always)]
pub const fn get_text_select(&self) -> TextSelectMode {
match self.text_select_mode() {
Some(mode) => mode,
None => TextSelectMode::None,
}
}
#[must_use]
#[inline(always)]
pub const fn get_selectable(&self) -> bool {
!matches!(self.get_text_select(), TextSelectMode::None)
}
#[inline(always)]
pub fn set_selectable(&mut self, selectable: bool) -> &mut Self {
let mode: TextSelectMode = if selectable {
TextSelectMode::SelectAndCopy
} else {
TextSelectMode::None
};
self.set_text_select(Some(mode))
}
#[must_use]
#[inline(always)]
pub fn selection_color(&self) -> Option<Color> {
let Self {
selection_color, ..
} = *self;
selection_color
}
#[must_use]
#[inline(always)]
pub(crate) fn same_layout_metrics(&self, other: &Self) -> bool {
self.get_family() == other.get_family()
&& self.get_font_size() == other.get_font_size()
&& self.get_weight() == other.get_weight()
&& self.get_line_height() == other.get_line_height()
&& self.get_letter_spacing() == other.get_letter_spacing()
&& self.get_align() == other.get_align()
&& self.get_overflow() == other.get_overflow()
&& self.get_italic() == other.get_italic()
}
}
impl FontWeight {
#[must_use]
#[inline(always)]
pub const fn numeric(&self) -> u16 {
match *self {
Self::Light => 300,
Self::Normal => 400,
Self::Medium => 500,
Self::SemiBold => 600,
Self::Bold => 700,
}
}
#[must_use]
#[inline(always)]
pub const fn is_bold(&self) -> bool {
matches!(*self, Self::SemiBold | Self::Bold)
}
}