Skip to content

Commit

Permalink
Add wheel event support for htmlbackend
Browse files Browse the repository at this point in the history
  • Loading branch information
alt-tosc committed Dec 5, 2020
1 parent 03fdbaa commit 95a37bf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/fidget/dom2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,13 @@ type
screenX*, screenY*: int
x*, y*: int

WheelEvent* = ref WheelEventObj ## see `docs<https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent>`
WheelEventObj {.importc.} = object of MouseEvent
deltaX*: float64
deltaY*: float64
deltaZ*: float64
deltaMode*: uint32

DataTransferItemKind* {.pure.} = enum
File = "file",
String = "string"
Expand Down
6 changes: 6 additions & 0 deletions src/fidget/htmlbackend.nim
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,12 @@ proc startFidget*(draw: proc(), load: proc() = nil, w = 0, h = 0) =
## Scroll does not need to do anything special in HTML mode
refresh()

dom.window.addEventListener "wheel", proc(event: Event) =
## When wheel is used
let event = cast[WheelEvent](event)
mouse.wheelDelta += vec2(event.deltaX, event.deltaY)
refresh()

dom.window.addEventListener "mousedown", proc(event: Event) =
## When mouse button is pressed
let event = cast[MouseEvent](event)
Expand Down

0 comments on commit 95a37bf

Please sign in to comment.