attrib "key" -> "shortcut", also fix #20

This commit is contained in:
airstruck
2016-01-03 01:18:04 -05:00
parent 3abcce1615
commit c73833337e
12 changed files with 98 additions and 90 deletions

View File

@@ -13,10 +13,10 @@ local Backend = require(ROOT .. 'backend')
local Layout, Event
local function checkMouseButton (layout, event)
local function checkMouseButton (self, event)
local button = event.button
if not button then return false end
if layout.isContextMenu then
if self.isContextMenu then
return button == 'left' or button == 'right'
end
return button == 'left'
@@ -133,14 +133,14 @@ local function registerLayoutEvents (self)
if self.parentMenu == self.rootMenu then
deactivateSiblings(self.rootMenu[1])
end
elseif checkMouseButton(menuLayout, event) then
elseif checkMouseButton(self, event) then
activate(event)
end
end)
menuLayout:onPress(function (event)
-- if event.button ~= 'left' then return end
if not checkMouseButton(menuLayout, event) then return end
if not checkMouseButton(self, event) then return end
for widget in event.target:eachAncestor(true) do
if widget.type == 'menu.item' and #widget.items == 0 then
menuLayout:hide()
@@ -151,7 +151,7 @@ local function registerLayoutEvents (self)
menuLayout:onPressEnd(function (event)
-- if event.button ~= 'left' then return end
if not checkMouseButton(menuLayout, event) then return end
if not checkMouseButton(self, 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
@@ -231,7 +231,6 @@ local function createLayout (self)
end
return function (self)
self.context = false
extractChildren(self)
initialize(self)
registerEvents(self)

View File

@@ -41,26 +41,16 @@ Contains the index in `items` of the item being displayed.
self.items = {}
self.index = 1
self.flow = 'x' -- TODO: support vertical stepper
local contextMenu
for index, child in ipairs(self) do
child.type = child.type or 'stepper.item'
if child.isContextMenu then
contextMenu = child
else
self.items[index] = child
end
self.items[index] = child
self[index] = nil
end
local before = self:addChild { type = 'stepper.before' }
local view = self:addChild { type = 'stepper.view' }
local after = self:addChild { type = 'stepper.after' }
if contextMenu then
self:addChild(contextMenu)
end
self:onReshape(function (event)
if self.flow == 'x' then

View File

@@ -198,13 +198,10 @@ This color is used to indicate the selected range of text.
--]]--
self:defineAttribute('highlight')
local defaultHighlight = { 0x80, 0x80, 0x80, 0x80 }
--[[--
@section end
--]]--
if not self.highlight then
self.highlight = { 0x80, 0x80, 0x80, 0x80 }
end
self.scrollX = 0
@@ -286,7 +283,7 @@ This color is used to indicate the selected range of text.
if self.focused then
-- draw highlighted selection
Backend.setColor(self.highlight)
Backend.setColor(self.highlight or defaultHighlight)
Backend.drawRectangle('fill', startX, y, width, height)
-- draw cursor selection
if Backend.getTime() % 2 < 1.75 then