2019-11-25 14:17:13 +01:00
|
|
|
//! Configure your application.
|
2020-06-01 22:07:29 +02:00
|
|
|
use crate::window;
|
2023-08-30 04:31:21 +02:00
|
|
|
use crate::{Font, Pixels};
|
2019-11-25 14:17:13 +01:00
|
|
|
|
2023-09-18 19:07:41 +02:00
|
|
|
use std::borrow::Cow;
|
2019-11-25 14:17:13 +01:00
|
|
|
|
2024-03-17 19:38:42 +01:00
|
|
|
/// The settings of an iced [`Program`].
|
|
|
|
|
///
|
|
|
|
|
/// [`Program`]: crate::Program
|
2020-07-01 06:09:39 +02:00
|
|
|
#[derive(Debug, Clone)]
|
2024-03-16 05:33:47 +01:00
|
|
|
pub struct Settings<Flags = ()> {
|
2021-08-11 19:23:05 +07:00
|
|
|
/// The identifier of the application.
|
|
|
|
|
///
|
|
|
|
|
/// If provided, this identifier may be used to identify the application or
|
|
|
|
|
/// communicate with it through the windowing system.
|
|
|
|
|
pub id: Option<String>,
|
|
|
|
|
|
2020-01-16 05:54:22 +01:00
|
|
|
/// The window settings.
|
2019-11-25 14:17:13 +01:00
|
|
|
///
|
|
|
|
|
/// They will be ignored on the Web.
|
2020-01-16 05:54:22 +01:00
|
|
|
pub window: window::Settings,
|
2019-12-29 12:29:47 +01:00
|
|
|
|
2024-03-17 19:38:42 +01:00
|
|
|
/// The data needed to initialize the [`Program`].
|
2020-03-30 18:00:15 +02:00
|
|
|
///
|
2024-03-17 19:38:42 +01:00
|
|
|
/// [`Program`]: crate::Program
|
2020-03-30 18:00:15 +02:00
|
|
|
pub flags: Flags,
|
|
|
|
|
|
2023-09-18 19:07:41 +02:00
|
|
|
/// The fonts to load on boot.
|
|
|
|
|
pub fonts: Vec<Cow<'static, [u8]>>,
|
|
|
|
|
|
2023-02-04 07:33:33 +01:00
|
|
|
/// The default [`Font`] to be used.
|
2020-01-09 18:31:07 +01:00
|
|
|
///
|
2023-09-09 12:24:47 +02:00
|
|
|
/// By default, it uses [`Family::SansSerif`](crate::font::Family::SansSerif).
|
2023-02-04 07:33:33 +01:00
|
|
|
pub default_font: Font,
|
2020-02-15 10:08:27 +01:00
|
|
|
|
2020-06-19 00:08:28 +02:00
|
|
|
/// The text size that will be used by default.
|
|
|
|
|
///
|
2023-01-31 06:29:21 +01:00
|
|
|
/// The default value is `16.0`.
|
2023-08-30 04:31:21 +02:00
|
|
|
pub default_text_size: Pixels,
|
2020-06-19 00:08:28 +02:00
|
|
|
|
2020-02-18 09:54:24 +01:00
|
|
|
/// If set to true, the renderer will try to perform antialiasing for some
|
2020-02-15 10:08:27 +01:00
|
|
|
/// primitives.
|
|
|
|
|
///
|
|
|
|
|
/// Enabling it can produce a smoother result in some widgets, like the
|
2020-04-01 04:35:24 +02:00
|
|
|
/// [`Canvas`], at a performance cost.
|
2020-02-15 10:08:27 +01:00
|
|
|
///
|
|
|
|
|
/// By default, it is disabled.
|
2020-04-01 04:35:24 +02:00
|
|
|
///
|
2020-11-25 07:11:27 +01:00
|
|
|
/// [`Canvas`]: crate::widget::Canvas
|
2020-02-18 09:54:24 +01:00
|
|
|
pub antialiasing: bool,
|
2019-12-29 12:29:47 +01:00
|
|
|
}
|
|
|
|
|
|
2020-04-06 01:14:38 +01:00
|
|
|
impl<Flags> Settings<Flags> {
|
2024-03-17 19:38:42 +01:00
|
|
|
/// Initialize [`Program`] settings using the given data.
|
2020-04-06 01:14:38 +01:00
|
|
|
///
|
2024-03-17 19:38:42 +01:00
|
|
|
/// [`Program`]: crate::Program
|
2020-04-06 01:14:38 +01:00
|
|
|
pub fn with_flags(flags: Flags) -> Self {
|
2020-06-19 00:08:28 +02:00
|
|
|
let default_settings = Settings::<()>::default();
|
|
|
|
|
|
2020-04-06 01:14:38 +01:00
|
|
|
Self {
|
|
|
|
|
flags,
|
2021-08-11 19:23:05 +07:00
|
|
|
id: default_settings.id,
|
2021-03-30 21:44:19 +02:00
|
|
|
window: default_settings.window,
|
2023-09-18 19:07:41 +02:00
|
|
|
fonts: default_settings.fonts,
|
2020-06-19 00:08:28 +02:00
|
|
|
default_font: default_settings.default_font,
|
|
|
|
|
default_text_size: default_settings.default_text_size,
|
2021-03-30 21:44:19 +02:00
|
|
|
antialiasing: default_settings.antialiasing,
|
2020-06-19 00:08:28 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<Flags> Default for Settings<Flags>
|
|
|
|
|
where
|
|
|
|
|
Flags: Default,
|
|
|
|
|
{
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
Self {
|
2021-08-11 19:23:05 +07:00
|
|
|
id: None,
|
2023-09-20 04:51:08 +02:00
|
|
|
window: window::Settings::default(),
|
2021-08-11 19:23:05 +07:00
|
|
|
flags: Default::default(),
|
2023-10-27 03:58:45 +02:00
|
|
|
fonts: Vec::new(),
|
2023-09-20 04:51:08 +02:00
|
|
|
default_font: Font::default(),
|
2023-08-30 04:31:21 +02:00
|
|
|
default_text_size: Pixels(16.0),
|
2021-03-30 21:44:19 +02:00
|
|
|
antialiasing: false,
|
2020-04-06 01:14:38 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-30 18:00:15 +02:00
|
|
|
impl<Flags> From<Settings<Flags>> for iced_winit::Settings<Flags> {
|
|
|
|
|
fn from(settings: Settings<Flags>) -> iced_winit::Settings<Flags> {
|
2019-12-03 07:08:12 +01:00
|
|
|
iced_winit::Settings {
|
2021-08-11 19:23:05 +07:00
|
|
|
id: settings.id,
|
2023-07-12 19:21:05 -07:00
|
|
|
window: settings.window,
|
2020-03-30 18:00:15 +02:00
|
|
|
flags: settings.flags,
|
2023-09-18 19:07:41 +02:00
|
|
|
fonts: settings.fonts,
|
2019-12-03 07:08:12 +01:00
|
|
|
}
|
2019-11-25 14:17:13 +01:00
|
|
|
}
|
|
|
|
|
}
|