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 /// The graphical backend to use.
31 ///
32 /// By default, it is [`Backend::Best`].
33 pub backend: Backend,
34
35 /// The [`PowerPreference`](backend::PowerPreference) of the backend.
36 ///
37 /// By default, it is [`backend::PowerPreference::None`].
38 pub power_preference: backend::PowerPreference,
39
40 /// If set to true, the renderer will try to perform antialiasing for some
41 /// primitives.
42 ///
43 /// Enabling it can produce a smoother result in some widgets, like the
44 /// `canvas` widget, at a performance cost.
45 ///
46 /// By default, it is enabled.
47 pub antialiasing: bool,
48
49 /// Whether or not to attempt to synchronize rendering when possible.
50 ///
51 /// Disabling it can improve rendering performance on some platforms.
52 ///
53 /// By default, it is enabled.
54 pub vsync: bool,
55}
56
57impl Default for Settings {
58 fn default() -> Self {
59 let renderer = renderer::Settings::default();
60
61 Self {
62 id: None,
63 fonts: Vec::new(),
64 default_font: renderer.default_font,
65 default_text_size: renderer.default_text_size,
66 backend: Backend::default(),
67 power_preference: backend::PowerPreference::None,
68 antialiasing: true,
69 vsync: true,
70 }
71 }
72}
73
74impl From<&Settings> for renderer::Settings {
75 fn from(settings: &Settings) -> Self {
76 Self {
77 default_font: settings.default_font,
78 default_text_size: settings.default_text_size,
79 }
80 }
81}