DEFAULT_FORCED_GROUP_VALUES.caption=1 function Icon.setCaption(X,r)assert(typeof(r)=="\115\116\114\105\110\103"or r==nil,"\069\120\112\101\099\116\101\100 \115\116\114\105\110\103\044 \103\111\116 "..typeof(r))local v=r or""local V=v~=""X.captionText=r X.instances.captionLabel.Text=v X.instances.captionContainer.Parent=V and activeItems or X.instances.iconContainer X._maid.captionContainer=X.instances.captionContainer X:_updateIconSize(nil,X:getIconState())local I=Maid.new()X._maid.captionMaid=I if V then I:give(X.hoverStarted:Connect(function()if not X.isSelected then X:displayCaption(true)end end))I:give(X.hoverEnded:Connect(function()X:displayCaption(false)end))I:give(X.selected:Connect(function()if X.hovering then X:displayCaption(false)end end))local r=X.instances.iconContainer I:give((r:GetPropertyChangedSignal("\065\098\115\111\108\117\116\101\083\105\122\101")):Connect(function()if X.hovering then X:displayCaption()end end))I:give((r:GetPropertyChangedSignal("\065\098\115\111\108\117\116\101\080\111\115\105\116\105\111\110")):Connect(function()if X.hovering then X:displayCaption()end end))end local J=6 local e=.8 local A=.58 local Y=X:get("\105\099\111\110\083\105\122\101")local c=X:get("\099\097\112\116\105\111\110\070\111\110\116")if Y and c then local r=Y.Y.Offset local v=Y.Y.Scale local I=X.instances.iconContainer local W=X.instances.captionContainer if V then local V=r+v*I.Parent.AbsoluteSize.Y local Y=X.instances.captionLabel local G=V*e local E=G*A local H=X:_getContentText(X.captionText)local h=(textService:GetTextSize(H,E,c,Vector2.new(10000,E))).X Y.TextSize=E Y.Size=UDim2.new(0,h,A,0)W.Size=UDim2.new(0,h+J*2,0,V*e)else W.Size=UDim2.new(0,0,0,0)end end X:displayCaption(X.hovering and V)return X end function Icon.displayCaption(X,r)if userInputService.TouchEnabled and not X._draggingFinger then return end local v=8 if X._draggingFinger then v=v+THUMB_OFFSET end local V=X.instances.iconContainer local I=X.instances.captionContainer local J=UDim2.new(0,(V.AbsolutePosition.X+V.AbsoluteSize.X/2)-I.AbsoluteSize.X/2,0,(V.AbsolutePosition.Y+V.AbsoluteSize.Y*2)+v)I.Position=J local e=X.captionVisible or false if typeof(r)=="\098\111\111\108\101\097\110"then e=r end X.captionVisible=e local A=X:get("\099\097\112\116\105\111\110\070\097\100\101\073\110\102\111")for r,v in pairs(X._groupSettings.caption)do local V=X._settingsDictionary[v]V.useForcedGroupValue=not e X:_update(v)end end
-- Captions
DEFAULT_FORCED_GROUP_VALUES["caption"] = 1

function Icon:setCaption(text)
	assert(typeof(text) == "string" or text == nil, "Expected string, got " .. typeof(text))
	local realText = text or ""
	local isVisible = realText ~= ""
	self.captionText = text
	self.instances.captionLabel.Text = realText
	self.instances.captionContainer.Parent = (isVisible and activeItems) or self.instances.iconContainer
	self._maid.captionContainer = self.instances.captionContainer
	self:_updateIconSize(nil, self:getIconState())
	local captionMaid = Maid.new()
	self._maid.captionMaid = captionMaid
	if isVisible then
		captionMaid:give(self.hoverStarted:Connect(function()
			if not self.isSelected then
				self:displayCaption(true)
			end
		end))
		captionMaid:give(self.hoverEnded:Connect(function()
			self:displayCaption(false)
		end))
		captionMaid:give(self.selected:Connect(function()
			if self.hovering then
				self:displayCaption(false)
			end
		end))
		local iconContainer = self.instances.iconContainer
		captionMaid:give(iconContainer:GetPropertyChangedSignal("AbsoluteSize"):Connect(function()
			if self.hovering then
				self:displayCaption()
			end
		end))
		captionMaid:give(iconContainer:GetPropertyChangedSignal("AbsolutePosition"):Connect(function()
			if self.hovering then
				self:displayCaption()
			end
		end))
	end

	-- This adapts the caption size
	local CAPTION_X_MARGIN = 6
	local CAPTION_CONTAINER_Y_SIZE_SCALE = 0.8
	local CAPTION_LABEL_Y_SCALE = 0.58
	local iconSize = self:get("iconSize")
	local labelFont = self:get("captionFont")
	if iconSize and labelFont then
		local cellSizeYOffset = iconSize.Y.Offset
		local cellSizeYScale = iconSize.Y.Scale
		local iconContainer = self.instances.iconContainer
		local captionContainer = self.instances.captionContainer

		if isVisible then
			local cellHeight = cellSizeYOffset + (cellSizeYScale * iconContainer.Parent.AbsoluteSize.Y)
			local captionLabel = self.instances.captionLabel
			local captionContainerHeight = cellHeight * CAPTION_CONTAINER_Y_SIZE_SCALE
			local captionLabelHeight = captionContainerHeight * CAPTION_LABEL_Y_SCALE
			local iconContentText = self:_getContentText(self.captionText)
			local textWidth = textService:GetTextSize(
				iconContentText,
				captionLabelHeight,
				labelFont,
				Vector2.new(10000, captionLabelHeight)
			).X
			captionLabel.TextSize = captionLabelHeight
			captionLabel.Size = UDim2.new(0, textWidth, CAPTION_LABEL_Y_SCALE, 0)
			captionContainer.Size =
				UDim2.new(0, textWidth + CAPTION_X_MARGIN * 2, 0, cellHeight * CAPTION_CONTAINER_Y_SIZE_SCALE)
		else
			captionContainer.Size = UDim2.new(0, 0, 0, 0)
		end
	end

	self:displayCaption(self.hovering and isVisible)
	return self
end

function Icon:displayCaption(bool)
	if userInputService.TouchEnabled and not self._draggingFinger then
		return
	end
	local yOffset = 8

	-- Determine caption position
	if self._draggingFinger then
		yOffset = yOffset + THUMB_OFFSET
	end
	local iconContainer = self.instances.iconContainer
	local captionContainer = self.instances.captionContainer
	local newPos = UDim2.new(
		0,
		iconContainer.AbsolutePosition.X + iconContainer.AbsoluteSize.X / 2 - captionContainer.AbsoluteSize.X / 2,
		0,
		iconContainer.AbsolutePosition.Y + (iconContainer.AbsoluteSize.Y * 2) + yOffset
	)
	captionContainer.Position = newPos

	-- Determine caption visibility
	local isVisible = self.captionVisible or false
	if typeof(bool) == "boolean" then
		isVisible = bool
	end
	self.captionVisible = isVisible

	-- Change transparency of relavent caption instances
	local captionFadeInfo = self:get("captionFadeInfo")
	for _, settingName in pairs(self._groupSettings.caption) do
		local settingDetail = self._settingsDictionary[settingName]
		settingDetail.useForcedGroupValue = not isVisible
		self:_update(settingName)
	end
end
