Custom color selector

This code snippet demonstrates how to customize an elementary color selector widget. Our example color selector will consist of only three colors: red, green and blue.
static void colorselector_cb(void *data, Evas_Object *obj, void *event_info) {
	int r, g, b, a;
	Elm_Object_Item *color_it = (Elm_Object_Item *) event_info;
	elm_colorselector_palette_item_color_get(color_it, &r, &g, &b, &a);
	evas_color_argb_premul(a, &r, &g, &b);
	LOGI("Color changed to (RGBA): %d %d %d %d", r, g, b, a);
}

static Evas_Object *colorselector_test(Evas_Object *parent) {
	//create a color selector
	Evas_Object *colorselector = elm_colorselector_add(parent);
	elm_colorselector_mode_set(colorselector, ELM_COLORSELECTOR_ALL);

	//clear default values
	elm_colorselector_palette_clear(colorselector);

	//populate colorselector with custom color items
	elm_colorselector_palette_color_add(colorselector, 255, 0, 0, 200);
	elm_colorselector_palette_color_add(colorselector, 0, 255, 0, 200);
	elm_colorselector_palette_color_add(colorselector, 0, 0, 255, 200);

	//callback for set event
	evas_object_smart_callback_add(colorselector, "color,item,selected", colorselector_cb, NULL);
	evas_object_show(colorselector);

	return colorselector;
}

Responses

0 Replies