This code places an Elementary diskselector widgets on a window, along with some buttons trigerring actions on it (though its A\+PI).

It covers most of diskselector item functions.

On our {\ttfamily main} function, we are adding a default diskselector with 3 items. We are only setting their labels (second parameter of function elm\+\_\+diskselector\+\_\+item\+\_\+append)\+:  
\begin{DoxyCodeInclude}
   ds = elm_diskselector_add(win);
   evas\_object\_size\_hint\_weight\_set(ds, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(ds, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   evas\_object\_smart\_callback\_add(ds, \textcolor{stringliteral}{"selected"}, \_ds\_selected\_cb, NULL);
   elm\_box\_pack\_end(bx, ds);
   evas\_object\_show(ds);

   elm\_diskselector\_item\_append(ds, \textcolor{stringliteral}{"Item 0"}, NULL, NULL, NULL);
   elm\_diskselector\_item\_append(ds, \textcolor{stringliteral}{"Item 1"}, NULL, NULL, NULL);
   elm\_diskselector\_item\_append(ds, \textcolor{stringliteral}{"Item 2"}, NULL, NULL, NULL);

\end{DoxyCodeInclude}


Next we are adding lots of buttons, each one for a callback function that will realize a task covering part of diskselector items A\+PI. Lets check the first one\+: 
\begin{DoxyCodeInclude}
   bt = elm_button_add(win);
   elm\_object\_text\_set(bt, \textcolor{stringliteral}{"Append item"});
   evas\_object\_smart\_callback\_add(bt, \textcolor{stringliteral}{"clicked"}, \_add\_cb, ds);
   elm\_box\_pack\_end(hbx, bt);
   evas\_object\_size\_hint\_weight\_set(bt, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_size\_hint\_align\_set(bt, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   evas\_object\_show(bt);

\end{DoxyCodeInclude}


We are labeling the button with a task description with elm\+\_\+object\+\_\+text\+\_\+set() and setting a callback function evas\+\_\+object\+\_\+smart\+\_\+callback\+\_\+add(). Each callback function will have the signature\+: {\ttfamily  static void \+\_\+task\+\_\+cb(void $\ast$data, Evas\+\_\+\+Object $\ast$obj, void $\ast$event\+\_\+info)} with the function name varying for each task.

Now let\textquotesingle{}s cover all of them.

{\bfseries  Appending an item\+: }  
\begin{DoxyCodeInclude}
\_add\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *ds\_it;
   Evas\_Object *ds = data;
   \textcolor{keywordtype}{char} label[32];

   snprintf(label, \textcolor{keyword}{sizeof}(label), \textcolor{stringliteral}{"Item %i"}, counter++);
   ds\_it = elm\_diskselector\_item\_append(ds, label, NULL, NULL, NULL);
   \textcolor{keywordflow}{if} (!ds\_it) printf(\textcolor{stringliteral}{"Error adding item\(\backslash\)n"});
\}

\end{DoxyCodeInclude}


All items are included on diskselector after last one. You {\bfseries can\textquotesingle{}t} prepend items.

The first parameter of elm\+\_\+diskselector\+\_\+item\+\_\+append() is the diskselector object, that we are receiving as data on our callback function. The second one is a label, the string that will be placed in the center of our item. As we don\textquotesingle{}t wan\textquotesingle{}t icons or callback functions, we can send N\+U\+LL as third, fourth and fifth parameters.

{\bfseries  Appending an item with icon\+: }  
\begin{DoxyCodeInclude}
\_add\_ic\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *ds\_it;
   Evas\_Object *ic, *ds = data;
   \textcolor{keywordtype}{char} label[32];

   snprintf(label, \textcolor{keyword}{sizeof}(label), \textcolor{stringliteral}{"Item %i"}, counter++);
   ic = elm_icon_add(ds);
   elm\_icon\_standard\_set(ic, \textcolor{stringliteral}{"home"});

   ds\_it = elm\_diskselector\_item\_append(ds, label, ic, NULL, NULL);
   \textcolor{keywordflow}{if} (!ds\_it) printf(\textcolor{stringliteral}{"Error adding item with icon\(\backslash\)n"});
\}

\end{DoxyCodeInclude}


If an icon is required, you can pass it as third parameter on our elm\+\_\+diskselector\+\_\+item\+\_\+append() function. It will be place on the left side of item\textquotesingle{}s label, that will be shifted to right a bit.

For more details about how to create icons, look for elm\+\_\+icon examples.

{\bfseries  Appending an item with callback function for selected\+: }  
\begin{DoxyCodeInclude}
\_sel\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *ds\_it = event\_info;
   printf(\textcolor{stringliteral}{"Selected label: %s\(\backslash\)n"}, elm\_object\_item\_text\_get(ds\_it));
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_add\_func\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *ds\_it;
   Evas\_Object *ds = data;
   \textcolor{keywordtype}{char} label[32];

   snprintf(label, \textcolor{keyword}{sizeof}(label), \textcolor{stringliteral}{"Item %i"}, counter++);
   ds\_it = elm\_diskselector\_item\_append(ds, label, NULL, \_sel\_cb, NULL);
   \textcolor{keywordflow}{if} (!ds\_it) printf(\textcolor{stringliteral}{"Error adding item\(\backslash\)n"});
\}

\end{DoxyCodeInclude}


To set a callback function that will be called every time an item is selected, i.\+e., everytime the diskselector stops with this item in center position, just pass the function as fourth parameter.

{\bfseries  Appending an item with callback function for selected with data\+: }  
\begin{DoxyCodeInclude}
\_sel\_data\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   \textcolor{keywordtype}{char} *content = data;
   Elm_Object_Item *ds\_it = event\_info;
   printf(\textcolor{stringliteral}{"Selected label: %s with data: %s\(\backslash\)n"},
          elm\_object\_item\_text\_get(ds\_it), content);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_free\_data(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   free(data);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_add\_data\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *ds\_it;
   Evas\_Object *ds = data;
   \textcolor{keywordtype}{char} label[32];
   \textcolor{keywordtype}{char} *content = malloc(\textcolor{keyword}{sizeof}(\textcolor{keywordtype}{char}) * 32);

   snprintf(content, 32, \textcolor{stringliteral}{"Item content %i"}, counter);
   snprintf(label, \textcolor{keyword}{sizeof}(label), \textcolor{stringliteral}{"Item %i"}, counter++);
   ds\_it = elm\_diskselector\_item\_append(ds, label, NULL, \_sel\_data\_cb, content);
   \textcolor{keywordflow}{if} (!ds\_it)
     \{
        printf(\textcolor{stringliteral}{"Error adding item\(\backslash\)n"});
        \textcolor{keywordflow}{return};
     \}
   elm\_object\_item\_del\_cb\_set(ds\_it, \_free\_data);
\}

\end{DoxyCodeInclude}


If the callback function request an extra data, it can be attached to our item passing a pointer for data as fifth parameter. Our function \+\_\+sel\+\_\+data\+\_\+cb will receive it as {\ttfamily  void $\ast$data }.

If you want to free this data, or handle that the way you need when the item is deleted, set a callback function for that, with elm\+\_\+object\+\_\+item\+\_\+del\+\_\+cb\+\_\+set().

As you can see we check if {\ttfamily it} is not {\ttfamily N\+U\+LL} after appending it. If an error happens, we won\textquotesingle{}t try to set a function for it.

{\bfseries  Deleting an item\+: }  
\begin{DoxyCodeInclude}
\_del\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *selected\_ds\_it;
   Evas\_Object *ds = data;

   selected\_ds\_it = elm\_diskselector\_selected\_item\_get(ds);
   elm\_object\_item\_del(selected\_ds\_it);
\}

