function init(M)local C=M.Frame local F=C.Dragger local Q=C.Background local t=M._Axis local b=M._Maid local v=M._Spring local a=Lazy.Classes.Dragger.new(F)M.DragStart=a.DragStart M.DragStop=a.DragStop b:Mark(C)b:Mark(M._ChangedBind)b:Mark(M._ClickedBind)b:Mark(function()a:Destroy()end)local function I(M,C)if t=="\121"then M,C=C,M end return UDim2.new(M,0,C,0)end local G=-1 local K,j local function P()K,j=getBounds(M)Q.Size=I(j/C.AbsoluteSize[t],1)G=-1 end P()b:Mark((C:GetPropertyChangedSignal("\065\098\115\111\108\117\116\101\083\105\122\101")):Connect(P))b:Mark((C:GetPropertyChangedSignal("\065\098\115\111\108\117\116\101\080\111\115\105\116\105\111\110")):Connect(P))b:Mark((C:GetPropertyChangedSignal("\080\097\114\101\110\116")):Connect(P))local B=0 local H=0 local Y=false b:Mark(F.SelectionGained:Connect(function()Y=true end))b:Mark(F.SelectionLost:Connect(function()Y=false end))b:Mark(UIS.InputChanged:Connect(function(M,C)if C and M.KeyCode==THUMBSTICK then local C=M.Position B=math.abs(C[t])>XBOX_DEADZONE and math.sign(C[t])or 0 end end))b:Mark(a.DragChanged:Connect(function(C,F,Q)if M.IsActive then M:Set((F.Position[t]-K)/j,false)end end))b:Mark(C.InputBegan:Connect(function(C)if C.UserInputType==Enum.UserInputType.MouseButton1 or C.UserInputType==Enum.UserInputType.Touch then local F=(C.Position[t]-K)/j M._ClickedBind:Fire(math.clamp(F,0,1))if M.IsActive then M:Set(F,M.TweenClick)end end end))b:Mark(RUNSERVICE.RenderStepped:Connect(function(Q)if Y then local C=tick()if M.Interval<=0 then M:Set(M:Get()+((B*XBOX_STEP)*Q)*60)elseif C-H>DEBOUNCE_TICK then H=C M:Set(M:Get()+M.Interval*B)end end v:Update(Q)local b=v.x if b~=G then local Q=((K+b*j)-C.AbsolutePosition[t])/C.AbsoluteSize[t]F.Position=I(Q,.5)M._ChangedBind:Fire(M:Get())G=b end end))end function getBounds(M)local C=M.Frame local F=C.Dragger local Q=M._Axis local t=C.AbsolutePosition[Q]+F.AbsoluteSize[Q]/2 local b=C.AbsoluteSize[Q]-F.AbsoluteSize[Q]return t,b 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(dragger)
	
	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(dragger.SelectionGained:Connect(function()
		xboxSelected = true
	end))
	
	maid:Mark(dragger.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
