From cd72b080bd949d9ec0b42c29e0ea31e300464dad Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 24 Aug 2016 00:10:33 +0200 Subject: Focus() return bool --- button.lua | 1 + element.lua | 8 ++------ header.lua | 8 ++------ menu.lua | 8 ++++++-- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/button.lua b/button.lua index d7caf74..fd12e0b 100644 --- a/button.lua +++ b/button.lua @@ -34,6 +34,7 @@ end function Button:getPosition() return self.x,self.y end function Button:focus(next) self.focused = true + return true end function Button:blur() self.focused = false diff --git a/element.lua b/element.lua index 5ca013b..f9d1c3d 100644 --- a/element.lua +++ b/element.lua @@ -26,12 +26,8 @@ function Element:set(name, func) end -- Menu callbacks -function Element:focus(next) -- Called when Element gains focus - if next and self.parent then - self.parent:next() - else - self.parent:previous() - end +function Element:focus() -- Called when Element gains focus + return false end function Element:blur() end -- Called when Element loses focus diff --git a/header.lua b/header.lua index d538ab3..d67e582 100644 --- a/header.lua +++ b/header.lua @@ -29,12 +29,8 @@ function Header:getBounce(f) return math.sin(self.bounce*f*math.pi) end function Header:getPosition() return self.x,self.y end -- gives x,y of Element -function Header:focus(next) - if next and self.parent then - self.parent:next() - else - self.parent:previous() - end +function Header:focus() + return false end function Header:blur() end -- Called when Element loses focus diff --git a/menu.lua b/menu.lua index 3ef477d..95e764b 100644 --- a/menu.lua +++ b/menu.lua @@ -34,7 +34,9 @@ end function Menu:next() self.elements[self.active]:blur() self.active = (self.active%#self.elements)+1 - self.elements[self.active]:focus(true) + if not self.elements[self.active]:focus() then + self:next() + end end function Menu:previous() self.elements[self.active]:blur() @@ -43,7 +45,9 @@ function Menu:previous() else self.active = self.active - 1 end - self.elements[self.active]:focus() + if not self.elements[self.active]:focus() then + self:previous() + end end -- LÖVE2D callbacks -- cgit v1.1