\end{DoxyCodeInclude}


To delete an item we simple need to call elm\+\_\+object\+\_\+item\+\_\+del() with a pointer for such item.

If you need, you can get selected item with elm\+\_\+diskselector\+\_\+selected\+\_\+item\+\_\+get(), that will return a pointer for it.

{\bfseries  Unselecting an item\+: }  
\begin{DoxyCodeInclude}
\_unselect\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *selected\_ds\_it;
   Evas\_Object *ds = data;

   selected\_ds\_it = elm\_diskselector\_selected\_item\_get(ds);
   elm\_diskselector\_item\_selected\_set(selected\_ds\_it, EINA\_FALSE);
\}

\end{DoxyCodeInclude}


To select an item, you should call elm\+\_\+diskselector\+\_\+item\+\_\+selected\+\_\+set() passing {\ttfamily E\+I\+N\+A\+\_\+\+T\+R\+UE}, and to unselect it, {\ttfamily E\+I\+N\+A\+\_\+\+F\+A\+L\+SE}.

If you unselect the selected item, diskselector will automatically select the first item.

{\bfseries  Printing all items\+: }  
\begin{DoxyCodeInclude}
\_print\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   \textcolor{keyword}{const} Eina\_List *l, *items;
   Elm_Object_Item *ds\_it;
   Evas\_Object *ds = data;

   items = elm\_diskselector\_items\_get(ds);
   EINA\_LIST\_FOREACH(items, l, ds\_it)
     printf("%s\(\backslash\)n", elm\_object\_item\_text\_get(ds\_it));
