Sun, 24 Jan 2016 11:59:58 +0100
radio buttons bind to UiInteger now
application/main.c | file | annotate | diff | comparison | revisions | |
ui/common/context.c | file | annotate | diff | comparison | revisions | |
ui/gtk/button.c | file | annotate | diff | comparison | revisions | |
ui/gtk/button.h | file | annotate | diff | comparison | revisions | |
ui/ui/button.h | file | annotate | diff | comparison | revisions |
--- a/application/main.c Sat Jan 23 23:44:41 2016 +0100 +++ b/application/main.c Sun Jan 24 11:59:58 2016 +0100 @@ -33,7 +33,7 @@ #include <ucx/buffer.h> #include <ucx/utils.h> -UiRadioButtonGroup rgroup; +UiInteger radio; void action_menu(UiEvent *event, void *data) { printf("action_menu test: {%s}\n", data); @@ -47,12 +47,11 @@ } void action_button(UiEvent *event, void *data) { - printf("radio: %d\n", ui_radiobuttongroup_selection(&rgroup)); - fflush(stdout); + printf("radio: %d\n", ui_getval(radio)); } void action_button2(UiEvent *event, void *data) { - ui_radiobuttongroup_select(&rgroup, 3); + ui_setval(radio, 1); } void draw(UiEvent *event, UiGraphics *g, void *data) { @@ -132,14 +131,15 @@ ui_layout_fill(obj, FALSE); ui_grid_sp(obj, 0, 4, 4); - rgroup = ui_radiobuttongroup(); - ui_radiobutton(obj, "better", &rgroup); + ui_radiobutton(obj, "better", &radio); + ui_newline(obj); + ui_radiobutton(obj, "smarter", &radio); ui_newline(obj); - ui_radiobutton(obj, "awesome", &rgroup); - ui_newline(obj); - ui_radiobutton(obj, "smarter", &rgroup); + ui_radiobutton(obj, "awesome", &radio); ui_end(obj); + ui_space(obj); + ui_button(obj, "OK", action_button, NULL); ui_button(obj, "Activate", action_button2, NULL);
--- a/ui/common/context.c Sat Jan 23 23:44:41 2016 +0100 +++ b/ui/common/context.c Sun Jan 24 11:59:58 2016 +0100 @@ -176,7 +176,7 @@ return var; } } else { - // create an empty value and add it to the window variables + // create an empty value and add it to the context variables // it can be moved to the document vars later void *value = uic_create_value(ctx->mempool->allocator, type); if(!value) {
--- a/ui/gtk/button.c Sat Jan 23 23:44:41 2016 +0100 +++ b/ui/gtk/button.c Sun Jan 24 11:59:58 2016 +0100 @@ -151,48 +151,21 @@ } -UiRadioButtonGroup ui_radiobuttongroup() { - UiRadioButtonGroup rgroup; - rgroup.group = NULL; - rgroup.ref = 0; - return rgroup; -} -void ui_radiobuttongroup_select(UiRadioButtonGroup *rgroup, int index) { - GSList *ls = rgroup->group; - int s = g_slist_length(rgroup->group) - 1 - index; - int i = 0; - while(ls) { - if(i == s) { - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ls->data), TRUE); - break; +UIWIDGET ui_radiobutton(UiObject *obj, char *label, UiInteger *rgroup) { + GSList *rg = rgroup ? rgroup->obj : NULL; + + GtkWidget *rbutton = gtk_radio_button_new_with_label(rg, label); + rg = gtk_radio_button_get_group(GTK_RADIO_BUTTON(rbutton)); + + if(rgroup) { + rgroup->obj = rg; + rgroup->get = ui_radiobutton_get; + rgroup->set = ui_radiobutton_set; + if(rgroup->value > 0) { + ui_radiobutton_set(rgroup, rgroup->value); } - ls = ls->next; - i++; } -} - -int ui_radiobuttongroup_selection(UiRadioButtonGroup *rgroup) { - GSList *ls = rgroup->group; - int i = 0; - while(ls) { - if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ls->data))) { - return g_slist_length(rgroup->group) - i - 1; - } - ls = ls->next; - i++; - } - return -1; -} - -int io_radiobuttongroup_count(UiRadioButtonGroup *rgroup) { - return g_slist_length(rgroup->group); -} - -UIWIDGET ui_radiobutton(UiObject *obj, char *label, UiRadioButtonGroup *rgroup) { - GtkWidget *rbutton = gtk_radio_button_new_with_label(rgroup->group, label); - rgroup->group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(rbutton)); - rgroup->ref++; UiContainer *ct = uic_get_current_container(obj); ct->add(ct, rbutton, FALSE); @@ -200,3 +173,36 @@ return rbutton; } +int ui_radiobutton_get(UiInteger *value) { + int selection = 0; + GSList *ls = value->obj; + int i = 0; + while(ls) { + if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ls->data))) { + selection = g_slist_length(value->obj) - i - 1; + break; + } + ls = ls->next; + i++; + } + + value->value = selection; + return selection; +} + +void ui_radiobutton_set(UiInteger *value, int i) { + GSList *ls = value->obj; + int s = g_slist_length(ls) - 1 - i; + int j = 0; + while(ls) { + if(j == s) { + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(ls->data), TRUE); + break; + } + ls = ls->next; + j++; + } + + value->value = j; +} +
--- a/ui/gtk/button.h Sat Jan 23 23:44:41 2016 +0100 +++ b/ui/gtk/button.h Sun Jan 24 11:59:58 2016 +0100 @@ -41,6 +41,8 @@ void ui_button_clicked(GtkWidget *widget, UiEventData *event); void ui_button_toggled(GtkToggleToolButton *widget, UiEventData *event); +int ui_radiobutton_get(UiInteger *value); +void ui_radiobutton_set(UiInteger *value, int i); #ifdef __cplusplus }
--- a/ui/ui/button.h Sat Jan 23 23:44:41 2016 +0100 +++ b/ui/ui/button.h Sun Jan 24 11:59:58 2016 +0100 @@ -34,23 +34,13 @@ #ifdef __cplusplus extern "C" { #endif - -typedef struct { - void *group; - int ref; -} UiRadioButtonGroup; 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); -UiRadioButtonGroup ui_radiobuttongroup(); -void ui_radiobuttongroup_select(UiRadioButtonGroup *rgroup, int index); -int ui_radiobuttongroup_selection(UiRadioButtonGroup *rgroup); -int io_radiobuttongroup_count(UiRadioButtonGroup *rgroup); - -UIWIDGET ui_radiobutton(UiObject *obj, char *label, UiRadioButtonGroup *rgroup); +UIWIDGET ui_radiobutton(UiObject *obj, char *label, UiInteger *rgroup); #ifdef __cplusplus