5151
5252local _currentWindow = nil
5353
54+ local function withCurrentWindow (func , ...)
55+ local win = TimMenu .GetCurrentWindow ()
56+ if not win then
57+ return
58+ end
59+ return func (win , ... )
60+ end
61+
5462local Common = require (" TimMenu.Common" )
5563local Globals = require (" TimMenu.Globals" )
5664local Utils = require (" TimMenu.Utils" )
@@ -170,24 +178,21 @@ function TimMenu.ShowDebug()
170178end
171179
172180function TimMenu .NextLine (spacing )
173- local win = TimMenu .GetCurrentWindow ()
174- if win then
181+ return withCurrentWindow (function (win , spacing )
175182 win :NextLine (spacing )
176- end
183+ end , spacing )
177184end
178185
179186function TimMenu .SameLine (spacing )
180- local win = TimMenu .GetCurrentWindow ()
181- if win then
187+ return withCurrentWindow (function (win , spacing )
182188 win :SameLine (spacing )
183- end
189+ end , spacing )
184190end
185191
186192function TimMenu .Spacing (verticalSpacing )
187- local win = TimMenu .GetCurrentWindow ()
188- if win then
193+ return withCurrentWindow (function (win , verticalSpacing )
189194 win :Spacing (verticalSpacing )
190- end
195+ end , verticalSpacing )
191196end
192197
193198function TimMenu .Slider (label , value , min , max , step )
@@ -199,11 +204,9 @@ function TimMenu.Slider(label, value, min, max, step)
199204end
200205
201206function TimMenu .Separator (label )
202- local win = TimMenu .GetCurrentWindow ()
203- if not win then
204- return
205- end
206- return SeparatorLayout .Draw (win , label )
207+ return withCurrentWindow (function (win , label )
208+ return SeparatorLayout .Draw (win , label )
209+ end , label )
207210end
208211
209212function TimMenu .TextInput (label , text )
@@ -255,11 +258,9 @@ function TimMenu.TabControl(id, tabs, defaultSelection)
255258end
256259
257260function TimMenu .BeginSector (label )
258- local win = TimMenu .GetCurrentWindow ()
259- if not win then
260- return
261- end
262- SectorWidget .Begin (win , label )
261+ return withCurrentWindow (function (win , label )
262+ SectorWidget .Begin (win , label )
263+ end , label )
263264end
264265
265266function TimMenu .EndSector ()
@@ -368,29 +369,25 @@ function TimMenu.Keybind(label, currentKey)
368369 return withFontReset (Widgets .Keybind , win , label , currentKey )
369370end
370371
371- function TimMenu . FontSet ( name , size , weight )
372- Globals .Style . FontName = name
373- Globals .Style . FontSize = size
374- Globals .Style . FontWeight = weight
372+ local function setFontStyle ( style , name , size , weight )
373+ Globals .Style [ style .. " Name " ] = name
374+ Globals .Style [ style .. " Size " ] = size
375+ Globals .Style [ style .. " Weight " ] = weight
375376 Globals .ReloadFonts ()
376377end
377378
379+ function TimMenu .FontSet (name , size , weight )
380+ setFontStyle (" Font" , name , size , weight )
381+ end
382+
378383function TimMenu .FontSetBold (name , size , weight )
379- Globals .Style .FontBoldName = name
380- Globals .Style .FontBoldSize = size
381- Globals .Style .FontBoldWeight = weight
382- Globals .ReloadFonts ()
384+ setFontStyle (" FontBold" , name , size , weight )
383385end
384386
385387function TimMenu .FontReset ()
386388 local d = Globals .DefaultFontSettings
387- Globals .Style .FontName = d .FontName
388- Globals .Style .FontSize = d .FontSize
389- Globals .Style .FontWeight = d .FontWeight
390- Globals .Style .FontBoldName = d .FontBoldName
391- Globals .Style .FontBoldSize = d .FontBoldSize
392- Globals .Style .FontBoldWeight = d .FontBoldWeight
393- Globals .ReloadFonts ()
389+ setFontStyle (" Font" , d .FontName , d .FontSize , d .FontWeight )
390+ setFontStyle (" FontBold" , d .FontBoldName , d .FontBoldSize , d .FontBoldWeight )
394391end
395392
396393function TimMenu .ColorPicker (label , color )
@@ -402,11 +399,9 @@ function TimMenu.ColorPicker(label, color)
402399end
403400
404401function TimMenu .Tooltip (text )
405- local win = TimMenu .GetCurrentWindow ()
406- if not win then
407- return
408- end
409- Widgets .Tooltip .AttachToLastWidget (win , text )
402+ return withCurrentWindow (function (win , text )
403+ Widgets .Tooltip .AttachToLastWidget (win , text )
404+ end , text )
410405end
411406
412407_G .TimMenu = TimMenu
0 commit comments