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"
[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]
iced_winit = { version = "0.3", path = "winit" }

View File

@ -7,6 +7,4 @@ publish = false
[dependencies]
iced = { path = "../.." }
iced_native = { path = "../../native" }
syslog="4.0"
log="0.4"
iced_native = { path = "../../native" }

View File

@ -1,8 +1,11 @@
use iced::{
executor, Application, Command, Clipboard,
Container, Element, Length, Settings, Subscription, Text,
executor, Application, Clipboard, Command, Container, Element, Length,
Settings, Subscription, Text,
};
use iced_native::{
event::{MacOS, PlatformSpecific},
Event,
};
use iced_native::Event;
pub fn main() -> iced::Result {
App::run(Settings::default())
@ -38,7 +41,10 @@ impl Application for App {
) -> Command<Message> {
match message {
Message::EventOccurred(event) => {
if let Event::UrlReceived(url) = event{
if let Event::PlatformSpecific(PlatformSpecific::MacOS(
MacOS::ReceivedUrl(url),
)) = event
{
self.url = Some(url);
}
}
@ -52,9 +58,9 @@ impl Application for App {
}
fn view(&mut self) -> Element<Message> {
let content = match &self.url{
let content = match &self.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))

View File

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

View File

@ -23,10 +23,27 @@ pub enum Event {
/// A touch event
Touch(touch::Event),
// TODO: System(system::Event)?
/// A url was received.
UrlReceived(String),
/// A platform specific event
PlatformSpecific(PlatformSpecific),
}
/// 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.

View File

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