Skip to content

Commit 062c40b

Browse files
TimMenu: fixed some code
1 parent 87c99c5 commit 062c40b

5 files changed

Lines changed: 110 additions & 187 deletions

File tree

TimMenu/Globals.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Globals.Defaults = {
4646
DEFAULT_X = 100,
4747
DEFAULT_Y = 100,
4848
DEFAULT_W = 300,
49-
DEFAULT_H = 200,
49+
DEFAULT_H = 0,
5050
SLIDER_WIDTH = 250,
5151
TITLE_BAR_HEIGHT = 30,
5252
WINDOW_CONTENT_PADDING = 8,

TimMenu/Main.lua

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ local function restoreWidgetFont(prev)
4242
end
4343
end
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+
4552
local _currentWindow = nil
4653

4754
local 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)
109113
end
110114

111115
function 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)
120121
end
121122

122123
function 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)
201199
end
202200

203201
function 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)
220215
end
221216

222217
function 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)
231223
end
232224

233225
function 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)
242231
end
243232

244233
function 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)
253239
end
254240

255241
function 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")
377361
callbacks.Unregister("Draw", "zTimMenu_GlobalDraw")
378362
callbacks.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

384367
function 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)
393373
end
394374

395375
function 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)
427406
end
428407

429408
function TimMenu.Tooltip(text)

TimMenu/Utils.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function Utils.PruneOrphanedWindows(windows, order)
1515
end
1616
end
1717

18-
function Utils.IsMouseOverWindow(win, mouseX, mouseY)
18+
function Utils.IsMouseOverWindow(win, mouseX, mouseY, titleHeight)
1919
local titleHeight = require("TimMenu.Globals").Defaults.TITLE_BAR_HEIGHT
2020
return mouseX >= win.X and mouseX <= win.X + win.W and mouseY >= win.Y and mouseY <= win.Y + titleHeight + win.H
2121
end

0 commit comments

Comments
 (0)