diff --git a/button.lua b/button.lua index c63c6fe..a1f0589 100644 --- a/button.lua +++ b/button.lua @@ -69,7 +69,7 @@ return function(w) -- core.registerDraw(id, drawfunction, drawfunction-arguments...) -- shows widget when core.draw() is called. - core.registerDraw(id, w.draw or core.style.Button, false, + core.registerDraw(id, w.draw or core.style.Button, w.text, pos[1],pos[2], size[1],size[2]) return mouse.releasedOn(id) or keyboard.pressedOn(id, 'return') diff --git a/checkbox.lua b/checkbox.lua index dbaf953..5137bb0 100644 --- a/checkbox.lua +++ b/checkbox.lua @@ -60,7 +60,7 @@ return function(w) w.checked = not w.checked end - core.registerDraw(id, w.draw or core.style.Checkbox, false, + core.registerDraw(id, w.draw or core.style.Checkbox, w.checked, w.text, w.align or 'left', pos[1], pos[2], size[1], size[2]) return w.checked ~= checked diff --git a/core.lua b/core.lua index d1dd999..bec356c 100644 --- a/core.lua +++ b/core.lua @@ -66,7 +66,7 @@ end -- Drawing / Frame update -- local draw_items = {n = 0} -local function registerDraw(id, f, isGroup, ...) +local function registerDraw(id, f, ...) assert(type(f) == 'function' or (getmetatable(f) or {}).__call, 'Drawing function is not a callable type!') @@ -80,7 +80,7 @@ local function registerDraw(id, f, isGroup, ...) draw_items.n = draw_items.n + 1 local targetindex = draw_items.n - if isGroup then targetindex = 1 end + if id == "group_draw" then targetindex = 1 end table.insert(draw_items, targetindex, function() if font then love.graphics.setFont(font) end diff --git a/group.lua b/group.lua index 7441189..82c1111 100644 --- a/group.lua +++ b/group.lua @@ -79,10 +79,7 @@ local function push(info) assert(size, "Size 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)) - - local id = info.id - if not id then id = core.generateID() end - + current = { pos = pos, grow = grow, @@ -92,7 +89,6 @@ local function push(info) border = info.border, bkg = info.bkg, draw = info.draw, - id = id, upper_left = { math.huge, math.huge}, lower_right = {-math.huge, -math.huge}, } @@ -154,8 +150,9 @@ local function pop() } advance(current.pos, size) + -- skip the draw call if we don't need it if child.bkg or child.border then - core.registerDraw(child.id, child.draw or core.style.Group, true, + 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 diff --git a/input.lua b/input.lua index a7e1753..b161993 100644 --- a/input.lua +++ b/input.lua @@ -73,7 +73,7 @@ return function(w) w.info.cursor = w.info.cursor + 1 end - core.registerDraw(id, w.draw or core.style.Input, false, + core.registerDraw(id, w.draw or core.style.Input, w.info.text, w.info.cursor, pos[1],pos[2], size[1],size[2]) return mouse.releasedOn(id) or keyboard.pressedOn(id, 'return') diff --git a/label.lua b/label.lua index 58e5cbc..345516c 100644 --- a/label.lua +++ b/label.lua @@ -53,7 +53,7 @@ return function(w) keyboard.clearFocus() end - core.registerDraw(id, w.draw or core.style.Label, false, + core.registerDraw(id, w.draw or core.style.Label, w.text, w.align, pos[1],pos[2], size[1],size[2]) return mouse.releasedOn(id) diff --git a/slider.lua b/slider.lua index 2977f80..4700ae5 100644 --- a/slider.lua +++ b/slider.lua @@ -72,7 +72,7 @@ return function(w) end end - core.registerDraw(id, w.draw or core.style.Slider, false, + core.registerDraw(id, w.draw or core.style.Slider, fraction, w.vertical, pos[1],pos[2], size[1],size[2]) return changed diff --git a/slider2d.lua b/slider2d.lua index ca732f6..19e264c 100644 --- a/slider2d.lua +++ b/slider2d.lua @@ -92,7 +92,7 @@ return function(w) end end - core.registerDraw(id, w.draw or core.style.Slider2D, false, + core.registerDraw(id, w.draw or core.style.Slider2D, fraction, pos[1],pos[2], size[1],size[2]) return changed