~~Title: Segmentcontrol Widget PG~~ {{page>widgets_index}} ---- ===== Segment Control Widgets ===== {{ :widgets_segmentcontrol_tree.png }}{{ :widgets_segmentcontrol.png }} This widget 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. This widget inherits from the layout widget, so all the layout widgets API can be used on segmentcontrol objects. === Table of Contents === * [[#Adding_a_Segmentcontrol|Adding a Segmentcontrol]] * [[#Adding_Items|Adding Items]] * [[#Using_the_Segmentcontrol_Callbacks|Using the Segmentcontrol Callbacks]] === Related Info === * [[https://build.enlightenment.org/job/nightly_elm_gcc_x86_64/lastSuccessfulBuild/artifact/doc/html/group__SegmentControl.html|Segmentcontrol Widget API]] * [[https://build.enlightenment.org/job/nightly_elm_gcc_x86_64/lastSuccessfulBuild/artifact/doc/html/segment_control_example.html|A Segment Control Example]] ==== Adding a Segmentcontrol ==== This is how to add a segmentcontrol widget. Evas_Object *segcontrol = elm_segment_control_add(parent); ==== Adding Items ==== We can add items to it. Here we add four items containing only text labels (no icons). Elm_Object_Item *it; 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"); We can insert an item at a specific position starting at 0 elm_segment_control_item_insert_at(segcontrol, NULL, "item7", 2); or delete an item. elm_segment_control_item_del_at(segcontrol, 2); We can also set the selected state of an item manually elm_segment_control_item_selected_set(it, EINA_TRUE); or disable the whole segment control. elm_object_disabled_set(segcontrol, EINA_TRUE); ==== Using the Segmentcontrol Callbacks ==== This is how to register a callback on the "changed" signal. It 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 static void _changed_cb(void *data, Evas_Object *obj, void *event_info) { Elm_Segment_Item *it = event_info; printf("The selected segment item has changed\n"); } \\ //**__[[https://build.enlightenment.org/job/nightly_elm_gcc_x86_64/lastSuccessfulBuild/artifact/doc/html/segment_control_example.html|A Segment Control Example]]__**// ---- {{page>widgets_index}}