function Icon.setLabel(U,L,c)L=L or""U:set("\105\099\111\110\084\101\120\116",L,c)return U end function Icon.setCornerRadius(M,L,c,U)local r=M.instances.iconCorner.CornerRadius local W=UDim.new(L or r.Scale,c or r.Offset)M:set("\105\099\111\110\067\111\114\110\101\114\082\097\100\105\117\115",W,U)return M end function Icon.setImage(U,L,c)local M=tonumber(L)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"..L or L or""return U:set("\105\099\111\110\073\109\097\103\101",M,c)end function Icon.setOrder(U,L,c)local M=tonumber(L)or 1 return U:set("\111\114\100\101\114",M,c)end function Icon.setLeft(c,L)return c:set("\097\108\105\103\110\109\101\110\116","\108\101\102\116",L)end function Icon.setMid(c,L)return c:set("\097\108\105\103\110\109\101\110\116","\109\105\100",L)end function Icon.setRight(c,L)return c:set("\097\108\105\103\110\109\101\110\116","\114\105\103\104\116",L)end function Icon.setImageYScale(U,L,c)local M=tonumber(L)or.63 return U:set("\105\099\111\110\073\109\097\103\101\089\083\099\097\108\101",M,c)end function Icon.setImageRatio(U,L,c)local M=tonumber(L)or 1 return U:set("\105\099\111\110\073\109\097\103\101\082\097\116\105\111",M,c)end function Icon.setLabelYScale(U,L,c)local M=tonumber(L)or.45 return U:set("\105\099\111\110\076\097\098\101\108\089\083\099\097\108\101",M,c)end function Icon.setBaseZIndex(U,L,c)local M=tonumber(L)or 1 return U:set("\098\097\115\101\090\073\110\100\101\120",M,c)end function Icon._updateBaseZIndex(c,L)local U=c.instances.iconContainer local M=tonumber(L)or U.ZIndex local r=M-U.ZIndex if r==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 L,c in pairs(c.instances)do c.ZIndex=c.ZIndex+r end return true end function Icon.setSize(M,L,c,U)local r=tonumber(L)or 32 local W=tonumber(c)or r M:set("\102\111\114\099\101\100\073\099\111\110\083\105\122\101",UDim2.new(0,r,0,W),U)M:set("\105\099\111\110\083\105\122\101",UDim2.new(0,r,0,W),U)return M end function Icon._updateIconSize(U,L,c)if U._destroyed then return end local M=12 local r=8 local W={iconImage=U:get("\105\099\111\110\073\109\097\103\101",c)or"\095\078\073\076";iconText=U:get("\105\099\111\110\084\101\120\116",c)or"\095\078\073\076";iconFont=U:get("\105\099\111\110\070\111\110\116",c)or"\095\078\073\076";iconSize=U:get("\105\099\111\110\083\105\122\101",c)or"\095\078\073\076";forcedIconSize=U:get("\102\111\114\099\101\100\073\099\111\110\083\105\122\101",c)or"\095\078\073\076";iconImageYScale=U:get("\105\099\111\110\073\109\097\103\101\089\083\099\097\108\101",c)or"\095\078\073\076",iconImageRatio=U:get("\105\099\111\110\073\109\097\103\101\082\097\116\105\111",c)or"\095\078\073\076";iconLabelYScale=U:get("\105\099\111\110\076\097\098\101\108\089\083\099\097\108\101",c)or"\095\078\073\076"}for L,c in pairs(W)do if c=="\095\078\073\076"then return end end local A=U.instances.iconContainer if not A.Parent then return end local q=W.iconSize.X.Offset local t=W.iconSize.X.Scale local o=q+t*A.Parent.AbsoluteSize.X local N=W.forcedIconSize.X.Offset local O=t>0 and o or 9999 local z=W.iconSize.Y.Offset local R=W.iconSize.Y.Scale local d=z+R*A.Parent.AbsoluteSize.Y local K=d*W.iconLabelYScale local x=(textService:GetTextSize(W.iconText,K,W.iconFont,Vector2.new(10000,K))).X local i=(d*W.iconImageYScale)*W.iconImageRatio local h=W.iconImage~=""local D=W.iconText~=""local j=.5 local B local Z=K/2 if h and not D then j=.45 U:set("\105\099\111\110\073\109\097\103\101\086\105\115\105\098\108\101",true,c)U: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),c)U:set("\105\099\111\110\073\109\097\103\101\080\111\115\105\116\105\111\110",UDim2.new(.5,0,.5,0),c)U:set("\105\099\111\110\073\109\097\103\101\083\105\122\101",UDim2.new(W.iconImageYScale*W.iconImageRatio,0,W.iconImageYScale,0),c)U:set("\105\099\111\110\076\097\098\101\108\086\105\115\105\098\108\101",false,c)elseif not h and D then B=x+M*2 U:set("\105\099\111\110\076\097\098\101\108\086\105\115\105\098\108\101",true,c)U: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),c)U:set("\105\099\111\110\076\097\098\101\108\080\111\115\105\116\105\111\110",UDim2.new(0,M,.5,0),c)U:set("\105\099\111\110\076\097\098\101\108\083\105\122\101",UDim2.new(1,-M*2,W.iconLabelYScale,Z),c)U: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,c)U:set("\105\099\111\110\073\109\097\103\101\086\105\115\105\098\108\101",false,c)elseif h and D then local L=(M+i)+r B=(L+x)+M U:set("\105\099\111\110\073\109\097\103\101\086\105\115\105\098\108\101",true,c)U: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),c)U:set("\105\099\111\110\073\109\097\103\101\080\111\115\105\116\105\111\110",UDim2.new(0,M,.5,0),c)U:set("\105\099\111\110\073\109\097\103\101\083\105\122\101",UDim2.new(0,i,W.iconImageYScale,0),c)U:set("\105\099\111\110\076\097\098\101\108\086\105\115\105\098\108\101",true,c)U: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),c)U:set("\105\099\111\110\076\097\098\101\108\080\111\115\105\116\105\111\110",UDim2.new(0,L,.5,0),c)U:set("\105\099\111\110\076\097\098\101\108\083\105\122\101",UDim2.new(1,-L-M,W.iconLabelYScale,Z),c)U: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,c)end if B then if not U._updatingIconSize then U._updatingIconSize=true local L=t>0 and t or 0 local M=t>0 and 0 or math.clamp(B,N,O)U:set("\105\099\111\110\083\105\122\101",UDim2.new(L,M,W.iconSize.Y.Scale,W.iconSize.Y.Offset),c,"\095\105\103\110\111\114\101\080\114\101\118\105\111\117\115")U._updatingIconSize=false end end U:set("\105\099\111\110\076\097\098\101\108\084\101\120\116\083\105\122\101",K,c)U:set("\110\111\116\105\099\101\070\114\097\109\101\080\111\115\105\116\105\111\110",UDim2.new(j,0,0,-2),c)U._updatingIconSize=false end

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


