iced_core/settings.rs
1//! Configure your application.
2use crate::backend;
3use crate::renderer;
4use crate::{Backend, Font, Pixels};
5
6use std::borrow::Cow;
7
8/// The settings of an iced program.
9#[derive(Debug, Clone)]
10pub struct Settings {
11 /// The identifier of the application.
12 ///
13 /// If provided, this identifier may be used to identify the application or
14 /// communicate with it through the windowing system.
15 pub id: Option<String>,
16
17 /// The fonts to load on boot.
18 pub fonts: Vec<Cow<'static, [u8]>>,
19
20 /// The default [`Font`] to be used.
21 ///
22 /// By default, it uses [`Family::SansSerif`](crate::font::Family::SansSerif).
23 pub default_font: Font,
24
25 /// The text size that will be used by default.
26 ///
27 /// By default, it is `16.0`.
28 pub default_text_size: Pixels,
29
30 /// Whether certain widgets should be rendered using metrics hinting.
31 ///
32 /// Metrics hinting can improve the readability of smaller text in
33 /// low-DPI screens, as well as the clarity of widgets that render thin lines.
34 ///
35 /// By default, it is enabled.
36 pub metrics_hinting: bool,
37
38 /// The graphical backend to use.
39 ///
40 /// By default, it is [`Backend::Best`].
41 pub backend: Backend,
42
43 /// The [`PowerPreference`](backend::PowerPreference) of the backend.
44 ///
45 /// By default, it is [`backend::PowerPreference::None`].
46 pub power_preference: backend::PowerPreference,
47
48 /// If set to true, the renderer will try to perform antialiasing for some
49 /// primitives.
50 ///
51 /// Enabling it can produce a smoother result in some widgets, like the
52 /// `canvas` widget, at a performance cost.
53 ///
54 /// By default, it is enabled.
55 pub antialiasing: bool,
56
57 /// Whether or not to attempt to synchronize rendering when possible.
58 ///
59 /// Disabling it can improve rendering performance on some platforms.
60 ///
61 /// By default, it is enabled.
62 pub vsync: bool,
63}
64
65impl Default for Settings {
66 fn default() -> Self {
67 let renderer = renderer::Settings::default();
68
69 Self {
70 id: None,
71 fonts: Vec::new(),
72 default_font: renderer.default_font,
73 default_text_size: renderer.default_text_size,
74 metrics_hinting: true,
75 backend: Backend::default(),
76 power_preference: backend::PowerPreference::None,
77 antialiasing: true,
78 vsync: true,
79 }
80 }
81}
82
83impl From<&Settings> for renderer::Settings {
84 fn from(settings: &Settings) -> Self {
85 Self {
86 default_font: settings.default_font,
87 default_text_size: settings.default_text_size,
88 metrics_hinting: settings.metrics_hinting,
89 }
90 }
91}