function Icon.setDropdown(u,a)for a,u in pairs(u.dropdownIcons)do u:leave()end if type(a)=="\116\097\098\108\101"then for a,O in pairs(a)do O:join(u,"\100\114\111\112\100\111\119\110",true)end end u:_updateDropdown()return u end function Icon._updateDropdown(a)local u={maxIconsBeforeScroll=a: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=a:get("\100\114\111\112\100\111\119\110\077\105\110\087\105\100\116\104")or"\095\078\073\076";padding=a: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=a:get("\100\114\111\112\100\111\119\110\065\108\105\103\110\109\101\110\116")or"\095\078\073\076",iconAlignment=a:get("\097\108\105\103\110\109\101\110\116")or"\095\078\073\076",scrollBarThickness=a: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 a,u in pairs(u)do if u=="\095\078\073\076"then return end end local O=u.padding.Offset local C=a.instances.dropdownContainer local p=a.instances.dropdownFrame local d=a.instances.dropdownList local b=#a.dropdownIcons local k=b>u.maxIconsBeforeScroll and u.maxIconsBeforeScroll or b local M=-O local i=0 local E=u.minWidth table.sort(a.dropdownIcons,function(a,u)return a:get("\111\114\100\101\114")<u:get("\111\114\100\101\114")end)for u=1,b,1 do local C=a.dropdownIcons[u]local p,d=C: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 l=d.Y.Offset+O if u<=k then i=i+l end if u==b then i=i+l/4 end M=M+l local j=d.X.Offset if j>E then E=j end local N=u==1 and a or a.dropdownIcons[u-1]local L=a.dropdownIcons[u+1]C.instances.iconButton.NextSelectionUp=N and N.instances.iconButton C.instances.iconButton.NextSelectionDown=L and L.instances.iconButton end local l=k==b and 0 or M a:set("\100\114\111\112\100\111\119\110\067\097\110\118\097\115\083\105\122\101",UDim2.new(0,0,0,l))a:set("\100\114\111\112\100\111\119\110\083\105\122\101",UDim2.new(0,(E+4)*2,0,i))local j=u.dropdownAlignment:lower()local N={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 L=N[j]if not L then L=N[u.iconAlignment:lower()]end C.AnchorPoint=L.AnchorPoint C.Position=UDim2.new(L.PositionXScale,0,1,O+0)local w=u.scrollBarThickness local o=w*L.ThicknessMultiplier local V=p.VerticalScrollBarPosition==Enum.VerticalScrollBarPosition.Right and o or-o p.AnchorPoint=L.FrameAnchorPoint or L.AnchorPoint p.Position=UDim2.new(L.FramePositionXScale or L.PositionXScale,V,0,0)a._dropdownCanvasPos=Vector2.new(0,0)end function Icon._dropdownIgnoreClipping(a)a:_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
		-- This ensures the dropdown is navigated fully and correctly with a controller
		local prevIcon = (i == 1 and self) or self.dropdownIcons[i-1]
		local nextIcon = self.dropdownIcons[i+1]
		otherIcon.instances.iconButton.NextSelectionUp = prevIcon and prevIcon.instances.iconButton
		otherIcon.instances.iconButton.NextSelectionDown = nextIcon and nextIcon.instances.iconButton
	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

