Make Command implementations platform-specific

This allows us to introduce a platform-specific `Action` to both `iced_native`
and `iced_web` and remove the `Clipboard` from `Application::update` to maintain
purity.

Additionally, this should let us implement further actions to let users query
and modify the shell environment (e.g. window, clipboard, and more!)
This commit is contained in:
Héctor Ramón Jiménez 2021-09-01 19:21:49 +07:00
parent b7b7741578
commit 76698ff2b5
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
34 changed files with 363 additions and 342 deletions

View file

@ -1,7 +1,7 @@
use iced::{
canvas::{self, Cache, Canvas, Cursor, Geometry, LineCap, Path, Stroke},
executor, time, Application, Clipboard, Color, Command, Container, Element,
Length, Point, Rectangle, Settings, Subscription, Vector,
executor, time, Application, Color, Command, Container, Element, Length,
Point, Rectangle, Settings, Subscription, Vector,
};
pub fn main() -> iced::Result {
@ -40,11 +40,7 @@ impl Application for Clock {
String::from("Clock - Iced")
}
fn update(
&mut self,
message: Message,
_clipboard: &mut Clipboard,
) -> Command<Message> {
fn update(&mut self, message: Message) -> Command<Message> {
match message {
Message::Tick(local_time) => {
let now = local_time;

View file

@ -1,6 +1,6 @@
use iced::{
button, executor, Align, Application, Button, Clipboard, Column, Command,
Container, Element, Length, ProgressBar, Settings, Subscription, Text,
button, executor, Align, Application, Button, Column, Command, Container,
Element, Length, ProgressBar, Settings, Subscription, Text,
};
mod download;
@ -43,11 +43,7 @@ impl Application for Example {
String::from("Download progress - Iced")
}
fn update(
&mut self,
message: Message,
_clipboard: &mut Clipboard,
) -> Command<Message> {
fn update(&mut self, message: Message) -> Command<Message> {
match message {
Message::Add => {
self.last_id = self.last_id + 1;

View file

@ -1,7 +1,7 @@
use iced::{
button, executor, Align, Application, Button, Checkbox, Clipboard, Column,
Command, Container, Element, HorizontalAlignment, Length, Settings,
Subscription, Text,
button, executor, Align, Application, Button, Checkbox, Column, Command,
Container, Element, HorizontalAlignment, Length, Settings, Subscription,
Text,
};
use iced_native::{window, Event};
@ -40,11 +40,7 @@ impl Application for Events {
String::from("Events - Iced")
}
fn update(
&mut self,
message: Message,
_clipboard: &mut Clipboard,
) -> Command<Message> {
fn update(&mut self, message: Message) -> Command<Message> {
match message {
Message::EventOccurred(event) if self.enabled => {
self.last.push(event);

View file

@ -12,8 +12,8 @@ use iced::slider::{self, Slider};
use iced::time;
use iced::window;
use iced::{
Align, Application, Checkbox, Clipboard, Column, Command, Container,
Element, Length, Row, Settings, Subscription, Text,
Align, Application, Checkbox, Column, Command, Container, Element, Length,
Row, Settings, Subscription, Text,
};
use preset::Preset;
use std::time::{Duration, Instant};
@ -71,11 +71,7 @@ impl Application for GameOfLife {
String::from("Game of Life - Iced")
}
fn update(
&mut self,
message: Message,
_clipboard: &mut Clipboard,
) -> Command<Message> {
fn update(&mut self, message: Message) -> Command<Message> {
match message {
Message::Grid(message, version) => {
if version == self.version {

View file

@ -1,7 +1,7 @@
use iced_glow::Renderer;
use iced_glutin::{
slider, Align, Clipboard, Color, Column, Command, Element, Length, Program,
Row, Slider, Text,
slider, Align, Color, Column, Command, Element, Length, Program, Row,
Slider, Text,
};
pub struct Controls {
@ -30,13 +30,8 @@ impl Controls {
impl Program for Controls {
type Renderer = Renderer;
type Message = Message;
type Clipboard = Clipboard;
fn update(
&mut self,
message: Message,
_clipboard: &mut Clipboard,
) -> Command<Message> {
fn update(&mut self, message: Message) -> Command<Message> {
match message {
Message::BackgroundColorChanged(color) => {
self.background_color = color;

View file

@ -1,7 +1,7 @@
use iced_wgpu::Renderer;
use iced_winit::{
slider, Align, Clipboard, Color, Column, Command, Element, Length, Program,
Row, Slider, Text,
slider, Align, Color, Column, Command, Element, Length, Program, Row,
Slider, Text,
};
pub struct Controls {
@ -30,13 +30,8 @@ impl Controls {
impl Program for Controls {
type Renderer = Renderer;
type Message = Message;
type Clipboard = Clipboard;
fn update(
&mut self,
message: Message,
_clipboard: &mut Clipboard,
) -> Command<Message> {
fn update(&mut self, message: Message) -> Command<Message> {
match message {
Message::BackgroundColorChanged(color) => {
self.background_color = color;

View file

@ -1,7 +1,6 @@
use iced::menu::{self, Menu};
use iced::{
executor, Application, Clipboard, Command, Container, Element, Length,
Settings, Text,
executor, Application, Command, Container, Element, Length, Settings, Text,
};
use iced_native::keyboard::{Hotkey, KeyCode, Modifiers};
@ -92,11 +91,7 @@ impl Application for App {
])
}
fn update(
&mut self,
message: Message,
_clipboard: &mut Clipboard,
) -> Command<Message> {
fn update(&mut self, message: Message) -> Command<Message> {
match message {
Message::MenuActivated(entry) => self.selected = Some(entry),
}

View file

@ -1,8 +1,7 @@
use iced::{
button, executor, keyboard, pane_grid, scrollable, Align, Application,
Button, Clipboard, Color, Column, Command, Container, Element,
HorizontalAlignment, Length, PaneGrid, Row, Scrollable, Settings,
Subscription, Text,
Button, Color, Column, Command, Container, Element, HorizontalAlignment,
Length, PaneGrid, Row, Scrollable, Settings, Subscription, Text,
};
use iced_native::{event, subscription, Event};
@ -51,11 +50,7 @@ impl Application for Example {
String::from("Pane grid - Iced")
}
fn update(
&mut self,
message: Message,
_clipboard: &mut Clipboard,
) -> Command<Message> {
fn update(&mut self, message: Message) -> Command<Message> {
match message {
Message::Split(axis, pane) => {
let result = self.panes.split(

View file

@ -1,6 +1,6 @@
use iced::{
button, futures, image, Align, Application, Button, Clipboard, Column,
Command, Container, Element, Length, Row, Settings, Text,
button, futures, image, Align, Application, Button, Column, Command,
Container, Element, Length, Row, Settings, Text,
};
pub fn main() -> iced::Result {
@ -48,11 +48,7 @@ impl Application for Pokedex {
format!("{} - Pokédex", subtitle)
}
fn update(
&mut self,
message: Message,
_clipboard: &mut Clipboard,
) -> Command<Message> {
fn update(&mut self, message: Message) -> Command<Message> {
match message {
Message::PokemonFound(Ok(pokemon)) => {
*self = Pokedex::Loaded {

View file

@ -8,8 +8,8 @@
//! [1]: https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Basic_animations#An_animated_solar_system
use iced::{
canvas::{self, Cursor, Path, Stroke},
executor, time, window, Application, Canvas, Clipboard, Color, Command,
Element, Length, Point, Rectangle, Settings, Size, Subscription, Vector,
executor, time, window, Application, Canvas, Color, Command, Element,
Length, Point, Rectangle, Settings, Size, Subscription, Vector,
};
use std::time::Instant;
@ -48,11 +48,7 @@ impl Application for SolarSystem {
String::from("Solar system - Iced")
}
fn update(
&mut self,
message: Message,
_clipboard: &mut Clipboard,
) -> Command<Message> {
fn update(&mut self, message: Message) -> Command<Message> {
match message {
Message::Tick(instant) => {
self.state.update(instant);

View file

@ -1,6 +1,6 @@
use iced::{
button, executor, time, Align, Application, Button, Clipboard, Column,
Command, Container, Element, HorizontalAlignment, Length, Row, Settings,
button, executor, time, Align, Application, Button, Column, Command,
Container, Element, HorizontalAlignment, Length, Row, Settings,
Subscription, Text,
};
use std::time::{Duration, Instant};
@ -49,11 +49,7 @@ impl Application for Stopwatch {
String::from("Stopwatch - Iced")
}
fn update(
&mut self,
message: Message,
_clipboard: &mut Clipboard,
) -> Command<Message> {
fn update(&mut self, message: Message) -> Command<Message> {
match message {
Message::Toggle => match self.state {
State::Idle => {

View file

@ -1,7 +1,7 @@
use iced::{
button, scrollable, text_input, Align, Application, Button, Checkbox,
Clipboard, Column, Command, Container, Element, Font, HorizontalAlignment,
Length, Row, Scrollable, Settings, Text, TextInput,
Column, Command, Container, Element, Font, HorizontalAlignment, Length,
Row, Scrollable, Settings, Text, TextInput,
};
use serde::{Deserialize, Serialize};
@ -58,11 +58,7 @@ impl Application for Todos {
format!("Todos{} - Iced", if dirty { "*" } else { "" })
}
fn update(
&mut self,
message: Message,
_clipboard: &mut Clipboard,
) -> Command<Message> {
fn update(&mut self, message: Message) -> Command<Message> {
match self {
Todos::Loading => {
match message {

View file

@ -1,6 +1,6 @@
use iced::{
executor, Application, Clipboard, Command, Container, Element, Length,
Settings, Subscription, Text,
executor, Application, Command, Container, Element, Length, Settings,
Subscription, Text,
};
use iced_native::{
event::{MacOS, PlatformSpecific},
@ -34,11 +34,7 @@ impl Application for App {
String::from("Url - Iced")
}
fn update(
&mut self,
message: Message,
_clipboard: &mut Clipboard,
) -> Command<Message> {
fn update(&mut self, message: Message) -> Command<Message> {
match message {
Message::EventOccurred(event) => {
if let Event::PlatformSpecific(PlatformSpecific::MacOS(