         let diameter = backgroundView.bounds.size.height
         let thumbSize = CGSize(width: diameter, height: diameter)
         let thumbFrame = CGRect(origin: thumbOrigin, size: thumbSize)
-        
         thumbView = NSSwitchThumbView(frame: thumbFrame)
         thumbView.wantsLayer = true
         

    }
    
    private func updatePosition(pan: NSPanGestureRecognizer) {
        
        let thumbWidth = thumbView.bounds.size.width
        
        let leadingSpace = thumbView.frame.origin.x
        let trailingSpace = backgroundView.bounds.size.width - (leadingSpace + thumbWidth)
        
        let xTranslation = pan.translation(in: backgroundView).x
        
        if xTranslation >= 0 {
            
            let delta = trailingSpace >= xTranslation ? xTranslation : trailingSpace
            thumbView.frame.origin.x += delta * dragVelocityGain
            
        }
        else {
            
            if leadingSpace >= -xTranslation {
                thumbView.frame.origin.x += xTranslation * dragVelocityGain
            }
            else {
                thumbView.frame.origin.x += -leadingSpace * dragVelocityGain
            }
            
        }
    }
    
    private func moveToNearestSwitchPosition() {
        setOn(on: on, animated: true)
    }
    
}

    
    @objc private func panned(pan: NSPanGestureRecognizer) {
        switch pan.state {
        case .changed:
            updatePosition(pan: pan)
            
            let x = thumbView.frame.origin.x
            let thumbViewWidth = thumbView.bounds.size.width
            let backgroundViewWidth = backgroundView.bounds.size.width
            if x + thumbViewWidth / 2 >= backgroundViewWidth / 2 {
                setOn(on: true, animated: false)
            } else {
                setOn(on: false, animated: false)
