Use new enum variant and new winit repo

This commit is contained in:
Richard 2021-06-09 15:00:01 -03:00 committed by Héctor Ramón Jiménez
parent 9ae22b58d8
commit 96a462d2f2
No known key found for this signature in database
GPG Key ID: 44B88EB52AB1EE8D
6 changed files with 41 additions and 18 deletions

View File

@ -93,7 +93,7 @@ iced_futures = { version = "0.3", path = "futures" }
thiserror = "1.0" thiserror = "1.0"
[patch.crates-io] [patch.crates-io]
winit = { git="https://github.com/cryptowatch/winit", rev="f9180f3b3c0f4fb8fd8c65bd0adf641cd6b32dd0" } winit = { git="https://github.com/iced-rs/winit", rev="152eda9b2d995dd0f5b886a53bddac7c75738b47" }
[target.'cfg(not(target_arch = "wasm32"))'.dependencies] [target.'cfg(not(target_arch = "wasm32"))'.dependencies]
iced_winit = { version = "0.3", path = "winit" } iced_winit = { version = "0.3", path = "winit" }

View File

@ -8,5 +8,3 @@ publish = false
[dependencies] [dependencies]
iced = { path = "../.." } iced = { path = "../.." }
iced_native = { path = "../../native" } iced_native = { path = "../../native" }
syslog="4.0"
log="0.4"

View File

@ -1,8 +1,11 @@
use iced::{ use iced::{
executor, Application, Command, Clipboard, executor, Application, Clipboard, Command, Container, Element, Length,
Container, Element, Length, Settings, Subscription, Text, Settings, Subscription, Text,
};
use iced_native::{
event::{MacOS, PlatformSpecific},
Event,
}; };
use iced_native::Event;
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
App::run(Settings::default()) App::run(Settings::default())
@ -38,7 +41,10 @@ impl Application for App {
) -> Command<Message> { ) -> Command<Message> {
match message { match message {
Message::EventOccurred(event) => { Message::EventOccurred(event) => {
if let Event::UrlReceived(url) = event{ if let Event::PlatformSpecific(PlatformSpecific::MacOS(
MacOS::ReceivedUrl(url),
)) = event
{
self.url = Some(url); self.url = Some(url);
} }
} }
@ -54,7 +60,7 @@ impl Application for App {
fn view(&mut self) -> Element<Message> { fn view(&mut self) -> Element<Message> {
let content = match &self.url { let content = match &self.url {
Some(url) => Text::new(format!("{}", url)), Some(url) => Text::new(format!("{}", url)),
None => Text::new("No URL received yet!") None => Text::new("No URL received yet!"),
}; };
Container::new(content.size(48)) Container::new(content.size(48))

View File

@ -237,8 +237,9 @@ async fn run_instance<A, E, C>(
context.window().request_redraw(); context.window().request_redraw();
} }
event::Event::ReceivedUrl(url) => { event::Event::PlatformSpecific(event::PlatformSpecific::MacOS(event::MacOS::ReceivedUrl(url))) => {
events.push(iced_native::Event::UrlReceived(url)); use iced_native::event;
events.push(iced_native::Event::PlatformSpecific(event::PlatformSpecific::MacOS(event::MacOS::ReceivedUrl(url))));
} }
event::Event::UserEvent(message) => { event::Event::UserEvent(message) => {
messages.push(message); messages.push(message);

View File

@ -24,9 +24,26 @@ pub enum Event {
/// A touch event /// A touch event
Touch(touch::Event), Touch(touch::Event),
// TODO: System(system::Event)? /// A platform specific event
/// A url was received. PlatformSpecific(PlatformSpecific),
UrlReceived(String), }
/// A platform specific event
#[derive(Debug, Clone, PartialEq)]
pub enum PlatformSpecific {
/// A MacOS specific event
MacOS(MacOS),
}
/// Describes an event specific to MacOS
#[derive(Debug, Clone, PartialEq)]
pub enum MacOS {
/// Triggered when the app receives an URL from the system
///
/// _**Note:** For this event to be triggered, the executable needs to be properly [bundled]!_
///
/// [bundled]: https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/BundleTypes/BundleTypes.html#//apple_ref/doc/uid/10000123i-CH101-SW19
ReceivedUrl(String),
} }
/// The status of an [`Event`] after being processed. /// The status of an [`Event`] after being processed.

View File

@ -310,8 +310,9 @@ async fn run_instance<A, E, C>(
window.request_redraw(); window.request_redraw();
} }
event::Event::ReceivedUrl(url) => { event::Event::PlatformSpecific(event::PlatformSpecific::MacOS(event::MacOS::ReceivedUrl(url))) => {
events.push(iced_native::Event::UrlReceived(url)); use iced_native::event;
events.push(iced_native::Event::PlatformSpecific(event::PlatformSpecific::MacOS(event::MacOS::ReceivedUrl(url))));
} }
event::Event::UserEvent(message) => { event::Event::UserEvent(message) => {
messages.push(message); messages.push(message);