views:

143

answers:

2

I'd like to have an NSSlider that doesn't snap to tick points, except of the last two. This is the same behavior of the slider in System Preferences -> Energy Saver -> Computer Sleep. Any ideas on how to do this?

+1  A: 

I don't know of an easy way offhand, but if it comes down to it you could create your own NSSliderCell subclass and override some or all of these three methods:

- (BOOL)startTrackingAt:(NSPoint)startPoint inView:(NSView *)controlView;
- (BOOL)continueTracking:(NSPoint)lastPoint at:(NSPoint)currentPoint inView:(NSView *)controlView;
- (void)stopTracking:(NSPoint)lastPoint at:(NSPoint)stopPoint inView:(NSView *)controlView mouseIsUp:(BOOL)flag;
Marc Charbonneau
A: 

I think the best way would be to subclass NSSliderCell and override some or all of the tick methods.

- (double)closestTickMarkValueToValue:(double)aValue

My guess is that that method allows you to choose which points to stop at, but if that doesn't work....

You could make the NSSlider continuous. Your target will receive the action you have set as the user moves the slider. Once it gets above/below the threshold, you can change whether it only stops at tick marks or not. This may or may not be what you're looking for (since it won't play nicely with bindings, etc), but it's a possible hack.

wbyoung