-
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathiced.rs
More file actions
77 lines (71 loc) · 2.05 KB
/
iced.rs
File metadata and controls
77 lines (71 loc) · 2.05 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//! Example demonstrating integration with the `iced` crate.
use iced::{
application,
theme::Style,
widget::{button, column, container, text},
Alignment::Center,
Element,
Length::Fill,
Result,
};
const COLORS: catppuccin::FlavorColors = catppuccin::PALETTE.latte.colors;
#[derive(Default)]
struct Counter {
value: i64,
}
#[derive(Clone, Copy, Debug)]
enum Message {
Increment,
Decrement,
}
impl Counter {
const fn update(&mut self, message: Message) {
match message {
Message::Increment => {
self.value += 1;
}
Message::Decrement => {
self.value -= 1;
}
}
}
fn view(&self) -> Element<'_, Message> {
let green: iced::Color = COLORS.green.into();
let red: iced::Color = COLORS.red.into();
container(
column![
button(text("+").size(50).center())
.style(move |_, _| button::Style {
background: Some(green.into()),
text_color: COLORS.crust.into(),
..Default::default()
})
.width(60)
.on_press(Message::Increment),
text(self.value).size(50),
button(text("-").size(50).center())
.style(move |_, _| button::Style {
background: Some(red.into()),
text_color: COLORS.crust.into(),
..Default::default()
})
.width(60)
.on_press(Message::Decrement),
]
.align_x(Center)
.spacing(10),
)
.padding(20)
.center_x(Fill)
.center_y(Fill)
.into()
}
}
fn main() -> Result {
application(|| Counter { value: 0 }, Counter::update, Counter::view)
.style(move |_, _| Style {
background_color: COLORS.base.into(),
text_color: COLORS.text.into(),
})
.run()
}