Posted 25 March 2015 - 05:06 PM
I am taking a break from co routines to finish my file browser, although I have encountered a small problem, I am trying to add a scroll bar in that allows you to scroll using the mouse wheel and the scroll bar will change, now currently I have this working… but it doesn't exactly work the correct way…
There is no error but the actual size of scroll button/bar is calculated using:
EDIT: The size isn't dynamic either :/
This is the code for the function to make the scroll bar:
Any help would be appreciated
Here is the api code:
There is no error but the actual size of scroll button/bar is calculated using:
size = math.ceil(fileslen / 15)
which is the space it has to wok with… Although the actual position of the bar is the problem, so as said before it has 15 spaces to use so I made a code:EDIT: The size isn't dynamic either :/
pos = 3 + scroll
As this, in the meantime, works but it goes off the screen a lot, so I am not completely sure how to fix this…This is the code for the function to make the scroll bar:
function xplore.scrollbar(fileslen, scroll)
draw.box(1, 1, 2, 18, false, "grey", "grey")
draw.texta("^", 1, 2, false, "white", "grey")
draw.texta("v", 1, 19, false, "white", "grey")
fileslen = fileslen / 10
size = math.ceil(fileslen / 15)
pos = 2 + math.ceil(scroll + #fileslen / 16)
draw.texta(fileslen, 40, 1, false, "lime", "grey")
draw.box(1, 1, pos, size, " ", "lightGrey", "lightGrey")
end
Any help would be appreciated
Here is the api code:
function draw.box(StartX, lengthX, StartY, lengthY, Text, Color, BkgColor)
local x, y = term.getSize()
if Color then
col.set(Color, BkgColor)
end
if not Text then
Text = "*"
end
lengthX = lengthX - 1
lengthY = lengthY - 1
EndX = StartX + lengthX
EndY = StartY + lengthY
term.setCursorPos(StartX, StartY)
term.write(string.rep(Text, lengthX))
term.setCursorPos(StartX, EndY)
term.write(string.rep(Text, lengthX))
for i = StartY, EndY do
term.setCursorPos(StartX, i)
term.write(Text)
term.setCursorPos(EndX, i)
term.write(Text)
end
col.reset(Color, BkgColor)
return true
end
function draw.texta(Text, xx, yy, NextLine, Color, BkgColor)
term.setCursorPos(xx,yy)
if Color then
col.set(Color, BkgColor)
end
term.write(Text)
if NextLine then
term.setCursorPos(1, NextLine)
end
if Color then
col.reset(Color, BkgColor)
end
return true
end
Edited on 25 March 2015 - 04:13 PM