rm-code / On-The-Roadside

A turn-based ASCII strategy game.
https://rmcode.itch.io/on-the-roadside
MIT License
24 stars 1 forks source link

Grid align scrollbar movement #183

Open rm-code opened 6 years ago

rm-code commented 6 years ago

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))
rm-code commented 6 years ago

This should actually be listed as a bug.