aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Richter <vrld@vrld.org>2013-01-23 13:18:58 +0100
committerMatthias Richter <vrld@vrld.org>2013-01-23 13:18:58 +0100
commite5c9e7e29fd34271522a4ed7dfc6b8b8ee6670cd (patch)
treed508a22e72112d6563a25689f15df1b42da3fae7
parentf799f48164775ce79a09fc5edf2f22e4b324c57c (diff)
downloadQuickie-e5c9e7e29fd34271522a4ed7dfc6b8b8ee6670cd.tar.gz
Quickie-e5c9e7e29fd34271522a4ed7dfc6b8b8ee6670cd.tar.bz2
Quickie-e5c9e7e29fd34271522a4ed7dfc6b8b8ee6670cd.tar.xz
Quickie-e5c9e7e29fd34271522a4ed7dfc6b8b8ee6670cd.zip
Allow setting custom widget ids
-rw-r--r--button.lua2
-rw-r--r--checkbox.lua2
-rw-r--r--core.lua9
-rw-r--r--input.lua2
-rw-r--r--label.lua2
-rw-r--r--slider.lua2
-rw-r--r--slider2d.lua2
7 files changed, 13 insertions, 8 deletions
diff --git a/button.lua b/button.lua
index fd0cff4..2e2b310 100644
--- a/button.lua
+++ b/button.lua
@@ -48,7 +48,7 @@ return function(w)
end
-- Generate unique identifier for gui state update and querying.
- local id = core.generateID()
+ local id = w.id or core.generateID()
-- group.getRect determines the position and size of the widget according
-- to the currently active group. Both arguments may be omitted.
diff --git a/checkbox.lua b/checkbox.lua
index 14a92a5..5137bb0 100644
--- a/checkbox.lua
+++ b/checkbox.lua
@@ -48,7 +48,7 @@ return function(w)
w.size[1] = w.size[1] + bw + 4
end
- local id = core.generateID()
+ local id = w.id or core.generateID()
local pos, size = group.getRect(w.pos, w.size)
mouse.updateWidget(id, pos, size, w.widgetHit)
diff --git a/core.lua b/core.lua
index 67602ac..533ab96 100644
--- a/core.lua
+++ b/core.lua
@@ -65,10 +65,15 @@ end
--
-- Widget ID
--
-local maxid = 0
+local maxid, uids = 0, {}
+setmetatable(uids, {__index = function(t, i)
+ t[i] = {}
+ return t[i]
+end})
+
local function generateID()
maxid = maxid + 1
- return maxid
+ return uids[maxid]
end
--
diff --git a/input.lua b/input.lua
index 64f2ced..87d980e 100644
--- a/input.lua
+++ b/input.lua
@@ -36,7 +36,7 @@ return function(w)
w.info.text = w.info.text or ""
w.info.cursor = math.min(w.info.cursor or w.info.text:len(), w.info.text:len())
- local id = core.generateID()
+ local id = w.id or core.generateID()
local pos, size = group.getRect(w.pos, w.size)
mouse.updateWidget(id, pos, size, w.widgetHit)
keyboard.makeCyclable(id)
diff --git a/label.lua b/label.lua
index c84d08e..345516c 100644
--- a/label.lua
+++ b/label.lua
@@ -46,7 +46,7 @@ return function(w)
end
end
- local id = core.generateID()
+ local id = w.id or core.generateID()
local pos, size = group.getRect(w.pos, w.size)
if keyboard.hasFocus(id) then
diff --git a/slider.lua b/slider.lua
index 4561d4a..1a0ef77 100644
--- a/slider.lua
+++ b/slider.lua
@@ -38,7 +38,7 @@ return function(w)
w.info.step = w.info.step or (w.info.max - w.info.min) / 20
local fraction = (w.info.value - w.info.min) / (w.info.max - w.info.min)
- local id = core.generateID()
+ local id = w.id or core.generateID()
local pos, size = group.getRect(w.pos, w.info.size)
mouse.updateWidget(id, pos, size, w.widgetHit)
diff --git a/slider2d.lua b/slider2d.lua
index 19abaf1..0ebfeb8 100644
--- a/slider2d.lua
+++ b/slider2d.lua
@@ -51,7 +51,7 @@ return function(w)
(w.info.value[2] - w.info.min[2]) / (w.info.max[2] - w.info.min[2]),
}
- local id = core.generateID()
+ local id = w.id or core.generateID()
local pos, size = group.getRect(w.pos, w.size)
mouse.updateWidget(id, pos, size, w.widgetHit)