/* gcc -g `pkg-config --cflags --libs gtk+-3.0` test.c -o test */

#include <gtk/gtk.h>

static GtkRadioButton *radio_group = NULL;

typedef struct {
    GtkWidget *plain;
    GtkWidget *bold;
} LabelPair;

static LabelPair *
create_labels (const char *text)
{
    char *bold_text;
    LabelPair *pair = g_new (LabelPair, 1);

    pair->plain = gtk_label_new (text);
    bold_text = g_strdup_printf ("<b>%s</b>", text);
    pair->bold = gtk_label_new (bold_text);
    gtk_label_set_use_markup (GTK_LABEL (pair->bold), TRUE);
    g_free (bold_text);

    g_object_ref (pair->plain);
    g_object_ref (pair->bold);

    return pair;
}

static void
on_toggle (GtkWidget *radio, LabelPair *labels)
{
    gtk_container_remove (GTK_CONTAINER (radio), gtk_bin_get_child (GTK_BIN (radio)));
    if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (radio))) {
        gtk_container_add (GTK_CONTAINER (radio), labels->bold);
    } else {
        gtk_container_add (GTK_CONTAINER (radio), labels->plain);
    }
    gtk_widget_show_all (radio);
}

static GtkWidget *
radio_button (LabelPair *labels)
{
    GtkWidget *radio;

    radio = gtk_radio_button_new_from_widget (radio_group);
    radio_group = GTK_RADIO_BUTTON (radio);
    g_object_set (radio, "draw-indicator", FALSE, NULL);

    gtk_container_add (GTK_CONTAINER (radio), labels->bold);

    g_signal_connect (radio, "toggled", G_CALLBACK (on_toggle), labels);

    return radio;
}

int
main (int argc, char *argv[])
{
    GtkWidget *window;
    GtkWidget *box;
    GtkWidget *radio;
    LabelPair *labels_foo;
    LabelPair *labels_bar;

    gtk_init (&argc, &argv);

    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    box = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
    gtk_container_add (GTK_CONTAINER (window), box);

    labels_foo = create_labels ("Foo");
    radio = radio_button (labels_foo);
    gtk_container_add (GTK_CONTAINER (box), radio);
    labels_bar = create_labels ("Bar");
    radio = radio_button (labels_bar);
    gtk_container_add (GTK_CONTAINER (box), radio);

    gtk_widget_show_all (window);
    gtk_main ();

    return 0;
}
