fixed grid container when using gtk2

Wed, 21 Jan 2015 11:21:47 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 21 Jan 2015 11:21:47 +0100
changeset 74
55718d4ed227
parent 73
473acef47ddd
child 75
efe2f65bea17

fixed grid container when using gtk2

application/main.c file | annotate | diff | comparison | revisions
ui/gtk/container.c file | annotate | diff | comparison | revisions
ui/gtk/container.h file | annotate | diff | comparison | revisions
--- a/application/main.c	Wed Jan 21 16:02:30 2015 +0100
+++ b/application/main.c	Wed Jan 21 11:21:47 2015 +0100
@@ -133,14 +133,22 @@
     ui_list_append(list, p3);
     ui_list_append(list, p4);
     
+    ui_layout_fill(window, FALSE);
+    ui_grid(window);
+    ui_button(window, "Test", NULL, NULL);
+    ui_button(window, "Test", NULL, NULL);
+    ui_button(window, "Test", NULL, NULL);
+    ui_newline(window);
+    ui_textfield(window, NULL);
+    ui_end(window);
     ui_listview(window, list, (ui_model_getvalue_f)person_getvalue, action_activate, NULL);
-    ui_contextmenu(window);
-    ui_widget_menuitem(window, "OK", action_test, NULL);
-    ui_widget_menuitem(window, "1", action_test, NULL);
-    ui_widget_menuitem(window, "2", action_test, NULL);
-    ui_widget_menuitem(window, "3", action_test, NULL);
-    ui_widget_menuitem(window, "4", action_test, NULL);
-    ui_widget_menuitem_st(window, UI_STOCK_CLOSE, action_test, NULL);
+    //ui_contextmenu(window);
+    //ui_widget_menuitem(window, "OK", action_test, NULL);
+    //ui_widget_menuitem(window, "1", action_test, NULL);
+    //ui_widget_menuitem(window, "2", action_test, NULL);
+    //ui_widget_menuitem(window, "3", action_test, NULL);
+    //ui_widget_menuitem(window, "4", action_test, NULL);
+    //ui_widget_menuitem_st(window, UI_STOCK_CLOSE, action_test, NULL);
     
     
     ui_show(window);
--- a/ui/gtk/container.c	Wed Jan 21 16:02:30 2015 +0100
+++ b/ui/gtk/container.c	Wed Jan 21 11:21:47 2015 +0100
@@ -104,9 +104,14 @@
             sizeof(UiGridContainer));
     ct->container.widget = grid;
     ct->container.add = ui_grid_container_add;
+#ifdef UI_GTK2
+    ct->width = 0;
+    ct->height = 1;
+#endif
     return (UiContainer*)ct;
 }
 
+#ifdef UI_GTK3
 void ui_grid_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill) {
     UiGridContainer *grid = (UiGridContainer*)ct;
     
@@ -121,6 +126,27 @@
     
     ui_reset_layout(ct->layout);
 }
+#endif
+#ifdef UI_GTK2
+void ui_grid_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill) {
+    UiGridContainer *grid = (UiGridContainer*)ct;
+    
+    if(ct->layout.newline) {
+        grid->x = 0;
+        grid->y++;
+        ct->layout.newline = FALSE;
+    }
+    
+    gtk_table_attach(GTK_TABLE(ct->widget), widget, grid->x, grid->x+1, grid->y, grid->y+1, GTK_FILL, GTK_FILL, 0, 0);
+    grid->x++;
+    int nw = grid->x > grid->width ? grid->x : grid->width;
+    if(grid->x > grid->width || grid->y > grid->height) {
+        grid->width = nw;
+        grid->height = grid->y + 1;
+        gtk_table_resize(GTK_TABLE(ct->widget), grid->width, grid->height);
+    }
+}
+#endif
 
 UiContainer* ui_tabview_container(UiObject *obj, GtkWidget *tabview) {
     UiTabViewContainer *ct = ucx_mempool_calloc(
@@ -169,7 +195,11 @@
 UIWIDGET ui_grid(UiObject *obj) {
     UiContainer *ct = uic_get_current_container(obj);
     
+#ifdef UI_GTK3
     GtkWidget *grid = gtk_grid_new();
+#elif defined(UI_GTK2)
+    GtkWidget *grid = gtk_table_new(1, 1, FALSE);
+#endif
     ct->add(ct, grid, TRUE);
     
     UiObject *newobj = uic_object_new(obj, grid);
--- a/ui/gtk/container.h	Wed Jan 21 16:02:30 2015 +0100
+++ b/ui/gtk/container.h	Wed Jan 21 11:21:47 2015 +0100
@@ -74,6 +74,10 @@
     UiContainer container;
     int x;
     int y;
+#ifdef UI_GTK2
+    int width;
+    int height;
+#endif
 } UiGridContainer;
 
 typedef struct UiTabViewContainer {

mercurial