ui/cocoa/GridLayout.m

Thu, 12 Dec 2024 20:01:43 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 12 Dec 2024 20:01:43 +0100
changeset 100
d2bd73d28ff1
permissions
-rw-r--r--

update toolkit

100
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2024 Olaf Wintermann. All rights reserved.
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
d2bd73d28ff1 update toolkit
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
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #import "GridLayout.h"
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
31
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 @implementation GridLayout
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 @synthesize label=_label;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 @synthesize uilayout=_uilayout;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 @synthesize newline=_newline;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 - (GridLayout*)init {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 self = [super init];
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41 _columnspacing = 0;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
42 _rowspacing = 0;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 _children = cxArrayListCreateSimple(sizeof(GridElm), 32);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
45 return self;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
46 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 /*
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 - (void) layout {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 [super layout];
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 NSRect r1 = _test.frame;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 NSSize s1 = _test.intrinsicContentSize;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 NSEdgeInsets e1 = _test.alignmentRectInsets;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 printf("fuck\n");
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58 */
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 - (void) layout {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 int ncols = _cols+1;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 int nrows = _rows+1;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 GridDef *coldef = calloc(ncols, sizeof(GridDef));
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 GridDef *rowdef = calloc(nrows, sizeof(GridDef));
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 NSRect viewFrame = self.frame;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 int colspacing = _columnspacing;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71 int rowspacing = _rowspacing;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 CxIterator i = cxListIterator(_children);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 cx_foreach(GridElm *, elm, i) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 NSSize size = elm->view.intrinsicContentSize;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 NSEdgeInsets alignment = elm->view.alignmentRectInsets;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 if(size.width != NSViewNoIntrinsicMetric) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 CGFloat width = size.width + alignment.left + alignment.right;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 if(width > coldef[elm->x].preferred_size) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 coldef[elm->x].preferred_size = width;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 if(size.height != NSViewNoIntrinsicMetric) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84 CGFloat height = size.height + alignment.top + alignment.right;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 //CGFloat height = size.height;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 if(height > rowdef[elm->y].preferred_size) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 rowdef[elm->y].preferred_size = height;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91 if(elm->hexpand) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 coldef[elm->x].extend = TRUE;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 if(elm->vexpand) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 rowdef[elm->y].extend = TRUE;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 int col_ext = 0;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 int row_ext = 0;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 int preferred_width = 0;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 int preferred_height = 0;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 for(int j=0;j<ncols;j++) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 preferred_width += coldef[j].preferred_size + colspacing;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 if(coldef[j].extend) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 col_ext++;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 for(int j=0;j<nrows;j++) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 preferred_height += rowdef[j].preferred_size + rowspacing;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112 if(rowdef[j].extend) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113 row_ext++;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
116
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
117 _preferredSize.width = preferred_width;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 _preferredSize.height = preferred_height;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 int hremaining = viewFrame.size.width - preferred_width;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122 int vremaining = viewFrame.size.height - preferred_height;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 int hext = hremaining/col_ext;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 int vext = vremaining/row_ext;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 for(int j=0;j<ncols;j++) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127 GridDef *col = &coldef[j];
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128 if(col->extend) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 col->size = col->preferred_size + hext;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 } else {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 col->size = col->preferred_size;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134 for(int j=0;j<nrows;j++) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135 GridDef *row = &rowdef[j];
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 if(row->extend) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137 row->size = row->preferred_size + vext;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138 } else {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
139 row->size = row->preferred_size;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143 int pos = 0;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144 for(int j=0;j<ncols;j++) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145 coldef[j].pos = pos;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 pos += coldef[j].size + colspacing;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
147 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
148 pos = 0;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149 for(int j=0;j<nrows;j++) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150 rowdef[j].pos = pos;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
151 pos += rowdef[j].size + rowspacing;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
152 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
153
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154 i = cxListIterator(_children);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
155 cx_foreach(GridElm *, elm, i) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
156 //NSSize size = elm->view.intrinsicContentSize;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
157 GridDef *col = &coldef[elm->x];
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158 GridDef *row = &rowdef[elm->y];
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
160 NSEdgeInsets alignment = elm->view.alignmentRectInsets;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
161 NSRect frame;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
162 frame.size.width = col->size;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163 frame.size.height = row->size;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164 frame.origin.x = col->pos - (alignment.left+alignment.right)/2;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
165 frame.origin.y = viewFrame.size.height - row->pos - frame.size.height + ((alignment.top+alignment.right)/2);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
166 elm->view.frame = frame;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
167 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
168
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
169 free(coldef);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
170 free(rowdef);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
171 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
172
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
173
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
174 - (NSSize)intrinsicContentSize {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
175 return self.preferredSize;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
176 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178 - (void) addView:(NSView*)view fill:(BOOL)fill {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
179 if(_newline) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
180 _y++;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
181 _x = 0;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182 _newline = FALSE;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185 GridElm elm;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186 elm.x = _x;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187 elm.y = _y;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188 elm.margin = 0;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
189 elm.colspan = _uilayout.colspan;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
190 elm.rowspan = _uilayout.rowspan;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
191 elm.hfill = _uilayout.hfill;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
192 elm.vfill = _uilayout.vfill;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193 elm.hexpand = _uilayout.hexpand;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
194 elm.vexpand = _uilayout.vexpand;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
195 elm.view = view;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196 cxListAdd(_children, &elm);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198 [self addSubview:view];
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199 self.needsLayout = YES;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
200
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
201 if(_x > _cols) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
202 _cols = _x;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
203 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
204 if(_y > _rows) {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
205 _rows = _y;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
206 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
207 _x++;
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
208 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
209
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
210 - (void) dealloc {
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
211 cxListDestroy(_children);
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
212 }
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
213
d2bd73d28ff1 update toolkit
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
214 @end

mercurial