efl_ui_popup: add timeout property
authorTaehyub Kim <taehyub.kim@samsung.com>
Thu, 21 Sep 2017 08:21:18 +0000 (17:21 +0900)
committerJaehyun Cho <jae_hyun.cho@samsung.com>
Tue, 28 Nov 2017 08:15:42 +0000 (17:15 +0900)
Summary: add timeout property

Test Plan:
1. run elementary_test -to efluipopup
2. after 3 seconds, popup will be delete

Reviewers: Jaehyun_Cho, jpeg, woohyun, thiepha, Blackmole, cedric

Reviewed By: Jaehyun_Cho

Differential Revision: https://phab.enlightenment.org/D5205

src/bin/elementary/test_popup.c
src/lib/elementary/efl_ui_popup.c
src/lib/elementary/efl_ui_popup.eo
src/lib/elementary/efl_ui_popup_private.h

index 701cd17..960cbab 100644 (file)
@@ -1011,6 +1011,14 @@ _position_set_cb(void *data, Evas_Object *obj EINA_UNUSED,
    evas_object_move(data, 0, 0);
 }
 
+static void
+_timeout_set_cb(void *data, Evas_Object *obj EINA_UNUSED,
+                void *event_info EINA_UNUSED)
+{
+   efl_ui_popup_timeout_set(data, 3);
+   printf("timemout is set to 3 seconds\n");
+}
+
 void
 test_efl_ui_popup(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
 {
@@ -1031,7 +1039,6 @@ test_efl_ui_popup(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *ev
    Evas_Object *efl_ui_popup= efl_add(EFL_UI_POPUP_CLASS, win);
 
    evas_object_smart_callback_add(efl_ui_popup, "bg,clicked", _bg_clicked, NULL);
-
    evas_object_resize(efl_ui_popup, 160, 160);
    evas_object_show(efl_ui_popup);
 
@@ -1092,6 +1099,14 @@ test_efl_ui_popup(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *ev
    evas_object_show(position_btn);
    evas_object_smart_callback_add(position_btn, "clicked", _position_set_cb, efl_ui_popup);
 
+   Evas_Object *timeout_btn;
+   timeout_btn = elm_button_add(win);
+   elm_object_text_set(timeout_btn, "Timeout Set");
+   evas_object_move(timeout_btn, 0, 400);
+   evas_object_resize(timeout_btn, 100, 50);
+   evas_object_show(timeout_btn);
+   evas_object_smart_callback_add(timeout_btn, "clicked", _timeout_set_cb, efl_ui_popup);
+
    efl_content_set(efl_ui_popup, btn);
 }
 
index 2deb6a2..3441054 100644 (file)
@@ -131,6 +131,67 @@ _efl_ui_popup_align_get(Eo *obj EINA_UNUSED, Efl_Ui_Popup_Data *pd)
    return pd->align;
 }
 
+static Eina_Bool
+_timer_cb(void *data)
+{
+   Evas_Object *popup = data;
+   evas_object_del(popup);
+
+   return ECORE_CALLBACK_CANCEL;
+}
+
+static void
+_timer_del(Efl_Ui_Popup_Data *pd)
+{
+   if (pd->timer)
+     {
+        ecore_timer_del(pd->timer);
+        pd->timer = NULL;
+     }
+}
+
+static void
+_timer_init(Eo *obj, Efl_Ui_Popup_Data *pd)
+{
+   if (pd->timeout > 0.0)
+     pd->timer = ecore_timer_add(pd->timeout, _timer_cb, obj);
+}
+
+EOLIAN static void
+_efl_ui_popup_efl_gfx_visible_set(Eo *obj, Efl_Ui_Popup_Data *pd, Eina_Bool v)
+{
+   if (_evas_object_intercept_call(obj, EVAS_OBJECT_INTERCEPT_CB_VISIBLE, 0, v))
+     return;
+
+   efl_gfx_visible_set(efl_super(obj, MY_CLASS), v);
+
+   if (v)
+     {
+        _timer_del(pd);
+        _timer_init(obj, pd);
+     }
+}
+
+EOLIAN static void
+_efl_ui_popup_timeout_set(Eo *obj, Efl_Ui_Popup_Data *pd, double time)
+{
+   if (time < 0.0)
+     time = 0.0;
+
+   pd->timeout = time;
+
+   _timer_del(pd);
+
+   if (efl_gfx_visible_get(obj))
+     _timer_init(obj, pd);
+}
+
+EOLIAN static double
+_efl_ui_popup_timeout_get(Eo *obj EINA_UNUSED, Efl_Ui_Popup_Data *pd)
+{
+   return pd->timeout;
+}
+
 EOLIAN static void
 _efl_ui_popup_efl_canvas_group_group_add(Eo *obj, Efl_Ui_Popup_Data *pd)
 {
index a1a1664..06aefd0 100644 (file)
@@ -50,10 +50,24 @@ class Efl.Ui.Popup(Efl.Ui.Layout)
              type: Efl.Ui.Popup.Align;
          }
       }
+      @property timeout {
+         set {
+            [[ Set the timeout seconds.
+               After timeout seconds, popup will be deleted automatically.
+            ]]
+         }
+         get {
+            [[ Get the currently set timeout seconds.]]
+         }
+         values {
+             time: double;
+         }
+      }
    }
    implements {
       class.constructor;
       Efl.Gfx.position { set; }
+      Efl.Gfx.visible { set; }
       Elm.Widget.widget_parent { set; }
       Efl.Container.content { get; set; }
       Efl.Container.content_unset;
index e87151e..8256ec5 100644 (file)
@@ -7,6 +7,8 @@ struct _Efl_Ui_Popup_Data
    Evas_Object *win_parent;
    Evas_Object *event_bg;
    Efl_Ui_Popup_Align align;
+   Ecore_Timer *timer;
+   double timeout;
    Eina_Bool    bg_repeat_events : 1;
 };