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:
#include <Elementary.h>
static void _change_color(
void *data,
Evas_Object *obj,
void *event_info);
static void _colorpalette_clicked_cb(
void *data,
Evas_Object *obj,
void *event_info);
static void _colorpalette_longpressed_cb(
void *data,
Evas_Object *obj,
void *event_info);
EAPI_MAIN int
elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
{
elm_object_text_set(fr, "Color View");
elm_box_pack_end(bx, fr);
elm_object_content_set(fr, rect);
Now that we have a window with background and a rectangle we can create our color_selector
elm_object_text_set(fr, "Color Selector");
elm_box_pack_end(bx, fr);
Now colors can be loaded to color selector's palette by setting the palette name
elm_colorselector_palette_name_set(cs, "painting");
elm_colorselector_color_set(cs, 255, 90, 18, 255);
Next we ask to be notified whenever the color changes on selector:
Next we ask to be notified whenever the color item is selected and longpressed:
We add some more code to the usual setup code:
elm_object_content_set(fr, cs);
return 0;
}
now get to the "changed" callback that sets the color of the rectangle:
static void
_change_color(
void *data,
Evas_Object *obj,
void *event_info EINA_UNUSED)
{
int r, g, b, a;
elm_colorselector_color_get(obj, &r, &g, &b, &a);
}
And now get to the "color,item,selected" callback that sets the color of the rectangle:
static void
_colorpalette_clicked_cb(
void *data,
Evas_Object *obj EINA_UNUSED,
void *event_info)
{
int r = 0, g = 0, b = 0 ,a = 0;
}
And now get to the "color,item,longpressed" callback that gets and displays the color of the rectangle:
static void
_colorpalette_longpressed_cb(
void *data EINA_UNUSED,
Evas_Object *obj EINA_UNUSED,
void *event_info)
{
int r = 0,g = 0,b = 0 ,a = 0;
printf("\ncolor = %d-%d-%d-%d\n", r, g, b, a);
}
This example will look like this: