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