mirror of
https://github.com/airstruck/luigi.git
synced 2025-12-19 02:16:43 +00:00
rework mouse buttons, fixes #18
This commit is contained in:
@@ -13,7 +13,8 @@ standard themes, the widget's value should be indicated in some other way.
|
||||
--]]--
|
||||
|
||||
return function (self)
|
||||
self:onPress(function ()
|
||||
self:onPress(function (event)
|
||||
if event.button ~= 'left' then return end
|
||||
self.value = not self.value
|
||||
end)
|
||||
|
||||
|
||||
@@ -87,6 +87,7 @@ local function deactivateSiblings (target)
|
||||
end
|
||||
|
||||
local function activate (event, ignoreIfNoneOpen)
|
||||
if event.button and event.button ~= 'left' then return end
|
||||
local target = event.target
|
||||
|
||||
while target.parent
|
||||
@@ -120,12 +121,13 @@ local function registerLayoutEvents (self)
|
||||
if self.parentMenu == self.rootMenu then
|
||||
deactivateSiblings(self.rootMenu[1])
|
||||
end
|
||||
else
|
||||
elseif event.button == 'left' then
|
||||
activate(event)
|
||||
end
|
||||
end)
|
||||
|
||||
menuLayout:onPress(function (event)
|
||||
if event.button ~= 'left' then return end
|
||||
for widget in event.target:eachAncestor(true) do
|
||||
if widget.type == 'menu.item' and #widget.items == 0 then
|
||||
menuLayout:hide()
|
||||
@@ -135,6 +137,7 @@ local function registerLayoutEvents (self)
|
||||
end)
|
||||
|
||||
menuLayout:onPressEnd(function (event)
|
||||
if event.button ~= 'left' then return end
|
||||
for widget in event.target:eachAncestor(true) do
|
||||
if widget.type == 'menu.item' and #widget.items == 0
|
||||
and event.target ~= event.origin then
|
||||
|
||||
@@ -64,7 +64,8 @@ in the same group change to `false`.
|
||||
@section end
|
||||
--]]--
|
||||
|
||||
self:onPress(function ()
|
||||
self:onPress(function (event)
|
||||
if event.button ~= 'left' then return end
|
||||
for _, widget in ipairs(groups[self.group]) do
|
||||
widget.value = widget == self
|
||||
end
|
||||
|
||||
@@ -63,6 +63,7 @@ return function (self)
|
||||
end)
|
||||
|
||||
self:onPressDrag(function (event)
|
||||
if event.button ~= 'left' then return end
|
||||
local axis = self.parent.flow
|
||||
if axis == 'x' then
|
||||
dimension = 'width'
|
||||
|
||||
@@ -21,7 +21,8 @@ return function (self)
|
||||
type = 'slider.thumb',
|
||||
}
|
||||
|
||||
local function unpress ()
|
||||
local function unpress (event)
|
||||
if event.button ~= 'left' then return end
|
||||
thumb.pressed = false -- don't make the thumb appear pushed in
|
||||
return false -- don't press thumb on focused keyboard activation
|
||||
end
|
||||
@@ -39,6 +40,7 @@ return function (self)
|
||||
end)
|
||||
|
||||
local function press (event)
|
||||
if event.button ~= 'left' then return end
|
||||
local x1, y1, w, h = self:getRectangle(true, true)
|
||||
local x2, y2 = x1 + w, y1 + h
|
||||
if self.flow == 'x' then
|
||||
|
||||
@@ -94,10 +94,12 @@ Contains the index in `items` of the item being displayed.
|
||||
end
|
||||
|
||||
before:onPress(function (event)
|
||||
if event.button ~= 'left' then return end
|
||||
if self.flow == 'x' then decrement() else increment() end
|
||||
end)
|
||||
|
||||
after:onPress(function (event)
|
||||
if event.button ~= 'left' then return end
|
||||
if self.flow == 'x' then increment() else decrement() end
|
||||
end)
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ local function scrollToCaret (self)
|
||||
end
|
||||
|
||||
local function findCaretFromText (self, text)
|
||||
local font = self.fontData
|
||||
local font = self:getFont()
|
||||
local x = self:getRectangle(true, true)
|
||||
return #text, font:getAdvance(text) + x - self.scrollX
|
||||
end
|
||||
@@ -178,12 +178,7 @@ local function insertText (self, newText)
|
||||
end
|
||||
|
||||
return function (self)
|
||||
if not self.fontData then
|
||||
self.fontData = Backend.Font(self.font, self.size)
|
||||
end
|
||||
|
||||
self.value = tostring(self.value or self.text or '')
|
||||
|
||||
self.text = ''
|
||||
|
||||
--[[--
|
||||
@@ -201,12 +196,14 @@ This color is used to indicate the selected range of text.
|
||||
|
||||
@attrib highlight
|
||||
--]]--
|
||||
|
||||
self:defineAttribute('highlight')
|
||||
|
||||
--[[--
|
||||
@section end
|
||||
--]]--
|
||||
if not self.highlight then
|
||||
self.highlight = { 0x80, 0x80, 0x80 }
|
||||
self.highlight = { 0x80, 0x80, 0x80, 0x80 }
|
||||
end
|
||||
|
||||
self.scrollX = 0
|
||||
@@ -214,11 +211,13 @@ This color is used to indicate the selected range of text.
|
||||
setCaretFromText(self, self.value)
|
||||
|
||||
self:onPressStart(function (event)
|
||||
if event.button ~= 'left' then return end
|
||||
self.startIndex, self.startX = findCaretFromPoint(self, event.x)
|
||||
self.endIndex, self.endX = self.startIndex, self.startX
|
||||
end)
|
||||
|
||||
self:onPressDrag(function (event)
|
||||
if event.button ~= 'left' then return end
|
||||
self.endIndex, self.endX = findCaretFromPoint(self, event.x)
|
||||
scrollToCaret(self)
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user