summaryrefslogtreecommitdiffstats
path: root/examples/events/src
diff options
context:
space:
mode:
Diffstat (limited to 'examples/events/src')
-rw-r--r--examples/events/src/main.rs35
1 files changed, 19 insertions, 16 deletions
diff --git a/examples/events/src/main.rs b/examples/events/src/main.rs
index 7f024c56..234e1423 100644
--- a/examples/events/src/main.rs
+++ b/examples/events/src/main.rs
@@ -1,6 +1,9 @@
+use iced::alignment;
+use iced::executor;
+use iced::widget::{button, checkbox, container, text, Column};
use iced::{
- alignment, button, executor, Alignment, Application, Button, Checkbox,
- Column, Command, Container, Element, Length, Settings, Subscription, Text,
+ Alignment, Application, Command, Element, Length, Settings, Subscription,
+ Theme,
};
use iced_native::{window, Event};
@@ -15,7 +18,6 @@ pub fn main() -> iced::Result {
struct Events {
last: Vec<iced_native::Event>,
enabled: bool,
- exit: button::State,
should_exit: bool,
}
@@ -27,8 +29,9 @@ enum Message {
}
impl Application for Events {
- type Executor = executor::Default;
type Message = Message;
+ type Theme = Theme;
+ type Executor = executor::Default;
type Flags = ();
fn new(_flags: ()) -> (Events, Command<Message>) {
@@ -72,23 +75,23 @@ impl Application for Events {
self.should_exit
}
- fn view(&mut self) -> Element<Message> {
- let events = self.last.iter().fold(
- Column::new().spacing(10),
- |column, event| {
- column.push(Text::new(format!("{:?}", event)).size(40))
- },
+ fn view(&self) -> Element<Message> {
+ let events = Column::with_children(
+ self.last
+ .iter()
+ .map(|event| text(format!("{:?}", event)).size(40))
+ .map(Element::from)
+ .collect(),
);
- let toggle = Checkbox::new(
- self.enabled,
+ let toggle = checkbox(
"Listen to runtime events",
+ self.enabled,
Message::Toggled,
);
- let exit = Button::new(
- &mut self.exit,
- Text::new("Exit")
+ let exit = button(
+ text("Exit")
.width(Length::Fill)
.horizontal_alignment(alignment::Horizontal::Center),
)
@@ -103,7 +106,7 @@ impl Application for Events {
.push(toggle)
.push(exit);
- Container::new(content)
+ container(content)
.width(Length::Fill)
.height(Length::Fill)
.center_x()