mirror of
https://github.com/airstruck/luigi.git
synced 2026-01-09 15:58:22 +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.
|
'KeyRelease', -- A keyboard key was released.
|
||||||
'TextInput', -- Text was entered.
|
'TextInput', -- Text was entered.
|
||||||
'Move', -- The cursor moved, and no button was pressed.
|
'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.
|
'Enter', -- The cursor entered a widget, and no button was pressed.
|
||||||
'Leave', -- The cursor left 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.
|
'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 ()
|
function Widget:focus ()
|
||||||
local layout = self.layout
|
local layout = self.layout
|
||||||
|
|
||||||
|
if layout.focusedWidget == self then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
if layout.focusedWidget then
|
if layout.focusedWidget then
|
||||||
layout.focusedWidget.focused = nil
|
layout.focusedWidget.focused = nil
|
||||||
|
Event.Blur:emit(self.layout, layout.focusedWidget)
|
||||||
layout.focusedWidget = nil
|
layout.focusedWidget = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.focusable then
|
if self.focusable then
|
||||||
self.focused = true
|
self.focused = true
|
||||||
layout.focusedWidget = self
|
layout.focusedWidget = self
|
||||||
|
Event.Focus:emit(self.layout, self)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user