Languages

Menu
Sites
Language
Entry on popup focus

Hi all, following the varoius guides, i managed to create a popup with an Entry object in it, to grap the input.

The only problem is that i'm not able to give the focus to the entry, so when the popup appear with the keyboard, the user can enter directly its input without having to tap on the Entry object first. 

This is the code i used: 

Evas_Object *popup, *layout;
    popup = elm_popup_add(parent);
	elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
	evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
	elm_object_part_text_set(popup, "title,text", "Use energy");

	layout = elm_layout_add(popup);
	elm_layout_theme_set(layout, "layout", "drawer", "panel");
	evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
	elm_object_content_set(popup, layout);

	Evas_Object *entry = elm_entry_add(layout);
	set_number_on_entry(entry, 0);
	elm_entry_input_panel_layout_set(entry, ELM_INPUT_PANEL_LAYOUT_NUMBERONLY);
	elm_entry_input_panel_show(entry);
	elm_object_part_content_set(layout, "elm.swallow.content" , entry);
	dlog_print(DLOG_INFO, APP_TAG, elm_entry_entry_get(entry));
	container->entry = entry;
	Evas_Object *button1;
	button1 = elm_button_add(popup);
	elm_object_text_set(button1, "OK");
	elm_object_part_content_set(popup, "button1", button1);
	elm_object_style_set(button1, "popup");
	evas_object_smart_callback_add(button1, "clicked", ok_pressed_energy, container);

	/* Add a "Cancel" button to popup */
	button1 = elm_button_add(popup);
	elm_object_text_set(button1, "Cancel");
	elm_object_part_content_set(popup, "button2", button1);

	evas_object_smart_callback_add(button1, "clicked", dismissed_cb, popup);
	evas_object_smart_callback_add(popup, "dismissed", dismissed_cb, NULL);
	container->popup = popup;
	evas_object_show(popup);
	elm_object_focus_set(entry, EINA_TRUE);
	elm_entry_cursor_end_set(entry);

What i'm doing wrong?

I tried also to move the elm_object_focus_set and elm_cursor_end_set before the show (i moved it after, because i read the focus has to be set after the object has shown).

View Selected Answer

Responses

13 Replies
Yasin Ali

Hi,

I think you should first set the ability for an Elementary object to be focused using
this function :

void elm_object_focus_allow_set  ( Evas_Object *  obj, 
  Eina_Bool  enable 
 )

 obj -> The Elementary object to operate on 
 enable -> If EINA_TRUE the object can be focused, otherwise EINA_FALSE if it cannot (and on errors) 


Hope it'll help.

Ivan Gualandri

I tried to allow the focus, but is still not working.

I tried to give the focus just after the focus_allow function, just after the popup is showd, even tried to give the focus inside the focused event for the popup (that is being called), but the entry doesn't look like is focused.

Anyway what i'm trying to obtain is that when the dialog is displayed, along with the keyboard (i configured it to display also the keyboard), and the user enter any input, it goes directly to the entry, instead now the user need first to tap into the entry box, than he can enter the input. 

Is possible to do that? 

Yasin Ali
void  elm_entry_input_panel_enabled_set (Evas_Object *obj, Eina_Bool enabled)


This function sets the attribute to show the input panel automatically.

If keyboard shows automatically cursor may move at appropriate place.

Some changes in order of different functions calling may also help.

Ivan Gualandri

It is not working. 

