Implement Focus event. (#62)

* Implement `Focus` event.

* Add Blur event.
This commit is contained in:
Nolan Darilek
2019-04-23 09:19:17 -07:00
committed by airstruck
parent 967002a816
commit 52a9f818d8
2 changed files with 8 additions and 0 deletions

View File

@@ -34,6 +34,8 @@ Event.names = {
'KeyRelease', -- A keyboard key was released.
'TextInput', -- Text was entered.
'Move', -- The cursor moved, and no button was pressed.
'Focus', -- A widget received focus.
'Blur', -- A widget lost focus.
'Enter', -- The cursor entered a widget, and no button was pressed.
'Leave', -- The cursor left a widget, and no button was pressed.
'PressEnter', -- The cursor entered a widget, and a button was pressed.

View File

@@ -330,14 +330,20 @@ true if this widget was focused, else false.
function Widget:focus ()
local layout = self.layout
if layout.focusedWidget == self then
return true
end
if layout.focusedWidget then
layout.focusedWidget.focused = nil
Event.Blur:emit(self.layout, layout.focusedWidget)
layout.focusedWidget = nil
end
if self.focusable then
self.focused = true
layout.focusedWidget = self
Event.Focus:emit(self.layout, self)
return true
end