cedric pushed a commit to branch master. http://git.enlightenment.org/core/elementary.git/commit/?id=49ec1ec570561a260b94eb98c1a73a217822ba8d
commit 49ec1ec570561a260b94eb98c1a73a217822ba8d Author: Jee-Yong Um <jc9...@samsung.com> Date: Sun Oct 4 15:09:22 2015 +0200 elm_hoversel: add elm_hoversel_label_auto_changed_set/get() API 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 <ced...@osg.samsung.com> --- src/bin/test_hoversel.c | 1 + src/lib/elc_hoversel.c | 37 +++++++++++++++++++++++++++++++++++++ src/lib/elm_hoversel.eo | 10 ++++++++++ src/lib/elm_widget_hoversel.h | 1 + 4 files changed, 49 insertions(+) diff --git a/src/bin/test_hoversel.c b/src/bin/test_hoversel.c index 87f9e55..e65efd9 100644 --- a/src/bin/test_hoversel.c +++ b/src/bin/test_hoversel.c @@ -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); diff --git a/src/lib/elc_hoversel.c b/src/lib/elc_hoversel.c index 5f7d0a8..6628bf5 100644 --- a/src/lib/elc_hoversel.c +++ b/src/lib/elc_hoversel.c @@ -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" diff --git a/src/lib/elm_hoversel.eo b/src/lib/elm_hoversel.eo index 878b454..ca24396 100644 --- a/src/lib/elm_hoversel.eo +++ b/src/lib/elm_hoversel.eo @@ -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.]] } diff --git a/src/lib/elm_widget_hoversel.h b/src/lib/elm_widget_hoversel.h index ff62512..2b97728 100644 --- a/src/lib/elm_widget_hoversel.h +++ b/src/lib/elm_widget_hoversel.h @@ -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; --