dom.odin 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #+build js wasm32, js wasm64p32
  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. get_element_key_f64 :: proc(id: string, key: string) -> f64 ---
  9. set_element_key_f64 :: proc(id: string, key: string, value: f64) ---
  10. set_element_value_string :: proc(id: string, value: string) ---
  11. get_element_value_string_length :: proc(id: string) -> int ---
  12. set_element_key_string :: proc(id: string, key: string, value: string) ---
  13. get_element_key_string_length :: proc(id: string, key: string, ) -> int ---
  14. device_pixel_ratio :: proc() -> f64 ---
  15. window_set_scroll :: proc(x, y: f64) ---
  16. set_element_style :: proc(id: string, key: string, value: string) ---
  17. }
  18. get_element_value_string :: proc "contextless" (id: string, buf: []byte) -> string {
  19. @(default_calling_convention="contextless")
  20. foreign dom_lib {
  21. @(link_name="get_element_value_string")
  22. _get_element_value_string :: proc(id: string, buf: []byte) -> int ---
  23. }
  24. n := _get_element_value_string(id, buf)
  25. return string(buf[:n])
  26. }
  27. get_element_key_string :: proc "contextless" (id: string, key: string, buf: []byte) -> string {
  28. @(default_calling_convention="contextless")
  29. foreign dom_lib {
  30. @(link_name="get_element_key_string")
  31. _get_element_key_string :: proc(id: string, key: string, buf: []byte) -> int ---
  32. }
  33. n := _get_element_key_string(id, key, buf)
  34. return string(buf[:n])
  35. }
  36. get_element_min_max :: proc "contextless" (id: string) -> (min, max: f64) {
  37. @(default_calling_convention="contextless")
  38. foreign dom_lib {
  39. @(link_name="get_element_min_max")
  40. _get_element_min_max :: proc(min_max: ^[2]f64, id: string) ---
  41. }
  42. min_max: [2]f64
  43. _get_element_min_max(&min_max, id)
  44. return min_max[0], min_max[1]
  45. }
  46. Rect :: struct {
  47. x, y, width, height: f64,
  48. }
  49. get_bounding_client_rect :: proc "contextless" (id: string) -> (rect: Rect) {
  50. @(default_calling_convention="contextless")
  51. foreign dom_lib {
  52. @(link_name="get_bounding_client_rect")
  53. _get_bounding_client_rect :: proc(rect: ^Rect, id: string) ---
  54. }
  55. _get_bounding_client_rect(&rect, id)
  56. return
  57. }
  58. window_get_rect :: proc "contextless" () -> (rect: Rect) {
  59. @(default_calling_convention="contextless")
  60. foreign dom_lib {
  61. @(link_name="window_get_rect")
  62. _window_get_rect :: proc(rect: ^Rect) ---
  63. }
  64. _window_get_rect(&rect)
  65. return
  66. }
  67. window_get_scroll :: proc "contextless" () -> (x, y: f64) {
  68. @(default_calling_convention="contextless")
  69. foreign dom_lib {
  70. @(link_name="window_get_scroll")
  71. _window_get_scroll :: proc(scroll: ^[2]f64) ---
  72. }
  73. scroll: [2]f64
  74. _window_get_scroll(&scroll)
  75. return scroll.x, scroll.y
  76. }