Mobile native

Segmentcontrol

This feature is supported in mobile applications only.

The segmentcontrol component consists of several segment items. A segment item is similar to a discrete two state button. Any time, only one segment item can be selected. A segment item is composed of a label (text) and an icon.

The segmentcontrol component inherits from the layout component, which means that layout functions can be used on segmentcontrol objects.

For more information, see the SegmentControl API.

Figure: Segmentcontrol (with text on left and with icons on right)

Segmentcontrol with text Segmentcontrol with icons

Figure: Segmentcontrol hierarchy

Segmentcontrol hierarchy

Adding a Segmentcontrol Component

To add a segmentcontrol component, use the elm_segment_control_add() function:

Evas_Object *segcontrol, *parent;

segcontrol = elm_segment_control_add(parent);

Adding Items

To add items to the segmentcontrol component:

  1. Add the items. In the following example, 4 items containing only text labels (no icons) are added.
    Elm_Object_Item *it;
    int count, idx;
    
    elm_segment_control_item_add(segcontrol, NULL, "item1");
    elm_segment_control_item_add(segcontrol, NULL, "item2");
    elm_segment_control_item_add(segcontrol, NULL, "item3");
    it = elm_segment_control_item_add(segcontrol, NULL, "item4");
    
  2. Manage the items:

    • Insert an item at a specific position starting at 0:
      elm_segment_control_item_insert_at(segcontrol, NULL, "item7", 2);
      
    • Delete an item:
      elm_segment_control_item_del_at(segcontrol, 2);
      
    • Set the selected state of an item manually:
      elm_segment_control_item_selected_set(it, EINA_TRUE);
      
    • Disable the whole segment control:
      elm_object_disabled_set(segcontrol, EINA_TRUE);
      
    • Get the selected item:
      it = elm_segment_control_item_selected_get(segcontrol);
      
    • Get the item placed at a specified index:
      it = elm_segment_control_item_get(segcontrol, 2);
      
    • Get the item count from the segment control:
      count = elm_segment_control_item_count_get(segcontrol);
      
    • Get the index of an item:
      idx = elm_segment_control_item_index_get(it);
      

Using the Segmentcontrol Callbacks

The following example shows how to register a callback on the changed signal, which is called when the user clicks on a segment item which is not previously selected. The event_info parameter is the segment item pointer.

{
   evas_object_smart_callback_add(segcontrol, "changed", changed_cb, data);
}

// Callback function for the "changed" signal
// This callback is called when the segcontrol selected item changes
void 
changed_cb(void *data, Evas_Object *obj, void *event_info)
{
   Elm_Object_Item *it = event_info;
   dlog_print(DLOG_INFO, LOG_TAG, "The selected segment item is %s\n",
              elm_object_item_text_get(it));
}
Note
Except as noted, this content is licensed under LGPLv2.1+.
Go to top