dropdown open animation
This commit is contained in:
parent
ed5f93104d
commit
34fdd83ab3
1 changed files with 15 additions and 6 deletions
21
dropdown.lua
21
dropdown.lua
|
@ -48,6 +48,7 @@ local function insertDropdown(tab, f)
|
||||||
dropdownId = dropdownId + 1
|
dropdownId = dropdownId + 1
|
||||||
f.selected = (self.kget(f.name) or dropdownValueCache[f.name] or {selected = 1}).selected
|
f.selected = (self.kget(f.name) or dropdownValueCache[f.name] or {selected = 1}).selected
|
||||||
f.selected = (f.selected - 1) % #f.options + 1
|
f.selected = (f.selected - 1) % #f.options + 1
|
||||||
|
f.open = (self.kget(f.name) or {open = 0}).open
|
||||||
return table.insert(tab, f)
|
return table.insert(tab, f)
|
||||||
end
|
end
|
||||||
function self.createDropdowns()
|
function self.createDropdowns()
|
||||||
|
@ -110,6 +111,14 @@ function self.update(dt)
|
||||||
dropdownScroll = math.min(dropdownScroll, 0)
|
dropdownScroll = math.min(dropdownScroll, 0)
|
||||||
dropdownScrollE = mix(dropdownScrollE, dropdownScroll, dt * 10)
|
dropdownScrollE = mix(dropdownScrollE, dropdownScroll, dt * 10)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
for i, v in ipairs(dropdowns) do
|
||||||
|
if i == self.openDropdown then
|
||||||
|
v.open = mix(v.open, 1, dt * 14)
|
||||||
|
else
|
||||||
|
v.open = mix(v.open, 0, dt * 20)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function self.render()
|
function self.render()
|
||||||
|
@ -130,18 +139,18 @@ function self.render()
|
||||||
-- love.graphics.rectangle('line', x + w - h, y, h, h)
|
-- love.graphics.rectangle('line', x + w - h, y, h, h)
|
||||||
love.graphics.polygon('line', x + w - h/2 + 0.3 * h, y + h/2 - 0.3 * h, x + w - h/2 - 0.3 * h, y + h/2 - 0.3 * h, x + w - h/2, y + h/2 + 0.3 * h)
|
love.graphics.polygon('line', x + w - h/2 + 0.3 * h, y + h/2 - 0.3 * h, x + w - h/2 - 0.3 * h, y + h/2 - 0.3 * h, x + w - h/2, y + h/2 + 0.3 * h)
|
||||||
|
|
||||||
if self.openDropdown == i then
|
if self.openDropdown == i or v.open > 0.01 then
|
||||||
for i,o in ipairs(v.options) do
|
for i,o in ipairs(v.options) do
|
||||||
local x, y, w, h = x, y + i * h, w, h
|
local x, y, w, h = x, y + ((i - 1) * v.open + 1) * h, w, h * v.open
|
||||||
|
|
||||||
y = y + dropdownScrollE * h
|
y = y + dropdownScrollE * h * v.open
|
||||||
local gi = y / h
|
local gi = y / h
|
||||||
if gi > (maxDropdown + 1) or gi < 1 then
|
if gi > (maxDropdown + 1) or gi < 1 then
|
||||||
goto continue
|
goto continue
|
||||||
end
|
end
|
||||||
|
|
||||||
-- help
|
-- help
|
||||||
local a = (1 - math.min(math.max((1 - (maxDropdown - gi)) * (1 - (math.abs(dropdownScrollE) / (#v.options - maxDropdown + 1))), 0), 1)) * math.max(math.min(gi - 1, 1), 0)
|
local a = (1 - math.min(math.max((1 - (maxDropdown - gi)) * (1 - (math.abs(dropdownScrollE) / (#v.options - maxDropdown + 1))), 0), 1)) * math.max(math.min(gi - 1, 1), 0) * v.open
|
||||||
|
|
||||||
love.graphics.setColor(0.06, 0.06, 0.12, 0.3 * a)
|
love.graphics.setColor(0.06, 0.06, 0.12, 0.3 * a)
|
||||||
if mx > x and mx < x + w and my > y and my < y + h then
|
if mx > x and mx < x + w and my > y and my < y + h then
|
||||||
|
@ -165,8 +174,8 @@ function self.render()
|
||||||
local scroll = math.abs(dropdownScrollE) / (#v.options - maxDropdown + 1)
|
local scroll = math.abs(dropdownScrollE) / (#v.options - maxDropdown + 1)
|
||||||
local size = margin
|
local size = margin
|
||||||
|
|
||||||
love.graphics.setColor(1, 1, 1, 0.9)
|
love.graphics.setColor(1, 1, 1, 0.9 * v.open)
|
||||||
love.graphics.rectangle('fill', x + w - size, y + h + scroll * (1 - displayed) * (maxDropdown - 1) * h, size, displayed * (maxDropdown - 1) * h)
|
love.graphics.rectangle('fill', x + w - size, y + h + scroll * (1 - displayed) * (maxDropdown - 1) * h * v.open, size, displayed * (maxDropdown - 1) * h * v.open)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue