improved box (Motif)

Thu, 01 Jan 2015 17:22:55 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 01 Jan 2015 17:22:55 +0100
changeset 61
7ee124a58fe3
parent 60
7cd1b8890302
child 62
70d2aee84432

improved box (Motif)

application/main.c file | annotate | diff | comparison | revisions
ui/motif/container.c file | annotate | diff | comparison | revisions
ui/motif/container.h file | annotate | diff | comparison | revisions
ui/motif/window.c file | annotate | diff | comparison | revisions
ui/ui/toolkit.h file | annotate | diff | comparison | revisions
--- a/application/main.c	Thu Jan 01 14:13:37 2015 +0100
+++ b/application/main.c	Thu Jan 01 17:22:55 2015 +0100
@@ -116,9 +116,19 @@
     ui_list_append(list, p4);
     
     //ui_sidebar(window);
-    ui_table(window, list, model);
+    ui_layout_fill(window, FALSE);
+    ui_hbox(window);
     ui_button(window, "Test1", NULL, NULL);
     ui_button(window, "Test2", NULL, NULL);
+    ui_button(window, "Test3", NULL, NULL);
+    ui_button(window, "Test4", NULL, NULL);
+    ui_button(window, "Test5", NULL, NULL);
+    ui_button(window, "Test6", NULL, NULL);
+    ui_button(window, "Test7", NULL, NULL);
+    ui_button(window, "Test8", NULL, NULL);
+    ui_end(window);
+    ui_table(window, list, model);
+    
     //ui_end(window);
     /*
     UiTabbedPane *view = ui_tabbed_document_view(window);
--- a/ui/motif/container.c	Thu Jan 01 14:13:37 2015 +0100
+++ b/ui/motif/container.c	Thu Jan 01 17:22:55 2015 +0100
@@ -63,18 +63,19 @@
 }
 
 
-UiContainer* ui_vbox_container(UiObject *obj, Widget box) {
-    UiContainer *ct = ucx_mempool_calloc(
+UiContainer* ui_box_container(UiObject *obj, Widget box, UiBoxOrientation orientation) {
+    UiBoxContainer *ct = ucx_mempool_calloc(
             obj->ctx->mempool,
             1,
             sizeof(UiBoxContainer));
-    ct->widget = box;
-    ct->prepare = ui_vbox_container_prepare;
-    ct->add = ui_vbox_container_add;
-    return ct;
+    ct->container.widget = box;
+    ct->container.prepare = ui_box_container_prepare;
+    ct->container.add = ui_box_container_add;
+    ct->orientation = orientation;
+    return (UiContainer*)ct;
 }
 
-Widget ui_vbox_container_prepare(UiContainer *ct, Arg *args, int *n, UiBool fill) {
+Widget ui_box_container_prepare(UiContainer *ct, Arg *args, int *n, UiBool fill) {
     UiBoxContainer *bc = (UiBoxContainer*)ct;
     if(ct->layout.fill != UI_LAYOUT_UNDEFINED) {
         fill = ui_lb2bool(ct->layout.fill);
@@ -87,65 +88,129 @@
     if(fill) {
         bc->has_fill = TRUE;
     }
-    //UiBool expand = fill;
     
     int a = *n;
-    XtSetArg(args[a], XmNleftAttachment, XmATTACH_FORM); a++;
-    XtSetArg(args[a], XmNrightAttachment, XmATTACH_FORM); a++;
+    // determine fixed and dynamic attachments
+    void *f1;
+    void *f2;
+    void *d1;
+    void *d2;
+    void *w1;
+    void *w2;
+    if(bc->orientation == UI_BOX_VERTICAL) {
+        f1 = XmNleftAttachment;
+        f2 = XmNrightAttachment;
+        d1 = XmNtopAttachment;
+        d2 = XmNbottomAttachment;
+        w1 = XmNtopWidget;
+        w2 = XmNbottomWidget;
+        
+    } else {
+        f1 = XmNtopAttachment;
+        f2 = XmNbottomAttachment;
+        d1 = XmNleftAttachment;
+        d2 = XmNrightAttachment;
+        w1 = XmNleftWidget;
+        w2 = XmNrightWidget;
+    }
+    XtSetArg(args[a], f1, XmATTACH_FORM); a++;
+    XtSetArg(args[a], f2, XmATTACH_FORM); a++;
+
     if(fill) {
-        XtSetArg(args[a], XmNbottomAttachment, XmATTACH_FORM); a++;
-        bc->cur_fill = TRUE;
+        XtSetArg(args[a], d2, XmATTACH_FORM); a++;
     }
     if(bc->prev_widget) {
-        XtSetArg(args[a], XmNtopAttachment, XmATTACH_WIDGET); a++;
-        XtSetArg(args[a], XmNtopWidget, bc->prev_widget); a++;
+        XtSetArg(args[a], d1, XmATTACH_WIDGET); a++;
+        XtSetArg(args[a], w1, bc->prev_widget); a++;
     } else {
-        XtSetArg(args[a], XmNtopAttachment, XmATTACH_FORM); a++;
+        XtSetArg(args[a], d1, XmATTACH_FORM); a++;
     }
     
     *n += a;
     return ct->widget;
 }
 
-void ui_vbox_container_add(UiContainer *ct, Widget widget) {
+void ui_box_container_add(UiContainer *ct, Widget widget) {
     UiBoxContainer *bc = (UiBoxContainer*)ct;
+    // determine dynamic attachments
+    void *d1;
+    void *d2;
+    void *w1;
+    void *w2;
+    if(bc->orientation == UI_BOX_VERTICAL) {
+        d1 = XmNtopAttachment;
+        d2 = XmNbottomAttachment;
+        w1 = XmNtopWidget;
+        w2 = XmNbottomWidget;
+        
+    } else {
+        d1 = XmNleftAttachment;
+        d2 = XmNrightAttachment;
+        w1 = XmNleftWidget;
+        w2 = XmNrightWidget;
+    }
+    
     if(bc->prev_widget) {
         int v = 0;
-        XtVaGetValues(bc->prev_widget, XmNbottomAttachment, &v, 0);
+        XtVaGetValues(bc->prev_widget, d2, &v, 0);
         if(v == XmATTACH_FORM) {
             XtVaSetValues(
                     bc->prev_widget,
-                    XmNbottomAttachment,
+                    d2,
                     XmATTACH_WIDGET,
-                    XmNbottomWidget,
+                    w2,
                     widget,
                     0);
             XtVaSetValues(
                     widget,
-                    XmNtopAttachment,
+                    d1,
                     XmATTACH_NONE,
-                    XmNbottomAttachment,
+                    d2,
                     XmATTACH_FORM,
                     0);
         }
     }
     bc->prev_widget = widget;
-    if(bc->cur_fill) {
-        bc->filled_widget = widget;
-    }
+    
+    ui_reset_layout(ct->layout);
 }
 
+UIWIDGET ui_box(UiObject *obj, UiBoxOrientation orientation) {
+    UiContainer *ct = uic_get_current_container(obj);
+    
+    Arg args[16];
+    int n = 0;
+    Widget parent = ct->prepare(ct, args, &n, TRUE);
+    Widget form = XmCreateForm(parent, "vbox", args, n);
+    ct->add(ct, form);
+    XtManageChild(form);
+    
+    UiObject *newobj = uic_object_new(obj, form);
+    newobj->container = ui_box_container(obj, form, orientation);
+    uic_obj_add(obj, newobj);
+    
+    return form;
+}
+
+UIWIDGET ui_vbox(UiObject *obj) {
+    return ui_box(obj, UI_BOX_VERTICAL);
+}
+
+UIWIDGET ui_hbox(UiObject *obj) {
+    return ui_box(obj, UI_BOX_HORIZONTAL);
+}
 
 UIWIDGET ui_sidebar(UiObject *obj) {
     UiContainer *ct = uic_get_current_container(obj);
     
-    Arg args[8];
+    Arg args[16];
     int n = 0;
     XtSetArg(args[n], XmNorientation, XmHORIZONTAL);
     n++;
     
     Widget parent = ct->prepare(ct, args, &n, TRUE);
     Widget pane = XmCreatePanedWindow(parent, "pane", args, n);
+    ct->add(ct, pane);
     XtManageChild(pane);
     
     // add sidebar widget
@@ -372,3 +437,16 @@
 void ui_tab_detach_document(UiContext *ctx, void *document) {
     uic_context_detach_document(ctx->parent, document);
 }
+
+
+/*
+ * -------------------- Layout Functions --------------------
+ * 
+ * functions for setting layout attributes for the current container
+ *
+ */
+
+void ui_layout_fill(UiObject *obj, UiBool fill) {
+    UiContainer *ct = uic_get_current_container(obj);
+    ct->layout.fill = ui_bool2lb(fill);
+}
--- a/ui/motif/container.h	Thu Jan 01 14:13:37 2015 +0100
+++ b/ui/motif/container.h	Thu Jan 01 17:22:55 2015 +0100
@@ -42,11 +42,12 @@
 typedef struct MotifTabbedPane MotifTabbedPane;
 typedef struct UiTab           UiTab;
 typedef struct UiBoxContainer  UiBoxContainer;
