Radio Widgets

This widget displays one or more options, but the user can only select one of them. It is composed of an indicator (selected/unselected), an optional icon and an optional label. Usually grouped with two or more other radio objects, it can also be used alone.

The radio widget inherits from the layout widget. All the layout functions can be used with radio objects.

Table of Contents

Adding a Radio

We create a radio widget and set a label to it.

Evas_Object *radio;
 
// Creating a radio
radio = elm_radio_add(parent);
 
// Set a label to it
elm_object_text_set(radio, "Radio widget");

We set an icon to the radio object.

// Create a Home icon
Evas_Object *icon;
 
icon = elm_icon_add(parent);
elm_icon_standard_set(icon, "home");
 
// Set it to the radio widget
elm_object_part_content_set(radio, "icon", icon);

Changing Radio Value

The user can select one of a set of values with the radio widget. Each radio object from a group of radio objects represents an integer value. Here we set the value one to the new radio object.

elm_radio_state_value_set(radio, 1);

Managing Radio Groups

We create a group of radio objects with at least two radio widgets.

// Create another radio object
Evas_Object *radio2 = elm_radio_add(parent);
elm_radio_state_value_set(radio2, 2);
 
// Create a group composed of radio and radio2
Evas_Object *group = radio;
elm_radio_group_add(radio2, group);

Now that we have a group composed of two radio objects, we can choose which one is selected. Here we select radio2.

elm_radio_value_set(group, 2);

We can use elm_radio_value_get() to see the currently selected radio of the group.

Using Radio Callbacks

This widget emits the following signals, besides the ones sent from Layout:

  • “changed” - This is called when the radio object is selected. If you want to trace the state change of a radio group, you should add this callback to all the radio objects in that group.
  • “focused” - When the radio has received focus. (since 1.8)
  • “unfocused” - When the radio has lost focus. (since 1.8)
  • “language,changed” - the program's language changed (since 1.9)

When the state of a radio is modified in a group of radio objects, the “changed” signal is emitted.

This is how to register a callback on this signal.

evas_object_smart_callback_add(radio, "changed", _changed_cb, data);
// Callback function for the "changed" signal
// This callback is called when the radio value changes
static void
changed_cb(void *data, Evas_Object *obj, void *event_info)
{
   printf("The value has changed\n");
}


A Radio Example