zmike pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=92c01d9e630103281875e757ac36a4115f0622c6

commit 92c01d9e630103281875e757ac36a4115f0622c6
Author: Marcel Hollerbach <[email protected]>
Date:   Thu Jan 2 09:07:13 2020 -0500

    efl_ui_item: add API that restricts a item from beeing unselected
    
    Summary:
    There are usecases where items should not be unselectable by the user.
    For example in the tab_bar. With this commit, a tab bar user cannot
    unselect a item by hand anymore.
    
    Depends on D10305
    
    Reviewers: zmike, woohyun, segfaultxavi, cedric
    
    Reviewed By: zmike, segfaultxavi, cedric
    
    Subscribers: SanghyeonLee, cedric, #reviewers, #committers
    
    Tags: #efl
    
    Differential Revision: https://phab.enlightenment.org/D10306
---
 src/lib/elementary/efl_ui_collection.c         | 16 ++++++++++++++++
 src/lib/elementary/efl_ui_collection.eo        |  1 +
 src/lib/elementary/efl_ui_item.c               |  5 ++++-
 src/lib/elementary/efl_ui_radio_group_impl.c   | 12 ++++++++++++
 src/lib/elementary/efl_ui_radio_group_impl.eo  |  1 +
 src/lib/elementary/efl_ui_single_selectable.eo |  6 ++++++
 src/lib/elementary/efl_ui_tab_bar.c            | 13 +++++++++++++
 src/lib/elementary/efl_ui_tab_bar.eo           |  1 +
 src/lib/elementary/efl_ui_tab_bar_private.h    |  1 +
 9 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/src/lib/elementary/efl_ui_collection.c 
b/src/lib/elementary/efl_ui_collection.c
index 02e76552e6..b6f96ba2da 100644
--- a/src/lib/elementary/efl_ui_collection.c
+++ b/src/lib/elementary/efl_ui_collection.c
@@ -146,6 +146,7 @@ typedef struct {
    Fast_Accessor size_accessor;
    Efl_Gfx_Entity *sizer;
    unsigned int start_id, end_id;
+   Eina_Bool allow_manual_deselection : 1;
 } Efl_Ui_Collection_Data;
 
 static Eina_Bool register_item(Eo *obj, Efl_Ui_Collection_Data *pd, 
Efl_Ui_Item *item);
@@ -360,6 +361,8 @@ _efl_ui_collection_efl_object_constructor(Eo *obj, 
Efl_Ui_Collection_Data *pd EI
 {
    Eo *o;
 
+   efl_ui_selectable_allow_manual_deselection_set(obj, EINA_TRUE);
+
    pd->dir = EFL_UI_LAYOUT_ORIENTATION_VERTICAL;
 
    _fast_accessor_init(&pd->obj_accessor, &pd->items);
@@ -1176,6 +1179,19 @@ 
_efl_ui_collection_efl_ui_single_selectable_fallback_selection_get(const Eo *obj
    return pd->fallback;
 }
 
+EOLIAN static void
+_efl_ui_collection_efl_ui_single_selectable_allow_manual_deselection_set(Eo 
*obj EINA_UNUSED, Efl_Ui_Collection_Data *pd, Eina_Bool 
allow_manual_deselection)
+{
+   pd->allow_manual_deselection = !!allow_manual_deselection;
+}
+
+EOLIAN static Eina_Bool
+_efl_ui_collection_efl_ui_single_selectable_allow_manual_deselection_get(const 
Eo *obj EINA_UNUSED, Efl_Ui_Collection_Data *pd)
+{
+   return pd->allow_manual_deselection;
+}
+
+
 #include "efl_ui_collection.eo.c"
 
 #define ITEM_IS_OUTSIDE_VISIBLE(id) id < collection_pd->start_id || id > 
collection_pd->end_id
diff --git a/src/lib/elementary/efl_ui_collection.eo 
b/src/lib/elementary/efl_ui_collection.eo
index 4a5a440002..d890b1656e 100644
--- a/src/lib/elementary/efl_ui_collection.eo
+++ b/src/lib/elementary/efl_ui_collection.eo
@@ -97,6 +97,7 @@ class Efl.Ui.Collection extends Efl.Ui.Layout_Base implements
       Efl.Ui.Multi_Selectable_Object_Range.range_select;
       Efl.Ui.Multi_Selectable_Object_Range.range_unselect;
       Efl.Ui.Single_Selectable.fallback_selection {get; set;}
+      Efl.Ui.Single_Selectable.allow_manual_deselection {get; set;}
    }
 }
 
diff --git a/src/lib/elementary/efl_ui_item.c b/src/lib/elementary/efl_ui_item.c
index 85b50ee758..2504f410e0 100644
--- a/src/lib/elementary/efl_ui_item.c
+++ b/src/lib/elementary/efl_ui_item.c
@@ -96,7 +96,10 @@ _item_unpressed(void *data, const Efl_Event *ev EINA_UNUSED)
    m = _fetch_state(pd->container);
 
    if (pd->selected)
-     efl_ui_selectable_selected_set(obj, EINA_FALSE);
+     {
+        if (efl_ui_selectable_allow_manual_deselection_get(pd->container))
+          efl_ui_selectable_selected_set(obj, EINA_FALSE);
+     }
    else if (m != EFL_UI_SELECT_MODE_NONE)
      efl_ui_selectable_selected_set(obj, EINA_TRUE);
 }
diff --git a/src/lib/elementary/efl_ui_radio_group_impl.c 
b/src/lib/elementary/efl_ui_radio_group_impl.c
index 6a14f37115..ff1e085b8d 100644
--- a/src/lib/elementary/efl_ui_radio_group_impl.c
+++ b/src/lib/elementary/efl_ui_radio_group_impl.c
@@ -16,6 +16,18 @@ typedef struct {
    Eina_Bool in_value_change;
 } Efl_Ui_Radio_Group_Impl_Data;
 
+EOLIAN static void
+_efl_ui_radio_group_impl_efl_ui_single_selectable_allow_manual_deselection_set(Eo
 *obj EINA_UNUSED, Efl_Ui_Radio_Group_Impl_Data *pd EINA_UNUSED, Eina_Bool 
allow_manual_deselection EINA_UNUSED)
+{
+   if (allow_manual_deselection == EINA_FALSE)
+     ERR("This is right now not supported.");
+}
+
+EOLIAN static Eina_Bool
+_efl_ui_radio_group_impl_efl_ui_single_selectable_allow_manual_deselection_get(const
 Eo *obj EINA_UNUSED, Efl_Ui_Radio_Group_Impl_Data *pd EINA_UNUSED)
+{
+   return EINA_FALSE;
+}
 
 EOLIAN static void
 _efl_ui_radio_group_impl_efl_ui_single_selectable_fallback_selection_set(Eo 
*obj EINA_UNUSED, Efl_Ui_Radio_Group_Impl_Data *pd, Efl_Ui_Selectable *fallback)
diff --git a/src/lib/elementary/efl_ui_radio_group_impl.eo 
b/src/lib/elementary/efl_ui_radio_group_impl.eo
index 7e4fefe01b..6bc4379d39 100644
--- a/src/lib/elementary/efl_ui_radio_group_impl.eo
+++ b/src/lib/elementary/efl_ui_radio_group_impl.eo
@@ -12,5 +12,6 @@ class Efl.Ui.Radio_Group_Impl extends Efl.Object implements 
Efl.Ui.Radio_Group
       Efl.Ui.Radio_Group.unregister;
       Efl.Ui.Single_Selectable.last_selected {get;}
       Efl.Ui.Single_Selectable.fallback_selection {set; get;}
+      Efl.Ui.Single_Selectable.allow_manual_deselection {set; get;}
    }
 }
