This example shows how to create a prefs widget with Elementary, where some prefs item values are changed, some actions take place on an object different than the prefs widget (an Edge object).

With this new object, we\textquotesingle{}re also exemplifying the prefs S\+W\+A\+L\+L\+O\+W item type, as the Edje object is put inside the prefs widget\textquotesingle{}s viewport.

It also shows how subpages can be created using the prefs P\+A\+G\+E item type.

Explain step by step the .E\+D\+C file is out of scope, the source code can be found at \hyperlink{prefs_example_03_edc}{prefs\+\_\+example\+\_\+03.\+edc}\hypertarget{prefs_example_03_prefs-epc-03}{}\section{Creating items on E\+P\+C file}\label{prefs_example_03_prefs-epc-03}


First we\textquotesingle{}ll create prefs items on .E\+P\+C file that we\textquotesingle{}ll use later on the .C file.


\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


In the following part, we create an item of the P\+A\+G\+E type, that will create a subpage inside the main page. The source parameter is used to set which page will be used to fill the subpage, in this example, the page named \char`\"{}configpage\char`\"{} will be used.


\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


Now we create a S\+W\+A\+L\+L\+O\+W type item, that, as the name suggests, will swallow an Evas\+\_\+\+Object.


\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


Now we create the page that will be used to fill the item \char`\"{}config\char`\"{} of the main page. It has another two subpages and a S\+E\+P\+A\+R\+A\+T\+O\+R item arranged horizontally so we could achieve the desired layout.


\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}


Then we create the pages used by the \char`\"{}configpage\char`\"{} page, whose items were covered in \hyperlink{prefs_example_01}{Prefs Example 01} and \hyperlink{prefs_example_02}{Prefs Example 02}.


\begin{DoxyCodeInclude}

\end{DoxyCodeInclude}
\hypertarget{prefs_example_03_prefs-c-03}{}\section{Handling items on C File}\label{prefs_example_03_prefs-c-03}


Now we\textquotesingle{}re handling the .C file and first we\textquotesingle{}ll create a layout setting the edje file to after a prefs item swallows it.


\begin{DoxyCodeInclude}
   layout = elm_layout_add(win);
   elm_layout_file_set(layout, \textcolor{stringliteral}{"prefs\_example\_03.edj"}, \textcolor{stringliteral}{"prefs\_edje"});

\end{DoxyCodeInclude}


Here we create the prefs widget, add smart callbacks and create the prefs data handle.


\begin{DoxyCodeInclude}
   prefs = elm_prefs_add(win);
   evas\_object\_size\_hint\_weight\_set(prefs, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   evas\_object\_resize(prefs, WIDTH, HEIGHT);
   evas\_object\_show(prefs);

   evas\_object\_smart\_callback\_add(prefs, \textcolor{stringliteral}{"page,loaded"}, \_page\_loaded\_cb,
                                  layout);
   evas\_object\_smart\_callback\_add(prefs, \textcolor{stringliteral}{"item,changed"}, \_item\_changed\_cb,
                                  layout);

   elm_prefs_autosave_set(prefs, EINA\_TRUE);

   prefs\_data =
      elm_prefs_data_new(\textcolor{stringliteral}{"./prefs\_example\_03.cfg"}, NULL, EET\_FILE\_MODE\_READ\_WRITE);

   elm_prefs_file_set(prefs, \textcolor{stringliteral}{"prefs\_example\_03.epb"}, NULL);
   elm_prefs_data_set(prefs, prefs\_data);

\end{DoxyCodeInclude}


Now we \char`\"{}swallow\char`\"{} the layout into the S\+W\+A\+L\+L\+O\+W item of the prefs widget.


\begin{DoxyCodeInclude}
   elm_prefs_item_swallow(prefs, \textcolor{stringliteral}{"main:swal"}, layout);

\end{DoxyCodeInclude}


Page loaded and item changed callbacks will call update functions.

 
\begin{DoxyCodeInclude}
\_page\_loaded\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   Evas\_Object *layout = data;

   \_update(obj, layout);
\}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_item\_changed\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   \textcolor{keyword}{const} \textcolor{keywordtype}{char} *item = event\_info;
   Evas\_Object *layout = data;

   \textcolor{keywordflow}{if} (!strcmp(item, \textcolor{stringliteral}{"main:config:options:animation\_time"}))
     \_update\_animation\_time(obj, layout);
   \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (!strcmp(item, \textcolor{stringliteral}{"main:config:options:animation"}))
     \_update\_animation(obj, layout);
\}

\end{DoxyCodeInclude}


These update functions will be called in order to get the new value from the items and pass it as signal to edje handle it and affects on animation.

 
\begin{DoxyCodeInclude}
\_update(Evas\_Object *prefs, Evas\_Object *layout)
\{
   \_update\_animation(prefs, layout);
   \_update\_animation\_time(prefs, layout);
\}

\end{DoxyCodeInclude}


In this function we\textquotesingle{}ll get the checkbox (bool) value and start or stop the animation on edje.

 
\begin{DoxyCodeInclude}
\_update\_animation(Evas\_Object *prefs, Evas\_Object *layout)
\{
   Eina\_Value value;
   Eina\_Bool animation;

   elm_prefs_item_value_get(prefs, \textcolor{stringliteral}{"main:config:options:animation"}, &value);
   eina\_value\_get(&value, &animation);
   \textcolor{keywordflow}{if} (animation)
     elm\_layout\_signal\_emit(layout, \textcolor{stringliteral}{"start"}, \textcolor{stringliteral}{"animation"});
   \textcolor{keywordflow}{else}
     elm\_layout\_signal\_emit(layout, \textcolor{stringliteral}{"stop"}, \textcolor{stringliteral}{"animation"});
\}

\end{DoxyCodeInclude}


In this function we\textquotesingle{}ll get the slider (float item) value and send it as animation time to edje.


\begin{DoxyCodeInclude}
\_update\_animation\_time(Evas\_Object *prefs, Evas\_Object *layout)
\{
   Eina\_Value value;
   \textcolor{keywordtype}{float} animation\_time;
   Edje\_Message\_Float msg;

   elm_prefs_item_value_get(prefs, \textcolor{stringliteral}{"main:config:options:animation\_time"}, &value);
   eina\_value\_get(&value, &animation\_time);
   \textcolor{keywordflow}{if} (animation\_time < 0.01) animation\_time = 0.01;
   msg.val = animation\_time;
   edje\_object\_message\_send(elm\_layout\_edje\_get(layout), EDJE\_MESSAGE\_FLOAT,
                            MSG\_ID\_VEL, &msg);
\}

\end{DoxyCodeInclude}


Here we finish the example. The full source code can be found on \hyperlink{prefs_example_03_c}{prefs\+\_\+example\+\_\+03.\+c}, \hyperlink{prefs_example_03_epc}{prefs\+\_\+example\+\_\+03.\+epc} and \hyperlink{prefs_example_03_edc}{prefs\+\_\+example\+\_\+03.\+edc} 