Re: NSSplitView can't expand once collapsed
Re: NSSplitView can't expand once collapsed
- Subject: Re: NSSplitView can't expand once collapsed
- From: "Qi Liu" <email@hidden>
- Date: Wed, 12 Nov 2008 01:12:47 +0800
Hi,
At first, I think just as you mentioned, and I want to file a bug too.
But the view being collapsed is not actually being collapsed, it is just
being set *HIDDEN*, and its size remains unchanged. Suppose the splitview is
horizontal and we have 2 views, leftView and rightView. We overrided the
following code:
- (BOOL)splitView:(NSSplitView *)sender canCollapseSubview:(NSView *)subview
{
return YES;
}
- (float)splitView:(NSSplitView *)sender
constrainMinCoordinate:(float)proposedMin ofSubviewAt:(NSInteger)offset
{
return proposedMin + 100.0;
}
- (float)splitView:(NSSplitView *)sender
constrainMaxCoordinate:(float)proposedMax ofSubviewAt:(NSInteger)offset
{
return proposedMax - 100.0;
}
If we want to collapse/expand leftView, we better invoke following function:
- (IBAction)collapse:(id)sender
{
NSView * leftview = [[splitview subviews] objectAtIndex:0];
NSView * rightview = [[splitview subviews] objectAtIndex:1];
NSRect leftFrame = [leftview frame];
NSRect rightFrame = [rightview frame];
rightFrame.origin.x = [splitview dividerThickness];
rightFrame.size.width += leftFrame.size.width;
[leftview setHidden:YES];
[rightview setFrame:rightFrame];
}
- (IBAction)expand:(id)sender
{
NSView * leftview = [[splitview subviews] objectAtIndex:0];
NSView * rightview = [[splitview subviews] objectAtIndex:1];
NSRect leftFrame = [leftview frame];
NSRect rightFrame = [rightview frame];
rightFrame.size.width -= leftFrame.size.width;
rightFrame.origin.x = leftFrame.size.width + [splitview dividerThickness];
[leftview setHidden:NO];
[rightview setFrame:rightFrame];
}
Personally I don't think setting width of leftview to zero is a good idea.
Hope this can be helpful.
=============================================
Qi Liu
--Stay Hungry. Stay Foolish.
--You've got to find what you love.
=============================================
> On Sat, Mar 01, 2003 at 09:04:37PM -0800, matt neuburg wrote:
> >* I think I'm seeing a bug, as follows.*
> >* *
> >* I have an NSSplitView with two subviews. If I "collapse" one of the*
> >* subviews programatically (i.e. I set its height to zero, so that the
> user*
> >* sees only the other subview), then I can expand it again later*
> >* programatically (e.g. I set both subviews to have the same height, and*
> >* adjust subviews).*
> >* *
> >* But if (via the delegate methods) I permit the user to collapse a
> subview*
> >* by hand, I can't find a way to expand it again programatically.
> Everything*
> >* I try gives funky results, wrong sizes, drawing glitches, and so on. If
> *
> >* anyone has counterexample code showing that there is a way to expand a*
> >* subview that the user has collapsed, I'd like to see it. Thanks - m.*
>
> Yup, this is a total mess. Horizontal splits are even worse as you
> can't even uncollapse from code after a programmatic collapse. This
> is my workaround, though it would need to be adapted for your
> purposes.
>
> <http://cocoa.mamasam.com/COCOADEV/2003/02/2/57202.php>
>
> Please file a bug on this issue (I did, #3179051, which is not marked
> as a duplicate).
>
> --
> =Nicholas Riley <email@hidden> | <http://www.uiuc.edu/ph/www/njriley>
> Pablo Research Group, Department of Computer Science and
> Medical Scholars Program, University of Illinois at Urbana-Champaign
_______________________________________________
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