function Icon.setLabel(F,N,U)N=N or""F:set("\105\099\111\110\084\101\120\116",N,U)return F end function Icon.setCornerRadius(J,N,U,F)local O=J.instances.iconCorner.CornerRadius local M=UDim.new(N or O.Scale,U or O.Offset)J:set("\105\099\111\110\067\111\114\110\101\114\082\097\100\105\117\115",M,F)return J end function Icon.setImage(F,N,U)local J=tonumber(N)and"\104\116\116\112\058\047\047\119\119\119\046\114\111\098\108\111\120\046\099\111\109\047\097\115\115\101\116\047\063\105\100\061"..N or N or""return F:set("\105\099\111\110\073\109\097\103\101",J,U)end function Icon.setOrder(F,N,U)local J=tonumber(N)or 1 return F:set("\111\114\100\101\114",J,U)end function Icon.setLeft(U,N)return U:set("\097\108\105\103\110\109\101\110\116","\108\101\102\116",N)end function Icon.setMid(U,N)return U:set("\097\108\105\103\110\109\101\110\116","\109\105\100",N)end function Icon.setRight(U,N)return U:set("\097\108\105\103\110\109\101\110\116","\114\105\103\104\116",N)end function Icon.setImageYScale(F,N,U)local J=tonumber(N)or.63 return F:set("\105\099\111\110\073\109\097\103\101\089\083\099\097\108\101",J,U)end function Icon.setImageRatio(F,N,U)local J=tonumber(N)or 1 return F:set("\105\099\111\110\073\109\097\103\101\082\097\116\105\111",J,U)end function Icon.setLabelYScale(F,N,U)local J=tonumber(N)or.45 return F:set("\105\099\111\110\076\097\098\101\108\089\083\099\097\108\101",J,U)end function Icon.setBaseZIndex(F,N,U)local J=tonumber(N)or 1 return F:set("\098\097\115\101\090\073\110\100\101\120",J,U)end function Icon._updateBaseZIndex(U,N)local F=U.instances.iconContainer local J=tonumber(N)or F.ZIndex local O=J-F.ZIndex if O==0 then return"\084\104\101 \098\097\115\101\086\097\108\117\101 \105\115 \116\104\101 \115\097\109\101"end for N,U in pairs(U.instances)do U.ZIndex=U.ZIndex+O end return true end function Icon.setSize(J,N,U,F)local O=tonumber(N)or 32 local M=tonumber(U)or O J:set("\102\111\114\099\101\100\073\099\111\110\083\105\122\101",UDim2.new(0,O,0,M),F)J:set("\105\099\111\110\083\105\122\101",UDim2.new(0,O,0,M),F)return J end function Icon._updateIconSize(F,N,U)if F._destroyed then return end local J=12 local O=8 local M={iconImage=F:get("\105\099\111\110\073\109\097\103\101",U)or"\095\078\073\076",iconText=F:get("\105\099\111\110\084\101\120\116",U)or"\095\078\073\076";iconFont=F:get("\105\099\111\110\070\111\110\116",U)or"\095\078\073\076";iconSize=F:get("\105\099\111\110\083\105\122\101",U)or"\095\078\073\076",forcedIconSize=F:get("\102\111\114\099\101\100\073\099\111\110\083\105\122\101",U)or"\095\078\073\076",iconImageYScale=F:get("\105\099\111\110\073\109\097\103\101\089\083\099\097\108\101",U)or"\095\078\073\076",iconImageRatio=F:get("\105\099\111\110\073\109\097\103\101\082\097\116\105\111",U)or"\095\078\073\076";iconLabelYScale=F:get("\105\099\111\110\076\097\098\101\108\089\083\099\097\108\101",U)or"\095\078\073\076"}for N,U in pairs(M)do if U=="\095\078\073\076"then return end end local z=F.instances.iconContainer if not z.Parent then return end local e=M.iconSize.X.Offset local v=M.iconSize.X.Scale local w=e+v*z.Parent.AbsoluteSize.X local b=M.forcedIconSize.X.Offset local S=v>0 and w or 9999 local s=M.iconSize.Y.Offset local a=M.iconSize.Y.Scale local Y=s+a*z.Parent.AbsoluteSize.Y local j=Y*M.iconLabelYScale local C=(textService:GetTextSize(M.iconText,j,M.iconFont,Vector2.new(10000,j))).X local W=(Y*M.iconImageYScale)*M.iconImageRatio local g=M.iconImage~=""local B=M.iconText~=""local t=.5 local X local m=j/2 if g and not B then t=.45 F:set("\105\099\111\110\073\109\097\103\101\086\105\115\105\098\108\101",true,U)F:set("\105\099\111\110\073\109\097\103\101\065\110\099\104\111\114\080\111\105\110\116",Vector2.new(.5,.5),U)F:set("\105\099\111\110\073\109\097\103\101\080\111\115\105\116\105\111\110",UDim2.new(.5,0,.5,0),U)F:set("\105\099\111\110\073\109\097\103\101\083\105\122\101",UDim2.new(M.iconImageYScale*M.iconImageRatio,0,M.iconImageYScale,0),U)F:set("\105\099\111\110\076\097\098\101\108\086\105\115\105\098\108\101",false,U)elseif not g and B then X=C+J*2 F:set("\105\099\111\110\076\097\098\101\108\086\105\115\105\098\108\101",true,U)F:set("\105\099\111\110\076\097\098\101\108\065\110\099\104\111\114\080\111\105\110\116",Vector2.new(0,.5),U)F:set("\105\099\111\110\076\097\098\101\108\080\111\115\105\116\105\111\110",UDim2.new(0,J,.5,0),U)F:set("\105\099\111\110\076\097\098\101\108\083\105\122\101",UDim2.new(1,-J*2,M.iconLabelYScale,m),U)F:set("\105\099\111\110\076\097\098\101\108\084\101\120\116\088\065\108\105\103\110\109\101\110\116",Enum.TextXAlignment.Center,U)F:set("\105\099\111\110\073\109\097\103\101\086\105\115\105\098\108\101",false,U)elseif g and B then local N=(J+W)+O X=(N+C)+J F:set("\105\099\111\110\073\109\097\103\101\086\105\115\105\098\108\101",true,U)F:set("\105\099\111\110\073\109\097\103\101\065\110\099\104\111\114\080\111\105\110\116",Vector2.new(0,.5),U)F:set("\105\099\111\110\073\109\097\103\101\080\111\115\105\116\105\111\110",UDim2.new(0,J,.5,0),U)F:set("\105\099\111\110\073\109\097\103\101\083\105\122\101",UDim2.new(0,W,M.iconImageYScale,0),U)F:set("\105\099\111\110\076\097\098\101\108\086\105\115\105\098\108\101",true,U)F:set("\105\099\111\110\076\097\098\101\108\065\110\099\104\111\114\080\111\105\110\116",Vector2.new(0,.5),U)F:set("\105\099\111\110\076\097\098\101\108\080\111\115\105\116\105\111\110",UDim2.new(0,N,.5,0),U)F:set("\105\099\111\110\076\097\098\101\108\083\105\122\101",UDim2.new(1,-N-J,M.iconLabelYScale,m),U)F:set("\105\099\111\110\076\097\098\101\108\084\101\120\116\088\065\108\105\103\110\109\101\110\116",Enum.TextXAlignment.Left,U)end if X then if not F._updatingIconSize then F._updatingIconSize=true local N=v>0 and v or 0 local J=v>0 and 0 or math.clamp(X,b,S)F:set("\105\099\111\110\083\105\122\101",UDim2.new(N,J,M.iconSize.Y.Scale,M.iconSize.Y.Offset),U,"\095\105\103\110\111\114\101\080\114\101\118\105\111\117\115")F._updatingIconSize=false end end F:set("\105\099\111\110\076\097\098\101\108\084\101\120\116\083\105\122\101",j,U)F:set("\110\111\116\105\099\101\070\114\097\109\101\080\111\115\105\116\105\111\110",UDim2.new(t,0,0,-2),U)F._updatingIconSize=false end
-- TOGGLEABLE METHODS
function Icon:setLabel(text, iconState)
	text = text or ""
	self:set("iconText", text, iconState)
	return self
