iced_graphics/
settings.rs

1use crate::Antialiasing;
2use crate::core::{self, Font, Pixels};
3
4/// The settings of a renderer.
5#[derive(Debug, Clone, Copy, PartialEq)]
6pub struct Settings {
7    /// The default [`Font`] to use.
8    pub default_font: Font,
9
10    /// The default size of text.
11    ///
12    /// By default, it will be set to `16.0`.
13    pub default_text_size: Pixels,
14
15    /// The antialiasing strategy that will be used for triangle primitives.
16    ///
17    /// By default, it is `None`.
18    pub antialiasing: Option<Antialiasing>,
19}
20
21impl Default for Settings {
22    fn default() -> Settings {
23        Settings {
24            default_font: Font::default(),
25            default_text_size: Pixels(16.0),
26            antialiasing: None,
27        }
28    }
29}
30
31impl From<core::Settings> for Settings {
32    fn from(settings: core::Settings) -> Self {
33        Self {
34            default_font: if cfg!(all(
35                target_arch = "wasm32",
36                feature = "fira-sans"
37            )) && settings.default_font == Font::default()
38            {
39                Font::with_name("Fira Sans")
40            } else {
41                settings.default_font
42            },
43            default_text_size: settings.default_text_size,
44            antialiasing: settings.antialiasing.then_some(Antialiasing::MSAAx4),
45        }
46    }
47}