Snippet #35
Language: Objective-C, Author: Michael Bianco
License: Public domain
Resizes a NSSplitView in a nice fashion allowing for minimum splitview restraints for the left panel
- (float) splitView:(NSSplitView *)sender constrainMinCoordinate:(float)proposedMin ofSubviewAt:(int)offset { if(offset == 0) { return MIN_LEFT_PANEL_W; } else { return 0; //this never happens so.... } } - (void) splitView:(NSSplitView *)sender resizeSubviewsWithOldSize:(NSSize)oldSize { // http://www.wodeveloper.com/omniLists/macosx-dev/2003/May/msg00261.html // grab the splitviews NSView *left = [[sender subviews] objectAtIndex:0]; NSView *right = [[sender subviews] objectAtIndex:1]; float dividerThickness = [sender dividerThickness]; // get the different frames NSRect newFrame = [sender frame]; NSRect leftFrame = [left frame]; NSRect rightFrame = [right frame]; // change in width for this redraw int dWidth = newFrame.size.width - oldSize.width; // ratio of the left frame width to the right used for resize speed when both panes are being resized float rLeftRight = (leftFrame.size.width - MIN_LEFT_PANEL_W) / rightFrame.size.width; // resize the height of the left leftFrame.size.height = newFrame.size.height; leftFrame.origin = NSMakePoint(0,0); // resize the left & right pane equally if we are shrinking the frame // resize the right pane only if we are increasing the frame // when resizing lock at minimum width for the left panel if(leftFrame.size.width <= MIN_LEFT_PANEL_W && dWidth < 0) { rightFrame.size.width += dWidth; } else if(dWidth > 0) { rightFrame.size.width += dWidth; } else { leftFrame.size.width += floor(dWidth * rLeftRight); rightFrame.size.width += ceil(dWidth * (1 - rLeftRight)); } rightFrame.size.width = newFrame.size.width - leftFrame.size.width - dividerThickness; rightFrame.size.height = newFrame.size.height; rightFrame.origin.x = leftFrame.size.width + dividerThickness; [left setFrame:leftFrame]; [right setFrame:rightFrame]; }
Compatible with:
- Mac OS X 10.3
- Mac OS X 10.4 PPC
- Mac OS X 10.4 Intel
Comments
Comment feed
