Re: Strange NSScroller sizing behaviour
Re: Strange NSScroller sizing behaviour
- Subject: Re: Strange NSScroller sizing behaviour
- From: Jo Meder <email@hidden>
- Date: Tue, 4 May 2010 00:53:45 +1200
Hi,
Further to my original post, I've done some more investigation. I wrote a pure Cocoa app (i.e. without my C++ UI framework code getting in the way) and still experienced the resizing problems. The problems seem to effect scrollers which are placed at the bottom or right edges of a window with a resize control, as you would for scrolling window content. A scroller which was away from that area resized as expected. After a bit of messing about I found that placing the scroller inside an NSView and adjusting the scroller frame when the NSView frame changed largely solves the problem. Vertical scrollers seem fine but horizontal ones are sometimes off by a pixel or two after resizing. I can live with it for now.
I don't think the NSScroller resizing behaviour is what it should be so will file a bug.
In case anyone has a similar problem here is some code to give an idea of what I'm doing. handleFrameDidChange: is a handler for the NSViewFrameDidChangeNotification, where the scroller frame is updated. I should probably also handle the bounds change notification.
INTERFACE CODE
@interface UCMacNSScrollerView : NSView
{
NSScroller* m_scroller;
}
- (id) initWithFrame:(NSRect) frame;
- (IBAction) handleAction: (id)sender;
- (void) handleFrameDidChange:( NSNotification* ) note;
@end
IMPLEMENTATION CODE
#import "UCMacNSScrollerView.h"
@implementation UCMacNSScrollerView
- (id) initWithFrame:(NSRect) frame
{
self = [super initWithFrame:frame];
if (self)
{
CGFloat width = NSWidth( frame );
CGFloat height = NSHeight( frame );
NSRect bounds = NSMakeRect( 0, 0, width, height );
m_scroller = [[NSScroller alloc] initWithFrame:bounds];
if ( width >= height )
{
// NOTE: The NSViewMinYMargin flag here may not apply to you, as I need to deal with the top left origin my UI framework uses
[m_scroller setAutoresizingMask:NSViewMinYMargin | NSViewWidthSizable | NSViewMaxXMargin | NSViewMinXMargin];
}
else
{
[m_scroller setAutoresizingMask:NSViewMinYMargin | NSViewHeightSizable | NSViewMaxYMargin];
}
[self addSubview:m_scroller];
[m_scroller setTarget:self];
[m_scroller setAction:@selector( handleAction: )];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector( handleFrameDidChange: )
name:@"NSViewFrameDidChangeNotification" object:self];
}
return self;
}
- (IBAction)handleAction: (id)sender
{
// Handle scroller action here
return;
}
- (void) handleFrameDidChange:( NSNotification* ) note
{
NSRect frame = [self frame];
NSRect scrollerFrame = [m_scroller frame];
scrollerFrame.origin.x = 0;
scrollerFrame.origin.y = 0;
scrollerFrame.size = frame.size;
[m_scroller setFrame:scrollerFrame];
return;
}
@end
Regards,
Jo Meder
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden