iced_core/settings.rs
1//! Configure your application.
2use crate::renderer;
3use crate::{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 /// If set to true, the renderer will try to perform antialiasing for some
30 /// primitives.
31 ///
32 /// Enabling it can produce a smoother result in some widgets, like the
33 /// `canvas` widget, at a performance cost.
34 ///
35 /// By default, it is enabled.
36 pub antialiasing: bool,
37
38 /// Whether or not to attempt to synchronize rendering when possible.
39 ///
40 /// Disabling it can improve rendering performance on some platforms.
41 ///
42 /// By default, it is enabled.
43 pub vsync: bool,
44}
45
46impl Default for Settings {
47 fn default() -> Self {
48 let renderer = renderer::Settings::default();
49
50 Self {
51 id: None,
52 fonts: Vec::new(),
53 default_font: renderer.default_font,
54 default_text_size: renderer.default_text_size,
55 antialiasing: true,
56 vsync: true,
57 }
58 }
59}
60
61impl From<&Settings> for renderer::Settings {
62 fn from(settings: &Settings) -> Self {
63 Self {
64 default_font: settings.default_font,
65 default_text_size: settings.default_text_size,
66 }
67 }
68}