summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorLibravatar TimUntersberger <timuntersberger2@gmail.com>2021-06-25 18:03:18 +0200
committerLibravatar TimUntersberger <timuntersberger2@gmail.com>2021-06-25 18:03:18 +0200
commitde79a01b88e1610d374ed06077ac78f3e10b9c3d (patch)
tree679bec69f434182ee17a0e2da55a29b454334ed8 /examples
parent5c45d36d1a8cfd92cd1a454a7f4deedcd4d13fe7 (diff)
downloadiced-de79a01b88e1610d374ed06077ac78f3e10b9c3d.tar.gz
iced-de79a01b88e1610d374ed06077ac78f3e10b9c3d.tar.bz2
iced-de79a01b88e1610d374ed06077ac78f3e10b9c3d.zip
done
Diffstat (limited to 'examples')
-rw-r--r--examples/winit/src/main.rs63
1 files changed, 22 insertions, 41 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()
}
}