Allow setting custom widget ids

This commit is contained in:
Matthias Richter 2013-01-23 13:18:58 +01:00
parent f799f48164
commit e5c9e7e29f
7 changed files with 13 additions and 8 deletions

View file

@ -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.

View file

@ -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)

View file

@ -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
--

View file

@ -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)

View file

@ -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

View file

@ -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)

View file

@ -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)