ui/gtk/container.c

changeset 65
4697592e24ba
parent 62
70d2aee84432
child 66
8d490d97aab8
--- a/ui/gtk/container.c	Mon Jan 05 14:47:19 2015 +0100
+++ b/ui/gtk/container.c	Mon Jan 05 18:47:07 2015 +0100
@@ -105,6 +105,49 @@
     ui_reset_layout(ct->layout);
 }
 
+UiContainer* ui_grid_container(UiObject *obj, GtkWidget *grid) {
+    UiGridContainer *ct = ucx_mempool_calloc(
+            obj->ctx->mempool,
+            1,
+            sizeof(UiGridContainer));
+    ct->container.widget = grid;
+    ct->container.add = ui_grid_container_add;
+    return (UiContainer*)ct;
+}
+
+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_grid_attach(GTK_GRID(ct->widget), widget, grid->x, grid->y, 1, 1);
+    grid->x++;
+    
+    ui_reset_layout(ct->layout);
+}
+
+UiContainer* ui_tabview_container(UiObject *obj, GtkWidget *tabview) {
+    UiTabViewContainer *ct = ucx_mempool_calloc(
+            obj->ctx->mempool,
+            1,
+            sizeof(UiTabViewContainer));
+    ct->container.widget = tabview;
+    ct->container.add = ui_tabview_container_add;
+    return (UiContainer*)ct;
+}
+
+void ui_tabview_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill) {
+    gtk_notebook_append_page(
+            GTK_NOTEBOOK(ct->widget),
+            widget,
+            gtk_label_new(ct->layout.label));
+}
+
+
 UIWIDGET ui_vbox(UiObject *obj) {
     UiContainer *ct = uic_get_current_container(obj);
     
@@ -131,6 +174,44 @@
     return hbox;
 }
 
+UIWIDGET ui_grid(UiObject *obj) {
+    UiContainer *ct = uic_get_current_container(obj);
+    
+    GtkWidget *grid = gtk_grid_new();
+    ct->add(ct, grid, TRUE);
+    
+    UiObject *newobj = uic_object_new(obj, grid);
+    newobj->container = ui_grid_container(obj, grid);
+    uic_obj_add(obj, newobj);
+    
+    return grid;
+}
+
+UIWIDGET ui_tabview(UiObject *obj) {
+    GtkWidget *tabview = gtk_notebook_new();
+    gtk_notebook_set_show_border(GTK_NOTEBOOK(tabview), FALSE);
+    gtk_notebook_set_show_tabs(GTK_NOTEBOOK(tabview), FALSE);
+    
+    UiContainer *ct = uic_get_current_container(obj);
+    ct->add(ct, tabview, TRUE);
+    
+    UiObject *tabviewobj = uic_object_new(obj, tabview);
+    tabviewobj->container = ui_tabview_container(obj, tabview);
+    uic_obj_add(obj, tabviewobj);
+    
+    return tabview;
+}
+
+void ui_tab(UiObject *obj, char *title) {
+    UiContainer *ct = uic_get_current_container(obj);
+    ct->layout.label = title;
+    ui_vbox(obj);
+}
+
+void ui_select_tab(UIWIDGET tabview, int tab) {
+    gtk_notebook_set_current_page(GTK_NOTEBOOK(tabview), tab);
+}
+
 
 /* -------------------- Sidebar -------------------- */
 UIWIDGET ui_sidebar(UiObject *obj) {
@@ -256,3 +337,8 @@
     UiContainer *ct = uic_get_current_container(obj);
     ct->layout.fill = ui_bool2lb(fill);
 }
+
+void ui_newline(UiObject *obj) {
+    UiContainer *ct = uic_get_current_container(obj);
+    ct->layout.newline = TRUE;
+}

mercurial