dom.odin 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //+build js wasm32, js wasm64
  2. package wasm_js_interface
  3. foreign import dom_lib "odin_dom"
  4. @(default_calling_convention="contextless")
  5. foreign dom_lib {
  6. get_element_value_f64 :: proc(id: string) -> f64 ---
  7. set_element_value_f64 :: proc(id: string, value: f64) ---
  8. set_element_value_string :: proc(id: string, value: string) ---
  9. get_element_value_string_length :: proc(id: string) -> int ---
  10. device_pixel_ratio :: proc() -> f64 ---
  11. window_set_scroll :: proc(x, y: f64) ---
  12. }
  13. get_element_value_string :: proc "contextless" (id: string, buf: []byte) -> string {
  14. @(default_calling_convention="contextless")
  15. foreign dom_lib {
  16. @(link_name="get_element_value_string")
  17. _get_element_value_string :: proc(id: string, buf: []byte) -> int ---
  18. }
  19. n := _get_element_value_string(id, buf)
  20. return string(buf[:n])
  21. }
  22. get_element_min_max :: proc "contextless" (id: string) -> (min, max: f64) {
  23. @(default_calling_convention="contextless")
  24. foreign dom_lib {
  25. @(link_name="get_element_min_max")
  26. _get_element_min_max :: proc(min_max: ^[2]f64, id: string) ---
  27. }
  28. min_max: [2]f64
  29. _get_element_min_max(&min_max, id)
  30. return min_max[0], min_max[1]
  31. }
  32. Rect :: struct {
  33. x, y, width, height: f64,
  34. }
  35. get_bounding_client_rect :: proc "contextless" (id: string) -> (rect: Rect) {
  36. @(default_calling_convention="contextless")
  37. foreign dom_lib {
  38. @(link_name="get_bounding_client_rect")
  39. _get_bounding_client_rect :: proc(rect: ^Rect, id: string) ---
  40. }
  41. _get_bounding_client_rect(&rect, id)
  42. return
  43. }
  44. window_get_rect :: proc "contextless" () -> (rect: Rect) {
  45. @(default_calling_convention="contextless")
  46. foreign dom_lib {
  47. @(link_name="window_get_rect")
  48. _window_get_rect :: proc(rect: ^Rect) ---
  49. }
  50. _window_get_rect(&rect)
  51. return
  52. }
  53. window_get_scroll :: proc "contextless" () -> (x, y: f64) {
  54. @(default_calling_convention="contextless")
  55. foreign dom_lib {
  56. @(link_name="window_get_scroll")
  57. _window_get_scroll :: proc(scroll: ^[2]f64) ---
  58. }
  59. scroll := [2]f64{x, y}
  60. _window_get_scroll(&scroll)
  61. return
  62. }