local w=script.Parent.Parent local j=require(w:WaitForChild("\076\097\122\121\076\111\097\100\101\114"))local i=w:WaitForChild("\068\101\102\097\117\108\116\115")local b=i:WaitForChild("\076\105\115\116\066\117\116\116\111\110")local c={SortOrder=Enum.SortOrder.LayoutOrder}local function t(w,j)local i=b:Clone()i.Name=j.."\095\098\117\116\116\111\110"i.Label.Text=j return i end local g={}function g.Create(w,j,i,b,c)j=j or math.huge b=b or UDim.new(0,0)i=i or Enum.FillDirection.Vertical c=c or t local g=#w local r=1/g local T=i==Enum.FillDirection.Vertical local K=Instance.new("\070\114\097\109\101")K.Name="\076\105\115\116\070\114\097\109\101"K.BorderSizePixel=0 local e=Instance.new("\083\099\114\111\108\108\105\110\103\070\114\097\109\101")e.Name="\083\099\114\111\108\108\070\114\097\109\101"e.BackgroundTransparency=1 e.BorderSizePixel=0 e.Size=UDim2.new(1,0,1,0)local W=nil local k=nil local v=nil local Q=(g-1)/g local I=b.Scale*Q local C=b.Offset*Q if T then W=UDim2.new(0,0,g/j,0)k=UDim2.new(1,0,r-I,-C)else W=UDim2.new(g/j,0,0,0)k=UDim2.new(r-I,-C,1,0)end e.CanvasSize=W local G={}for w,j in ipairs(w)do local i=c(w,j)i.LayoutOrder=w i.Size=k i.Position=UDim2.new(0,0,(w-1)*r,0)if T then i.Position=i.Position+UDim2.new(0,0,(b.Scale/g)*(w-1),(b.Offset/g)*(w-1))else i.Position=i.Position+UDim2.new((b.Scale/g)*(w-1),(b.Offset/g)*(w-1),0,0)end G[w]=i i.Parent=e end K.BackgroundTransparency=G[1].BackgroundTransparency K.BackgroundColor3=G[1].BackgroundColor3 e.Parent=K return K end return g
--[[
Constructors.List

This module provides a set of functions useful for generating lists that can be scrolled through.

This module only has one function:

List.Create(
	string[] list, -- an array of strings used to generate instances for the list
	integer scrollMax, -- the maximum number of elements visible in the scroll frame at any given time. Defaults to math.huge
	enum fillDirection, -- Enum.FillDirection lets you decide if the list is vertical or horizontal. Defaults to verical
	udim padding, -- scale and offset for padding between instances. Defaults to no padding
	function instanceFunc -- must return a UI object such as a frame. Defaults to creating a textbutton with a child textlabel
)

--]]

-- CONSTANTS

local GuiLib = script.Parent.Parent
local Lazy = require(GuiLib:WaitForChild("LazyLoader"))
local Defaults = GuiLib:WaitForChild("Defaults")

local LIST_BUTTON = Defaults:WaitForChild("ListButton")

local DEFAULT_LAYOUT = {
	SortOrder = Enum.SortOrder.LayoutOrder
}

-- Private Functions

local function defaultButton(index, option)
	local button = LIST_BUTTON:Clone()
	button.Name = option .. "_button"
	button.Label.Text = option
	return button
end

-- Library

local List = {}

function List.Create(list, max, fillDirection, padding, instanceFunc)
	max = max or math.huge
	padding = padding or UDim.new(0, 0)
	fillDirection = fillDirection or Enum.FillDirection.Vertical
	instanceFunc = instanceFunc or defaultButton

	local nList = #list
	local dList = 1 / nList
	
	local isVertical = (fillDirection == Enum.FillDirection.Vertical)
	
	local listFrame = Instance.new("Frame")
	listFrame.Name = "ListFrame"
	listFrame.BorderSizePixel = 0 
	
	local scrollFrame = Instance.new("ScrollingFrame")
	scrollFrame.Name = "ScrollFrame"
	scrollFrame.BackgroundTransparency = 1
	scrollFrame.BorderSizePixel = 0
	scrollFrame.Size = UDim2.new(1, 0, 1, 0)
	
	local canvasSize = nil	
	local elementSize = nil
	local extraPosition = nil
	
	local adj = (nList - 1) / nList
	local scale = padding.Scale * adj
	local offset = padding.Offset * adj
	
	if (isVertical) then
		canvasSize = UDim2.new(0, 0, nList / max, 0) 
		elementSize = UDim2.new(1, 0, dList - scale, -offset)
	else
		canvasSize = UDim2.new(nList / max , 0, 0, 0)
		elementSize = UDim2.new(dList - scale, -offset, 1, 0)
	end
	
	scrollFrame.CanvasSize = canvasSize
	
	local items = {}
	for i, option in ipairs(list) do
		local item = instanceFunc(i, option)
		item.LayoutOrder = i
		item.Size = elementSize
		item.Position = UDim2.new(0, 0, (i-1)*dList, 0)
		
		if (isVertical) then
			item.Position = item.Position + UDim2.new(0, 0, padding.Scale/nList*(i-1), padding.Offset/nList*(i-1))
		else
			item.Position = item.Position + UDim2.new(padding.Scale/nList*(i-1), padding.Offset/nList*(i-1), 0, 0)
		end
		
		items[i] = item
		item.Parent = scrollFrame
	end
	
	listFrame.BackgroundTransparency = items[1].BackgroundTransparency
	listFrame.BackgroundColor3 = items[1].BackgroundColor3
	scrollFrame.Parent = listFrame
	
	return listFrame	
end

--

return List