Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stdweb support for eventloop 2.0 #797

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
fd4db40
Create the type layout
ryanisaacg Feb 13, 2019
f44e98d
Implemented a few easy methods
ryanisaacg Feb 20, 2019
c088f8b
Create the outline of event input and handler calls
ryanisaacg Feb 26, 2019
f698d45
Add key and mouse event support that typechecks
ryanisaacg Mar 2, 2019
37d354c
Get to a state where a canvas is spawned
ryanisaacg Mar 10, 2019
283a8de
Refactor out the stdweb functionality into different modules
ryanisaacg Mar 10, 2019
3dd0e31
Merge eventloop-2.0 into stdweb-eventloop-2
ryanisaacg Mar 11, 2019
aaee724
Rearchitect to allow API compliance
ryanisaacg Mar 12, 2019
d1deba8
Rename modules
ryanisaacg Mar 12, 2019
a5166ba
Implement request_redraw
ryanisaacg Mar 16, 2019
96786bb
Implement focus event
ryanisaacg Mar 16, 2019
85446d8
Fix warnings
ryanisaacg Mar 16, 2019
b09629f
Handle ControlFlow::Exit
ryanisaacg Mar 19, 2019
7c6bdcc
Handle ControlFlow::Exit and dealing with events-in-events
ryanisaacg Mar 23, 2019
9e25561
Fix compile failures and add canvas positioning
ryanisaacg Apr 3, 2019
fe5e300
Clean up and document the core of stdweb event handling
ryanisaacg Apr 25, 2019
9f801cf
Only send the request-redraw on the next animation frame
ryanisaacg Apr 29, 2019
70c7382
Fix the request_animation_frame lifetimes
ryanisaacg May 2, 2019
37dadab
Add access to the canvas in the Window
ryanisaacg Jun 1, 2019
1409f83
Add support for mouse wheel
ryanisaacg Jun 1, 2019
f2b6ef2
Merge master into stdweb-eventloop-2
ryanisaacg Jun 1, 2019
b59e3c6
WIP
ryanisaacg Jun 15, 2019
2690306
Implement Poll and WaitUntil in the stdweb backend
ryanisaacg Jun 17, 2019
182beb4
Indicate that I will be maintaing the stdweb backend
ryanisaacg Jun 17, 2019
b571362
Fix a panic due to double-borrow
ryanisaacg Jun 21, 2019
cf28751
Remove unnecessary set-to-wait in example
ryanisaacg Jun 23, 2019
a0f280e
Update how timeouts are cleared to avoid possible double-clearing
ryanisaacg Jun 23, 2019
94387c4
Merge master Monitor APIs to stdweb
ryanisaacg Jun 27, 2019
e94a006
Merge remote-tracking branch 'upstream/master' into stdweb-eventloop-2
ryanisaacg Jul 9, 2019
7bbc829
Fix a few warnings
ryanisaacg Jul 9, 2019
c76ab65
Add on-close event listening
ryanisaacg Jul 9, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ This table summarizes who can be contacted in which case, with the following leg
- `T` - Tester: has the ability of testing the platform
- ` `: knows nothing of this platform

| Platform | Windows | macOS | X11 | Wayland | Android | iOS | Emscripten |
| :--- | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
| @mitchmindtree | T | | T | T | | | |
| @Osspial | M | | T | T | T | | T |
| @vberger | | | T | M | | | |
| @mtak- | | T | | | T | M | |
| Platform | Windows | macOS | X11 | Wayland | Android | iOS | Emscripten | Stdweb |
| :--- | :---: | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
| @mitchmindtree | T | | T | T | | | | |
| @Osspial | M | | T | T | T | | T | |
| @vberger | | | T | M | | | | |
| @mtak- | | T | | | T | M | | |
| @ryanisacg | T | T | | | | | | M |
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ categories = ["gui"]
features = ["serde"]

[dependencies]
instant = "0.1"
lazy_static = "1"
libc = "0.2"
log = "0.4"
Expand Down Expand Up @@ -72,3 +73,7 @@ percent-encoding = "1.0"

[target.'cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd", target_os = "windows"))'.dependencies.parking_lot]
version = "0.8"

