mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 07:08:48 +00:00
Improve events handling
This commit is contained in:
Vendored
-2
@@ -182,7 +182,6 @@ Event_Phase :: enum u8 {
|
|||||||
Bubbling_Phase = 3,
|
Bubbling_Phase = 3,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Event :: struct {
|
Event :: struct {
|
||||||
kind: Event_Kind,
|
kind: Event_Kind,
|
||||||
target_kind: Event_Target_Kind,
|
target_kind: Event_Target_Kind,
|
||||||
@@ -231,7 +230,6 @@ Event :: struct {
|
|||||||
offset: [2]i64,
|
offset: [2]i64,
|
||||||
page: [2]i64,
|
page: [2]i64,
|
||||||
movement: [2]i64,
|
movement: [2]i64,
|
||||||
using pos: [2]i64,
|
|
||||||
|
|
||||||
ctrl: bool,
|
ctrl: bool,
|
||||||
shift: bool,
|
shift: bool,
|
||||||
|
|||||||
Vendored
+22
-17
@@ -94,7 +94,7 @@ function odinSetupDefaultImports(wasmMemoryInterface, consoleElement) {
|
|||||||
const MAX_INFO_CONSOLE_LINES = 512;
|
const MAX_INFO_CONSOLE_LINES = 512;
|
||||||
let infoConsoleLines = new Array();
|
let infoConsoleLines = new Array();
|
||||||
const addConsoleLine = (line) => {
|
const addConsoleLine = (line) => {
|
||||||
if (line === undefined) {
|
if (!line) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (line.endsWith("\n")) {
|
if (line.endsWith("\n")) {
|
||||||
@@ -117,7 +117,7 @@ function odinSetupDefaultImports(wasmMemoryInterface, consoleElement) {
|
|||||||
data = data.concat(infoConsoleLines[i]);
|
data = data.concat(infoConsoleLines[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (consoleElement !== undefined) {
|
if (consoleElement) {
|
||||||
let info = consoleElement;
|
let info = consoleElement;
|
||||||
info.innerHTML = data;
|
info.innerHTML = data;
|
||||||
info.scrollTop = info.scrollHeight;
|
info.scrollTop = info.scrollHeight;
|
||||||
@@ -165,7 +165,7 @@ function odinSetupDefaultImports(wasmMemoryInterface, consoleElement) {
|
|||||||
let offset = ep;
|
let offset = ep;
|
||||||
let off = (amount, alignment) => {
|
let off = (amount, alignment) => {
|
||||||
if (alignment === undefined) {
|
if (alignment === undefined) {
|
||||||
alignment = amount;
|
alignment = Math.min(amount, W);
|
||||||
}
|
}
|
||||||
if (offset % alignment != 0) {
|
if (offset % alignment != 0) {
|
||||||
offset += alignment - (offset%alignment);
|
offset += alignment - (offset%alignment);
|
||||||
@@ -207,7 +207,7 @@ function odinSetupDefaultImports(wasmMemoryInterface, consoleElement) {
|
|||||||
wmi.storeU8(off(1), !!e.isComposing);
|
wmi.storeU8(off(1), !!e.isComposing);
|
||||||
wmi.storeU8(off(1), !!e.isTrusted);
|
wmi.storeU8(off(1), !!e.isTrusted);
|
||||||
|
|
||||||
off(0, 8);
|
let base = off(0, 8);
|
||||||
if (e instanceof MouseEvent) {
|
if (e instanceof MouseEvent) {
|
||||||
wmi.storeI64(off(8), e.screenX);
|
wmi.storeI64(off(8), e.screenX);
|
||||||
wmi.storeI64(off(8), e.screenY);
|
wmi.storeI64(off(8), e.screenY);
|
||||||
@@ -219,8 +219,6 @@ function odinSetupDefaultImports(wasmMemoryInterface, consoleElement) {
|
|||||||
wmi.storeI64(off(8), e.pageY);
|
wmi.storeI64(off(8), e.pageY);
|
||||||
wmi.storeI64(off(8), e.movementX);
|
wmi.storeI64(off(8), e.movementX);
|
||||||
wmi.storeI64(off(8), e.movementY);
|
wmi.storeI64(off(8), e.movementY);
|
||||||
wmi.storeI64(off(8), e.x);
|
|
||||||
wmi.storeI64(off(8), e.y);
|
|
||||||
|
|
||||||
wmi.storeU8(off(1), !!e.ctrlKey);
|
wmi.storeU8(off(1), !!e.ctrlKey);
|
||||||
wmi.storeU8(off(1), !!e.shiftKey);
|
wmi.storeU8(off(1), !!e.shiftKey);
|
||||||
@@ -339,30 +337,37 @@ function odinSetupDefaultImports(wasmMemoryInterface, consoleElement) {
|
|||||||
get_element_value_f64: (id_ptr, id_len) => {
|
get_element_value_f64: (id_ptr, id_len) => {
|
||||||
let id = wasmMemoryInterface.loadString(id_ptr, id_len);
|
let id = wasmMemoryInterface.loadString(id_ptr, id_len);
|
||||||
let element = document.getElementById(id);
|
let element = document.getElementById(id);
|
||||||
return element.value;
|
return element ? element.value : 0;
|
||||||
},
|
},
|
||||||
get_element_value_string: (id_ptr, id_len, buf_ptr, buf_len) => {
|
get_element_value_string: (id_ptr, id_len, buf_ptr, buf_len) => {
|
||||||
let id = wasmMemoryInterface.loadString(id_ptr, id_len);
|
let id = wasmMemoryInterface.loadString(id_ptr, id_len);
|
||||||
let element = document.getElementById(id);
|
let element = document.getElementById(id);
|
||||||
let str = element.value;
|
if (element) {
|
||||||
if (buf_len > 0 && buf_ptr) {
|
let str = element.value;
|
||||||
let n = Math.min(buf_len, str.length);
|
if (buf_len > 0 && buf_ptr) {
|
||||||
str = str.substring(0, n);
|
let n = Math.min(buf_len, str.length);
|
||||||
this.mem.loadBytes(buf_ptr, buf_len).set(new TextEncoder("utf-8").encode(str))
|
str = str.substring(0, n);
|
||||||
return n;
|
this.mem.loadBytes(buf_ptr, buf_len).set(new TextEncoder("utf-8").encode(str))
|
||||||
|
return n;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
},
|
},
|
||||||
get_element_min_max: (ptr_array2_f64, id_ptr, id_len) => {
|
get_element_min_max: (ptr_array2_f64, id_ptr, id_len) => {
|
||||||
let id = wasmMemoryInterface.loadString(id_ptr, id_len);
|
let id = wasmMemoryInterface.loadString(id_ptr, id_len);
|
||||||
let element = document.getElementById(id);
|
let element = document.getElementById(id);
|
||||||
let values = wasmMemoryInterface.loadF64Array(ptr_array2_f64, 2);
|
if (element) {
|
||||||
values[0] = element.min;
|
let values = wasmMemoryInterface.loadF64Array(ptr_array2_f64, 2);
|
||||||
values[1] = element.max;
|
values[0] = element.min;
|
||||||
|
values[1] = element.max;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
set_element_value: (id_ptr, id_len, value) => {
|
set_element_value: (id_ptr, id_len, value) => {
|
||||||
let id = wasmMemoryInterface.loadString(id_ptr, id_len);
|
let id = wasmMemoryInterface.loadString(id_ptr, id_len);
|
||||||
document.getElementById(id).value = value;
|
let element = document.getElementById(id);
|
||||||
|
if (element) {
|
||||||
|
element.value = value;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user