diff options
author | 2021-06-25 17:16:44 +0200 | |
---|---|---|
committer | 2021-06-25 17:33:40 +0200 | |
commit | 5c45d36d1a8cfd92cd1a454a7f4deedcd4d13fe7 (patch) | |
tree | ef903447347a70a4a350f390241b576bf262046a | |
parent | 52d44769a332d1d96a5e9292805a5884073b9185 (diff) | |
download | iced-5c45d36d1a8cfd92cd1a454a7f4deedcd4d13fe7.tar.gz iced-5c45d36d1a8cfd92cd1a454a7f4deedcd4d13fe7.tar.bz2 iced-5c45d36d1a8cfd92cd1a454a7f4deedcd4d13fe7.zip |
wip
-rw-r--r-- | examples/winit/Cargo.toml | 2 | ||||
-rw-r--r-- | examples/winit/src/main.rs | 27 | ||||
-rw-r--r-- | src/window/settings.rs | 7 | ||||
-rw-r--r-- | winit/src/settings.rs | 4 |
4 files changed, 27 insertions, 13 deletions
diff --git a/examples/winit/Cargo.toml b/examples/winit/Cargo.toml index 6d16a7a9..2d58f031 100644 --- a/examples/winit/Cargo.toml +++ b/examples/winit/Cargo.toml @@ -6,4 +6,4 @@ edition = "2018" publish = false [dependencies] -iced_winit = { path = "../../winit" } +iced = { path = "../.." } diff --git a/examples/winit/src/main.rs b/examples/winit/src/main.rs index 890ded79..202d9b5a 100644 --- a/examples/winit/src/main.rs +++ b/examples/winit/src/main.rs @@ -1,7 +1,15 @@ -use iced_winit::{button, Align, Button, Column, Element, Application, Settings, Text, Renderer, Program, Command}; +use iced::{button, Align, Button, Column, Element, Sandbox, Settings, window::Settings as WindowSettings, Text}; pub fn main() { - Counter::run(Settings::default()).unwrap() + let settings = Settings { + window: WindowSettings { + size: (400, 200), + position: (100, 100), + ..Default::default() + }, + ..Default::default() + }; + Counter::run(settings).unwrap() } #[derive(Default)] @@ -17,21 +25,16 @@ enum Message { DecrementPressed, } -impl Application for Counter { - type Flags = (); +impl Sandbox for Counter { + type Message = Message; - fn new(flags: Self::Flags) -> (Self, Command<Message>) { - (Self::default(), Command::none()) + fn new() -> Self { + Self::default() } fn title(&self) -> String { String::from("Counter with winit - Iced") } -} - -impl Program for Counter { - type Renderer = Renderer; - type Message = Message; fn update(&mut self, message: Message) { match message { @@ -44,7 +47,7 @@ impl Program for Counter { } } - fn view(&mut self) -> Element<Message, Self::Renderer> { + fn view(&mut self) -> Element<Message> { Column::new() .padding(20) .align_items(Align::Center) diff --git a/src/window/settings.rs b/src/window/settings.rs index 6b5d2985..981f0858 100644 --- a/src/window/settings.rs +++ b/src/window/settings.rs @@ -6,6 +6,11 @@ pub struct Settings { /// The initial size of the window. pub size: (u32, u32), + /// The initial position of the window. + /// + /// Note: this gets ignored on the web + pub position: (u32, u32), + /// The minimum size of the window. pub min_size: Option<(u32, u32)>, @@ -32,6 +37,7 @@ impl Default for Settings { fn default() -> Settings { Settings { size: (1024, 768), + position: (100, 100), min_size: None, max_size: None, resizable: true, @@ -48,6 +54,7 @@ impl From<Settings> for iced_winit::settings::Window { fn from(settings: Settings) -> Self { Self { size: settings.size, + position: settings.position, min_size: settings.min_size, max_size: settings.max_size, resizable: settings.resizable, diff --git a/winit/src/settings.rs b/winit/src/settings.rs index 941d88ce..0508cd9b 100644 --- a/winit/src/settings.rs +++ b/winit/src/settings.rs @@ -35,6 +35,9 @@ pub struct Window { /// The size of the window. pub size: (u32, u32), + /// The position of the window. + pub position: (u32, u32), + /// The minimum size of the window. pub min_size: Option<(u32, u32)>, @@ -75,6 +78,7 @@ impl Window { window_builder = window_builder .with_title(title) .with_inner_size(winit::dpi::LogicalSize { width, height }) + .with_outer_position(self.position) .with_resizable(self.resizable) .with_decorations(self.decorations) .with_transparent(self.transparent) |