diff options
author | 2021-06-25 18:03:18 +0200 | |
---|---|---|
committer | 2021-06-25 18:03:18 +0200 | |
commit | de79a01b88e1610d374ed06077ac78f3e10b9c3d (patch) | |
tree | 679bec69f434182ee17a0e2da55a29b454334ed8 | |
parent | 5c45d36d1a8cfd92cd1a454a7f4deedcd4d13fe7 (diff) | |
download | iced-de79a01b88e1610d374ed06077ac78f3e10b9c3d.tar.gz iced-de79a01b88e1610d374ed06077ac78f3e10b9c3d.tar.bz2 iced-de79a01b88e1610d374ed06077ac78f3e10b9c3d.zip |
done
-rw-r--r-- | examples/winit/src/main.rs | 63 | ||||
-rw-r--r-- | src/window/settings.rs | 17 | ||||
-rw-r--r-- | winit/src/settings.rs | 5 |
3 files changed, 41 insertions, 44 deletions
diff --git a/examples/winit/src/main.rs b/examples/winit/src/main.rs index 202d9b5a..a1364ea6 100644 --- a/examples/winit/src/main.rs +++ b/examples/winit/src/main.rs @@ -1,65 +1,46 @@ -use iced::{button, Align, Button, Column, Element, Sandbox, Settings, window::Settings as WindowSettings, Text}; +use iced::{Column, Element, Sandbox, Settings, window::Settings as WindowSettings}; + +const WINDOW_WIDTH: i32 = 200; +const WINDOW_HEIGHT: i32 = 200; +const DISPLAY_WIDTH: i32 = 1920; +const DISPLAY_HEIGHT: i32 = 1080; +// These numbers are specific to a 1920x1080 monitor +const BORDER_X: i32 = 8; +const BORDER_Y: i32 = 2; +const CAPTION_HEIGHT: i32 = 4; pub fn main() { + let x = DISPLAY_WIDTH / 2 - WINDOW_WIDTH / 2 - BORDER_X; + let y = DISPLAY_HEIGHT / 2 - WINDOW_HEIGHT / 2 - BORDER_Y - CAPTION_HEIGHT; let settings = Settings { window: WindowSettings { - size: (400, 200), - position: (100, 100), + size: (WINDOW_WIDTH as u32, WINDOW_HEIGHT as u32), + position: (x, y), ..Default::default() }, ..Default::default() }; - Counter::run(settings).unwrap() + Winit::run(settings).unwrap() } #[derive(Default)] -struct Counter { - value: i32, - increment_button: button::State, - decrement_button: button::State, -} - -#[derive(Debug, Clone, Copy)] -enum Message { - IncrementPressed, - DecrementPressed, -} +struct Winit; -impl Sandbox for Counter { - type Message = Message; +impl Sandbox for Winit { + type Message = (); fn new() -> Self { Self::default() } fn title(&self) -> String { - String::from("Counter with winit - Iced") + String::from("winit - Iced") } - fn update(&mut self, message: Message) { - match message { - Message::IncrementPressed => { - self.value += 1; - } - Message::DecrementPressed => { - self.value -= 1; - } - } + fn update(&mut self, _message: Self::Message) { } - fn view(&mut self) -> Element<Message> { - Column::new() - .padding(20) - .align_items(Align::Center) - .push( - Button::new(&mut self.increment_button, Text::new("Increment")) - .on_press(Message::IncrementPressed), - ) - .push(Text::new(self.value.to_string()).size(50)) - .push( - Button::new(&mut self.decrement_button, Text::new("Decrement")) - .on_press(Message::DecrementPressed), - ) - .into() + fn view(&mut self) -> Element<Self::Message> { + Column::new().into() } } diff --git a/src/window/settings.rs b/src/window/settings.rs index 981f0858..0fecc3bb 100644 --- a/src/window/settings.rs +++ b/src/window/settings.rs @@ -8,8 +8,23 @@ pub struct Settings { /// The initial position of the window. /// + /// When the decorations of the window are enabled, Windows 10 will add some inivisble padding + /// to the window. This padding gets included in the position. So if you have decorations + /// enabled and want the window to be at 0,0 you would have to set the position to + /// -DPI_BORDER_X,-DPI_BORDER_Y. + /// + /// DPI_BORDER_X/DPI_BORDER_Y are the usual size of the padding, which changes based on the DPI of the display. + /// + /// On a 1920x1080 monitor you would have to set the position to -8,-2. + /// + /// For info on how you could implement positioning that supports all DPI monitors look at the + /// following WINAPI calls: + /// + /// * GetDpiForMonitor (with MDT_RAW_DPI) + /// * GetSystemMetricsForDpi (with SM_CXFRAME and SM_CYFRAME) + /// /// Note: this gets ignored on the web - pub position: (u32, u32), + pub position: (i32, i32), /// The minimum size of the window. pub min_size: Option<(u32, u32)>, diff --git a/winit/src/settings.rs b/winit/src/settings.rs index 0508cd9b..1769c676 100644 --- a/winit/src/settings.rs +++ b/winit/src/settings.rs @@ -36,7 +36,7 @@ pub struct Window { pub size: (u32, u32), /// The position of the window. - pub position: (u32, u32), + pub position: (i32, i32), /// The minimum size of the window. pub min_size: Option<(u32, u32)>, @@ -78,7 +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_position(winit::dpi::LogicalPosition { x: self.position.0, y: self.position.1 }) .with_resizable(self.resizable) .with_decorations(self.decorations) .with_transparent(self.transparent) @@ -116,6 +116,7 @@ impl Default for Window { fn default() -> Window { Window { size: (1024, 768), + position: (100, 100), min_size: None, max_size: None, resizable: true, |