+typedef struct UiLayout        UiLayout;
 
 typedef Widget (*ui_container_add_f)(UiContainer*, Arg*, int*, UiBool);
 
-typedef struct UiLayout UiLayout;
-typedef enum UiLayoutBool UiLayoutBool;
+typedef enum UiLayoutBool     UiLayoutBool;
+typedef enum UiBoxOrientation UiBoxOrientation;
 
 
 enum UiLayoutBool {
@@ -55,6 +56,11 @@
     UI_LAYOUT_FALSE,
 };
 
+enum UiBoxOrientation {
+    UI_BOX_VERTICAL = 0,
+    UI_BOX_HORIZONTAL
+};
+
 struct UiLayout {
     UiLayoutBool fill;
 };
@@ -69,9 +75,8 @@
 struct UiBoxContainer {
     UiContainer container;
     Widget prev_widget;
-    Widget filled_widget;
-    UiBool cur_fill;
     UiBool has_fill;
+    UiBoxOrientation orientation;
 };
 
 struct MotifTabbedPane {
@@ -92,9 +97,9 @@
 Widget ui_frame_container_prepare(UiContainer *ct, Arg *args, int *n, UiBool fill);
 void ui_frame_container_add(UiContainer *ct, Widget widget);
 
-UiContainer* ui_vbox_container(UiObject *obj, Widget box);
-Widget ui_vbox_container_prepare(UiContainer *ct, Arg *args, int *n, UiBool fill);
-void ui_vbox_container_add(UiContainer *ct, Widget widget);
+UiContainer* ui_box_container(UiObject *obj, Widget box, UiBoxOrientation orientation);
+Widget ui_box_container_prepare(UiContainer *ct, Arg *args, int *n, UiBool fill);
+void ui_box_container_add(UiContainer *ct, Widget widget);
 
 void ui_tab_button_callback(Widget widget, UiTab *tab, XtPointer d);
 void ui_change_tab(MotifTabbedPane *pane, UiTab *tab);
--- a/ui/motif/window.c	Thu Jan 01 14:13:37 2015 +0100
+++ b/ui/motif/window.c	Thu Jan 01 17:22:55 2015 +0100
@@ -121,8 +121,7 @@
     
     Widget content_form = XmCreateForm(frame, "content_form", NULL, 0);
     XtManageChild(content_form);
-    obj->container = ui_vbox_container(obj, content_form);
-    //obj->container = ui_frame_container(obj, frame);
+    obj->container = ui_box_container(obj, content_form, UI_BOX_VERTICAL);
     
     XtManageChild(form);
       
--- a/ui/ui/toolkit.h	Thu Jan 01 14:13:37 2015 +0100
+++ b/ui/ui/toolkit.h	Thu Jan 01 17:22:55 2015 +0100
@@ -225,6 +225,8 @@
 void ui_set_show_all(UIWIDGET widget, int value);
 void ui_set_visible(UIWIDGET widget, int visible);
 
+UIWIDGET ui_vbox(UiObject *obj);
+UIWIDGET ui_hbox(UiObject *obj);
 UIWIDGET ui_sidebar(UiObject *obj);
 void ui_end(UiObject *obj);
 

mercurial