

For this example we are going to assume knowledge of evas smart callbacks and some basic evas object functions. Elementary is not meant to be used without evas, if you\textquotesingle{}re not yet familiar with evas it probably is worth checking that out.

And now to the example, when using Elementary we start by including Elementary.\+h\+: 
\begin{DoxyCodeInclude}
\textcolor{preprocessor}{#include <Elementary.h>}

\end{DoxyCodeInclude}


Next we define some callbacks, they all share the same signature because they are all to be used with evas\+\_\+object\+\_\+smart\+\_\+callback\+\_\+add(). The first one just prints the selected label(in two different ways)\+: 
\begin{DoxyCodeInclude}

\textcolor{keyword}{static} \textcolor{keywordtype}{void} \_pos\_selected\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   printf(\textcolor{stringliteral}{"Selection: %s\(\backslash\)n"}, (\textcolor{keywordtype}{char} *)event\_info);
   printf(\textcolor{stringliteral}{"Label selected: %s\(\backslash\)n"}, elm\_actionslider\_selected\_label\_get(obj));
\}

\end{DoxyCodeInclude}


This next callback is a little more interesting, it makes the selected label magnetic(except if it\textquotesingle{}s the center label)\+: 
\begin{DoxyCodeInclude}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_position\_change\_magnetic\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object * obj, \textcolor{keywordtype}{void} *event\_info)
\{
   \textcolor{keywordflow}{if} (!strcmp((\textcolor{keywordtype}{char} *)event\_info, \textcolor{stringliteral}{"left"}))
     elm\_actionslider\_magnet\_pos\_set(obj, ELM\_ACTIONSLIDER\_LEFT);
   \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (!strcmp((\textcolor{keywordtype}{char} *)event\_info, \textcolor{stringliteral}{"right"}))
     elm\_actionslider\_magnet\_pos\_set(obj, ELM\_ACTIONSLIDER\_RIGHT);
\}

\end{DoxyCodeInclude}


This callback enables or disables the magnetic property of the center label\+: 
\begin{DoxyCodeInclude}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_magnet\_enable\_disable\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   \textcolor{keywordflow}{if} (!strcmp((\textcolor{keywordtype}{char} *)event\_info, \textcolor{stringliteral}{"left"}))
     elm\_actionslider\_magnet\_pos\_set(obj, ELM\_ACTIONSLIDER\_CENTER);
   \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (!strcmp((\textcolor{keywordtype}{char} *)event\_info, \textcolor{stringliteral}{"right"}))
     elm\_actionslider\_magnet\_pos\_set(obj, ELM\_ACTIONSLIDER\_NONE);
\}

\end{DoxyCodeInclude}


And finally a callback to stop the main loop when the window is closed\+: 
\begin{DoxyCodeInclude}

EAPI\_MAIN \textcolor{keywordtype}{int}
elm\_main(\textcolor{keywordtype}{int} argc, \textcolor{keywordtype}{char} **argv)
\{
   Evas\_Object *win, *bx, *as;

   elm_policy_set(ELM\_POLICY\_QUIT, ELM\_POLICY\_QUIT\_LAST\_WINDOW\_CLOSED);

   win = elm_win_util_standard_add(\textcolor{stringliteral}{"actionslider"}, \textcolor{stringliteral}{"Actionslider"});
   elm\_win\_autodel\_set(win, EINA\_TRUE);

   bx = elm_box_add(win);
   evas\_object\_size\_hint\_weight\_set(bx, EVAS\_HINT\_EXPAND, 0);
   elm\_win\_resize\_object\_add(win, bx);
   evas\_object\_show(bx);

   as = elm_actionslider_add(win);
   evas\_object\_size\_hint\_weight\_set(as, EVAS\_HINT\_EXPAND, 0);
   evas\_object\_size\_hint\_align\_set(as, EVAS\_HINT\_FILL, 0);
   elm\_actionslider\_indicator\_pos\_set(as, ELM\_ACTIONSLIDER\_RIGHT);
   elm\_actionslider\_magnet\_pos\_set(as, ELM\_ACTIONSLIDER\_RIGHT);
   elm_object_part_text_set(as, \textcolor{stringliteral}{"left"}, \textcolor{stringliteral}{"Snooze"});
   elm_object_part_text_set(as, \textcolor{stringliteral}{"right"}, \textcolor{stringliteral}{"Stop"});
   elm\_actionslider\_enabled\_pos\_set(as, ELM\_ACTIONSLIDER\_LEFT |
                                    ELM\_ACTIONSLIDER\_RIGHT);
   evas\_object\_smart\_callback\_add(as, \textcolor{stringliteral}{"pos\_changed"},
                                  \_position\_change\_magnetic\_cb, NULL);
   evas\_object\_smart\_callback\_add(as, \textcolor{stringliteral}{"selected"}, \_pos\_selected\_cb, NULL);
   evas\_object\_show(as);
   elm\_box\_pack\_end(bx, as);

   as = elm_actionslider_add(win);
   evas\_object\_size\_hint\_weight\_set(as, EVAS\_HINT\_EXPAND, 0);
   evas\_object\_size\_hint\_align\_set(as, EVAS\_HINT\_FILL, 0);
   elm\_actionslider\_indicator\_pos\_set(as, ELM\_ACTIONSLIDER\_CENTER);
   elm\_actionslider\_magnet\_pos\_set(as, ELM\_ACTIONSLIDER\_CENTER);
   elm_object_part_text_set(as, \textcolor{stringliteral}{"left"}, \textcolor{stringliteral}{"Snooze"});
   elm_object_part_text_set(as, \textcolor{stringliteral}{"right"}, \textcolor{stringliteral}{"Stop"});
   elm\_actionslider\_enabled\_pos\_set(as, ELM\_ACTIONSLIDER\_LEFT |
                                    ELM\_ACTIONSLIDER\_RIGHT);
   evas\_object\_smart\_callback\_add(as, \textcolor{stringliteral}{"selected"}, \_pos\_selected\_cb, NULL);
   evas\_object\_show(as);
   elm\_box\_pack\_end(bx, as);

   as = elm_actionslider_add(win);
   elm_object_style_set(as, \textcolor{stringliteral}{"bar"});
   evas\_object\_size\_hint\_weight\_set(as, EVAS\_HINT\_EXPAND, 0);
   evas\_object\_size\_hint\_align\_set(as, EVAS\_HINT\_FILL, 0);
   elm\_actionslider\_indicator\_pos\_set(as, ELM\_ACTIONSLIDER\_LEFT);
   elm\_actionslider\_magnet\_pos\_set(as, ELM\_ACTIONSLIDER\_CENTER|
                                   ELM\_ACTIONSLIDER\_RIGHT);
   elm\_actionslider\_enabled\_pos\_set(as, ELM\_ACTIONSLIDER\_CENTER |
                                    ELM\_ACTIONSLIDER\_RIGHT);
   elm_object_part_text_set(as, \textcolor{stringliteral}{"center"}, \textcolor{stringliteral}{"Accept"});
   elm_object_part_text_set(as, \textcolor{stringliteral}{"right"}, \textcolor{stringliteral}{"Reject"});
   evas\_object\_smart\_callback\_add(as, \textcolor{stringliteral}{"selected"}, \_pos\_selected\_cb, NULL);
   evas\_object\_show(as);
   elm\_box\_pack\_end(bx, as);

   as = elm_actionslider_add(win);
   elm_object_style_set(as, \textcolor{stringliteral}{"bar"});
   evas\_object\_size\_hint\_weight\_set(as, EVAS\_HINT\_EXPAND, 0);
   evas\_object\_size\_hint\_align\_set(as, EVAS\_HINT\_FILL, 0);
   elm\_actionslider\_indicator\_pos\_set(as, ELM\_ACTIONSLIDER\_LEFT);
   elm\_actionslider\_magnet\_pos\_set(as, ELM\_ACTIONSLIDER\_LEFT);
   elm_object_part_text_set(as, \textcolor{stringliteral}{"center"}, \textcolor{stringliteral}{"Accept"});
   elm_object_part_text_set(as, \textcolor{stringliteral}{"right"}, \textcolor{stringliteral}{"Reject"});
   elm\_object\_text\_set(as, \textcolor{stringliteral}{"Go"});
   evas\_object\_smart\_callback\_add(as, \textcolor{stringliteral}{"pos\_changed"},
                                  \_position\_change\_magnetic\_cb, NULL);
   evas\_object\_smart\_callback\_add(as, \textcolor{stringliteral}{"selected"}, \_pos\_selected\_cb, NULL);
   evas\_object\_show(as);
   elm\_box\_pack\_end(bx, as);

   as = elm_actionslider_add(win);
   evas\_object\_size\_hint\_weight\_set(as, EVAS\_HINT\_EXPAND, 0);
   evas\_object\_size\_hint\_align\_set(as, EVAS\_HINT\_FILL, 0);
   elm\_actionslider\_indicator\_pos\_set(as, ELM\_ACTIONSLIDER\_LEFT);
   elm\_actionslider\_magnet\_pos\_set(as, ELM\_ACTIONSLIDER\_ALL);
   elm_object_part_text_set(as, \textcolor{stringliteral}{"left"}, \textcolor{stringliteral}{"Left"});
   elm_object_part_text_set(as, \textcolor{stringliteral}{"center"}, \textcolor{stringliteral}{"Center"});
   elm_object_part_text_set(as, \textcolor{stringliteral}{"right"}, \textcolor{stringliteral}{"Right"});
   elm\_object\_text\_set(as, \textcolor{stringliteral}{"Go"});
   evas\_object\_smart\_callback\_add(as, \textcolor{stringliteral}{"selected"}, \_pos\_selected\_cb, NULL);
   evas\_object\_show(as);
   elm\_box\_pack\_end(bx, as);

   as = elm_actionslider_add(win);
   evas\_object\_size\_hint\_weight\_set(as, EVAS\_HINT\_EXPAND, 0);
   evas\_object\_size\_hint\_align\_set(as, EVAS\_HINT\_FILL, 0);
   elm\_actionslider\_indicator\_pos\_set(as, ELM\_ACTIONSLIDER\_CENTER);
   elm\_actionslider\_magnet\_pos\_set(as, ELM\_ACTIONSLIDER\_CENTER);
   elm_object_part_text_set(as, \textcolor{stringliteral}{"left"}, \textcolor{stringliteral}{"Enable"});
   elm_object_part_text_set(as, \textcolor{stringliteral}{"center"}, \textcolor{stringliteral}{"Magnet"});
   elm_object_part_text_set(as, \textcolor{stringliteral}{"right"}, \textcolor{stringliteral}{"Disable"});
   evas\_object\_smart\_callback\_add(as, \textcolor{stringliteral}{"pos\_changed"},
                                  \_magnet\_enable\_disable\_cb, NULL);
   evas\_object\_smart\_callback\_add(as, \textcolor{stringliteral}{"selected"}, \_pos\_selected\_cb, NULL);
   evas\_object\_show(as);
   elm\_box\_pack\_end(bx, as);

   evas\_object\_resize(win, 320, 400);
   evas\_object\_show(win);

   elm_run();
   \textcolor{keywordflow}{return} 0;
\}

