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