Scrollbar cursors still aren't aligning to the grid correctly.
Example-code by Antti Riikonen:
from math import *
# Input text has this many lines (starts at 0 because that's where you'll probably be indexing from)
textHeight=200
# Scrollbar has this many lines
scrollbarHeight=34
def scrollbarPos(textHeight, scrollbarHeight, currentHeight):
# One scrollbar line corresponds to at least this many lines of text
minSegmentHeight = floor(textHeight / scrollbarHeight)
# How many extra lines we have that don't fit neatly into segments of minSegmentHeight size
remainder = textHeight-scrollbarHeight*minSegmentHeight
# Extra line is added to a scrollbar segment after each remainderSplit number of lines
remainderSplit = textHeight / remainder
return floor((currentHeight - floor(currentHeight / remainderSplit)) / minSegmentHeight)
print("Text height: ", textHeight, ", scrollbar height: ",scrollbarHeight,", minSegmentHeight: ",floor(textHeight / scrollbarHeight),", remainder: ", textHeight-scrollbarHeight*floor(textHeight / scrollbarHeight))
for i in range(textHeight):
print ("Line ",i,"/",textHeight,", scrollbar at ",scrollbarPos(textHeight,scrollbarHeight, i))
Scrollbar cursors still aren't aligning to the grid correctly.
Example-code by Antti Riikonen: