hotkeys use modifiers

This commit is contained in:
airstruck
2015-11-11 23:49:54 -05:00
parent 68a250e273
commit 6aaa128463
13 changed files with 205 additions and 113 deletions

View File

@@ -132,15 +132,14 @@ local function initialize (self)
key = ' '
edgeType = 'menu.expander'
else
key = key:gsub('%f[%w].', string.upper)
key = key:gsub('%f[%w].', string.upper) -- :gsub('-', '+')
end
self.height = self.fontData:getLineHeight() + pad * 2
self.flow = 'x'
self:addChild({ icon = icon, width = self.height })
self:addChild({ text = text, width = textWidth })
self:addChild({ text = key, align = 'middle right',
minwidth = self.height,
textColor = keyColor, type = edgeType })
self:addChild { icon = icon, width = self.height }
self:addChild { text = text, width = textWidth }
self:addChild { text = key, align = 'middle right',
minwidth = self.height, textColor = keyColor, type = edgeType }
self.icon = nil
self.text = nil

View File

@@ -4,7 +4,7 @@ return function (self)
return value < 0 and 0 or value > 1 and 1 or value
end
self:setValue(clamp(self.value or 0.5))
self.value = clamp(self.value or 0.5)
self.step = self.step or 0.01
self.flow = 'x' -- TODO: support vertical slider
@@ -28,9 +28,9 @@ return function (self)
thumb:onKeyPress(function (event)
local key = event.key
if key == 'left' or key == 'down' then
self:setValue(clamp(self.value - self.step))
self.value = clamp(self.value - self.step)
elseif event.key == 'right' or key == 'up' then
self:setValue(clamp(self.value + self.step))
self.value = clamp(self.value + self.step)
end
end)
@@ -38,7 +38,7 @@ return function (self)
local x1, y1, x2, y2 = self:getRectangle(true, true)
local halfThumb = thumb:getWidth() / 2
x1, x2 = x1 + halfThumb, x2 - halfThumb
self:setValue(clamp((event.x - x1) / (x2 - x1)))
self.value = clamp((event.x - x1) / (x2 - x1))
thumb:focus()
end

View File

@@ -1,22 +1,17 @@
return function (self)
self.items = {}
self.index = 1
self.flow = 'x' -- TODO: support vertical stepper
local decrement = self:addChild {
type = 'stepper.left',
}
for index, child in ipairs(self) do
child.type = child.type or 'stepper.item'
self.items[index] = child
self[index] = nil
end
local view = self:addChild {
type = 'text',
align = 'middle center',
margin = 0,
canFocus = false,
}
local increment = self:addChild {
type = 'stepper.right',
}
local decrement = self:addChild { type = 'stepper.left' }
local view = self:addChild()
local increment = self:addChild { type = 'stepper.right' }
self:onReshape(function (event)
decrement.width = decrement:getHeight()
@@ -24,30 +19,30 @@ return function (self)
end)
local function updateValue ()
if not self.options then return end
local option = self.options[self.index]
self:setValue(option.value)
view.text = option.text
local item = self.items[self.index]
self.value = item.value
view[1] = nil
view:addChild(item)
item:reshape()
end
decrement:onPress(function (event)
if not self.options then return end
if not self.items then return end
self.index = self.index - 1
if self.index < 1 then
self.index = #self.options
self.index = #self.items
end
updateValue()
end)
increment:onPress(function (event)
if not self.options then return end
if not self.items then return end
self.index = self.index + 1
if self.index > #self.options then
if self.index > #self.items then
self.index = 1
end
updateValue()
end)
updateValue()
end

View File

@@ -113,7 +113,7 @@ local function deleteRange (self)
if first ~= last then
local left = text:sub(1, first)
text = left .. text:sub(last + 1)
self:setValue(text)
self.value = text
setCaretFromText(self, left)
return true
end
@@ -132,7 +132,7 @@ local function deleteCharacterLeft (self)
local offset = utf8.offset(text, -1, first) or 0
local left = text:sub(1, offset)
text = left .. text:sub(first + 1)
self:setValue(text)
self.value = text
setCaretFromText(self, left)
end
@@ -150,7 +150,7 @@ local function pasteFromClipboard (self)
local first, last = getRange(self)
local left = text:sub(1, first) .. pasted
text = left .. text:sub(last + 1)
self:setValue(text)
self.value = text
setCaretFromText(self, left)
end
@@ -160,12 +160,11 @@ local function insertText (self, newText)
local left = text:sub(1, first) .. newText
self.value = left .. text:sub(last + 1)
self:setValue(self.value)
setCaretFromText(self, left)
end
return function (self)
self:setValue(self.value or self.text or '')
self.value = self.value or self.text or ''
self.text = ''
self.highlight = self.highlight or { 0x80, 0x80, 0x80 }
self.scrollX = 0