Languages

Menu
Sites
Language
Add icon into Box container, but cant see in UI

Hi, All

Please help to check my code. Seems it's not working, the icon image cant show on the UI.

Evas_Object*
create_aboutme_view(Evas_Object *parent)
{
    Evas_Object *sub_view, *box1, *box2, *box3;

	sub_view = elm_box_add(parent);
	evas_object_size_hint_weight_set(sub_view, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
	evas_object_size_hint_align_set(sub_view, EVAS_HINT_FILL, EVAS_HINT_FILL);

	box1 = elm_box_add(sub_view);
	elm_box_horizontal_set(box1, EINA_TRUE);
	elm_box_padding_set(box1, 16, 16);

	char filename[PATH_MAX];
    Evas_Object *ic = elm_icon_add(box1);
    snprintf(filename, sizeof(filename), "%s%s", ICON_DIR, "head_man72.png");
    elm_image_file_set(ic, filename, NULL);
    evas_object_size_hint_min_set(ic, 72, 72);
    evas_object_show(ic);
    elm_box_pack_start(box1, ic);

    evas_object_show(box1);
    elm_box_pack_end(sub_view, box1);

	box2 = elm_box_add(sub_view);
	evas_object_show(box2);
	elm_box_pack_end(sub_view, box2);

	box3 = elm_box_add(sub_view);
	evas_object_show(box3);
	elm_box_pack_end(sub_view, box3);

	evas_object_show(sub_view);

	return sub_view;
}

static void
tabbar_item_cb(void *data, Evas_Object *obj, void *event_info)
{
    appdata_s *ad = data;
	Elm_Object_Item *it;
	Evas_Object *sub_view;
	Eina_Bool b;
	const char *str = NULL;

	it = event_info;

	str = elm_object_item_text_get(it);

	if (str && !strcmp(str, "Message")) {
		//...
	}
	else if (str && !strcmp(str, "Friends")) {
		//...
	}
	else {
		sub_view = create_aboutme_view(ad->nf);
	}

	elm_object_content_set(ad->nf, sub_view);
}

 

Responses

7 Replies
Alex Ashirov

Hi,

This code snippet seems to be ok. What is type of ad->nf variable?

colin Rao

Hi Alex, 

Thanks! I've solved this issue, but I have another issue about the alignment in box container. others, the ad->nf is a instance of naviframe. 

As the source code, I want to make label2 to align to the left border of box3, but the actually result seems it was located in the center of box3. I don't know what's wrong in my code. Additional, I am not very farmiliar with the box layout. Many thanks for your help. ;) 

Evas_Object*
create_aboutme_view(Evas_Object *parent)
{
    Evas_Object *sub_view, *box1, *box2, *box3;
    int screen_size_w, screen_size_h;

    sub_view = elm_box_add(parent);
	evas_object_size_hint_weight_set(sub_view, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
	evas_object_size_hint_align_set(sub_view, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);

	box1 = elm_box_add(sub_view);
	evas_object_size_hint_weight_set(box1, EVAS_HINT_EXPAND, 0.4);
	evas_object_size_hint_align_set(box1, EVAS_HINT_FILL, EVAS_HINT_FILL);
	elm_box_horizontal_set(box1, EINA_TRUE);
	elm_box_padding_set(box1, 32, 16);
	elm_box_align_set(box1, 0.2, 0.5);

	char filename[PATH_MAX];
    Evas_Object *ic = elm_icon_add(box1);
    snprintf(filename, sizeof(filename), "%s%s", ICON_DIR, "head_man72.png");
    elm_image_file_set(ic, filename, NULL);
    evas_object_size_hint_min_set(ic, screen_size_h*0.2, screen_size_h*0.2);
    evas_object_show(ic);
    elm_box_pack_start(box1, ic);
	Evas_Object *label = elm_label_add(box1);
	elm_object_text_set(label, "Colin Rao");
	evas_object_show(label);
	elm_box_pack_end(box1, label);

    evas_object_show(box1);
    elm_box_pack_end(sub_view, box1);


	box2 = elm_box_add(sub_view);
	evas_object_size_hint_weight_set(box2, EVAS_HINT_EXPAND, 0.3);
	evas_object_size_hint_align_set(box2, EVAS_HINT_FILL, EVAS_HINT_FILL);
	evas_object_show(box2);
	elm_box_pack_end(sub_view, box2);

	box3 = elm_box_add(sub_view);
	evas_object_size_hint_weight_set(box3, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
	evas_object_size_hint_align_set(box3, EVAS_HINT_FILL, EVAS_HINT_FILL);
	elm_box_padding_set(box3, 16, 16);
	elm_box_align_set(box3, 0.2, 0.0);

	Evas_Object *label2 = elm_label_add(box3);
	elm_object_text_set(label2, "Logout");
	evas_object_show(label2);
	elm_box_pack_end(box3, label2);

	evas_object_show(box3);
	elm_box_pack_end(sub_view, box3);

	evas_object_show(sub_view);

	return sub_view;
}

 

colin Rao

Code update, please ignore the previous code. 

#include <system_info.h>
#include "main.h"

static void
get_system_info_int(char* key, int *value)
{
    int ret, val;
    ret = system_info_get_platform_int(key, &val);
    *value = val;
    if (ret != SYSTEM_INFO_ERROR_NONE)
	{
	    // Error handling
	}
	dlog_print(DLOG_INFO, LOG_TAG, "screen size %s : %d", key, val);
	return;
}

Evas_Object*
create_aboutme_view(Evas_Object *parent)
{
	Evas_Object *sub_view, *box1, *box2, *box3;
    int screen_size_w, screen_size_h;

    get_system_info_int("tizen.org/feature/screen.width", &screen_size_w);
    get_system_info_int("tizen.org/feature/screen.height", &screen_size_h);
    dlog_print(DLOG_INFO, LOG_TAG, "screen width is: %d", screen_size_w);
    dlog_print(DLOG_INFO, LOG_TAG, "screen height is: %d", screen_size_h);

    sub_view = elm_box_add(parent);
	evas_object_size_hint_weight_set(sub_view, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
	evas_object_size_hint_align_set(sub_view, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);

	box1 = elm_box_add(sub_view);
	evas_object_size_hint_weight_set(box1, EVAS_HINT_EXPAND, 0.4);
	evas_object_size_hint_align_set(box1, EVAS_HINT_FILL, EVAS_HINT_FILL);
	elm_box_horizontal_set(box1, EINA_TRUE);
	elm_box_padding_set(box1, 32, 16);
	elm_box_align_set(box1, 0.2, 0.5);

	char filename[PATH_MAX];
    Evas_Object *ic = elm_icon_add(box1);
    snprintf(filename, sizeof(filename), "%s%s", ICON_DIR, "head_man72.png");
    elm_image_file_set(ic, filename, NULL);
    evas_object_size_hint_min_set(ic, screen_size_h*0.2, screen_size_h*0.2);
    evas_object_show(ic);
    elm_box_pack_start(box1, ic);
	Evas_Object *label = elm_label_add(box1);
	elm_object_text_set(label, "Colin Rao");
	evas_object_show(label);
	elm_box_pack_end(box1, label);

    evas_object_show(box1);
    elm_box_pack_end(sub_view, box1);


	box2 = elm_box_add(sub_view);
	evas_object_size_hint_weight_set(box2, EVAS_HINT_EXPAND, 0.3);
	evas_object_size_hint_align_set(box2, EVAS_HINT_FILL, EVAS_HINT_FILL);
	evas_object_show(box2);
	elm_box_pack_end(sub_view, box2);

	box3 = elm_box_add(sub_view);
	evas_object_size_hint_weight_set(box3, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
	evas_object_size_hint_align_set(box3, EVAS_HINT_FILL, EVAS_HINT_FILL);
	elm_box_padding_set(box3, 16, 16);
	elm_box_align_set(box3, 0.2, 0.0);

	Evas_Object *label2 = elm_label_add(box3);
	elm_object_text_set(label2, "Logout");
	evas_object_show(label2);
	elm_box_pack_end(box3, label2);

	evas_object_show(box3);
	elm_box_pack_end(sub_view, box3);

	evas_object_show(sub_view);

	return sub_view;
}

 

Alex Ashirov

Hi,

Please try 

elm_box_align_set(box3, 0.0, 0.0);

instead of 

elm_box_align_set(box3, 0.2, 0.0);

Alex Ashirov

Also, you can try to minimize padding elm_box_padding_set(vbox, 0, 0);

colin Rao

I've tested, not working.

colin Rao

Seems use evas_object_size_hint_align_set(label, 0.0, 0.0); can fix this issue.