Skip to content

Commit 9a83654

Browse files
fixed examples
1 parent 8ce5a96 commit 9a83654

File tree

3 files changed

+22
-78
lines changed

3 files changed

+22
-78
lines changed

TimMenu/Common.lua

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---@diagnostic disable: duplicate-set-field
12
local Utils = require("TimMenu.Utils")
23
local Globals = require("TimMenu.Globals")
34

@@ -241,36 +242,6 @@ end
241242
callbacks.Unregister("Unload", "TimMenu_Unload")
242243
callbacks.Register("Unload", "TimMenu_Unload", OnUnload)
243244

244-
-- Ensure all draw positions are integers
245-
do
246-
local origFilled = draw.FilledRect
247-
draw.FilledRect = function(x1, y1, x2, y2)
248-
origFilled(math.floor(x1), math.floor(y1), math.floor(x2), math.floor(y2))
249-
end
250-
251-
local origOutlined = draw.OutlinedRect
252-
draw.OutlinedRect = function(x1, y1, x2, y2)
253-
origOutlined(math.floor(x1), math.floor(y1), math.floor(x2), math.floor(y2))
254-
end
255-
256-
local origLine = draw.Line
257-
if origLine then
258-
draw.Line = function(x1, y1, x2, y2)
259-
origLine(math.floor(x1), math.floor(y1), math.floor(x2), math.floor(y2))
260-
end
261-
end
262-
263-
local origText = draw.Text
264-
draw.Text = function(x, y, text)
265-
origText(math.floor(x), math.floor(y), text)
266-
end
267-
268-
local origTextured = draw.TexturedRect
269-
if origTextured then
270-
draw.TexturedRect = function(id, x1, y1, x2, y2)
271-
origTextured(id, math.floor(x1), math.floor(y1), math.floor(x2), math.floor(y2))
272-
end
273-
end
274-
end
245+
-- Monkey patch draw functions to ensure all draw positions are integers-- This prevents floating point coordinates which can cause rendering issuesdo local origFilled = draw.FilledRect ---@diagnostic disable-next-line: duplicate-set-field draw.FilledRect = function(x1, y1, x2, y2) origFilled(math.floor(x1), math.floor(y1), math.floor(x2), math.floor(y2)) end local origOutlined = draw.OutlinedRect ---@diagnostic disable-next-line: duplicate-set-field draw.OutlinedRect = function(x1, y1, x2, y2) origOutlined(math.floor(x1), math.floor(y1), math.floor(x2), math.floor(y2)) end local origLine = draw.Line if origLine then ---@diagnostic disable-next-line: duplicate-set-field draw.Line = function(x1, y1, x2, y2) origLine(math.floor(x1), math.floor(y1), math.floor(x2), math.floor(y2)) end end local origText = draw.Text ---@diagnostic disable-next-line: duplicate-set-field draw.Text = function(x, y, text) origText(math.floor(x), math.floor(y), text) end local origTextured = draw.TexturedRect if origTextured then ---@diagnostic disable-next-line: duplicate-set-field draw.TexturedRect = function(id, x1, y1, x2, y2) origTextured(id, math.floor(x1), math.floor(y1), math.floor(x2), math.floor(y2)) end endend
275246

276247
return Common

examples/menudemo2.lua

Lines changed: 14 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ local balanceVal2 = 0
88
local selectedOption2 = 1
99
local options2 = { "Option A", "Option B", "Option C", "Option D" }
1010
local tabs = { "Main", "Audio", "Options", "Debug" }
11-
local currentTab = tabs[1]
11+
local currentTab = 1 -- Use index instead of label
1212
local dropdownIndex2 = 1
1313
local comboState2 = { false, false, false, false }
1414
-- Keybind demo state
@@ -18,14 +18,10 @@ local pickerColor2 = { 0, 255, 0, 255 }
1818

1919
local function OnDraw_Menudemo2()
2020
if TimMenu.Begin("Demo Window 2 - Advanced") then
21-
-- Use simplified TabControl (returns selected label)
22-
local newTabLabel, changedTab = TimMenu.TabControl("DemoTabs", tabs, currentTab)
21+
-- Use simplified TabControl (returns selected index)
22+
currentTab = TimMenu.TabControl("DemoTabs", tabs, currentTab)
2323

24-
if changedTab then
25-
currentTab = newTabLabel
26-
end
27-
28-
if currentTab == "Main" then
24+
if currentTab == 1 then -- Main tab
2925
TimMenu.Text("Welcome to the Main Tab")
3026
TimMenu.NextLine()
3127
cbState2 = TimMenu.Checkbox("Enable Feature", cbState2)
@@ -34,60 +30,34 @@ local function OnDraw_Menudemo2()
3430
print("[Menudemo2] Action executed")
3531
end
3632
-- Color Picker in Main tab
37-
pickerColor2, changedColor2 = TimMenu.ColorPicker("Main Color", pickerColor2)
38-
if changedColor2 then
39-
print("[Menudemo2] New color: ", pickerColor2[1], pickerColor2[2], pickerColor2[3])
40-
end
33+
pickerColor2 = TimMenu.ColorPicker("Main Color", pickerColor2)
4134
TimMenu.NextLine()
4235

4336
TimMenu.NextLine()
4437
-- Keybind widget
45-
bindKey2, changed2 = TimMenu.Keybind("Demo2 Bind", bindKey2)
46-
if changed2 then
47-
print("[Menudemo2] New bind key code: " .. tostring(bindKey2))
48-
end
49-
elseif currentTab == "Audio" then
50-
sliderVal2, changed2 = TimMenu.Slider("Volume", sliderVal2, 0, 100, 5)
38+
bindKey2 = TimMenu.Keybind("Demo2 Bind", bindKey2)
39+
elseif currentTab == 2 then -- Audio tab
40+
sliderVal2 = TimMenu.Slider("Volume", sliderVal2, 0, 100, 5)
5141
TimMenu.Tooltip("Adjust the audio volume from 0 to 100")
52-
if changed2 then
53-
print("[Menudemo2] Volume -> " .. sliderVal2)
54-
end
5542
TimMenu.NextLine()
56-
balanceVal2, changed3 = TimMenu.Slider("Balance", balanceVal2, -50, 50, 1)
43+
balanceVal2 = TimMenu.Slider("Balance", balanceVal2, -50, 50, 1)
5744
TimMenu.Tooltip("Adjust audio balance: negative = left, positive = right")
58-
if changed3 then
59-
print("[Menudemo2] Balance -> " .. balanceVal2)
60-
end
61-
elseif currentTab == "Options" then
45+
elseif currentTab == 3 then -- Options tab
6246
TimMenu.Text("Select Option:")
6347
TimMenu.NextLine()
6448

6549
-- Selector example using the dedicated widget
66-
selectedOption2, changedOption = TimMenu.Selector("Option Selector", selectedOption2, options2)
67-
if changedOption then
68-
print("[Menudemo2] Selector selected: " .. options2[selectedOption2])
69-
end
50+
selectedOption2 = TimMenu.Selector("Option Selector", selectedOption2, options2)
7051
TimMenu.NextLine()
7152

7253
-- Dropdown example using the dedicated widget
73-
dropdownIndex2, changedOption = TimMenu.Dropdown("Dropdown in Demo2", dropdownIndex2, options2)
74-
if changedOption then
75-
print("[Menudemo2] Dropdown selected: " .. options2[dropdownIndex2])
76-
end
54+
dropdownIndex2 = TimMenu.Dropdown("Dropdown in Demo2", dropdownIndex2, options2)
7755
TimMenu.NextLine()
7856

7957
-- Multi-selection Combo example
80-
comboState2, changedOption = TimMenu.Combo("Combo in Demo2", comboState2, options2)
81-
if changedOption then
82-
print("[Menudemo2] Combo selections:")
83-
for i, sel in ipairs(comboState2) do
84-
if sel then
85-
print(" - " .. options2[i])
86-
end
87-
end
88-
end
58+
comboState2 = TimMenu.Combo("Combo in Demo2", comboState2, options2)
8959
TimMenu.NextLine()
90-
elseif currentTab == "Debug" then
60+
elseif currentTab == 4 then -- Debug tab
9161
TimMenu.ShowDebug()
9262
end
9363
end

examples/tooltip_test.lua

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
-- Simple tooltip test example
22
local TimMenu = require("TimMenu")
33

4+
-- State variables to properly maintain widget values
5+
local checkboxState = false
6+
local sliderValue = 50
7+
48
local function main()
59
if TimMenu.Begin("Tooltip Test") then
610
-- Button with tooltip
@@ -14,7 +18,7 @@ local function main()
1418
TimMenu.NextLine()
1519

1620
-- Checkbox with tooltip
17-
local checkboxState = TimMenu.Checkbox("Enable Feature", false)
21+
checkboxState = TimMenu.Checkbox("Enable Feature", checkboxState)
1822
TimMenu.Tooltip("Toggle this checkbox to enable or disable the feature")
1923

2024
TimMenu.NextLine()
@@ -26,10 +30,9 @@ local function main()
2630
TimMenu.NextLine()
2731

2832
-- Slider with tooltip
29-
local sliderValue = TimMenu.Slider("Volume", 50, 0, 100, 1)
33+
sliderValue = TimMenu.Slider("Volume", sliderValue, 0, 100, 1)
3034
TimMenu.Tooltip("Adjust the volume level from 0 to 100")
3135
end
32-
TimMenu.End()
3336
end
3437

3538
-- Register the callback

0 commit comments

Comments
 (0)