summaryrefslogtreecommitdiffstats
path: root/winit/src
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-11-25 14:17:13 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-11-25 14:17:13 +0100
commitd70021fa68b556e20638f29e2e303f6d156afdb6 (patch)
treeddc0f00151b1ec71610e60045812493153788632 /winit/src
parente72b5ceeb8c6461a34e85909a48debf46505d00a (diff)
downloadiced-d70021fa68b556e20638f29e2e303f6d156afdb6.tar.gz
iced-d70021fa68b556e20638f29e2e303f6d156afdb6.tar.bz2
iced-d70021fa68b556e20638f29e2e303f6d156afdb6.zip
Allow `Application` configuration with `Settings`
Diffstat (limited to 'winit/src')
-rw-r--r--winit/src/application.rs12
-rw-r--r--winit/src/lib.rs2
-rw-r--r--winit/src/settings.rs29
3 files changed, 38 insertions, 5 deletions
diff --git a/winit/src/application.rs b/winit/src/application.rs
index ec1444f6..1042b412 100644
--- a/winit/src/application.rs
+++ b/winit/src/application.rs
@@ -3,7 +3,7 @@ use crate::{
input::{keyboard, mouse},
renderer::{Target, Windowed},
Cache, Command, Container, Debug, Element, Event, Length, MouseCursor,
- UserInterface,
+ Settings, UserInterface,
};
/// An interactive, native cross-platform application.
@@ -72,7 +72,7 @@ pub trait Application: Sized {
/// It should probably be that last thing you call in your `main` function.
///
/// [`Application`]: trait.Application.html
- fn run()
+ fn run(settings: Settings)
where
Self: 'static,
{
@@ -96,13 +96,15 @@ pub trait Application: Sized {
let mut title = application.title();
- // TODO: Ask for window settings and configure this properly
+ let (width, height) = settings.window.size;
+
let window = WindowBuilder::new()
.with_title(&title)
.with_inner_size(winit::dpi::LogicalSize {
- width: 1280.0,
- height: 1024.0,
+ width: f64::from(width),
+ height: f64::from(height),
})
+ .with_resizable(settings.window.resizable)
.build(&event_loop)
.expect("Open window");
diff --git a/winit/src/lib.rs b/winit/src/lib.rs
index 0a2bf7dd..00d200f9 100644
--- a/winit/src/lib.rs
+++ b/winit/src/lib.rs
@@ -26,10 +26,12 @@ pub use iced_native::*;
pub use winit;
pub mod conversion;
+pub mod settings;
mod application;
pub use application::Application;
+pub use settings::Settings;
// We disable debug capabilities on release builds unless the `debug` feature
// is explicitly enabled.
diff --git a/winit/src/settings.rs b/winit/src/settings.rs
new file mode 100644
index 00000000..d257ecd8
--- /dev/null
+++ b/winit/src/settings.rs
@@ -0,0 +1,29 @@
+//! Configure your application.
+
+/// The settings of an application.
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
+pub struct Settings {
+ /// The [`Window`] settings
+ ///
+ /// [`Window`]: struct.Window.html
+ pub window: Window,
+}
+
+/// The window settings of an application.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub struct Window {
+ /// The size of the window.
+ pub size: (u32, u32),
+
+ /// Whether the window should be resizable or not.
+ pub resizable: bool,
+}
+
+impl Default for Window {
+ fn default() -> Window {
+ Window {
+ size: (1024, 768),
+ resizable: true,
+ }
+ }
+}