-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
removed more extraneous files, old crates and made progress on WASM
- Loading branch information
Showing
52 changed files
with
419 additions
and
2,124 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,72 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<link data-trunk rel="copy-dir" href="../../img" /> | ||
<link data-trunk rel="copy-dir" href="../../gltf" /> | ||
<link data-trunk rel="copy-dir" href="../../fonts" /> | ||
</head> | ||
<head> | ||
<style> | ||
/* A sane CSS reset from | ||
* https://www.digitalocean.com/community/tutorials/css-minimal-css-reset | ||
*/ | ||
html { | ||
box-sizing: border-box; | ||
font-size: 16px; | ||
} | ||
|
||
*, | ||
*:before, | ||
*:after { | ||
box-sizing: inherit; | ||
} | ||
|
||
body, | ||
h1, | ||
h2, | ||
h3, | ||
h4, | ||
h5, | ||
h6, | ||
p, | ||
ol, | ||
ul { | ||
margin: 0; | ||
padding: 0; | ||
font-weight: normal; | ||
} | ||
|
||
ol, | ||
ul { | ||
list-style: none; | ||
} | ||
|
||
img { | ||
max-width: 100%; | ||
height: auto; | ||
} | ||
|
||
main { | ||
margin: 0; | ||
width: 100%; | ||
height: 100%; | ||
background-color: #7f7f7f; | ||
} | ||
|
||
main canvas { | ||
margin: 0; | ||
padding: 0; | ||
position: absolute; | ||
left: 0; | ||
right: 0; | ||
top: 0; | ||
bottom: 0; | ||
background-color: #ffffff; | ||
} | ||
|
||
section fieldset { | ||
margin: 0 0.25em 0.5em 0.25em; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<main> | ||
<canvas></canvas> | ||
</main> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
//! A light abstraction over UI event callbacks. | ||
//! | ||
//! This uses [`futures-lite::Stream`] to send events to downstream listeners. | ||
use std::{ | ||
pin::Pin, | ||
sync::{Arc, Mutex}, | ||
task::Waker, | ||
}; | ||
|
||
use futures_lite::Stream; | ||
use wasm_bindgen::{prelude::Closure, JsCast, JsValue}; | ||
use web_sys::EventTarget; | ||
|
||
struct WebCallback { | ||
target: EventTarget, | ||
name: String, | ||
closure: Option<Arc<Closure<dyn FnMut(JsValue)>>>, | ||
waker: Arc<Mutex<Option<Waker>>>, | ||
event: Arc<Mutex<Option<web_sys::Event>>>, | ||
} | ||
|
||
impl Drop for WebCallback { | ||
fn drop(&mut self) { | ||
if let Some(arc) = self.closure.take() { | ||
if let Some(closure) = Arc::try_unwrap(arc).ok() { | ||
self.target | ||
.remove_event_listener_with_callback( | ||
self.name.as_str(), | ||
closure.as_ref().unchecked_ref(), | ||
) | ||
.unwrap(); | ||
log::trace!("dropping event {}", self.name); | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl Stream for WebCallback { | ||
type Item = web_sys::Event; | ||
|
||
fn poll_next( | ||
self: Pin<&mut Self>, | ||
cx: &mut std::task::Context<'_>, | ||
) -> std::task::Poll<Option<Self::Item>> { | ||
let data = self.get_mut(); | ||
*data.waker.lock().unwrap() = Some(cx.waker().clone()); | ||
|
||
if let Some(event) = data.event.lock().unwrap().take() { | ||
std::task::Poll::Ready(Some(event)) | ||
} else { | ||
std::task::Poll::Pending | ||
} | ||
} | ||
} | ||
|
||
/// Listen for events of the given name on the given target. | ||
/// All events will be sent downstream until the stream is | ||
/// dropped. | ||
pub fn event_stream( | ||
ev_name: &str, | ||
target: &web_sys::EventTarget, | ||
) -> impl Stream<Item = web_sys::Event> { | ||
let waker: Arc<Mutex<Option<Waker>>> = Default::default(); | ||
let waker_here = waker.clone(); | ||
|
||
let event: Arc<Mutex<Option<web_sys::Event>>> = Default::default(); | ||
let event_here = event.clone(); | ||
|
||
let closure = Closure::wrap(Box::new(move |val: JsValue| { | ||
let ev = val.unchecked_into(); | ||
*event.lock().unwrap() = Some(ev); | ||
if let Some(waker) = waker.lock().unwrap().take() { | ||
waker.wake() | ||
} | ||
}) as Box<dyn FnMut(JsValue)>); | ||
|
||
target | ||
.add_event_listener_with_callback(ev_name, closure.as_ref().unchecked_ref()) | ||
.unwrap(); | ||
|
||
WebCallback { | ||
target: target.clone(), | ||
name: ev_name.to_string(), | ||
closure: Some(closure.into()), | ||
event: event_here, | ||
waker: waker_here, | ||
} | ||
} |
Oops, something went wrong.