升级控件模块,封装focus相关的几个静态方法
This commit is contained in:
@@ -190,7 +190,7 @@ function love.touchreleased(id,x,y)
|
||||
WIDGET.release(x,y)
|
||||
touching=false
|
||||
if WIDGET.sel and not WIDGET.sel.keepFocus then
|
||||
WIDGET.sel=false
|
||||
WIDGET.unFocus()
|
||||
end
|
||||
end
|
||||
if SCN.touchUp then SCN.touchUp(x,y)end
|
||||
@@ -214,7 +214,7 @@ local function noDevkeyPressed(key)
|
||||
end
|
||||
end
|
||||
elseif key=="f4"then if not kb.isDown("lalt","ralt")then LOG.copy()end
|
||||
elseif key=="f5"then if WIDGET.sel then print(WIDGET.sel)end
|
||||
elseif key=="f5"then print(WIDGET.isFocus()or"no widget selected")
|
||||
elseif key=="f6"then for k,v in next,_G do print(k,v)end
|
||||
elseif key=="f7"then if love._openConsole then love._openConsole()end
|
||||
elseif key=="f8"then devMode=nil LOG.print("DEBUG OFF")
|
||||
@@ -224,8 +224,8 @@ local function noDevkeyPressed(key)
|
||||
elseif key=="f12"then devMode=4 LOG.print("DEBUG 4")
|
||||
elseif key=="\\"then _G["\100\114\97\119\70\87\77"]=NULL
|
||||
elseif devMode==2 then
|
||||
if WIDGET.sel then
|
||||
local W=WIDGET.sel
|
||||
local W=WIDGET.sel
|
||||
if W then
|
||||
if key=="left"then W.x=W.x-10
|
||||
elseif key=="right"then W.x=W.x+10
|
||||
elseif key=="up"then W.y=W.y-10
|
||||
|
||||
@@ -1035,7 +1035,7 @@ WIDGET.indexMeta={
|
||||
end
|
||||
}
|
||||
function WIDGET.set(list)
|
||||
WIDGET.sel=false
|
||||
WIDGET.unFocus()
|
||||
WIDGET.active=list or NONE
|
||||
|
||||
--Reset all widgets
|
||||
@@ -1072,6 +1072,21 @@ function WIDGET.setLang(widgetText)
|
||||
end
|
||||
end
|
||||
end
|
||||
function WIDGET.isFocus(W)
|
||||
return W==nil and WIDGET.sel or WIDGET.sel==W
|
||||
end
|
||||
function WIDGET.focus(W)
|
||||
if WIDGET.sel and WIDGET.sel.type=='inputBox'then kb.setTextInput(false)end
|
||||
WIDGET.sel=W
|
||||
if W and W.type=='inputBox'then
|
||||
local _,y1=SCR.xOy:transformPoint(0,W.y+W.h)
|
||||
kb.setTextInput(true,0,y1,1,1)
|
||||
end
|
||||
end
|
||||
function WIDGET.unFocus()
|
||||
if WIDGET.sel and WIDGET.sel.type=='inputBox'then kb.setTextInput(false)end
|
||||
WIDGET.sel=false
|
||||
end
|
||||
|
||||
function WIDGET.cursorMove(x,y)
|
||||
for _,W in next,WIDGET.active do
|
||||
@@ -1081,22 +1096,22 @@ function WIDGET.cursorMove(x,y)
|
||||
end
|
||||
end
|
||||
if WIDGET.sel and not WIDGET.sel.keepFocus then
|
||||
WIDGET.sel=false
|
||||
WIDGET.unFocus()
|
||||
end
|
||||
end
|
||||
function WIDGET.press(x,y,k)
|
||||
local W=WIDGET.sel
|
||||
if not W then return end
|
||||
W:press(x,y,k)
|
||||
if W.hide then WIDGET.sel=false end
|
||||
if W.hide then WIDGET.unFocus()end
|
||||
end
|
||||
function WIDGET.drag(x,y,dx,dy)
|
||||
local W=WIDGET.sel
|
||||
if not W then return end
|
||||
if W.type=='slider'or W.type=='textBox'then
|
||||
W:drag(x,y,dx,dy)
|
||||
elseif not W:isAbove(x,y)then
|
||||
WIDGET.sel=false
|
||||
elseif not W:isAbove(x,y)and not WIDGET.sel.keepFocus then
|
||||
WIDGET.unFocus()
|
||||
end
|
||||
end
|
||||
function WIDGET.release(x,y)
|
||||
|
||||
Reference in New Issue
Block a user