discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSSplitView - how to programmatically resize the subviews?


From: Dr. H. Nikolaus Schaller
Subject: Re: NSSplitView - how to programmatically resize the subviews?
Date: Tue, 31 Mar 2009 17:12:58 +0200


Am 31.03.2009 um 17:07 schrieb Wolfgang Lux:

Dr. H. Nikolaus Schaller wrote:

at is exactly what the current code is thought for. But at least on 10.5 it did not (yet). Subviews are evenly split (e.g. 50%, 50%). Maybe, I have
made some mistake so I will try to look again in that direction...

Below is a small method that resizes all subviews of a split view such that they have (up to rounding errors) the same height. Works for me on 10.5.

Wolfgang

- (void)spaceEvenly:(NSSplitView *)splitView
{
   // get the subviews of the split view
   NSArray *subviews = [splitView subviews];
   unsigned int n = [subviews count];

   // compute the new height of each subview
   float divider = [splitView dividerThickness];
float height = ([splitView bounds].size.height - (n - 1) * divider) / n;

   // adjust the frames of all subviews
   float y = 0;
   NSView *subview;
   NSEnumerator *e = [subviews objectEnumerator];
   while ((subview = [e nextObject]) != nil)
   {
        NSRect frame = [subview frame];
        frame.origin.y = rintf(y);
        frame.size.height = rintf(y + height) - frame.origin.y;
        [subview setFrame:frame];
        y += height + divider;
   }

   // have the AppKit redraw the dividers
   [splitView adjustSubviews];
}



I have just finished plumbing together a small test application. And it simply works...

So I must have a bug in the SWK logic that translates from rows/cols information to (new) frame dimensions.

Thanks for helping to clarify this issue!

Nikolaus




reply via email to

[Prev in Thread] Current Thread [Next in Thread]