From 9ae22b58d843d9a39212028478598c19a49bc2e6 Mon Sep 17 00:00:00 2001 From: Richard Date: Wed, 21 Apr 2021 17:52:31 -0300 Subject: Added events for url handling and create example --- examples/url_handler/Cargo.toml | 12 +++++++ examples/url_handler/src/main.rs | 67 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 examples/url_handler/Cargo.toml create mode 100644 examples/url_handler/src/main.rs (limited to 'examples') diff --git a/examples/url_handler/Cargo.toml b/examples/url_handler/Cargo.toml new file mode 100644 index 00000000..595bdac0 --- /dev/null +++ b/examples/url_handler/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "url_handler" +version = "0.1.0" +authors = ["Héctor Ramón Jiménez "] +edition = "2018" +publish = false + +[dependencies] +iced = { path = "../.." } +iced_native = { path = "../../native" } +syslog="4.0" +log="0.4" \ No newline at end of file diff --git a/examples/url_handler/src/main.rs b/examples/url_handler/src/main.rs new file mode 100644 index 00000000..56d81031 --- /dev/null +++ b/examples/url_handler/src/main.rs @@ -0,0 +1,67 @@ +use iced::{ + executor, Application, Command, Clipboard, + Container, Element, Length, Settings, Subscription, Text, +}; +use iced_native::Event; + +pub fn main() -> iced::Result { + App::run(Settings::default()) +} + +#[derive(Debug, Default)] +struct App { + url: Option, +} + +#[derive(Debug, Clone)] +enum Message { + EventOccurred(iced_native::Event), +} + +impl Application for App { + type Executor = executor::Default; + type Message = Message; + type Flags = (); + + fn new(_flags: ()) -> (App, Command) { + (App::default(), Command::none()) + } + + fn title(&self) -> String { + String::from("Url - Iced") + } + + fn update( + &mut self, + message: Message, + _clipboard: &mut Clipboard, + ) -> Command { + match message { + Message::EventOccurred(event) => { + if let Event::UrlReceived(url) = event{ + self.url = Some(url); + } + } + }; + + Command::none() + } + + fn subscription(&self) -> Subscription { + iced_native::subscription::events().map(Message::EventOccurred) + } + + fn view(&mut self) -> Element { + let content = match &self.url{ + Some(url) => Text::new(format!("{}", url)), + None => Text::new("No URL received yet!") + }; + + Container::new(content.size(48)) + .width(Length::Fill) + .height(Length::Fill) + .center_x() + .center_y() + .into() + } +} -- cgit From 96a462d2f2cb608ad14c93cc55896108a2dccb2b Mon Sep 17 00:00:00 2001 From: Richard Date: Wed, 9 Jun 2021 15:00:01 -0300 Subject: Use new enum variant and new winit repo --- examples/url_handler/Cargo.toml | 4 +--- examples/url_handler/src/main.rs | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) (limited to 'examples') diff --git a/examples/url_handler/Cargo.toml b/examples/url_handler/Cargo.toml index 595bdac0..911b2f25 100644 --- a/examples/url_handler/Cargo.toml +++ b/examples/url_handler/Cargo.toml @@ -7,6 +7,4 @@ publish = false [dependencies] iced = { path = "../.." } -iced_native = { path = "../../native" } -syslog="4.0" -log="0.4" \ No newline at end of file +iced_native = { path = "../../native" } \ No newline at end of file diff --git a/examples/url_handler/src/main.rs b/examples/url_handler/src/main.rs index 56d81031..f14e5227 100644 --- a/examples/url_handler/src/main.rs +++ b/examples/url_handler/src/main.rs @@ -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 { 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 { - 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)) -- cgit