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

	-- 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 textWidth = textService:GetTextSize(self.captionText, 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
