Re: Displaying live NSSlider value
On Jun 17, 2008, at 1:19 PM, Andy Klepack wrote: I have an NSSlider and while the drag is in progress I would like to display the value in a text field. When the drag completes I would like the new value to get set in the user preferences and an action executed. As far as I can tell I'll have to set the slider to send its action continually in order to find out that value has changed. If that's so then I would need a way to determine whether the drag had completed and then behave appropriately. Am I wrong, is there actually some sort of delegate method like "valueDidChange:" that could be used to differentiate the drag events from the drag-complete event? If I do have to do the determination in the action itself how would I find out that the drag completed? This is probably a common usage pattern for a slider but I haven't found any previous discussion. Ideally I'd like to display the value and its changes in a tooltip as the user drags but that also has proven difficult to do. Bindings? Perhaps I didn't understand your question, since nobody else has suggested this, but couldn't you bind the value of the slider to a controller, and it set the user preferences / execute the action in the accessor method? Omar Qazi Hello, Galaxy! 1.310.294.1593 smime.p7s Description: S/MIME cryptographic signature ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Displaying live NSSlider value
On Tue, Jun 17, 2008 at 1:19 PM, Andy Klepack <[EMAIL PROTECTED]> wrote: > I have an NSSlider and while the drag is in progress I would like to display > the value in a text field. When the drag completes I would like the new value > to get set in the user preferences and an action executed. > > As far as I can tell I'll have to set the slider to send its action > continually in order to find out that value has changed. If that's so then I > would need a way to determine whether the drag had completed and then behave > appropriately. > > Am I wrong, is there actually some sort of delegate method like > "valueDidChange:" that could be used to differentiate the drag events from > the drag-complete event? If I do have to do the determination in the action > itself how would I find out that the drag completed? There is no delegate method, but it's actually fairly easy to make your own. However, before you do that, consider whether you really need to. Do you really need to run the final code once? Will it work if you just run it every time the value changes? If your code isn't really slow then this can be the simplest way to go. However, if your code takes a significant amount of time to run such that it disturbs the operation of the slider, or there's some other good reason to do this, you can write code like this: - (IBAction)sliderMoved:(id)sender { // update the value here [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(sliderDoneMoving:) object:sender]; [self performSelector:@selector(sliderDoneMoving:) withObject:sender afterDelay:0]; } - (void)sliderDoneMoving:(id)sender { // do your expensive update here } The reason this works is because while the mouse button is held on the slider, the runloop is running in a special event tracking mode. The delayed perform is scheduled in the default mode, and thus won't run while the mouse button is held down. When you release the mouse button, the blocked delayed perform finally runs. The cancellation above it is to make sure you only ever have one, otherwise you'd get sliderDoneMoving: called repeatedly in a flood when the mouse button is released. The first time the method runs there is nothing to cancel, but that's fine because it will just do nothing. Mike ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Re: Displaying live NSSlider value
> I have an NSSlider and while the drag is in progress I would like to display > the value in a text field. When the drag completes I would like the new value > to get set in the user preferences and an action executed. > > As far as I can tell I'll have to set the slider to send its action > continually in order to find out that value has changed. If that's so then I > would need a way to determine whether the drag had completed and then behave > appropriately. This isn't really how the target/action mechanism is designed to work. I remember seeing a far more elegant solution to this somewhere recently - it was a custom NSSlider (or cell) that shows the value in a small bubble above the handle while it's being dragged. If you used such a control, you could avoid the "continuous" mode (setting the actual value only when the drag is complete) while still giving your users visual feedback of the "intended" value. I tried to google around for this control but couldn't find it. Perhaps you'll have better luck or some helpful soul will point the way. -- I.S. ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]
Displaying live NSSlider value
I have an NSSlider and while the drag is in progress I would like to display the value in a text field. When the drag completes I would like the new value to get set in the user preferences and an action executed. As far as I can tell I'll have to set the slider to send its action continually in order to find out that value has changed. If that's so then I would need a way to determine whether the drag had completed and then behave appropriately. Am I wrong, is there actually some sort of delegate method like "valueDidChange:" that could be used to differentiate the drag events from the drag-complete event? If I do have to do the determination in the action itself how would I find out that the drag completed? This is probably a common usage pattern for a slider but I haven't found any previous discussion. Ideally I'd like to display the value and its changes in a tooltip as the user drags but that also has proven difficult to do. Thanks all, -Andy ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]