1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-26 22:53:14 -04:00

Update wasm/web example

This commit is contained in:
Emil Ernerfeldt
2020-04-23 09:50:03 +02:00
parent 723c3ca908
commit 25b06a6ff0
8 changed files with 47 additions and 19 deletions

View File

@@ -419,6 +419,9 @@ async function init(input) {
imports.wbg.__wbg_uniform2f_c1a2fa4599b15748 = function(arg0, arg1, arg2, arg3) {
getObject(arg0).uniform2f(getObject(arg1), arg2, arg3);
};
imports.wbg.__wbg_uniform4f_6e9aa69017843be0 = function(arg0, arg1, arg2, arg3, arg4, arg5) {
getObject(arg0).uniform4f(getObject(arg1), arg2, arg3, arg4, arg5);
};
imports.wbg.__wbg_useProgram_324a22a196d1f113 = function(arg0, arg1) {
getObject(arg0).useProgram(getObject(arg1));
};

Binary file not shown.

View File

@@ -62,6 +62,8 @@
var g_mouse_pos = null;
var g_mouse_down = false;
var g_is_touch = false;
var g_scroll_delta_x = 0;
var g_scroll_delta_y = 0;
function pixels_per_point() {
// return 1.0;
@@ -76,14 +78,17 @@
}
function get_input(canvas) {
return {
var input = {
mouse_down: g_mouse_down,
mouse_pos: g_mouse_pos,
// TODO: scroll_delta
scroll_delta: { x: -g_scroll_delta_x, y: -g_scroll_delta_y }, // TODO: standardize scroll direction
screen_size: { x: window.innerWidth, y: window.innerHeight },
pixels_per_point: pixels_per_point(),
time: window.performance.now() / 1000.0,
};
g_scroll_delta_x = 0;
g_scroll_delta_y = 0;
return input;
}
function mouse_pos_from_event(canvas, event) {
@@ -94,6 +99,9 @@
};
}
// If true, paint at full framerate always.
// If false, only paint on input.
// TODO: if this is turned off we must turn off animations too (which hasn't been implemented yet).
const ANIMATION_FRAME = true;
function paint() {
@@ -173,6 +181,14 @@
event.preventDefault();
});
canvas.addEventListener("wheel", function (event) {
g_scroll_delta_x += event.deltaX;
g_scroll_delta_y += event.deltaY;
invalidate();
event.stopPropagation();
event.preventDefault();
});
if (!ANIMATION_FRAME) {
window.addEventListener("load", invalidate);
window.addEventListener("pagehide", invalidate);