@@ -13,34 +13,11 @@ local kMinLabelWidth = GuiUtilities.kCheckboxMinLabelWidth
1313local kMinMargin = GuiUtilities .kCheckboxMinMargin
1414local kMinButtonWidth = kCheckboxWidth ;
1515
16- local kMinLabelSize = UDim2 .new (0 , kMinLabelWidth , 0 , kMinHeight )
17- local kMinLabelPos = UDim2 .new (0 , kMinButtonWidth + kMinMargin , 0 , kMinHeight / 2 )
18-
19- local kMinButtonSize = UDim2 .new (0 , kMinButtonWidth , 0 , kMinButtonWidth )
20- local kMinButtonPos = UDim2 .new (0 , 0 , 0 , kMinHeight / 2 )
21-
22- local kCheckImageWidth = kMinMargin
23- local kMinCheckImageWidth = kCheckImageWidth
24-
25- local kCheckImageSize = UDim2 .new (0 , kCheckImageWidth , 0 , kCheckImageWidth )
26- local kMinCheckImageSize = UDim2 .new (0 , kMinCheckImageWidth , 0 , kMinCheckImageWidth )
27-
28- local kEnabledCheckImage = " rbxasset://textures/DeveloperFramework/checkbox_checked_light.png"
29- local kDisabledCheckImage = " rbxasset://textures/DeveloperFramework/checkbox_indeterminate_light.png"
30- local kHoverCheckImage = " rbxasset://textures/DeveloperFramework/checkbox_unchecked_hover_light.png"
31- local kCheckboxFrameImage = " rbxasset://textures/DeveloperFramework/checkbox_unchecked_light.png"
32-
33- local kEnabledCheckImageDark = " rbxasset://textures/DeveloperFramework/checkbox_checked_dark.png"
34- local kDisabledCheckImageDark = " rbxasset://textures/DeveloperFramework/checkbox_indeterminate_dark.png"
35- local kHoverCheckImageDark = " rbxasset://textures/DeveloperFramework/checkbox_unchecked_hover_dark.png"
36- local kCheckboxFrameImageDark = " rbxasset://textures/DeveloperFramework/checkbox_unchecked_dark.png"
37-
3816LabeledButtonClass = {}
3917LabeledButtonClass .__index = LabeledButtonClass
4018
4119LabeledButtonClass .kMinFrameSize = UDim2 .new (0 , kMinLabelWidth + kMinMargin + kMinButtonWidth , 0 , kMinHeight )
4220
43-
4421function LabeledButtonClass .new (nameSuffix , labelText , initValue , initDisabled )
4522 local self = {}
4623 setmetatable (self , LabeledButtonClass )
@@ -49,47 +26,39 @@ function LabeledButtonClass.new(nameSuffix, labelText, initValue, initDisabled)
4926 local initDisabled = not not initDisabled
5027
5128 local frame = GuiUtilities .MakeDefaultFixedHeightFrame (" CBF" .. nameSuffix )
29+ frame .Size = UDim2 .new (1 , 0 , GuiUtilities .kDefaultPropertyHeight , 0 )
5230
5331 local fullBackgroundButton = Instance .new (" TextButton" )
5432 fullBackgroundButton .Name = " FullBackground"
5533 fullBackgroundButton .Parent = frame
56- fullBackgroundButton .BackgroundTransparency = 1
57- fullBackgroundButton .Size = UDim2 .new (1 , 0 , 1 , 0 )
34+ fullBackgroundButton .BorderSizePixel = 0
35+ fullBackgroundButton .BackgroundTransparency = 0
36+ fullBackgroundButton .Size = UDim2 .new (0 , GuiUtilities .DefaultLineLabelWidth , 1 , 0 )
5837 fullBackgroundButton .Position = UDim2 .new (0 , 0 , 0 , 0 )
5938 fullBackgroundButton .Text = " "
60-
61- local label = GuiUtilities .MakeDefaultPropertyLabel (labelText , true )
39+ fullBackgroundButton .AutoButtonColor = false
40+
41+ local label = Instance .new (" TextButton" )
42+ label .Text = labelText
43+ label .RichText = true
44+ label .Name = ' Label'
45+ label .Font = GuiUtilities .kDefaultFontFace
46+ label .TextSize = GuiUtilities .kDefaultFontSize
47+ label .BackgroundTransparency = 1
48+ label .TextXAlignment = Enum .TextXAlignment .Center
49+ label .AnchorPoint = Vector2 .new (0.5 , 0.5 )
50+ label .AutoButtonColor = false
51+ label .Position = UDim2 .new (0.5 , 0 , 0.5 , GuiUtilities .kTextVerticalFudge )
52+ label .Size = UDim2 .new (1 , 0 , 1 , 0 )
6253 label .Parent = fullBackgroundButton
6354
64- local button = Instance .new (' ImageButton' )
65- button .Name = ' Button'
66- button .Size = UDim2 .new (0 , kCheckboxWidth , 0 , kCheckboxWidth )
67- button .AnchorPoint = Vector2 .new (0 , .5 )
68- button .BackgroundTransparency = 1
69- button .Position = UDim2 .new (0 , GuiUtilities .DefaultLineElementLeftMargin , .5 , 0 )
70- button .Parent = fullBackgroundButton
71- button .BorderSizePixel = 0
72- button .AutoButtonColor = false
73-
74- local checkImage = Instance .new (" ImageLabel" )
75- checkImage .Name = " CheckImage"
76- checkImage .Parent = button
77- checkImage .Visible = false
78- checkImage .Size = kCheckImageSize
79- checkImage .AnchorPoint = Vector2 .new (0.5 , 0.5 )
80- checkImage .Position = UDim2 .new (0.5 , 0 , 0.5 , 0 )
81- checkImage .BackgroundTransparency = 1
82- checkImage .BorderSizePixel = 0
83-
8455 self ._frame = frame
85- self ._button = button
8656 self ._label = label
8757
8858 self ._clicked = false
8959 self ._hovered = false
9060
91- self ._checkImage = checkImage
92- self ._fullBackgroundButton = fullBackgroundButton
61+ self ._button = fullBackgroundButton
9362 self ._useDisabledOverride = false
9463 self ._disabledOverride = false
9564 self :SetDisabled (initDisabled )
@@ -99,26 +68,6 @@ function LabeledButtonClass.new(nameSuffix, labelText, initValue, initDisabled)
9968
10069 self :_SetupMouseClickHandling ()
10170
102- local function updateImages ()
103- if (GuiUtilities :ShouldUseIconsForDarkerBackgrounds ()) then
104- self ._button .Image = kCheckboxFrameImageDark
105- if self ._checkImage .Image == kDisabledCheckImage then
106- self ._checkImage .Image = kDisabledCheckImageDark
107- else
108- self ._checkImage .Image = kEnabledCheckImageDark
109- end
110- else
111- self ._button .Image = kCheckboxFrameImage
112- if self ._checkImage .Image == kDisabledCheckImageDark then
113- self ._checkImage .Image = kDisabledCheckImage
114- else
115- self ._checkImage .Image = kEnabledCheckImage
116- end
117- end
118- end
119- settings ().Studio .ThemeChanged :Connect (updateImages )
120- updateImages ()
121-
12271 local function updateFontColors ()
12372 self :UpdateFontColors ()
12473 end
@@ -132,72 +81,69 @@ function LabeledButtonClass:_MaybeToggleState()
13281 if not self ._disabled then
13382 self :SetValue (not self ._value )
13483 end
84+
13585end
13686
13787function LabeledButtonClass :_SetupMouseClickHandling ()
138- self ._button .MouseButton1Down :Connect (function ()
139- self ._clicked = true
140- self :_MaybeToggleState ()
141- end )
142-
143- self ._fullBackgroundButton .InputBegan :Connect (function (input )
88+ self ._label .InputBegan :Connect (function (input )
14489 if (input .UserInputType == Enum .UserInputType .MouseMovement ) then
14590 self ._hovered = true
14691 self :_updateCheckboxVisual ()
14792 end
14893 end )
14994
150- self ._fullBackgroundButton .InputEnded :Connect (function (input )
95+ self ._label .InputEnded :Connect (function (input )
15196 if (input .UserInputType == Enum .UserInputType .MouseMovement ) then
15297 self ._hovered = false
15398 self ._clicked = false
15499 self :_updateCheckboxVisual ()
155100 end
156101 end )
157102
158- self ._fullBackgroundButton .MouseButton1Down :Connect (function ()
103+ self ._label .MouseButton1Down :Connect (function ()
159104 self ._clicked = true
160105 self :_updateCheckboxVisual ()
161106 self :_MaybeToggleState ()
162107 end )
163108end
164109
165- -- Too buggy with other GuiObjects to be used.
166- function LabeledButtonClass :_updateCheckboxVisual ()
167- -- if (self._clicked) then
168- -- self._button.Image = kCheckboxFrameImage
169- -- elseif (self._hovered) then
170- -- self._button.Image = kHoverCheckImage
171- -- else
172- -- self._button.Image = kCheckboxFrameImage
173- -- end
174- end
175-
176110function LabeledButtonClass :_HandleUpdatedValue ()
177- self ._checkImage .Visible = self :GetValue ()
111+ self ._button .Visible = self :GetValue ()
178112
179113 if (self ._valueChangedFunction ) then
180114 self ._valueChangedFunction (self :GetValue ())
181115 end
182116end
183117
184- -- Small checkboxes are a different entity.
185- -- All the bits are smaller.
186- -- Fixed width instead of flood-fill.
187- -- Box comes first, then label.
188- function LabeledButtonClass :UseSmallSize ()
189- self ._label .TextSize = kMinTextSize
190- self ._label .Size = kMinLabelSize
191- self ._label .Position = kMinLabelPos
192- self ._label .TextXAlignment = Enum .TextXAlignment .Left
193-
194- self ._button .Size = kMinButtonSize
195- self ._button .Position = kMinButtonPos
118+ -- Too buggy with other GuiObjects to be used.
119+ function LabeledButtonClass :_updateCheckboxVisual ()
120+ local kButtonDefaultBackgroundColor = settings ().Studio .Theme :GetColor (Enum .StudioStyleGuideColor .Button , Enum .StudioStyleGuideModifier .Default )
121+ local kButtonHoverBackgroundColor = settings ().Studio .Theme :GetColor (Enum .StudioStyleGuideColor .Button , Enum .StudioStyleGuideModifier .Hover )
122+ local kButtonPressedBackgroundColor = settings ().Studio .Theme :GetColor (Enum .StudioStyleGuideColor .Button , Enum .StudioStyleGuideModifier .Pressed )
123+
124+ if (self ._value ) then
125+ self ._button .BackgroundColor3 = kButtonPressedBackgroundColor
126+ elseif (self ._clicked ) then
127+ self ._button .BackgroundColor3 = kButtonPressedBackgroundColor
128+ elseif (self ._hovered ) then
129+ self ._button .BackgroundColor3 = kButtonHoverBackgroundColor
130+ else
131+ self ._button .BackgroundColor3 = kButtonDefaultBackgroundColor
132+ end
133+ end
196134
197- self ._checkImage .Size = kMinCheckImageSize
135+ function LabeledButtonClass :_HandleUpdatedValue ()
136+ if (self :GetValue ())then
137+ kButtonBackgroundColor = settings ().Studio .Theme :GetColor (Enum .StudioStyleGuideColor .Button , Enum .StudioStyleGuideModifier .Pressed )
138+ self ._button .BackgroundColor3 = kButtonBackgroundColor
139+ else
140+ kButtonBackgroundColor = settings ().Studio .Theme :GetColor (Enum .StudioStyleGuideColor .Button , Enum .StudioStyleGuideModifier .Default )
141+ self ._button .BackgroundColor3 = kButtonBackgroundColor
142+ end
198143
199- self ._frame .Size = LabeledButtonClass .kMinFrameSize
200- self ._frame .BackgroundTransparency = 1
144+ if (self ._valueChangedFunction ) then
145+ self ._valueChangedFunction (self :GetValue ())
146+ end
201147end
202148
203149function LabeledButtonClass :GetFrame ()
@@ -240,20 +186,6 @@ function LabeledButtonClass:SetDisabled(newDisabled)
240186 self ._useDisabledOverride = false
241187 end
242188
243- if (newDisabled ) then
244- if (GuiUtilities :ShouldUseIconsForDarkerBackgrounds ()) then
245- self ._checkImage .Image = kDisabledCheckImageDark
246- else
247- self ._checkImage .Image = kDisabledCheckImage
248- end
249- else
250- if (GuiUtilities :ShouldUseIconsForDarkerBackgrounds ()) then
251- self ._checkImage .Image = kEnabledCheckImageDark
252- else
253- self ._checkImage .Image = kEnabledCheckImage
254- end
255- end
256-
257189 self :UpdateFontColors ()
258190 self ._button .BackgroundColor3 = self ._disabled and GuiUtilities .kButtonDisabledBackgroundColor or GuiUtilities .kButtonDefaultBackgroundColor
259191 self ._button .BorderColor3 = self ._disabled and GuiUtilities .kButtonDisabledBorderColor or GuiUtilities .kButtonDefaultBorderColor
0 commit comments