Skip to content

Commit 48d6f17

Browse files
TimMenu: improvements
1 parent 99fecf5 commit 48d6f17

File tree

4 files changed

+35
-18
lines changed

4 files changed

+35
-18
lines changed

TimMenu/Globals.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ Globals.Style = {
2929
FontBoldWeight = 400,
3030
ItemPadding = 7,
3131
ItemMargin = 5,
32+
ItemSpacingX = 8,
33+
ItemSpacingY = 8,
3234
ItemSize = 10,
3335
EnableWindowBorder = true,
3436
FrameBorder = false,
@@ -90,6 +92,8 @@ Globals.DefaultFontSettings = {
9092
local scale = Globals.Style.Scale or 1
9193
Globals.Style.ItemPadding = math.ceil(Globals.Style.ItemPadding * scale)
9294
Globals.Style.ItemMargin = math.ceil(Globals.Style.ItemMargin * scale)
95+
Globals.Style.ItemSpacingX = math.ceil((Globals.Style.ItemSpacingX or Globals.Defaults.ITEM_SPACING) * scale)
96+
Globals.Style.ItemSpacingY = math.ceil((Globals.Style.ItemSpacingY or Globals.Defaults.WINDOW_CONTENT_PADDING) * scale)
9397
Globals.Style.ItemSize = math.ceil(Globals.Style.ItemSize * scale)
9498

9599
-- Scale default dimensions
@@ -98,7 +102,7 @@ Globals.Defaults.DEFAULT_H = math.ceil(Globals.Defaults.DEFAULT_H * scale)
98102
Globals.Defaults.SLIDER_WIDTH = math.ceil(Globals.Defaults.SLIDER_WIDTH * scale)
99103
Globals.Defaults.TITLE_BAR_HEIGHT = math.ceil(Globals.Defaults.TITLE_BAR_HEIGHT * scale)
100104
Globals.Defaults.WINDOW_CONTENT_PADDING = math.ceil(Globals.Defaults.WINDOW_CONTENT_PADDING * scale)
101-
Globals.Defaults.ITEM_SPACING = math.ceil(Globals.Defaults.ITEM_SPACING * scale)
105+
Globals.Defaults.ITEM_SPACING = Globals.Style.ItemSpacingX
102106
Globals.Defaults.DebugHeaderX = math.ceil(Globals.Defaults.DebugHeaderX * scale)
103107
Globals.Defaults.DebugHeaderY = math.ceil(Globals.Defaults.DebugHeaderY * scale)
104108
Globals.Defaults.DebugLineSpacing = math.ceil(Globals.Defaults.DebugLineSpacing * scale)

TimMenu/Layout/Sector.lua

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,21 @@ local Common = require("TimMenu.Common") -- EndSector might need this for DrawLi
55
local Sector = {}
66

77
-- Spacing between rows of sectors (adjust this to change vertical gap)
8-
local ROW_VERTICAL_GAP = Globals.Defaults.WINDOW_CONTENT_PADDING
8+
local function getVerticalGap()
9+
return Globals.Style.ItemSpacingY or Globals.Defaults.WINDOW_CONTENT_PADDING
10+
end
11+
912
-- Horizontal spacing after a sector completes (mirrors widget spacing)
10-
local HORIZONTAL_ITEM_SPACING = Globals.Defaults.ITEM_SPACING or 0
13+
local function getHorizontalGap()
14+
return Globals.Style.ItemSpacingX or Globals.Defaults.ITEM_SPACING or 0
15+
end
1116

1217
--[[----------------------------------------------------------------------------
1318
-- Private Helper Functions for Sector.End
1419
------------------------------------------------------------------------------]]
1520

21+
local _prepareRowState
22+
1623
local function _calculateDimensions(layoutState, pad)
1724
local currentWidth = (layoutState.maxX - layoutState.startX) + pad
1825
local currentHeight = (layoutState.maxY - layoutState.startY) + pad
@@ -117,9 +124,11 @@ end
117124

118125
local function _finalizeCursorAndLayout(win, layoutState, width, rowHeight)
119126
-- Treat sector as a single widget occupying the computed width/height
120-
win.cursorX = layoutState.startX + width + HORIZONTAL_ITEM_SPACING
127+
local horizontalSpacing = getHorizontalGap()
128+
win.cursorX = layoutState.startX + width + horizontalSpacing
121129
win.cursorY = layoutState.startY
122-
win.lineHeight = math.max(layoutState.preLineHeight or 0, rowHeight + ROW_VERTICAL_GAP)
130+
local verticalGap = getVerticalGap()
131+
win.lineHeight = math.max(layoutState.preLineHeight or 0, rowHeight + verticalGap)
123132

124133
if #win._sectorStack > 0 then
125134
local parentSector = win._sectorStack[#win._sectorStack]
@@ -128,7 +137,7 @@ local function _finalizeCursorAndLayout(win, layoutState, width, rowHeight)
128137
end
129138
end
130139

131-
local function _prepareRowState(win, layoutState)
140+
function _prepareRowState(win, layoutState)
132141
win._sectorRows = win._sectorRows or {}
133142
local depth = #win._sectorStack
134143
local rows = win._sectorRows
@@ -205,7 +214,7 @@ function Sector.Begin(win, label)
205214

206215
win.NextLine = function(self, spacing)
207216
-- Advance to next line within sector
208-
local baseSpacing = spacing or Globals.Defaults.WINDOW_CONTENT_PADDING
217+
local baseSpacing = spacing or getVerticalGap()
209218
self.cursorY = self.cursorY + self.lineHeight + baseSpacing
210219
-- Keep cursor aligned to sector's left edge
211220
self.cursorX = layoutState.startX + layoutState.padding

TimMenu/Widgets/ColorPicker.lua

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,13 @@ local function ColorPicker(win, label, initColor)
6969
draw.SetFont(Globals.Style.Font)
7070
local txtW, txtH = draw.GetTextSize(label)
7171
local padding = Globals.Style.ItemPadding
72-
local colorSize = Globals.Style.ItemSize
73-
local previewSize = colorSize + (padding * 2)
74-
local height = math.max(previewSize, txtH + (padding * 2))
72+
local extraVerticalInset = math.ceil((Globals.Style.ItemSpacingY or padding) * 0.5)
73+
local verticalInset = padding + extraVerticalInset
74+
local colorSize = math.max(Globals.Style.ItemSize, txtH)
75+
local height = colorSize + (verticalInset * 2)
76+
local previewBlockW = colorSize + (padding * 2)
7577
local arrowBoxW = height
76-
local width = previewSize + padding + txtW + padding + arrowBoxW
78+
local width = previewBlockW + padding + txtW + padding + arrowBoxW
7779

7880
local ctx = WidgetBase.Setup(win, "ColorPicker", label, width, height)
7981
local absX, absY = ctx.absX, ctx.absY
@@ -183,7 +185,7 @@ local function ColorPicker(win, label, initColor)
183185
end
184186
local mainW = width - arrowBoxW
185187
local arrowX = px + mainW
186-
local colorY = py + (height - colorSize) * 0.5
188+
local colorY = py + verticalInset
187189
local colorX = px + padding
188190
local colorX2 = colorX + colorSize
189191
Common.QueueRect(win, Globals.Layers.WidgetBackground, px, py, px + mainW, py + height, bg, nil)

TimMenu/Window.lua

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,15 +169,17 @@ function Window:AddWidget(width, height)
169169
self.H = math.max(self.H, y + self.lineHeight)
170170

171171
-- Update cursor position for the *next* widget on this line
172-
self.cursorX = self.cursorX + width + Globals.Defaults.ITEM_SPACING
172+
local horizontalSpacing = Globals.Style.ItemSpacingX or Globals.Defaults.ITEM_SPACING
173+
self.cursorX = self.cursorX + width + horizontalSpacing
173174

174175
return x, y
175176
end
176177

177178
--- Provide a simple way to "new line" to place subsequent widgets below
178179
--- Resets horizontal position and advances vertically.
179180
function Window:NextLine(spacing)
180-
spacing = spacing or Globals.Defaults.WINDOW_CONTENT_PADDING
181+
local baseSpacing = Globals.Style.ItemSpacingY or Globals.Defaults.WINDOW_CONTENT_PADDING
182+
spacing = spacing or baseSpacing
181183
self.cursorY = self.cursorY + self.lineHeight + spacing
182184
self.cursorX = Globals.Defaults.WINDOW_CONTENT_PADDING -- reset to left padding
183185
local endOfLineY = self.cursorY -- Y position *before* resetting lineHeight
@@ -188,17 +190,17 @@ end
188190

189191
--- Advances the cursor horizontally to place the next widget on the same line.
190192
function Window:SameLine(spacing)
191-
-- Default spacing is Globals.Defaults.ITEM_SPACING
192-
spacing = spacing or Globals.Defaults.ITEM_SPACING
193+
local defaultSpacing = Globals.Style.ItemSpacingX or Globals.Defaults.ITEM_SPACING
194+
spacing = spacing or defaultSpacing
193195
self.cursorX = self.cursorX + spacing -- Add specified spacing
194196
-- Note: We don't add widget width here, AddWidget already does that
195197
-- and advances cursorX *after* returning the position.
196198
end
197199

198200
--- Adds vertical spacing without resetting the horizontal cursor position.
199201
function Window:Spacing(verticalSpacing)
200-
-- Default spacing is half the content padding
201-
verticalSpacing = verticalSpacing or (Globals.Defaults.WINDOW_CONTENT_PADDING / 2)
202+
local baseSpacing = Globals.Style.ItemSpacingY or Globals.Defaults.WINDOW_CONTENT_PADDING
203+
verticalSpacing = verticalSpacing or math.floor(baseSpacing * 0.5)
202204
-- Use current line height + spacing to advance Y
203205
self.cursorY = self.cursorY + self.lineHeight + verticalSpacing
204206
self.lineHeight = 0 -- Reset line height for the *next* line that might start here

0 commit comments

Comments
 (0)