Skip to content

Commit 8ce5a96

Browse files
readme: update
1 parent d74bdaa commit 8ce5a96

File tree

1 file changed

+88
-14
lines changed

1 file changed

+88
-14
lines changed

README.md

Lines changed: 88 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,8 @@ local function OnDraw()
4545
end
4646
TimMenu.NextLine()
4747

48-
sliderValue, changed = TimMenu.Slider("Value", sliderValue, 0, 100, 1)
49-
if changed then
50-
print("Slider:", sliderValue)
51-
end
48+
sliderValue = TimMenu.Slider("Value", sliderValue, 0, 100, 1)
49+
print("Current slider value:", sliderValue)
5250

5351
end
5452
end
@@ -72,15 +70,24 @@ callbacks.Register("Draw", "ExampleDraw", OnDraw)
7270

7371
### Basic Widgets
7472

73+
**All widgets now use simplified single-return APIs:**
74+
7575
- Text: `TimMenu.Text(text)`
76-
- Button: `clicked = TimMenu.Button(label [, selected])`
77-
- Checkbox: `newState = TimMenu.Checkbox(label, state)`
78-
- TextInput: `newText, changed = TimMenu.TextInput(label, text)`
79-
- Slider: `newValue, changed = TimMenu.Slider(label, value, min, max, step)`
80-
- Selector: `newIndex, changed = TimMenu.Selector(label, selectedIndex, options)`
81-
- Dropdown: `newIndex, changed = TimMenu.Dropdown(label, selectedIndex, options)`
82-
- Combo: `newIndex, changed = TimMenu.Combo(label, selectedIndex, options)`
83-
- TabControl: `newIndex = TimMenu.TabControl(id, tabs, currentTabIndex)`
76+
- Button: `clicked = TimMenu.Button(label)`
77+
- Checkbox: `checked = TimMenu.Checkbox(label, checked)`
78+
- TextInput: `text = TimMenu.TextInput(label, text)`
79+
- Slider: `value = TimMenu.Slider(label, value, min, max, step)`
80+
- Selector: `selectedIndex = TimMenu.Selector(label, selectedIndex, options)`
81+
- Dropdown: `selectedIndex = TimMenu.Dropdown(label, selectedIndex, options)`
82+
- Combo: `selectedItems = TimMenu.Combo(label, selectedItems, options)`
83+
- TabControl: `selectedTab = TimMenu.TabControl(id, tabs, selectedTab)`
84+
- Keybind: `keyCode = TimMenu.Keybind(label, keyCode)`
85+
- ColorPicker: `color = TimMenu.ColorPicker(label, color)`
86+
87+
### Advanced Widgets
88+
89+
- Image: `hovered, pressed, clicked = TimMenu.Image(texture, width, height, [raw_data])`
90+
- Tooltip: `TimMenu.Tooltip(text)` - Shows tooltip for the last widget
8491

8592
### Customization
8693

@@ -91,10 +98,69 @@ TimMenu.Globals.Colors.Window = {40, 40, 40, 255}
9198
TimMenu.Globals.Style.ItemPadding = 8
9299
```
93100

101+
## Widget Usage Examples
102+
103+
### Simple State Management
104+
105+
```lua
106+
-- Each widget modifies and returns its value directly
107+
local volume = 50
108+
local enabled = true
109+
local selectedOption = 1
110+
local options = {"Low", "Medium", "High"}
111+
112+
local function OnDraw()
113+
if TimMenu.Begin("Settings") then
114+
enabled = TimMenu.Checkbox("Enable Audio", enabled)
115+
116+
if enabled then
117+
volume = TimMenu.Slider("Volume", volume, 0, 100, 5)
118+
selectedOption = TimMenu.Dropdown("Quality", selectedOption, options)
119+
end
120+
end
121+
end
122+
```
123+
124+
### Color Picker Example
125+
126+
```lua
127+
local backgroundColor = {30, 30, 30, 255} -- RGBA
128+
129+
local function OnDraw()
130+
if TimMenu.Begin("Color Settings") then
131+
backgroundColor = TimMenu.ColorPicker("Background Color", backgroundColor)
132+
TimMenu.Text(string.format("RGB: %d, %d, %d, %d",
133+
backgroundColor[1], backgroundColor[2], backgroundColor[3], backgroundColor[4]))
134+
end
135+
end
136+
```
137+
138+
### Multi-Selection with Combo
139+
140+
```lua
141+
local features = {"Feature A", "Feature B", "Feature C"}
142+
local enabledFeatures = {true, false, true} -- Which features are enabled
143+
144+
local function OnDraw()
145+
if TimMenu.Begin("Feature Selection") then
146+
enabledFeatures = TimMenu.Combo("Enabled Features", enabledFeatures, features)
147+
148+
-- Show which features are enabled
149+
for i, feature in ipairs(features) do
150+
if enabledFeatures[i] then
151+
TimMenu.Text("" .. feature .. " is enabled")
152+
end
153+
end
154+
end
155+
end
156+
```
157+
94158
## Tips
95159

96160
- Use `BeginSector`/`EndSector` to group widgets in bordered panels.
97-
- sectors can be easly stacked horizontaly and verticaly
161+
- Sectors can be easily stacked horizontally and vertically
162+
- All widgets return their current value - no need to track "changed" flags
163+
- Values are automatically maintained between frames by the widget system
98164

99165
## Sector Grouping
100166

@@ -107,13 +173,21 @@ if TimMenu.Begin("Example Window") then
107173
-- Start a grouped panel
108174
TimMenu.BeginSector("Settings")
109175
-- Place widgets inside the sector
110-
local volume, changed = TimMenu.Slider("Volume", 50, 0, 100, 1)
176+
local volume = TimMenu.Slider("Volume", 50, 0, 100, 1)
111177
TimMenu.EndSector()
112178
end
113179
```
114180

115181
## Changelog
116182

183+
### Simplified Widget APIs (Latest)
184+
185+
- **BREAKING CHANGE**: All widgets now return single values instead of value + changed pairs
186+
- Simplified API: `value = Widget("Label", value)` instead of `value, changed = Widget("Label", value)`
187+
- Removed confusing "changed" flags - just use the returned values directly
188+
- Updated all example code to use the new simplified patterns
189+
- Much cleaner and more intuitive widget usage
190+
117191
### Fixed Keybind Widget Lag
118192

119193
- Keybind widget now recalculates its display label immediately after a key press and dynamically computes its draw position inside the rendering callback, eliminating frame delay when dragging windows.

0 commit comments

Comments
 (0)