rpgsheet

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 2bf8d856d1a4e35be7501b68a0c71521f30b64ba
parent 17a9272df0e1daa2f9837db00197f7d11e2d5f39
Author: Skylar Hill <stellarskylark@posteo.net>
Date:   Sun,  5 Jun 2022 02:04:01 -0500

Add scrolling through items within a window

Diffstat:
Msrc/tui.nim | 31++++++++++++++++++++++++-------
1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/src/tui.nim b/src/tui.nim @@ -136,6 +136,7 @@ proc runTui*(sheet: YamlDocument, file: string): void = var selWinIndex = 0 var selectedByWindow = initTable[string, int]() var itemsByWindow = initTable[string, seq[string]]() + var scrollByWindow = initTable[string, int]() var statusText = "" var commandText = "" var descScroll = 0 @@ -147,6 +148,7 @@ proc runTui*(sheet: YamlDocument, file: string): void = for win in windows.elems: itemsByWindow[win.content] = newSeqOfCap[string](100) selectedByWindow[win.content] = 0 + scrollByWindow[win.content] = 0 for name, content in sheet.root["expressions"].fields.pairs: let win = content.getContent("window") @@ -328,17 +330,32 @@ proc runTui*(sheet: YamlDocument, file: string): void = tb.write(x1 + 2, y1+1, fancyDisplay(window.content, textWidth)) # Write expressions - for window in tabWindows: - for item in itemsByWindow[window.content]: - let itemWin = sheet.getExpression(item).getContent("window") - let (x1, y1, x2, _) = windowPositions[itemWin] + for windowNode in tabWindows: + let window = windowNode.content + let items = itemsByWindow[window] + var scroll = scrollByWindow[window] + let sel = selectedByWindow[window] + let (x1, y1, x2, y2) = windowPositions[window] + if sel < scroll: + scroll = sel + scrollByWindow[window] = sel + # height of the writable area plus scroll = maximum visible index + if sel > y2-y1-4+scroll: + # scroll = sel-(y2-y1-4), simplified + scroll = sel-y2+y1+4 + scrollByWindow[window] = scroll + for item in items: + let itemIndex = items.find(item) + if itemIndex < scroll: + continue + if itemIndex > y2-y1-4+scroll: + continue let textWidth = x2 - x1 - 4 - let sel = selectedByWindow[itemWin] - if item == itemsByWindow[itemWin][sel]: + if item == items[sel]: tb.setForegroundColor(fgBlue) tb.write( x1 + 2, - y1 + 3 + itemsByWindow[itemWin].find(item), + y1 + 3 + itemIndex - scroll, fancyDisplay(item, textWidth) ) tb.setForegroundColor(fgNone)