Fix #17: Support multiple instances
This commit is contained in:
parent
f77ab8e5e8
commit
aca8a297bb
14 changed files with 385 additions and 244 deletions
23
slider.lua
23
slider.lua
|
@ -1,9 +1,8 @@
|
|||
-- This file is part of SUIT, copyright (c) 2016 Matthias Richter
|
||||
|
||||
local BASE = (...):match('(.-)[^%.]+$')
|
||||
local core = require(BASE .. 'core')
|
||||
|
||||
return function(info, ...)
|
||||
return function(core, info, ...)
|
||||
local opt, x,y,w,h = core.getOptionsAndSize(...)
|
||||
|
||||
opt.id = opt.id or info
|
||||
|
@ -14,11 +13,11 @@ return function(info, ...)
|
|||
local fraction = (info.value - info.min) / (info.max - info.min)
|
||||
local value_changed = false
|
||||
|
||||
core.registerHitbox(opt.id, x,y,w,h)
|
||||
opt.state = core:registerHitbox(opt.id, x,y,w,h)
|
||||
|
||||
if core.isActive(opt.id) then
|
||||
if core:isActive(opt.id) then
|
||||
-- mouse update
|
||||
local mx,my = core.getMousePosition()
|
||||
local mx,my = core:getMousePosition()
|
||||
if opt.vertical then
|
||||
fraction = math.min(1, math.max(0, (y+h - my) / h))
|
||||
else
|
||||
|
@ -33,23 +32,23 @@ return function(info, ...)
|
|||
-- keyboard update
|
||||
local key_up = opt.vertical and 'up' or 'right'
|
||||
local key_down = opt.vertical and 'down' or 'left'
|
||||
if core.getPressedKey() == key_up then
|
||||
if core:getPressedKey() == key_up then
|
||||
info.value = math.min(info.max, info.value + info.step)
|
||||
value_changed = true
|
||||
elseif core.getPressedKey() == key_down then
|
||||
elseif core:getPressedKey() == key_down then
|
||||
info.value = math.max(info.min, info.value - info.step)
|
||||
value_changed = true
|
||||
end
|
||||
end
|
||||
|
||||
core.registerDraw(core.theme.Slider, fraction, opt, x,y,w,h)
|
||||
core:registerDraw(core.theme.Slider, fraction, opt, x,y,w,h)
|
||||
|
||||
return {
|
||||
id = opt.id,
|
||||
hit = core.mouseReleasedOn(opt.id),
|
||||
hit = core:mouseReleasedOn(opt.id),
|
||||
changed = value_changed,
|
||||
hovered = core.isHot(opt.id),
|
||||
entered = core.isHot(opt.id) and not core.wasHot(opt.id),
|
||||
left = not core.isHot(opt.id) and core.wasHot(opt.id)
|
||||
hovered = core:isHovered(opt.id),
|
||||
entered = core:isHovered(opt.id) and not core:wasHovered(opt.id),
|
||||
left = not core:isHovered(opt.id) and core:wasHovered(opt.id)
|
||||
}
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue