Skip to main content

cosmic/
font.rs

1// Copyright 2022 System76 <info@system76.com>
2// SPDX-License-Identifier: MPL-2.0
3
4//! Select preferred fonts.
5
6pub use iced::Font;
7use iced_core::font::Weight;
8
9use crate::cosmic_theme::FontConfig;
10
11/// The font used by the active theme.
12#[inline]
13pub fn default() -> Font {
14    let theme = crate::theme::active();
15    Font::from(&theme.cosmic().font)
16}
17
18#[inline]
19pub fn light() -> Font {
20    Font {
21        weight: Weight::Light,
22        ..default()
23    }
24}
25
26#[inline]
27pub fn semibold() -> Font {
28    Font {
29        weight: Weight::Semibold,
30        ..default()
31    }
32}
33
34#[inline]
35pub fn bold() -> Font {
36    Font {
37        weight: Weight::Bold,
38        ..default()
39    }
40}
41
42/// The monospace font used by the active theme.
43#[inline]
44pub fn mono() -> Font {
45    let theme = crate::theme::active();
46    Font::from(&theme.cosmic().mono_font)
47}
48
49/// Convert a theme font configuration into an [`iced::Font`].
50#[must_use]
51pub fn from_config(font: &FontConfig) -> Font {
52    Font::from(font)
53}