ui/cocoa/container.m

changeset 847
50de0f36973f
parent 846
ffa983c223c1
child 851
367b2bbbc07e
equal deleted inserted replaced
846:ffa983c223c1 847:50de0f36973f
74 return (__bridge void*)grid; 74 return (__bridge void*)grid;
75 } 75 }
76 76
77 UIWIDGET ui_frame_create(UiObject *obj, UiFrameArgs *args) { 77 UIWIDGET ui_frame_create(UiObject *obj, UiFrameArgs *args) {
78 NSString *title = args->label ? [[NSString alloc]initWithUTF8String:args->label] : nil; 78 NSString *title = args->label ? [[NSString alloc]initWithUTF8String:args->label] : nil;
79 FrameContainer *frame = [[FrameContainer alloc] init:title]; UiLayout layout = UI_ARGS2LAYOUT(args); 79 FrameContainer *frame = [[FrameContainer alloc] init:title];
80 UiLayout layout = UI_ARGS2LAYOUT(args);
80 ui_container_add(obj, frame, &layout); 81 ui_container_add(obj, frame, &layout);
81 82
82 // add container to the chain 83 // add container to the chain
83 UiContainerX *container; 84 UiContainerX *container;
84 UiLayout subLayout = {0}; 85 UiLayout subLayout = {0};
113 } 114 }
114 } 115 }
115 116
116 uic_object_push_container(obj, container); 117 uic_object_push_container(obj, container);
117 118
118 return NULL; 119 return (__bridge void*)frame;
120 }
121
122 UIWIDGET ui_scrolledwindow_create(UiObject *obj, UiFrameArgs *args) {
123 int colspacing = args->spacing;
124 int rowspacing = args->spacing;
125 if(args->subcontainer == UI_CONTAINER_GRID) {
126 colspacing = args->columnspacing;
127 rowspacing = args->rowspacing;
128 }
129 ScrollViewContainer *scrollview = [[ScrollViewContainer alloc]init:args->subcontainer columnSpacing:colspacing rowSpacing:rowspacing];
130 scrollview.hasVerticalScroller = YES;
131 scrollview.scrollerStyle = NSScrollerStyleOverlay;
132 scrollview.autohidesScrollers = YES;
133 UiLayout layout = UI_ARGS2LAYOUT(args);
134 ui_container_add(obj, scrollview, &layout);
135
136 UiContainerX *container = ui_create_container(obj, scrollview);
137 uic_object_push_container(obj, container);
138
139 return (__bridge void*)scrollview;
119 } 140 }
120 141
121 void ui_container_begin_close(UiObject *obj) { 142 void ui_container_begin_close(UiObject *obj) {
122 UiContainerX *ct = obj->container_end; 143 UiContainerX *ct = obj->container_end;
123 ct->close = 1; 144 ct->close = 1;
159 ]]; 180 ]];
160 } 181 }
161 182
162 @end 183 @end
163 184
185
186 /* -------------------------- Expander Container -------------------------- */
187
188 // TODO
189
190
191 /* ------------------------ ScrollView Container ------------------------ */
192
193 @implementation ScrollViewContainer
194
195 @synthesize container = _container;
196
197 - (id)init:(UiSubContainerType)subContainer columnSpacing:(int)columnSpacing rowSpacing:(int)rowSpacing {
198 self = [super init];
199
200 if(subContainer != UI_CONTAINER_NO_SUB) {
201 GridLayout *child;
202 switch(subContainer) {
203 default:
204 case UI_CONTAINER_VBOX: {
205 child = [[BoxContainer alloc]init:NSUserInterfaceLayoutOrientationVertical spacing:columnSpacing];
206 break;
207 }
208 case UI_CONTAINER_HBOX: {
209 child = [[BoxContainer alloc]init:NSUserInterfaceLayoutOrientationHorizontal spacing:columnSpacing];
210 break;
211 }
212 case UI_CONTAINER_GRID: {
213 child = [[GridLayout alloc]init];
214 child.columnspacing = columnSpacing;
215 child.rowspacing = rowSpacing;
216 break;
217 }
218 }
219 child.translatesAutoresizingMaskIntoConstraints = NO;
220
221 self.documentView = child;
222 [child.widthAnchor constraintEqualToAnchor:self.contentView.widthAnchor].active = YES;
223
224 _child = child;
225 }
226
227
228 return self;
229 }
230
231 - (void) addView:(NSView*)view layout:(UiLayout*)layout {
232 if(_child != nil) {
233 _child.container = self.container; // required, otherwise child has no container and can't access the newline property
234 view.translatesAutoresizingMaskIntoConstraints = NO;
235 [_child addView:view layout:layout];
236 } else {
237 self.documentView = view;
238 [view.widthAnchor constraintEqualToAnchor:self.contentView.widthAnchor].active = YES;
239 }
240 }
241
242 @end
243
164 /* ------------------------- private functions ------------------------- */ 244 /* ------------------------- private functions ------------------------- */
165 245
166 UiContainerX* ui_create_container(UiObject *obj, id<Container> container) { 246 UiContainerX* ui_create_container(UiObject *obj, id<Container> container) {
167 UiContainerX *ctn = ui_malloc(obj->ctx, sizeof(UiContainerX)); 247 UiContainerX *ctn = ui_malloc(obj->ctx, sizeof(UiContainerX));
168 ctn->container = (__bridge void*)container; 248 ctn->container = (__bridge void*)container;
181 adjustedLayout.margin_left = adjustedLayout.margin; 261 adjustedLayout.margin_left = adjustedLayout.margin;
182 adjustedLayout.margin_right = adjustedLayout.margin; 262 adjustedLayout.margin_right = adjustedLayout.margin;
183 adjustedLayout.margin_top = adjustedLayout.margin; 263 adjustedLayout.margin_top = adjustedLayout.margin;
184 adjustedLayout.margin_bottom = adjustedLayout.margin; 264 adjustedLayout.margin_bottom = adjustedLayout.margin;
185 } 265 }
186 [container addView:view layout:layout]; 266 [container addView:view layout:&adjustedLayout];
187 } 267 }
188 268

mercurial