function Icon.setDropdown(c,L)for L,c in pairs(c.dropdownIcons)do c:leave()end if type(L)=="\116\097\098\108\101"then for L,U in pairs(L)do U:join(c,"\100\114\111\112\100\111\119\110",true)end end c:_updateDropdown()return c end function Icon._updateDropdown(L)local c={maxIconsBeforeScroll=L:get("\100\114\111\112\100\111\119\110\077\097\120\073\099\111\110\115\066\101\102\111\114\101\083\099\114\111\108\108")or"\095\078\073\076";minWidth=L:get("\100\114\111\112\100\111\119\110\077\105\110\087\105\100\116\104")or"\095\078\073\076";padding=L:get("\100\114\111\112\100\111\119\110\076\105\115\116\080\097\100\100\105\110\103")or"\095\078\073\076";dropdownAlignment=L:get("\100\114\111\112\100\111\119\110\065\108\105\103\110\109\101\110\116")or"\095\078\073\076";iconAlignment=L:get("\097\108\105\103\110\109\101\110\116")or"\095\078\073\076";scrollBarThickness=L:get("\100\114\111\112\100\111\119\110\083\099\114\111\108\108\066\097\114\084\104\105\099\107\110\101\115\115")or"\095\078\073\076"}for L,c in pairs(c)do if c=="\095\078\073\076"then return end end local U=c.padding.Offset local M=L.instances.dropdownContainer local r=L.instances.dropdownFrame local W=L.instances.dropdownList local A=#L.dropdownIcons local q=A>c.maxIconsBeforeScroll and c.maxIconsBeforeScroll or A local t=-U local o=0 local N=c.minWidth table.sort(L.dropdownIcons,function(L,c)return L:get("\111\114\100\101\114")<c:get("\111\114\100\101\114")end)for c=1,A,1 do local M=L.dropdownIcons[c]local r,W=M:get("\105\099\111\110\083\105\122\101",nil,"\098\101\102\111\114\101\068\114\111\112\100\111\119\110")local O=W.Y.Offset+U if c<=q then o=o+O end if c==A then o=o+O/4 end t=t+O local z=W.X.Offset if z>N then N=z end end local O=q==A and 0 or t L:set("\100\114\111\112\100\111\119\110\067\097\110\118\097\115\083\105\122\101",UDim2.new(0,0,0,O))L:set("\100\114\111\112\100\111\119\110\083\105\122\101",UDim2.new(0,(N+4)*2,0,o))local z=c.dropdownAlignment:lower()local R={left={AnchorPoint=Vector2.new(0,0);PositionXScale=0,ThicknessMultiplier=0};mid={AnchorPoint=Vector2.new(.5,0);PositionXScale=.5,ThicknessMultiplier=.5};right={AnchorPoint=Vector2.new(.5,0);PositionXScale=1;FrameAnchorPoint=Vector2.new(0,0),FramePositionXScale=0;ThicknessMultiplier=1}}local d=R[z]if not d then d=R[c.iconAlignment:lower()]end M.AnchorPoint=d.AnchorPoint M.Position=UDim2.new(d.PositionXScale,0,1,U+0)local K=c.scrollBarThickness local x=K*d.ThicknessMultiplier local i=r.VerticalScrollBarPosition==Enum.VerticalScrollBarPosition.Right and x or-x r.AnchorPoint=d.FrameAnchorPoint or d.AnchorPoint r.Position=UDim2.new(d.FramePositionXScale or d.PositionXScale,i,0,0)L._dropdownCanvasPos=Vector2.new(0,0)end function Icon._dropdownIgnoreClipping(L)L:_ignoreClipping("\100\114\111\112\100\111\119\110")end

function Icon:setDropdown(arrayOfIcons)
	-- Reset any previous icons
	for i, otherIcon in pairs(self.dropdownIcons) do
		otherIcon:leave()
	end
	-- Apply new icons
	if type(arrayOfIcons) == "table" then
		for i, otherIcon in pairs(arrayOfIcons) do
			otherIcon:join(self, "dropdown", true)
		end
	end
	-- Update dropdown
	self:_updateDropdown()
	return self
end

