Merge ebf0b1fc69
into 4eadfee6f4
This commit is contained in:
commit
03f677edef
4 changed files with 62 additions and 10 deletions
|
@ -73,7 +73,7 @@ Quickie is an [immediate mode gui][IMGUI] library for [LÖVE][LOVE]. Initial
|
||||||
gui.group.pop{}
|
gui.group.pop{}
|
||||||
|
|
||||||
if menu_open.demo then
|
if menu_open.demo then
|
||||||
gui.group{grow = "down", pos = {200, 80}, function()
|
gui.group{grow = "down", pos = {200, 80}, pad = 10, border = true, bkg = true, function()
|
||||||
love.graphics.setFont(fonts[20])
|
love.graphics.setFont(fonts[20])
|
||||||
gui.Label{text = "Widgets"}
|
gui.Label{text = "Widgets"}
|
||||||
love.graphics.setFont(fonts[12])
|
love.graphics.setFont(fonts[12])
|
||||||
|
|
8
core.lua
8
core.lua
|
@ -78,10 +78,14 @@ local function registerDraw(id, f, ...)
|
||||||
end
|
end
|
||||||
local rest = {n = select('#', ...), ...}
|
local rest = {n = select('#', ...), ...}
|
||||||
draw_items.n = draw_items.n + 1
|
draw_items.n = draw_items.n + 1
|
||||||
draw_items[draw_items.n] = function()
|
|
||||||
|
local targetindex = draw_items.n
|
||||||
|
if id == "group_draw" then targetindex = 1 end
|
||||||
|
|
||||||
|
table.insert(draw_items, targetindex, function()
|
||||||
if font then love.graphics.setFont(font) end
|
if font then love.graphics.setFont(font) end
|
||||||
f(state, unpack(rest, 1, rest.n))
|
f(state, unpack(rest, 1, rest.n))
|
||||||
end
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- actually update-and-draw
|
-- actually update-and-draw
|
||||||
|
|
40
group.lua
40
group.lua
|
@ -24,6 +24,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
|
local BASE = (...):match("(.-)[^%.]+$")
|
||||||
|
local core = nil -- cant load here bc of circular dependencies
|
||||||
|
|
||||||
local stack = {n = 0}
|
local stack = {n = 0}
|
||||||
local default = {
|
local default = {
|
||||||
pos = {0,0},
|
pos = {0,0},
|
||||||
|
@ -32,6 +35,7 @@ local default = {
|
||||||
size = {100, 30},
|
size = {100, 30},
|
||||||
upper_left = {0,0},
|
upper_left = {0,0},
|
||||||
lower_right = {0,0},
|
lower_right = {0,0},
|
||||||
|
pad = 0
|
||||||
}
|
}
|
||||||
local current = default
|
local current = default
|
||||||
|
|
||||||
|
@ -43,10 +47,15 @@ local Grow = {
|
||||||
right = { 1, 0}
|
right = { 1, 0}
|
||||||
}
|
}
|
||||||
|
|
||||||
-- {grow = grow, spacing = spacing, size = size, pos = pos}
|
-- {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
|
||||||
|
|
||||||
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 size = {
|
local size = {
|
||||||
info.size and info.size[1] or current.size[1],
|
info.size and info.size[1] or current.size[1],
|
||||||
|
@ -54,6 +63,14 @@ 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)
|
||||||
|
local parent = stack[stack.n]
|
||||||
|
if parent then
|
||||||
|
pos[1] = pos[1] + parent.pad
|
||||||
|
pos[2] = pos[2] + parent.pad
|
||||||
|
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)
|
||||||
pos[2] = pos[2] + (info.pos[2] or 0)
|
pos[2] = pos[2] + (info.pos[2] or 0)
|
||||||
|
@ -68,6 +85,10 @@ local function push(info)
|
||||||
grow = grow,
|
grow = grow,
|
||||||
size = size,
|
size = size,
|
||||||
spacing = spacing,
|
spacing = spacing,
|
||||||
|
pad = pad,
|
||||||
|
border = info.border,
|
||||||
|
bkg = info.bkg,
|
||||||
|
draw = info.draw,
|
||||||
upper_left = { math.huge, math.huge},
|
upper_left = { math.huge, math.huge},
|
||||||
lower_right = {-math.huge, -math.huge},
|
lower_right = {-math.huge, -math.huge},
|
||||||
}
|
}
|
||||||
|
@ -87,6 +108,7 @@ local function advance(pos, size)
|
||||||
if current.grow[2] ~= 0 then
|
if current.grow[2] ~= 0 then
|
||||||
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
|
||||||
|
|
||||||
return pos, size
|
return pos, size
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -105,20 +127,34 @@ 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]
|
||||||
|
|
||||||
return advance(pos, size)
|
pos, size = advance(pos, size)
|
||||||
|
pos[1] = pos[1] + current.pad
|
||||||
|
pos[2] = pos[2] + current.pad
|
||||||
|
return pos, size
|
||||||
end
|
end
|
||||||
|
|
||||||
local function pop()
|
local function pop()
|
||||||
assert(stack.n > 0, "Group stack is empty.")
|
assert(stack.n > 0, "Group stack is empty.")
|
||||||
|
|
||||||
stack.n = stack.n - 1
|
stack.n = stack.n - 1
|
||||||
local child = current
|
local child = current
|
||||||
current = stack[stack.n] or default
|
current = stack[stack.n] or default
|
||||||
|
|
||||||
|
-- adjust for padding
|
||||||
|
child.lower_right[1] = child.lower_right[1] + 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]),
|
||||||
child.lower_right[2] - math.max(child.upper_left[2], current.pos[2])
|
child.lower_right[2] - math.max(child.upper_left[2], current.pos[2])
|
||||||
}
|
}
|
||||||
advance(current.pos, size)
|
advance(current.pos, size)
|
||||||
|
|
||||||
|
-- skip the draw call if we don't need it
|
||||||
|
if child.bkg or child.border then
|
||||||
|
core.registerDraw("group_draw", child.draw or core.style.Group,
|
||||||
|
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
|
||||||
|
|
||||||
local function beginFrame()
|
local function beginFrame()
|
||||||
|
|
|
@ -31,7 +31,8 @@ local utf8 = require(BASE .. 'utf8')
|
||||||
local color = {
|
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}}
|
||||||
}
|
}
|
||||||
|
|
||||||
-- box drawing
|
-- box drawing
|
||||||
|
@ -189,6 +190,16 @@ local function Checkbox(state, checked, label, align, x,y,w,h)
|
||||||
love.graphics.print(label, tx, ty)
|
love.graphics.print(label, tx, ty)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function Group(state, bkg, border, x,y,w,h)
|
||||||
|
if bkg then
|
||||||
|
love.graphics.setColor(color.group.bg)
|
||||||
|
love.graphics.rectangle("fill", x, y, w, h)
|
||||||
|
end
|
||||||
|
if border then
|
||||||
|
love.graphics.setColor(color.group.border)
|
||||||
|
love.graphics.rectangle("line", x, y, w, h)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- the style
|
-- the style
|
||||||
return {
|
return {
|
||||||
|
@ -201,4 +212,5 @@ return {
|
||||||
Slider2D = Slider2D,
|
Slider2D = Slider2D,
|
||||||
Input = Input,
|
Input = Input,
|
||||||
Checkbox = Checkbox,
|
Checkbox = Checkbox,
|
||||||
|
Group = Group,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue