-
Notifications
You must be signed in to change notification settings - Fork 4
[Help wanted] Events on iced_web? #3
Comments
wasm-bindgen with web-sys works for events, I'm also able to use lazy static with Mutex to share data between the event and iced. Now the issue is, how do i make that event call the update method of the sandbox? Here's the event code. let window = web_sys::window().unwrap();
let closure = Closure::wrap(Box::new(move |_event: web_sys::MouseEvent| {
// ...
}) as Box<dyn FnMut(_)>);
window.add_event_listener_with_callback(
"mousedown",
closure.as_ref().unchecked_ref()
).expect("what happened?");
closure.forget(); |
You may be able to listen to mouse clicks by implementing your own event subscription (see iced-rs/iced#122). Basically, you need to implement the I think we should include subscriptions like this one in |
Using a cut down version of this example https://github.com/hecrj/iced/blob/master/examples/download_progress/src/download.rs fn stream(self: Box<Self>, _input: futures::stream::BoxStream<'static, I>)
-> futures::stream::BoxStream<'static, Self::Output> {
Box::pin(futures::stream::unfold(
State::Ready(self.url),
|_state| async move {
None
},
))
} This looks to compile fine natively, but when the target is wasm32 it's unable to satisfy types because it expects a Fixed: had to use |
New issue, there's no subscription() method for the Sandbox trait, and i don't see any way to subscribe the sandbox to the Recipe stream. |
This was fixed recently in iced-rs/iced#322. I recommend you to depend on
Yes,
|
https://pastebin.com/9NMLs5qd iced = { git = "https://github.com/hecrj/iced", features = ["canvas", "debug", "image"] }
iced_futures = { git = "https://github.com/hecrj/iced"}
async-std = { version = "1.0", features = ["unstable"] }
wasm-bindgen = "0.2.63"
js-sys = "*"
lazy_static = "1.4.0"
[dependencies.web-sys]
version = "0.3.4"
# TODO: remove unused features
features = [
'CanvasRenderingContext2d',
'CssStyleDeclaration',
'Document',
'Element',
'EventTarget',
'HtmlCanvasElement',
'HtmlElement',
'MouseEvent',
'Node',
'Window',
] |
@hecrj Using master and still having the same problem, even though I can see the fix in the repo: #[cfg(target_arch = "wasm32")]
pub type BoxStream<T> = futures::stream::LocalBoxStream<'static, T>;
error[E0053]: method `stream` has an incompatible type for trait
--> native\src\subscription\events.rs:18:5
|
18 | / fn stream(
19 | | self: Box<Self>,
20 | | event_stream: EventStream,
21 | | ) -> BoxStream<Self::Output> {
22 | | event_stream
23 | | }
| |_____^ expected trait `Stream<Item = event::Event>`, found trait `Stream<Item = event::Event> + std::marker::Send`
|
= note: expected fn pointer `fn(Box<_>, Pin<Box<(dyn Stream<Item = event::Event> + 'static)>>) -> Pin<_>`
found fn pointer `fn(Box<_>, Pin<Box<(dyn Stream<Item = event::Event> + std::marker::Send + 'static)>>) -> Pin<_>`
error: aborting due to previous error |
I am seeing the same behavior documented by @sum-elier when I attempt to build the pane_grid example.
Note: Not that I think it would have any bearing; but, I do have to override the iced dependency in Cargo.toml as follows since my current laptop does not support Vulkan: Any insight, guidance, etc. would be appreciated. Thank you for all of the work you are doing here. I am actually hoping to offer assistance once I become more familiar with both Rust and this framework. |
I can't find any way with iced to catch mouse and keyboard events, is this possible, or will a different library be needed for me to do this?
If the later is the case, which one would be recommended that is able to interface with iced, and modify various fields with those events, while making the events not trigger when on an input box, in the case of keyboard events.
The text was updated successfully, but these errors were encountered: