ui/cocoa/GridLayout.m

changeset 810
7b5ba65b246f
parent 800
814d374fb689
child 811
1391ba7e533f
equal deleted inserted replaced
809:f5ddce392617 810:7b5ba65b246f
56 NSEdgeInsets e1 = _test.alignmentRectInsets; 56 NSEdgeInsets e1 = _test.alignmentRectInsets;
57 57
58 } 58 }
59 */ 59 */
60 60
61 - (BOOL)isFlipped {
62 return YES;
63 }
61 64
62 - (void) layout { 65 - (void) layout {
63 int ncols = _cols+1; 66 int ncols = _cols+1;
64 int nrows = _rows+1; 67 int nrows = _rows+1;
65 68
66 GridDef *cols = calloc(ncols, sizeof(GridDef)); 69 GridDef *cols = calloc(ncols, sizeof(GridDef));
67 GridDef *rows = calloc(nrows, sizeof(GridDef)); 70 GridDef *rows = calloc(nrows, sizeof(GridDef));
68 71
69 NSRect viewFrame = self.frame; 72 //NSRect viewFrame = self.frame;
73 NSRect viewFrame = self.bounds;
70 74
71 int colspacing = _columnspacing; 75 int colspacing = _columnspacing;
72 int rowspacing = _rowspacing; 76 int rowspacing = _rowspacing;
73 77
74 int span_max = 1; 78 int span_max = 1;
247 cx_foreach(GridElm *, elm, i) { 251 cx_foreach(GridElm *, elm, i) {
248 //NSSize size = elm->view.intrinsicContentSize; 252 //NSSize size = elm->view.intrinsicContentSize;
249 GridDef *col = &cols[elm->x]; 253 GridDef *col = &cols[elm->x];
250 GridDef *row = &rows[elm->y]; 254 GridDef *row = &rows[elm->y];
251 255
252 NSEdgeInsets alignment = elm->view.alignmentRectInsets;
253 NSRect frame; 256 NSRect frame;
254 if(elm->hfill) { 257 if(elm->hfill) {
255 if(elm->colspan > 1) { 258 if(elm->colspan > 1) {
256 int cwidth = 0; 259 int cwidth = 0;
257 int end_col = elm->x + elm->colspan; 260 int end_col = elm->x + elm->colspan;
264 real_span++; 267 real_span++;
265 } 268 }
266 if(real_span > 0) { 269 if(real_span > 0) {
267 cwidth += (real_span-1) * colspacing; 270 cwidth += (real_span-1) * colspacing;
268 } 271 }
269 frame.size.width = cwidth + alignment.left + alignment.right; 272 frame.size.width = cwidth;
270 } else { 273 } else {
271 frame.size.width = col->size + alignment.left + alignment.right; 274 frame.size.width = col->size;
272 } 275 }
273 } else { 276 } else {
274 frame.size.width = elm->preferred_width + alignment.left + alignment.right; 277 frame.size.width = elm->preferred_width;
275 } 278 }
276 frame.size.width -= elm->margin.left + elm->margin.right; 279 frame.size.width -= elm->margin.left + elm->margin.right;
277 if(elm->vfill) { 280 if(elm->vfill) {
278 if(elm->rowspan > 1) { 281 if(elm->rowspan > 1) {
279 int rheight = 0; 282 int rheight = 0;
293 } 296 }
294 frame.size.height = row->size; 297 frame.size.height = row->size;
295 } else { 298 } else {
296 frame.size.height = elm->preferred_height; 299 frame.size.height = elm->preferred_height;
297 } 300 }
298 frame.size.height -= elm->margin.top + elm->margin.bottom; 301
299 frame.origin.x = col->pos + elm->margin.left - (alignment.left+alignment.right)/2; 302 frame.origin.x = col->pos + elm->margin.left;
300 //frame.origin.y = viewFrame.size.height - row->pos - frame.size.height + ((alignment.top+alignment.right)/2); 303 frame.origin.y = row->pos + elm->margin.top;
301 frame.origin.y = viewFrame.size.height - row->pos - elm->margin.top - frame.size.height; 304 NSRect viewFrame = [elm->view frameForAlignmentRect:frame];
302 elm->view.frame = frame; 305 elm->view.frame = viewFrame;
303 } 306 }
304 307
305 free(cols); 308 free(cols);
306 free(rows); 309 free(rows);
307 } 310 }

mercurial