mirror of
https://github.com/airstruck/luigi.git
synced 2026-01-10 16:28:23 +00:00
hotkeys use modifiers
This commit is contained in:
@@ -144,7 +144,7 @@
|
|||||||
</div> <!-- id="main" -->
|
</div> <!-- id="main" -->
|
||||||
<div id="about">
|
<div id="about">
|
||||||
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
|
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
|
||||||
<i style="float:right;">Last updated 2015-11-09 17:17:21 </i>
|
<i style="float:right;">Last updated 2015-11-11 18:35:22 </i>
|
||||||
</div> <!-- id="about" -->
|
</div> <!-- id="about" -->
|
||||||
</div> <!-- id="container" -->
|
</div> <!-- id="container" -->
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -70,6 +70,10 @@ and are trapped by the first layout that can handle the event
|
|||||||
</table>
|
</table>
|
||||||
<h2><a href="#Methods">Methods</a></h2>
|
<h2><a href="#Methods">Methods</a></h2>
|
||||||
<table class="function_list">
|
<table class="function_list">
|
||||||
|
<tr>
|
||||||
|
<td class="name" nowrap><a href="#Layout:setMaster">Layout:setMaster (layout)</a></td>
|
||||||
|
<td class="summary">Set the master layout for this layout.</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="name" nowrap><a href="#Layout:setStyle">Layout:setStyle (rules)</a></td>
|
<td class="name" nowrap><a href="#Layout:setStyle">Layout:setStyle (rules)</a></td>
|
||||||
<td class="summary">Set the style from a definition table or function.</td>
|
<td class="summary">Set the style from a definition table or function.</td>
|
||||||
@@ -79,6 +83,14 @@ and are trapped by the first layout that can handle the event
|
|||||||
<td class="summary">Set the theme from a definition table or function.</td>
|
<td class="summary">Set the theme from a definition table or function.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
<td class="name" nowrap><a href="#Layout:getStyle">Layout:getStyle ()</a></td>
|
||||||
|
<td class="summary">Get the style from master layout or this layout.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="name" nowrap><a href="#Layout:getTheme">Layout:getTheme ()</a></td>
|
||||||
|
<td class="summary">Get the theme from master layout or this layout.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
<td class="name" nowrap><a href="#Layout:show">Layout:show ()</a></td>
|
<td class="name" nowrap><a href="#Layout:show">Layout:show ()</a></td>
|
||||||
<td class="summary">Show the layout.</td>
|
<td class="summary">Show the layout.</td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -138,6 +150,37 @@ and are trapped by the first layout that can handle the event
|
|||||||
<h2 class="section-header "><a name="Methods"></a>Methods</h2>
|
<h2 class="section-header "><a name="Methods"></a>Methods</h2>
|
||||||
|
|
||||||
<dl class="function">
|
<dl class="function">
|
||||||
|
<dt>
|
||||||
|
<a name = "Layout:setMaster"></a>
|
||||||
|
<strong>Layout:setMaster (layout)</strong>
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
Set the master layout for this layout. </p>
|
||||||
|
|
||||||
|
<p>This layout's theme and style will be set the same as the master layout, and
|
||||||
|
widgets added to this layout will be indexed and keyboard-accelerated by the
|
||||||
|
master layout instead of this layout.
|
||||||
|
|
||||||
|
|
||||||
|
<h3>Parameters:</h3>
|
||||||
|
<ul>
|
||||||
|
<li><span class="parameter">layout</span>
|
||||||
|
<span class="types"><a class="type" href="../classes/Layout.html#">Layout</a></span>
|
||||||
|
Master layout
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h3>Returns:</h3>
|
||||||
|
<ol>
|
||||||
|
|
||||||
|
<span class="types"><a class="type" href="../classes/Layout.html#">Layout</a></span>
|
||||||
|
Self
|
||||||
|
</ol>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</dd>
|
||||||
<dt>
|
<dt>
|
||||||
<a name = "Layout:setStyle"></a>
|
<a name = "Layout:setStyle"></a>
|
||||||
<strong>Layout:setStyle (rules)</strong>
|
<strong>Layout:setStyle (rules)</strong>
|
||||||
@@ -154,6 +197,12 @@ and are trapped by the first layout that can handle the event
|
|||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
<h3>Returns:</h3>
|
||||||
|
<ol>
|
||||||
|
|
||||||
|
<span class="types"><a class="type" href="../classes/Layout.html#">Layout</a></span>
|
||||||
|
Self
|
||||||
|
</ol>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -179,6 +228,46 @@ and are trapped by the first layout that can handle the event
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</dd>
|
||||||
|
<dt>
|
||||||
|
<a name = "Layout:getStyle"></a>
|
||||||
|
<strong>Layout:getStyle ()</strong>
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
Get the style from master layout or this layout.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<h3>Returns:</h3>
|
||||||
|
<ol>
|
||||||
|
|
||||||
|
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.5">table</a></span>
|
||||||
|
Style table.
|
||||||
|
</ol>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</dd>
|
||||||
|
<dt>
|
||||||
|
<a name = "Layout:getTheme"></a>
|
||||||
|
<strong>Layout:getTheme ()</strong>
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
Get the theme from master layout or this layout.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<h3>Returns:</h3>
|
||||||
|
<ol>
|
||||||
|
|
||||||
|
<span class="types"><a class="type" href="http://www.lua.org/manual/5.1/manual.html#5.5">table</a></span>
|
||||||
|
Theme table.
|
||||||
|
</ol>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</dd>
|
</dd>
|
||||||
<dt>
|
<dt>
|
||||||
<a name = "Layout:show"></a>
|
<a name = "Layout:show"></a>
|
||||||
@@ -295,7 +384,7 @@ found, and focuses that widget.
|
|||||||
</div> <!-- id="main" -->
|
</div> <!-- id="main" -->
|
||||||
<div id="about">
|
<div id="about">
|
||||||
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
|
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
|
||||||
<i style="float:right;">Last updated 2015-11-09 17:17:21 </i>
|
<i style="float:right;">Last updated 2015-11-11 18:35:22 </i>
|
||||||
</div> <!-- id="about" -->
|
</div> <!-- id="about" -->
|
||||||
</div> <!-- id="container" -->
|
</div> <!-- id="container" -->
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -69,10 +69,6 @@
|
|||||||
<td class="summary">Fire an event on this widget and each ancestor.</td>
|
<td class="summary">Fire an event on this widget and each ancestor.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="name" nowrap><a href="#Widget:setValue">Widget:setValue (value)</a></td>
|
|
||||||
<td class="summary">Set widget's value property and bubble a Change event.</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td class="name" nowrap><a href="#Widget:getPreviousSibling">Widget:getPreviousSibling ()</a></td>
|
<td class="name" nowrap><a href="#Widget:getPreviousSibling">Widget:getPreviousSibling ()</a></td>
|
||||||
<td class="summary">Get widget's previous sibling.</td>
|
<td class="summary">Get widget's previous sibling.</td>
|
||||||
</tr>
|
</tr>
|
||||||
@@ -211,33 +207,6 @@ This table is identical to the constructed widget.
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
</dd>
|
|
||||||
<dt>
|
|
||||||
<a name = "Widget:setValue"></a>
|
|
||||||
<strong>Widget:setValue (value)</strong>
|
|
||||||
</dt>
|
|
||||||
<dd>
|
|
||||||
Set widget's value property and bubble a Change event.
|
|
||||||
|
|
||||||
|
|
||||||
<h3>Parameters:</h3>
|
|
||||||
<ul>
|
|
||||||
<li><span class="parameter">value</span>
|
|
||||||
<span class="types"><span class="type">mixed</span></span>
|
|
||||||
The new value of the widget.
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<h3>Returns:</h3>
|
|
||||||
<ol>
|
|
||||||
|
|
||||||
<span class="types"><span class="type">mixed</span></span>
|
|
||||||
The old value of the widget.
|
|
||||||
</ol>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</dd>
|
</dd>
|
||||||
<dt>
|
<dt>
|
||||||
<a name = "Widget:getPreviousSibling"></a>
|
<a name = "Widget:getPreviousSibling"></a>
|
||||||
@@ -611,7 +580,7 @@ on the parent widget.
|
|||||||
</div> <!-- id="main" -->
|
</div> <!-- id="main" -->
|
||||||
<div id="about">
|
<div id="about">
|
||||||
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
|
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
|
||||||
<i style="float:right;">Last updated 2015-11-09 17:17:21 </i>
|
<i style="float:right;">Last updated 2015-11-11 18:35:22 </i>
|
||||||
</div> <!-- id="about" -->
|
</div> <!-- id="about" -->
|
||||||
</div> <!-- id="container" -->
|
</div> <!-- id="container" -->
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -64,7 +64,7 @@
|
|||||||
</div> <!-- id="main" -->
|
</div> <!-- id="main" -->
|
||||||
<div id="about">
|
<div id="about">
|
||||||
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
|
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
|
||||||
<i style="float:right;">Last updated 2015-11-09 17:17:21 </i>
|
<i style="float:right;">Last updated 2015-11-11 18:35:22 </i>
|
||||||
</div> <!-- id="about" -->
|
</div> <!-- id="about" -->
|
||||||
</div> <!-- id="container" -->
|
</div> <!-- id="container" -->
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ local mainForm = { id = 'mainWindow', type = 'panel',
|
|||||||
{ text = 'Licenses', key = 'f3' },
|
{ text = 'Licenses', key = 'f3' },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ type = 'panel', id = 'toolbar', flow = 'x',
|
{ type = 'panel', id = 'toolbar', style = 'toolbar', flow = 'x',
|
||||||
{ type = 'button', id = 'newButton', style = 'toolButton', key = 'z',
|
{ type = 'button', id = 'newButton', style = 'toolButton', key = 'z',
|
||||||
icon = 'icon/32px/Blueprint.png' },
|
icon = 'icon/32px/Blueprint.png' },
|
||||||
{ type = 'button', id = 'loadButton', style = 'toolButton',
|
{ type = 'button', id = 'loadButton', style = 'toolButton',
|
||||||
@@ -84,11 +84,11 @@ local mainForm = { id = 'mainWindow', type = 'panel',
|
|||||||
{ type = 'panel', text = 'A slider', align = 'bottom', height = 24, padding = 4 },
|
{ type = 'panel', text = 'A slider', align = 'bottom', height = 24, padding = 4 },
|
||||||
{ type = 'slider', height = 32, margin = 4, id = 'slidey', value = 0 },
|
{ type = 'slider', height = 32, margin = 4, id = 'slidey', value = 0 },
|
||||||
{ type = 'panel', text = 'A stepper', align = 'bottom', height = 24, padding = 4 },
|
{ type = 'panel', text = 'A stepper', align = 'bottom', height = 24, padding = 4 },
|
||||||
{ type = 'stepper', height = 32, margin = 4, options = {
|
{ type = 'stepper', height = 32, margin = 4,
|
||||||
{ value = 1, text = 'Thing One' },
|
{ value = 1, text = 'Thing One' },
|
||||||
{ value = 2, text = 'Thing Two' },
|
{ value = 2, text = 'Thing Two' },
|
||||||
{ value = 3, text = 'Thing Three' },
|
{ value = 3, text = 'Thing Three' },
|
||||||
} },
|
},
|
||||||
{ type = 'panel', text = 'A progress bar', align = 'bottom', height = 24, padding = 4 },
|
{ type = 'panel', text = 'A progress bar', align = 'bottom', height = 24, padding = 4 },
|
||||||
{ type = 'progress', height = 32, margin = 4, id = 'progressBar', },
|
{ type = 'progress', height = 32, margin = 4, id = 'progressBar', },
|
||||||
},
|
},
|
||||||
@@ -114,7 +114,7 @@ layout.leftSideBox:addChild {
|
|||||||
}
|
}
|
||||||
|
|
||||||
layout.slidey:onChange(function (event)
|
layout.slidey:onChange(function (event)
|
||||||
layout.progressBar:setValue(event.value)
|
layout.progressBar.value = event.value
|
||||||
end)
|
end)
|
||||||
|
|
||||||
layout:onMove(function (event)
|
layout:onMove(function (event)
|
||||||
|
|||||||
@@ -20,6 +20,14 @@ function Input:handleDisplay (layout)
|
|||||||
Event.Display:emit(layout)
|
Event.Display:emit(layout)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Input:getModifierFlags ()
|
||||||
|
local alt = love.keyboard.isDown('lalt', 'ralt') and 1 or 0
|
||||||
|
local ctrl = love.keyboard.isDown('lctrl', 'rctrl') and 2 or 0
|
||||||
|
local shift = love.keyboard.isDown('lshift', 'rshift') and 4 or 0
|
||||||
|
|
||||||
|
return alt + ctrl + shift
|
||||||
|
end
|
||||||
|
|
||||||
function Input:handleKeyPress (layout, key, x, y)
|
function Input:handleKeyPress (layout, key, x, y)
|
||||||
local widget = layout.focusedWidget or layout:getWidgetAt(x, y)
|
local widget = layout.focusedWidget or layout:getWidgetAt(x, y)
|
||||||
local hit = true
|
local hit = true
|
||||||
@@ -29,7 +37,10 @@ function Input:handleKeyPress (layout, key, x, y)
|
|||||||
end
|
end
|
||||||
local result = widget:bubbleEvent('KeyPress', {
|
local result = widget:bubbleEvent('KeyPress', {
|
||||||
hit = hit,
|
hit = hit,
|
||||||
key = key, x = x, y = y
|
key = key,
|
||||||
|
modifierFlags = self:getModifierFlags(),
|
||||||
|
x = x,
|
||||||
|
y = y
|
||||||
})
|
})
|
||||||
if result ~= nil then return result end
|
if result ~= nil then return result end
|
||||||
return hit
|
return hit
|
||||||
@@ -44,7 +55,10 @@ function Input:handleKeyRelease (layout, key, x, y)
|
|||||||
end
|
end
|
||||||
local result = widget:bubbleEvent('KeyRelease', {
|
local result = widget:bubbleEvent('KeyRelease', {
|
||||||
hit = hit,
|
hit = hit,
|
||||||
key = key, x = x, y = y
|
key = key,
|
||||||
|
modifierFlags = self:getModifierFlags(),
|
||||||
|
x = x,
|
||||||
|
y = y
|
||||||
})
|
})
|
||||||
if result ~= nil then return result end
|
if result ~= nil then return result end
|
||||||
return hit
|
return hit
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ function Layout:setStyle (rules)
|
|||||||
if type(rules) == 'function' then
|
if type(rules) == 'function' then
|
||||||
rules = rules()
|
rules = rules()
|
||||||
end
|
end
|
||||||
self.style = Style(rules or {}, { 'id', 'style' })
|
self.style = Style(rules or {}, { 'style' })
|
||||||
|
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
@@ -228,6 +228,7 @@ function Layout:getWidgetAt (x, y, root)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Internal, called from Widget:new
|
-- Internal, called from Widget:new
|
||||||
|
--[[
|
||||||
function Layout:addWidget (widget)
|
function Layout:addWidget (widget)
|
||||||
if widget.id then
|
if widget.id then
|
||||||
self[widget.id] = widget
|
self[widget.id] = widget
|
||||||
@@ -236,14 +237,19 @@ function Layout:addWidget (widget)
|
|||||||
self.accelerators[widget.key] = widget
|
self.accelerators[widget.key] = widget
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
]]
|
||||||
|
|
||||||
-- Add handlers for keyboard accelerators and tab focus
|
-- Add handlers for keyboard accelerators and tab focus
|
||||||
function Layout:addDefaultHandlers ()
|
function Layout:addDefaultHandlers ()
|
||||||
self.accelerators = {}
|
self.accelerators = {}
|
||||||
|
|
||||||
|
for i = 0, 8 do
|
||||||
|
self.accelerators[i] = {}
|
||||||
|
end
|
||||||
|
|
||||||
self:onKeyPress(function (event)
|
self:onKeyPress(function (event)
|
||||||
|
|
||||||
-- tab / shift-tab cycles focused widget
|
-- tab/shift-tab cycles focused widget
|
||||||
if event.key == 'tab' then
|
if event.key == 'tab' then
|
||||||
if love.keyboard.isDown('lshift', 'rshift') then
|
if love.keyboard.isDown('lshift', 'rshift') then
|
||||||
self:focusPreviousWidget()
|
self:focusPreviousWidget()
|
||||||
@@ -253,7 +259,7 @@ function Layout:addDefaultHandlers ()
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- space / enter presses focused widget
|
-- space/enter presses focused widget
|
||||||
local widget = self.focusedWidget
|
local widget = self.focusedWidget
|
||||||
if widget and event.key == 'space' or event.key == ' '
|
if widget and event.key == 'space' or event.key == ' '
|
||||||
or event.key == 'return' then
|
or event.key == 'return' then
|
||||||
@@ -263,7 +269,8 @@ function Layout:addDefaultHandlers ()
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- accelerators
|
-- accelerators
|
||||||
local acceleratedWidget = self.accelerators[event.key]
|
local entry = self.accelerators[event.modifierFlags]
|
||||||
|
local acceleratedWidget = entry and entry[event.key]
|
||||||
if acceleratedWidget then
|
if acceleratedWidget then
|
||||||
acceleratedWidget.hovered = true
|
acceleratedWidget.hovered = true
|
||||||
self.input:handlePressStart(self, event.key, event.x, event.y,
|
self.input:handlePressStart(self, event.key, event.x, event.y,
|
||||||
@@ -283,7 +290,8 @@ function Layout:addDefaultHandlers ()
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- accelerators
|
-- accelerators
|
||||||
local acceleratedWidget = self.accelerators[event.key]
|
local entry = self.accelerators[event.modifierFlags]
|
||||||
|
local acceleratedWidget = entry and entry[event.key]
|
||||||
|
|
||||||
if acceleratedWidget then
|
if acceleratedWidget then
|
||||||
acceleratedWidget.hovered = false
|
acceleratedWidget.hovered = false
|
||||||
|
|||||||
@@ -35,8 +35,6 @@ return function (config)
|
|||||||
type = 'button',
|
type = 'button',
|
||||||
icon = RESOURCE .. 'triangle_right.png',
|
icon = RESOURCE .. 'triangle_right.png',
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
menu = {
|
menu = {
|
||||||
height = 24,
|
height = 24,
|
||||||
},
|
},
|
||||||
@@ -85,6 +83,10 @@ return function (config)
|
|||||||
slider_hovered = {
|
slider_hovered = {
|
||||||
},
|
},
|
||||||
stepper = {
|
stepper = {
|
||||||
|
slices = RESOURCE .. 'button_pressed.png',
|
||||||
|
},
|
||||||
|
['stepper.item'] = {
|
||||||
|
align = 'center middle',
|
||||||
},
|
},
|
||||||
text = {
|
text = {
|
||||||
align = 'left middle',
|
align = 'left middle',
|
||||||
|
|||||||
@@ -71,9 +71,50 @@ local function metaNewIndex (self, property, value)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if property == 'value' then
|
||||||
|
local oldValue = self.value
|
||||||
|
self.shadowProperties[property] = value
|
||||||
|
self:bubbleEvent('Change', {
|
||||||
|
value = value,
|
||||||
|
oldValue = oldValue,
|
||||||
|
})
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if property == 'key' then
|
||||||
|
self.shadowProperties[property] = value
|
||||||
|
|
||||||
|
if not value then return end
|
||||||
|
|
||||||
|
local mainKey = (value):match '[^%-]+$'
|
||||||
|
local alt = (value):match 'alt%-' and 1 or 0
|
||||||
|
local ctrl = (value):match 'ctrl%-' and 2 or 0
|
||||||
|
local shift = (value):match 'shift%-' and 4 or 0
|
||||||
|
local modifierFlags = alt + ctrl + shift
|
||||||
|
|
||||||
|
local layout = self.layout.master or self.layout
|
||||||
|
|
||||||
|
layout.accelerators[modifierFlags][mainKey] = self
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if property == 'id' then
|
||||||
|
self.shadowProperties[property] = value
|
||||||
|
|
||||||
|
if not value then return end
|
||||||
|
|
||||||
|
local layout = self.layout.master or self.layout
|
||||||
|
|
||||||
|
layout[value] = self
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
rawset(self, property, value)
|
rawset(self, property, value)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local shadowKeys = {
|
||||||
|
'font', 'fontSize', 'textColor', 'width', 'height', 'value', 'key', 'id'
|
||||||
|
}
|
||||||
--[[--
|
--[[--
|
||||||
Widget pseudo-constructor.
|
Widget pseudo-constructor.
|
||||||
|
|
||||||
@@ -98,19 +139,16 @@ local function metaCall (Widget, layout, self)
|
|||||||
|
|
||||||
setmetatable(self, { __index = metaIndex, __newindex = metaNewIndex })
|
setmetatable(self, { __index = metaIndex, __newindex = metaNewIndex })
|
||||||
|
|
||||||
for _, property
|
for _, property in ipairs(shadowKeys) do
|
||||||
in ipairs { 'font', 'fontSize', 'textColor', 'width', 'height' } do
|
|
||||||
local value = rawget(self, property)
|
local value = rawget(self, property)
|
||||||
rawset(self, property, nil)
|
rawset(self, property, nil)
|
||||||
if value ~= nil then
|
self[property] = value
|
||||||
self[property] = value
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
self.type = self.type or 'generic'
|
self.type = self.type or 'generic'
|
||||||
self.fontData = Font(self.font, self.fontSize, self.textColor)
|
self.fontData = Font(self.font, self.fontSize, self.textColor)
|
||||||
|
|
||||||
layout:addWidget(self)
|
-- layout:addWidget(self)
|
||||||
|
|
||||||
local decorate = Widget.typeDecorators[self.type]
|
local decorate = Widget.typeDecorators[self.type]
|
||||||
|
|
||||||
@@ -151,27 +189,6 @@ function Widget:bubbleEvent (eventName, data)
|
|||||||
return event:emit(self.layout, data)
|
return event:emit(self.layout, data)
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[--
|
|
||||||
Set widget's value property and bubble a Change event.
|
|
||||||
|
|
||||||
@tparam mixed value
|
|
||||||
The new value of the widget.
|
|
||||||
|
|
||||||
@treturn mixed
|
|
||||||
The old value of the widget.
|
|
||||||
--]]--
|
|
||||||
function Widget:setValue (value)
|
|
||||||
local oldValue = self.value
|
|
||||||
self.value = value
|
|
||||||
|
|
||||||
self:bubbleEvent('Change', {
|
|
||||||
value = value,
|
|
||||||
oldValue = oldValue,
|
|
||||||
})
|
|
||||||
|
|
||||||
return oldValue
|
|
||||||
end
|
|
||||||
|
|
||||||
--[[--
|
--[[--
|
||||||
Get widget's previous sibling.
|
Get widget's previous sibling.
|
||||||
|
|
||||||
|
|||||||
@@ -132,15 +132,14 @@ local function initialize (self)
|
|||||||
key = ' '
|
key = ' '
|
||||||
edgeType = 'menu.expander'
|
edgeType = 'menu.expander'
|
||||||
else
|
else
|
||||||
key = key:gsub('%f[%w].', string.upper)
|
key = key:gsub('%f[%w].', string.upper) -- :gsub('-', '+')
|
||||||
end
|
end
|
||||||
self.height = self.fontData:getLineHeight() + pad * 2
|
self.height = self.fontData:getLineHeight() + pad * 2
|
||||||
self.flow = 'x'
|
self.flow = 'x'
|
||||||
self:addChild({ icon = icon, width = self.height })
|
self:addChild { icon = icon, width = self.height }
|
||||||
self:addChild({ text = text, width = textWidth })
|
self:addChild { text = text, width = textWidth }
|
||||||
self:addChild({ text = key, align = 'middle right',
|
self:addChild { text = key, align = 'middle right',
|
||||||
minwidth = self.height,
|
minwidth = self.height, textColor = keyColor, type = edgeType }
|
||||||
textColor = keyColor, type = edgeType })
|
|
||||||
|
|
||||||
self.icon = nil
|
self.icon = nil
|
||||||
self.text = nil
|
self.text = nil
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ return function (self)
|
|||||||
return value < 0 and 0 or value > 1 and 1 or value
|
return value < 0 and 0 or value > 1 and 1 or value
|
||||||
end
|
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.step = self.step or 0.01
|
||||||
self.flow = 'x' -- TODO: support vertical slider
|
self.flow = 'x' -- TODO: support vertical slider
|
||||||
|
|
||||||
@@ -28,9 +28,9 @@ return function (self)
|
|||||||
thumb:onKeyPress(function (event)
|
thumb:onKeyPress(function (event)
|
||||||
local key = event.key
|
local key = event.key
|
||||||
if key == 'left' or key == 'down' then
|
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
|
elseif event.key == 'right' or key == 'up' then
|
||||||
self:setValue(clamp(self.value + self.step))
|
self.value = clamp(self.value + self.step)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ return function (self)
|
|||||||
local x1, y1, x2, y2 = self:getRectangle(true, true)
|
local x1, y1, x2, y2 = self:getRectangle(true, true)
|
||||||
local halfThumb = thumb:getWidth() / 2
|
local halfThumb = thumb:getWidth() / 2
|
||||||
x1, x2 = x1 + halfThumb, x2 - halfThumb
|
x1, x2 = x1 + halfThumb, x2 - halfThumb
|
||||||
self:setValue(clamp((event.x - x1) / (x2 - x1)))
|
self.value = clamp((event.x - x1) / (x2 - x1))
|
||||||
thumb:focus()
|
thumb:focus()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,22 +1,17 @@
|
|||||||
return function (self)
|
return function (self)
|
||||||
|
self.items = {}
|
||||||
self.index = 1
|
self.index = 1
|
||||||
self.flow = 'x' -- TODO: support vertical stepper
|
self.flow = 'x' -- TODO: support vertical stepper
|
||||||
|
|
||||||
local decrement = self:addChild {
|
for index, child in ipairs(self) do
|
||||||
type = 'stepper.left',
|
child.type = child.type or 'stepper.item'
|
||||||
}
|
self.items[index] = child
|
||||||
|
self[index] = nil
|
||||||
|
end
|
||||||
|
|
||||||
local view = self:addChild {
|
local decrement = self:addChild { type = 'stepper.left' }
|
||||||
type = 'text',
|
local view = self:addChild()
|
||||||
align = 'middle center',
|
local increment = self:addChild { type = 'stepper.right' }
|
||||||
margin = 0,
|
|
||||||
canFocus = false,
|
|
||||||
}
|
|
||||||
|
|
||||||
local increment = self:addChild {
|
|
||||||
type = 'stepper.right',
|
|
||||||
}
|
|
||||||
|
|
||||||
self:onReshape(function (event)
|
self:onReshape(function (event)
|
||||||
decrement.width = decrement:getHeight()
|
decrement.width = decrement:getHeight()
|
||||||
@@ -24,30 +19,30 @@ return function (self)
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
local function updateValue ()
|
local function updateValue ()
|
||||||
if not self.options then return end
|
local item = self.items[self.index]
|
||||||
local option = self.options[self.index]
|
self.value = item.value
|
||||||
self:setValue(option.value)
|
view[1] = nil
|
||||||
view.text = option.text
|
view:addChild(item)
|
||||||
|
item:reshape()
|
||||||
end
|
end
|
||||||
|
|
||||||
decrement:onPress(function (event)
|
decrement:onPress(function (event)
|
||||||
if not self.options then return end
|
if not self.items then return end
|
||||||
self.index = self.index - 1
|
self.index = self.index - 1
|
||||||
if self.index < 1 then
|
if self.index < 1 then
|
||||||
self.index = #self.options
|
self.index = #self.items
|
||||||
end
|
end
|
||||||
updateValue()
|
updateValue()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
increment:onPress(function (event)
|
increment:onPress(function (event)
|
||||||
if not self.options then return end
|
if not self.items then return end
|
||||||
self.index = self.index + 1
|
self.index = self.index + 1
|
||||||
if self.index > #self.options then
|
if self.index > #self.items then
|
||||||
self.index = 1
|
self.index = 1
|
||||||
end
|
end
|
||||||
updateValue()
|
updateValue()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
updateValue()
|
updateValue()
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ local function deleteRange (self)
|
|||||||
if first ~= last then
|
if first ~= last then
|
||||||
local left = text:sub(1, first)
|
local left = text:sub(1, first)
|
||||||
text = left .. text:sub(last + 1)
|
text = left .. text:sub(last + 1)
|
||||||
self:setValue(text)
|
self.value = text
|
||||||
setCaretFromText(self, left)
|
setCaretFromText(self, left)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@@ -132,7 +132,7 @@ local function deleteCharacterLeft (self)
|
|||||||
local offset = utf8.offset(text, -1, first) or 0
|
local offset = utf8.offset(text, -1, first) or 0
|
||||||
local left = text:sub(1, offset)
|
local left = text:sub(1, offset)
|
||||||
text = left .. text:sub(first + 1)
|
text = left .. text:sub(first + 1)
|
||||||
self:setValue(text)
|
self.value = text
|
||||||
setCaretFromText(self, left)
|
setCaretFromText(self, left)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -150,7 +150,7 @@ local function pasteFromClipboard (self)
|
|||||||
local first, last = getRange(self)
|
local first, last = getRange(self)
|
||||||
local left = text:sub(1, first) .. pasted
|
local left = text:sub(1, first) .. pasted
|
||||||
text = left .. text:sub(last + 1)
|
text = left .. text:sub(last + 1)
|
||||||
self:setValue(text)
|
self.value = text
|
||||||
setCaretFromText(self, left)
|
setCaretFromText(self, left)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -160,12 +160,11 @@ local function insertText (self, newText)
|
|||||||
local left = text:sub(1, first) .. newText
|
local left = text:sub(1, first) .. newText
|
||||||
|
|
||||||
self.value = left .. text:sub(last + 1)
|
self.value = left .. text:sub(last + 1)
|
||||||
self:setValue(self.value)
|
|
||||||
setCaretFromText(self, left)
|
setCaretFromText(self, left)
|
||||||
end
|
end
|
||||||
|
|
||||||
return function (self)
|
return function (self)
|
||||||
self:setValue(self.value or self.text or '')
|
self.value = self.value or self.text or ''
|
||||||
self.text = ''
|
self.text = ''
|
||||||
self.highlight = self.highlight or { 0x80, 0x80, 0x80 }
|
self.highlight = self.highlight or { 0x80, 0x80, 0x80 }
|
||||||
self.scrollX = 0
|
self.scrollX = 0
|
||||||
|
|||||||
Reference in New Issue
Block a user