dom.odin 2.6 KB

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