ui/gtk/container.c

branch
newapi
changeset 305
98470af75dcf
parent 304
d554b2a60105
equal deleted inserted replaced
304:d554b2a60105 305:98470af75dcf
122 obj->ctx->allocator, 122 obj->ctx->allocator,
123 1, 123 1,
124 sizeof(UiGridContainer)); 124 sizeof(UiGridContainer));
125 ct->container.widget = grid; 125 ct->container.widget = grid;
126 ct->container.add = ui_grid_container_add; 126 ct->container.add = ui_grid_container_add;
127 #ifdef UI_GTK2 127 UI_GTK_V2(ct->width = 0);
128 ct->width = 0; 128 UI_GTK_V2(ct->height = 1);
129 ct->height = 1;
130 #endif
131 return (UiContainer*)ct; 129 return (UiContainer*)ct;
132 } 130 }
133 131
134 #if GTK_MAJOR_VERSION >= 3 132 #if GTK_MAJOR_VERSION >= 3
135 void ui_grid_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill) { 133 void ui_grid_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill) {
212 return ct; 210 return ct;
213 } 211 }
214 212
215 void ui_scrolledwindow_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill) { 213 void ui_scrolledwindow_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill) {
216 // TODO: check if the widget implements GtkScrollable 214 // TODO: check if the widget implements GtkScrollable
217 #ifdef UI_GTK4 215 SCROLLEDWINDOW_SET_CHILD(ct->widget, widget);
218 gtk_scrolled_window_set_child(GTK_SCROLLED_WINDOW(ct->widget), widget);
219 #elif defined(UI_GTK3)
220 gtk_container_add(GTK_CONTAINER(ct->widget), widget);
221 #else
222 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(ct->widget), widget);
223 #endif
224 ui_reset_layout(ct->layout); 216 ui_reset_layout(ct->layout);
225 ct->current = widget; 217 ct->current = widget;
226 } 218 }
227 219
228 UiContainer* ui_tabview_container(UiObject *obj, GtkWidget *tabview) { 220 UiContainer* ui_tabview_container(UiObject *obj, GtkWidget *tabview) {
290 282
291 UIEXPORT UIWIDGET ui_hbox_create(UiObject *obj, UiContainerArgs args) { 283 UIEXPORT UIWIDGET ui_hbox_create(UiObject *obj, UiContainerArgs args) {
292 return ui_box_create(obj, args, UI_CONTAINER_HBOX); 284 return ui_box_create(obj, args, UI_CONTAINER_HBOX);
293 } 285 }
294 286
295 287 static GtkWidget* create_grid(int colspacing, int rowspacing) {
288 #if GTK_MAJOR_VERSION >= 3
289 GtkWidget *grid = gtk_grid_new();
290 gtk_grid_set_column_spacing(GTK_GRID(grid), colspacing);
291 gtk_grid_set_row_spacing(GTK_GRID(grid), rowspacing);
292 #else
293 GtkWidget *grid = gtk_table_new(1, 1, FALSE);
294 gtk_table_set_col_spacings(GTK_TABLE(grid), colspacing);
295 gtk_table_set_row_spacings(GTK_TABLE(grid), rowspacing);
296 #endif
297 return grid;
298 }
296 299
297 UIWIDGET ui_grid_create(UiObject *obj, UiContainerArgs args) { 300 UIWIDGET ui_grid_create(UiObject *obj, UiContainerArgs args) {
298 UiObject* current = uic_current_obj(obj); 301 UiObject* current = uic_current_obj(obj);
299 UI_APPLY_LAYOUT1(current, args); 302 UI_APPLY_LAYOUT1(current, args);
300 GtkWidget *widget; 303 GtkWidget *widget;
301 304
302 #if GTK_MAJOR_VERSION >= 3 305 GtkWidget *grid = create_grid(args.columnspacing, args.rowspacing);
303 GtkWidget *grid = gtk_grid_new(); 306 widget = box_set_margin(grid, args.margin);
304 gtk_grid_set_column_spacing(GTK_GRID(grid), args.columnspacing);
305 gtk_grid_set_row_spacing(GTK_GRID(grid), args.rowspacing);
306 #if GTK_MAJOR_VERSION * 1000 + GTK_MINOR_VERSION >= 3012
307 gtk_widget_set_margin_start(grid, args.margin);
308 gtk_widget_set_margin_end(grid, args.margin);
309 #else
310 gtk_widget_set_margin_left(grid, args.margin);
311 gtk_widget_set_margin_right(grid, args.margin);
312 #endif
313 gtk_widget_set_margin_top(grid, args.margin);
314 gtk_widget_set_margin_bottom(grid, args.margin);
315
316 widget = grid;
317 #elif defined(UI_GTK2)
318 GtkWidget *grid = gtk_table_new(1, 1, FALSE);
319
320 gtk_table_set_col_spacings(GTK_TABLE(grid), columnspacing);
321 gtk_table_set_row_spacings(GTK_TABLE(grid), rowspacing);
322
323 if(margin > 0) {
324 GtkWidget *a = gtk_alignment_new(0.5, 0.5, 1, 1);
325 gtk_alignment_set_padding(GTK_ALIGNMENT(a), margin, margin, margin, margin);
326 gtk_container_add(GTK_CONTAINER(a), grid);
327 widget = a;
328 } else {
329 widget = grid;
330 }
331 #endif
332 current->container->add(current->container, widget, TRUE); 307 current->container->add(current->container, widget, TRUE);
333 308
334 UiObject *newobj = uic_object_new(obj, grid); 309 UiObject *newobj = uic_object_new(obj, grid);
335 newobj->container = ui_grid_container(obj, grid); 310 newobj->container = ui_grid_container(obj, grid);
336 uic_obj_add(obj, newobj); 311 uic_obj_add(obj, newobj);

mercurial