mirror of
https://github.com/rust-windowing/winit.git
synced 2026-08-29 04:40:04 -04:00
TEMPORARY: add testing example
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -2,5 +2,9 @@ Cargo.lock
|
|||||||
target/
|
target/
|
||||||
rls/
|
rls/
|
||||||
.vscode/
|
.vscode/
|
||||||
|
util/
|
||||||
*~
|
*~
|
||||||
|
*.wasm
|
||||||
|
*.ts
|
||||||
|
*.js
|
||||||
#*#
|
#*#
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ log = "0.4"
|
|||||||
serde = { version = "1", optional = true, features = ["serde_derive"] }
|
serde = { version = "1", optional = true, features = ["serde_derive"] }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
web-sys-support = ["web-sys", "wasm-bindgen"]
|
web_sys = ["web-sys", "wasm-bindgen"]
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
image = "0.21"
|
image = "0.21"
|
||||||
@@ -81,6 +81,7 @@ version = "0.8"
|
|||||||
version = "0.3.22"
|
version = "0.3.22"
|
||||||
optional = true
|
optional = true
|
||||||
features = [
|
features = [
|
||||||
|
'console',
|
||||||
'Document',
|
'Document',
|
||||||
'DomRect',
|
'DomRect',
|
||||||
'Element',
|
'Element',
|
||||||
@@ -108,3 +109,7 @@ optional = true
|
|||||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||||
stdweb = { path = "../stdweb", optional = true }
|
stdweb = { path = "../stdweb", optional = true }
|
||||||
instant = { version = "0.1", features = ["stdweb"] }
|
instant = { version = "0.1", features = ["stdweb"] }
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "window"
|
||||||
|
crate-type = ["cdylib"]
|
||||||
|
|||||||
@@ -5,22 +5,28 @@ extern crate stdweb;
|
|||||||
#[cfg(feature = "wasm-bindgen")]
|
#[cfg(feature = "wasm-bindgen")]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate wasm_bindgen;
|
extern crate wasm_bindgen;
|
||||||
|
#[cfg(feature = "wasm-bindgen")]
|
||||||
|
extern crate web_sys;
|
||||||
|
|
||||||
use winit::window::WindowBuilder;
|
use winit::window::WindowBuilder;
|
||||||
use winit::event::{Event, WindowEvent};
|
use winit::event::{Event, WindowEvent};
|
||||||
use winit::event_loop::{EventLoop, ControlFlow};
|
use winit::event_loop::{EventLoop, ControlFlow};
|
||||||
|
use wasm_bindgen::{prelude::*, JsValue};
|
||||||
|
use web_sys::console;
|
||||||
|
|
||||||
fn main() {
|
#[wasm_bindgen(start)]
|
||||||
|
pub fn main() {
|
||||||
|
console::log_1(&JsValue::from_str("main"));
|
||||||
let event_loop = EventLoop::new();
|
let event_loop = EventLoop::new();
|
||||||
|
|
||||||
let _window = WindowBuilder::new()
|
let _window = WindowBuilder::new()
|
||||||
.with_title("A fantastic window!")
|
.with_title("A fantastic window!")
|
||||||
.build(&event_loop)
|
.build(&event_loop)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
//console!(log, "Built window!");
|
console::log_1(&JsValue::from_str("Created window"));
|
||||||
|
|
||||||
event_loop.run(|event, _, control_flow| {
|
event_loop.run(|event, _, control_flow| {
|
||||||
//console!(log, format!("{:?}", event));
|
console::log_1(&JsValue::from_str(&format!("{:?}", event)));
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
Event::WindowEvent {
|
Event::WindowEvent {
|
||||||
@@ -30,4 +36,4 @@ fn main() {
|
|||||||
_ => *control_flow = ControlFlow::Wait,
|
_ => *control_flow = ControlFlow::Wait,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
20
test.html
Normal file
20
test.html
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<script type="module">
|
||||||
|
import { default as init } from './window.js';
|
||||||
|
|
||||||
|
async function run() {
|
||||||
|
console.log("Loading");
|
||||||
|
await init('./window_bg.wasm');
|
||||||
|
console.log("Loaded");
|
||||||
|
}
|
||||||
|
|
||||||
|
run();
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<canvas id="test_canvas"></canvas>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user