In conjuction with jasperdekiller's database, I have made a client for it. One of the downsides is that the log might be 50 lines long and the height limit is 19. I am trying to make it so that whenever i scroll down, it will show the rest of the log and vice versa.
I will be happy if I can get a simple but clever answer.
How to use the mouse_scroll event
Started by _removed, Feb 14 2015 10:44 PM
8 replies to this topic
#1
Posted 14 February 2015 - 10:44 PM
#2
Posted 14 February 2015 - 10:47 PM
Best bet is to bung each line into a separate table index, then just print lines x through to x+18, where x is whatever position you've scrolled to.
I've got some code for a menu that should give you some idea as to how to go about it.
I've got some code for a menu that should give you some idea as to how to go about it.
#3
Posted 14 February 2015 - 10:55 PM
Bomb Bloke, on 14 February 2015 - 10:47 PM, said:
Best bet is to bung each line into a separate table index, then just print lines x through to x+18, where x is whatever position you've scrolled to.
I've got some code for a menu that should give you some idea as to how to go about it.
I've got some code for a menu that should give you some idea as to how to go about it.
All I want is a simple system that if I scroll down, it goes down and if i scroll up, it goes up.
#4
Posted 14 February 2015 - 11:03 PM
Well... what have you got?
#5
Posted 14 February 2015 - 11:07 PM
Heres the Main: Rxx5WNPW
Heres the API: SfXFSh0a
Im gonna post the part that i want to be edited here:
Heres the API: SfXFSh0a
Im gonna post the part that i want to be edited here:
term.setBackgroundColour(colours.black)
term.clear()
term.setTextColour(colours.white)
Log = db.getAllLogs(tonumber(serverID), serverName, serverPass)
local yPos = 1
term.setCursorPos(1, yPos)
for k, v in pairs(Log) do
if v[2] == "Info" then
term.setTextColour(colours.blue)
term.write("[ "..v[2].." ] ")
term.setTextColour(colours.lightGrey)
term.write(v[1])
yPos = yPos + 1
term.setCursorPos(1, yPos)
elseif v[2] == "Success" then
term.setTextColour(colours.green)
term.write("[ "..v[2].. " ] ")
term.setTextColour(colours.lightGrey)
term.write(v[1])
yPos = yPos + 1
term.setCursorPos(1, yPos)
elseif v[2] == "Warning" or v[2] == "Error" or v[2] == "Alert" then
term.setTextColour(colours.red)
term.write("[ "..v[2].." ] ")
term.setTextColour(colours.lightGrey)
term.write(v[1])
yPos = yPos + 1
term.setCursorPos(1, yPos)
end
end
event, key = os.pullEvent("key")
pageLayout()
Edited by smigger22, 14 February 2015 - 11:07 PM.
#6
Posted 15 February 2015 - 01:45 AM
Don't have time to go through all your code, but this is basically what I would do
Change 'offset' to move the list up or down.
Like I said, that's the basic idea, you will have to play with it to get it to work.
items = {
"This is the first line",
"This is the second line",
"This is the third line"
} --#You probably have more than three lines
local w,h = term.getSize()
local offset = 0
term.setCursorPos(1,1)
if #items > h then
for i = 1, h do
term.write(items[#items-(h+offset)+i])
end
else
for i = 1, h do
term.write(items[i])
end
end
Change 'offset' to move the list up or down.
Like I said, that's the basic idea, you will have to play with it to get it to work.
#7
Posted 15 February 2015 - 02:20 AM
This isn't as elegant as the other solutions, and it's not based on your code, but it's what I use in my programs. It views/scrolls a page at a time instead of a line at a time. You'll need to make changes to suit your needs. Note that this only works for ordered tables, not sparse tables...
local testData = { "Line 1", "Line 2", "Line 3", "Line 4", "Line 5", "Line 6", "Line 7", "Line 8", "Line 9", "Line 10", "Line 11", "Line 12" } --#substitute this with your actual data
local linesPerPage = 10 --# the number of lines per page (change this to suit your needs)
local pageNum = 1 --# which page we're currently on - we're starting at the first page
local numPages = math.ceil(#testData / linesPerPage) --# total number of pages based on number of entries
local function listPage()
term.clear() --# this is just for this example, you may wish to clear just the area the data fills
local xPos = 1 --# cursor X position (change this to be your actual 'top' x position)
local yPos = 1 --# cursor Y position (change this to be your actual 'top' y position)
local startY = 1 --# this should be equal to the initial yPos value
local currentEntry = ((pageNum - 1) * (linesPerPage - 1)) + pageNum
for i = currentEntry, #testData do --# start the listing loop from the current entry
term.setCursorPos(xPos, yPos) --# set the cursor position
term.write(testData[i]) --# write the data to screen
yPos = yPos + 1 --# increment the Y position so the next entry is written on the next display line
if yPos = startY + linesPerPage then break end --# we've listed the set number of entries per page so stop the loop
end
end
local function getInput()
while true do
local _, scroll = os.pullEvent("mouse_scroll")
if scroll == 1 then
pageNum = math.min(pageNum + 1, numPages) --# if the user scrolls down, increment the page number
elseif scroll == -1 then
pageNum = math.max(1, pageNum - 1) --# if the user scrolls up, decrement the page number
end
listPage()
end
end
listPage()
getInput()
Edited by Dog, 15 February 2015 - 02:33 AM.
#8
Posted 15 February 2015 - 05:14 PM
I understand nothing of what all of you have said.
#9
Posted 15 February 2015 - 06:12 PM
It doesn't matter because I found a function that scrolls through already.
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users











