• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Getting subviews to restore on NSSplitView collapse/uncollapse
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting subviews to restore on NSSplitView collapse/uncollapse


  • Subject: Re: Getting subviews to restore on NSSplitView collapse/uncollapse
  • From: Dustin Voss <email@hidden>
  • Date: Thu, 12 Jun 2003 11:39:57 -0700

On Wednesday, June 11, 2003, at 05:14 PM, Jay Koutavas wrote:

I'm using a vertical NSSplitView and have a couple of questions
regarding resize and collapse of its contained views.

The problem:
------------
In the left-side-pane of my NSSplitView I have a subview with the x
origin set to a positive value (some left margin left space). The
subview's springs are set up to resize horizontally, no horizontal
struts. When I drag the splitview's divider to a size less then the
subview's x origin, and then drag it back out to its original
position, the subview's width gets greatly increased, right off the
side of the left-side-pane.

Some say a picture is worth a 1000 words. I have provided both. :)
The following are some ASCII-art pictures (best seen in a monospaced
font) that diagram the problem, where "SV" is the subview mentioned
previously:

1) At start, before resize:

+------------------+-+---------+
| left-side-pane | | right- |
| +-----+ | | side- |
| | SV | | | pane |
| +-----+ | | |
| | | |
+------------------+-+---------+
^ NSSplitView
|-- divider


2) Using the mouse, I drag the divider to the left of the subview's
(SV) left edge:

+--+-+-------------------------+
| | | right-side-pane |
| | | |
| | | |
| | | |
| | | |
+--+-+-------------------------+


3) using the mouse, I then drag the divider back out to its original position:

+------------------+-+---------+
| left-side-pane | | right- |
| +-------------| | side- |
| | SV | | pane |
| +-------------| | |
| | | |
+------------------+-+---------+

Note now how the subview's (SV) width is now different.



A Partial Solution...
----------------------
Well, this part of the problem isn't too perplexing. Clearly there's
some bad interaction going on somewhere in Cocoa-land when the
subview's width goes negative. I went Ahead and added a delegate that
handles NSSplitView's constrainMinCoordinate: and had it return a
minimum that was greater than the subview's left margin and I added a
canCollapseSubview: to the delegate that returns true so the user
could completely close off the left side of the split view. Works
dandy, the subview doesn't get whacked.

So, why did I start this newsgroup thread?
------------------------------------------
I couldn't leave well enough alone. My application also has a
programmatic means of toggling the collapse/uncollapse of the
left-side-pane. I do it by smooshing-down the width of left-side-pane
using a variation of the code found in OmniGroup's NSSplitView
category in their AppToolKit (their's is for top/bottom arrangements
-- which, btw, this problem exists for too). When programmatically resized, regardless of what I am doing with constrainMinCoordinate:
and canCollapseSubview:, I end up with the "subview too wide" problem
as seen in diagram #2 above.

My Questions to the gentle readers of this newsgroup (and hopeful writers :)
----------------------------------------------------------------------- -----
1) Is there a way to programmatically call something that will result
in NSSplitView doing it's "constrainMinCoordinate" delegation
activity as it does on user drag when I programmatically collapse the
left-hand-pane?

2) Or is there some fundamental error in my approach, and there is a
much better way to do this that I simply haven't explored here?

3) Anyone willing to talk about why the subview's width gets so wide?

I really would like to avoid having to keep state info on the subview
and manually remove its horizontal stretchiness on collapse and then
restore it on uncollapse. That feels like a hack to me. Thus, my
questions. Hopefully I learn something from having asked.

Thank you for having taken the time to read this and triple-thanks to
those who end up replying.

I had a lot of trouble with issues like this in my app. Here's some things I've learned:

* "splitView:constrainMinCoordinate:ofSubviewAt:" should actually return (proposedMin + the minimum width you want).
* Implement "splitView:resizeSubviewsWithOldSize:" to adjust the space between the left and right sub-views. If you subtract space from one sub-view, add it to the other. And if you add space to the right-hand sub-view, subtract that space from the right-hand view's frame's origin, and if you subtract space, add to the origin.
* Even after doing that, my left-hand pane's controls gained about 4 pixels or so every time I moved the divider around. I had to write a fix-up method to enforce the margins I wanted.
* I also had to implement "windowWillResize:toSize:" to limit how the window can be resized when the divider was collapsed versus when it was open.

It was a huge pain. I don't know why, but resize logic almost never works right, in any programming framework I've used. Except Dylan's DUIM, which seems to somehow get it right. Even Java gives me grief.

I have four issues with the springs-and-struts system. First, controls can't be positioned relative to other controls in the same view or other views; the springs and struts only act in relation to the containing view. Second, only windows seem to have minimum/maximum sizes; controls need these too. Third, container controls like NSTableView or NSSplitView don't allow much resizing flexibility -- it's basically proportional or nothing -- and they have "bugs" like that 4-pixel thing above.

And (not related to the implementation) the resizing docs are almost useless. In addition to plainly erroneous/missing information like the "constrainMinCoordinate" method's return value, they also do not describe how the different parts interact with each other from a holistic viewpoint. Like, how did I find out about that origin thing? Through trial and error. The NSSplitView docs didn't say anything about shifting origins around.

Anyway, I hope this helps.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Getting subviews to restore on NSSplitView collapse/uncollapse (From: Jay Koutavas <email@hidden>)

  • Prev by Date: Re: Shouldn't there be a cocoa-talk mailing list?
  • Next by Date: Re: Separate list really needed?
  • Previous by thread: Getting subviews to restore on NSSplitView collapse/uncollapse
  • Next by thread: StarupItems problem ...
  • Index(es):
    • Date
    • Thread