Added events for url handling and create example
This commit is contained in:
parent
d2c8a3e04b
commit
9ae22b58d8
|
@ -84,6 +84,7 @@ members = [
|
||||||
"examples/todos",
|
"examples/todos",
|
||||||
"examples/tour",
|
"examples/tour",
|
||||||
"examples/tooltip",
|
"examples/tooltip",
|
||||||
|
"examples/url_handler",
|
||||||
]
|
]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -91,6 +92,9 @@ iced_core = { version = "0.4", path = "core" }
|
||||||
iced_futures = { version = "0.3", path = "futures" }
|
iced_futures = { version = "0.3", path = "futures" }
|
||||||
thiserror = "1.0"
|
thiserror = "1.0"
|
||||||
|
|
||||||
|
[patch.crates-io]
|
||||||
|
winit = { git="https://github.com/cryptowatch/winit", rev="f9180f3b3c0f4fb8fd8c65bd0adf641cd6b32dd0" }
|
||||||
|
|
||||||
[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" }
|
||||||
iced_glutin = { version = "0.2", path = "glutin", optional = true }
|
iced_glutin = { version = "0.2", path = "glutin", optional = true }
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
[package]
|
||||||
|
name = "url_handler"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
|
||||||
|
edition = "2018"
|
||||||
|
publish = false
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
iced = { path = "../.." }
|
||||||
|
iced_native = { path = "../../native" }
|
||||||
|
syslog="4.0"
|
||||||
|
log="0.4"
|
|
@ -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()
|
||||||
|
}
|
||||||
|
}
|
|
@ -237,6 +237,9 @@ async fn run_instance<A, E, C>(
|
||||||
|
|
||||||
context.window().request_redraw();
|
context.window().request_redraw();
|
||||||
}
|
}
|
||||||
|
event::Event::ReceivedUrl(url) => {
|
||||||
|
events.push(iced_native::Event::UrlReceived(url));
|
||||||
|
}
|
||||||
event::Event::UserEvent(message) => {
|
event::Event::UserEvent(message) => {
|
||||||
messages.push(message);
|
messages.push(message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,10 @@ pub enum Event {
|
||||||
|
|
||||||
/// A touch event
|
/// A touch event
|
||||||
Touch(touch::Event),
|
Touch(touch::Event),
|
||||||
|
|
||||||
|
// TODO: System(system::Event)?
|
||||||
|
/// A url was received.
|
||||||
|
UrlReceived(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The status of an [`Event`] after being processed.
|
/// The status of an [`Event`] after being processed.
|
||||||
|
|
|
@ -310,6 +310,9 @@ async fn run_instance<A, E, C>(
|
||||||
|
|
||||||
window.request_redraw();
|
window.request_redraw();
|
||||||
}
|
}
|
||||||
|
event::Event::ReceivedUrl(url) => {
|
||||||
|
events.push(iced_native::Event::UrlReceived(url));
|
||||||
|
}
|
||||||
event::Event::UserEvent(message) => {
|
event::Event::UserEvent(message) => {
|
||||||
messages.push(message);
|
messages.push(message);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue