Thu, 01 Jan 2015 11:23:43 +0100
added box container (GTK)
application/main.c | file | annotate | diff | comparison | revisions | |
ui/gtk/button.c | file | annotate | diff | comparison | revisions | |
ui/gtk/container.c | file | annotate | diff | comparison | revisions | |
ui/gtk/container.h | file | annotate | diff | comparison | revisions | |
ui/gtk/text.c | file | annotate | diff | comparison | revisions | |
ui/gtk/tree.c | file | annotate | diff | comparison | revisions | |
ui/gtk/window.c | file | annotate | diff | comparison | revisions | |
ui/motif/container.c | file | annotate | diff | comparison | revisions | |
ui/motif/toolkit.c | file | annotate | diff | comparison | revisions | |
ui/ui/toolkit.h | file | annotate | diff | comparison | revisions |
--- a/application/main.c Sat Aug 30 22:48:46 2014 +0200 +++ b/application/main.c Thu Jan 01 11:23:43 2015 +0100 @@ -43,14 +43,7 @@ UiText text; } Document; -UiText text; - -void action_new(UiEvent *event, void *data) { - printf("new\n"); -} - void action_close(UiEvent *event, void *data) { - printf("action_close\n"); ui_close(event->obj); } @@ -78,9 +71,8 @@ void action_button(UiEvent *event, void *data) { printf("button: %d\n", event->intval); - //char *s = ui_gettext(event->obj, "text"); - char *s = ui_getval(text); - printf("{%s}\n", s); + char *s = ui_gettext(event->obj, "text"); + printf("{%s}\n", s); } int main(int argc, char** argv) { @@ -92,19 +84,15 @@ ui_menu("File"); - //ui_menuitem("Close", action_close, NULL); - ui_menuitem_st(UI_STOCK_NEW, action_new, NULL); ui_menuitem_st(UI_STOCK_CLOSE, action_close, NULL); - //ui_checkitem("Check", action_button, NULL); + ui_checkitem("Check", action_button, NULL); - ui_toolitem_st("button", UI_STOCK_OPEN, action_button, NULL); + ui_toolitem_st("button", UI_STOCK_GO_BACK, action_button, NULL); ui_toolbar_add_default("button"); printf("create window\n"); UiObject *window = ui_window("Mod0", NULL); - //ui_textarea(window, &text); - ///* UiModelInfo *model = ui_model_info(window->ctx, UI_STRING, "Name", UI_STRING, "Email", -1); model->getvalue = (ui_model_getvalue_f)person_getvalue; model->activate = action_activate; @@ -129,8 +117,13 @@ //ui_sidebar(window); ui_table(window, list, model); + ui_button(window, "Test", NULL, NULL); + ui_button(window, "Test", NULL, NULL); + ui_button(window, "Test", NULL, NULL); + ui_button(window, "Test", NULL, NULL); + ui_button(window, "Test", NULL, NULL); + ui_button(window, "Test", NULL, NULL); //ui_end(window); - /* UiTabbedPane *view = ui_tabbed_document_view(window);
--- a/ui/gtk/button.c Sat Aug 30 22:48:46 2014 +0200 +++ b/ui/gtk/button.c Thu Jan 01 11:23:43 2015 +0100 @@ -60,7 +60,7 @@ } UiContainer *ct = uic_get_current_container(obj); - ct->add(ct, button); + ct->add(ct, button, FALSE); return button; }
--- a/ui/gtk/container.c Sat Aug 30 22:48:46 2014 +0200 +++ b/ui/gtk/container.c Thu Jan 01 11:23:43 2015 +0100 @@ -33,21 +33,80 @@ #include "../common/context.h" #include "../common/object.h" +static UiBool ui_lb2bool(UiLayoutBool b) { + return b == UI_LAYOUT_TRUE ? TRUE : FALSE; +} +static UiLayoutBool ui_bool2lb(UiBool b) { + return b ? UI_LAYOUT_TRUE : UI_LAYOUT_FALSE; +} + +GtkWidget* ui_gtk_vbox_new() { +#ifdef UI_GTK3 + return gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); +#else + return gtk_vbox_new(FALSE, 0); +#endif +} + +GtkWidget* ui_gtk_hbox_new() { +#ifdef UI_GTK3 + return gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); +#else + return gtk_hbox_new(FALSE, 0); +#endif +} + +/* -------------------- Frame Container (deprecated) -------------------- */ UiContainer* ui_frame_container(UiObject *obj, GtkWidget *frame) { - UiContainer *ct = ucx_mempool_malloc( + UiContainer *ct = ucx_mempool_calloc( obj->ctx->mempool, + 1, sizeof(UiContainer)); ct->widget = frame; ct->add = ui_frame_container_add; return ct; } -void ui_frame_container_add(UiContainer *ct, GtkWidget *widget) { +void ui_frame_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill) { gtk_container_add(GTK_CONTAINER(ct->widget), widget); + ui_reset_layout(ct->layout); } +/* -------------------- Box Container -------------------- */ +UiContainer* ui_box_container(UiObject *obj, GtkWidget *box) { + UiBoxContainer *ct = ucx_mempool_calloc( + obj->ctx->mempool, + 1, + sizeof(UiBoxContainer)); + ct->container.widget = box; + ct->container.add = ui_box_container_add; + return (UiContainer*)ct; +} + +void ui_box_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill) { + UiBoxContainer *bc = (UiBoxContainer*)ct; + if(ct->layout.fill != UI_LAYOUT_UNDEFINED) { + fill = ui_lb2bool(ct->layout.fill); + } + + if(bc->has_fill && fill) { + fprintf(stderr, "UiError: container has 2 filled widgets"); + fill = FALSE; + } + if(fill) { + bc->has_fill = TRUE; + } + + UiBool expand = fill; + gtk_box_pack_start(GTK_BOX(ct->widget), widget, expand, fill, 0); + + ui_reset_layout(ct->layout); +} + + +/* -------------------- Sidebar -------------------- */ UIWIDGET ui_sidebar(UiObject *obj) { #ifdef UI_GTK3 GtkWidget *paned = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL); @@ -56,20 +115,11 @@ #endif gtk_paned_set_position(GTK_PANED(paned), 200); - GtkWidget *sidebar; -#ifdef UI_GTK3 - sidebar = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); -#else - sidebar = gtk_vbox_new(FALSE, 0); -#endif + GtkWidget *sidebar = ui_gtk_vbox_new(); gtk_paned_pack1(GTK_PANED(paned), sidebar, TRUE, FALSE); UiObject *left = uic_object_new(obj, sidebar); - UiContainer *ct1 = ucx_mempool_malloc( - obj->ctx->mempool, - sizeof(UiContainer)); - ct1->widget = sidebar; - ct1->add = ui_box_add; + UiContainer *ct1 = ui_box_container(obj, sidebar); left->container = ct1; UiObject *right = uic_object_new(obj, sidebar); @@ -81,7 +131,7 @@ right->container = ct2; UiContainer *ct = uic_get_current_container(obj); - ct->add(ct, paned); + ct->add(ct, paned, TRUE); uic_obj_add(obj, right); uic_obj_add(obj, left); @@ -89,22 +139,17 @@ return sidebar; } -void ui_split_container_add1(UiContainer *ct, GtkWidget *widget) { +void ui_split_container_add1(UiContainer *ct, GtkWidget *widget, UiBool fill) { + // TODO: remove gtk_paned_pack1(GTK_PANED(ct->widget), widget, TRUE, FALSE); } -void ui_split_container_add2(UiContainer *ct, GtkWidget *widget) { +void ui_split_container_add2(UiContainer *ct, GtkWidget *widget, UiBool fill) { gtk_paned_pack2(GTK_PANED(ct->widget), widget, TRUE, FALSE); } -void ui_box_add(UiContainer *ct, GtkWidget *widget) { - gtk_box_pack_start(GTK_BOX(ct->widget), widget, TRUE, TRUE, 0); -} - - - - +/* -------------------- Document Tabview -------------------- */ static void page_change(GtkNotebook *notebook, GtkWidget *page, guint page_num, gpointer data) { GQuark q = g_quark_from_static_string("ui.tab.object"); UiObject *tab = g_object_get_qdata(G_OBJECT(page), q); @@ -128,7 +173,7 @@ NULL); UiContainer *ct = uic_get_current_container(obj); - ct->add(ct, tabview); + ct->add(ct, tabview, TRUE); UiTabbedPane *tabbedpane = ui_malloc(obj->ctx, sizeof(UiTabbedPane)); tabbedpane->ctx = uic_current_obj(obj)->ctx; @@ -172,3 +217,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/gtk/container.h Sat Aug 30 22:48:46 2014 +0200 +++ b/ui/gtk/container.h Thu Jan 01 11:23:43 2015 +0100 @@ -30,27 +30,53 @@ #define CONTAINER_H #include "../ui/toolkit.h" +#include <string.h> #ifdef __cplusplus extern "C" { #endif -typedef void (*ui_container_add_f)(UiContainer*, GtkWidget*); +#define ui_reset_layout(layout) memset(&(layout), 0, sizeof(UiLayout)) + +typedef void (*ui_container_add_f)(UiContainer*, GtkWidget*, UiBool); typedef struct UiDocumentView UiDocumentView; +typedef struct UiLayout UiLayout; +typedef enum UiLayoutBool UiLayoutBool; + +enum UiLayoutBool { + UI_LAYOUT_UNDEFINED = 0, + UI_LAYOUT_TRUE, + UI_LAYOUT_FALSE, +}; + +struct UiLayout { + UiLayoutBool fill; +}; + struct UiContainer { GtkWidget *widget; - void (*add)(UiContainer*, GtkWidget*); + void (*add)(UiContainer*, GtkWidget*, UiBool); + UiLayout layout; }; +typedef struct UiBoxContainer { + UiContainer container; + UiBool has_fill; +} UiBoxContainer; + +GtkWidget* ui_gtk_vbox_new(); +GtkWidget* ui_gtk_hbox_new(); + UiContainer* ui_frame_container(UiObject *obj, GtkWidget *frame); -void ui_frame_container_add(UiContainer *ct, GtkWidget *widget); +void ui_frame_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill); -void ui_split_container_add1(UiContainer *ct, GtkWidget *widget); -void ui_split_container_add2(UiContainer *ct, GtkWidget *widget); +UiContainer* ui_box_container(UiObject *obj, GtkWidget *box); +void ui_box_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill); -void ui_box_add(UiContainer *ct, GtkWidget *widget); +void ui_split_container_add1(UiContainer *ct, GtkWidget *widget, UiBool fill); +void ui_split_container_add2(UiContainer *ct, GtkWidget *widget, UiBool fill); UiObject* ui_add_document_tab(UiDocumentView *view);
--- a/ui/gtk/text.c Sat Aug 30 22:48:46 2014 +0200 +++ b/ui/gtk/text.c Thu Jan 01 11:23:43 2015 +0100 @@ -95,7 +95,7 @@ // add UiContainer *ct = uic_get_current_container(obj); - ct->add(ct, scroll_area); + ct->add(ct, scroll_area, TRUE); // bind value if(value) {
--- a/ui/gtk/tree.c Sat Aug 30 22:48:46 2014 +0200 +++ b/ui/gtk/tree.c Thu Jan 01 11:23:43 2015 +0100 @@ -100,7 +100,7 @@ gtk_container_add(GTK_CONTAINER(scroll_area), view); UiContainer *ct = uic_get_current_container(obj); - ct->add(ct, scroll_area); + ct->add(ct, scroll_area, TRUE); return scroll_area; } @@ -195,7 +195,7 @@ gtk_container_add(GTK_CONTAINER(scroll_area), view); UiContainer *ct = uic_get_current_container(obj); - ct->add(ct, scroll_area); + ct->add(ct, scroll_area, TRUE); return scroll_area; }
--- a/ui/gtk/window.c Sat Aug 30 22:48:46 2014 +0200 +++ b/ui/gtk/window.c Thu Jan 01 11:23:43 2015 +0100 @@ -87,12 +87,7 @@ G_CALLBACK(ui_exit_event), window_data); - GtkWidget *vbox; -#ifdef UI_GTK3 - vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); -#else - vbox = gtk_vbox_new(FALSE, 0); -#endif + GtkWidget *vbox = ui_gtk_vbox_new(); gtk_container_add(GTK_CONTAINER(obj->widget), vbox); // menu @@ -108,9 +103,14 @@ } // window content + // the content has a (TODO: not yet) configurable frame GtkWidget *frame = gtk_alignment_new(0.5, 0.5, 1, 1); gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0); - obj->container = ui_frame_container(obj, frame); + + // content vbox + GtkWidget *content_box = ui_gtk_vbox_new(); + gtk_container_add(GTK_CONTAINER(frame), content_box); + obj->container = ui_box_container(obj, content_box); nwindows++; return obj;
--- a/ui/motif/container.c Sat Aug 30 22:48:46 2014 +0200 +++ b/ui/motif/container.c Thu Jan 01 11:23:43 2015 +0100 @@ -160,13 +160,14 @@ XmString label = XmStringCreateLocalized("tab"); XtSetArg(args[0], XmNlabelString, label); - XtSetArg(args[1], XmNshadowThickness, 0); + XtSetArg(args[1], XmNshadowThickness, 1); XtSetArg(args[2], XmNtraversalOn, FALSE); XtSetArg(args[3], XmNtopAttachment, XmATTACH_FORM); XtSetArg(args[4], XmNbottomAttachment, XmATTACH_FORM); XtSetArg(args[5], XmNhighlightThickness, 0); XtSetArg(args[6], XmNindicatorOn, XmINDICATOR_NONE); XtSetArg(args[7], XmNfillOnSelect, TRUE); + XtSetArg(args[8], XmNtopShadowColor, 1); Widget button = XmCreateToggleButton(v->tabbar, "tab_button", args, 8); tab->tabbedpane = v;
--- a/ui/motif/toolkit.c Sat Aug 30 22:48:46 2014 +0200 +++ b/ui/motif/toolkit.c Thu Jan 01 11:23:43 2015 +0100 @@ -50,6 +50,7 @@ int event_pipe[2]; +/* static String fallback[] = { //"*fontList: -dt-interface system-medium-r-normal-s*utf*:", "*renderTable: rt", @@ -72,6 +73,15 @@ "*rt*fontSize: 10", NULL }; +*/ +static String fallback[] = { + //"*fontList: -dt-interface system-medium-r-normal-s*utf*:", + "*renderTable: rt", + "*rt*fontType: FONT_IS_XFT", + "*rt*fontName: Cantarell", + "*rt*fontSize: 11", + NULL +}; void input_proc(XtPointer data, int *source, XtInputId *iid) { void *ptr;
--- a/ui/ui/toolkit.h Sat Aug 30 22:48:46 2014 +0200 +++ b/ui/ui/toolkit.h Thu Jan 01 11:23:43 2015 +0100 @@ -67,6 +67,8 @@ #define UI_GROUP_SELECTION 20000 /* public types */ +typedef int UiBool; + typedef struct UiObject UiObject; typedef struct UiEvent UiEvent; typedef struct UiObserver UiObserver; @@ -226,7 +228,7 @@ UIWIDGET ui_sidebar(UiObject *obj); void ui_end(UiObject *obj); - +void ui_layout_fill(UiObject *obj, UiBool fill); UiTabbedPane* ui_tabbed_document_view(UiObject *obj);