diff --git a/elements/input.lua b/elements/input.lua index 2db7c67..927f008 100644 --- a/elements/input.lua +++ b/elements/input.lua @@ -81,7 +81,7 @@ uie.add("button", { bgNext = style.pressedBG fgNext = style.pressedFG borderNext = style.pressedBorder - elseif self.hovered then + elseif self.hovered or self.focused then bgNext = style.hoveredBG fgNext = style.hoveredFG borderNext = style.hoveredBorder @@ -125,6 +125,23 @@ uie.add("button", { if self.enabled and cb and button == 1 then cb(self, x, y, button) end + end, + + onKeyPress = function(self, key) + if self.enabled and (key == "space" or key == "return") then + self.pressed = true + end + end, + + onKeyRelease = function(self, key) + local cb = self.cb + if self.enabled and (key == "space" or key == "return") then + self.pressed = false + + if cb then + cb(self, self.screenX + self.width / 2, self.screenY + self.height / 2, 1) + end + end end }) @@ -1490,7 +1507,7 @@ uie.add("checkbox", { end local icon - local iconColor + local color if value and self.activeIcon then icon = self.activeIcon color = self.style.activeIconColor @@ -1525,6 +1542,24 @@ uie.add("checkbox", { self:cb(self.value) end end + end, + + onKeyPress = function(self, key) + if self.enabled and (key == "space" or key == "return") then + self.pressed = true + end + end, + + onKeyRelease = function(self, key) + local cb = self.cb + if self.enabled and (key == "space" or key == "return") then + self.pressed = false + self:setValue(not self:getValue()) + + if cb then + cb(self, self.value) + end + end end })