Cappuccino : automatic recursive layout

Posted: February 11, 2009 in IT/Dev
Tags: , , ,

Among many stunning features in Cappuccino for user interfaces creation (and among Interface Builder, dynamic binding/delegation chain, infinite and non fixed combination of components, specialization without need for inheritance – by using delegates -, very high abstraction level) is automatic layout management (tutorial posted two months ago). Contrary to JSP tags libraries (including JSF) and Java/Swing components, Cappuccino’s AppKit (as with Cocoa) automatically manages the layout of components in the parent container view.
We just have to define for each component the desired behaviours (constraints), through a properties mask (setted by using the setAutoresizingMask method) : CPViewWidthSizable, CPViewHeightSizable, CPViewMinXMargin, CPViewMaxXMargin, CPViewMinYMargin, CPViewMaxYMargin. The parent view then takes care of the components layout automatically, in a recursive manner (if nested views levels).

In a recent thread, a user stated :
Thankfully “layout managers” are a dopey Java-like paradigm that Cocoa avoids. Cocoa pretty much has one (fairly sensible) layout paradigm. If you look at the 6 layout-related attributes that you can set on any view in IB, these translate directly to flags that you can set on any view’s setAutoresizingMask: method from code. Views tell their parent which edges they want to be anchored to and which directions they wish their size to be expanded in. CPView figures out the rest “automagically” when it lays out its subview.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s