Skip to content

Commit

Permalink
fixed some bugs with input
Browse files Browse the repository at this point in the history
  • Loading branch information
Nimaoth committed Sep 26, 2023
1 parent 004a893 commit 6769007
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/platform/browser_platform.nim
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ method init*(self: BrowserPlatform) =
inc self.doubleClickCounter
case self.doubleClickCounter
of 1:
self.onMousePress.invoke (MouseButton.DoubleClick, modifiers, vec2(x.float, y.float))
events.add MouseButton.DoubleClick
of 2:
self.onMousePress.invoke (MouseButton.TripleClick, modifiers, vec2(x.float, y.float))
events.add MouseButton.TripleClick
else:
self.doubleClickCounter = 0
else:
Expand Down
25 changes: 17 additions & 8 deletions src/platform/terminal_platform.nim
Original file line number Diff line number Diff line change
Expand Up @@ -215,25 +215,29 @@ method processEvents*(self: TerminalPlatform): int =

if mouseInfo.scroll:
let scroll = if mouseInfo.scrollDir == ScrollDirection.sdDown: -1.0 else: 1.0
self.onScroll.invoke (pos, vec2(0, scroll), {})

if not self.builder.handleMouseScroll(pos, vec2(0, scroll), {}):
self.onScroll.invoke (pos, vec2(0, scroll), {})
elif mouseInfo.move:
# log(lvlInfo, fmt"move to {pos}")
self.onMouseMove.invoke (pos, vec2(0, 0), {}, self.mouseButtons)
if not self.builder.handleMouseMoved(pos, self.mouseButtons):
self.onMouseMove.invoke (pos, vec2(0, 0), {}, self.mouseButtons)
else:
# log(lvlInfo, fmt"{mouseInfo.action} {button} at {pos}")
case mouseInfo.action
of mbaPressed:
self.mouseButtons.incl button
self.onMousePress.invoke (button, modifiers, pos)

var events = @[button]

if button == input.MouseButton.Left:
if self.doubleClickTimer.elapsed.float < self.doubleClickTime:
inc self.doubleClickCounter
case self.doubleClickCounter
of 1:
self.onMousePress.invoke (input.MouseButton.DoubleClick, modifiers, pos)
events.add input.MouseButton.DoubleClick
of 2:
self.onMousePress.invoke (input.MouseButton.TripleClick, modifiers, pos)
events.add input.MouseButton.TripleClick
else:
self.doubleClickCounter = 0
else:
Expand All @@ -243,17 +247,22 @@ method processEvents*(self: TerminalPlatform): int =
else:
self.doubleClickCounter = 0

for event in events:
if not self.builder.handleMousePressed(event, modifiers, pos):
self.onMousePress.invoke (event, modifiers, pos)

of mbaReleased:
self.mouseButtons = {}
self.onMouseRelease.invoke (button, modifiers, pos)
if not self.builder.handleMouseReleased(button, modifiers, pos):
self.onMouseRelease.invoke (button, modifiers, pos)
else:
discard

else:
var modifiers: Modifiers = {}
let button = key.toInput(modifiers)
self.onKeyPress.invoke (button, modifiers)
discard
if not self.builder.handleKeyPressed(button, modifiers):
self.onKeyPress.invoke (button, modifiers)

return eventCounter

Expand Down
2 changes: 1 addition & 1 deletion src/platform/widget_builder_text_document.nim
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ proc createLines(self: TextDocumentEditor, builder: UINodeBuilder, app: App, bac

builder.panel(flags):
onScroll:
let scrollAmount = delta.y * 40 # self.configProvider.getValue("text.scroll-speed", 40.0) # todo
let scrollAmount = delta.y * app.asConfigProvider.getValue("text.scroll-speed", 40.0)
self.scrollOffset += scrollAmount
self.markDirty()

Expand Down

0 comments on commit 6769007

Please sign in to comment.