Cleaned up and fixed some tab issues

This commit is contained in:
zorfmorf 2015-02-12 13:25:32 +01:00
parent 99fade6625
commit 67f1d33ac9
2 changed files with 44 additions and 47 deletions

View file

@ -47,14 +47,15 @@ local Grow = {
right = { 1, 0} right = { 1, 0}
} }
-- {grow = grow, spacing = spacing, size = size, pos = pos, draw = draw, border = bool, bkg = bool, padding = padding} -- {grow = grow, spacing = spacing, size = size, pos = pos, draw = draw,
-- border = bool, bkg = bool, padding = padding}
local function push(info) local function push(info)
if not core then core = require(BASE .. 'core') end if not core then core = require(BASE .. 'core') end
local grow = info.grow or "none" local grow = info.grow or "none"
local spacing = info.spacing or default.spacing local spacing = info.spacing or default.spacing
local pad = info.pad or default.pad local pad = info.pad or default.pad
local size = { local size = {
info.size and info.size[1] or current.size[1], info.size and info.size[1] or current.size[1],
@ -63,12 +64,12 @@ local function push(info)
local pos = {current.pos[1], current.pos[2]} local pos = {current.pos[1], current.pos[2]}
-- apply parent container padding (if any) -- apply parent container padding (if any)
local parent = stack[stack.n] local parent = stack[stack.n]
if parent then if parent then
pos[1] = pos[1] + parent.pad pos[1] = pos[1] + parent.pad
pos[2] = pos[2] + parent.pad pos[2] = pos[2] + parent.pad
end end
if info.pos then if info.pos then
pos[1] = pos[1] + (info.pos[1] or 0) pos[1] = pos[1] + (info.pos[1] or 0)
@ -79,18 +80,18 @@ local function push(info)
assert(pos, "Position neither specified nor derivable from parent group.") assert(pos, "Position neither specified nor derivable from parent group.")
grow = assert(Grow[grow], "Invalid grow: " .. tostring(grow)) grow = assert(Grow[grow], "Invalid grow: " .. tostring(grow))
local id = info.id local id = info.id
if not id then id = core.generateID() end if not id then id = core.generateID() end
current = { current = {
pos = pos, pos = pos,
grow = grow, grow = grow,
size = size, size = size,
spacing = spacing, spacing = spacing,
pad = pad, pad = pad,
border = info.border, border = info.border,
bkg = info.bkg, bkg = info.bkg,
draw = info.draw, draw = info.draw,
id = id, id = id,
upper_left = { math.huge, math.huge}, upper_left = { math.huge, math.huge},
lower_right = {-math.huge, -math.huge}, lower_right = {-math.huge, -math.huge},
@ -112,10 +113,6 @@ local function advance(pos, size)
current.pos[2] = pos[2] + current.grow[2] * (size[2] + current.spacing) current.pos[2] = pos[2] + current.grow[2] * (size[2] + current.spacing)
end end
-- adjust for padding
--pos[1] = pos[1] + current.pad
--pos[2] = pos[2] + current.pad
return pos, size return pos, size
end end
@ -134,9 +131,9 @@ local function getRect(pos, size)
pos[1] = pos[1] + current.pos[1] pos[1] = pos[1] + current.pos[1]
pos[2] = pos[2] + current.pos[2] pos[2] = pos[2] + current.pos[2]
local pos, size = advance(pos, size) pos, size = advance(pos, size)
pos[1] = pos[1] + current.pad pos[1] = pos[1] + current.pad
pos[2] = pos[2] + current.pad pos[2] = pos[2] + current.pad
return pos, size return pos, size
end end
@ -147,9 +144,9 @@ local function pop()
local child = current local child = current
current = stack[stack.n] or default current = stack[stack.n] or default
-- adjust for padding -- adjust for padding
child.lower_right[1] = child.lower_right[1] + child.pad * 2 child.lower_right[1] = child.lower_right[1] + child.pad * 2
child.lower_right[2] = child.lower_right[2] + child.pad * 2 child.lower_right[2] = child.lower_right[2] + child.pad * 2
local size = { local size = {
child.lower_right[1] - math.max(child.upper_left[1], current.pos[1]), child.lower_right[1] - math.max(child.upper_left[1], current.pos[1]),
@ -157,10 +154,10 @@ local function pop()
} }
advance(current.pos, size) advance(current.pos, size)
if child.bkg or child.border then if child.bkg or child.border then
core.registerDraw(child.id, child.draw or core.style.Group, true, core.registerDraw(child.id, child.draw or core.style.Group, true,
child.bkg, child.border, child.upper_left[1], child.upper_left[2], child.lower_right[1] - child.upper_left[1], child.lower_right[2] - child.upper_left[2]) child.bkg, child.border, child.upper_left[1], child.upper_left[2], child.lower_right[1] - child.upper_left[1], child.lower_right[2] - child.upper_left[2])
end end
end end
local function beginFrame() local function beginFrame()

View file

@ -32,7 +32,7 @@ local color = {
normal = {bg = {78,78,78}, fg = {200,200,200}, border={20,20,20}}, normal = {bg = {78,78,78}, fg = {200,200,200}, border={20,20,20}},
hot = {bg = {98,98,98}, fg = {69,201,84}, border={30,30,30}}, hot = {bg = {98,98,98}, fg = {69,201,84}, border={30,30,30}},
active = {bg = {88,88,88}, fg = {49,181,64}, border={10,10,10}}, active = {bg = {88,88,88}, fg = {49,181,64}, border={10,10,10}},
group = {bg = {88,88,88}, border = {255,255,255}} group = {bg = {88,88,88}, border = {255,255,255}}
} }
-- box drawing -- box drawing
@ -191,14 +191,14 @@ local function Checkbox(state, checked, label, align, x,y,w,h)
end end
local function Group(state, bkg, border, x,y,w,h) local function Group(state, bkg, border, x,y,w,h)
if bkg then if bkg then
love.graphics.setColor(color.group.bg) love.graphics.setColor(color.group.bg)
love.graphics.rectangle("fill", x, y, w, h) love.graphics.rectangle("fill", x, y, w, h)
end end
if border then if border then
love.graphics.setColor(color.group.border) love.graphics.setColor(color.group.border)
love.graphics.rectangle("line", x, y, w, h) love.graphics.rectangle("line", x, y, w, h)
end end
end end
-- the style -- the style
@ -212,5 +212,5 @@ return {
Slider2D = Slider2D, Slider2D = Slider2D,
Input = Input, Input = Input,
Checkbox = Checkbox, Checkbox = Checkbox,
Group = Group, Group = Group,
} }