Skip to content

Commit e508b5d

Browse files
TimMenu:
1 parent c91e7bb commit e508b5d

5 files changed

Lines changed: 22 additions & 66 deletions

File tree

TimMenu/Main.lua

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -300,20 +300,9 @@ local function _TimMenu_GlobalDraw()
300300
for i = #TimMenuGlobal.order, 1, -1 do
301301
local key = TimMenuGlobal.order[i]
302302
local win = TimMenuGlobal.windows[key]
303-
if win and win.visible then
304-
-- Check if window has any click shapes at this point (popup-aware)
305-
local shapeId, shapeData = win:GetClickShapeAt(mouseX, mouseY)
306-
if shapeId then
307-
-- Found a click shape - check if it should change focus
308-
if win:ShouldChangeFocus(mouseX, mouseY) then
309-
focusedWindowKey = key
310-
break
311-
end
312-
elseif win:_HitTest(mouseX, mouseY) then
313-
-- Fallback to traditional hit testing for non-shape areas
314-
focusedWindowKey = key
315-
break
316-
end
303+
if win and win.visible and win:_HitTest(mouseX, mouseY) then
304+
focusedWindowKey = key
305+
break
317306
end
318307
end
319308

@@ -331,7 +320,8 @@ local function _TimMenu_GlobalDraw()
331320
input.IsButtonReleased(MOUSE_LEFT)
332321
)
333322

334-
if isFocused and input.IsButtonPressed(MOUSE_LEFT) then
323+
-- Only change focus if window allows it (prevents popup focus stealing)
324+
if isFocused and input.IsButtonPressed(MOUSE_LEFT) and win:ShouldChangeFocus(mouseX, mouseY) then
335325
if TimMenuGlobal.order[#TimMenuGlobal.order] ~= key then
336326
for j, v_key in ipairs(TimMenuGlobal.order) do
337327
if v_key == key then

TimMenu/Widgets/ColorPicker.lua

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,6 @@ local function ColorPicker(win, label, initColor)
117117
-- Maintain popup blocked regions while open
118118
if state.open then
119119
win._widgetBlockedRegions = { popupBounds }
120-
-- Register popup click shape with focus weight 0 (no focus change)
121-
win:AddClickShape(ctx.widgetKey .. "_popup", {
122-
type = "rectangle",
123-
x = popupBounds.x,
124-
y = popupBounds.y,
125-
w = popupBounds.w,
126-
h = popupBounds.h,
127-
}, 0, { type = "popup", widgetKey = ctx.widgetKey })
128120
end
129121

130122
-- Toggle popup on field click
@@ -183,7 +175,6 @@ local function ColorPicker(win, label, initColor)
183175
if not inField and not inPopup then
184176
state.open = false
185177
win._widgetBlockedRegions = {}
186-
win:RemoveClickShape(ctx.widgetKey .. "_popup")
187178
end
188179
end
189180

TimMenu/Widgets/Combo.lua

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,6 @@ local function Combo(win, label, selected, options)
135135
-- Maintain popup blocked regions while open
136136
if entry.open then
137137
win._widgetBlockedRegions = { popupBounds }
138-
-- Register popup click shape with focus weight 0 (no focus change)
139-
win:AddClickShape(ctx.widgetKey .. "_popup", {
140-
type = "rectangle",
141-
x = popupBounds.x,
142-
y = popupBounds.y,
143-
w = popupBounds.w,
144-
h = popupBounds.h,
145-
}, 0, { type = "popup", widgetKey = ctx.widgetKey })
146138
end
147139

148140
-- Close popup on outside click using cached mouse position
@@ -176,7 +168,6 @@ local function Combo(win, label, selected, options)
176168
else
177169
entry.open = false
178170
win._widgetBlockedRegions = {}
179-
win:RemoveClickShape(ctx.widgetKey .. "_popup")
180171
end
181172
end
182173
end

TimMenu/Widgets/Dropdown.lua

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,6 @@ local function Dropdown(win, label, selectedIndex, options)
123123
-- Maintain popup blocked regions while open
124124
if entry.open then
125125
win._widgetBlockedRegions = { popupBounds }
126-
-- Register popup click shape with focus weight 0 (no focus change)
127-
win:AddClickShape(ctx.widgetKey .. "_popup", {
128-
type = "rectangle",
129-
x = popupBounds.x,
130-
y = popupBounds.y,
131-
w = popupBounds.w,
132-
h = popupBounds.h,
133-
}, 0, { type = "popup", widgetKey = ctx.widgetKey })
134126
end
135127

136128
-- Close popup on outside click using cached mouse position
@@ -163,12 +155,10 @@ local function Dropdown(win, label, selectedIndex, options)
163155
entry.selected = idx
164156
entry.open = false
165157
win._widgetBlockedRegions = {}
166-
win:RemoveClickShape(ctx.widgetKey .. "_popup")
167158
end
168159
else
169160
entry.open = false
170161
win._widgetBlockedRegions = {}
171-
win:RemoveClickShape(ctx.widgetKey .. "_popup")
172162
end
173163
end
174164
end

TimMenu/Window.lua

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ function Window.new(params)
6262
self._widgetBlockedRegions = {}
6363
-- Initialize click shapes for precise hit testing
6464
self._clickShapes = {}
65+
-- Flag to prevent focus changes during popup interactions
66+
self._preventFocusChange = false
6567
self._requestedNextLineSpacing = nil
6668
return self
6769
end
@@ -219,8 +221,21 @@ end
219221
---@param y number Y coordinate
220222
---@return boolean
221223
function Window:ShouldChangeFocus(x, y)
222-
local _, shapeData = self:GetClickShapeAt(x, y)
223-
return shapeData and shapeData.focusWeight > 0
224+
-- If flag is set, prevent focus changes (used during popup interactions)
225+
if self._preventFocusChange then
226+
return false
227+
end
228+
229+
-- Check if point is in any popup region
230+
if self._widgetBlockedRegions then
231+
for _, region in ipairs(self._widgetBlockedRegions) do
232+
if x >= region.x and x <= region.x + region.w and y >= region.y and y <= region.y + region.h then
233+
return false -- Don't change focus if clicking popup area
234+
end
235+
end
236+
end
237+
238+
return true -- Allow focus change for regular window areas
224239
end
225240

226241
--- Get the focus weight of a click shape at a point
@@ -303,27 +318,6 @@ function Window:resetCursor()
303318
self.H = Globals.Defaults.DEFAULT_H
304319
-- Clear sector sizes to allow sectors to shrink each frame
305320
self._sectorSizes = {}
306-
307-
-- Register main window click shapes
308-
local titleHeight = Globals.Defaults.TITLE_BAR_HEIGHT
309-
310-
-- Title bar - high focus weight for dragging
311-
self:AddClickShape("title_bar", {
312-
type = "rectangle",
313-
x = self.X,
314-
y = self.Y,
315-
w = self.W,
316-
h = titleHeight,
317-
}, 2, { type = "title_bar" })
318-
319-
-- Content area - normal focus weight
320-
self:AddClickShape("content_area", {
321-
type = "rectangle",
322-
x = self.X,
323-
y = self.Y + titleHeight,
324-
w = self.W,
325-
h = self.H,
326-
}, 1, { type = "content_area" })
327321
end
328322

329323
return Window

0 commit comments

Comments
 (0)