Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/windy/platforms/emscripten/emdefs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ EM_JS(void, setup_drag_drop_handlers_internal, (const char* target, void* userDa
}
}, false);
});

EM_JS(void, set_cursor, (const char* cursor), {
const cursorUtf8 = UTF8ToString(cursor);
Module.canvas.style.cursor = cursorUtf8;
});
""".}

proc get_window_width*(): cint {.importc.}
Expand All @@ -168,8 +173,8 @@ proc get_window_url_into*(output: cstring, maxLen: cint): cint {.importc.}
proc get_device_pixel_ratio*(): cdouble {.importc.}
proc open_temp_text_file*(title, text: cstring) {.importc.}
proc open_url*(url: cstring) {.importc.}

proc setup_drag_drop_handlers_internal*(target: cstring, userData: pointer) {.importc.}
proc set_cursor*(cursor: cstring) {.importc.}

type
EMSCRIPTEN_RESULT* = cint
Expand Down
33 changes: 32 additions & 1 deletion src/windy/platforms/emscripten/platform.nim
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,38 @@ proc cursor*(window: Window): Cursor =

proc `cursor=`*(window: Window, cursor: Cursor) =
window.state.cursor = cursor
# TODO: Apply CSS cursor style based on cursor type
case cursor.kind:
of ArrowCursor:
set_cursor("auto")
of PointerCursor:
set_cursor("pointer")
of IBeamCursor:
set_cursor("text")
of CrosshairCursor:
set_cursor("crosshair")
of ClosedHandCursor:
set_cursor("grabbing")
of OpenHandCursor:
set_cursor("grab")
of ResizeLeftCursor:
set_cursor("w-resize")
of ResizeRightCursor:
set_cursor("e-resize")
of ResizeLeftRightCursor:
set_cursor("col-resize")
of ResizeUpCursor:
set_cursor("n-resize")
of ResizeDownCursor:
set_cursor("s-resize")
of ResizeUpDownCursor:
set_cursor("row-resize")
of OperationNotAllowedCursor:
set_cursor("not-allowed")
of WaitCursor:
set_cursor("wait")
of CustomCursor:
# TODO base64 encode Image?
set_cursor("auto")

# Style functions
proc style*(window: Window): WindowStyle =
Expand Down