Skip to content

Commit 1fd1750

Browse files
TimMenu/Wi: fixed ropdown a bit
1 parent dc36058 commit 1fd1750

File tree

3 files changed

+44
-15
lines changed

3 files changed

+44
-15
lines changed

TimMenu/Widgets/ColorPicker.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ local function ColorPicker(win, label, initColor)
7979
local absX, absY = ctx.absX, ctx.absY
8080
local baseSpacing = Globals.Style.ItemSpacingY or Globals.Defaults.WINDOW_CONTENT_PADDING
8181
local spacingBoost = baseSpacing + padding
82-
win._nextLineSpacingBoost = math.max(win._nextLineSpacingBoost or 0, spacingBoost)
82+
if win.RequestNextLineSpacing then
83+
win:RequestNextLineSpacing(spacingBoost)
84+
end
8385

8486
-- State management
8587
local state = Utils.GetState(win, ctx.widgetKey, {

TimMenu/Widgets/Dropdown.lua

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,17 @@ local function DrawDropdownPopupBackground(win, relX, relY, width, listH)
3838
Common.DrawFilledRect(absX, absY, absX + width, absY + listH)
3939
end
4040

41-
local function DrawDropdownPopupItem(win, relX, relY, width, itemH, pad, opt, isHovered)
41+
local function DrawDropdownPopupItem(win, relX, relY, width, itemH, pad, opt, isHovered, isSelected)
4242
local absX, absY = win.X + relX, win.Y + relY
4343
draw.SetFont(Globals.Style.Font)
44-
Common.SetColor(isHovered and Globals.Colors.ItemHover or Globals.Colors.Item)
44+
local bgColor = Globals.Colors.Item
45+
if isSelected then
46+
bgColor = Globals.Colors.HighlightActive
47+
end
48+
if isHovered then
49+
bgColor = Globals.Colors.ItemHover
50+
end
51+
Common.SetColor(bgColor)
4552
Common.DrawFilledRect(absX, absY, absX + width, absY + itemH)
4653
Common.SetColor(Globals.Colors.Text)
4754
local _, optH = draw.GetTextSize(opt)
@@ -115,15 +122,19 @@ local function Dropdown(win, label, selectedIndex, options)
115122
end
116123
end
117124
table.insert(TimMenuGlobal.order, win.id)
118-
elseif entry.open then
119-
if Interaction.IsHovered(win, popupBounds) then
120-
local idx = math.floor((input.GetMousePos()[2] - popupBounds.y) / height) + 1
121-
if idx >= 1 and idx <= #options then
122-
entry.selected = idx
125+
else
126+
if entry.open then
127+
if Interaction.IsHovered(win, popupBounds) then
128+
local idx = math.floor((input.GetMousePos()[2] - popupBounds.y) / height) + 1
129+
if idx >= 1 and idx <= #options then
130+
entry.selected = idx
131+
entry.open = false
132+
win._widgetBlockedRegions = {}
133+
end
134+
else
135+
entry.open = false
136+
win._widgetBlockedRegions = {}
123137
end
124-
else
125-
entry.open = false
126-
win._widgetBlockedRegions = {}
127138
end
128139
end
129140
end
@@ -171,7 +182,8 @@ local function Dropdown(win, label, selectedIndex, options)
171182
height,
172183
pad,
173184
opt,
174-
isH
185+
isH,
186+
i == entry.selected
175187
)
176188
end
177189

TimMenu/Window.lua

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ function Window.new(params)
5959
self.lineHeight = 0
6060
-- Initialize per-widget blocking regions for popup widgets
6161
self._widgetBlockedRegions = {}
62+
self._requestedNextLineSpacing = nil
6263
return self
6364
end
6465

@@ -180,9 +181,9 @@ end
180181
function Window:NextLine(spacing)
181182
local baseSpacing = Globals.Style.ItemSpacingY or Globals.Defaults.WINDOW_CONTENT_PADDING
182183
spacing = spacing or baseSpacing
183-
if self._nextLineSpacingBoost then
184-
spacing = math.max(spacing, self._nextLineSpacingBoost)
185-
self._nextLineSpacingBoost = nil
184+
if self._requestedNextLineSpacing then
185+
spacing = math.max(spacing, self._requestedNextLineSpacing)
186+
self._requestedNextLineSpacing = nil
186187
end
187188
self.cursorY = self.cursorY + self.lineHeight + spacing
188189
self.cursorX = Globals.Defaults.WINDOW_CONTENT_PADDING -- reset to left padding
@@ -215,12 +216,26 @@ function Window:Spacing(verticalSpacing)
215216
-- Important: Do NOT reset cursorX here.
216217
end
217218

219+
--- Allows a widget to request a minimum spacing before the next line starts.
220+
function Window:RequestNextLineSpacing(minSpacing)
221+
if type(minSpacing) ~= "number" then
222+
return
223+
end
224+
if minSpacing <= 0 then
225+
return
226+
end
227+
if not self._requestedNextLineSpacing or minSpacing > self._requestedNextLineSpacing then
228+
self._requestedNextLineSpacing = minSpacing
229+
end
230+
end
231+
218232
--- Reset the layout cursor for widgets (called on Begin)
219233
function Window:resetCursor()
220234
local padding = Globals.Defaults.WINDOW_CONTENT_PADDING
221235
self.cursorX = padding
222236
self.cursorY = Globals.Defaults.TITLE_BAR_HEIGHT + padding
223237
self.lineHeight = 0
238+
self._requestedNextLineSpacing = nil
224239
-- Clear any widget blocking regions at start of frame
225240
self._widgetBlockedRegions = {}
226241
-- Clear header tabs flag so titles center if no header tabs

0 commit comments

Comments
 (0)