\end{DoxyCodeInclude}


To be able to create our actionsliders we need to do some setup, but this isn\textquotesingle{}t really relevant here, so if you want to know about that go \hyperlink{group__Win}{here}.

With all that boring stuff out of the way we can proceed to creating some actionsliders.~\newline
All actionsliders are created the same way\+: 
\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}
 Next we must choose where the indicator starts, and for this one we choose the right, and set the right as magnetic\+: 
\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


We then set the labels for the left and right, passing N\+U\+LL as an argument to any of the labels makes that position have no label. 
\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


Furthermore we mark both left and right as enabled positions, if we didn\textquotesingle{}t do this all three positions would be enabled\+: 
\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


Having the enabled positions we now add a smart callback to change which position is magnetic, so that only the last selected position is magnetic\+: 
\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


And finally we set our printing callback and show the actionslider\+: 
\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


For our next actionslider we are going to do much as we did for the previous except we are going to have the center as the magnet(and not change it)\+: 
\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


And another actionslider, in this one the indicator starts on the left. It has labels only in the center and right, and both positions are magnetic. Because the left doesn\textquotesingle{}t have a label and is not magnetic once the indicator leaves it can\textquotesingle{}t return\+: 
\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}
 \begin{DoxyNote}{Note}
The greyed out area is a \hyperlink{group__Styles}{style}.
\end{DoxyNote}
And now an actionslider with a label in the indicator, and whose magnet properties change based on what was last selected\+: 
\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}
 \begin{DoxyNote}{Note}
The greyed out area is a \hyperlink{group__Styles}{style}.
\end{DoxyNote}
We are almost done, this next one is just an actionslider with all positions magnetized and having every possible label\+: 
\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


And for our last actionslider we have one that turns the magnetic property on and off\+: 
\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


The example will look like this\+:

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


See the full source code \hyperlink{actionslider_example_01}{here} 