end

function Icon:setCornerRadius(scale, offset, iconState)
	local oldCornerRadius = self.instances.iconCorner.CornerRadius
	local newCornerRadius = UDim.new(scale or oldCornerRadius.Scale, offset or oldCornerRadius.Offset)
	self:set("iconCornerRadius", newCornerRadius, iconState)
	return self
end

function Icon:setImage(imageId, iconState)
	local textureId = (tonumber(imageId) and "http://www.roblox.com/asset/?id=" .. imageId) or imageId or ""
	return self:set("iconImage", textureId, iconState)
end

function Icon:setOrder(order, iconState)
	local newOrder = tonumber(order) or 1
	return self:set("order", newOrder, iconState)
end

function Icon:setLeft(iconState)
	return self:set("alignment", "left", iconState)
end

function Icon:setMid(iconState)
	return self:set("alignment", "mid", iconState)
end

function Icon:setRight(iconState)
	return self:set("alignment", "right", iconState)
end

function Icon:setImageYScale(YScale, iconState)
	local newYScale = tonumber(YScale) or 0.63
	return self:set("iconImageYScale", newYScale, iconState)
end

function Icon:setImageRatio(ratio, iconState)
	local newRatio = tonumber(ratio) or 1
	return self:set("iconImageRatio", newRatio, iconState)
