feat: add drawWidget

Let the widget handle if its selected or not
This commit is contained in:
Kazhnuz 2020-12-04 12:55:48 +01:00
parent 37fc1fc9be
commit 7e697c3628

View file

@ -85,9 +85,16 @@ end
-- DRAW WIDGETS
-- Draw the widget
function BaseWidget:draw(x, y)
function BaseWidget:drawWidget(x, y, w, h)
if (self:haveFocus()) then
self:drawSelected(x, y, w, h)
else
self:draw(x, y, w, h)
end
end
function BaseWidget:draw(x, y, w, h)
if self.canvas.texture ~= nil then
utils.graphics.resetColor()
love.graphics.draw(self.canvas.texture, x, y)
end
end
@ -106,6 +113,13 @@ function BaseWidget:update(dt)
-- N/A
end
-- FOCUS FUNCTIONS
-- Detect if the widget have focus
function BaseWidget:haveFocus()
return (self.menu:haveFocus() and self.menu.widget:getSelected() == self.id)
end
-- ACTION FUNCTION
-- Functions to handle actions and selection.