reformat some code in Zframework/widget.lua
This commit is contained in:
@@ -776,114 +776,85 @@ function WIDGET.keyPressed(key)
|
|||||||
elseif kb.isDown("lshift","lalt","lctrl")and key=="left"or key=="right"then
|
elseif kb.isDown("lshift","lalt","lctrl")and key=="left"or key=="right"then
|
||||||
--When hold [↑], control slider with left/right
|
--When hold [↑], control slider with left/right
|
||||||
local W=WIDGET.sel
|
local W=WIDGET.sel
|
||||||
if W then
|
if not W then return end
|
||||||
if W.type=="slider"then
|
local isLeft = key == "left"
|
||||||
local p=W.disp()
|
if W.type=="slider"then
|
||||||
local u=(W.smooth and .01 or 1)
|
local p=W.disp()
|
||||||
local P=key=="left"and max(p-u,0)or min(p+u,W.unit)
|
local u=(W.smooth and .01 or 1)
|
||||||
if p==P or not P then return end
|
local P= isLeft and max(p-u,0)or min(p+u,W.unit)
|
||||||
W.code(P)
|
if p==P or not P then return end
|
||||||
if W.change and Timer()-W.lastTime>.18 then
|
W.code(P)
|
||||||
W.lastTime=Timer()
|
if W.change and Timer()-W.lastTime>.18 then
|
||||||
W.change()
|
W.lastTime=Timer()
|
||||||
end
|
W.change()
|
||||||
elseif W.type=="selector"then
|
|
||||||
local s=W.select
|
|
||||||
if key=="left"then
|
|
||||||
if s>1 then
|
|
||||||
s=s-1
|
|
||||||
sysFX.newShade(.3,1,1,1,W.x,W.y,W.w*.5,60)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
if s<#W.list then
|
|
||||||
s=s+1
|
|
||||||
sysFX.newShade(.3,1,1,1,W.x+W.w*.5,W.y,W.w*.5,60)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if W.select~=s then
|
|
||||||
W.code(W.list[s])
|
|
||||||
W.select=s
|
|
||||||
W.selText=W.list[s]
|
|
||||||
SFX.play("prerotate")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
elseif W.type=="selector"then
|
||||||
|
local s=W.select
|
||||||
|
if not ((isLeft and s > 1) or ((not isLeft) and s < #W.list)) then return end
|
||||||
|
if isLeft then
|
||||||
|
s=s-1
|
||||||
|
sysFX.newShade(.3,1,1,1,W.x,W.y,W.w*.5,60)
|
||||||
|
else
|
||||||
|
s=s+1
|
||||||
|
sysFX.newShade(.3,1,1,1,W.x+W.w*.5,W.y,W.w*.5,60)
|
||||||
|
end
|
||||||
|
W.code(W.list[s])
|
||||||
|
W.select=s
|
||||||
|
W.selText=W.list[s]
|
||||||
|
SFX.play("prerotate")
|
||||||
end
|
end
|
||||||
elseif key=="up"or key=="down"or key=="left"or key=="right"then
|
elseif key=="up"or key=="down"or key=="left"or key=="right"then
|
||||||
if WIDGET.sel then
|
if not WIDGET.sel then
|
||||||
local W=WIDGET.sel
|
|
||||||
if W.getCenter then
|
|
||||||
local WX,WY=W:getCenter()
|
|
||||||
local dir=(key=="right"or key=="down")and 1 or -1
|
|
||||||
local tar
|
|
||||||
local minDist=1e99
|
|
||||||
if key=="left"or key=="right"then
|
|
||||||
for i=1,#WIDGET.active do
|
|
||||||
local W1=WIDGET.active[i]
|
|
||||||
if W~=W1 and W1.resCtr then
|
|
||||||
local L=W1.resCtr
|
|
||||||
for j=1,#L,2 do
|
|
||||||
local x,y=L[j],L[j+1]
|
|
||||||
local dist=(x-WX)*dir
|
|
||||||
if dist>10 then
|
|
||||||
dist=dist+abs(y-WY)*6.26
|
|
||||||
if dist<minDist then
|
|
||||||
minDist=dist
|
|
||||||
tar=W1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
for i=1,#WIDGET.active do
|
|
||||||
local W1=WIDGET.active[i]
|
|
||||||
if W~=W1 and W1.resCtr then
|
|
||||||
local L=W1.resCtr
|
|
||||||
for j=1,#L,2 do
|
|
||||||
local x,y=L[j],L[j+1]
|
|
||||||
local dist=(y-WY)*dir
|
|
||||||
if dist>10 then
|
|
||||||
dist=dist+abs(x-WX)*6.26
|
|
||||||
if dist<minDist then
|
|
||||||
minDist=dist
|
|
||||||
tar=W1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if tar then
|
|
||||||
WIDGET.sel=tar
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
for _,v in next,WIDGET.active do
|
for _,v in next,WIDGET.active do
|
||||||
if v.isAbove then
|
if v.isAbove then
|
||||||
WIDGET.sel=v
|
WIDGET.sel=v
|
||||||
break
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return
|
||||||
end
|
end
|
||||||
else
|
local W=WIDGET.sel
|
||||||
if WIDGET.sel and WIDGET.sel.type=="textBox"then
|
if not W.getCenter then return end
|
||||||
local t=WIDGET.sel.value
|
local WX,WY=W:getCenter()
|
||||||
if key=="backspace"then
|
local dir=(key=="right"or key=="down")and 1 or -1
|
||||||
if #t>0 then
|
local tar
|
||||||
while t:byte(#t)>=128 and t:byte(#t)<192 do
|
local minDist=1e99
|
||||||
t=sub(t,1,-2)
|
local swap_xy = not (key=="left" or key == "right")
|
||||||
|
if swap_xy then WX, WY = WY, WX end -- note that we do not swap them back later
|
||||||
|
for i, W1 in ipairs(WIDGET.active) do
|
||||||
|
if W~=W1 and W1.resCtr then
|
||||||
|
local L=W1.resCtr
|
||||||
|
for j=1,#L,2 do
|
||||||
|
local x,y=L[j],L[j+1]
|
||||||
|
if swap_xy then x, y = y, x end -- note that we do not swap them back later
|
||||||
|
local dist=(x-WX)*dir
|
||||||
|
if dist>10 then
|
||||||
|
dist=dist+abs(y-WY)*6.26
|
||||||
|
if dist<minDist then
|
||||||
|
minDist=dist
|
||||||
|
tar=W1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
t=sub(t,1,-2)
|
|
||||||
SFX.play("lock")
|
|
||||||
end
|
|
||||||
elseif key=="delete"then
|
|
||||||
if #t>0 then
|
|
||||||
t=""
|
|
||||||
SFX.play("hold")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
WIDGET.sel.value=t
|
|
||||||
end
|
end
|
||||||
|
if tar then
|
||||||
|
WIDGET.sel=tar
|
||||||
|
end
|
||||||
|
elseif WIDGET.sel and WIDGET.sel.type=="textBox"then
|
||||||
|
local t=WIDGET.sel.value
|
||||||
|
if #t <= 0 then return end
|
||||||
|
if key=="backspace"then
|
||||||
|
while t:byte(#t)>=128 and t:byte(#t)<192 do
|
||||||
|
t=sub(t,1,-2)
|
||||||
|
end
|
||||||
|
t=sub(t,1,-2)
|
||||||
|
SFX.play("lock")
|
||||||
|
elseif key=="delete"then
|
||||||
|
t=""
|
||||||
|
SFX.play("hold")
|
||||||
|
end
|
||||||
|
WIDGET.sel.value=t
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local keyMirror={
|
local keyMirror={
|
||||||
|
|||||||
Reference in New Issue
Block a user