mirror of
https://github.com/airstruck/luigi.git
synced 2026-01-10 16:28:23 +00:00
Context menu mostly done
This commit is contained in:
@@ -41,7 +41,12 @@ return { id = 'mainWindow',
|
|||||||
{ flow = 'x',
|
{ flow = 'x',
|
||||||
{ id = 'leftSideBox', minwidth = 200, width = 200, scroll = true, type = 'panel',
|
{ id = 'leftSideBox', minwidth = 200, width = 200, scroll = true, type = 'panel',
|
||||||
{ style = 'listThing', align = 'middle center',
|
{ style = 'listThing', align = 'middle center',
|
||||||
text = 'Try the scroll wheel on this area.' },
|
text = 'Try the scroll wheel on this area.',
|
||||||
|
context = {
|
||||||
|
{ text = 'Use sans-serif font', id = 'sans' },
|
||||||
|
{ text = 'Use monospace font' }
|
||||||
|
}
|
||||||
|
},
|
||||||
{ style = 'listThing', align = 'middle center',
|
{ style = 'listThing', align = 'middle center',
|
||||||
text = 'This text is centered, and in the middle vertically.' },
|
text = 'This text is centered, and in the middle vertically.' },
|
||||||
{ style = 'listThing', align = 'middle left',
|
{ style = 'listThing', align = 'middle left',
|
||||||
|
|||||||
@@ -265,6 +265,28 @@ function Layout:addDefaultHandlers ()
|
|||||||
self.accelerators[i] = {}
|
self.accelerators[i] = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
self:onPressStart(function (event)
|
||||||
|
if event.button ~= 'right' then return end
|
||||||
|
local menu = event.target.contextMenu
|
||||||
|
if not menu then
|
||||||
|
local context = event.target.context
|
||||||
|
if not context then return end
|
||||||
|
context.text = 'foo'
|
||||||
|
menu = event.target:addChild {
|
||||||
|
type = 'menu',
|
||||||
|
width = 0,
|
||||||
|
height = 0,
|
||||||
|
context
|
||||||
|
}
|
||||||
|
menu[1].menuLayout.isContextMenu = true
|
||||||
|
event.target.contextMenu = menu
|
||||||
|
end
|
||||||
|
menu[1]:bubbleEvent('PressStart', event)
|
||||||
|
menu[1].menuLayout.root.left = event.x + 1
|
||||||
|
menu[1].menuLayout.root.top = event.y + 1
|
||||||
|
return false
|
||||||
|
end)
|
||||||
|
|
||||||
self:onKeyPress(function (event)
|
self:onKeyPress(function (event)
|
||||||
|
|
||||||
-- keyboard accelerators
|
-- keyboard accelerators
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ local ROOT = (...):gsub('[^.]*$', '')
|
|||||||
local Backend = require(ROOT .. 'backend')
|
local Backend = require(ROOT .. 'backend')
|
||||||
local Base = require(ROOT .. 'base')
|
local Base = require(ROOT .. 'base')
|
||||||
local Event = require(ROOT .. 'event')
|
local Event = require(ROOT .. 'event')
|
||||||
local Font = Backend.Font
|
|
||||||
local Text = Backend.Text
|
local Text = Backend.Text
|
||||||
|
|
||||||
local Painter = Base:extend()
|
local Painter = Base:extend()
|
||||||
@@ -277,8 +276,7 @@ function Painter:paintIconAndText ()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Painter:paintChildren ()
|
function Painter:paintChildren ()
|
||||||
local widget = self.widget
|
for i, child in ipairs(self.widget) do
|
||||||
for i, child in ipairs(widget) do
|
|
||||||
child:paint()
|
child:paint()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -13,6 +13,15 @@ local Backend = require(ROOT .. 'backend')
|
|||||||
|
|
||||||
local Layout, Event
|
local Layout, Event
|
||||||
|
|
||||||
|
local function checkMouseButton (layout, event)
|
||||||
|
local button = event.button
|
||||||
|
if not button then return false end
|
||||||
|
if layout.isContextMenu then
|
||||||
|
return button == 'left' or button == 'right'
|
||||||
|
end
|
||||||
|
return button == 'left'
|
||||||
|
end
|
||||||
|
|
||||||
local function addLayoutChildren (self)
|
local function addLayoutChildren (self)
|
||||||
local root = self.menuLayout.root
|
local root = self.menuLayout.root
|
||||||
local textWidth = 0
|
local textWidth = 0
|
||||||
@@ -87,7 +96,7 @@ local function deactivateSiblings (target)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function activate (event, ignoreIfNoneOpen)
|
local function activate (event, ignoreIfNoneOpen)
|
||||||
if event.button and event.button ~= 'left' then return end
|
-- if event.button and event.button ~= 'left' then return end
|
||||||
local target = event.target
|
local target = event.target
|
||||||
|
|
||||||
while target.parent
|
while target.parent
|
||||||
@@ -98,6 +107,8 @@ local function activate (event, ignoreIfNoneOpen)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- if not checkMouseButton(event) then return end
|
||||||
|
|
||||||
local wasSiblingOpen = deactivateSiblings(target)
|
local wasSiblingOpen = deactivateSiblings(target)
|
||||||
local ignore = ignoreIfNoneOpen and not wasSiblingOpen
|
local ignore = ignoreIfNoneOpen and not wasSiblingOpen
|
||||||
|
|
||||||
@@ -121,13 +132,14 @@ local function registerLayoutEvents (self)
|
|||||||
if self.parentMenu == self.rootMenu then
|
if self.parentMenu == self.rootMenu then
|
||||||
deactivateSiblings(self.rootMenu[1])
|
deactivateSiblings(self.rootMenu[1])
|
||||||
end
|
end
|
||||||
elseif event.button == 'left' then
|
elseif checkMouseButton(menuLayout, event) then
|
||||||
activate(event)
|
activate(event)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
menuLayout:onPress(function (event)
|
menuLayout:onPress(function (event)
|
||||||
if event.button ~= 'left' then return end
|
-- if event.button ~= 'left' then return end
|
||||||
|
if not checkMouseButton(menuLayout, event) then return end
|
||||||
for widget in event.target:eachAncestor(true) do
|
for widget in event.target:eachAncestor(true) do
|
||||||
if widget.type == 'menu.item' and #widget.items == 0 then
|
if widget.type == 'menu.item' and #widget.items == 0 then
|
||||||
menuLayout:hide()
|
menuLayout:hide()
|
||||||
@@ -137,7 +149,8 @@ local function registerLayoutEvents (self)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
menuLayout:onPressEnd(function (event)
|
menuLayout:onPressEnd(function (event)
|
||||||
if event.button ~= 'left' then return end
|
-- if event.button ~= 'left' then return end
|
||||||
|
if not checkMouseButton(menuLayout, event) then return end
|
||||||
for widget in event.target:eachAncestor(true) do
|
for widget in event.target:eachAncestor(true) do
|
||||||
if widget.type == 'menu.item' and #widget.items == 0
|
if widget.type == 'menu.item' and #widget.items == 0
|
||||||
and event.target ~= event.origin then
|
and event.target ~= event.origin then
|
||||||
|
|||||||
Reference in New Issue
Block a user