Skip to content

Commit

Permalink
Added scrolling in debugger variables view
Browse files Browse the repository at this point in the history
  • Loading branch information
Nimaoth committed Jun 10, 2024
1 parent 8668b29 commit 81d0a1b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
19 changes: 19 additions & 0 deletions src/text/language/debugger.nim
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type
currentFrameIndex: int
variablesCursor: VariableCursor
variablesScrollOffset*: float
maxVariablesScrollOffset*: float
eventHandler: EventHandler
threadsEventHandler: EventHandler
stackTraceEventHandler: EventHandler
Expand Down Expand Up @@ -239,6 +240,8 @@ proc prevVariable*(self: Debugger) {.expose("debugger").} =
let scope {.cursor.} = self.scopes.scopes[self.variablesCursor.scope]
if self.variablesCursor.scope > 0:
self.variablesCursor = self.lastChild(VariableCursor(scope: self.variablesCursor.scope - 1))
if self.variablesScrollOffset > 0:
self.variablesScrollOffset -= self.app.platform.totalLineHeight
return

else:
Expand All @@ -247,6 +250,8 @@ proc prevVariable*(self: Debugger) {.expose("debugger").} =
scope: self.variablesCursor.scope - 1,
path: @[(int.high, self.scopes.scopes[self.variablesCursor.scope - 1].variablesReference)],
))
if self.variablesScrollOffset > 0:
self.variablesScrollOffset -= self.app.platform.totalLineHeight
return

let (index, currentRef) = self.variablesCursor.path[self.variablesCursor.path.high]
Expand All @@ -258,9 +263,13 @@ proc prevVariable*(self: Debugger) {.expose("debugger").} =
if index > 0:
dec self.variablesCursor.path[self.variablesCursor.path.high].index
self.variablesCursor = self.lastChild(self.variablesCursor)
if self.variablesScrollOffset > 0:
self.variablesScrollOffset -= self.app.platform.totalLineHeight
return

discard self.variablesCursor.path.pop
if self.variablesScrollOffset > 0:
self.variablesScrollOffset -= self.app.platform.totalLineHeight

proc nextVariable*(self: Debugger) {.expose("debugger").} =
if self.scopes.scopes.len == 0 or self.variables.len == 0:
Expand All @@ -272,10 +281,14 @@ proc nextVariable*(self: Debugger) {.expose("debugger").} =
let scope = self.scopes.scopes[self.variablesCursor.scope]
if self.variables.contains(scope.variablesReference) and self.variables[scope.variablesReference].variables.len > 0:
self.variablesCursor.path.add (0, scope.variablesReference)
if self.variablesScrollOffset < self.maxVariablesScrollOffset:
self.variablesScrollOffset += self.app.platform.totalLineHeight
return

if self.variablesCursor.scope + 1 < self.scopes.scopes.len:
self.variablesCursor = VariableCursor(scope: self.variablesCursor.scope + 1)
if self.variablesScrollOffset < self.maxVariablesScrollOffset:
self.variablesScrollOffset += self.app.platform.totalLineHeight
return

else:
Expand All @@ -292,17 +305,23 @@ proc nextVariable*(self: Debugger) {.expose("debugger").} =
if descending and childrenRef != 0.VariablesReference and self.variables.contains(childrenRef) and
self.variables[childrenRef].variables.len > 0:
self.variablesCursor.path.add (0, childrenRef)
if self.variablesScrollOffset < self.maxVariablesScrollOffset:
self.variablesScrollOffset += self.app.platform.totalLineHeight
return

if index < variables.variables.high:
inc self.variablesCursor.path[self.variablesCursor.path.high].index
if self.variablesScrollOffset < self.maxVariablesScrollOffset:
self.variablesScrollOffset += self.app.platform.totalLineHeight
return

descending = false
discard self.variablesCursor.path.pop

if self.variablesCursor.scope + 1 < self.scopes.scopes.len:
self.variablesCursor = VariableCursor(scope: self.variablesCursor.scope + 1)
if self.variablesScrollOffset < self.maxVariablesScrollOffset:
self.variablesScrollOffset += self.app.platform.totalLineHeight
return

self.variablesCursor = self.lastChild(VariableCursor(
Expand Down
29 changes: 21 additions & 8 deletions src/ui/widget_builder_debugger.nim
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ proc createVariables*(self: DebuggerView, builder: UINodeBuilder, app: App, debu
if isSelected:
builder.panel(&{SizeToContentY, FillX, FillBackground}, backgroundColor = color(0.6, 0.5, 0.2, 0.3)):
builder.panel(&{SizeToContentY, SizeToContentX, DrawText}, text = text, textColor = textColor)
output.selectedNode = currentNode
else:
builder.panel(&{SizeToContentY, SizeToContentX, DrawText}, text = text, textColor = textColor)
# builder.panel(&{SizeToContentY, SizeToContentX, DrawText}, text = variable.name, textColor = textColor)
Expand All @@ -150,6 +151,7 @@ proc createScope*(self: DebuggerView, builder: UINodeBuilder, app: App, debugger
if isSelected:
builder.panel(&{SizeToContentY, FillX, FillBackground}, backgroundColor = color(0.6, 0.5, 0.2, 0.3)):
builder.panel(&{SizeToContentY, FillX, DrawText}, text = scope.name, textColor = textColor)
output.selectedNode = currentNode
else:
builder.panel(&{SizeToContentY, FillX, DrawText}, text = scope.name, textColor = textColor)

Expand Down Expand Up @@ -190,14 +192,25 @@ proc createLocals*(self: DebuggerView, builder: UINodeBuilder, app: App, debugge
else:
sizeFlags.incl FillY

builder.panel(sizeFlags + LayoutVertical):
builder.panel(&{FillX, SizeToContentY, FillBackground, LayoutHorizontal},
backgroundColor = headerColor):
builder.panel(&{SizeToContentX, SizeToContentY, DrawText}, textColor = textColor, text = "Variables")

builder.panel(sizeFlags + FillBackground, backgroundColor = chosenBackgroundColor):
builder.createLines(0, 0, debugger.scopes.scopes.high, sizeToContentX, sizeToContentY,
chosenBackgroundColor, handleScroll, handleLine)
builder.panel(sizeFlags):
builder.panel(sizeFlags + LayoutVertical):
builder.panel(&{FillX, SizeToContentY, FillBackground, LayoutHorizontal},
backgroundColor = headerColor):
builder.panel(&{SizeToContentX, SizeToContentY, DrawText}, textColor = textColor, text = "Variables")

builder.panel(sizeFlags + FillBackground + MaskContent, backgroundColor = chosenBackgroundColor):
var scrolledNode: UINode
builder.panel(sizeFlags):
scrolledNode = currentNode
builder.createLines(0, 0, debugger.scopes.scopes.high, sizeToContentX, sizeToContentY,
chosenBackgroundColor, handleScroll, handleLine)

debugger.maxVariablesScrollOffset = currentNode.bounds.h - builder.lineHeight

if createVariablesOutput.selectedNode.isNotNil:
let bounds = createVariablesOutput.selectedNode.transformBounds(currentNode)
let scrollOffset = debugger.variablesScrollOffset - bounds.y
scrolledNode.boundsRaw.y += scrollOffset

res

Expand Down

0 comments on commit 81d0a1b

Please sign in to comment.