elm_hoversel: add elm_hoversel_label_auto_changed_set/get() API
authorJee-Yong Um <jc9.um@samsung.com>
Sun, 4 Oct 2015 13:09:22 +0000 (15:09 +0200)
committerCedric BAIL <cedric@osg.samsung.com>
Sun, 4 Oct 2015 13:10:29 +0000 (15:10 +0200)
Summary:
Hoversel can be used like dropdown or pulldown menu.
In that case, changing hoversel label into selected item lable can be
considered as common usage of hoversel.
This API automatizes changing label.

Reviewers: SanghyeonLee, Hermet, cedric

Reviewed By: cedric

Subscribers: cedric

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

Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
src/bin/test_hoversel.c
src/lib/elc_hoversel.c
src/lib/elm_hoversel.eo
src/lib/elm_widget_hoversel.h

index 87f9e55..e65efd9 100644 (file)
@@ -182,6 +182,7 @@ test_hoversel(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_
 
    hoversel = elm_hoversel_add(win);
    elm_hoversel_scrollable_set(hoversel, EINA_TRUE);
+   elm_hoversel_label_auto_changed_set(hoversel, EINA_TRUE);
    elm_hoversel_hover_parent_set(hoversel, win);
    elm_object_text_set(hoversel, "Some Icons");
    elm_hoversel_item_add(hoversel, "Item 1", NULL, ELM_ICON_NONE, NULL, NULL);
index 5f7d0a8..6628bf5 100644 (file)
@@ -110,8 +110,33 @@ _on_item_clicked(void *data EINA_UNUSED,
    Evas_Object *obj2 = WIDGET(item);
    Elm_Object_Item *eo_it = EO_OBJ(item);
 
+   ELM_HOVERSEL_DATA_GET(obj2, sd);
+
    if (item->func) item->func((void *)WIDGET_ITEM_DATA_GET(eo_it), obj2, eo_it);
    eo_do(obj2, eo_event_callback_call(EVAS_SELECTABLE_INTERFACE_EVENT_SELECTED, eo_it));
+
+   if (sd->auto_changed)
+     {
+        Evas_Object *ic;
+
+        ic = elm_object_part_content_unset(obj2, "icon");
+        ELM_SAFE_FREE(ic, evas_object_del);
+
+        if (item->icon_file)
+          {
+             ic = elm_icon_add(obj2);
+             elm_image_resizable_set(ic, EINA_FALSE, EINA_TRUE);
+             if (item->icon_type == ELM_ICON_FILE)
+               elm_image_file_set(ic, item->icon_file, item->icon_group);
+             else if (item->icon_type == ELM_ICON_STANDARD)
+               elm_icon_standard_set(ic, item->icon_file);
+             elm_object_part_content_set(obj2, "icon", ic);
+          }
+
+        if(item->label)
+          elm_object_text_set(obj2, item->label);
+     }
+
    elm_hoversel_hover_end(obj2);
 
    return EINA_TRUE;
@@ -901,5 +926,17 @@ _elm_hoversel_scrollable_get(Eo *obj EINA_UNUSED, Elm_Hoversel_Data *sd)
    return sd->scroll_enabled;
 }
 
+EOLIAN void
+_elm_hoversel_label_auto_changed_set(Eo *obj EINA_UNUSED, Elm_Hoversel_Data *sd, Eina_Bool auto_changed)
+{
+   sd->auto_changed = !!auto_changed;
+}
+
+EOLIAN Eina_Bool
+_elm_hoversel_label_auto_changed_get(Eo *obj EINA_UNUSED, Elm_Hoversel_Data *sd)
+{
+   return sd->auto_changed;
+}
+
 #include "elm_hoversel_item.eo.c"
 #include "elm_hoversel.eo.c"
index 878b454..ca24396 100644 (file)
@@ -57,6 +57,16 @@ class Elm.Hoversel (Elm.Button, Evas.Selectable_Interface,
             scrollable: bool; [[$true if scrollable $false otherwise.]]
          }
       }
+      @property label_auto_changed {
+         [[Change the label of hoversel to that of selected item automatically.]]
+         get{
+         }
+         set{
+         }
+         values {
+            auto_changed: bool; [[$true if the label is changed automatically or $false otherwise]]
+         }
+      }
       hover_begin {
          [[This triggers the hoversel popup from code, the same as if the user had clicked the button.]]
       }
index ff62512..2b97728 100644 (file)
@@ -42,6 +42,7 @@ struct _Elm_Hoversel_Data
    Eina_Bool             horizontal    : 1;
    Eina_Bool             expanded      : 1;
    Eina_Bool             scroll_enabled: 1;
+   Eina_Bool             auto_changed  : 1;
 };
 
 typedef struct _Elm_Hoversel_Item_Data Elm_Hoversel_Item_Data;