@@ -42,6 +42,13 @@ local function restoreWidgetFont(prev)
4242 end
4343end
4444
45+ local function withFontReset (func , ...)
46+ local prevFont = applyNextWidgetFont ()
47+ local results = {func (... )}
48+ restoreWidgetFont (prevFont )
49+ return table.unpack (results )
50+ end
51+
4552local _currentWindow = nil
4653
4754local Common = require (" TimMenu.Common" )
@@ -102,21 +109,15 @@ function TimMenu.Button(label)
102109 if not win then
103110 return false
104111 end
105- local prevFont = applyNextWidgetFont ()
106- local clicked = Widgets .Button (win , label )
107- restoreWidgetFont (prevFont )
108- return clicked
112+ return withFontReset (Widgets .Button , win , label )
109113end
110114
111115function TimMenu .Checkbox (label , state )
112116 local win = TimMenu .GetCurrentWindow ()
113117 if not win then
114118 return state , false
115119 end
116- local prevFont = applyNextWidgetFont ()
117- local newState , clicked = Widgets .Checkbox (win , label , state )
118- restoreWidgetFont (prevFont )
119- return newState , clicked
120+ return withFontReset (Widgets .Checkbox , win , label , state )
120121end
121122
122123function TimMenu .Text (text )
@@ -194,10 +195,7 @@ function TimMenu.Slider(label, value, min, max, step)
194195 if not win then
195196 return value , false
196197 end
197- local prevFont = applyNextWidgetFont ()
198- local newValue , changed = Widgets .Slider (win , label , value , min , max , step )
199- restoreWidgetFont (prevFont )
200- return newValue , changed
198+ return withFontReset (Widgets .Slider , win , label , value , min , max , step )
201199end
202200
203201function TimMenu .Separator (label )
@@ -213,43 +211,31 @@ function TimMenu.TextInput(label, text)
213211 if not win then
214212 return text , false
215213 end
216- local prevFont = applyNextWidgetFont ()
217- local newText , changed = Widgets .TextInput (win , label , text )
218- restoreWidgetFont (prevFont )
219- return newText , changed
214+ return withFontReset (Widgets .TextInput , win , label , text )
220215end
221216
222217function TimMenu .Dropdown (label , selectedIndex , options )
223218 local win = TimMenu .GetCurrentWindow ()
224219 if not win then
225220 return selectedIndex , false
226221 end
227- local prevFont = applyNextWidgetFont ()
228- local newIdx , changed = Widgets .Dropdown (win , label , selectedIndex , options )
229- restoreWidgetFont (prevFont )
230- return newIdx , changed
222+ return withFontReset (Widgets .Dropdown , win , label , selectedIndex , options )
231223end
232224
233225function TimMenu .Combo (label , selectedTable , options )
234226 local win = TimMenu .GetCurrentWindow ()
235227 if not win then
236228 return selectedTable , false
237229 end
238- local prevFont = applyNextWidgetFont ()
239- local newTable , changed = Widgets .Combo (win , label , selectedTable , options )
240- restoreWidgetFont (prevFont )
241- return newTable , changed
230+ return withFontReset (Widgets .Combo , win , label , selectedTable , options )
242231end
243232
244233function TimMenu .Selector (label , selectedIndex , options )
245234 local win = TimMenu .GetCurrentWindow ()
246235 if not win then
247236 return selectedIndex , false
248237 end
249- local prevFont = applyNextWidgetFont ()
250- local newIdx , changed = Widgets .Selector (win , label , selectedIndex , options )
251- restoreWidgetFont (prevFont )
252- return newIdx , changed
238+ return withFontReset (Widgets .Selector , win , label , selectedIndex , options )
253239end
254240
255241function TimMenu .TabControl (id , tabs , defaultSelection )
@@ -261,9 +247,7 @@ function TimMenu.TabControl(id, tabs, defaultSelection)
261247 return 1 , false
262248 end
263249 end
264- local prevFont = applyNextWidgetFont ()
265- local newIndex , changed = Widgets .TabControl (win , id , tabs , defaultSelection )
266- restoreWidgetFont (prevFont )
250+ local newIndex , changed = withFontReset (Widgets .TabControl , win , id , tabs , defaultSelection )
267251 if type (defaultSelection ) == " string" then
268252 return tabs [newIndex ], changed
269253 end
@@ -377,19 +361,15 @@ callbacks.Unregister("Draw", "TimMenu_GlobalDraw")
377361callbacks .Unregister (" Draw" , " zTimMenu_GlobalDraw" )
378362callbacks .Register (" Draw" , " zTimMenu_GlobalDraw" , _TimMenu_GlobalDraw )
379363
380- function TimMenu .Textbox (label , text )
381- return TimMenu .TextInput (label , text )
382- end
364+ -- Textbox is deprecated, use TextInput instead
365+ TimMenu .Textbox = TimMenu .TextInput
383366
384367function TimMenu .Keybind (label , currentKey )
385368 local win = TimMenu .GetCurrentWindow ()
386369 if not win then
387370 return currentKey , false
388371 end
389- local prevFont = applyNextWidgetFont ()
390- local keycode , changed = Widgets .Keybind (win , label , currentKey )
391- restoreWidgetFont (prevFont )
392- return keycode , changed
372+ return withFontReset (Widgets .Keybind , win , label , currentKey )
393373end
394374
395375function TimMenu .FontSet (name , size , weight )
@@ -422,8 +402,7 @@ function TimMenu.ColorPicker(label, color)
422402 if not win then
423403 return color , false
424404 end
425- local newColor , changed = Widgets .ColorPicker (win , label , color )
426- return newColor , changed
405+ return withFontReset (Widgets .ColorPicker , win , label , color )
427406end
428407
429408function TimMenu .Tooltip (text )
0 commit comments