views:

40

answers:

1

What I'm looking for is a way with CA to dynamically lay out a window. Imagine the following SQL query in a window, each name between +PLUSSIGNS+ being a NSPopUpButton, rest is static text.

Select *
from +BURRITOS/TACOS1+ +AND/OR1+
+BURRITOS/TACOS2+ +AND/OR2+
Where
+TOPPING1+ +EQUALS/LT/GT1+ +TOPPINGLIST1+ +AND/OR3+
+TOPPING2+ +EQUALS/LT/GT2+ +TOPPINGLIST2+ +AND/OR4+

Ok: So the window starts showing "Select *" and "from" plain text labels, and BURRITOS/TACOS1 selected to "--" instead of a valid value.

When I set BURRITOS/TACOS1 to a valid value (BURRITOS), I want the AND/OR1 NSPopUpButton to appear, selected to "--". I also want the "Where" label to appear and I want "TOPPING1" "EQUALS/LT/GT1" "TOPPINGLIST1" to appear. All 3 of those will be selected to "--".

When I put AND/OR1 to a valid value (AND or OR), I want BURRITOS/TACOS2 to appear. If I select that to a value, I want AND/OR2 to appear. If I set that to a value, I want BURRITOS/TACOS3 to appear ....

If I set TOPPING1, EQUALS/LT/GT1, and TOPPINGLIST1 to valid values I want AND/OR3 to appear (as "--"). If I set AND/OR3 to a valid value, I want TOPPING2, EQUALS/LT/GT2, TOPPINGLIST2 to appear. If I set them to valid values, I want AND/OR4 to appear...

If for instance AND/OR3 is set to -- and there was a line under it, I'd want that entire line to disappear.

At the bottom of the entire Window I need a static checkbox "enable", always appears. I also want a left and right arrow button - clicking left would make the entire window "flip" to the left. Clicking right would make the entire window "flip" to the right to new queries.

I'd like these new NSPopUpButtons to appear similar to Mail.app where a new text entry for CC BCC etc appears based on your settings using that picker control thing.

A: 

Ends up this is truly 2 questions.

1 - Dynamic layout of window. In simplest way this is done by putting an NSView in an NSWindow and then using NSView's addSubview.. example:

NSRect rect = NSMakeRect(0, y, 100, 10);
NSButton *button = [[NSButton alloc] initWithFrame:rect];

y += 15;
[topView addSubview:button];

Here an NSButton is put every 15 pixels inside the view. Note that y has to be maintained by me, it's not automatic. If we overrun our NSView bounds we have to manage that size ourselves as well.

2 - Animating this transition. Using Core Animation isn't that smart, the more sensible route is NSAnimation and specifically NSViewAnimation. There's a great example thanks to Apple here. For my purpose I need to use this to resize and also move NSViews. Also If I want a Button to "fade in" what I can do is copy the NSView, keep that as "old", modify my NSView, and fade between those.

...thanks to #cocoa on freenode..

Nektarios