Skip to content

Instantly share code, notes, and snippets.

@hexsprite
Created April 16, 2010 01:03
Show Gist options
  • Select an option

  • Save hexsprite/367867 to your computer and use it in GitHub Desktop.

Select an option

Save hexsprite/367867 to your computer and use it in GitHub Desktop.
Ups.GridLayout = SC.View.extend({
init: function() {
sc_super();
var childViews = this.get('childViews'), idx, height, width, x, y, top, left, view, heightpct, widthpct;
// calculate height / width percentages
height = this.get('gridlayout').height;
heightpct = 1 / height;
width = this.get('gridlayout').width;
widthpct = 1 / width;
idx = 0;
for (x = 0; x < width; x++) {
for (y = 0; y < height; y++) {
top = x * heightpct;
left = y * widthpct;
view = childViews[idx++];
var layout = {top: top, left: left, height: heightpct, width: widthpct };
view.layout = layout;
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment