ui/cocoa/GridLayout.m

4 days ago

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 30 Mar 2025 16:38:27 +0200 (4 days ago)
changeset 538
5004b4a9b16d
parent 449
7681d538deaf
permissions
-rw-r--r--

use view.fittingSize as backup to intrisicContentSize in GridLayout (Cocoa)

404
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2024 Olaf Wintermann. All rights reserved.
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #import "GridLayout.h"
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 @implementation GridLayout
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 @synthesize label=_label;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 @synthesize uilayout=_uilayout;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 @synthesize newline=_newline;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 - (GridLayout*)init {
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 self = [super init];
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 _columnspacing = 0;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 _rowspacing = 0;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 _children = cxArrayListCreateSimple(sizeof(GridElm), 32);
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 return self;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 }
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 /*
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 - (void) layout {
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 [super layout];
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 NSRect r1 = _test.frame;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 NSSize s1 = _test.intrinsicContentSize;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 NSEdgeInsets e1 = _test.alignmentRectInsets;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 }
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 */
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 - (void) layout {
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 int ncols = _cols+1;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 int nrows = _rows+1;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63
448
629ac70913aa implement grid hfill/vfill (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 447
diff changeset
64 GridDef *cols = calloc(ncols, sizeof(GridDef));
629ac70913aa implement grid hfill/vfill (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 447
diff changeset
65 GridDef *rows = calloc(nrows, sizeof(GridDef));
404
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 NSRect viewFrame = self.frame;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 int colspacing = _columnspacing;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 int rowspacing = _rowspacing;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71
449
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
72 int span_max = 1;
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
73 for(int r=0;r<2;r++) {
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
74 CxIterator i = cxListIterator(_children);
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
75 cx_foreach(GridElm *, elm, i) {
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
76 int x = elm->x;
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
77 int y = elm->y;
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
78 GridDef *col = &cols[x];
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
79 GridDef *row = &rows[y];
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
80
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
81 NSSize size = elm->view.intrinsicContentSize;
538
5004b4a9b16d use view.fittingSize as backup to intrisicContentSize in GridLayout (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
82 NSSize size2 = elm->view.fittingSize;
449
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
83 NSEdgeInsets alignment = elm->view.alignmentRectInsets;
538
5004b4a9b16d use view.fittingSize as backup to intrisicContentSize in GridLayout (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
84 // TODO: remove alignment
5004b4a9b16d use view.fittingSize as backup to intrisicContentSize in GridLayout (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
85 alignment.left = 0;
5004b4a9b16d use view.fittingSize as backup to intrisicContentSize in GridLayout (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
86 alignment.right = 0;
5004b4a9b16d use view.fittingSize as backup to intrisicContentSize in GridLayout (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
87 alignment.top = 0;
5004b4a9b16d use view.fittingSize as backup to intrisicContentSize in GridLayout (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
88 alignment.bottom = 0;
5004b4a9b16d use view.fittingSize as backup to intrisicContentSize in GridLayout (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
89 if(size.width == NSViewNoIntrinsicMetric) {
5004b4a9b16d use view.fittingSize as backup to intrisicContentSize in GridLayout (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
90 size.width = size2.width;
5004b4a9b16d use view.fittingSize as backup to intrisicContentSize in GridLayout (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
91 }
5004b4a9b16d use view.fittingSize as backup to intrisicContentSize in GridLayout (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
92 if(size.height == NSViewNoIntrinsicMetric) {
5004b4a9b16d use view.fittingSize as backup to intrisicContentSize in GridLayout (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
93 size.height = size2.height;
5004b4a9b16d use view.fittingSize as backup to intrisicContentSize in GridLayout (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
94 }
449
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
95 if(size.width != NSViewNoIntrinsicMetric) {
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
96 CGFloat width = size.width + alignment.left + alignment.right;
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
97 if(width > cols[elm->x].preferred_size && elm->colspan <= 1 && span_max == 1) {
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
98 cols[elm->x].preferred_size = width;
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
99 }
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
100 elm->preferred_width = width;
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
101 }
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
102 if(size.height != NSViewNoIntrinsicMetric) {
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
103 CGFloat height = size.height + alignment.top + alignment.right;
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
104 //CGFloat height = size.height;
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
105 if(height > rows[elm->y].preferred_size && elm->rowspan <= 1 && span_max == 1) {
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
106 rows[elm->y].preferred_size = height;
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
107 }
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
108 elm->preferred_height = height;
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
109 }
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
110
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
111 if(elm->rowspan > span_max || elm->colspan > span_max) {
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
112 continue;
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
113 }
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
114
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
115 int end_col = x+elm->colspan;
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
116 if(end_col > ncols) {
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
117 end_col = ncols;
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
118 }
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
119 int end_row = y+elm->rowspan;
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
120 if(end_row > nrows) {
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
121 end_row = nrows;
404
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122 }
449
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
123
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
124 // are all columns in the span > preferred_width?
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
125 if(elm->colspan > 1) {
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
126 int span_width = 0;
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
127 GridDef *last_col = col;
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
128 for(int c=x;c<end_col;c++) {
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
129 span_width += cols[c].size;
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
130 last_col = &cols[c];
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
131 }
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
132 if(span_width < elm->preferred_width) {
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
133 last_col->size += elm->preferred_width - span_width;
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
134 }
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
135 }
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
136 // are all rows in the span > preferred_height?
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
137 if(elm->rowspan > 1) {
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
138 int span_height = 0;
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
139 GridDef *last_row = row;
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
140 for(int c=x;c<end_row;c++) {
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
141 span_height += rows[c].size;
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
142 last_row = &rows[c];
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
143 }
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
144 if(span_height < elm->preferred_height) {
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
145 last_row->size += elm->preferred_height - span_height;
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
146 }
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
147 }
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
148
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
149 if(elm->hexpand) {
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
150 if(elm->colspan > 1) {
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
151 // check if any column in the span is expanding
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
152 // if not, make the last column expanding
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
153 GridDef *last_col = col;
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
154 for(int c=x;c<end_col;c++) {
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
155 last_col = &cols[c];
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
156 if(last_col->expand) {
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
157 break;
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
158 }
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
159 }
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
160 last_col->expand = TRUE;
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
161 } else {
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
162 col->expand = TRUE;
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
163 }
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
164 }
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
165 if(elm->vexpand) {
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
166 if(elm->rowspan > 1) {
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
167 // same as colspan
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
168 GridDef *last_row = row;
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
169 for(int c=x;c<nrows;c++) {
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
170 last_row = &rows[c];
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
171 if(last_row->expand) {
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
172 break;
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
173 }
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
174 }
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
175 last_row->expand = TRUE;
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
176 } else {
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
177 row->expand = TRUE;
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
178 }
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
179 }
404
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
180 }
449
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
181 span_max = 50000; // not sure if this is unreasonable low or high
404
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182 }
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183
449
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
184
404
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185 int col_ext = 0;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186 int row_ext = 0;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188 int preferred_width = 0;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
189 int preferred_height = 0;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190 for(int j=0;j<ncols;j++) {
448
629ac70913aa implement grid hfill/vfill (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 447
diff changeset
191 preferred_width += cols[j].preferred_size + colspacing;
629ac70913aa implement grid hfill/vfill (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 447
diff changeset
192 if(cols[j].expand) {
404
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193 col_ext++;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
194 }
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
195 }
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196 for(int j=0;j<nrows;j++) {
448
629ac70913aa implement grid hfill/vfill (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 447
diff changeset
197 preferred_height += rows[j].preferred_size + rowspacing;
629ac70913aa implement grid hfill/vfill (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 447
diff changeset
198 if(rows[j].expand) {
404
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199 row_ext++;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
200 }
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
201 }
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
202
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
203 _preferredSize.width = preferred_width;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
204 _preferredSize.height = preferred_height;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
205
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
206
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
207 int hremaining = viewFrame.size.width - preferred_width;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
208 int vremaining = viewFrame.size.height - preferred_height;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
209 int hext = hremaining/col_ext;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
210 int vext = vremaining/row_ext;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
211
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
212 for(int j=0;j<ncols;j++) {
448
629ac70913aa implement grid hfill/vfill (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 447
diff changeset
213 GridDef *col = &cols[j];
629ac70913aa implement grid hfill/vfill (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 447
diff changeset
214 if(col->expand) {
404
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
215 col->size = col->preferred_size + hext;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
216 } else {
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
217 col->size = col->preferred_size;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
218 }
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
219 }
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
220 for(int j=0;j<nrows;j++) {
448
629ac70913aa implement grid hfill/vfill (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 447
diff changeset
221 GridDef *row = &rows[j];
629ac70913aa implement grid hfill/vfill (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 447
diff changeset
222 if(row->expand) {
404
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
223 row->size = row->preferred_size + vext;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
224 } else {
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
225 row->size = row->preferred_size;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
226 }
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
227 }
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
228
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
229 int pos = 0;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
230 for(int j=0;j<ncols;j++) {
448
629ac70913aa implement grid hfill/vfill (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 447
diff changeset
231 cols[j].pos = pos;
629ac70913aa implement grid hfill/vfill (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 447
diff changeset
232 pos += cols[j].size + colspacing;
404
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
233 }
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
234 pos = 0;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
235 for(int j=0;j<nrows;j++) {
448
629ac70913aa implement grid hfill/vfill (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 447
diff changeset
236 rows[j].pos = pos;
629ac70913aa implement grid hfill/vfill (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 447
diff changeset
237 pos += rows[j].size + rowspacing;
404
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
238 }
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
239
449
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
240 CxIterator i = cxListIterator(_children);
404
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
241 cx_foreach(GridElm *, elm, i) {
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
242 //NSSize size = elm->view.intrinsicContentSize;
448
629ac70913aa implement grid hfill/vfill (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 447
diff changeset
243 GridDef *col = &cols[elm->x];
629ac70913aa implement grid hfill/vfill (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 447
diff changeset
244 GridDef *row = &rows[elm->y];
404
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
245
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
246 NSEdgeInsets alignment = elm->view.alignmentRectInsets;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
247 NSRect frame;
448
629ac70913aa implement grid hfill/vfill (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 447
diff changeset
248 if(elm->hfill) {
449
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
249 if(elm->colspan > 1) {
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
250 int cwidth = 0;
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
251 int end_col = elm->x + elm->colspan;
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
252 if(end_col > ncols) {
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
253 end_col = ncols;
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
254 }
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
255 for(int c=elm->x;c<end_col;c++) {
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
256 cwidth += cols[c].size;
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
257 }
538
5004b4a9b16d use view.fittingSize as backup to intrisicContentSize in GridLayout (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
258 frame.size.width = cwidth + + alignment.left + alignment.right;
449
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
259 } else {
538
5004b4a9b16d use view.fittingSize as backup to intrisicContentSize in GridLayout (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
260 frame.size.width = col->size + alignment.left + alignment.right;
449
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
261 }
448
629ac70913aa implement grid hfill/vfill (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 447
diff changeset
262 } else {
538
5004b4a9b16d use view.fittingSize as backup to intrisicContentSize in GridLayout (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
263 frame.size.width = elm->preferred_width + alignment.left + alignment.right;
448
629ac70913aa implement grid hfill/vfill (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 447
diff changeset
264 }
629ac70913aa implement grid hfill/vfill (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 447
diff changeset
265 if(elm->vfill) {
449
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
266 if(elm->rowspan > 1) {
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
267 int rheight = 0;
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
268 int end_row = elm->y + elm->rowspan;
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
269 if(end_row > nrows) {
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
270 end_row = nrows;
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
271 }
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
272 for(int r=elm->y;r<end_row;r++) {
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
273 rheight += rows[r].size;
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
274 }
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
275 frame.size.height = rheight;
7681d538deaf implement grid colspan/rowspan (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 448
diff changeset
276 }
448
629ac70913aa implement grid hfill/vfill (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 447
diff changeset
277 frame.size.height = row->size;
629ac70913aa implement grid hfill/vfill (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 447
diff changeset
278 } else {
629ac70913aa implement grid hfill/vfill (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 447
diff changeset
279 frame.size.height = elm->preferred_height;
629ac70913aa implement grid hfill/vfill (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 447
diff changeset
280 }
404
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
281 frame.origin.x = col->pos - (alignment.left+alignment.right)/2;
538
5004b4a9b16d use view.fittingSize as backup to intrisicContentSize in GridLayout (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
282 //frame.origin.y = viewFrame.size.height - row->pos - frame.size.height + ((alignment.top+alignment.right)/2);
5004b4a9b16d use view.fittingSize as backup to intrisicContentSize in GridLayout (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
283 frame.origin.y = viewFrame.size.height - row->pos - frame.size.height;
404
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
284 elm->view.frame = frame;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
285 }
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
286
448
629ac70913aa implement grid hfill/vfill (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 447
diff changeset
287 free(cols);
629ac70913aa implement grid hfill/vfill (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 447
diff changeset
288 free(rows);
404
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
289 }
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
290
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
291
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
292 - (NSSize)intrinsicContentSize {
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
293 return self.preferredSize;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
294 }
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
295
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
296 - (void) addView:(NSView*)view fill:(BOOL)fill {
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
297 if(_newline) {
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
298 _y++;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
299 _x = 0;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
300 _newline = FALSE;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
301 }
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
302
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
303 GridElm elm;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
304 elm.x = _x;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
305 elm.y = _y;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
306 elm.margin = 0;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
307 elm.colspan = _uilayout.colspan;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
308 elm.rowspan = _uilayout.rowspan;
538
5004b4a9b16d use view.fittingSize as backup to intrisicContentSize in GridLayout (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
309 if(_uilayout.fill) {
5004b4a9b16d use view.fittingSize as backup to intrisicContentSize in GridLayout (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
310 elm.hfill = TRUE;
5004b4a9b16d use view.fittingSize as backup to intrisicContentSize in GridLayout (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
311 elm.vfill = TRUE;
5004b4a9b16d use view.fittingSize as backup to intrisicContentSize in GridLayout (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
312 elm.hexpand = TRUE;
5004b4a9b16d use view.fittingSize as backup to intrisicContentSize in GridLayout (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
313 elm.vexpand = TRUE;
5004b4a9b16d use view.fittingSize as backup to intrisicContentSize in GridLayout (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
314 } else {
5004b4a9b16d use view.fittingSize as backup to intrisicContentSize in GridLayout (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
315 elm.hfill = _uilayout.hfill;
5004b4a9b16d use view.fittingSize as backup to intrisicContentSize in GridLayout (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
316 elm.vfill = _uilayout.vfill;
5004b4a9b16d use view.fittingSize as backup to intrisicContentSize in GridLayout (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
317 elm.hexpand = _uilayout.hexpand;
5004b4a9b16d use view.fittingSize as backup to intrisicContentSize in GridLayout (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
318 elm.vexpand = _uilayout.vexpand;
5004b4a9b16d use view.fittingSize as backup to intrisicContentSize in GridLayout (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 449
diff changeset
319 }
404
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
320 elm.view = view;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
321 cxListAdd(_children, &elm);
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
322
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
323 [self addSubview:view];
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
324 self.needsLayout = YES;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
325
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
326 if(_x > _cols) {
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
327 _cols = _x;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
328 }
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
329 if(_y > _rows) {
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
330 _rows = _y;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
331 }
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
332 _x++;
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
333 }
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
334
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
335 - (void) dealloc {
447
7618acaaf684 fix build (Cocoa)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 404
diff changeset
336 cxListFree(_children);
404
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
337 }
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
338
384f6d1f5784 add first working cocoa code
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
339 @end

mercurial