end

function Icon:setLabelYScale(YScale, iconState)
	local newYScale = tonumber(YScale) or 0.45
	return self:set("iconLabelYScale", newYScale, iconState)
end

function Icon:setBaseZIndex(ZIndex, iconState)
	local newBaseZIndex = tonumber(ZIndex) or 1
	return self:set("baseZIndex", newBaseZIndex, iconState)
end

function Icon:_updateBaseZIndex(baseValue)
	local container = self.instances.iconContainer
	local newBaseValue = tonumber(baseValue) or container.ZIndex
	local difference = newBaseValue - container.ZIndex
	if difference == 0 then
		return "The baseValue is the same"
	end
	for _, object in pairs(self.instances) do
		object.ZIndex = object.ZIndex + difference
	end
	return true
end

function Icon:setSize(XOffset, YOffset, iconState)
	local newXOffset = tonumber(XOffset) or 32
	local newYOffset = tonumber(YOffset) or newXOffset
	self:set("forcedIconSize", UDim2.new(0, newXOffset, 0, newYOffset), iconState)
	self:set("iconSize", UDim2.new(0, newXOffset, 0, newYOffset), iconState)
	return self
end

function Icon:_updateIconSize(_, iconState)
	if self._destroyed then
		return
	end
	-- This is responsible for handling the appearance and size of the icons label and image, in additon to its own size
	local X_MARGIN = 12
	local X_GAP = 8

	local values = {
		iconImage = self:get("iconImage", iconState) or "_NIL",
		iconText = self:get("iconText", iconState) or "_NIL",
		iconFont = self:get("iconFont", iconState) or "_NIL",
		iconSize = self:get("iconSize", iconState) or "_NIL",
		forcedIconSize = self:get("forcedIconSize", iconState) or "_NIL",
		iconImageYScale = self:get("iconImageYScale", iconState) or "_NIL",
		iconImageRatio = self:get("iconImageRatio", iconState) or "_NIL",
		iconLabelYScale = self:get("iconLabelYScale", iconState) or "_NIL",
	}
	for k, v in pairs(values) do
		if v == "_NIL" then
			return
		end
	end

	local iconContainer = self.instances.iconContainer
	if not iconContainer.Parent then
		return
	end

	-- We calculate the cells dimensions as apposed to reading because there's a possibility the cells dimensions were changed at the exact time and have not yet updated
	-- this essentially saves us from waiting a heartbeat which causes additonal complications
	local cellSizeXOffset = values.iconSize.X.Offset
	local cellSizeXScale = values.iconSize.X.Scale
	local cellWidth = cellSizeXOffset + (cellSizeXScale * iconContainer.Parent.AbsoluteSize.X)
	local minCellWidth = values.forcedIconSize.X.Offset --cellWidth
	local maxCellWidth = (cellSizeXScale > 0 and cellWidth) or 9999
	local cellSizeYOffset = values.iconSize.Y.Offset
	local cellSizeYScale = values.iconSize.Y.Scale
	local cellHeight = cellSizeYOffset + (cellSizeYScale * iconContainer.Parent.AbsoluteSize.Y)
	local labelHeight = cellHeight * values.iconLabelYScale
	local labelWidth =
		textService:GetTextSize(values.iconText, labelHeight, values.iconFont, Vector2.new(10000, labelHeight)).X
	local imageWidth = cellHeight * values.iconImageYScale * values.iconImageRatio

	local usingImage = values.iconImage ~= ""
	local usingText = values.iconText ~= ""
	local notifPosYScale = 0.5
	local desiredCellWidth
	local preventClippingOffset = labelHeight / 2

	if usingImage and not usingText then
		notifPosYScale = 0.45
		self:set("iconImageVisible", true, iconState)
		self:set("iconImageAnchorPoint", Vector2.new(0.5, 0.5), iconState)
		self:set("iconImagePosition", UDim2.new(0.5, 0, 0.5, 0), iconState)
		self:set(
			"iconImageSize",
			UDim2.new(values.iconImageYScale * values.iconImageRatio, 0, values.iconImageYScale, 0),
			iconState
		)
		self:set("iconLabelVisible", false, iconState)
	elseif not usingImage and usingText then
		desiredCellWidth = labelWidth + (X_MARGIN * 2)
		self:set("iconLabelVisible", true, iconState)
		self:set("iconLabelAnchorPoint", Vector2.new(0, 0.5), iconState)
		self:set("iconLabelPosition", UDim2.new(0, X_MARGIN, 0.5, 0), iconState)
		self:set("iconLabelSize", UDim2.new(1, -X_MARGIN * 2, values.iconLabelYScale, preventClippingOffset), iconState)
		self:set("iconLabelTextXAlignment", Enum.TextXAlignment.Center, iconState)
		self:set("iconImageVisible", false, iconState)
	elseif usingImage and usingText then
		local labelGap = X_MARGIN + imageWidth + X_GAP
		desiredCellWidth = labelGap + labelWidth + X_MARGIN
		self:set("iconImageVisible", true, iconState)
		self:set("iconImageAnchorPoint", Vector2.new(0, 0.5), iconState)
		self:set("iconImagePosition", UDim2.new(0, X_MARGIN, 0.5, 0), iconState)
		self:set("iconImageSize", UDim2.new(0, imageWidth, values.iconImageYScale, 0), iconState)
		----
		self:set("iconLabelVisible", true, iconState)
		self:set("iconLabelAnchorPoint", Vector2.new(0, 0.5), iconState)
		self:set("iconLabelPosition", UDim2.new(0, labelGap, 0.5, 0), iconState)
		self:set(
			"iconLabelSize",
			UDim2.new(1, -labelGap - X_MARGIN, values.iconLabelYScale, preventClippingOffset),
			iconState
		)
		self:set("iconLabelTextXAlignment", Enum.TextXAlignment.Left, iconState)
	end
	if desiredCellWidth then
		if not self._updatingIconSize then
			self._updatingIconSize = true
			local widthScale = (cellSizeXScale > 0 and cellSizeXScale) or 0
			local widthOffset = (cellSizeXScale > 0 and 0) or math.clamp(desiredCellWidth, minCellWidth, maxCellWidth)
			self:set(
				"iconSize",
				UDim2.new(widthScale, widthOffset, values.iconSize.Y.Scale, values.iconSize.Y.Offset),
				iconState,
				"_ignorePrevious"
			)
			self._updatingIconSize = false
		end
	end
	self:set("iconLabelTextSize", labelHeight, iconState)
	self:set("noticeFramePosition", UDim2.new(notifPosYScale, 0, 0, -2), iconState)

	self._updatingIconSize = false
end
