Allow setting custom widget ids
This commit is contained in:
parent
f799f48164
commit
e5c9e7e29f
7 changed files with 13 additions and 8 deletions
|
@ -48,7 +48,7 @@ return function(w)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Generate unique identifier for gui state update and querying.
|
-- 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
|
-- group.getRect determines the position and size of the widget according
|
||||||
-- to the currently active group. Both arguments may be omitted.
|
-- to the currently active group. Both arguments may be omitted.
|
||||||
|
|
|
@ -48,7 +48,7 @@ return function(w)
|
||||||
w.size[1] = w.size[1] + bw + 4
|
w.size[1] = w.size[1] + bw + 4
|
||||||
end
|
end
|
||||||
|
|
||||||
local id = core.generateID()
|
local id = w.id or core.generateID()
|
||||||
local pos, size = group.getRect(w.pos, w.size)
|
local pos, size = group.getRect(w.pos, w.size)
|
||||||
|
|
||||||
mouse.updateWidget(id, pos, size, w.widgetHit)
|
mouse.updateWidget(id, pos, size, w.widgetHit)
|
||||||
|
|
9
core.lua
9
core.lua
|
@ -65,10 +65,15 @@ end
|
||||||
--
|
--
|
||||||
-- Widget ID
|
-- Widget ID
|
||||||
--
|
--
|
||||||
local maxid = 0
|
local maxid, uids = 0, {}
|
||||||
|
setmetatable(uids, {__index = function(t, i)
|
||||||
|
t[i] = {}
|
||||||
|
return t[i]
|
||||||
|
end})
|
||||||
|
|
||||||
local function generateID()
|
local function generateID()
|
||||||
maxid = maxid + 1
|
maxid = maxid + 1
|
||||||
return maxid
|
return uids[maxid]
|
||||||
end
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
|
|
|
@ -36,7 +36,7 @@ return function(w)
|
||||||
w.info.text = w.info.text or ""
|
w.info.text = w.info.text or ""
|
||||||
w.info.cursor = math.min(w.info.cursor or w.info.text:len(), w.info.text:len())
|
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)
|
local pos, size = group.getRect(w.pos, w.size)
|
||||||
mouse.updateWidget(id, pos, size, w.widgetHit)
|
mouse.updateWidget(id, pos, size, w.widgetHit)
|
||||||
keyboard.makeCyclable(id)
|
keyboard.makeCyclable(id)
|
||||||
|
|
|
@ -46,7 +46,7 @@ return function(w)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local id = core.generateID()
|
local id = w.id or core.generateID()
|
||||||
local pos, size = group.getRect(w.pos, w.size)
|
local pos, size = group.getRect(w.pos, w.size)
|
||||||
|
|
||||||
if keyboard.hasFocus(id) then
|
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
|
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 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)
|
local pos, size = group.getRect(w.pos, w.info.size)
|
||||||
|
|
||||||
mouse.updateWidget(id, pos, size, w.widgetHit)
|
mouse.updateWidget(id, pos, size, w.widgetHit)
|
||||||
|
|
|
@ -51,7 +51,7 @@ return function(w)
|
||||||
(w.info.value[2] - w.info.min[2]) / (w.info.max[2] - w.info.min[2]),
|
(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)
|
local pos, size = group.getRect(w.pos, w.size)
|
||||||
|
|
||||||
mouse.updateWidget(id, pos, size, w.widgetHit)
|
mouse.updateWidget(id, pos, size, w.widgetHit)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue