Languages

Menu
Sites
Language
Using image in Watch Face

Hi,

I follow the tutorials to display an image using the `elm_image_add` function to put an image in background of the default Watch Face template provided in Tizen Studio 4.1

But I can't get to have it displayed. Here are the main parts of the application. The load_image receives the application `appdata` which has a reference to the `win` window object and also the `conform` conformant object. But the image is not displayed (note the `elm_image_file_set` is returning `true`.

#define IMG_DIR "/opt/usr/apps/com.example.app-id/res/images"

static bool load_image(appdata_s *ad) {
	char filename[PATH_MAX];
	snprintf(filename, sizeof(filename), "%s/jsc-watch-face.png", IMG_DIR);

	ad->image = elm_image_add(ad->conform);
	elm_image_file_set(ad->image, filename, NULL);
	elm_image_no_scale_set(ad->image, EINA_TRUE);
	elm_image_resizable_set(ad->image, EINA_TRUE, EINA_TRUE);
	elm_image_aspect_fixed_set(ad->image, EINA_TRUE);
	elm_image_fill_outside_set(ad->image, EINA_TRUE);
	elm_image_preload_disabled_set(ad->image, EINA_TRUE);
	return true;
}

Then in the `create_base_gui` function I added the Image section and call to `evas_object_show` to show the image:

static void create_base_gui(appdata_s *ad, int width, int height) {
    int ret;
	watch_time_h watch_time = NULL;

	/* Window */
	ret = watch_app_get_elm_win(&ad->win);
	if (ret != APP_ERROR_NONE) {
		dlog_print(DLOG_ERROR, LOG_TAG, "failed to get window. err = %d", ret);
		return;
	}

	evas_object_resize(ad->win, width, height);

	/* Conformant */
	ad->conform = elm_conformant_add(ad->win);
	evas_object_size_hint_weight_set(ad->conform, EVAS_HINT_EXPAND,
			EVAS_HINT_EXPAND);
	elm_win_resize_object_add(ad->win, ad->conform);
	evas_object_show(ad->conform);

	/* Label*/
	ad->label = elm_label_add(ad->conform);
	evas_object_resize(ad->label, width, height / 3);
	evas_object_move(ad->label, 0, height / 3);
	evas_object_show(ad->label);

	/* Image */
	load_image(ad);
	evas_object_show(ad->image);

	ret = watch_time_get_current_time(&watch_time);
	if (ret != APP_ERROR_NONE)
		dlog_print(DLOG_ERROR, LOG_TAG, "failed to get current time. err = %d",
				ret);

	update_watch(ad, watch_time, 0);
	watch_time_delete(watch_time);

	/* Show window after base gui is set up */
	evas_object_show(ad->win);
}

The image is not displayed. Anything I am doing wrong?

Edited by: Cédric Rochefolle on 24 Jan, 2021

Responses

1 Replies
Cédric Rochefolle

After more digging and following Lesson 18 of the dev-guide training I found I didn't bind the image to the conformant component. Here is the final part of the code:

/* Image */
    char filename[PATH_MAX];
	char *res_dir_path = app_get_resource_path();
	snprintf(filename, sizeof(filename), "%s%s", res_dir_path, "images/jsc-watch-face.png");
	free(res_dir_path);
	ad->image = elm_image_add(ad->conform);
	if (elm_image_file_set(ad->image, filename, NULL)) {
		dlog_print(DLOG_INFO, LOG_TAG, "set image [%s]", filename);
		 elm_image_no_scale_set(ad->image, EINA_TRUE);
		 elm_image_resizable_set(ad->image, EINA_TRUE, EINA_TRUE);
		 elm_image_aspect_fixed_set(ad->image, EINA_TRUE);
		 elm_image_fill_outside_set(ad->image, EINA_TRUE);
		 elm_image_preload_disabled_set(ad->image, EINA_TRUE);
		evas_object_show(ad->image);
		elm_object_content_set(ad->conform, ad->image);
	} else {
		dlog_print(DLOG_ERROR, LOG_TAG, "failed to set image [%s]", filename);
	}

Missing part was

elm_object_content_set(ad->conform, ad->image);

After adding it then it all works