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 3105a0a373c9f4f09d6d7aab43bf1845ad2ce5f0
Author: Cedric BAIL <[email protected]>
AuthorDate: Tue Nov 17 21:29:59 2026 -0600

    elementary: a radio box's selected_value is written back to its model
    
    Efl.Ui.Radio documents that a whole group is followed from a model by
    binding the group's value, but nothing wrote that value back: the radio
    box showed the model's value, yet a user's press changed the group
    without the model hearing of it. Reflection already reaches
    selected_value through the composited Radio_Group, so only the
    write-back was missing.
    
    A press raises properties,changed for "selected" on the radio only, and
    only while something listens. The group now listens on each radio it
    holds and raises "selected_value" in turn; the box forwards that event
    to itself, where the generic widget binding writes the model. Setting
    the value from code raises nothing, so the binding's own writes do not
    come back. A group used without a box has no model to write to and is
    unchanged.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/lib/elementary/efl_ui_radio.eo               |   2 +-
 src/lib/elementary/efl_ui_radio_box.c            |   2 +
 src/lib/elementary/efl_ui_radio_box.eo           |   7 +
 src/lib/elementary/efl_ui_radio_group_impl.c     |  22 +++
 src/tests/elementary/efl_ui_test_property_bind.c | 170 +++++++++++++++++++++++
 5 files changed, 202 insertions(+), 1 deletion(-)

diff --git a/src/lib/elementary/efl_ui_radio.eo b/src/lib/elementary/efl_ui_radio.eo
index df458d158e..dfa16d4ab6 100644
--- a/src/lib/elementary/efl_ui_radio.eo
+++ b/src/lib/elementary/efl_ui_radio.eo
@@ -14,7 +14,7 @@ class Efl.Ui.Radio extends Efl.Ui.Check implements Efl.Access.Widget.Action
 
      A radio button raises @[Efl.Ui.Property_Bind.properties,changed] for "selected" when the
      user presses it. The buttons the group unchecks as a result do not: to follow a whole
-     group from a model, bind the group's value instead.
+     group from a model, bind the group's value instead, as @Efl.Ui.Radio_Box allows.
 
      @since 1.23
    ]]
diff --git a/src/lib/elementary/efl_ui_radio_box.c b/src/lib/elementary/efl_ui_radio_box.c
index 74d9e3e2b8..784b7aee71 100644
--- a/src/lib/elementary/efl_ui_radio_box.c
+++ b/src/lib/elementary/efl_ui_radio_box.c
@@ -118,6 +118,7 @@ _efl_ui_radio_box_efl_object_constructor(Eo *obj, Efl_Ui_Radio_Box_Data *pd)
    efl_composite_attach(obj, pd->group);
    efl_event_callback_forwarder_add(pd->group, EFL_UI_SELECTABLE_EVENT_SELECTION_CHANGED, obj);
    efl_event_callback_forwarder_add(pd->group, EFL_UI_RADIO_GROUP_EVENT_VALUE_CHANGED, obj);
+   efl_event_callback_forwarder_add(pd->group, EFL_UI_PROPERTY_BIND_EVENT_PROPERTIES_CHANGED, obj);
    return efl_constructor(efl_super(obj, MY_CLASS));
 }
 
