ui/cocoa/GridLayout.m

changeset 110
c00e968d018b
parent 109
c3dfcb8f0be7
child 112
c3f2f16fa4b8
equal deleted inserted replaced
109:c3dfcb8f0be7 110:c00e968d018b
39 - (GridLayout*)init { 39 - (GridLayout*)init {
40 self = [super init]; 40 self = [super init];
41 _columnspacing = 0; 41 _columnspacing = 0;
42 _rowspacing = 0; 42 _rowspacing = 0;
43 _children = cxArrayListCreateSimple(sizeof(GridElm), 32); 43 _children = cxArrayListCreateSimple(sizeof(GridElm), 32);
44 _preferredSize.width = -1;
45 _preferredSize.height = -1;
44 46
45 return self; 47 return self;
46 } 48 }
47 49
48 /* 50 /*
78 GridDef *col = &cols[x]; 80 GridDef *col = &cols[x];
79 GridDef *row = &rows[y]; 81 GridDef *row = &rows[y];
80 82
81 NSSize size = elm->view.intrinsicContentSize; 83 NSSize size = elm->view.intrinsicContentSize;
82 NSSize size2 = elm->view.fittingSize; 84 NSSize size2 = elm->view.fittingSize;
83 NSEdgeInsets alignment = elm->view.alignmentRectInsets;
84 // TODO: remove alignment
85 alignment.left = 0;
86 alignment.right = 0;
87 alignment.top = 0;
88 alignment.bottom = 0;
89 if(size.width == NSViewNoIntrinsicMetric) { 85 if(size.width == NSViewNoIntrinsicMetric) {
90 size.width = size2.width; 86 size.width = size2.width;
91 } 87 }
92 if(size.height == NSViewNoIntrinsicMetric) { 88 if(size.height == NSViewNoIntrinsicMetric) {
93 size.height = size2.height; 89 size.height = size2.height;
94 } 90 }
95 if(size.width != NSViewNoIntrinsicMetric) { 91 if(size.width != NSViewNoIntrinsicMetric) {
96 CGFloat width = size.width + alignment.left + alignment.right; 92 CGFloat width = size.width;
97 if(width > cols[elm->x].preferred_size && elm->colspan <= 1 && span_max == 1) { 93 if(width > cols[elm->x].preferred_size && elm->colspan <= 1 && span_max == 1) {
98 cols[elm->x].preferred_size = width; 94 cols[elm->x].preferred_size = width;
99 } 95 }
100 elm->preferred_width = width; 96 elm->preferred_width = width;
101 } 97 }
102 if(size.height != NSViewNoIntrinsicMetric) { 98 if(size.height != NSViewNoIntrinsicMetric) {
103 CGFloat height = size.height + alignment.top + alignment.right; 99 CGFloat height = size.height;
104 //CGFloat height = size.height; 100 //CGFloat height = size.height;
105 if(height > rows[elm->y].preferred_size && elm->rowspan <= 1 && span_max == 1) { 101 if(height > rows[elm->y].preferred_size && elm->rowspan <= 1 && span_max == 1) {
106 rows[elm->y].preferred_size = height; 102 rows[elm->y].preferred_size = height;
107 } 103 }
108 elm->preferred_height = height; 104 elm->preferred_height = height;
288 free(rows); 284 free(rows);
289 } 285 }
290 286
291 287
292 - (NSSize)intrinsicContentSize { 288 - (NSSize)intrinsicContentSize {
289 if(_preferredSize.width == -1) {
290 [self layout];
291 }
293 return self.preferredSize; 292 return self.preferredSize;
294 } 293 }
295 294
296 - (void) addView:(NSView*)view { 295 - (void) addView:(NSView*)view {
296 _preferredSize.width = -1;
297 _preferredSize.height = -1;
298
297 if(_newline) { 299 if(_newline) {
298 _y++; 300 _y++;
299 _x = 0; 301 _x = 0;
300 _newline = FALSE; 302 _newline = FALSE;
301 } 303 }

mercurial