summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/events/src/main.rs5
-rw-r--r--examples/modal/src/main.rs8
-rw-r--r--examples/pane_grid/src/main.rs14
-rw-r--r--examples/screenshot/src/main.rs7
-rw-r--r--examples/stopwatch/src/main.rs16
-rw-r--r--examples/toast/src/main.rs8
-rw-r--r--examples/todos/src/main.rs40
-rw-r--r--examples/url_handler/src/main.rs13
-rw-r--r--examples/visible_bounds/src/main.rs8
9 files changed, 56 insertions, 63 deletions
diff --git a/examples/events/src/main.rs b/examples/events/src/main.rs
index 7f3a5e1d..32d0da2c 100644
--- a/examples/events/src/main.rs
+++ b/examples/events/src/main.rs
@@ -1,9 +1,8 @@
use iced::alignment;
+use iced::event::{self, Event};
use iced::executor;
-use iced::subscription;
use iced::widget::{button, checkbox, container, text, Column};
use iced::window;
-use iced::Event;
use iced::{
Alignment, Application, Command, Element, Length, Settings, Subscription,
Theme,
@@ -71,7 +70,7 @@ impl Application for Events {
}
fn subscription(&self) -> Subscription<Message> {
- subscription::events().map(Message::EventOccurred)
+ event::listen().map(Message::EventOccurred)
}
fn view(&self) -> Element<Message> {
diff --git a/examples/modal/src/main.rs b/examples/modal/src/main.rs
index 8a48f830..4aa70886 100644
--- a/examples/modal/src/main.rs
+++ b/examples/modal/src/main.rs
@@ -1,12 +1,14 @@
+use iced::event::{self, Event};
use iced::executor;
use iced::keyboard;
-use iced::subscription::{self, Subscription};
use iced::theme;
use iced::widget::{
self, button, column, container, horizontal_space, pick_list, row, text,
text_input,
};
-use iced::{Alignment, Application, Command, Element, Event, Length, Settings};
+use iced::{
+ Alignment, Application, Command, Element, Length, Settings, Subscription,
+};
use modal::Modal;
use std::fmt;
@@ -49,7 +51,7 @@ impl Application for App {
}
fn subscription(&self) -> Subscription<Self::Message> {
- subscription::events().map(Message::Event)
+ event::listen().map(Message::Event)
}
fn update(&mut self, message: Message) -> Command<Message> {
diff --git a/examples/pane_grid/src/main.rs b/examples/pane_grid/src/main.rs
index 04896e20..af87e2c0 100644
--- a/examples/pane_grid/src/main.rs
+++ b/examples/pane_grid/src/main.rs
@@ -1,8 +1,6 @@
use iced::alignment::{self, Alignment};
-use iced::event::{self, Event};
use iced::executor;
use iced::keyboard;
-use iced::subscription;
use iced::theme::{self, Theme};
use iced::widget::pane_grid::{self, PaneGrid};
use iced::widget::{
@@ -146,18 +144,12 @@ impl Application for Example {
}
fn subscription(&self) -> Subscription<Message> {
- subscription::events_with(|event, status| {
- if let event::Status::Captured = status {
+ keyboard::on_key_press(|key_code, modifiers| {
+ if !modifiers.command() {
return None;
}
- match event {
- Event::Keyboard(keyboard::Event::KeyPressed {
- modifiers,
- key_code,
- }) if modifiers.command() => handle_hotkey(key_code),
- _ => None,
- }
+ handle_hotkey(key_code)
})
}
diff --git a/examples/screenshot/src/main.rs b/examples/screenshot/src/main.rs
index 83824535..54446724 100644
--- a/examples/screenshot/src/main.rs
+++ b/examples/screenshot/src/main.rs
@@ -4,9 +4,8 @@ use iced::theme::{Button, Container};
use iced::widget::{button, column, container, image, row, text, text_input};
use iced::window::screenshot::{self, Screenshot};
use iced::{
- event, executor, keyboard, subscription, Alignment, Application, Command,
- ContentFit, Element, Event, Length, Rectangle, Renderer, Subscription,
- Theme,
+ event, executor, keyboard, Alignment, Application, Command, ContentFit,
+ Element, Event, Length, Rectangle, Renderer, Subscription, Theme,
};
use ::image as img;
@@ -254,7 +253,7 @@ impl Application for Example {
}
fn subscription(&self) -> Subscription<Self::Message> {
- subscription::events_with(|event, status| {
+ event::listen_with(|event, status| {
if let event::Status::Captured = status {
return None;
}
diff --git a/examples/stopwatch/src/main.rs b/examples/stopwatch/src/main.rs
index 842ba3d4..0b0f0607 100644
--- a/examples/stopwatch/src/main.rs
+++ b/examples/stopwatch/src/main.rs
@@ -1,5 +1,6 @@
use iced::alignment;
use iced::executor;
+use iced::keyboard;
use iced::theme::{self, Theme};
use iced::time;
use iced::widget::{button, column, container, row, text};
@@ -77,12 +78,25 @@ impl Application for Stopwatch {
}
fn subscription(&self) -> Subscription<Message> {
- match self.state {
+ let tick = match self.state {
State::Idle => Subscription::none(),
State::Ticking { .. } => {
time::every(Duration::from_millis(10)).map(Message::Tick)
}
+ };
+
+ fn handle_hotkey(
+ key_code: keyboard::KeyCode,
+ _modifiers: keyboard::Modifiers,
+ ) -> Option<Message> {
+ match key_code {
+ keyboard::KeyCode::Space => Some(Message::Toggle),
+ keyboard::KeyCode::R => Some(Message::Reset),
+ _ => None,
+ }
}
+
+ Subscription::batch(vec![tick, keyboard::on_key_press(handle_hotkey)])
}
fn view(&self) -> Element<Message> {
diff --git a/examples/toast/src/main.rs b/examples/toast/src/main.rs
index 42f6c348..47b272a9 100644
--- a/examples/toast/src/main.rs
+++ b/examples/toast/src/main.rs
@@ -1,10 +1,12 @@
+use iced::event::{self, Event};
use iced::executor;
use iced::keyboard;
-use iced::subscription::{self, Subscription};
use iced::widget::{
self, button, column, container, pick_list, row, slider, text, text_input,
};
-use iced::{Alignment, Application, Command, Element, Event, Length, Settings};
+use iced::{
+ Alignment, Application, Command, Element, Length, Settings, Subscription,
+};
use toast::{Status, Toast};
@@ -57,7 +59,7 @@ impl Application for App {
}
fn subscription(&self) -> Subscription<Self::Message> {
- subscription::events().map(Message::Event)
+ event::listen().map(Message::Event)
}
fn update(&mut self, message: Message) -> Command<Message> {
diff --git a/examples/todos/src/main.rs b/examples/todos/src/main.rs
index 6ad7b4fb..62c17926 100644
--- a/examples/todos/src/main.rs
+++ b/examples/todos/src/main.rs
@@ -1,8 +1,6 @@
use iced::alignment::{self, Alignment};
-use iced::event::{self, Event};
use iced::font::{self, Font};
-use iced::keyboard::{self, KeyCode, Modifiers};
-use iced::subscription;
+use iced::keyboard;
use iced::theme::{self, Theme};
use iced::widget::{
self, button, checkbox, column, container, row, scrollable, text,
@@ -52,7 +50,7 @@ enum Message {
FilterChanged(Filter),
TaskMessage(usize, TaskMessage),
TabPressed { shift: bool },
- ToggleFullscreen(window::Mode),
+ ChangeWindowMode(window::Mode),
}
impl Application for Todos {
@@ -163,7 +161,7 @@ impl Application for Todos {
widget::focus_next()
}
}
- Message::ToggleFullscreen(mode) => {
+ Message::ChangeWindowMode(mode) => {
window::change_mode(mode)
}
_ => Command::none(),
@@ -262,33 +260,19 @@ impl Application for Todos {
}
fn subscription(&self) -> Subscription<Message> {
- subscription::events_with(|event, status| match (event, status) {
- (
- Event::Keyboard(keyboard::Event::KeyPressed {
- key_code: keyboard::KeyCode::Tab,
- modifiers,
- ..
+ keyboard::on_key_press(|key_code, modifiers| {
+ match (key_code, modifiers) {
+ (keyboard::KeyCode::Tab, _) => Some(Message::TabPressed {
+ shift: modifiers.shift(),
}),
- event::Status::Ignored,
- ) => Some(Message::TabPressed {
- shift: modifiers.shift(),
- }),
- (
- Event::Keyboard(keyboard::Event::KeyPressed {
- key_code,
- modifiers: Modifiers::SHIFT,
- }),
- event::Status::Ignored,
- ) => match key_code {
- KeyCode::Up => {
- Some(Message::ToggleFullscreen(window::Mode::Fullscreen))
+ (keyboard::KeyCode::Up, keyboard::Modifiers::SHIFT) => {
+ Some(Message::ChangeWindowMode(window::Mode::Fullscreen))
}
- KeyCode::Down => {
- Some(Message::ToggleFullscreen(window::Mode::Windowed))
+ (keyboard::KeyCode::Down, keyboard::Modifiers::SHIFT) => {
+ Some(Message::ChangeWindowMode(window::Mode::Windowed))
}
_ => None,
- },
- _ => None,
+ }
})
}
}
diff --git a/examples/url_handler/src/main.rs b/examples/url_handler/src/main.rs
index f63fa06a..bf570123 100644
--- a/examples/url_handler/src/main.rs
+++ b/examples/url_handler/src/main.rs
@@ -1,6 +1,5 @@
-use iced::event::{Event, MacOS, PlatformSpecific};
+use iced::event::{self, Event};
use iced::executor;
-use iced::subscription;
use iced::widget::{container, text};
use iced::{
Application, Command, Element, Length, Settings, Subscription, Theme,
@@ -37,9 +36,11 @@ impl Application for App {
fn update(&mut self, message: Message) -> Command<Message> {
match message {
Message::EventOccurred(event) => {
- if let Event::PlatformSpecific(PlatformSpecific::MacOS(
- MacOS::ReceivedUrl(url),
- )) = event
+ if let Event::PlatformSpecific(
+ event::PlatformSpecific::MacOS(event::MacOS::ReceivedUrl(
+ url,
+ )),
+ ) = event
{
self.url = Some(url);
}
@@ -50,7 +51,7 @@ impl Application for App {
}
fn subscription(&self) -> Subscription<Message> {
- subscription::events().map(Message::EventOccurred)
+ event::listen().map(Message::EventOccurred)
}
fn view(&self) -> Element<Message> {
diff --git a/examples/visible_bounds/src/main.rs b/examples/visible_bounds/src/main.rs
index 8b684514..42dfc24c 100644
--- a/examples/visible_bounds/src/main.rs
+++ b/examples/visible_bounds/src/main.rs
@@ -1,14 +1,14 @@
+use iced::event::{self, Event};
use iced::executor;
use iced::mouse;
-use iced::subscription::{self, Subscription};
use iced::theme::{self, Theme};
use iced::widget::{
column, container, horizontal_space, row, scrollable, text, vertical_space,
};
use iced::window;
use iced::{
- Alignment, Application, Color, Command, Element, Event, Font, Length,
- Point, Rectangle, Settings,
+ Alignment, Application, Color, Command, Element, Font, Length, Point,
+ Rectangle, Settings, Subscription,
};
pub fn main() -> iced::Result {
@@ -163,7 +163,7 @@ impl Application for Example {
}
fn subscription(&self) -> Subscription<Message> {
- subscription::events_with(|event, _| match event {
+ event::listen_with(|event, _| match event {
Event::Mouse(mouse::Event::CursorMoved { position }) => {
Some(Message::MouseMoved(position))
}