On 22 Jun 2009, at 14:16, Quincey Morris wrote:

(2) *Nested* wheel-scrolling behavior can be a frustration for users, because it forces them to stop and think what the effect of using the scroll wheel is going to be. This is just exacerbated when some of the behavior is "harmless" adjustment of the UI (e.g. scrolling) and some is real change to the data model. That means the price of the users missing the scroll target by a pixel is pretty high.

That's a good point actually. Everything I do in my software happens inside one window with no scroll bars etc. For completeness here is my current number box class :)


// header

#import <Cocoa/Cocoa.h>

@interface ASNumberBox : NSTextField <NSCoding>
{
        float   curValue;
        float   minValue;
        float   maxValue;
        float   range;
        
        float   dragSize;
        float   scrollStep;
        float   fineGrain;
        
        // float        start_x;
        float   start_y;
        float   prev_y;
        
        BOOL    drag;
}

-(void)checkBounds;

@end


// implementation

#import "ASNumberBox.h"

@implementation ASNumberBox

-(void)initValues
{
        curValue = [super floatValue];
        minValue = 0;
        maxValue = 127;
        range = maxValue - minValue;
        
        scrollStep = range / 256;
        dragSize = 512;
        fineGrain = 0.25;
        
        drag = NO;
}

-(id)initWithFrame:(NSRect)rect
{
        if (self = [super initWithFrame:rect])
        {
                [self initValues];
        }
        return self;
}

-(id)initWithCoder:(NSCoder*)coder
{
        if (self = [super initWithCoder:coder])
        {
                [self initValues];
        };
        return self;
}

-(void)encodeWithCoder:(NSCoder*)coder
{
        [super encodeWithCoder:coder];
}

-(void)dealloc
{       
        [super dealloc];
}

-(BOOL)isFlipped
{
        return NO;
}

-(void)checkBounds
{
        if(curValue < minValue) {
                curValue = minValue;
        } else if (curValue > maxValue) {
                curValue = maxValue;
        };
}


#pragma mark Events

-(void)mouseUp:(NSEvent*)theEvent
{
        if(drag) drag = NO;
}

-(void)mouseDragged:(NSEvent*)theEvent
{
        if(!drag) {
// float start_x = [self convertPoint: [theEvent locationInWindow] fromView: nil].x; start_y = [self convertPoint:[theEvent locationInWindow] fromView: nil].y;
                prev_y = start_y;
                drag = YES;
        };
                
        // key modifier key flags
        unsigned int flags;
        flags = [theEvent modifierFlags];
        
float next_y = [self convertPoint:[theEvent locationInWindow] fromView: nil].y;
        float deltaY = (next_y - prev_y) / dragSize;
        prev_y = next_y;
        
        if(flags & NSAlternateKeyMask) deltaY *= fineGrain;
        curValue += range * deltaY;
        
        [self checkBounds];
        [self setIntValue:curValue];
        
        // continuously send the action
        [self sendAction:(SEL)[self action] to:(id)[self target]];
}

-(void)scrollWheel:(NSEvent*)event
{
        // key modifier key flags
        unsigned int flags;
        flags = [event modifierFlags];

        float wheelY = [event deltaY];
        if(flags & NSAlternateKeyMask) {
                curValue += wheelY * scrollStep * fineGrain;
        } else {
                curValue += wheelY * scrollStep;
        };

        [self checkBounds];
        [self setIntValue:curValue];
        
        // send the action
        [self sendAction:(SEL)[self action] to:(id)[self target]];
}

@end
_______________________________________________

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 arch...@mail-archive.com

Reply via email to