Posted 15 July 2013 - 11:51 AM
I'm writing a program which is to include DireWolf20's Button API. However, I don't like it's lack of flexibility. I want my program to be usable with monitors of varying sizes. So I'm trying to figure up the logic to determine the xMin, xMax, yMin, yMax of all of the buttons. The easiest way to tackle this seems to start off by finding the largest string length so all buttons can be of equal size.
Even without knowledge of the button API, this should be an easy concept for someone to grasp, and someone more experience to point me in the right direction. We have a set monitor size, set button size, and set padding between buttons and the monitor edge. I don't know how to go about determining where to put the buttons based on how many buttons there are and how much monitor room there is. Here is some code that I will eventually scrap but attempted to solve this problem nonetheless:
To clarify, I want to be able to evenly space buttons according to how many buttons there are. I could figure out multiple pages on my own if we can figure out the spacing.
Here is the link to my full code, which is embedded in it's usage: http://pastebin.com/Q5nSMXEr
Even without knowledge of the button API, this should be an easy concept for someone to grasp, and someone more experience to point me in the right direction. We have a set monitor size, set button size, and set padding between buttons and the monitor edge. I don't know how to go about determining where to put the buttons based on how many buttons there are and how much monitor room there is. Here is some code that I will eventually scrap but attempted to solve this problem nonetheless:
for k,v in pairs(spawners) do
local xmin, ymin, xmax, ymax = 0
for i=1, possibleButtonColumns do
if buttonCurrent <= possibleButtonColumns then
rowCurrent = 1
else
if buttonCurrent <= pos
if buttonCurrent <= possibleButtonColumns then
rowCurrent = 1
else
local rowCurrent = math.floor(buttonCurrent/possibleButtonColumns)
local columnCurrent = math.floor(buttonCurrent/possibleButtonRows)
if buttonCurrent == 1 then
xmin = 2 xmax = xmin+buttonSize-1
ymin = 3 ymax = ymin+2
else
xmin = columnCurrent*buttonSize+2 xmax = xmin + buttonSize-1
ymin = (rowCurrent*3)+2 ymax = ymin + 2
end
button.setTable(v.name, v.toggle, xmin, xmax, ymin, ymax)
buttonCurrent = buttonCurrent + 1
end
To clarify, I want to be able to evenly space buttons according to how many buttons there are. I could figure out multiple pages on my own if we can figure out the spacing.
Here is the link to my full code, which is embedded in it's usage: http://pastebin.com/Q5nSMXEr
Edited on 15 July 2013 - 09:54 AM