function Icon:_updateDropdown()
	local values = {
		maxIconsBeforeScroll = self:get("dropdownMaxIconsBeforeScroll") or "_NIL",
		minWidth = self:get("dropdownMinWidth") or "_NIL",
		padding = self:get("dropdownListPadding") or "_NIL",
		dropdownAlignment = self:get("dropdownAlignment") or "_NIL",
		iconAlignment = self:get("alignment") or "_NIL",
		scrollBarThickness = self:get("dropdownScrollBarThickness") or "_NIL",
	}
	for k, v in pairs(values) do if v == "_NIL" then return end end
	
	local YPadding = values.padding.Offset
	local dropdownContainer = self.instances.dropdownContainer
	local dropdownFrame = self.instances.dropdownFrame
	local dropdownList = self.instances.dropdownList
	local totalIcons = #self.dropdownIcons

	local lastVisibleIconIndex = (totalIcons > values.maxIconsBeforeScroll and values.maxIconsBeforeScroll) or totalIcons
	local newCanvasSizeY = -YPadding
	local newFrameSizeY = 0
	local newMinWidth = values.minWidth
	table.sort(self.dropdownIcons, function(a,b) return a:get("order") < b:get("order") end)
	for i = 1, totalIcons do
		local otherIcon = self.dropdownIcons[i]
		local _, otherIconSize = otherIcon:get("iconSize", nil, "beforeDropdown")
		local increment = otherIconSize.Y.Offset + YPadding
		if i <= lastVisibleIconIndex then
			newFrameSizeY = newFrameSizeY + increment
		end
		if i == totalIcons then
			newFrameSizeY = newFrameSizeY + increment/4
		end
		newCanvasSizeY = newCanvasSizeY + increment
		local otherIconWidth = otherIconSize.X.Offset --+ 4 + 100 -- the +100 is to allow for notices
		if otherIconWidth > newMinWidth then
			newMinWidth = otherIconWidth
		end
	end

	local finalCanvasSizeY = (lastVisibleIconIndex == totalIcons and 0) or newCanvasSizeY
	self:set("dropdownCanvasSize", UDim2.new(0, 0, 0, finalCanvasSizeY))
	self:set("dropdownSize", UDim2.new(0, (newMinWidth+4)*2, 0, newFrameSizeY))

	-- Set alignment while considering screen bounds
	local dropdownAlignment = values.dropdownAlignment:lower()
	local alignmentDetails = {
		left = {
			AnchorPoint = Vector2.new(0, 0),
			PositionXScale = 0,
			ThicknessMultiplier = 0,
		},
		mid = {
			AnchorPoint = Vector2.new(0.5, 0),
			PositionXScale = 0.5,
			ThicknessMultiplier = 0.5,
		},
		right = {
			AnchorPoint = Vector2.new(0.5, 0),
			PositionXScale = 1,
			FrameAnchorPoint = Vector2.new(0, 0),
			FramePositionXScale = 0,
			ThicknessMultiplier = 1,
		}
	}
	local alignmentDetail = alignmentDetails[dropdownAlignment]
	if not alignmentDetail then
		alignmentDetail = alignmentDetails[values.iconAlignment:lower()]
	end
	dropdownContainer.AnchorPoint = alignmentDetail.AnchorPoint
	dropdownContainer.Position = UDim2.new(alignmentDetail.PositionXScale, 0, 1, YPadding+0)
	local scrollbarThickness = values.scrollBarThickness
	local newThickness = scrollbarThickness * alignmentDetail.ThicknessMultiplier
	local additionalOffset = (dropdownFrame.VerticalScrollBarPosition == Enum.VerticalScrollBarPosition.Right and newThickness) or -newThickness
	dropdownFrame.AnchorPoint = alignmentDetail.FrameAnchorPoint or alignmentDetail.AnchorPoint
	dropdownFrame.Position = UDim2.new(alignmentDetail.FramePositionXScale or alignmentDetail.PositionXScale, additionalOffset, 0, 0)
	self._dropdownCanvasPos = Vector2.new(0, 0)
end

function Icon:_dropdownIgnoreClipping()
	self:_ignoreClipping("dropdown")
end

