1
+ surface .CreateFont ( " CustomChatEntry" , {
2
+ font = " Roboto" ,
3
+ extended = true ,
4
+ size = math.floor ( ScrH () * 0.019 ),
5
+ weight = 400 ,
6
+ blursize = 0 ,
7
+ scanlines = 0 ,
8
+ antialias = true ,
9
+ underline = false ,
10
+ italic = false ,
11
+ strikeout = false ,
12
+ symbol = false ,
13
+ rotary = false ,
14
+ shadow = false ,
15
+ additive = false ,
16
+ outline = false
17
+ } )
18
+
1
19
local L = CustomChat .GetLanguageText
2
20
local PANEL = {}
3
21
@@ -38,10 +56,18 @@ function PANEL:Init()
38
56
39
57
self .entryDock .Paint = function ( s , w , h )
40
58
draw .RoundedBox ( 0 , 0 , 0 , w , h , s ._backgroundColor )
59
+
60
+ if not s ._calculatedFontHeight then
61
+ surface .SetFont ( " CustomChatEntry" )
62
+ local _ , textH = surface .GetTextSize ( " A" )
63
+ s ._calculatedFontHeight = textH
64
+ end
41
65
end
42
66
67
+ self .entryDock ._originalPerformLayout = self .entryDock .PerformLayout
68
+
43
69
self .entry = vgui .Create ( " DTextEntry" , self .entryDock )
44
- self .entry :SetFont ( " ChatFont " )
70
+ self .entry :SetFont ( " CustomChatEntry " )
45
71
self .entry :SetDrawBorder ( false )
46
72
self .entry :SetPaintBackground ( false )
47
73
self .entry :SetMaximumCharCount ( CustomChat .MAX_MESSAGE_LENGTH )
@@ -55,18 +81,16 @@ function PANEL:Init()
55
81
derma .SkinHook ( " Paint" , " TextEntry" , s , w , h )
56
82
end
57
83
84
+ self .entry .GetLineCount = function ( s )
85
+ local _ , lineCount = string.gsub ( s :GetText (), " \n " , " \n " )
86
+ return math .Clamp ( lineCount + 1 , 1 , 5 )
87
+ end
88
+
58
89
self .entry .OnChange = function ( s )
59
90
if not s .GetText then return end
60
91
61
- local text = s :GetText () or " "
62
-
63
- hook .Run ( " ChatTextChanged" , text )
64
-
65
- local _ , lineCount = string.gsub ( text , " \n " , " \n " )
66
- lineCount = math .Clamp ( lineCount + 1 , 1 , 5 )
67
-
68
- self .entryDock :SetTall ( 20 * lineCount )
69
- self .entry ._multilineMode = lineCount > 1
92
+ hook .Run ( " ChatTextChanged" , s :GetText () or " " )
93
+ self .entryDock :InvalidateLayout ()
70
94
end
71
95
72
96
self .entry .OnKeyCodeTyped = function ( s , code )
@@ -103,15 +127,24 @@ function PANEL:Init()
103
127
if code == KEY_UP then
104
128
s .HistoryPos = s .HistoryPos - 1
105
129
s :UpdateFromHistory ()
130
+ s :SetCaretPos ( 0 )
106
131
end
107
132
108
133
if code == KEY_DOWN then
109
134
s .HistoryPos = s .HistoryPos + 1
110
135
s :UpdateFromHistory ()
136
+ s :SetCaretPos ( 0 )
111
137
end
112
138
end
113
139
end
114
140
141
+ self .entryDock .PerformLayout = function ( s )
142
+ local lineCount = self .entry :GetLineCount ()
143
+
144
+ self .entry ._multilineMode = lineCount > 1
145
+ s :SetTall ( lineCount * ( s ._calculatedFontHeight or 20 ) * 1.3 )
146
+ end
147
+
115
148
local emojisButton = vgui .Create ( " DImageButton" , self .entryDock )
116
149
emojisButton :SetImage ( " icon16/emoticon_smile.png" )
117
150
emojisButton :SetStretchToFit ( false )
0 commit comments