@@ -129,6 +130,7 @@ _efl_ui_radio_box_efl_object_destructor(Eo *obj, Efl_Ui_Radio_Box_Data *pd)
 {
    efl_event_callback_forwarder_del(pd->group, EFL_UI_SELECTABLE_EVENT_SELECTION_CHANGED, obj);
    efl_event_callback_forwarder_del(pd->group, EFL_UI_RADIO_GROUP_EVENT_VALUE_CHANGED, obj);
+   efl_event_callback_forwarder_del(pd->group, EFL_UI_PROPERTY_BIND_EVENT_PROPERTIES_CHANGED, obj);
    efl_composite_detach(obj, pd->group);
    efl_unref(pd->group);
    pd->group = NULL;
diff --git a/src/lib/elementary/efl_ui_radio_box.eo b/src/lib/elementary/efl_ui_radio_box.eo
index 9672b8db7b..89d221e6c2 100644
--- a/src/lib/elementary/efl_ui_radio_box.eo
+++ b/src/lib/elementary/efl_ui_radio_box.eo
@@ -6,6 +6,13 @@ class Efl.Ui.Radio_Box extends Efl.Ui.Box composites Efl.Ui.Radio_Group
      All @Efl.Ui.Radio widgets are added to the same internal group which you only indirectly
      access through this object.
 
+     The group's @Efl.Ui.Radio_Group.selected_value can be bound to a property of a model with
+     @Efl.Ui.Property_Bind.property_bind: the box shows the model's value, and raises
+     @[Efl.Ui.Property_Bind.properties,changed] for "selected_value" when the user presses a radio,
+     which writes the value back to the model. Setting the value from code does not.
+     A press that deselects the selected radio, which only a group with
+     @Efl.Ui.Single_Selectable.allow_manual_deselection allows, writes -1.
+
      @since 1.24
    ]]
    implements {
diff --git a/src/lib/elementary/efl_ui_radio_group_impl.c b/src/lib/elementary/efl_ui_radio_group_impl.c
index d75207aa71..f56d5b2781 100644
--- a/src/lib/elementary/efl_ui_radio_group_impl.c
+++ b/src/lib/elementary/efl_ui_radio_group_impl.c
@@ -149,8 +149,30 @@ _invalidate_cb(void *data, const Efl_Event *ev)
    efl_ui_radio_group_unregister(data, ev->object);
 }
 
+/* A radio raises properties,changed for "selected" only for what the user
+   did to it, and only while someone listens: the group listens, so that the
+   radio box composing it can tell its own binding that the group's value is
+   the user's. The value the group holds is what changed, whichever radio it
+   was pressed on. */
+static void
+_user_changed_cb(void *data, const Efl_Event *ev)
+{
+   Efl_Ui_Property_Event *evt = ev->info;
+   Eina_Stringshare *property;
+   Eina_Array_Iterator it;
+   unsigned int i;
+
+   EINA_ARRAY_ITER_NEXT(evt->changed_properties, i, property, it)
+     {
+        if (!eina_streq(property, "selected")) continue;
+        _efl_ui_property_bind_user_changed(data, "selected_value");
+        return;
+     }
+}
+
 EFL_CALLBACKS_ARRAY_DEFINE(radio_btn_cb,
   {EFL_UI_EVENT_SELECTED_CHANGED, _selected_cb},
+  {EFL_UI_PROPERTY_BIND_EVENT_PROPERTIES_CHANGED, _user_changed_cb},
   {EFL_EVENT_INVALIDATE, _invalidate_cb},
 )
 
diff --git a/src/tests/elementary/efl_ui_test_property_bind.c b/src/tests/elementary/efl_ui_test_property_bind.c
index a86a3afada..a07a6bd8ef 100644
--- a/src/tests/elementary/efl_ui_test_property_bind.c
+++ b/src/tests/elementary/efl_ui_test_property_bind.c
@@ -566,6 +566,168 @@ EFL_START_TEST(radio_click_reaches_the_model)
 }
 EFL_END_TEST
 
