This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository efl.

View the commit online.

commit 52068bfaaf19d060e8c983993faa2a0fbe8ce9da
Author: Cedric BAIL <[email protected]>
AuthorDate: Tue Nov 17 21:29:59 2026 -0600

    elementary: the selected radio stays unless deselection is allowed
    
    Efl.Ui.Single_Selectable.allow_manual_deselection says whether a click
    may deselect the selected item, but a radio group ignored it: the
    getter always answered false, the setter logged an error when given
    false, and a press on the selected radio toggled it off anyway.
    Efl.Ui.Radio_Group.selected_value also documents -1 as usable, yet
    setting it only logged "not associated with any radio button".
    
    The group now keeps the flag, false by default as the getter always
    said, and a press on its selected radio does nothing unless it is set:
    pressing the selected radio of an Efl.Ui.Radio_Box no longer unchecks
    it. Check and Radio both consult the group, so mouse and key presses
    agree. A radio in no group, legacy radios included, is unaffected.
    Setting the value to -1 deselects, or selects the group's fallback if
    it has one; the flag only concerns clicks, so it does not hold back the
    program. The theme's efl,action,unselect signal is left alone on
    purpose: no radio theme EFL ships sends it.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/lib/elementary/efl_ui_check.c              |   5 ++
 src/lib/elementary/efl_ui_radio.c              |   2 +
 src/lib/elementary/efl_ui_radio_group_impl.c   |  36 +++++++--
 src/lib/elementary/elm_priv.h                  |   6 ++
 src/tests/elementary/efl_ui_test_radio_group.c | 108 +++++++++++++++++++++++++
 5 files changed, 152 insertions(+), 5 deletions(-)

diff --git a/src/lib/elementary/efl_ui_check.c b/src/lib/elementary/efl_ui_check.c
index 79749a5b1d..73ea051edd 100644
--- a/src/lib/elementary/efl_ui_check.c
+++ b/src/lib/elementary/efl_ui_check.c
@@ -72,6 +72,11 @@ _check_legacy_event(Eo *obj)
 static void
 _activate(Evas_Object *obj)
 {
+   /* A radio of a group that does not allow it stays selected when pressed. */
+   if (efl_ui_selectable_selected_get(obj) && efl_isa(obj, EFL_UI_RADIO_CLASS) &&
+       !_efl_ui_radio_user_deselect_allowed(obj))
+     return;
+
    // state will be changed by the later call to the selected_set call
    if (!efl_ui_selectable_selected_get(obj))
      {
diff --git a/src/lib/elementary/efl_ui_radio.c b/src/lib/elementary/efl_ui_radio.c
index b4690794a4..7d951e31d4 100644
--- a/src/lib/elementary/efl_ui_radio.c
+++ b/src/lib/elementary/efl_ui_radio.c
@@ -144,6 +144,8 @@ _activate(Evas_Object *obj)
    else
      {
         //in new API, we just toggle the state of the widget, rest will be automatically handled
+        if (efl_ui_selectable_selected_get(obj) && !_efl_ui_radio_user_deselect_allowed(obj))
+          return;
         efl_ui_selectable_selected_set(obj, !efl_ui_selectable_selected_get(obj));
         _efl_ui_property_bind_user_changed(obj, "selected");
      }
diff --git a/src/lib/elementary/efl_ui_radio_group_impl.c b/src/lib/elementary/efl_ui_radio_group_impl.c
index 4e32efa2ec..d75207aa71 100644
--- a/src/lib/elementary/efl_ui_radio_group_impl.c
+++ b/src/lib/elementary/efl_ui_radio_group_impl.c
@@ -14,19 +14,19 @@ typedef struct {
    Efl_Ui_Radio *fallback_object;
    Eina_List *registered_set;
    Eina_Bool in_value_change;
+   Eina_Bool allow_manual_deselection;
 } 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)
+_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_Bool allow_manual_deselection)
 {
-   if (allow_manual_deselection == EINA_FALSE)
-     ERR("This is right now not supported.");
+   pd->allow_manual_deselection = !!allow_manual_deselection;
 }
 
 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)
+_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)
 {
-   return EINA_FALSE;
+   return pd->allow_manual_deselection;
 }
 
 EOLIAN static void
