Focus test 6: add ability to move the focus by API
authorDave Andreoli <dave@gurumeditation.it>
Sat, 24 Feb 2018 10:33:27 +0000 (11:33 +0100)
committerWonki Kim <wonki_.kim@samsung.com>
Tue, 10 Apr 2018 11:10:37 +0000 (20:10 +0900)
src/bin/elementary/test_focus.c

index 3701b45..567e6e9 100644 (file)
@@ -1087,12 +1087,22 @@ _focus6_gl_text_get(void *data, Evas_Object *obj EINA_UNUSED,
    snprintf(buf, sizeof(buf), "Focus item %d", (int)(uintptr_t)data);
    return strdup(buf);
 }
+
+static void
+_focus6_btn_clicked(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
+{
+   Evas_Object *ly = data;
+   Elm_Focus_Direction dir = (uintptr_t)evas_object_data_get(obj, "direction");
+
+   elm_object_focus_next(ly, dir);
+}
+
 void
 test_focus6(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
 {
-   Evas_Object *win, *ly, *lb, *btn, *gl;
+   Evas_Object *win, *box, *box2, *sep, *ly, *lb, *btn, *gl;
    Elm_Genlist_Item_Class *itc;
-//   Elm_Object_Item *it;
+   Elm_Object_Item *it;
    char buf[PATH_MAX];
    int i;
 
@@ -1100,13 +1110,19 @@ test_focus6(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_in
    elm_win_autodel_set(win, EINA_TRUE);
    elm_win_focus_highlight_enabled_set(win, EINA_TRUE);
 
+   // main vertical box
+   box = elm_box_add(win);
+   evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+   elm_win_resize_object_add(win, box);
+   evas_object_show(box);
+
    // main layout
    ly = elm_layout_add(win);
    snprintf(buf, sizeof(buf), "%s/objects/test.edj", elm_app_data_dir_get());
    elm_layout_file_set(ly, buf, "focus_test_6");
    evas_object_size_hint_weight_set(ly, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
    evas_object_size_hint_align_set(ly, EVAS_HINT_FILL, EVAS_HINT_FILL);
-   elm_win_resize_object_add(win, ly);
+   elm_box_pack_end(box, ly);
    evas_object_show(ly);
 
    lb = elm_label_add(ly);
@@ -1126,12 +1142,16 @@ test_focus6(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_in
    itc->func.text_get = _focus6_gl_text_get;
    for (i = 0; i < 3; i++)
      {
-//        it = 
-        elm_genlist_item_append(gl, itc, (void*)(uintptr_t)i, NULL,
-                                ELM_GENLIST_ITEM_NONE, NULL, NULL);
-        /* This is another bug! This focus item at start do not work */
-        // if (i == 1)
-           // elm_object_item_focus_set(it, EINA_TRUE);
+        it = elm_genlist_item_append(gl, itc, (void*)(uintptr_t)i, NULL,
+                                     ELM_GENLIST_ITEM_NONE, NULL, NULL);
+        
+        if (i == 1)
+          {
+             elm_genlist_item_selected_set(it, EINA_TRUE);
+
+             /* This is another bug! This focus item at start do not work */
+             // elm_object_item_focus_set(it, EINA_TRUE);
+          }
      }
    elm_genlist_item_class_free(itc);
 
@@ -1147,6 +1167,58 @@ test_focus6(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_in
           elm_object_focus_set(btn, EINA_TRUE);
      }
 
+   // 4 buttons (not focusable) to test focus move by API
+   sep = elm_separator_add(win);
+   elm_separator_horizontal_set(sep, EINA_TRUE);
+   elm_box_pack_end(box, sep);
+   evas_object_show(sep);
+
+   box2 = elm_box_add(win);
+   elm_box_horizontal_set(box2, EINA_TRUE);
+   evas_object_size_hint_weight_set(box2, EVAS_HINT_EXPAND, 0.0);
+   evas_object_size_hint_align_set(box2, EVAS_HINT_FILL, 0.0);
+   elm_box_pack_end(box, box2);
+   evas_object_show(box2);
+
+   lb = elm_label_add(ly);
+   evas_object_size_hint_weight_set(lb, EVAS_HINT_EXPAND, 0.0);
+   elm_object_text_set(lb, "Move the focus using elm_object_focus_next()");
+   elm_box_pack_end(box2, lb);
+   evas_object_show(lb);
+   
+   btn = elm_button_add(win);
+   elm_object_text_set(btn, "LEFT");
+   elm_object_focus_allow_set(btn, EINA_FALSE);
+   evas_object_data_set(btn, "direction", (void *)(uintptr_t)ELM_FOCUS_LEFT);
+   evas_object_smart_callback_add(btn, "clicked", _focus6_btn_clicked, ly);
+   elm_box_pack_end(box2, btn);
+   evas_object_show(btn);
+
+   btn = elm_button_add(win);
+   elm_object_text_set(btn, "UP");
+   elm_object_focus_allow_set(btn, EINA_FALSE);
+   evas_object_data_set(btn, "direction", (void *)(uintptr_t)ELM_FOCUS_UP);
+   evas_object_smart_callback_add(btn, "clicked", _focus6_btn_clicked, ly);
+   elm_box_pack_end(box2, btn);
+   evas_object_show(btn);
+
+   btn = elm_button_add(win);
+   elm_object_text_set(btn, "DOWN");
+   elm_object_focus_allow_set(btn, EINA_FALSE);
+   evas_object_data_set(btn, "direction", (void *)(uintptr_t)ELM_FOCUS_DOWN);
+   evas_object_smart_callback_add(btn, "clicked", _focus6_btn_clicked, ly);
+   elm_box_pack_end(box2, btn);
+   evas_object_show(btn);
+
+   btn = elm_button_add(win);
+   elm_object_text_set(btn, "RIGHT");
+   elm_object_focus_allow_set(btn, EINA_FALSE);
+   evas_object_data_set(btn, "direction", (void *)(uintptr_t)ELM_FOCUS_RIGHT);
+   evas_object_smart_callback_add(btn, "clicked", _focus6_btn_clicked, ly);
+   elm_box_pack_end(box2, btn);
+   evas_object_show(btn);
+
+   // size and show the window
    evas_object_resize(win, 400, 400);
    evas_object_show(win);
 }