Languages

Menu
Sites
Language
Set icon in a circle button

Hello to all,

   I a trying to make a cercle button with a png icon image, well, I was cheching the forum and I didnt fount too much, and the few code that I found was not working, I can make a circle button but never shows the image, any one did before? Thanks, this is my code:

Evas_Object *ic;
    char bt_info_img[PATH_MAX];
    ic = elm_image_add(ad->btn_info);
    app_get_resource("info.png", bt_info_img, (int)PATH_MAX);
    elm_image_file_set(ic, bt_info_img, NULL);
    elm_image_resizable_set(ic, EINA_TRUE, EINA_TRUE);
    elm_object_part_content_set(ad->btn_info, "icon", ic);
    evas_object_size_hint_min_set(ad->btn_info, ELM_SCALE_SIZE(150), ELM_SCALE_SIZE(58));
       // evas_object_smart_callback_add(btn, "clicked", btn_clicked_cb, (void *)4);

    ad->btn_info = elm_button_add(table);

    evas_object_smart_callback_add(ad->btn_info, "clicked", btn_info_clicked_cb, ad);

    elm_table_pack(table, ad->btn_info,0,0,2,1);
    evas_object_show(ad->btn_info);
    evas_object_show(ic);
    //evas_object_color_set(ad->btn_info, 0, 0, 0, 128);
    elm_object_style_set(ad->btn_info,"circle");

View Selected Answer

Responses

4 Replies
Mark as answer
Shaswati Saha

You may try to do this in the following way. Please have a look.

Evas_Object *table = elm_table_add(ad->win);
evas_object_size_hint_weight_set(table, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
elm_object_content_set(ad->conform,table);
evas_object_show(table);


ad->button = elm_button_add(ad->conform);
evas_object_size_hint_weight_set(ad->button,0.0,1.0);
evas_object_size_hint_align_set(ad->button,-1.0,1.0);
elm_object_style_set(ad->button, "circle");
elm_object_text_set(ad->button,"Click Me!");
evas_object_show(ad->button);
elm_table_pack(table, ad->button, 3, 1, 1, 1);

Evas_Object *ic;
ic = elm_icon_add(ad->button);
elm_image_file_set(ic,ICON_DIR"/img.png",NULL);
elm_object_part_content_set(ad->button,"icon",ic);
evas_object_show(ic);

I've defined the macro ICON_DIR like below as I've created a folder named "images" in the res dir and kept the png file inside it.

#define ICON_DIR "/opt/usr/apps/org.example.button_image/res/images"

 

Carlos Dominguez

Its works, but i dont know why... should be the order of commands because I was doing the same but different order. But works!

GEUNSOO KIM

the reason is because you added the image to the button which is not created yet.. (you created the button later...)

Carlos Dominguez

Thats true! Thanks!