From 64e21535c7e5df9a1ff94b9b9036b6ae5b5c82b0 Mon Sep 17 00:00:00 2001 From: Richard Date: Tue, 28 Jun 2022 14:27:06 -0300 Subject: Fix `multi_window` example --- examples/multi_window/src/main.rs | 58 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 examples/multi_window/src/main.rs (limited to 'examples/multi_window/src') diff --git a/examples/multi_window/src/main.rs b/examples/multi_window/src/main.rs new file mode 100644 index 00000000..0ba6a591 --- /dev/null +++ b/examples/multi_window/src/main.rs @@ -0,0 +1,58 @@ +use iced::multi_window::Application; +use iced::pure::{button, column, text, Element}; +use iced::{window, Alignment, Command, Settings}; + +pub fn main() -> iced::Result { + Counter::run(Settings::default()) +} + +struct Counter { + value: i32, +} + +#[derive(Debug, Clone, Copy)] +enum Message { + IncrementPressed, + DecrementPressed, +} + +impl Application for Counter { + type Flags = (); + type Executor = iced::executor::Default; + type Message = Message; + + fn new(_flags: ()) -> (Self, Command) { + (Self { value: 0 }, Command::none()) + } + + fn title(&self) -> String { + String::from("MultiWindow - Iced") + } + + fn windows(&self) -> Vec<(window::Id, iced::window::Settings)> { + todo!() + } + + fn update(&mut self, message: Message) -> Command { + match message { + Message::IncrementPressed => { + self.value += 1; + } + Message::DecrementPressed => { + self.value -= 1; + } + } + + Command::none() + } + + fn view(&self) -> Element { + column() + .padding(20) + .align_items(Alignment::Center) + .push(button("Increment").on_press(Message::IncrementPressed)) + .push(text(self.value.to_string()).size(50)) + .push(button("Decrement").on_press(Message::DecrementPressed)) + .into() + } +} -- cgit