use iced::widget::text as text_fn;
use iced::widget::text::{IntoFragment, Text};
use iced::{Font, Theme as IcedTheme};
use crate::theme::resolve::Theme;
impl Theme {
pub fn text<'a>(
&self,
content: impl IntoFragment<'a>,
classes: &[&str],
) -> Text<'a, IcedTheme> {
let computed = self.resolve(classes, None);
let mut t = text_fn(content);
if let Some(size) = computed.length("font-size") {
t = t.size(size);
}
if let Some(color) = computed.color("color") {
t = t.color(color.to_iced());
}
if let Some(weight) = computed.number("font-weight") {
t = t.font(Font {
weight: weight_from_css(weight),
..self.default_font()
});
}
t
}
}
pub(crate) fn weight_from_css(v: f32) -> iced::font::Weight {
use iced::font::Weight;
match v.round() as i32 {
100 => Weight::Thin,
200 => Weight::ExtraLight,
300 => Weight::Light,
400 => Weight::Normal,
500 => Weight::Medium,
600 => Weight::Semibold,
700 => Weight::Bold,
800 => Weight::ExtraBold,
900 => Weight::Black,
_ => Weight::Normal,
}
}