Languages

Menu
Sites
Language
How to add dynamic text box in UI using EFL???

I want to add dynamic text box on button click event in my application using EFL.
I tried elm_box_pack_before and elm_box_pack_after API in my code but it's not working.
 

        ad->phone = elm_entry_add(ad->box);
        elm_object_part_text_set(ad->phone, "elm.guide","Enter Phone Number");
        elm_entry_input_panel_layout_set(ad->phone,ELM_INPUT_PANEL_LAYOUT_NUMBERONLY);
        my_box_pack(ad->box,ad->phone,1.0,0.0,-1.0,0.5);

        ad->btn_phone = elm_button_add(ad->box);
        elm_object_text_set(ad->btn_phone, "add no");
        my_box_pack(ad->box, ad->btn_phone, 1.0, 0.0, -1.0, 0.0);
        evas_object_smart_callback_add(ad->btn_phone, "clicked", add_number_cb, ad);
void
add_number_cb(void *data, Evas_Object * obj, void *event_info)
{
    appdata_s *ad=data;
	Evas_Object *entry=elm_entry_add(ad->box);
	elm_object_part_text_set(entry,"elm.guide","enter mobile no");
	elm_box_pack_before(ad->box,entry,ad->btn_phone);
	evas_object_show(entry);
}

 

View Selected Answer

Responses

9 Replies
GEUNSOO KIM

I think you missed some steps for the 'enter mobile no' entry when you add it in 'add_number_cb()'.

before showing any elm control, the control size should be specified or be possible to guess out its size.

just like other elm contorls do in my_box_pack().

So you may need to call evas_object_size_hint_weight_set() and evas_object_size_hint_align_set() in most cases.

(except using EDJ or layout. But in this case, the EDJ or layout should hold the same info too..)

I cannot sure you should call 'elm_object_content_set()' or not. you'd better find out yourself.

good luck.

 

 

Shaswati Saha

You may use the code snippet below. Here two lables are used for show and hide purpose and one image obj is used showed and made hidden accordingly.

ad->box = elm_box_add(ad->conform);
evas_object_move(ad->box, 20, 120);
evas_object_show(ad->box);


ad->show = elm_label_add(ad->box);
elm_object_text_set(ad->show, "<align=center>Show</align>");
evas_object_smart_callback_add(ad->show, "clicked", show, ad);
evas_object_show(ad->show);
elm_box_pack_end(ad->box, ad->show);

ad->hide = elm_label_add(ad->box);
elm_object_text_set(ad->hide, "<align=center>Hide</align>");
evas_object_smart_callback_add(ad->hide, "clicked", hide, ad);
evas_object_show(ad->hide);
elm_box_pack_end(ad->box, ad->hide);

Callbacks:
 

static void show(void *data, Evas_Object *obj, void *event_info)
{
	appdata_s *ad = data;
	char buf[PATH_MAX];
	ad->img = elm_image_add(ad->box);
	snprintf(buf, sizeof(buf), "%s/Tizen.png", ICON_DIR);
	elm_image_file_set(ad->img, buf, NULL);
	evas_object_size_hint_min_set(ad->img, 200, 200);
	evas_object_show(ad->img);
	elm_box_pack_end(ad->box, ad->img);
}

static void hide(void *data, Evas_Object *obj, void *event_info)
{
	appdata_s *ad = data;
	evas_object_hide(ad->img);
}

My appdata structure:

typedef struct appdata {
    Evas_Object *win;
	Evas_Object *conform;
	Evas_Object *show;
	Evas_Object *hide;
	Evas_Object *box;
	Evas_Object * img
} appdata_s;

It works in my case. Hope it'll help!

bhoomika rathod

Actually i am working on contact application in which i need to add multiple phone numbers. And we don't have specific count of number.
Because it depends upon user. 

Shaswati Saha

In that case, please try this one:

ad->show = elm_label_add(ad->box);
elm_object_text_set(ad->show, "<align=center>Create New Contact</align>");
evas_object_smart_callback_add(ad->show, "clicked", ad_new_contact, ad);
evas_object_show(ad->show);
elm_box_pack_end(ad->box, ad->show);

Callback:

static void ad_new_contact(void *data, Evas_Object *obj, void *event_info)
{
	appdata_s *ad = data;

	Evas_Object *entry = elm_entry_add(ad->box);
	elm_entry_single_line_set(entry, EINA_TRUE);
	elm_entry_entry_insert(entry, "New Entry");
	elm_object_part_text_set(entry, "elm.guide", "Input Text");
	evas_object_show(entry);
	elm_box_pack_end(ad->box, entry);
}

P.S. I guess, in your callback you'd missed below line:

evas_object_show(entry);

 

Dinal Jivani

Hi Shaswati Saha , how can i add the entry field dynamically above the AddButton (ad->AddBtn

This the the Code i Wrote 

ad->box = elm_box_add(ad->conform);
evas_object_size_hint_weight_set(ad->box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
elm_object_content_set(ad->conform, ad->box);
evas_object_show(ad->box);

ad->AddBtn=elm_button_add(ad->box);
elm_object_style_set(ad->AddBtn,"icon_expand_add");
evas_object_smart_callback_add(ad->AddBtn,"clicked",New_Entry_Phone,ad);
my_box_pack(ad->box,ad->AddBtn,1.0,0.0,-1.0,0.5);

Function on Click Of Button :

void
New_Entry_Phone(void *data, Evas_Object * obj, void *event_info)
{
    appdata_s *ad = data;

    Evas_Object *entry = elm_entry_add(ad->box);
	elm_entry_single_line_set(entry, EINA_TRUE);
	elm_entry_entry_insert(entry, "New Entry");
	elm_object_part_text_set(entry, "elm.guide", "Input Text");
	elm_box_pack_before(ad->box,entry,ad->AddBtn);
        evas_object_show(entry);
}

I want to add the Entry above the button itself ........

Mark as answer
Shaswati Saha

Please check my previous reply. I've shared a code snippet. Use that snippet as it is, just change below line of that snippet

elm_box_pack_end(ad->box, entry);

to below line:

elm_box_pack_before(ad->box, entry, ad->show);

It perfectly works in my case(check below image). 

 

 

Dinal Jivani

Thanks A Lot Shaswati Saha, That Helped Me Much :D

Shaswati Saha

Hi bhoomika rathod,

Did you find the solution you're expecting here? What's the status right now?

bhoomika rathod

yeah, it is working...thank you so much Shaswati Saha.