Widget.pressed is now a table of booleans keyed by mouse button name

This commit is contained in:
airstruck
2015-12-20 01:13:43 -05:00
parent 1ee239b203
commit 73e9a10b15
5 changed files with 13 additions and 14 deletions

View File

@@ -12,7 +12,7 @@ return {
width = 48,
height = 48,
slices = function (self)
if self.focused or self.hovered or self.pressed then
if self.focused or self.hovered or self.pressed.left then
return nil -- fall back to theme default
end
return false -- no slices

View File

@@ -129,9 +129,7 @@ function Input:handlePressedMove (layout, x, y)
x = x, y = y
})
else
if button == 'left' then
originWidget.pressed = (widget == originWidget) or nil
end
originWidget.pressed[button] = (widget == originWidget) or nil
if passedWidget then
passedWidget:bubbleEvent('PressLeave', {
hit = hit,
@@ -165,8 +163,8 @@ function Input:handlePressStart (layout, button, x, y, widget, accelerator)
if hit then
self.pressedWidgets[button] = widget
self.passedWidgets[button] = widget
widget.pressed[button] = true
if button == 'left' then
widget.pressed = true
widget:focus()
end
end
@@ -188,8 +186,8 @@ function Input:handlePressEnd (layout, button, x, y, widget, accelerator)
end
local originWidget = self.pressedWidgets[button]
if not originWidget then return end
if hit and button == 'left' then
originWidget.pressed = nil
if hit then
originWidget.pressed[button] = nil
end
widget:bubbleEvent('PressEnd', {
hit = hit,

View File

@@ -36,14 +36,14 @@ return function (config)
local text = resources .. 'text.png'
local function getButtonSlices (self)
return self.pressed and button_pressed
return self.pressed.left and button_pressed
or self.focused and button_focused
or self.hovered and button_hovered
or button
end
local function getCheckIcon (self)
if self.pressed then
if self.pressed.left then
return self.value and check_checked_pressed
or check_unchecked_pressed
end
@@ -67,7 +67,7 @@ return function (config)
end
local function getRadioIcon (self)
if self.pressed then
if self.pressed.left then
return self.value and radio_checked_pressed
or radio_unchecked_pressed
end

View File

@@ -48,7 +48,7 @@ Whether the pointer was pressed on this widget and not yet released.
Can be used by styles and themes. This value is automatically set by
the `Input` class, and should generally be treated as read-only.
--]]--
Widget.pressed = false
Widget.pressed = nil
--[[--
Internal Properties
@@ -88,12 +88,12 @@ Widget.hasType = false
--[[--
The `Font` object associated with the widget.
--]]--
Widget.fontData = false
Widget.fontData = nil
--[[--
The `Text` object associated with the widget.
--]]--
Widget.textData = false
Widget.textData = nil
--[[--
@@ -216,6 +216,7 @@ local function metaCall (Widget, layout, self)
self.dimensions = { width = nil, height = nil }
self.attributes = {}
self.attributeDescriptors = {}
self.pressed = {}
self.painter = Painter(self)
setmetatable(self, { __index = metaIndex, __newindex = metaNewIndex })

View File

@@ -23,7 +23,7 @@ return function (self)
local function unpress (event)
if event.button ~= 'left' then return end
thumb.pressed = false -- don't make the thumb appear pushed in
thumb.pressed.left = nil -- don't make the thumb appear pushed in
return false -- don't press thumb on focused keyboard activation
end