@@ -4,6 +4,7 @@ local Utils = require("TimMenu.Utils")
44local Interaction = require (" TimMenu.Interaction" )
55local DrawHelpers = require (" TimMenu.DrawHelpers" )
66local DrawManager = require (" TimMenu.DrawManager" )
7+ local WidgetBase = require (" TimMenu.WidgetBase" )
78
89-- HSV to RGB conversion
910local function hsvToRGB (h , s , v )
@@ -68,24 +69,17 @@ local function ColorPicker(win, label, initColor)
6869 draw .SetFont (Globals .Style .Font )
6970 local txtW , txtH = draw .GetTextSize (label )
7071 local padding = Globals .Style .ItemPadding
71- local boxSize = Globals .Style .ItemSize + ( padding * 2 )
72- local arrowBoxW = boxSize
73- local extraPadding = padding
74- local width = boxSize + padding + txtW + extraPadding + arrowBoxW
75- local height = boxSize
72+ local colorSize = Globals .Style .ItemSize
73+ local previewSize = colorSize + ( padding * 2 )
74+ local height = math.max ( previewSize , txtH + ( padding * 2 ))
75+ local arrowBoxW = height
76+ local width = previewSize + padding + txtW + padding + arrowBoxW
7677
77- if win .cursorX > Globals .Defaults .WINDOW_CONTENT_PADDING then
78- win .cursorX = win .cursorX + padding
79- end
80- local x , y = win :AddWidget (width , height )
81- local absX , absY = win .X + x , win .Y + y
78+ local ctx = WidgetBase .Setup (win , " ColorPicker" , label , width , height )
79+ local absX , absY = ctx .absX , ctx .absY
8280
8381 -- State management
84- local stateKey = win .id .. " :ColorPicker:" .. label
85- win ._widgetCounter = (win ._widgetCounter or 0 ) + 1
86- local widgetKey = stateKey .. " :" .. win ._widgetCounter
87-
88- local state = Utils .GetState (win , stateKey , {
82+ local state = Utils .GetState (win , ctx .widgetKey , {
8983 open = false ,
9084 hue = 0 ,
9185 sat = 0 ,
@@ -112,8 +106,8 @@ local function ColorPicker(win, label, initColor)
112106 }
113107
114108 -- Interaction
115- local bounds = { x = absX , y = absY , w = width , h = height }
116- local hovered , pressed , clicked = Interaction . Process ( win , widgetKey , bounds , state .open )
109+ local bounds = ctx . bounds
110+ local hovered , pressed , clicked = WidgetBase . ProcessInteraction ( ctx , state .open )
117111
118112 -- Maintain popup blocked regions while open
119113 if state .open then
@@ -159,7 +153,7 @@ local function ColorPicker(win, label, initColor)
159153 -- Alpha slider interaction
160154 local sliderBounds =
161155 { x = popupBounds .x , y = popupBounds .y + imageData .height , w = popupBounds .w , h = sliderHeight }
162- local _ , sPressed = Interaction .Process (win , widgetKey .. " :alpha" , sliderBounds , state .open )
156+ local _ , sPressed = Interaction .Process (win , ctx . widgetKey .. " :alpha" , sliderBounds , state .open )
163157 if sPressed then
164158 local mx2 , _ = table.unpack (input .GetMousePos ())
165159 local newA = math.floor (((mx2 - sliderBounds .x ) / sliderBounds .w ) * 255 )
@@ -188,13 +182,17 @@ local function ColorPicker(win, label, initColor)
188182 bg = Globals .Colors .ItemHover
189183 end
190184 local mainW = width - arrowBoxW
185+ local arrowX = px + mainW
186+ local colorY = py + (height - colorSize ) * 0.5
187+ local colorX = px + padding
188+ local colorX2 = colorX + colorSize
191189 Common .QueueRect (win , Globals .Layers .WidgetBackground , px , py , px + mainW , py + height , bg , nil )
192190 Common .QueueRect (
193191 win ,
194192 Globals .Layers .WidgetBackground ,
195- px + mainW ,
193+ arrowX ,
196194 py ,
197- px + width ,
195+ arrowX + arrowBoxW ,
198196 py + height ,
199197 Globals .Colors .ArrowBoxBg ,
200198 nil
@@ -213,17 +211,17 @@ local function ColorPicker(win, label, initColor)
213211 Common .QueueRect (
214212 win ,
215213 Globals .Layers .WidgetFill ,
216- px + padding ,
217- py + padding ,
218- px + boxSize - padding ,
219- py + boxSize - padding ,
214+ colorX ,
215+ colorY ,
216+ colorX2 ,
217+ colorY + colorSize ,
220218 state .color ,
221219 nil
222220 )
223221 Common .QueueText (
224222 win ,
225223 Globals .Layers .WidgetText ,
226- px + boxSize + padding ,
224+ colorX2 + padding ,
227225 py + (height - txtH ) * 0.5 ,
228226 label ,
229227 Globals .Colors .Text
@@ -233,7 +231,7 @@ local function ColorPicker(win, label, initColor)
233231 draw .SetFont (Globals .Style .Font )
234232 local arrowCharW , arrowCharH = draw .GetTextSize (" ▼" )
235233 local triW , triH = arrowCharW * 0.5 , arrowCharH * 0.5
236- local triX = px + mainW + (arrowBoxW - triW ) / 2
234+ local triX = arrowX + (arrowBoxW - triW ) / 2
237235 local triY = py + (height - triH ) / 2
238236 win :QueueDrawAtLayer (Globals .Layers .WidgetText , function ()
239237 DrawHelpers .DrawArrow (triX , triY , triW , triH , state .open and " up" or " down" , Globals .Colors .Text )
0 commit comments