[target.'cfg(target_arch = "wasm32")'.dependencies]
stdweb = { path = "../stdweb", optional = true }
instant = { version = "0.1", features = ["stdweb"] }
6 changes: 5 additions & 1 deletion examples/window.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
extern crate winit;
#[macro_use]
extern crate stdweb;

use winit::window::WindowBuilder;
use winit::event::{Event, WindowEvent};
use winit::event_loop::{EventLoop, ControlFlow};
Expand All @@ -10,9 +13,10 @@ fn main() {
.with_title("A fantastic window!")
.build(&event_loop)
.unwrap();
console!(log, "Built window!");

event_loop.run(|event, _, control_flow| {
println!("{:?}", event);
console!(log, format!("{:?}", event));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to revert the changes in this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, before merge I'll be doing some cleanup (this is still actively in development and I use this example to test.)


match event {
Event::WindowEvent {
Expand Down
4 changes: 2 additions & 2 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! processed and used to modify the program state. For more details, see the root-level documentation.
//!
//! [event_loop_run]: ../event_loop/struct.EventLoop.html#method.run
use std::time::Instant;
use instant::Instant;
use std::path::PathBuf;

use dpi::{LogicalPosition, LogicalSize};
Expand Down Expand Up @@ -58,7 +58,7 @@ impl<T> Event<T> {
}

/// Describes the reason the event loop is resuming.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum StartCause {
/// Sent if the time specified by `ControlFlow::WaitUntil` has been reached. Contains the
/// moment the timeout was requested and the requested resume time. The actual resume time is
Expand Down
4 changes: 2 additions & 2 deletions src/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//! [event_loop_proxy]: ./struct.EventLoopProxy.html
//! [send_event]: ./struct.EventLoopProxy.html#method.send_event
use std::{fmt, error};
use std::time::Instant;
use instant::Instant;
use std::ops::Deref;

use platform_impl;
Expand Down Expand Up @@ -69,7 +69,7 @@ impl<T> fmt::Debug for EventLoopWindowTarget<T> {
/// the control flow to `Poll`.
///
/// [events_cleared]: ../event/enum.Event.html#variant.EventsCleared
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum ControlFlow {
/// When the current loop iteration finishes, immediately begin a new iteration regardless of
/// whether or not new events are available to process.
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
//! [`LoopDestroyed`]: ./event/enum.Event.html#variant.LoopDestroyed
//! [`platform`]: ./platform/index.html

extern crate instant;
#[allow(unused_imports)]
#[macro_use]
extern crate lazy_static;
Expand Down Expand Up @@ -109,6 +110,9 @@ extern crate parking_lot;
extern crate percent_encoding;
#[cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))]
extern crate smithay_client_toolkit as sctk;
#[cfg(feature = "stdweb")]
#[macro_use]
extern crate stdweb;
#[cfg(any(target_os = "linux", target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))]
extern crate calloop;

Expand Down
2 changes: 2 additions & 0 deletions src/platform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ pub mod macos;
pub mod unix;
pub mod windows;

pub mod stdweb;

pub mod desktop;
8 changes: 8 additions & 0 deletions src/platform/stdweb.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![cfg(feature = "stdweb")]

use stdweb::web::html_element::CanvasElement;

pub trait WindowExtStdweb {
fn canvas(&self) -> CanvasElement;
}

6 changes: 5 additions & 1 deletion src/platform_impl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ mod platform;
#[cfg(target_os = "emscripten")]
#[path="emscripten/mod.rs"]
mod platform;
#[cfg(feature = "stdweb")]
#[path="stdweb/mod.rs"]
mod platform;

#[cfg(all(not(target_os = "ios"), not(target_os = "windows"), not(target_os = "linux"),
not(target_os = "macos"), not(target_os = "android"), not(target_os = "dragonfly"),
not(target_os = "freebsd"), not(target_os = "netbsd"), not(target_os = "openbsd"),
not(target_os = "emscripten")))]
not(target_os = "emscripten"),
not(feature = "stdweb")))]
compile_error!("The platform you're compiling for is not supported by winit");
Loading