Context menu mostly done

This commit is contained in:
airstruck
2015-12-21 16:14:05 -05:00
parent 147de8e010
commit 2d0dec2c70
4 changed files with 46 additions and 8 deletions

View File

@@ -41,7 +41,12 @@ return { id = 'mainWindow',
{ flow = 'x',
{ id = 'leftSideBox', minwidth = 200, width = 200, scroll = true, type = 'panel',
{ 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',
text = 'This text is centered, and in the middle vertically.' },
{ style = 'listThing', align = 'middle left',

View File

@@ -265,6 +265,28 @@ function Layout:addDefaultHandlers ()
self.accelerators[i] = {}
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)
-- keyboard accelerators

View File

@@ -3,7 +3,6 @@ local ROOT = (...):gsub('[^.]*$', '')
local Backend = require(ROOT .. 'backend')
local Base = require(ROOT .. 'base')
local Event = require(ROOT .. 'event')
local Font = Backend.Font
local Text = Backend.Text
local Painter = Base:extend()
@@ -277,8 +276,7 @@ function Painter:paintIconAndText ()
end
function Painter:paintChildren ()
local widget = self.widget
for i, child in ipairs(widget) do
for i, child in ipairs(self.widget) do
child:paint()
end
end

View File

@@ -13,6 +13,15 @@ local Backend = require(ROOT .. 'backend')
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 root = self.menuLayout.root
local textWidth = 0
@@ -87,7 +96,7 @@ local function deactivateSiblings (target)
end
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
while target.parent
@@ -98,6 +107,8 @@ local function activate (event, ignoreIfNoneOpen)
end
end
-- if not checkMouseButton(event) then return end
local wasSiblingOpen = deactivateSiblings(target)
local ignore = ignoreIfNoneOpen and not wasSiblingOpen
@@ -121,13 +132,14 @@ local function registerLayoutEvents (self)
if self.parentMenu == self.rootMenu then
deactivateSiblings(self.rootMenu[1])
end
elseif event.button == 'left' then
elseif checkMouseButton(menuLayout, event) then
activate(event)
end
end)
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
if widget.type == 'menu.item' and #widget.items == 0 then
menuLayout:hide()
@@ -137,7 +149,8 @@ local function registerLayoutEvents (self)
end)
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
if widget.type == 'menu.item' and #widget.items == 0
and event.target ~= event.origin then