1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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<Message>) {
(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<Message> {
match message {
Message::IncrementPressed => {
self.value += 1;
}
Message::DecrementPressed => {
self.value -= 1;
}
}
Command::none()
}
fn view(&self) -> Element<Message> {
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()
}
}
|