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

function Icon:_updateCaptionSize()
	-- 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
		local realText = self.captionText or ""
		local isVisible = realText ~= ""
		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
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
