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    /// Whether or not to synchronize frames.
21    ///
22    /// By default, it is `true`.
23    pub vsync: bool,
24}
25
26impl Default for Settings {
27    fn default() -> Settings {
28        Settings {
29            default_font: Font::default(),
30            default_text_size: Pixels(16.0),
31            antialiasing: None,
32            vsync: true,
33        }
34    }
35}
36
37impl From<core::Settings> for Settings {
38    fn from(settings: core::Settings) -> Self {
39        Self {
40            default_font: if cfg!(all(
41                target_arch = "wasm32",
42                feature = "fira-sans"
43            )) && settings.default_font == Font::default()
44            {
45                Font::with_name("Fira Sans")
46            } else {
47                settings.default_font
48            },
49            default_text_size: settings.default_text_size,
50            antialiasing: settings.antialiasing.then_some(Antialiasing::MSAAx4),
51            vsync: settings.vsync,
52        }
53    }
54}