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 d5932d0d41553b4e10c70ab2238b2769f6819b82
Author: Cedric BAIL <[email protected]>
AuthorDate: Mon Oct 26 12:14:26 2026 -0600
elementary: a collection view's last selected is the item, and it stays
A list or grid view composites its selection from the select model it
wraps the application's model in, so last_selected and
fallback_selection handed out that model's rows -- an
Efl.Ui.Select_Model child, not anything on screen -- where every other
widget hands out the item. An application asking which item the user
chose got an object it could not show, style or ask for its text.
The view now answers them itself, translating between rows and items:
last_selected is the item showing the row selected last, and
fallback_selection takes and gives items. The item's model leads back
to the row.
An item only exists while its row is near the screen, so a selected row
now keeps its item: the idle pass that lets rows' items go skips a
selected one and hides it instead, and the position manager shows it
again when its row comes back. A row selected from code that was never
shown is given an item when the selection changes.
That needed one fix underneath: a request asking for a row's item only
built one when the model could not give the row's size. With a
homogeneous model the size is known, so the request got the size and
no item.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
src/lib/elementary/efl_ui_collection_view.c | 146 ++++++++++++++++++++-
src/lib/elementary/efl_ui_collection_view.eo | 6 +
src/tests/elementary/efl_ui_test_collection_view.c | 99 ++++++++++++++
3 files changed, 250 insertions(+), 1 deletion(-)
diff --git a/src/lib/elementary/efl_ui_collection_view.c b/src/lib/elementary/efl_ui_collection_view.c
index 389aa801f2..c4e1fbcb5b 100644
--- a/src/lib/elementary/efl_ui_collection_view.c
+++ b/src/lib/elementary/efl_ui_collection_view.c
@@ -232,6 +232,34 @@ EFL_CALLBACKS_ARRAY_DEFINE(active_item_cbs,
{ EFL_INPUT_EVENT_CLICKED, _redirect_item_cb },
{ EFL_INPUT_EVENT_CLICKED_ANY, _redirect_item_cb });
+/* The item showing a row of the selection chain, if it has one. */
+static Efl_Gfx_Entity *
+_row_entity(Efl_Ui_Collection_View_Data *pd, Efl_Model *row)
+{
+ Efl_Ui_Collection_Item_Lookup *lookup;
+ unsigned int index;
+
+ if (!row || !efl_isa(row, EFL_COMPOSITE_MODEL_CLASS)) return NULL;
+ index = efl_composite_model_index_get(row);
+ lookup = (void*) eina_rbtree_inline_lookup(pd->cache, &index, sizeof (index),
+ _cache_tree_lookup, NULL);
+ return lookup ? lookup->item.entity : NULL;
+}
+
+/* The row of the selection chain an item shows: its model is a wrapper of
+ it, which is a wrapper of the application's. */
+static Efl_Model *
+_entity_row(Efl_Gfx_Entity *entity)
+{
+ Efl_Model *model = NULL;
+
+ if (efl_isa(entity, EFL_UI_VIEW_INTERFACE)) model = efl_ui_view_model_get(entity);
+ while (model && !efl_isa(model, EFL_UI_SELECTABLE_INTERFACE) &&
+ efl_isa(model, EFL_COMPOSITE_MODEL_CLASS))
+ model = efl_ui_view_model_get(model);
+ return (model && efl_isa(model, EFL_UI_SELECTABLE_INTERFACE)) ? model : NULL;
+}
+
static void
_entity_cleanup(Efl_Ui_Collection_View *obj, Efl_Ui_Factory *factory,
Efl_Ui_Collection_Item *item, Eina_Array *scheduled_release)
@@ -464,7 +492,10 @@ _model_fetched_cb(Eo *obj, void *data, const Eina_Value v)
request_entity = EINA_TRUE;
}
- if (request_entity)
+ /* An item is built when its size is not known otherwise, and when the
+ request asked for one: knowing the size of a row is no item to show
+ or hand out. */
+ if (request_entity || request->need_entity)
{
request->need_entity = EINA_TRUE;
@@ -1384,6 +1415,30 @@ _viewport_walk_fill(Eina_List *requests,
#endif
+/* Whether a row is selected, as its model says: the item mirrors it, but
+ may not have caught up yet. */
+static Eina_Bool
+_row_selected(Efl_Model *model)
+{
+ Eina_Value *v;
+ Eina_Bool selected = EINA_FALSE;
+
+ if (!model) return EINA_FALSE;
+ v = efl_model_property_get(model, "self.selected");
+ if (eina_value_type_get(v) == EINA_VALUE_TYPE_UCHAR)
+ eina_value_bool_get(v, &selected);
+ eina_value_free(v);
+ return selected;
+}
+
+/* A selected row keeps its item while it is off screen, so that what
+ last_selected hands out stays the object the application was given. */
+static Eina_Bool
+_lookup_kept(Efl_Ui_Collection_Item_Lookup *lookup)
+{
+ return lookup->item.entity && _row_selected(lookup->item.model);
+}
+
// An RbTree has the nice property of sorting content. The smaller than the root being in
// son[1] and the greater than the root in son[0]. Using this we can efficiently walk the
// tree once to take note of all the item that need cleaning.
@@ -1448,6 +1503,24 @@ _idle_cb(void *data, const Efl_Event *event EINA_UNUSED)
_mark_lesser((void*) pd->cache, &mark, lower_end);
_mark_ge((void*) pd->cache, &mark, upper_end);
+ /* A selected row's item stays, out of sight: nothing places it while its
+ row is off screen, and the position manager shows it again when it
+ comes back. */
+ {
+ Eina_Array gone;
+
+ eina_array_step_set(&gone, sizeof (Eina_Array), 16);
+ EINA_ARRAY_ITER_NEXT(&mark, i, lookup, iterator)
+ {
+ if (_lookup_kept(lookup))
+ efl_gfx_entity_visible_set(lookup->item.entity, EINA_FALSE);
+ else
+ eina_array_push(&gone, lookup);
+ }
+ eina_array_flush(&mark);
+ mark = gone;
+ }
+
/* Out of the tree first, cleaned up second.
*
* Releasing an item runs callbacks, and those callbacks walk this same
@@ -1744,6 +1817,28 @@ _manager_content_visible_range_changed_cb(void *data, const Efl_Event *ev)
}
#endif
+/* A row selected while no item shows it -- chosen from code, or never
+ scrolled to -- gets one, kept like any selected row's, so that
+ last_selected has an item to hand out. */
+static void
+_selection_realize_cb(void *data, const Efl_Event *ev EINA_UNUSED)
+{
+ Efl_Ui_Collection_View *obj = data;
+ Efl_Ui_Collection_Request *request = NULL;
+ Eina_List *requests;
+ Efl_Model *row;
+ MY_DATA_GET(obj, pd);
+
+ if (!pd->multi_selectable_async_model) return;
+ row = efl_ui_selectable_last_selected_get(pd->multi_selectable_async_model);
+ if (!row || !efl_isa(row, EFL_COMPOSITE_MODEL_CLASS)) return;
+ if (_row_entity(pd, row)) return;
+
+ requests = _request_add(NULL, &request, efl_composite_model_index_get(row), EINA_TRUE);
+ if (request) requests = eina_list_append(requests, request);
+ _batch_request_flush(requests, obj, pd);
+}
+
EFL_CALLBACKS_ARRAY_DEFINE(manager_cbs,
{ EFL_UI_POSITION_MANAGER_ENTITY_EVENT_CONTENT_SIZE_CHANGED, _manager_content_size_changed_cb },
{ EFL_UI_POSITION_MANAGER_ENTITY_EVENT_CONTENT_MIN_SIZE_CHANGED, _manager_content_min_size_changed_cb },
@@ -2131,6 +2226,9 @@ _efl_ui_collection_view_model_changed(void *data, const Efl_Event *event)
efl_event_callback_forwarder_del(pd->multi_selectable_async_model,
EFL_UI_SELECTABLE_EVENT_SELECTION_CHANGED,
data);
+ efl_event_callback_del(pd->multi_selectable_async_model,
+ EFL_UI_SELECTABLE_EVENT_SELECTION_CHANGED,
+ _selection_realize_cb, data);
efl_composite_detach(data, pd->multi_selectable_async_model);
}
@@ -2185,6 +2283,9 @@ _efl_ui_collection_view_model_changed(void *data, const Efl_Event *event)
efl_event_callback_forwarder_add(pd->multi_selectable_async_model,
EFL_UI_SELECTABLE_EVENT_SELECTION_CHANGED,
data);
+ efl_event_callback_add(pd->multi_selectable_async_model,
+ EFL_UI_SELECTABLE_EVENT_SELECTION_CHANGED,
+ _selection_realize_cb, data);
if (!sizing) model = efl_add_ref(EFL_UI_HOMOGENEOUS_MODEL_CLASS, data,
efl_ui_view_model_set(efl_added, model),
@@ -2374,6 +2475,9 @@ _efl_ui_collection_view_efl_object_invalidate(Eo *obj,
efl_event_callback_forwarder_del(pd->multi_selectable_async_model,
EFL_UI_SELECTABLE_EVENT_SELECTION_CHANGED,
obj);
+ efl_event_callback_del(pd->multi_selectable_async_model,
+ EFL_UI_SELECTABLE_EVENT_SELECTION_CHANGED,
+ _selection_realize_cb, obj);
efl_composite_detach(obj, pd->multi_selectable_async_model);
efl_replace(&pd->multi_selectable_async_model, NULL);
}
@@ -2523,6 +2627,46 @@ _efl_ui_collection_view_efl_ui_widget_focus_state_apply(Eo *obj, Efl_Ui_Collecti
return efl_ui_widget_focus_state_apply(efl_super(obj, MY_CLASS), current_state, configured_state, obj);
}
+/* last_selected and fallback_selection are about items here, as they are for
+ every other widget: the selection itself is the select model's, of rows,
+ and these translate between the two. */
+EOLIAN static Efl_Ui_Selectable *
+_efl_ui_collection_view_efl_ui_single_selectable_last_selected_get(const Eo *obj EINA_UNUSED,
+ Efl_Ui_Collection_View_Data *pd)
+{
+ if (!pd->multi_selectable_async_model) return NULL;
+ return _row_entity(pd, efl_ui_selectable_last_selected_get(pd->multi_selectable_async_model));
+}
+
+EOLIAN static Efl_Ui_Selectable *
+_efl_ui_collection_view_efl_ui_single_selectable_fallback_selection_get(const Eo *obj EINA_UNUSED,
+ Efl_Ui_Collection_View_Data *pd)
+{
+ if (!pd->multi_selectable_async_model) return NULL;
+ return _row_entity(pd, efl_ui_selectable_fallback_selection_get(pd->multi_selectable_async_model));
+}
+
+EOLIAN static void
+_efl_ui_collection_view_efl_ui_single_selectable_fallback_selection_set(Eo *obj,
+ Efl_Ui_Collection_View_Data *pd,
+ Efl_Ui_Selectable *fallback)
+{
+ Efl_Model *row = NULL;
+
+ if (!pd->multi_selectable_async_model) return;
+ if (fallback)
+ {
+ row = _entity_row(fallback);
+ if (!row)
+ {
+ ERR("'%s' is not an item of '%s'", efl_debug_name_get(fallback),
+ efl_debug_name_get(obj));
+ return;
+ }
+ }
+ efl_ui_selectable_fallback_selection_set(pd->multi_selectable_async_model, row);
+}
+
#include "efl_ui_collection_view.eo.c"
#define ITEM_IS_OUTSIDE_VISIBLE(id) id < cpd->start_id || id > cpd->end_id
diff --git a/src/lib/elementary/efl_ui_collection_view.eo b/src/lib/elementary/efl_ui_collection_view.eo
index 669554db29..d393b5ab05 100644
--- a/src/lib/elementary/efl_ui_collection_view.eo
+++ b/src/lib/elementary/efl_ui_collection_view.eo
@@ -23,6 +23,10 @@ class Efl.Ui.Collection_View extends Efl.Ui.Layout_Base implements
Items inside this widget can be selected according to the @Efl.Ui.Multi_Selectable.select_mode
policy, and the selection can be retrieved with @Efl.Ui.Multi_Selectable_Index_Range.selected_ndx_iterator_new.
+ @Efl.Ui.Single_Selectable.last_selected is the item showing the row selected last, as for any
+ other widget; its model is the row. The item of a selected row is kept while the row is
+ scrolled out of sight, so it stays the same object, and a row selected from code that was
+ never shown gets one, a moment after @[Efl.Ui.Single_Selectable.selection_changed].
@since 1.23
]]
@@ -60,6 +64,8 @@ class Efl.Ui.Collection_View extends Efl.Ui.Layout_Base implements
Efl.Ui.Widget_Focus_Manager.focus_manager_create;
Efl.Ui.Focus.Manager.move;
Efl.Ui.Widget.focus_state_apply;
+ Efl.Ui.Single_Selectable.last_selected { get; }
+ Efl.Ui.Single_Selectable.fallback_selection { get; set; }
}
events {
item,realized : Efl.Ui.Item; [[Event triggered when an @Efl.Ui.Item has been provided by the @Efl.Ui.Factory and is about to be used.]]
diff --git a/src/tests/elementary/efl_ui_test_collection_view.c b/src/tests/elementary/efl_ui_test_collection_view.c
index c2bd4aa7ef..e90eee0909 100644
--- a/src/tests/elementary/efl_ui_test_collection_view.c
+++ b/src/tests/elementary/efl_ui_test_collection_view.c
@@ -161,6 +161,104 @@ _count_size_disagreements(const Eina_Log_Domain *d, Eina_Log_Level level,
eina_log_print_cb_stderr(d, level, file, fnc, line, fmt, NULL, args);
}
+/* The row an item shows: the item sits in a view, not in a pack, so it has
+ no index of its own, but its model is the row. */
+static int
+_item_row(Eo *item)
+{
+ Efl_Model *model = NULL;
+
+ if (efl_isa(item, EFL_UI_VIEW_INTERFACE)) model = efl_ui_view_model_get(item);
+ return (model && efl_isa(model, EFL_COMPOSITE_MODEL_CLASS)) ?
+ (int) efl_composite_model_index_get(model) : -1;
+}
+
+static Eina_Value
+_select_child(Eo *o EINA_UNUSED, void *data EINA_UNUSED, const Eina_Value v)
+{
+ Efl_Model *child = NULL;
+ Eina_Value set = eina_value_bool_init(EINA_TRUE);
+
+ eina_value_array_get(&v, 0, &child);
+ efl_model_property_set(child, "self.selected", &set);
+ eina_value_flush(&set);
+ return v;
+}
+
+/* Turns the loop until last_selected is an item showing row index, or gives
+ up; returns the item. */
+static Eo *
+_wait_last_selected(Eo *lv, int index)
+{
+ int i;
+
+ for (i = 0; i < 500; i++)
+ {
+ Eo *item = efl_ui_selectable_last_selected_get(lv);
+
+ if (item && (_item_row(item) == index)) return item;
+ ecore_main_loop_iterate();
+ }
+ return efl_ui_selectable_last_selected_get(lv);
+}
+
+/* What a view says was selected last is an item, as for any other widget,
+ and it stays that item while its row is scrolled away: the view keeps it
+ aside, out of sight, rather than letting it go. A row selected without
+ ever being shown gets an item too. */
+EFL_START_TEST(test_efl_ui_collection_view_last_selected_is_an_item)
+{
+ Efl_Ui_Win *win;
+ Efl_Model *model;
+ Efl_Ui_List_View *lv;
+ Efl_Ui_Factory *fl;
+ Eo *item, *later;
+ int i;
+
+ win = win_add(NULL, "win", EFL_UI_WIN_TYPE_BASIC);
+ efl_gfx_entity_size_set(win, EINA_SIZE2D(100, 100));
+
+ model = _make_model(win);
+ model = efl_add(EFL_UI_SELECT_MODEL_CLASS, efl_main_loop_get(),
+ efl_ui_view_model_set(efl_added, model));
+ fl = efl_add(EFL_UI_LAYOUT_FACTORY_CLASS, win,
+ efl_ui_property_bind(efl_added, "text", "title"),
+ efl_ui_widget_factory_item_class_set(efl_added, EFL_UI_LIST_DEFAULT_ITEM_CLASS));
+ lv = efl_add(EFL_UI_LIST_VIEW_CLASS, win,
+ efl_ui_collection_view_factory_set(efl_added, fl),
+ efl_ui_view_model_set(efl_added, model));
+ efl_content_set(win, lv);
+ get_me_to_those_events(lv);
+
+ click_object_at(lv, 50, 5);
+ item = _wait_last_selected(lv, 0);
+ ck_assert_ptr_nonnull(item);
+ ck_assert(efl_isa(item, EFL_UI_LIST_DEFAULT_ITEM_CLASS));
+ ck_assert_int_eq(_item_row(item), 0);
+ ck_assert(efl_ui_selectable_selected_get(item));
+
+ /* far away, and long enough for the view to let rows' items go */
+ efl_ui_scrollable_content_pos_set(lv, EINA_POSITION2D(0, 100000));
+ get_me_to_those_events(lv);
+ for (i = 0; i < 50; i++)
+ {
+ ecore_main_loop_iterate();
+ }
+
+ ck_assert_ptr_eq(efl_ui_selectable_last_selected_get(lv), item);
+ ck_assert_int_eq(_item_row(item), 0);
+ ck_assert(efl_ui_selectable_selected_get(item));
+ ck_assert(!efl_gfx_entity_visible_get(item));
+
+ /* a row nobody scrolled to, chosen from code */
+ efl_future_then(model, efl_model_children_slice_get(model, 25, 1),
+ .success = _select_child, .success_type = EINA_VALUE_TYPE_ARRAY);
+ later = _wait_last_selected(lv, 25);
+ ck_assert_ptr_nonnull(later);
+ ck_assert_int_eq(_item_row(later), 25);
+}
+EFL_END_TEST
+
/* The sizes the position manager caches and the sizes it places must agree
while the window resizes the view. */
EFL_START_TEST(test_efl_ui_collection_view_sizes_agree)
@@ -215,5 +313,6 @@ void efl_ui_test_collection_view(TCase *tc)
tcase_add_test(tc, test_efl_ui_collection_view_basic);
tcase_add_test(tc, efl_ui_collection_view_manager_twice);
tcase_add_test(tc, test_efl_ui_collection_view_select);
+ tcase_add_test(tc, test_efl_ui_collection_view_last_selected_is_an_item);
tcase_add_test(tc, test_efl_ui_collection_view_sizes_agree);
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.