What i also tried is to create a focus_callback on the popup dialog, then when the callback is called, it means that the dialog is shown, i tried to set the focus to the entry input there, but still not work. (during popup creation i added the line to enable the focus: p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px 'Eco Sans Mono'; color: #793d93}

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px 'Eco Sans Mono'; color: #793d93} span.s1 {color: #000000} span.Apple-tab-span {white-space:pre}

    elm_object_focus_allow_set(entry, EINA_TRUE);

 

The focus_cb function is: 

void focused_cb(void *data, Evas_Object *obj, void *event_info){
    popup_container *container = (popup_container*) data;
	dlog_print(DLOG_INFO, APP_TAG, "Focused");
	elm_object_focus_set(container->entry, EINA_TRUE);
}

Where the popup_container, contains the pointer to some of the data i need, included entry.

What i'm trying to achieve is simply that when the dialog is created the popup is open, along with the keyboard, and you can start typing directly updating the entry, instead what happens now is that the dialog is open, the keypad displayed, but the entry doesn't have the focus, then i have to tap on it, in order to start typing.

Yasin Ali

As you've used

elm_entry_cursor_end_set(entry); 

at last line

I think below function should be called earlier(and possibly related other functions if need, see link below).

void elm_entry_cursor_begin_set  ( Evas_Object *  obj ) 

Moves the cursor to the beginning of the entry.
Parameters: [in] obj The entry object 

Link related: https://developer.tizen.org/development/api-references/native-application?redirect=/dev-guide/2.3.0//org.tizen.native.mobile.apireference/group__Entry.html#ga4a6e3e654f36d227c5a5b80bf0f9cd22

Check Managing the Cursor Section: https://developer.tizen.org/ko/development/guides/native-application/user-interface/efl/ui-components/wearable-ui-components/entry?langredirect=1
See also Configuring the Entry Section

Ivan Gualandri

I've tried nearly everything that i can think of. 

I tried:

  • To move the cursor at the beginning, then select all, then move the cursor at the end, and finally setting the focus on the elemenet. Nothing
  • Tried to handle the focus callback, and set the position of the cursor and selecting the text from inside the handler. Nothing (and i checked that the focused callback function is called. Nothing.
  • I Tried to do the same as above, but set the focus after the popup show function is called. Nothing
  • And tried to move all the functions around the popup code, without success.

I've run out of ideas. My purpose is simply (And can be easily achieved on nearly every platform) popup displayed with keyboard, and if i enter text on the keyboard it  change the entry content, as soon the popup is displayed, without the need of tapping the entry first. 

 

Ivan Gualandri

Ok, still no solution to a problem that should be trivial. 

Reading the documentation i found: 

elm_entry_input_panel_enabled_set(entry, EINA_TRUE);

And it says: "

If true, the input panel is appeared when entry is clicked or has a focus." Tried it! I'm programmatically giving the focus to the entry once it is displayed with: 

elm_object_focus_set(entry, EINA_TRUE);

And i'm pretty sure it got the focus since that function:

void focused_cb(void *data, Evas_Object *obj, void *event_info){
    popup_container *container = (popup_container*) data;
	dlog_print(DLOG_INFO, APP_TAG, "Focused");
	elm_entry_select_all(container->entry);
	elm_entry_cursor_end_set(container->entry);
	//elm_object_focus_set(container->entry, EINA_TRUE);
}

 

Is being called, so it means it got the focus, but in that way the panel doesn't show up!! i need to tap on the entry!!!

I also tried to display the keyboard from the imf context: 

Ecore_IMF_Context *imf_context = (Ecore_IMF_Context*) elm_entry_imf_context_get(entry);
if(imf_context){
    	dlog_print(DLOG_INFO, APP_TAG , "Imf context");
	ecore_imf_context_input_panel_show(imf_context);
}

But again in this case the input is being displayed, but in order to change the entry content i need to tap on it first. Please help me. 

I can't find a way to solve that problem.

Yasin Ali

Hi,

Could you please share API version of your development device.
Some details of your development device.

 

Ivan Gualandri

On the device: 

Tizen version 3.0.0.1

On the emukator: 

Tizen version 3.0

The application manifest api version: 3.0

Another thing that i can add, is that i just tried to change the device name (that opens a popup with an entry and the keyboard), and in that case the entry text is correctly focused, and it update the text without needing to tap on the entry.

I tried to have a look at the source (this is where i found the code that was using;

ecore_imf_context_input_panel_show

 

 but it seems that this is not the solution to my problem, or maybe additional steps that i missed are needed. This is the source code of the settings screen in android: https://review.tizen.org/git/?p=apps/core/preloaded/settings.git;a=blob;f=setting-about/src/setting-about-main.c;h=e95c4f6610048aec44962c2c95ba9e8df4f5a836;hb=HEAD 

Maybe it could help in identifying the solution. 

(anyway i think that this should happen by default, and probably i think that this is a common use case, and it should be documented in the entry documentation)

Yasin Ali

Share your code if you find the solution. Hope it will
help others. By the way possibly you are trying to indicate this portion
of code.

LineNo:   code line:
519           ecore_imf_context_input_panel_show(imf_context);

Ivan Gualandri

Hi Yasin, 

the problem is that i wasn't able to find a solution, and i was hoping to get some help in the forum.

Yes i've been through that line,  and I tried to use the imf_context, but i'm still getting the same result. There should be something else that i need to do, but i really can't figure it out.

I included that bit in my code: 

Ecore_IMF_Context *imf_context = (Ecore_IMF_Context*) elm_entry_imf_context_get(entry);
if(imf_context){
        dlog_print(DLOG_INFO, APP_TAG , "Imf context");
	ecore_imf_context_input_panel_show(imf_context);
}

Probably something else is missing. But i can't understand what. I hope that the solution is not to do something like listening to the keypress event, read the value in input and update the entry accordingly (and i haven't checked if that can also be asily done). There should be a simpler solution i hope! 

It's nearly a month that i'm trying to solve this basic issue. 

 

Mark as answer
Yasin Ali

I used below code that works on wearable 3.0 emulator.

static void _my_entry_show_cb(void *data, Evas *e, Evas_Object *obj,
  void *event_info) {
 elm_object_focus_set(obj, EINA_TRUE);
}
static void _popup_text_cb(void *data, Evas_Object *obj, void *event_info) {
 Evas_Object *popup;
 Evas_Object *layout;
 Evas_Object *btn;
 Evas_Object *entry;
 appdata_s *ad;
 ad = (appdata_s *) data;

 popup = elm_popup_add(ad->win);
 elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
 elm_object_style_set(popup, "circle");
 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
 eext_object_event_callback_add(popup, EEXT_CALLBACK_BACK, _popup_hide_cb,
   NULL);
 evas_object_smart_callback_add(popup, "dismissed", _popup_hide_finished_cb,
   NULL);
 elm_object_part_text_set(popup, "title,text", "Title");

 layout = elm_layout_add(popup);
 //elm_layout_file_set(layout, ELM_DEMO_EDJ, "popup_input_text");
 evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND,
   EVAS_HINT_EXPAND);
 elm_layout_theme_set(layout, "layout", "popup", "content/circle");
 elm_object_content_set(popup, layout);

 entry = elm_entry_add(layout);
 evas_object_resize(entry, 1, 0);
 evas_object_move(entry, 1, 0);
 elm_entry_single_line_set(entry, EINA_TRUE);

 elm_entry_scrollable_set(entry, EINA_TRUE);
 evas_object_size_hint_weight_set(entry, 0.5, 0.5);
 evas_object_size_hint_align_set(entry, 0.5, 0.5);
 eext_entry_selection_back_event_allow_set(entry, EINA_TRUE);
 elm_object_part_text_set(entry, "elm.guide", "Guide Text");
 elm_object_part_content_set(layout, "elm.swallow.content", entry);
 evas_object_event_callback_add(entry, EVAS_CALLBACK_SHOW, _my_entry_show_cb,
   NULL);

 btn = elm_button_add(popup);

 elm_object_style_set(btn, "bottom");
 elm_object_text_set(btn, "OK");
 evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
 elm_object_part_content_set(popup, "button1", btn);
 evas_object_smart_callback_add(btn, "clicked", _response_cb, popup);

 evas_object_show(popup);
}

You may use in this way.

Ivan Gualandri

Thank you Yasin! It worked.

Anyway i think that this should be explained in the documentation, since it is a think a common use case.

I marked your post as answer. 

Thanks again!