控件系统文本框的显示调整,输入框新增clear方法

This commit is contained in:
MrZ626
2021-02-27 23:25:55 +08:00
parent 2bddffd538
commit a330d29a28
2 changed files with 23 additions and 16 deletions

View File

@@ -260,19 +260,11 @@ function love.keyreleased(i)
if SCN.keyUp then SCN.keyUp(i)end
end
function love.textedited(text)
EDITING=text
function love.textedited(texts)
EDITING=texts
end
function love.textinput(text)
local W=WIDGET.sel
if W and W.type=="inputBox"then
if not W.regex or text:match(W.regex)then
WIDGET.sel.value=WIDGET.sel.value..text
SFX.play("move")
else
SFX.play("finesseError",.3)
end
end
function love.textinput(texts)
WIDGET.textinput(texts)
end
function love.joystickadded(JS)

View File

@@ -698,6 +698,9 @@ function inputBox:reset()
kb.setTextInput(true)
end
end
function inputBox:clear()
self.value=""
end
function inputBox:isAbove(x,y)
return
x>self.x and
@@ -878,11 +881,13 @@ function textBox:draw()
local cap=self.capacity
--Frame
gc.setLineWidth(4)
--Background
gc.setColor(0,0,0,.3)
gc.rectangle("fill",x,y,w,h)
gc.setColor(1,1,1)
--Frame
gc.setLineWidth(4)
gc.setColor(COLOR[WIDGET.sel==self and"Y"or"W"])
gc.rectangle("line",x,y,w,h)
--Slider
@@ -890,7 +895,6 @@ function textBox:draw()
gc.setLineWidth(2)
gc.rectangle("line",x-25,y,20,h)
local len=max(h*cap/#texts,26)
gc.setColor(COLOR[WIDGET.sel==self and"Y"or"W"])
gc.rectangle("fill",x-22,y+(h-len-6)*(scroll-cap)/(#texts-cap)+3,14,len)
end
@@ -1089,6 +1093,17 @@ function WIDGET.keyPressed(k)
end
end
end
function WIDGET.textinput(texts)
local W=WIDGET.sel
if W and W.type=="inputBox"then
if not W.regex or texts:match(W.regex)then
WIDGET.sel.value=WIDGET.sel.value..texts
SFX.play("move")
else
SFX.play("finesseError",.3)
end
end
end
local keyMirror={
dpup="up",
dpdown="down",