Tue, 12 Jan 2016 17:41:08 +0100
improved grid container (Gtk)
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 | |
ui/motif/container.c | file | annotate | diff | comparison | revisions | |
ui/motif/container.h | file | annotate | diff | comparison | revisions | |
ui/motif/toolkit.c | file | annotate | diff | comparison | revisions | |
ui/motif/toolkit.h | file | annotate | diff | comparison | revisions | |
ui/ui/toolkit.h | file | annotate | diff | comparison | revisions |
--- a/application/main.c Mon Nov 30 14:09:55 2015 +0100 +++ b/application/main.c Tue Jan 12 17:41:08 2016 +0100 @@ -47,7 +47,7 @@ void draw(UiEvent *event, UiGraphics *g, void *data) { int width = g->width; int height = g->height; - printf("rec[%d,%d]\n", width, height); + //printf("rec[%d,%d]\n", width, height); ui_graphics_color(g, 64, 64, 64); ui_draw_rect(g, 0, 0, width, height, TRUE); @@ -56,7 +56,7 @@ ui_text_setstring(text, "Hello World"); int w, h; ui_text_getsize(text, &w, &h); - printf("ext[%d,%d]\n", w, h); + //printf("ext[%d,%d]\n", w, h); ui_graphics_color(g, 255, 255, 255); ui_draw_text(g, 50, 50, text); @@ -88,8 +88,28 @@ ui_toolbar_add_default("button2"); UiObject *obj = ui_window("Test", NULL); - UIWIDGET w = ui_drawingarea(obj, draw, NULL); - ui_mouse_handler(obj, w, click, NULL); + //UIWIDGET w = ui_drawingarea(obj, draw, NULL); + //ui_mouse_handler(obj, w, click, NULL); + + ui_grid_sp(obj, 40, 4, 4); + ui_button(obj, "OK", NULL, NULL); + ui_button(obj, "Google", NULL, NULL); + ui_textfield(obj, NULL); + ui_newline(obj); + + ui_button(obj, "OK", NULL, NULL); + ui_space(obj); + ui_textfield(obj, NULL); + ui_newline(obj); + + ui_vbox(obj); + ui_button(obj, "txt", NULL, NULL); + ui_end(obj); + ui_layout_hexpand(obj, TRUE); + ui_layout_vexpand(obj, TRUE); + ui_textarea(obj, NULL); + + ui_end(obj); ui_show(obj); ui_main();
--- a/ui/gtk/container.c Mon Nov 30 14:09:55 2015 +0100 +++ b/ui/gtk/container.c Tue Jan 12 17:41:08 2016 +0100 @@ -123,12 +123,21 @@ ct->layout.newline = FALSE; } - if(ct->layout.fill != UI_LAYOUT_UNDEFINED) { - fill = ui_lb2bool(ct->layout.fill); + int hexpand = FALSE; + int vexpand = FALSE; + if(ct->layout.hexpand != UI_LAYOUT_UNDEFINED) { + hexpand = ct->layout.hexpand; } - if(fill) { + if(ct->layout.vexpand != UI_LAYOUT_UNDEFINED) { + vexpand = ct->layout.vexpand; + } + + if(hexpand) { gtk_widget_set_hexpand(widget, TRUE); } + if(vexpand) { + gtk_widget_set_vexpand(widget, TRUE); + } gtk_grid_attach(GTK_GRID(ct->widget), widget, grid->x, grid->y, 1, 1); grid->x++; @@ -209,16 +218,25 @@ } UIWIDGET ui_grid(UiObject *obj) { - return ui_grid_sp(obj, 0, 0); + return ui_grid_sp(obj, 0, 0, 0); } -UIWIDGET ui_grid_sp(UiObject *obj, int columnspacing, int rowspacing) { +UIWIDGET ui_grid_sp(UiObject *obj, int margin, int columnspacing, int rowspacing) { UiContainer *ct = uic_get_current_container(obj); #ifdef UI_GTK3 GtkWidget *grid = gtk_grid_new(); gtk_grid_set_column_spacing(GTK_GRID(grid), columnspacing); - gtk_grid_set_row_spacing(GTK_GRID(grid), rowspacing); + gtk_grid_set_row_spacing(GTK_GRID(grid), rowspacing); +#if GTK_MAJOR_VERSION == 3 && GTK_MINOR_VERSION >= 12 + gtk_widget_set_margin_start(grid, margin); + gtk_widget_set_margin_end(grid, margin); +#else + gtk_widget_set_margin_left(grid, margin); + gtk_widget_set_margin_right(grid, margin); +#endif + gtk_widget_set_margin_top(grid, margin); + gtk_widget_set_margin_bottom(grid, margin); #elif defined(UI_GTK2) GtkWidget *grid = gtk_table_new(1, 1, FALSE); @@ -315,7 +333,7 @@ return; } - printf("page_change: %d\n", page_num); + //printf("page_change: %d\n", page_num); UiContext *ctx = tab->ctx; ctx->parent->set_document(ctx->parent, ctx->document); } @@ -389,7 +407,18 @@ ct->layout.fill = ui_bool2lb(fill); } +void ui_layout_hexpand(UiObject *obj, UiBool expand) { + UiContainer *ct = uic_get_current_container(obj); + ct->layout.hexpand = ui_bool2lb(expand); +} + +void ui_layout_vexpand(UiObject *obj, UiBool expand) { + UiContainer *ct = uic_get_current_container(obj); + ct->layout.vexpand = ui_bool2lb(expand); +} + void ui_newline(UiObject *obj) { UiContainer *ct = uic_get_current_container(obj); ct->layout.newline = TRUE; } +
--- a/ui/gtk/container.h Mon Nov 30 14:09:55 2015 +0100 +++ b/ui/gtk/container.h Tue Jan 12 17:41:08 2016 +0100 @@ -57,6 +57,8 @@ UiLayoutBool fill; UiBool newline; char *label; + UiLayoutBool hexpand; + UiLayoutBool vexpand; }; struct UiContainer {
--- a/ui/motif/container.c Mon Nov 30 14:09:55 2015 +0100 +++ b/ui/motif/container.c Tue Jan 12 17:41:08 2016 +0100 @@ -179,7 +179,7 @@ ct->current = widget; } -UiContainer* ui_grid_container(UiObject *obj, Widget form) { +UiContainer* ui_grid_container(UiObject *obj, Widget form, int columnspacing, int rowspacing) { UiGridContainer *ct = ucx_mempool_calloc( obj->ctx->mempool, 1, @@ -187,6 +187,8 @@ ct->container.widget = form; ct->container.prepare = ui_grid_container_prepare; ct->container.add = ui_grid_container_add; + ct->columnspacing = columnspacing; + ct->rowspacing = rowspacing; return (UiContainer*)ct; } @@ -368,6 +370,10 @@ } UIWIDGET ui_grid(UiObject *obj) { + return ui_grid_sp(obj, 0, 0); +} + +UIWIDGET ui_grid_sp(UiObject *obj, int margin, int columnspacing, int rowspacing) { UiContainer *ct = uic_get_current_container(obj); Arg args[16]; @@ -378,7 +384,7 @@ XtManageChild(grid); UiObject *newobj = uic_object_new(obj, grid); - newobj->container = ui_grid_container(obj, grid); + newobj->container = ui_grid_container(obj, grid, columnspacing, rowspacing); uic_obj_add(obj, newobj); XtAddCallback (grid, XmNresizeCallback , ui_grid_resize, newobj->container);
--- a/ui/motif/container.h Mon Nov 30 14:09:55 2015 +0100 +++ b/ui/motif/container.h Tue Jan 12 17:41:08 2016 +0100 @@ -67,6 +67,8 @@ UiLayoutBool fill; UiBool newline; char *label; + UiLayoutBool hexpand; + UiLayoutBool vexpand; }; struct UiContainer { @@ -89,6 +91,8 @@ UiContainer container; UcxList *lines; UcxList *current; + int columnspacing; + int rowspacing; }; struct UiTabViewContainer { @@ -125,7 +129,7 @@ Widget ui_box_container_prepare(UiContainer *ct, Arg *args, int *n, UiBool fill); void ui_box_container_add(UiContainer *ct, Widget widget); -UiContainer* ui_grid_container(UiObject *obj, Widget rowcolumn); +UiContainer* ui_grid_container(UiObject *obj, Widget form, int columnspacing, int rowspacing); Widget ui_grid_container_prepare(UiContainer *ct, Arg *args, int *n, UiBool fill); void ui_grid_container_add(UiContainer *ct, Widget widget);
--- a/ui/motif/toolkit.c Mon Nov 30 14:09:55 2015 +0100 +++ b/ui/motif/toolkit.c Tue Jan 12 17:41:08 2016 +0100 @@ -166,6 +166,7 @@ void ui_show(UiObject *obj) { uic_check_group_widgets(obj->ctx); XtRealizeWidget(obj->widget); + ui_window_dark_theme(XtDisplay(obj->widget), XtWindow(obj->widget)); // TODO: if } // implemented in window.c @@ -293,3 +294,17 @@ Widget ui_get_active_window() { return active_window; } + +void ui_window_dark_theme(Display *dp, Window window) { + Atom atom = XInternAtom(dp, "_GTK_THEME_VARIANT", False); + Atom type = XInternAtom(dp, "UTF8_STRING", False); + XChangeProperty( + dp, + window, + atom, + type, + 8, + PropModeReplace, + "dark", + 4); +}
--- a/ui/motif/toolkit.h Mon Nov 30 14:09:55 2015 +0100 +++ b/ui/motif/toolkit.h Tue Jan 12 17:41:08 2016 +0100 @@ -61,6 +61,7 @@ Widget ui_get_active_window(); void ui_secondary_event_loop(int *loop); +void ui_window_dark_theme(Display *dp, Window window); #ifdef __cplusplus }
--- a/ui/ui/toolkit.h Mon Nov 30 14:09:55 2015 +0100 +++ b/ui/ui/toolkit.h Tue Jan 12 17:41:08 2016 +0100 @@ -250,7 +250,7 @@ UIWIDGET ui_hbox(UiObject *obj); UIWIDGET ui_grid(UiObject *obj); -UIWIDGET ui_grid_sp(UiObject *obj, int columnspacing, int rowspacing); +UIWIDGET ui_grid_sp(UiObject *obj, int margin, int columnspacing, int rowspacing); UIWIDGET ui_sidebar(UiObject *obj); void ui_end(UiObject *obj); @@ -260,6 +260,8 @@ void ui_select_tab(UIWIDGET tabview, int tab); void ui_layout_fill(UiObject *obj, UiBool fill); +void ui_layout_hexpand(UiObject *obj, UiBool expand); +void ui_layout_vexpand(UiObject *obj, UiBool expand); void ui_newline(UiObject *obj);