ui/gtk/container.c

changeset 32
e5f4d8af567e
parent 29
3fc287f06305
equal deleted inserted replaced
31:bf810176ddb8 32:e5f4d8af567e
139 } 139 }
140 if(vexpand) { 140 if(vexpand) {
141 gtk_widget_set_vexpand(widget, TRUE); 141 gtk_widget_set_vexpand(widget, TRUE);
142 } 142 }
143 143
144 int gwidth = ct->layout.gridwidth > 0 ? ct->layout.gridwidth : 1; 144 int colspan = ct->layout.colspan > 0 ? ct->layout.colspan : 1;
145 145 int rowspan = ct->layout.rowspan > 0 ? ct->layout.rowspan : 1;
146 gtk_grid_attach(GTK_GRID(ct->widget), widget, grid->x, grid->y, gwidth, 1); 146
147 grid->x += gwidth; 147 gtk_grid_attach(GTK_GRID(ct->widget), widget, grid->x, grid->y, colspan, rowspan);
148 grid->x += colspan;
148 149
149 ui_reset_layout(ct->layout); 150 ui_reset_layout(ct->layout);
150 ct->current = widget; 151 ct->current = widget;
151 } 152 }
152 #endif 153 #endif
168 if(ct->layout.vexpand != UI_LAYOUT_UNDEFINED) { 169 if(ct->layout.vexpand != UI_LAYOUT_UNDEFINED) {
169 vexpand = ct->layout.vexpand; 170 vexpand = ct->layout.vexpand;
170 } 171 }
171 GtkAttachOptions xoptions = hexpand ? GTK_FILL | GTK_EXPAND : GTK_FILL; 172 GtkAttachOptions xoptions = hexpand ? GTK_FILL | GTK_EXPAND : GTK_FILL;
172 GtkAttachOptions yoptions = vexpand ? GTK_FILL | GTK_EXPAND : GTK_FILL; 173 GtkAttachOptions yoptions = vexpand ? GTK_FILL | GTK_EXPAND : GTK_FILL;
174
175 int colspan = ct->layout.colspan > 0 ? ct->layout.colspan : 1;
176 int rowspan = ct->layout.rowspan > 0 ? ct->layout.rowspan : 1;
177 // TODO: use colspan/rowspan
173 178
174 gtk_table_attach(GTK_TABLE(ct->widget), widget, grid->x, grid->x+1, grid->y, grid->y+1, xoptions, yoptions, 0, 0); 179 gtk_table_attach(GTK_TABLE(ct->widget), widget, grid->x, grid->x+1, grid->y, grid->y+1, xoptions, yoptions, 0, 0);
175 grid->x++; 180 grid->x++;
176 int nw = grid->x > grid->width ? grid->x : grid->width; 181 int nw = grid->x > grid->width ? grid->x : grid->width;
177 if(grid->x > grid->width || grid->y > grid->height) { 182 if(grid->x > grid->width || grid->y > grid->height) {
252 UIWIDGET ui_box_create(UiObject *obj, UiContainerArgs args, UiSubContainerType type) { 257 UIWIDGET ui_box_create(UiObject *obj, UiContainerArgs args, UiSubContainerType type) {
253 UiObject *current = uic_current_obj(obj); 258 UiObject *current = uic_current_obj(obj);
254 UiContainer *ct = current->container; 259 UiContainer *ct = current->container;
255 UI_APPLY_LAYOUT1(current, args); 260 UI_APPLY_LAYOUT1(current, args);
256 261
257 GtkWidget *vbox = ui_gtk_vbox_new(args.spacing); 262 GtkWidget *box = type == UI_CONTAINER_VBOX ? ui_gtk_vbox_new(args.spacing) : ui_gtk_hbox_new(args.spacing);
258 GtkWidget *widget = args.margin > 0 ? box_set_margin(vbox, args.margin) : vbox; 263 GtkWidget *widget = args.margin > 0 ? box_set_margin(box, args.margin) : box;
259 ct->add(ct, widget, TRUE); 264 ct->add(ct, widget, TRUE);
260 265
261 UiObject *newobj = uic_object_new(obj, vbox); 266 UiObject *newobj = uic_object_new(obj, box);
262 newobj->container = ui_box_container(obj, vbox); 267 newobj->container = ui_box_container(obj, box);
263 uic_obj_add(obj, newobj); 268 uic_obj_add(obj, newobj);
264 269
265 return widget; 270 return widget;
266 } 271 }
267 272
274 } 279 }
275 280
276 281
277 282
278 UIWIDGET ui_grid_create(UiObject *obj, UiContainerArgs args) { 283 UIWIDGET ui_grid_create(UiObject *obj, UiContainerArgs args) {
279 UiContainer *ct = uic_get_current_container(obj); 284 UiObject* current = uic_current_obj(obj);
285 UI_APPLY_LAYOUT1(current, args);
280 GtkWidget *widget; 286 GtkWidget *widget;
281 287
282 #ifdef UI_GTK3 288 #ifdef UI_GTK3
283 GtkWidget *grid = gtk_grid_new(); 289 GtkWidget *grid = gtk_grid_new();
284 gtk_grid_set_column_spacing(GTK_GRID(grid), args.columnspacing); 290 gtk_grid_set_column_spacing(GTK_GRID(grid), args.columnspacing);
285 gtk_grid_set_row_spacing(GTK_GRID(grid), args.rowspacing); 291 gtk_grid_set_row_spacing(GTK_GRID(grid), args.rowspacing);
286 #if GTK_MAJOR_VERSION == 3 && GTK_MINOR_VERSION >= 12 292 #if GTK_MAJOR_VERSION == 3 && GTK_MINOR_VERSION >= 12
287 gtk_widget_set_margin_start(grid, args.margin); 293 gtk_widget_set_margin_start(grid, args.margin);
288 gtk_widget_set_margin_end(grid, args.margin); 294 gtk_widget_set_margin_end(grid, args.margin);
289 #else 295 #else
290 gtk_widget_set_margin_left(grid, margin); 296 gtk_widget_set_margin_left(grid, args.margin);
291 gtk_widget_set_margin_right(grid, margin); 297 gtk_widget_set_margin_right(grid, args.margin);
292 #endif 298 #endif
293 gtk_widget_set_margin_top(grid, args.margin); 299 gtk_widget_set_margin_top(grid, args.margin);
294 gtk_widget_set_margin_bottom(grid, args.margin); 300 gtk_widget_set_margin_bottom(grid, args.margin);
295 301
296 widget = grid; 302 widget = grid;
307 widget = a; 313 widget = a;
308 } else { 314 } else {
309 widget = grid; 315 widget = grid;
310 } 316 }
311 #endif 317 #endif
312 ct->add(ct, widget, TRUE); 318 current->container->add(current->container, widget, TRUE);
313 319
314 UiObject *newobj = uic_object_new(obj, grid); 320 UiObject *newobj = uic_object_new(obj, grid);
315 newobj->container = ui_grid_container(obj, grid); 321 newobj->container = ui_grid_container(obj, grid);
316 uic_obj_add(obj, newobj); 322 uic_obj_add(obj, newobj);
317 323
318 return widget; 324 return widget;
325 }
326
327
328 UIWIDGET ui_scrolledwindow_create(UiObject* obj, UiFrameArgs args) {
329 UiObject* current = uic_current_obj(obj);
330 UI_APPLY_LAYOUT1(current, args);
331
332 GtkWidget *sw = gtk_scrolled_window_new(NULL, NULL);
333 UiObject *newobj = uic_object_new(obj, sw);
334 newobj->container = ui_scrolledwindow_container(obj, sw);
335 uic_obj_add(obj, newobj);
336
337 return sw;
319 } 338 }
320 339
321 340
322 void ui_select_tab(UIWIDGET tabview, int tab) { 341 void ui_select_tab(UIWIDGET tabview, int tab) {
323 gtk_notebook_set_current_page(GTK_NOTEBOOK(tabview), tab); 342 gtk_notebook_set_current_page(GTK_NOTEBOOK(tabview), tab);
365 void ui_layout_vexpand(UiObject *obj, UiBool expand) { 384 void ui_layout_vexpand(UiObject *obj, UiBool expand) {
366 UiContainer *ct = uic_get_current_container(obj); 385 UiContainer *ct = uic_get_current_container(obj);
367 ct->layout.vexpand = expand; 386 ct->layout.vexpand = expand;
368 } 387 }
369 388
370 void ui_layout_gridwidth(UiObject *obj, int width) {
371 UiContainer *ct = uic_get_current_container(obj);
372 ct->layout.gridwidth = width;
373 }
374
375 void ui_layout_colspan(UiObject* obj, int cols) { 389 void ui_layout_colspan(UiObject* obj, int cols) {
376 UiContainer* ct = uic_get_current_container(obj); 390 UiContainer* ct = uic_get_current_container(obj);
377 ct->layout.colspan = cols; 391 ct->layout.colspan = cols;
378 } 392 }
379 393

mercurial