DEFAULT_FORCED_GROUP_VALUES.tip=1 function Icon.setTip(U,s)assert(typeof(s)=="\115\116\114\105\110\103"or s==nil,"\069\120\112\101\099\116\101\100 \115\116\114\105\110\103\044 \103\111\116 "..typeof(s))local p=s or""local c=p~=""U.tipText=s U.instances.tipLabel.Text=p U.instances.tipFrame.Parent=c and activeItems or U.instances.iconContainer U._maid.tipFrame=U.instances.tipFrame U:_updateTipSize()local B=Maid.new()U._maid.tipMaid=B if c then B:give(U.hoverStarted:Connect(function()if not U.isSelected then U:displayTip(true)end end))B:give(U.hoverEnded:Connect(function()U:displayTip(false)end))B:give(U.selected:Connect(function()if U.hovering then U:displayTip(false)end end))end U:displayTip(U.hovering and c)return U end function Icon._updateTipSize(s)local U=s.tipText or""local p=U~=""local c=s:_getContentText(U)local B=textService:GetTextSize(c,12,Enum.Font.GothamSemibold,Vector2.new(1000,14))s.instances.tipFrame.Size=p and UDim2.new(0,B.X+6,0,20)or UDim2.new(0,0,0,0)end function Icon.displayTip(U,s)if userInputService.TouchEnabled and not U._draggingFinger then return end local p=U.tipVisible or false if typeof(s)=="\098\111\111\108\101\097\110"then p=s end U.tipVisible=p local c=U.instances.tipFrame if p then local function s(s,U)local p=s local B=U local q=workspace.CurrentCamera local f=q and q.ViewportSize if userInputService.TouchEnabled then local s=p-c.Size.X.Offset/2 local U=0 local q=f.X-c.Size.X.Offset local o=(B+THUMB_OFFSET)+60 local x=((c.AbsoluteSize.Y+THUMB_OFFSET)+64)+3 local N=f.Y-c.Size.Y.Offset p=math.clamp(s,U,q)B=math.clamp(o,x,N)elseif IconController.controllerModeEnabled then local s=TopbarPlusGui.Indicator local U=s.AbsolutePosition p=(U.X-c.Size.X.Offset/2)+s.AbsoluteSize.X/2 B=U.Y+90 else local s=p local U=0 local q=(f.X-c.Size.X.Offset)-48 local o=B local x=c.Size.Y.Offset+3 local N=f.Y p=math.clamp(s,U,q)B=math.clamp(o,x,N)end c.Position=UDim2.new(0,p,0,B-20)end local p=userInputService:GetMouseLocation()if p then s(p.X,p.Y)end U._hoveringMaid:give(U.instances.iconButton.MouseMoved:Connect(s))end for s,c in pairs(U._groupSettings.tip)do local B=U._settingsDictionary[c]B.useForcedGroupValue=not p U:_update(c)end end
-- Tips
DEFAULT_FORCED_GROUP_VALUES["tip"] = 1

function Icon:setTip(text)
	assert(typeof(text) == "string" or text == nil, "Expected string, got " .. typeof(text))
	local realText = text or ""
	local isVisible = realText ~= ""
	self.tipText = text
	self.instances.tipLabel.Text = realText
	self.instances.tipFrame.Parent = (isVisible and activeItems) or self.instances.iconContainer
	self._maid.tipFrame = self.instances.tipFrame
	self:_updateTipSize()

	local tipMaid = Maid.new()
	self._maid.tipMaid = tipMaid
	if isVisible then
		tipMaid:give(self.hoverStarted:Connect(function()
			if not self.isSelected then
				self:displayTip(true)
			end
		end))
		tipMaid:give(self.hoverEnded:Connect(function()
			self:displayTip(false)
		end))
		tipMaid:give(self.selected:Connect(function()
			if self.hovering then
				self:displayTip(false)
			end
		end))
	end
	self:displayTip(self.hovering and isVisible)
	return self
end

function Icon:_updateTipSize()
	local realText = self.tipText or ""
	local isVisible = realText ~= ""
	local iconContentText = self:_getContentText(realText)
	local textSize = textService:GetTextSize(iconContentText, 12, Enum.Font.GothamSemibold, Vector2.new(1000, 20 - 6))
	self.instances.tipFrame.Size = (isVisible and UDim2.new(0, textSize.X + 6, 0, 20)) or UDim2.new(0, 0, 0, 0)
end

function Icon:displayTip(bool)
	if userInputService.TouchEnabled and not self._draggingFinger then
		return
	end

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

	-- Have tip position track mouse or finger
	local tipFrame = self.instances.tipFrame
	if isVisible then
		-- When the user moves their cursor/finger, update tip to match the position
		local function updateTipPositon(x, y)
			local newX = x
			local newY = y
			local camera = workspace.CurrentCamera
			local viewportSize = camera and camera.ViewportSize
			if userInputService.TouchEnabled then
				--tipFrame.AnchorPoint = Vector2.new(0.5, 0.5)
				local desiredX = newX - tipFrame.Size.X.Offset / 2
				local minX = 0
				local maxX = viewportSize.X - tipFrame.Size.X.Offset
				local desiredY = newY + THUMB_OFFSET + 60
				local minY = tipFrame.AbsoluteSize.Y + THUMB_OFFSET + 64 + 3
				local maxY = viewportSize.Y - tipFrame.Size.Y.Offset
				newX = math.clamp(desiredX, minX, maxX)
				newY = math.clamp(desiredY, minY, maxY)
			elseif IconController.controllerModeEnabled then
				local indicator = TopbarPlusGui.Indicator
				local newPos = indicator.AbsolutePosition
				newX = newPos.X - tipFrame.Size.X.Offset / 2 + indicator.AbsoluteSize.X / 2
				newY = newPos.Y + 90
			else
				local desiredX = newX
				local minX = 0
				local maxX = viewportSize.X - tipFrame.Size.X.Offset - 48
				local desiredY = newY
				local minY = tipFrame.Size.Y.Offset + 3
				local maxY = viewportSize.Y
				newX = math.clamp(desiredX, minX, maxX)
				newY = math.clamp(desiredY, minY, maxY)
			end
			--local difX = tipFrame.AbsolutePosition.X - tipFrame.Position.X.Offset
			--local difY = tipFrame.AbsolutePosition.Y - tipFrame.Position.Y.Offset
			--local globalX = newX - difX
			--local globalY = newY - difY
			--tipFrame.Position = UDim2.new(0, globalX, 0, globalY-55)
			tipFrame.Position = UDim2.new(0, newX, 0, newY - 20)
		end
		local cursorLocation = userInputService:GetMouseLocation()
		if cursorLocation then
			updateTipPositon(cursorLocation.X, cursorLocation.Y)
		end
		self._hoveringMaid:give(self.instances.iconButton.MouseMoved:Connect(updateTipPositon))
	end

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