Browse Source

sys/wasm/js: add `set_element_style`

Laytan Laats 9 months ago
parent
commit
bd38b4839c
2 changed files with 12 additions and 0 deletions
  1. 2 0
      core/sys/wasm/js/dom.odin
  2. 10 0
      core/sys/wasm/js/odin.js

+ 2 - 0
core/sys/wasm/js/dom.odin

@@ -20,6 +20,8 @@ foreign dom_lib {
 	device_pixel_ratio :: proc() -> f64 ---
 	device_pixel_ratio :: proc() -> f64 ---
 
 
 	window_set_scroll :: proc(x, y: f64) ---
 	window_set_scroll :: proc(x, y: f64) ---
+
+	set_element_style :: proc(id: string, key: string, value: string) ---
 }
 }
 
 
 get_element_value_string :: proc "contextless" (id: string, buf: []byte) -> string {
 get_element_value_string :: proc "contextless" (id: string, buf: []byte) -> string {

+ 10 - 0
core/sys/wasm/js/odin.js

@@ -1802,6 +1802,16 @@ function odinSetupDefaultImports(wasmMemoryInterface, consoleElement, memory, ev
 				}
 				}
 			},
 			},
 
 
+			set_element_style: (id_ptr, id_len, key_ptr, key_len, value_ptr, value_len) => {
+				let id = wasmMemoryInterface.loadString(id_ptr, id_len);
+				let key = wasmMemoryInterface.loadString(key_ptr, key_len);
+				let value = wasmMemoryInterface.loadString(value_ptr, value_len);
+				let element = getElement(id);
+				if (element) {
+					element.style[key] = value;
+				}
+			},
+
 			get_element_key_f64: (id_ptr, id_len, key_ptr, key_len) => {
 			get_element_key_f64: (id_ptr, id_len, key_ptr, key_len) => {
 				let id = wasmMemoryInterface.loadString(id_ptr, id_len);
 				let id = wasmMemoryInterface.loadString(id_ptr, id_len);
 				let key = wasmMemoryInterface.loadString(key_ptr, key_len);
 				let key = wasmMemoryInterface.loadString(key_ptr, key_len);