diff --git a/src/lib/elementary/efl_ui_single_selectable.eo 
b/src/lib/elementary/efl_ui_single_selectable.eo
index 1044082cc6..6e65c0a0ac 100644
--- a/src/lib/elementary/efl_ui_single_selectable.eo
+++ b/src/lib/elementary/efl_ui_single_selectable.eo
@@ -30,6 +30,12 @@ interface Efl.Ui.Single_Selectable {
             fallback : Efl.Ui.Selectable;
          }
       }
+      @property allow_manual_deselection {
+         [[This controlls if a selected item can be deselected due to 
clicking]]
+         values {
+            allow_manual_deselection : bool; [[$true if clicking while 
selected results in a state change to unselected]]
+         }
+      }
    }
    events {
       selection_changed : void; [[Emitted when there is a change in the 
selection state. This event will collect all
diff --git a/src/lib/elementary/efl_ui_tab_bar.c 
b/src/lib/elementary/efl_ui_tab_bar.c
index 34e37299e2..da5ca2c43d 100644
--- a/src/lib/elementary/efl_ui_tab_bar.c
+++ b/src/lib/elementary/efl_ui_tab_bar.c
@@ -26,6 +26,19 @@ 
_efl_ui_tab_bar_efl_ui_single_selectable_fallback_selection_set(Eo *obj EINA_UNU
      efl_ui_selectable_selected_set(pd->fallback_selection, EINA_TRUE);
 }
 
+EOLIAN static void
+_efl_ui_tab_bar_efl_ui_single_selectable_allow_manual_deselection_set(Eo *obj 
EINA_UNUSED, Efl_Ui_Tab_Bar_Data *pd, Eina_Bool allow_manual_deselection)
+{
+   pd->allow_manual_deselection = !!allow_manual_deselection;
+}
+
+EOLIAN static Eina_Bool
+_efl_ui_tab_bar_efl_ui_single_selectable_allow_manual_deselection_get(const Eo 
*obj EINA_UNUSED, Efl_Ui_Tab_Bar_Data *pd)
+{
+   return pd->allow_manual_deselection;
+}
+
+
 EOLIAN static Efl_Ui_Selectable*
 _efl_ui_tab_bar_efl_ui_single_selectable_fallback_selection_get(const Eo *obj 
EINA_UNUSED, Efl_Ui_Tab_Bar_Data *pd)
 {
diff --git a/src/lib/elementary/efl_ui_tab_bar.eo 
b/src/lib/elementary/efl_ui_tab_bar.eo
index cf06e0de47..c077cf0a57 100644
--- a/src/lib/elementary/efl_ui_tab_bar.eo
+++ b/src/lib/elementary/efl_ui_tab_bar.eo
@@ -15,6 +15,7 @@ class @beta Efl.Ui.Tab_Bar extends Efl.Ui.Layout_Base
       Efl.Object.destructor;
       Efl.Ui.Single_Selectable.last_selected {get;}
       Efl.Ui.Single_Selectable.fallback_selection {get; set;}
+      Efl.Ui.Single_Selectable.allow_manual_deselection {get; set;}
       Efl.Pack.pack;
       Efl.Pack.pack_clear;
       Efl.Pack.unpack_all;
diff --git a/src/lib/elementary/efl_ui_tab_bar_private.h 
b/src/lib/elementary/efl_ui_tab_bar_private.h
index 87763a9e87..02775c36a7 100644
--- a/src/lib/elementary/efl_ui_tab_bar_private.h
+++ b/src/lib/elementary/efl_ui_tab_bar_private.h
@@ -8,6 +8,7 @@ struct _Efl_Ui_Tab_Bar_Data
    Efl_Ui_Box                           *bx;
    Efl_Ui_Item                          *selected, *fallback_selection;
    Eina_Bool                             in_value_change;
+   Eina_Bool                             allow_manual_deselection : 1;
 };
 
 #define EFL_UI_TAB_BAR_DATA_GET(o, sd) \

-- 


Reply via email to