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

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
