function init(M)local l=M.Frame local v=l.Dragger local Z=l.Background local w=M._Axis local Y=M._Maid local c=M._Spring local g=Lazy.Classes.Dragger.new(l)M.DragStart=g.DragStart M.DragStop=g.DragStop Y:Mark(M._ChangedBind)Y:Mark(M._ClickedBind)Y:Mark(function()g:Destroy()end)local function I(M,l)if w=="\121"then M,l=l,M end return UDim2.new(M,0,l,0)end local N=-1 local D,R local function W()D,R=getBounds(M)Z.Size=I(R/l.AbsoluteSize[w],1)N=-1 end W()Y:Mark((l:GetPropertyChangedSignal("\065\098\115\111\108\117\116\101\083\105\122\101")):Connect(W))Y:Mark((l:GetPropertyChangedSignal("\065\098\115\111\108\117\116\101\080\111\115\105\116\105\111\110")):Connect(W))Y:Mark((l:GetPropertyChangedSignal("\080\097\114\101\110\116")):Connect(W))local V=0 local z=0 local i=false Y:Mark(l.SelectionGained:Connect(function()i=true end))Y:Mark(l.SelectionLost:Connect(function()i=false end))Y:Mark(UIS.InputChanged:Connect(function(M,l)if l and M.KeyCode==THUMBSTICK then local l=M.Position V=math.abs(l[w])>XBOX_DEADZONE and math.sign(l[w])or 0 end end))Y:Mark(g.DragChanged:Connect(function(l,v,Z)if M.IsActive then M:Set((v.Position[w]-D)/R,false)end end))Y:Mark(l.InputBegan:Connect(function(l)if l.UserInputType==Enum.UserInputType.MouseButton1 or l.UserInputType==Enum.UserInputType.Touch then local v=(l.Position[w]-D)/R M._ClickedBind:Fire(math.clamp(v,0,1))if M.IsActive then M:Set(v,M.TweenClick)end end end))Y:Mark(RUNSERVICE.RenderStepped:Connect(function(Z)if i then local l=tick()if M.Interval<=0 then M:Set(M:Get()+((V*XBOX_STEP)*Z)*60)elseif l-z>DEBOUNCE_TICK then z=l M:Set(M:Get()+M.Interval*V)end end c:Update(Z)local Y=c.x if Y~=N then local Z=((D+Y*R)-l.AbsolutePosition[w])/l.AbsoluteSize[w]v.Position=I(Z,.5)M._ChangedBind:Fire(M:Get())N=Y end end))end function getBounds(M)local l=M.Frame local v=l.Dragger local Z=M._Axis local w=l.AbsolutePosition[Z]+v.AbsoluteSize[Z]/2 local Y=l.AbsoluteSize[Z]-v.AbsoluteSize[Z]return w,Y end


function init(self)
	local frame = self.Frame
	local dragger = frame.Dragger
	local background = frame.Background
	
	local axis = self._Axis
	local maid = self._Maid
	local spring = self._Spring
	local dragTracker = Lazy.Classes.Dragger.new(frame)
	
	self.DragStart = dragTracker.DragStart
	self.DragStop = dragTracker.DragStop
	
	--maid:Mark(frame)
	maid:Mark(self._ChangedBind)
	maid:Mark(self._ClickedBind)
	maid:Mark(function() dragTracker:Destroy() end)
	
	-- Get bounds and background size scaled accordingly for calculations
	local function setUdim2(a, b)
		if (axis == "y") then a, b = b, a end
		return UDim2.new(a, 0, b, 0)
	end
	
	local last = -1
	local bPos, bSize
	local function updateBounds()
		bPos, bSize = getBounds(self)
		background.Size = setUdim2(bSize / frame.AbsoluteSize[axis], 1)
		last = -1
	end
	
	updateBounds()
	maid:Mark(frame:GetPropertyChangedSignal("AbsoluteSize"):Connect(updateBounds))
	maid:Mark(frame:GetPropertyChangedSignal("AbsolutePosition"):Connect(updateBounds))
	maid:Mark(frame:GetPropertyChangedSignal("Parent"):Connect(updateBounds))
	
	-- Move the slider when the xbox moves it
	local xboxDir = 0
	local xboxTick = 0
	local xboxSelected = false
	
	maid:Mark(frame.SelectionGained:Connect(function()
		xboxSelected = true
	end))
	
	maid:Mark(frame.SelectionLost:Connect(function()
		xboxSelected = false
	end))
	
	maid:Mark(UIS.InputChanged:Connect(function(input, process)
		if (process and input.KeyCode == THUMBSTICK) then
			local pos = input.Position
			xboxDir = math.abs(pos[axis]) > XBOX_DEADZONE and math.sign(pos[axis]) or 0
		end
	end))
	
	-- Move the slider when we drag it
	maid:Mark(dragTracker.DragChanged:Connect(function(element, input, delta)
		if (self.IsActive) then
			self:Set((input.Position[axis] - bPos) / bSize, false)
		end
	end))
	
	-- Move the slider when we click somewhere on the bar
	maid:Mark(frame.InputBegan:Connect(function(input)
		if (input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch) then
			local t = (input.Position[axis] - bPos) / bSize
			self._ClickedBind:Fire(math.clamp(t, 0, 1))
			if (self.IsActive) then
				self:Set(t, self.TweenClick)
			end
		end
	end))
	
	-- position the slider
	maid:Mark(RUNSERVICE.RenderStepped:Connect(function(dt)
		if (xboxSelected) then
			local t = tick()
			if (self.Interval <= 0) then
				self:Set(self:Get() + xboxDir*XBOX_STEP*dt*60)
			elseif (t - xboxTick > DEBOUNCE_TICK) then
				xboxTick = t
				self:Set(self:Get() + self.Interval*xboxDir)
			end
		end
		
		spring:Update(dt)
		local x = spring.x
		if (x ~= last) then
			local scalePos = (bPos + (x * bSize) - frame.AbsolutePosition[axis]) / frame.AbsoluteSize[axis]
			dragger.Position = setUdim2(scalePos, 0.5)
			self._ChangedBind:Fire(self:Get())
			last = x
		end
	end))
end

function getBounds(self)
	local frame = self.Frame
	local dragger = frame.Dragger
	local axis = self._Axis
	
	local pos = frame.AbsolutePosition[axis] + dragger.AbsoluteSize[axis]/2
	local size = frame.AbsoluteSize[axis] - dragger.AbsoluteSize[axis]
	
	return pos, size
end
