system.library.textBox = class()
function system.library.textBox:init(help, pass, pos, width)
self.pos = pos
self.w = width
self.text = ""
self.hint = help
self.selected = false
self.password = pass
end
function system.library.textBox:draw()
stroke(255, 255, 255, 255)
strokeWidth(40)
line(self.pos.x, self.pos.y, self.w + self.pos.x, self.pos.y)
fill(0, 0, 0, 255)
fontSize(30)
font("ArialMT")
text(self.text, self.pos.x+self.w/2, self.pos.y)
if #self.text==0 then fill(127) text(self.hint, self.pos.x+self.w/2, self.pos.y) end
end
function system.library.textBox:touched(t)
if t.x>self.pos.x and t.y>self.pos.y-20 and t.x<self.pos.x+self.w and t.y<self.pos.y+20 and t.state == ENDED then
self.selected = true
showKeyboard()
else
self.selected = false
hideKeyboard()
end
end
function system.library.textBox:keyboard(k)
if self.selected then
if k == RETURN then
self.selected = false
hideKeyboard()
elseif k == BACKSPACE then
self.text = string.sub(self.text, 1, #self.text-1)
else
if self.password then
self.text = self.text .. "*"
else
self.text = self.text .. k
end
end
end
end
The above class ^ use two of them in a table, and only one of them will work.
Table array is:
tab = {TextBox(name1), TextBox(name2)}
TextBox with name2 will be touchable, the name1 will get bugged like this:
- Keyboard opens then hides