-
-
Notifications
You must be signed in to change notification settings - Fork 74
/
passwordtextbox.lua
105 lines (79 loc) · 2.34 KB
/
passwordtextbox.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
--=========== Copyright © 2019, Planimeter, All rights reserved. ===========--
--
-- Purpose: Password Text Box class
--
--==========================================================================--
class "gui.passwordtextbox" ( "gui.textbox" )
local passwordtextbox = gui.passwordtextbox
local function getInnerWidth( self )
return self:getWidth() - 2 * self.padding
end
function passwordtextbox:passwordtextbox( parent, name, placeholder )
gui.textbox.textbox( self, parent, name, placeholder or "Password" )
self.password = ""
end
local utf8sub = string.utf8sub
function passwordtextbox:doBackspace( count )
count = count or 1
if ( count == 0 ) then
count = self.cursorPos + 1
end
if ( self.cursorPos > 0 ) then
local sub1 = utf8sub( self.password, 1, self.cursorPos - count )
if ( sub1 == self.password ) then
sub1 = ""
end
local sub2 = utf8sub( self.password, self.cursorPos + 1 )
self.password = sub1 .. sub2
end
gui.textbox.doBackspace( self, count )
end
local utf8len = string.utf8len
function passwordtextbox:doDelete( count )
count = count or 1
if ( count == 0 ) then
count = utf8len( self.password ) - self.cursorPos
end
local sub1 = utf8sub( self.password, 1, self.cursorPos )
if ( self.cursorPos == 0 ) then
sub1 = ""
end
local sub2 = utf8sub( self.password, self.cursorPos + 1 + count )
self.password = sub1 .. sub2
gui.textbox.doDelete( self, count )
end
function passwordtextbox:doCut()
end
function passwordtextbox:doCopy()
end
function passwordtextbox:getAutocomplete()
end
accessor( passwordtextbox, "password" )
function passwordtextbox:insertText( text )
local buffer = {}
for i = 1, string.utf8len( text ) do
table.insert( buffer, "•" )
end
local sub1 = utf8sub( self.password, self.cursorPos + 1 )
local sub2 = utf8sub( self.password, 1, self.cursorPos )
if ( self.cursorPos == 0 ) then
sub2 = ""
end
self.password = sub2 .. text .. sub1
gui.textbox.insertText( self, table.concat( buffer ) )
end
function passwordtextbox:isMultiline()
return false
end
function passwordtextbox:setMultiline( multiline )
assert( false )
end
function passwordtextbox:setText( text )
local buffer = {}
for i = 1, string.utf8len( text ) do
table.insert( buffer, "•" )
end
gui.textbox.setText( self, table.concat( buffer ) )
self.password = text
end
passwordtextbox.setPassword = passwordtextbox.setText