

This example shows how to change the color of a rectangle using a color selector. We aren't going to explain a lot of the code since it's the usual setup code\-: 
\begin{DoxyCodeInclude}
\textcolor{comment}{//Compile with:}
\textcolor{comment}{//gcc -g colorselector\_example\_01.c -o colorselector\_example\_01 `pkg-config --cflags --libs elementary`}

\textcolor{preprocessor}{#include <Elementary.h>}

\textcolor{keyword}{static} \textcolor{keywordtype}{void} \_change\_color(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info);
\textcolor{keyword}{static} \textcolor{keywordtype}{void} \_colorpalette\_clicked\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info);
\textcolor{keyword}{static} \textcolor{keywordtype}{void} \_colorpalette\_longpressed\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info);

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

   elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);

   win = elm_win_util_standard_add(\textcolor{stringliteral}{"color selector"}, \textcolor{stringliteral}{"Color selector"});
   elm_win_autodel_set(win, EINA\_TRUE);

   bx = elm_box_add(win);
   evas\_object\_size\_hint\_weight\_set(bx, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   elm_win_resize_object_add(win, bx);
   evas\_object\_show(bx);

   fr = elm_frame_add(win);
   evas\_object\_size\_hint\_weight\_set(fr, 1.0, 0.5);
   evas\_object\_size\_hint\_align\_set(fr, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   elm\_object\_text\_set(fr, \textcolor{stringliteral}{"Color View"});
   elm_box_pack_end(bx, fr);
   evas\_object\_show(fr);

   rect = evas\_object\_rectangle\_add(evas\_object\_evas\_get(win));
   elm\_object\_content\_set(fr, rect);
   evas\_object\_color\_set(rect, 255, 90, 18, 255);
   evas\_object\_show(rect);

\end{DoxyCodeInclude}


Now that we have a window with background and a rectangle we can create our color\-\_\-selector 
\begin{DoxyCodeInclude}

   fr = elm_frame_add(win);
   evas\_object\_size\_hint\_weight\_set(fr, 1.0, 0.5);
   evas\_object\_size\_hint\_align\_set(fr, EVAS\_HINT\_FILL, EVAS\_HINT\_FILL);
   elm\_object\_text\_set(fr, \textcolor{stringliteral}{"Color Selector"});
   elm_box_pack_end(bx, fr);
   evas\_object\_show(fr);

   cs = elm_colorselector_add(win);

\end{DoxyCodeInclude}


Now colors can be loaded to color selector's palette by setting the palette name 
\begin{DoxyCodeInclude}
   elm_colorselector_palette_name_set(cs, \textcolor{stringliteral}{"painting"});
   evas\_object\_size\_hint\_weight\_set(cs, EVAS\_HINT\_EXPAND, 0.0);
   evas\_object\_size\_hint\_align\_set(cs, EVAS\_HINT\_FILL, 0.0);
   elm_colorselector_color_set(cs, 255, 90, 18, 255);
   evas\_object\_show(cs);

\end{DoxyCodeInclude}


Next we ask to be notified whenever the color changes on selector\-: 
\begin{DoxyCodeInclude}
   evas\_object\_smart\_callback\_add(cs, \textcolor{stringliteral}{"changed"}, \_change\_color, rect);

\end{DoxyCodeInclude}


Next we ask to be notified whenever the color item is selected and longpressed\-: 
\begin{DoxyCodeInclude}
   evas\_object\_smart\_callback\_add(cs, \textcolor{stringliteral}{"color,item,selected"}, \_colorpalette\_clicked\_cb, rect);
   evas\_object\_smart\_callback\_add(cs, \textcolor{stringliteral}{"color,item,longpressed"}, \_colorpalette\_longpressed\_cb, rect);

\end{DoxyCodeInclude}


We add some more code to the usual setup code\-: 
\begin{DoxyCodeInclude}
   elm\_object\_content\_set(fr, cs);

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

   elm_run();
   elm_shutdown();

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

\end{DoxyCodeInclude}


now get to the \char`\"{}changed\char`\"{} callback that sets the color of the rectangle\-: 
\begin{DoxyCodeInclude}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_change\_color(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   \textcolor{keywordtype}{int} r, g, b, a;
   elm_colorselector_color_get(obj, &r, &g, &b, &a);
   \textcolor{comment}{// ensure colors are pre-multiplied by alpha}
   evas\_color\_argb\_premul(a, &r, &g, &b);
   evas\_object\_color\_set(data, r, g, b, a);
\}

\end{DoxyCodeInclude}


And now get to the \char`\"{}color,item,selected\char`\"{} callback that sets the color of the rectangle\-: 
\begin{DoxyCodeInclude}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_colorpalette\_clicked\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   \textcolor{keywordtype}{int} r = 0, g = 0, b = 0 ,a = 0;
   Elm_Object_Item *color\_it = (Elm_Object_Item *) event\_info;
   elm_colorselector_palette_item_color_get(color\_it, &r, &g, &b, &a);
   \textcolor{comment}{// ensure colors are pre-multiplied by alpha}
   evas\_color\_argb\_premul(a, &r, &g, &b);
   evas\_object\_color\_set(data, r, g, b, a);
\}

\end{DoxyCodeInclude}


And now get to the \char`\"{}color,item,longpressed\char`\"{} callback that gets and displays the color of the rectangle\-: 
\begin{DoxyCodeInclude}

\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_colorpalette\_longpressed\_cb(\textcolor{keywordtype}{void} *data, Evas\_Object *obj, \textcolor{keywordtype}{void} *event\_info)
\{
   \textcolor{keywordtype}{int} r = 0,g = 0,b = 0 ,a = 0;
   Elm_Object_Item *color\_it = (Elm_Object_Item *) event\_info;
   elm_colorselector_palette_item_color_get(color\_it, &r, &g, &b, &a);
   printf(\textcolor{stringliteral}{"\(\backslash\)ncolor = %d-%d-%d-%d\(\backslash\)n"}, r, g, b, a);
\}

\end{DoxyCodeInclude}


This example will look like this\-:

 
\begin{DoxyImage}
\includegraphics{screenshots/colorselector_example_01}
\caption{width=}
\end{DoxyImage}
 