

This example shows how to change the color of a rectangle using a color selector. We aren\textquotesingle{}t going to explain a lot of the code since it\textquotesingle{}s the usual setup code\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{comment}{//Compile with:}}
\DoxyCodeLine{\textcolor{comment}{//gcc -\/g colorselector\_example\_01.c -\/o colorselector\_example\_01 `pkg-\/config -\/-\/cflags -\/-\/libs elementary`}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{preprocessor}{\#include <Elementary.h>}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static} \textcolor{keywordtype}{void} \_change\_color(\textcolor{keywordtype}{void} *data, \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *obj, \textcolor{keywordtype}{void} *event\_info);}
\DoxyCodeLine{\textcolor{keyword}{static} \textcolor{keywordtype}{void} \_colorpalette\_clicked\_cb(\textcolor{keywordtype}{void} *data, \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *obj, \textcolor{keywordtype}{void} *event\_info);}
\DoxyCodeLine{\textcolor{keyword}{static} \textcolor{keywordtype}{void} \_colorpalette\_longpressed\_cb(\textcolor{keywordtype}{void} *data, \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *obj, \textcolor{keywordtype}{void} *event\_info);}
\DoxyCodeLine{}
\DoxyCodeLine{EAPI\_MAIN \textcolor{keywordtype}{int}}
\DoxyCodeLine{elm\_main(\textcolor{keywordtype}{int} argc \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, \textcolor{keywordtype}{char} **argv \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}})}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *win, *cs, *rect, *bx, *fr;}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__General_ga7a05f37fd3a019da5e26c5fc91fcd937}{elm\_policy\_set}}(\mbox{\hyperlink{group__Elm__General_ggaa16f3378ecdbf660fa378402e3c5a0a9a02fadb6faada04b19d0fa42c11a8d32a}{ELM\_POLICY\_QUIT}}, \mbox{\hyperlink{group__Elm__General_gga46af37e6ac2c406321060be827117196abbe0962d88ae12afe1a173da881f56cd}{ELM\_POLICY\_QUIT\_LAST\_WINDOW\_CLOSED}});}
\DoxyCodeLine{}
\DoxyCodeLine{   win = \mbox{\hyperlink{group__Elm__Win_gac75d7752662fab73d6420706ce5be996}{elm\_win\_util\_standard\_add}}(\textcolor{stringliteral}{"color selector"}, \textcolor{stringliteral}{"Color selector"});}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__Win_ga9a16a2f8c9fd5b6e9203ed9dcb53ea8b}{elm\_win\_autodel\_set}}(win, \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}});}
\DoxyCodeLine{}
\DoxyCodeLine{   bx = \mbox{\hyperlink{group__Elm__Box_ga3d0998b60ada633bacfa8869a921cfd7}{elm\_box\_add}}(win);}
\DoxyCodeLine{   evas\_object\_size\_hint\_weight\_set(bx, \mbox{\hyperlink{Evas__Common_8h_aa47c85083d3dae0111c21ec49359306a}{EVAS\_HINT\_EXPAND}}, \mbox{\hyperlink{Evas__Common_8h_aa47c85083d3dae0111c21ec49359306a}{EVAS\_HINT\_EXPAND}});}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__Win_ga505d6bd217e5ee01e82b548ec35986eb}{elm\_win\_resize\_object\_add}}(win, bx);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}}(bx);}
\DoxyCodeLine{}
\DoxyCodeLine{   fr = \mbox{\hyperlink{group__Elm__Frame_ga02fadf955eebe3737e076b08ef81b159}{elm\_frame\_add}}(win);}
\DoxyCodeLine{   evas\_object\_size\_hint\_weight\_set(fr, 1.0, 0.5);}
\DoxyCodeLine{   evas\_object\_size\_hint\_align\_set(fr, \mbox{\hyperlink{Evas__Common_8h_aecbac710f36d52911fc34dcdaf8e729c}{EVAS\_HINT\_FILL}}, \mbox{\hyperlink{Evas__Common_8h_aecbac710f36d52911fc34dcdaf8e729c}{EVAS\_HINT\_FILL}});}
\DoxyCodeLine{   elm\_object\_text\_set(fr, \textcolor{stringliteral}{"Color View"});}
\DoxyCodeLine{   elm\_box\_pack\_end(bx, fr);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}}(fr);}
\DoxyCodeLine{}
\DoxyCodeLine{   rect = \mbox{\hyperlink{group__Evas__Object__Rectangle_ga4d80fc32ad1cac28428cebd65d746751}{evas\_object\_rectangle\_add}}(evas\_object\_evas\_get(win));}
\DoxyCodeLine{   elm\_object\_content\_set(fr, rect);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_gae34bdcfd7f5100151f6ea8ef4a392949}{evas\_object\_color\_set}}(rect, 255, 90, 18, 255);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{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}{0}
\DoxyCodeLine{}
\DoxyCodeLine{   fr = \mbox{\hyperlink{group__Elm__Frame_ga02fadf955eebe3737e076b08ef81b159}{elm\_frame\_add}}(win);}
\DoxyCodeLine{   evas\_object\_size\_hint\_weight\_set(fr, 1.0, 0.5);}
\DoxyCodeLine{   evas\_object\_size\_hint\_align\_set(fr, \mbox{\hyperlink{Evas__Common_8h_aecbac710f36d52911fc34dcdaf8e729c}{EVAS\_HINT\_FILL}}, \mbox{\hyperlink{Evas__Common_8h_aecbac710f36d52911fc34dcdaf8e729c}{EVAS\_HINT\_FILL}});}
\DoxyCodeLine{   elm\_object\_text\_set(fr, \textcolor{stringliteral}{"Color Selector"});}
\DoxyCodeLine{   elm\_box\_pack\_end(bx, fr);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}}(fr);}
\DoxyCodeLine{}
\DoxyCodeLine{   cs = \mbox{\hyperlink{group__Elm__Colorselector_ga27ebfd6da68b578e5f462eb4e71ce372}{elm\_colorselector\_add}}(win);}

