2019-11-25 14:17:13 +01:00
|
|
|
//! Configure your application.
|
2020-06-01 22:07:29 +02:00
|
|
|
use crate::window;
|
2019-11-25 14:17:13 +01:00
|
|
|
|
|
|
|
|
/// The settings of an application.
|
2020-07-01 06:09:39 +02:00
|
|
|
#[derive(Debug, Clone)]
|
2020-03-30 18:00:15 +02:00
|
|
|
pub struct Settings<Flags> {
|
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.
|
|
|
|
|
///
|
|
|
|
|
/// [`Window`]: struct.Window.html
|
2020-01-16 05:54:22 +01:00
|
|
|
pub window: window::Settings,
|
2019-12-29 12:29:47 +01:00
|
|
|
|
2020-03-30 18:00:15 +02:00
|
|
|
/// The data needed to initialize an [`Application`].
|
|
|
|
|
///
|
2020-04-01 04:35:24 +02:00
|
|
|
/// [`Application`]: ../trait.Application.html
|
2020-03-30 18:00:15 +02:00
|
|
|
pub flags: Flags,
|
|
|
|
|
|
2020-01-09 18:31:07 +01:00
|
|
|
/// The bytes of the font that will be used by default.
|
|
|
|
|
///
|
|
|
|
|
/// If `None` is provided, a default system font will be chosen.
|
2020-01-01 17:49:48 +01:00
|
|
|
// TODO: Add `name` for web compatibility
|
|
|
|
|
pub default_font: Option<&'static [u8]>,
|
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.
|
|
|
|
|
///
|
|
|
|
|
/// The default value is 20.
|
|
|
|
|
pub default_text_size: u16,
|
|
|
|
|
|
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
|
|
|
///
|
|
|
|
|
/// [`Canvas`]: ../widget/canvas/struct.Canvas.html
|
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> {
|
|
|
|
|
/// Initialize application settings using the given data.
|
|
|
|
|
///
|
|
|
|
|
/// [`Application`]: ../trait.Application.html
|
|
|
|
|
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,
|
2020-06-19 00:08:28 +02:00
|
|
|
antialiasing: default_settings.antialiasing,
|
|
|
|
|
default_font: default_settings.default_font,
|
|
|
|
|
default_text_size: default_settings.default_text_size,
|
|
|
|
|
window: default_settings.window,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<Flags> Default for Settings<Flags>
|
|
|
|
|
where
|
|
|
|
|
Flags: Default,
|
|
|
|
|
{
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
flags: Default::default(),
|
2020-04-06 01:14:38 +01:00
|
|
|
antialiasing: Default::default(),
|
|
|
|
|
default_font: Default::default(),
|
2020-06-19 00:08:28 +02:00
|
|
|
default_text_size: 20,
|
2020-04-06 01:14:38 +01:00
|
|
|
window: Default::default(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-25 14:17:13 +01:00
|
|
|
#[cfg(not(target_arch = "wasm32"))]
|
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 {
|
2020-06-25 00:32:41 +02:00
|
|
|
window: settings.window.into(),
|
2020-03-30 18:00:15 +02:00
|
|
|
flags: settings.flags,
|
2019-12-03 07:08:12 +01:00
|
|
|
}
|
2019-11-25 14:17:13 +01:00
|
|
|
}
|
|
|
|
|
}
|