Re: radio_button behavior with toggle_button style ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Alain D'EURVEILHER wrote:

Hi,

Is it possible to make a group of toggle button, but behavioring as the radiobuttons ??

Here it is... : have for example 3 toggle_button and, pressing one down release (up) the other ones...


Hello, here's one of the possible solutions:

static void button_toggled(GtkToggleButton *toggle, GSlist **list)
{
GSlist *node;

g_return_if_fail(*list != NULL); /* this is for debugging only */

   if (!toggle->active)    /* skip the code below if button is depressed */
       return;

for (node=*list; node!=NULL; node=node->next)
if (node->data != toggle) /* iterate through the list and deactivate all buttons other than pressed */
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON((*list)->data), FALSE);
}


/* helper function, saves some lines of code */
static GtkWidget *toggle_new(GSList **list, const gchar *label)
{
GtkWidget *button;

button = gtk_toggle_button_new_with_label(label);
g_signal_connect(button, "toggle", G_CALLBACK(button_toggled), list);
*list = g_slist_prepend(*list, button); /* adding button to the list (prepend is faster than append) */
}


void setup()
{
GtkWidget *button1, *button2, *button3;
static GSList *list;    /* this var SHOULD be static */

   /* creating 3 widgets */
   button1 = toggle_new(&list, "toggle 1");
   button2 = toggle_new(&list, "toggle 2");
   button3 = toggle_new(&list, "toggle 3");
}

PS: I just typed some C lines here, so some typos/bugs can be found

Olexiy

_______________________________________________

gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux