summaryrefslogtreecommitdiffstats
path: root/examples/events
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-01-12 02:59:08 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-01-12 02:59:08 +0100
commit7354f68b3ca345767de3f09dccddf168493977bf (patch)
treea09626c11a25ab4260c576733f1700e9ad12894b /examples/events
parent7ccd87c36b54e0d53f65f5774f140a0528ae4504 (diff)
downloadiced-7354f68b3ca345767de3f09dccddf168493977bf.tar.gz
iced-7354f68b3ca345767de3f09dccddf168493977bf.tar.bz2
iced-7354f68b3ca345767de3f09dccddf168493977bf.zip
Draft `Shell:request_redraw` API
... and implement `TextInput` cursor blink :tada:
Diffstat (limited to 'examples/events')
-rw-r--r--examples/events/Cargo.toml2
-rw-r--r--examples/events/src/main.rs24
2 files changed, 12 insertions, 14 deletions
diff --git a/examples/events/Cargo.toml b/examples/events/Cargo.toml
index 8ad04a36..8c56e471 100644
--- a/examples/events/Cargo.toml
+++ b/examples/events/Cargo.toml
@@ -6,5 +6,5 @@ edition = "2021"
publish = false
[dependencies]
-iced = { path = "../.." }
+iced = { path = "../..", features = ["debug"] }
iced_native = { path = "../../native" }
diff --git a/examples/events/src/main.rs b/examples/events/src/main.rs
index 234e1423..4ae8d6fb 100644
--- a/examples/events/src/main.rs
+++ b/examples/events/src/main.rs
@@ -1,11 +1,12 @@
use iced::alignment;
use iced::executor;
use iced::widget::{button, checkbox, container, text, Column};
+use iced::window;
use iced::{
Alignment, Application, Command, Element, Length, Settings, Subscription,
Theme,
};
-use iced_native::{window, Event};
+use iced_native::Event;
pub fn main() -> iced::Result {
Events::run(Settings {
@@ -18,7 +19,6 @@ pub fn main() -> iced::Result {
struct Events {
last: Vec<iced_native::Event>,
enabled: bool,
- should_exit: bool,
}
#[derive(Debug, Clone)]
@@ -50,31 +50,29 @@ impl Application for Events {
if self.last.len() > 5 {
let _ = self.last.remove(0);
}
+
+ Command::none()
}
Message::EventOccurred(event) => {
if let Event::Window(window::Event::CloseRequested) = event {
- self.should_exit = true;
+ window::close()
+ } else {
+ Command::none()
}
}
Message::Toggled(enabled) => {
self.enabled = enabled;
- }
- Message::Exit => {
- self.should_exit = true;
- }
- };
- Command::none()
+ Command::none()
+ }
+ Message::Exit => window::close(),
+ }
}
fn subscription(&self) -> Subscription<Message> {
iced_native::subscription::events().map(Message::EventOccurred)
}
- fn should_exit(&self) -> bool {
- self.should_exit
- }
-
fn view(&self) -> Element<Message> {
let events = Column::with_children(
self.last