@@ -56,6 +56,18 @@ _efl_ui_radio_group_impl_efl_ui_radio_group_selected_value_set(Eo *obj EINA_UNUS
    Efl_Ui_Radio *reged;
    Eina_List *n;
 
+   /* -1 is "nothing selected". Only a click is held back by
+      allow_manual_deselection; the program may always ask for it, and a
+      fallback selection takes what would be left empty. */
+   if (selected_value == -1)
+     {
+        if (pd->fallback_object)
+          efl_ui_selectable_selected_set(pd->fallback_object, EINA_TRUE);
+        else if (pd->selected)
+          efl_ui_selectable_selected_set(pd->selected, EINA_FALSE);
+        return;
+     }
+
    EINA_LIST_FOREACH(pd->registered_set, n, reged)
      {
         if (efl_ui_radio_state_value_get(reged) == selected_value)
@@ -73,6 +85,20 @@ _efl_ui_radio_group_impl_efl_ui_radio_group_selected_value_get(const Eo *obj EIN
    return pd->selected ? efl_ui_radio_state_value_get(pd->selected) : -1;
 }
 
+/* Whether a press on the selected @p radio may deselect it: the group it
+   belongs to decides. A radio outside any group has nothing to hold it
+   selected. */
+Eina_Bool
+_efl_ui_radio_user_deselect_allowed(Efl_Ui_Radio *radio)
+{
+   Eo *group = eina_hash_find(radio_group_map, &radio);
+   Efl_Ui_Radio_Group_Impl_Data *pd;
+
+   if (!group) return EINA_TRUE;
+   pd = efl_data_scope_safe_get(group, MY_CLASS);
+   return !pd || pd->allow_manual_deselection;
+}
+
 static void
 _selected_cb(void *data, const Efl_Event *ev)
 {
diff --git a/src/lib/elementary/elm_priv.h b/src/lib/elementary/elm_priv.h
index d7d8b6a80a..793517edce 100644
--- a/src/lib/elementary/elm_priv.h
+++ b/src/lib/elementary/elm_priv.h
@@ -1101,6 +1101,12 @@ void _drop_event_unregister(Eo *obj);
 void _register_selection_changed(Efl_Ui_Selection *selection);
 Efl_Ui_Win* efl_ui_win_get(Evas_Object *obj);
 
+/*
+ * Whether a press may deselect @p radio, the selected one of its group: the
+ * group's allow_manual_deselection. True for a radio in no group.
+ */
+Eina_Bool _efl_ui_radio_user_deselect_allowed(Efl_Ui_Radio *radio);
+
 /*
  * Tells whoever is bound to @p property of @p obj that the user changed it.
  *
diff --git a/src/tests/elementary/efl_ui_test_radio_group.c b/src/tests/elementary/efl_ui_test_radio_group.c
index bb04fdee16..6de649345b 100644
--- a/src/tests/elementary/efl_ui_test_radio_group.c
+++ b/src/tests/elementary/efl_ui_test_radio_group.c
@@ -279,6 +279,109 @@ EFL_START_TEST(radio_box_frees_its_group)
 }
 EFL_END_TEST
 
+/* A box of three radios, laid out so that a press lands on each. */
+static Eo *
+_pressable_box(Eo **radios)
+{
+   Eo *box = efl_add(EFL_UI_RADIO_BOX_CLASS, win,
+                     efl_gfx_entity_size_set(efl_added, EINA_SIZE2D(300, 150)));
+   int i;
+
+   for (i = 0; i < 3; i++)
+     {
+        radios[i] = radio();
+        efl_gfx_hint_size_min_set(radios[i], EINA_SIZE2D(100, 40));
+        efl_pack_end(box, radios[i]);
+        efl_gfx_entity_visible_set(radios[i], EINA_TRUE);
+     }
+   efl_gfx_entity_visible_set(box, EINA_TRUE);
+   efl_canvas_group_calculate(box);
+   ecore_main_loop_iterate();
+   return box;
+}
+
+EFL_START_TEST(press_selected_radio_keeps_it)
+{
+   Eo *radios[3];
+   Eo *box = _pressable_box(radios);
+
+   ck_assert(!efl_ui_selectable_allow_manual_deselection_get(box));
+   efl_ui_radio_group_selected_value_set(box, 1);
+   click_object(radios[0]);
+   ecore_main_loop_iterate();
+   ck_assert(efl_ui_selectable_selected_get(radios[0]));
+   ck_assert_int_eq(efl_ui_radio_group_selected_value_get(box), 1);
+}
+EFL_END_TEST
+
+EFL_START_TEST(press_selected_radio_deselects_when_allowed)
+{
+   Eo *radios[3];
+   Eo *box = _pressable_box(radios);
+
+   efl_ui_selectable_allow_manual_deselection_set(box, EINA_TRUE);
+   ck_assert(efl_ui_selectable_allow_manual_deselection_get(box));
+   efl_ui_radio_group_selected_value_set(box, 1);
+   click_object(radios[0]);
+   ecore_main_loop_iterate();
+   ck_assert(!efl_ui_selectable_selected_get(radios[0]));
+   ck_assert_int_eq(efl_ui_radio_group_selected_value_get(box), -1);
+}
+EFL_END_TEST
+
+EFL_START_TEST(press_selected_radio_falls_back_when_allowed)
+{
+   Eo *radios[3];
+   Eo *box = _pressable_box(radios);
+
+   efl_ui_selectable_allow_manual_deselection_set(box, EINA_TRUE);
+   efl_ui_selectable_fallback_selection_set(box, radios[2]);
+   efl_ui_radio_group_selected_value_set(box, 1);
+   click_object(radios[0]);
+   ecore_main_loop_iterate();
+   ck_assert_int_eq(efl_ui_radio_group_selected_value_get(box), 3);
+}
+EFL_END_TEST
+
+EFL_START_TEST(selected_value_minus_one_deselects)
+{
+   Eo *r1 = radio();
+   Eo *r2 = radio();
+
+   efl_ui_radio_group_register(radio_group, r1);
+   efl_ui_radio_group_register(radio_group, r2);
+   efl_ui_radio_group_selected_value_set(radio_group, 2);
+
+   RESET_EVT
+   efl_ui_radio_group_selected_value_set(radio_group, -1);
+   ck_assert_int_eq(efl_ui_radio_group_selected_value_get(radio_group), -1);
+   ck_assert_ptr_eq(efl_ui_selectable_last_selected_get(radio_group), NULL);
+   ck_assert(!efl_ui_selectable_selected_get(r2));
+   EXPECT_EVT(1, -1);
+
+   // Nothing selected already: nothing to do, and no event
+   RESET_EVT
+   efl_ui_radio_group_selected_value_set(radio_group, -1);
+   ck_assert_int_eq(changed_evt.called, 0);
+}
+EFL_END_TEST
+
+EFL_START_TEST(selected_value_minus_one_applies_the_fallback)
+{
+   Eo *r1 = radio();
+   Eo *r2 = radio();
+
+   efl_ui_radio_group_register(radio_group, r1);
+   efl_ui_radio_group_register(radio_group, r2);
+   efl_ui_selectable_fallback_selection_set(radio_group, r1);
+   efl_ui_radio_group_selected_value_set(radio_group, 2);
+
+   efl_ui_radio_group_selected_value_set(radio_group, -1);
+   ck_assert_int_eq(efl_ui_radio_group_selected_value_get(radio_group), 1);
+   ck_assert(efl_ui_selectable_selected_get(r1));
+}
+EFL_END_TEST
+
 void efl_ui_test_radio_group(TCase *tc)
 {
    tcase_add_checked_fixture(tc, fail_on_errors_setup, fail_on_errors_teardown);
@@ -295,4 +398,9 @@ void efl_ui_test_radio_group(TCase *tc)
    tcase_add_test(tc, delete_setted);
    tcase_add_test(tc, group_invalid_value);
    tcase_add_test(tc, radio_box_frees_its_group);
+   tcase_add_test(tc, press_selected_radio_keeps_it);
+   tcase_add_test(tc, press_selected_radio_deselects_when_allowed);
+   tcase_add_test(tc, press_selected_radio_falls_back_when_allowed);
+   tcase_add_test(tc, selected_value_minus_one_deselects);
+   tcase_add_test(tc, selected_value_minus_one_applies_the_fallback);
 }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to