Can I change the image file of an existing Evas_Object?

228 Views Asked by At

I am developing a watch face with Tizen Native using the EFL libraries. After creating many objects with:

Evas_Object *view_create_parts(Evas_Object *parent, const char *image_path,
    int position_x, int position_y, int size_w, int size_h) {
    Evas_Object *parts = NULL;

    parts = elm_image_add(parent);

    elm_image_file_set(parts, image_path, NULL);

    evas_object_move(parts, position_x, position_y);
    evas_object_resize(parts, size_w, size_h);

    evas_object_show(parts);

    return parts;
}

I would like to change the image of some of the existing objects later on as needed. Is this possible? I know that I could also load all possible variants as individual objects and show/hide the objects accordingly. But I find it way simpler and elegant to just change the image of an existing object. Plus, this probably uses less resources too.

I tried to do this:

elm_image_file_set(<part_I_want_to_change_its_image>, "images/newimage.png", NULL));

But instead of changing to the correct image, the object just disappears. Any ideas?

3

There are 3 best solutions below

0
On BEST ANSWER

I finally found out what I was doing wrong. I was not aware of how the image path has to be formed. Nonworking method:

elm_image_file_set(s_info.hand_hour, "images/new_image.png", NULL);

Working method:

char image_path[PATH_MAX] = { 0, };
data_get_resource_path("images/new_image.png", image_path, sizeof(image_path));
elm_image_file_set(s_info.hand_hour, image_path, NULL);
0
On

In order for someone to be able to follow, I am testing this on one of the included samples, the "Chronograph Watch". In the file view.c there is the function view_chronograph_create_parts(). Here, all I do is to change the code from:

case PARTS_TYPE_HANDS_HOUR:
    s_info.hand_hour = part; // at this point, the image is already set
    break;

to:

case PARTS_TYPE_HANDS_HOUR:
    s_info.hand_hour = part; // at this point, the image is already set

    elm_image_file_set(s_info.hand_hour, "images/chrono_hand_min.png", NULL);

    // I tried these two lines as well, but no change
    evas_object_move(s_info.hand_hour, 166, 0);
    evas_object_resize(s_info.hand_hour, 28, 360);

    break;

The idea is to change the image of the hour hand after it was set initially, to see if elm_image_file_set() is successfully changing the image. But all I get is the hour hand being not visible at all.

1
On

Yes, elm_image supports image conversion. But the normal image is included in the container widget or works as an area of the layout, but in your example, it seems to be an isolated and drawn image on the canvas.

In this case, if the image file is changed, the old geometry is meaningless, so you need to set a new geometry value. do the below action after elm_image_file_set called.

evas_object_move(parts, position_x, position_y);
evas_object_resize(parts, size_w, size_h);