Re: Triangle Collapse
Re: Triangle Collapse
- Subject: Re: Triangle Collapse
- From: Bill Cheeseman <email@hidden>
- Date: Tue, 12 Aug 2003 06:09:53 -0400
on 03-08-12 5:30 AM, email@hidden at email@hidden wrote:
>
Is there a standard way do to the collapsing windows that have parts
>
that can be expanded or hidden by click a button (usually a triangle).
It isn't hard. Here's approximately what I do, made up from scratch on the
basis of first principles:
1. Design the window in Interface Builder in its expanded state.
2. Put any on/off button where you will eventually install the triangle (the
triangle isn't available in IB in Jaguar).
3. Set up the springs and struts for everything in the window, using IB's
Size inspector pane, so that it resizes properly when the user drags the
grow area. When you have these right, they will work correctly whether the
window is expanded or collapsed.
4. Write an action method to expand/collapse the window, and connect it to
the button in IB. In the action method, programmatically reset the springs
and struts if necessary so that anything like a text view in the
expanding/collapsing part of the window will grow or shrink smoothly when
the action method is triggered (in other words, force Cocoa to do the
resizing and repositioning of controls in the collapsing/expanding area of
the window for you). Reset the springs and struts at the end of the action
method so that user resizing will once again work correctly. In the middle
of the action method, call NSWindow's -setFrame:display:animate: method to
expand or collapse the window to the other size smoothly with animation.
This requires a little arithmetic on the window frame's origin.y and
size.height fields to pin the window's top left corner to a constant point
on the screen, since a window's origin is normally at the bottom left.
5. Assuming you want your user to see the window initially in its collapsed
state: In your -awakeFromNib override, set the button's state to NSOffState
programmatically (to simulate the user's having clicked it, in order to get
the UI right before calling the action method), set the window's frame to
its default expanded size in case it comes out of the nib at the wrong size
(for the same reason), and call your action method to collapse it.
6. "Borrow" the expanded and collapsed arrow graphics from another
application (Interface Builder has good ones), or draw your own in a
graphics app. Add them to your project in PB. In your -awakeFromNib
override, set the button's image and alternateImage to the two borrowed
graphics.
7. Test and revise to taste.
Alternatively, wait for Panther.
I'm told that there are ready-made third-party frameworks to do all this.
Somebody posted a URL recently, so search mamasam for it.
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
http://www.quecheesoftware.com
The AppleScript Sourcebook -
http://www.AppleScriptSourcebook.com
Vermont Recipes -
http://www.stepwise.com/Articles/VermontRecipes
_______________________________________________
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.