Return to Snippet

Revision: 2744
at April 11, 2007 11:42 by iloveitaly


Initial Code
- (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 += dWidth * rLeftRight;
		rightFrame.size.width += 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];
}

Initial URL

                                

Initial Description
This provides a nice split view resizing method with a minimum size restraint. You HAVE to specify MIN_LEFT_PANE_W for this to work.

Initial Title
Resize NSSplitView Nicely

Initial Tags
resize

Initial Language
Objective C