mirror of
https://github.com/airstruck/luigi.git
synced 2025-11-18 12:25:06 +00:00
Implement Focus event. (#62)
* Implement `Focus` event. * Add Blur event.
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user