\}

\end{DoxyCodeInclude}


{\bfseries  Clearing the diskselector\+: }  
\begin{DoxyCodeInclude}
\_clear\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Evas\_Object *ds = data;
   elm\_diskselector\_clear(ds);
\}

\end{DoxyCodeInclude}


{\bfseries  Selecting the first item\+: }  
\begin{DoxyCodeInclude}
\_select\_first\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *first\_ds\_it;
   Evas\_Object *ds = data;

   first\_ds\_it = elm\_diskselector\_first\_item\_get(ds);
   \textcolor{keywordflow}{if} (first\_ds\_it)
     elm\_diskselector\_item\_selected\_set(first\_ds\_it, EINA\_TRUE);
\}

\end{DoxyCodeInclude}


{\bfseries  Selecting the last item\+: }  
\begin{DoxyCodeInclude}
\_select\_last\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *last\_ds\_it;
   Evas\_Object *ds = data;

   last\_ds\_it = elm\_diskselector\_last\_item\_get(ds);
   \textcolor{keywordflow}{if} (last\_ds\_it)
     elm\_diskselector\_item\_selected\_set(last\_ds\_it, EINA\_TRUE);
\}

\end{DoxyCodeInclude}


{\bfseries  Selecting the next item\+: }  
\begin{DoxyCodeInclude}
\_select\_next\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *selected\_ds\_it, *next\_ds\_it;
   Evas\_Object *ds = data;

   selected\_ds\_it = elm\_diskselector\_selected\_item\_get(ds);
   \textcolor{keywordflow}{if} (!selected\_ds\_it) \textcolor{keywordflow}{return};

   next\_ds\_it = elm\_diskselector\_item\_next\_get(selected\_ds\_it);
   \textcolor{keywordflow}{if} (next\_ds\_it)
     elm\_diskselector\_item\_selected\_set(next\_ds\_it, EINA\_TRUE);
\}

\end{DoxyCodeInclude}


{\bfseries  Selecting the previous item\+: }  
\begin{DoxyCodeInclude}
\_select\_prev\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Elm_Object_Item *selected\_ds\_it, *prev\_ds\_it;
   Evas\_Object *ds = data;

   selected\_ds\_it = elm\_diskselector\_selected\_item\_get(ds);
   \textcolor{keywordflow}{if} (!selected\_ds\_it) \textcolor{keywordflow}{return};

   prev\_ds\_it = elm\_diskselector\_item\_prev\_get(selected\_ds\_it);
   \textcolor{keywordflow}{if} (prev\_ds\_it)
     elm\_diskselector\_item\_selected\_set(prev\_ds\_it, EINA\_TRUE);
\}

\end{DoxyCodeInclude}


See the full \hyperlink{diskselector_example_02_8c-example}{diskselector\+\_\+example\+\_\+02.c} code, whose window should look like this picture\+:

 
\begin{DoxyImageNoCaption}
  \mbox{\includegraphics[width=\textwidth]{screenshots/diskselector_example_02}}
\end{DoxyImageNoCaption}
 