Sat, 10 Oct 2015 15:29:31 +0200
added checkbox and labels with alignment (GTK)
application/main.c | file | annotate | diff | comparison | revisions | |
ui/common/context.c | file | annotate | diff | comparison | revisions | |
ui/common/context.h | 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/label.c | file | annotate | diff | comparison | revisions | |
ui/gtk/text.c | file | annotate | diff | comparison | revisions | |
ui/ui/button.h | file | annotate | diff | comparison | revisions | |
ui/ui/text.h | file | annotate | diff | comparison | revisions | |
ui/ui/toolkit.h | file | annotate | diff | comparison | revisions |
--- a/application/main.c Thu Aug 20 17:14:27 2015 +0200 +++ b/application/main.c Sat Oct 10 15:29:31 2015 +0200 @@ -64,16 +64,48 @@ UiObject *obj = ui_window("Test", NULL); - UiTabbedPane *docs = ui_tabbed_document_view(obj); - UiObject *tab; - tab = ui_document_tab(docs); - ui_textarea(tab, NULL); - tab = ui_document_tab(docs); - ui_textarea(tab, NULL); - tab = ui_document_tab(docs); - ui_textarea(tab, NULL); - tab = ui_document_tab(docs); - ui_textarea(tab, NULL); + ui_layout_fill(obj, FALSE); + ui_grid_sp(obj, 10, 2); + + ui_rlabel(obj, "Name"); + ui_textfield(obj, NULL); + ui_newline(obj); + + ui_rlabel(obj, "Email"); + ui_textfield(obj, NULL); + ui_button(obj, "OK", NULL, NULL); + ui_newline(obj); + + ui_checkbox(obj, "fuck", NULL); + ui_rlabel(obj, "FUCK"); + ui_newline(obj); + ui_checkbox(obj, "this", NULL); + ui_newline(obj); + ui_checkbox(obj, "shit", NULL); + ui_newline(obj); + + ui_label(obj, "Awesome Button"); + UIWIDGET button = ui_button(obj, "...", NULL, NULL); + + ui_end(obj); + + ui_checkbox(obj, "A", NULL); + ui_checkbox(obj, "B", NULL); + ui_checkbox(obj, "C", NULL); + ui_checkbox(obj, "D", NULL); + ui_checkbox(obj, "E", NULL); + ui_checkbox(obj, "F", NULL); + ui_space(obj); + + ui_separator(obj); + + ui_layout_fill(obj, FALSE); + ui_hbox(obj); + ui_button(obj, "Submit", NULL, NULL); + //ui_space(obj); + ui_button(obj, "Cancel", NULL, NULL); + ui_end(obj); + ui_show(obj); ui_main();
--- a/ui/common/context.c Thu Aug 20 17:14:27 2015 +0200 +++ b/ui/common/context.c Sat Oct 10 15:29:31 2015 +0200 @@ -49,6 +49,8 @@ ctx->set_document = uic_context_set_document; ctx->detach_document = uic_context_detach_document; + ctx->title = NULL; + #ifdef UI_GTK if(toplevel->widget) { ctx->accel_group = gtk_accel_group_new();
--- a/ui/common/context.h Thu Aug 20 17:14:27 2015 +0200 +++ b/ui/common/context.h Sat Oct 10 15:29:31 2015 +0200 @@ -55,6 +55,8 @@ void (*set_document)(UiContext *ctx, void *document); void (*detach_document)(UiContext *ctx, void *document); + char *title; + #ifdef UI_GTK GtkAccelGroup *accel_group; #endif
--- a/ui/gtk/button.c Thu Aug 20 17:14:27 2015 +0200 +++ b/ui/gtk/button.c Sat Oct 10 15:29:31 2015 +0200 @@ -86,3 +86,67 @@ e.intval = gtk_toggle_tool_button_get_active(widget); event->callback(&e, event->userdata); } + +int ui_toggle_button_get(UiInteger *integer) { + GtkToggleButton *button = integer->obj; + integer->value = (int)gtk_toggle_button_get_active(button); + return integer->value; +} + +void ui_toggle_button_set(UiInteger *integer, int value) { + GtkToggleButton *button = integer->obj; + integer->value = value; + gtk_toggle_button_set_active(button, value != 0 ? TRUE : FALSE); +} + + +UIWIDGET ui_checkbox(UiObject *obj, char *label, UiInteger *value) { + GtkWidget *button = gtk_check_button_new_with_label(label); + + // bind value + if(value) { + value->obj = GTK_TOGGLE_BUTTON(button); + value->get = ui_toggle_button_get; + value->set = ui_toggle_button_set; + if(value->value != 0) { + gtk_toggle_button_set_active(value->obj, TRUE); + } + } + + UiContainer *ct = uic_get_current_container(obj); + ct->add(ct, button, FALSE); + + return button; +} + +UIWIDGET ui_checkbox_cb(UiObject *obj, char *label, ui_callback f, void *data) { + GtkWidget *button = gtk_check_button_new_with_label(label); + + if(f) { + //UiEventData *event = ucx_mempool_malloc( + // obj->ctx->mempool, + // sizeof(UiEventData)); + UiEventData *event = malloc(sizeof(UiEventData)); + event->obj = obj; + event->userdata = data; + event->callback = f; + event->value = 0; + + g_signal_connect( + button, + "clicked", + G_CALLBACK(ui_button_toggled), + event); + g_signal_connect( + button, + "destroy", + G_CALLBACK(ui_destroy_userdata), + event); + } + + UiContainer *ct = uic_get_current_container(obj); + ct->add(ct, button, FALSE); + + return button; +} +
--- a/ui/gtk/container.c Thu Aug 20 17:14:27 2015 +0200 +++ b/ui/gtk/container.c Sat Oct 10 15:29:31 2015 +0200 @@ -123,6 +123,13 @@ ct->layout.newline = FALSE; } + if(ct->layout.fill != UI_LAYOUT_UNDEFINED) { + fill = ui_lb2bool(ct->layout.fill); + } + if(fill) { + gtk_widget_set_hexpand(widget, TRUE); + } + gtk_grid_attach(GTK_GRID(ct->widget), widget, grid->x, grid->y, 1, 1); grid->x++; @@ -202,10 +209,17 @@ } UIWIDGET ui_grid(UiObject *obj) { + return ui_grid_sp(obj, 0, 0); +} + +UIWIDGET ui_grid_sp(UiObject *obj, 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); + #elif defined(UI_GTK2) GtkWidget *grid = gtk_table_new(1, 1, FALSE); #endif
--- a/ui/gtk/label.c Thu Aug 20 17:14:27 2015 +0200 +++ b/ui/gtk/label.c Sat Oct 10 15:29:31 2015 +0200 @@ -44,6 +44,19 @@ return widget; } +UIWIDGET ui_llabel(UiObject *obj, char *label) { + UIWIDGET widget = ui_label(obj, label); + gtk_misc_set_alignment(GTK_MISC(widget), 0, .5); + return widget; +} + +UIWIDGET ui_rlabel(UiObject *obj, char *label) { + UIWIDGET widget = ui_label(obj, label); + //gtk_label_set_justify(GTK_LABEL(widget), GTK_JUSTIFY_RIGHT); + gtk_misc_set_alignment(GTK_MISC(widget), 1, .5); + return widget; +} + UIWIDGET ui_space(UiObject *obj) { GtkWidget *widget = gtk_label_new(""); UiContainer *ct = uic_get_current_container(obj); @@ -51,3 +64,12 @@ return widget; } + +UIWIDGET ui_separator(UiObject *obj) { + GtkWidget *widget = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL); + UiContainer *ct = uic_get_current_container(obj); + ct->add(ct, widget, FALSE); + + return widget; +} +
--- a/ui/gtk/text.c Thu Aug 20 17:14:27 2015 +0200 +++ b/ui/gtk/text.c Sat Oct 10 15:29:31 2015 +0200 @@ -456,7 +456,15 @@ UIWIDGET ui_textfield(UiObject *obj, UiString *value) { + return ui_textfield_w(obj, 0, value); +} + +UIWIDGET ui_textfield_w(UiObject *obj, int width, UiString *value) { GtkWidget *textfield = gtk_entry_new(); + if(width > 0) { + gtk_entry_set_width_chars(GTK_ENTRY(textfield), width); + } + UiContainer *ct = uic_get_current_container(obj); ct->add(ct, textfield, FALSE); @@ -477,10 +485,14 @@ } UIWIDGET ui_textfield_nv(UiObject *obj, char *varname) { + return ui_textfield_wnv(obj, 0, varname); +} + +UIWIDGET ui_textfield_wnv(UiObject *obj, int width, char *varname) { UiVar *var = uic_connect_var(obj->ctx, varname, UI_VAR_STRING); if(var) { UiString *value = var->value; - return ui_textfield(obj, value); + return ui_textfield_w(obj, width, value); } else { // TODO: error }
--- a/ui/ui/button.h Thu Aug 20 17:14:27 2015 +0200 +++ b/ui/ui/button.h Sat Oct 10 15:29:31 2015 +0200 @@ -37,6 +37,9 @@ UIWIDGET ui_button(UiObject *obj, char *label, ui_callback f, void *data); +UIWIDGET ui_checkbox(UiObject *obj, char *label, UiInteger *value); +UIWIDGET ui_checkbox_cb(UiObject *obj, char *label, ui_callback f, void *data); + #ifdef __cplusplus }
--- a/ui/ui/text.h Thu Aug 20 17:14:27 2015 +0200 +++ b/ui/ui/text.h Sat Oct 10 15:29:31 2015 +0200 @@ -37,6 +37,8 @@ UIWIDGET ui_textarea(UiObject *obj, UiText *value); UIWIDGET ui_textarea_nv(UiObject *obj, char *varname); +UIWIDGET ui_textfield_w(UiObject *obj, int width, UiString *value); +UIWIDGET ui_textfield_wnv(UiObject *obj, int width, char *varname); void ui_text_undo(UiText *value); void ui_text_redo(UiText *value);
--- a/ui/ui/toolkit.h Thu Aug 20 17:14:27 2015 +0200 +++ b/ui/ui/toolkit.h Sat Oct 10 15:29:31 2015 +0200 @@ -238,7 +238,10 @@ UIWIDGET ui_vbox(UiObject *obj); UIWIDGET ui_hbox(UiObject *obj); + UIWIDGET ui_grid(UiObject *obj); +UIWIDGET ui_grid_sp(UiObject *obj, int columnspacing, int rowspacing); + UIWIDGET ui_sidebar(UiObject *obj); void ui_end(UiObject *obj); @@ -325,7 +328,10 @@ UIWIDGET ui_label(UiObject *obj, char *label); +UIWIDGET ui_llabel(UiObject *obj, char *label); +UIWIDGET ui_rlabel(UiObject *obj, char *label); UIWIDGET ui_space(UiObject *obj); +UIWIDGET ui_separator(UiObject *obj); #ifdef __cplusplus }