+/* A radio box shows and edits the value of its group: binding
+ * "selected_value" follows the model both ways. Radios are packed before the
+ * binding exists, as the group refuses a value none of its radios holds. */
+static Eo *
+_unit_box(Eo *win, Eo *model, 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] = efl_add(EFL_UI_RADIO_CLASS, box,
+                            efl_ui_radio_state_value_set(efl_added, i + 1),
+                            efl_gfx_hint_size_min_set(efl_added, EINA_SIZE2D(100, 40)));
+        efl_pack_end(box, radios[i]);
+        efl_gfx_entity_visible_set(radios[i], EINA_TRUE);
+     }
+   efl_ui_view_model_set(box, model);
+   efl_ui_property_bind(box, "selected_value", "unit");
+   efl_gfx_entity_visible_set(box, EINA_TRUE);
+   efl_canvas_group_calculate(box);
+   ecore_main_loop_iterate();
+   return box;
+}
+
+static int
+_model_int(Eo *model, const char *property)
+{
+   Eina_Value *v = _model_get(model, property);
+   int i = -1;
+
+   eina_value_int_convert(v, &i);
+   eina_value_free(v);
+   return i;
+}
+
+EFL_START_TEST(radio_box_shows_the_model_value)
+{
+   Eo *win = _window();
+   Eo *model = _model_new("unit", eina_value_int_new(2));
+   Eo *radios[3];
+   Eo *box = _unit_box(win, model, radios);
+
+   ck_assert_int_eq(efl_ui_radio_group_selected_value_get(box), 2);
+   ck_assert(efl_ui_selectable_selected_get(radios[1]));
+   ck_assert(!efl_ui_selectable_selected_get(radios[0]));
+}
+EFL_END_TEST
+
+EFL_START_TEST(radio_box_follows_the_model)
+{
+   Eo *win = _window();
+   Eo *model = _model_new("unit", eina_value_int_new(1));
+   Eo *radios[3];
+   Eo *box = _unit_box(win, model, radios);
+
+   _model_set(model, "unit", eina_value_int_new(3));
+   ecore_main_loop_iterate();
+   ck_assert_int_eq(efl_ui_radio_group_selected_value_get(box), 3);
+   ck_assert(efl_ui_selectable_selected_get(radios[2]));
+   ck_assert(!efl_ui_selectable_selected_get(radios[0]));
+}
+EFL_END_TEST
+
+EFL_START_TEST(radio_box_press_reaches_the_model)
+{
+   Eo *win = _window();
+   Eo *model = _model_new("unit", eina_value_int_new(1));
+   Eo *radios[3];
+   Eo *box = _unit_box(win, model, radios);
+
+   model_changes = 0;
+   efl_event_callback_add(model, EFL_MODEL_EVENT_PROPERTIES_CHANGED, _model_changed, NULL);
+   click_object(radios[2]);
+   ecore_main_loop_iterate();
+   ck_assert_int_eq(efl_ui_radio_group_selected_value_get(box), 3);
+   ck_assert_int_eq(_model_int(model, "unit"), 3);
+   // The box's own write comes back through the model and must stop there
+   ck_assert_uint_eq(model_changes, 1);
+   efl_event_callback_del(model, EFL_MODEL_EVENT_PROPERTIES_CHANGED, _model_changed, NULL);
+}
+EFL_END_TEST
+
+EFL_START_TEST(radio_box_programmatic_value_does_not_reach_the_model)
+{
+   Eo *win = _window();
+   Eo *model = _model_new("unit", eina_value_int_new(1));
+   Eo *radios[3];
+   Eo *box = _unit_box(win, model, radios);
+
+   efl_ui_radio_group_selected_value_set(box, 2);
+   ecore_main_loop_iterate();
+   ck_assert_int_eq(efl_ui_radio_group_selected_value_get(box), 2);
+   ck_assert_int_eq(_model_int(model, "unit"), 1);
+}
+EFL_END_TEST
+
+EFL_START_TEST(radio_box_model_change_does_not_loop)
+{
+   Eo *win = _window();
+   Eo *model = _model_new("unit", eina_value_int_new(1));
+   Eo *radios[3];
+
+   _unit_box(win, model, radios);
+   model_changes = 0;
+   efl_event_callback_add(model, EFL_MODEL_EVENT_PROPERTIES_CHANGED, _model_changed, NULL);
+   _model_set(model, "unit", eina_value_int_new(2));
+   ecore_main_loop_iterate();
+   ck_assert_uint_eq(model_changes, 1);
+   efl_event_callback_del(model, EFL_MODEL_EVENT_PROPERTIES_CHANGED, _model_changed, NULL);
+}
+EFL_END_TEST
+
+EFL_START_TEST(radio_box_pressing_the_selected_radio_writes_nothing)
+{
+   Eo *win = _window();
+   Eo *model = _model_new("unit", eina_value_int_new(2));
+   Eo *radios[3];
+   Eo *box = _unit_box(win, model, radios);
+
+   model_changes = 0;
+   efl_event_callback_add(model, EFL_MODEL_EVENT_PROPERTIES_CHANGED, _model_changed, NULL);
+   click_object(radios[1]);
+   ecore_main_loop_iterate();
+   ck_assert(efl_ui_selectable_selected_get(radios[1]));
+   ck_assert_int_eq(efl_ui_radio_group_selected_value_get(box), 2);
+   ck_assert_int_eq(_model_int(model, "unit"), 2);
+   ck_assert_uint_eq(model_changes, 0);
+   efl_event_callback_del(model, EFL_MODEL_EVENT_PROPERTIES_CHANGED, _model_changed, NULL);
+}
+EFL_END_TEST
+
+EFL_START_TEST(radio_box_deselecting_press_writes_minus_one)
+{
+   Eo *win = _window();
+   Eo *model = _model_new("unit", eina_value_int_new(2));
+   Eo *radios[3];
+   Eo *box = _unit_box(win, model, radios);
+
+   efl_ui_selectable_allow_manual_deselection_set(box, EINA_TRUE);
+   click_object(radios[1]);
+   ecore_main_loop_iterate();
+   ck_assert(!efl_ui_selectable_selected_get(radios[1]));
+   ck_assert_int_eq(_model_int(model, "unit"), -1);
+}
+EFL_END_TEST
+
+EFL_START_TEST(radio_box_shows_a_model_value_of_minus_one)
+{
+   Eo *win = _window();
+   Eo *model = _model_new("unit", eina_value_int_new(2));
+   Eo *radios[3];
+   Eo *box = _unit_box(win, model, radios);
+
+   _model_set(model, "unit", eina_value_int_new(-1));
+   ecore_main_loop_iterate();
+   ck_assert_int_eq(efl_ui_radio_group_selected_value_get(box), -1);
+   ck_assert(!efl_ui_selectable_selected_get(radios[1]));
+}
+EFL_END_TEST
+
 /* A widget that finds its model through a provider follows the provider to a
  * new model, and then hears that model change as it heard the first. */
 EFL_START_TEST(efl_ui_model_provider_live_edit)
@@ -805,6 +967,14 @@ efl_ui_test_property_bind(TCase *tc)
    tcase_add_test(tc, spin_button_entry_reaches_the_model);
    tcase_add_test(tc, spin_button_stale_entry_is_not_written_back);
    tcase_add_test(tc, radio_click_reaches_the_model);
+   tcase_add_test(tc, radio_box_shows_the_model_value);
+   tcase_add_test(tc, radio_box_follows_the_model);
+   tcase_add_test(tc, radio_box_press_reaches_the_model);
+   tcase_add_test(tc, radio_box_programmatic_value_does_not_reach_the_model);
+   tcase_add_test(tc, radio_box_model_change_does_not_loop);
+   tcase_add_test(tc, radio_box_pressing_the_selected_radio_writes_nothing);
+   tcase_add_test(tc, radio_box_deselecting_press_writes_minus_one);
+   tcase_add_test(tc, radio_box_shows_a_model_value_of_minus_one);
    tcase_add_test(tc, check_click_reaches_the_model);
    tcase_add_test(tc, check_model_change_does_not_loop);
    tcase_add_test(tc, slider_key_reaches_the_model);

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

Reply via email to