\end{DoxyCodeInclude}


Now colors can be loaded to color selector\textquotesingle{}s palette by setting the palette name 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{   elm\_colorselector\_palette\_name\_set(cs, \textcolor{stringliteral}{"painting"});}
\DoxyCodeLine{   evas\_object\_size\_hint\_weight\_set(cs, \mbox{\hyperlink{Evas__Common_8h_aa47c85083d3dae0111c21ec49359306a}{EVAS\_HINT\_EXPAND}}, 0.0);}
\DoxyCodeLine{   evas\_object\_size\_hint\_align\_set(cs, \mbox{\hyperlink{Evas__Common_8h_aecbac710f36d52911fc34dcdaf8e729c}{EVAS\_HINT\_FILL}}, 0.0);}
\DoxyCodeLine{   elm\_colorselector\_color\_set(cs, 255, 90, 18, 255);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}}(cs);}

\end{DoxyCodeInclude}


Next we ask to be notified whenever the color changes on selector\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Smart__Object__Group_ga18a8b179f94d21b2b09e19db11741061}{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}{0}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Smart__Object__Group_ga18a8b179f94d21b2b09e19db11741061}{evas\_object\_smart\_callback\_add}}(cs, \textcolor{stringliteral}{"color,item,selected"}, \_colorpalette\_clicked\_cb, rect);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Smart__Object__Group_ga18a8b179f94d21b2b09e19db11741061}{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}{0}
\DoxyCodeLine{   elm\_object\_content\_set(fr, cs);}
\DoxyCodeLine{}
\DoxyCodeLine{   evas\_object\_resize(win, 320, 480);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}}(win);}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__General_gadf2553f83e6b0b9c7fbe054019a664a1}{elm\_run}}();}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{return} 0;}
\DoxyCodeLine{\}}
\DoxyCodeLine{\mbox{\hyperlink{group__Elm__General_ga50fe52d513f7e89c9c770afd76de7ad9}{ELM\_MAIN}}()}

\end{DoxyCodeInclude}


now get to the \char`\"{}changed\char`\"{} callback that sets the color of the rectangle\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static} \textcolor{keywordtype}{void}}
\DoxyCodeLine{\_change\_color(\textcolor{keywordtype}{void} *data, \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *obj, \textcolor{keywordtype}{void} *event\_info \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}})}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \textcolor{keywordtype}{int} r, g, b, a;}
\DoxyCodeLine{   elm\_colorselector\_color\_get(obj, \&r, \&g, \&b, \&a);}
\DoxyCodeLine{   \textcolor{comment}{// ensure colors are pre-\/multiplied by alpha}}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Utils_gac02bf3973675ae7591b9f34deef1554f}{evas\_color\_argb\_premul}}(a, \&r, \&g, \&b);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_gae34bdcfd7f5100151f6ea8ef4a392949}{evas\_object\_color\_set}}(data, r, g, b, a);}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}


And now get to the \char`\"{}color,item,selected\char`\"{} callback that sets the color of the rectangle\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static} \textcolor{keywordtype}{void}}
\DoxyCodeLine{\_colorpalette\_clicked\_cb(\textcolor{keywordtype}{void} *data, \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *obj \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}},}
\DoxyCodeLine{                         \textcolor{keywordtype}{void} *event\_info)}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \textcolor{keywordtype}{int} r = 0, g = 0, b = 0 ,a = 0;}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__General_ga13a0c231414b86e62f68afe3c6fb462b}{Elm\_Object\_Item}} *color\_it = (\mbox{\hyperlink{group__Elm__General_ga13a0c231414b86e62f68afe3c6fb462b}{Elm\_Object\_Item}} *) event\_info;}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__Colorselector_ga9058fd3f763834982fc00c1cc66c1288}{elm\_colorselector\_palette\_item\_color\_get}}(color\_it, \&r, \&g, \&b, \&a);}
\DoxyCodeLine{   \textcolor{comment}{// ensure colors are pre-\/multiplied by alpha}}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Utils_gac02bf3973675ae7591b9f34deef1554f}{evas\_color\_argb\_premul}}(a, \&r, \&g, \&b);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_gae34bdcfd7f5100151f6ea8ef4a392949}{evas\_object\_color\_set}}(data, r, g, b, a);}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}


And now get to the \char`\"{}color,item,longpressed\char`\"{} callback that gets and displays the color of the rectangle\+: 
\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static} \textcolor{keywordtype}{void}}
\DoxyCodeLine{\_colorpalette\_longpressed\_cb(\textcolor{keywordtype}{void} *data \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *obj \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}},}
\DoxyCodeLine{                             \textcolor{keywordtype}{void} *event\_info)}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \textcolor{keywordtype}{int} r = 0,g = 0,b = 0 ,a = 0;}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__General_ga13a0c231414b86e62f68afe3c6fb462b}{Elm\_Object\_Item}} *color\_it = (\mbox{\hyperlink{group__Elm__General_ga13a0c231414b86e62f68afe3c6fb462b}{Elm\_Object\_Item}} *) event\_info;}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__Colorselector_ga9058fd3f763834982fc00c1cc66c1288}{elm\_colorselector\_palette\_item\_color\_get}}(color\_it, \&r, \&g, \&b, \&a);}
\DoxyCodeLine{   printf(\textcolor{stringliteral}{"\(\backslash\)ncolor = \%d-\/\%d-\/\%d-\/\%d\(\backslash\)n"}, r, g, b, a);}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}


This example will look like this\+:

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