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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
use iced::Element;
use iced::Length::Fill;
use iced::widget::{button, column, container, pick_list, row};
use iced_anim::{Animated, Animation, Event};
use iced_dialog::dialog;
use material_theme::button::{elevated, filled_tonal, outlined, text};
use material_theme::container::{
error, error_container, inverse_surface, primary, primary_container,
secondary, secondary_container, surface, surface_container,
surface_container_high, surface_container_highest, surface_container_low,
surface_container_lowest, tertiary, tertiary_container,
};
use material_theme::text::surface_variant;
use material_theme::{DARK, LIGHT, Theme};
fn main() -> iced::Result {
iced::application(State::default, State::update, State::view)
.theme(|state| state.theme.value().clone())
.run()
}
#[allow(dead_code)]
#[derive(Debug, Clone)]
enum Message {
Noop,
OpenDialog,
CloseDialog,
SwitchTheme(Event<Theme>),
}
#[derive(Debug, Default)]
pub struct State {
show_dialog: bool,
theme: Animated<Theme>,
}
impl State {
fn update(&mut self, message: Message) {
match message {
Message::Noop => {}
Message::OpenDialog => {
self.show_dialog = true;
}
Message::CloseDialog => {
self.show_dialog = false;
}
Message::SwitchTheme(event) => {
self.theme.update(event);
}
}
}
fn view(&self) -> Element<'_, Message, Theme> {
let base = container(
row![
column![
button("Disabled"),
button("Filled").on_press(Message::Noop),
button("Filled Tonal")
.on_press(Message::Noop)
.style(filled_tonal),
button("Elevated").on_press(Message::Noop).style(elevated),
button("Outlined").on_press(Message::Noop).style(outlined),
button("Text").on_press(Message::Noop).style(text),
button("Text Disabled").style(text),
]
.spacing(10),
column![
container("None").padding(8),
container("Primary").padding(8).style(primary),
container("Primary Container")
.padding(8)
.style(primary_container),
container("Secondary").padding(8).style(secondary),
container("Secondary Container")
.padding(8)
.style(secondary_container),
container("Tertiary").padding(8).style(tertiary),
container("Tertiary Container")
.padding(8)
.style(tertiary_container),
container("Error").padding(8).style(error),
container("Error Container")
.padding(8)
.style(error_container),
container("Surface").padding(8).style(surface),
container(
iced::widget::text("Surface Variant")
.style(surface_variant)
)
.padding(8)
.style(surface),
container("Inverse Surface")
.padding(8)
.style(inverse_surface),
container("Surface Container Lowest")
.padding(8)
.style(surface_container_lowest),
container("Surface Container Low")
.padding(8)
.style(surface_container_low),
container("Surface Container")
.padding(8)
.style(surface_container),
container("Surface Container High")
.padding(8)
.style(surface_container_high),
container("Surface Container Highest")
.padding(8)
.style(surface_container_highest),
]
.spacing(10),
pick_list(
[LIGHT.clone(), DARK.clone()],
Some(self.theme.target()),
|theme| Message::SwitchTheme(theme.into())
)
.placeholder("Select a theme..."),
button("Open Dialog").on_press(Message::OpenDialog)
]
.spacing(20),
)
.width(Fill)
.height(Fill)
.padding(12);
let dialog =
dialog(self.show_dialog, base, iced::widget::text("Say Hi!"))
.title("This is a Dialog.")
.push_button(iced_dialog::button("Hi!", Message::CloseDialog))
.width(280)
.height(186);
Animation::new(&self.theme, dialog)
.on_update(Message::SwitchTheme)
.into()
}
}
|