summaryrefslogtreecommitdiffstats
path: root/examples/url_handler/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/url_handler/src/main.rs')
-rw-r--r--examples/url_handler/src/main.rs67
1 files changed, 67 insertions, 0 deletions
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<String>,
+}
+
+#[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<Message>) {
+ (App::default(), Command::none())
+ }
+
+ fn title(&self) -> String {
+ String::from("Url - Iced")
+ }
+
+ fn update(
+ &mut self,
+ message: Message,
+ _clipboard: &mut Clipboard,
+ ) -> Command<Message> {
+ match message {
+ Message::EventOccurred(event) => {
+ if let Event::UrlReceived(url) = event{
+ self.url = Some(url);
+ }
+ }
+ };
+
+ Command::none()
+ }
+
+ fn subscription(&self) -> Subscription<Message> {
+ iced_native::subscription::events().map(Message::EventOccurred)
+ }
+
+ fn view(&mut self) -> Element<Message> {
+ 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()
+ }
+}