-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|208|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
SoCoder -> Snippet Home -> Text and GUI's


 
Cower
Created : 10 April 2010
Edited : 11 April 2010
System : Mac
Language : C#

NLayoutView

View that permits relative layouts among subviews (similar to the Android RelativeLayout viewgroup)

This is a fairly simple NSView subclass that performs layout of its subviews using relative constraints or rules (depending on what GUI you're used to, the terms probably differ). This is inspired mainly by the Android RelativeLayout viewgroup that allows for roughly the same thing. It behaves in more or less the same manner - it iterates over subviews in the order that they are added to the view, applies the rules, and moves on to the next. As such, you should avoid circular relations between subviews.

The API is fairly simple, just look at the NLayoutView header for reference. The layout params all have comments describing the relation between subview and base.

Again, this uses the MIT license.

If you want to see a short example of this being used, here's a video:

Example Code

Source Code

 

Comments


Saturday, 10 April 2010, 15:54
Cower
Just added alignment of edges to the horizontal/vertical centers of bases. That should make things a bit more flexible, I think...
Sunday, 11 April 2010, 23:38
Cower
Fixed some bugs here and there. The performLayout message no longer needs to be sent manually, since the view will observe base views for frame changes and queue up a call to performLayout (see the Private category for implementation details - might be of interest since it uses libdispatch). Also, I moved the code into a gist, since copy/pasting it in here is a pain.