Look at supporting Cocoa's Auto Layout.
In 10.7, Apple added a really interesting new method for building interfaces. I think this could be a replacement for the posSize argument in the standard vanilla object constructor. It's definitely worth a try.
I have skimmed the conceptual documentation and a couple of blog posts and I think the two bits of data are the layout string and an identifier hat the layout engine uses in conjunction with the layout string. These are my initial thoughts for the layout string:
- posSize could be a triple as it has been for years or it could be a string. If it is a string, the string is the auto layout string.
- A new autoLayout keyword argument.
For the identifier:
- Use the attribute name that is used when adding the object to the super view.
- Add a new autoLayoutIdentifier.
I think using the string as posSize and the attribute name as he identifier seem the cleanest. I'll experiment with the timing and structure of all of this.
a proposal for the auto layout https://gist.github.com/typemytype/b9c85801762c579448d7
a proposal for the auto layout
From an API perspective, this looks cool. The internal code looks nice and simple, too. The only less-than-vanilla-like-thing is the constraint syntax:
V:|-padding-[info(>=controlHeight)]-padding-[info1(>=controlHeight)]-80-|
However, it's well document and we wouldn't have to reinvent the wheel so it's probably best to use it as specced by Apple.
I'm still trying to understand that syntax, but overall this looks good!
I'm going to create a branch, implement this and see what happens. I'd really like to add NSCollectionView, NSStackView and NSGridView to vanilla and those require auto layout. I'll submit a PR if it works.
Regarding the PR I just submitted: there are two other views that could be useful for auto layout:
- NSGridView
- NSCollectionView
I have NSGridView wrapped and in an experiment, but it's complex and doesn't feel ready yet. I haven't wrapped NSCollectionView yet. That one may be too complex to wrap with vanilla.
I'll keep adjusting auto layout and implement things as they seem necessary. What I have now is a good starting point.
@typesupply: Did you ever get anywhere with NSGridView? I would be interested in seeing the experiment you did (and maybe finishing it).
Did you ever get anywhere with NSGridView?
No. I focused on NSCollectionView. I'll publish that at some point, but it probably won't be in vanilla. It's a pretty different set of concepts.
Fair enough; I got most of what I wanted with a list view and horrible hackery.
"horrible hackery" should be the code name for vanilla. 😄