diff options
author | Matthias Richter <vrld@vrld.org> | 2013-01-23 13:18:58 +0100 |
---|---|---|
committer | Matthias Richter <vrld@vrld.org> | 2013-01-23 13:18:58 +0100 |
commit | e5c9e7e29fd34271522a4ed7dfc6b8b8ee6670cd (patch) | |
tree | d508a22e72112d6563a25689f15df1b42da3fae7 | |
parent | f799f48164775ce79a09fc5edf2f22e4b324c57c (diff) | |
download | Quickie-e5c9e7e29fd34271522a4ed7dfc6b8b8ee6670cd.tar.gz Quickie-e5c9e7e29fd34271522a4ed7dfc6b8b8ee6670cd.tar.bz2 Quickie-e5c9e7e29fd34271522a4ed7dfc6b8b8ee6670cd.tar.xz Quickie-e5c9e7e29fd34271522a4ed7dfc6b8b8ee6670cd.zip |
Allow setting custom widget ids
-rw-r--r-- | button.lua | 2 | ||||
-rw-r--r-- | checkbox.lua | 2 | ||||
-rw-r--r-- | core.lua | 9 | ||||
-rw-r--r-- | input.lua | 2 | ||||
-rw-r--r-- | label.lua | 2 | ||||
-rw-r--r-- | slider.lua | 2 | ||||
-rw-r--r-- | slider2d.lua | 2 |
7 files changed, 13 insertions, 8 deletions
@@ -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) @@ -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 -- @@ -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) @@ -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 @@ -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) |