summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorMarcel Hollerbach <mail@marcel-hollerbach.de>2019-08-05 19:07:29 +0200
committerMarcel Hollerbach <mail@marcel-hollerbach.de>2019-08-05 19:49:13 +0200
commit1bd9a8f232ec1891cc396d13d7106aa7c255d78e (patch)
tree5dd46a9b1a892eb2ceb718a3fd414dc3fd937491 /src/lib
parentfc12e7721fd2ea2b39f9a732522e744d43a66840 (diff)
introduce a new interface efl_ui_selectable
this is meant to be implemented by entities that *can* be selectabled (not to be confused with containers that can have selected contents)! ref T8057 Reviewed-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com> Differential Revision: https://phab.enlightenment.org/D9503
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/elementary/Efl_Ui.h1
-rw-r--r--src/lib/elementary/efl_ui_collection.c50
-rw-r--r--src/lib/elementary/efl_ui_item.c14
-rw-r--r--src/lib/elementary/efl_ui_item.eo19
-rw-r--r--src/lib/elementary/efl_ui_selectable.eo21
-rw-r--r--src/lib/elementary/meson.build1
6 files changed, 60 insertions, 46 deletions
diff --git a/src/lib/elementary/Efl_Ui.h b/src/lib/elementary/Efl_Ui.h
index 56fe6a7d5e..74003bd452 100644
--- a/src/lib/elementary/Efl_Ui.h
+++ b/src/lib/elementary/Efl_Ui.h
@@ -259,6 +259,7 @@ typedef Eo Efl_Ui_Spotlight_Indicator;
259# include <efl_ui_list_default_item.eo.h> 259# include <efl_ui_list_default_item.eo.h>
260# include <efl_ui_grid_default_item.eo.h> 260# include <efl_ui_grid_default_item.eo.h>
261# include <efl_ui_list_placeholder_item.eo.h> 261# include <efl_ui_list_placeholder_item.eo.h>
262# include <efl_ui_selectable.eo.h>
262 263
263/** 264/**
264 * Initialize Elementary 265 * Initialize Elementary
diff --git a/src/lib/elementary/efl_ui_collection.c b/src/lib/elementary/efl_ui_collection.c
index c637be0744..2241c5209d 100644
--- a/src/lib/elementary/efl_ui_collection.c
+++ b/src/lib/elementary/efl_ui_collection.c
@@ -371,7 +371,7 @@ deselect_all(Efl_Ui_Collection_Data *pd)
371 while(pd->selected) 371 while(pd->selected)
372 { 372 {
373 Eo *item = eina_list_data_get(pd->selected); 373 Eo *item = eina_list_data_get(pd->selected);
374 efl_ui_item_selected_set(item, EINA_FALSE); 374 efl_ui_selectable_selected_set(item, EINA_FALSE);
375 EINA_SAFETY_ON_TRUE_RETURN(eina_list_data_get(pd->selected) == item); 375 EINA_SAFETY_ON_TRUE_RETURN(eina_list_data_get(pd->selected) == item);
376 } 376 }
377} 377}
@@ -456,41 +456,40 @@ _efl_ui_collection_efl_ui_multi_selectable_select_mode_get(const Eo *obj EINA_UN
456} 456}
457 457
458static void 458static void
459_selected_cb(void *data, const Efl_Event *ev) 459_selection_changed(void *data, const Efl_Event *ev)
460{ 460{
461 Eina_Bool selection = *((Eina_Bool*) ev->info);
461 Eo *obj = data; 462 Eo *obj = data;
462 MY_DATA_GET(obj, pd); 463 MY_DATA_GET(obj, pd);
463 464
464 if (pd->mode == EFL_UI_SELECT_MODE_SINGLE_ALWAYS || pd->mode == EFL_UI_SELECT_MODE_SINGLE) 465 if (selection)
465 { 466 {
466 //we might get the situation that the item is already in the list and selected again, so just free the list, it will be rebuild below 467 if (pd->mode == EFL_UI_SELECT_MODE_SINGLE_ALWAYS || pd->mode == EFL_UI_SELECT_MODE_SINGLE)
467 if (eina_list_data_get(pd->selected) == ev->object)
468 { 468 {
469 pd->selected = eina_list_free(pd->selected); 469 //we might get the situation that the item is already in the list and selected again, so just free the list, it will be rebuild below
470 if (eina_list_data_get(pd->selected) == ev->object)
471 {
472 pd->selected = eina_list_free(pd->selected);
473 }
474 else
475 {
476 deselect_all(pd);
477 }
478
470 } 479 }
471 else 480 else if (pd->mode == EFL_UI_SELECT_MODE_NONE)
472 { 481 {
473 deselect_all(pd); 482 ERR("Selection while mode is NONE, uncaught state!");
483 return;
474 } 484 }
475 485 pd->selected = eina_list_append(pd->selected, ev->object);
486 efl_event_callback_call(obj, EFL_UI_EVENT_ITEM_SELECTED, ev->object);
476 } 487 }
477 else if (pd->mode == EFL_UI_SELECT_MODE_NONE) 488 else
478 { 489 {
479 ERR("Selection while mode is NONE, uncaught state!"); 490 pd->selected = eina_list_remove(pd->selected, ev->object);
480 return; 491 efl_event_callback_call(obj, EFL_UI_EVENT_ITEM_UNSELECTED, ev->object);
481 } 492 }
482 pd->selected = eina_list_append(pd->selected, ev->object);
483 efl_event_callback_call(obj, EFL_UI_EVENT_ITEM_SELECTED, ev->object);
484}
485
486static void
487_unselected_cb(void *data, const Efl_Event *ev)
488{
489 Eo *obj = data;
490 MY_DATA_GET(obj, pd);
491
492 pd->selected = eina_list_remove(pd->selected, ev->object);
493 efl_event_callback_call(obj, EFL_UI_EVENT_ITEM_UNSELECTED, ev->object);
494} 493}
495 494
496static void 495static void
@@ -529,8 +528,7 @@ _redirect_cb(void *data, const Efl_Event *ev)
529 528
530EFL_CALLBACKS_ARRAY_DEFINE(active_item, 529EFL_CALLBACKS_ARRAY_DEFINE(active_item,
531 {EFL_GFX_ENTITY_EVENT_HINTS_CHANGED, _hints_changed_cb}, 530 {EFL_GFX_ENTITY_EVENT_HINTS_CHANGED, _hints_changed_cb},
532 {EFL_UI_EVENT_ITEM_SELECTED, _selected_cb}, 531 {EFL_UI_EVENT_SELECTED_CHANGED, _selection_changed},
533 {EFL_UI_EVENT_ITEM_UNSELECTED, _unselected_cb},
534 {EFL_INPUT_EVENT_PRESSED, _redirect_cb}, 532 {EFL_INPUT_EVENT_PRESSED, _redirect_cb},
535 {EFL_INPUT_EVENT_UNPRESSED, _redirect_cb}, 533 {EFL_INPUT_EVENT_UNPRESSED, _redirect_cb},
536 {EFL_INPUT_EVENT_LONGPRESSED, _redirect_cb}, 534 {EFL_INPUT_EVENT_LONGPRESSED, _redirect_cb},
diff --git a/src/lib/elementary/efl_ui_item.c b/src/lib/elementary/efl_ui_item.c
index c0c863bf73..1ccc987759 100644
--- a/src/lib/elementary/efl_ui_item.c
+++ b/src/lib/elementary/efl_ui_item.c
@@ -142,6 +142,7 @@ static void
142_item_select(Eo *obj, Efl_Ui_Item_Data *pd) 142_item_select(Eo *obj, Efl_Ui_Item_Data *pd)
143{ 143{
144 Efl_Ui_Select_Mode m; 144 Efl_Ui_Select_Mode m;
145
145 if (!pd->parent) 146 if (!pd->parent)
146 return; 147 return;
147 m = efl_ui_select_mode_get(pd->parent); 148 m = efl_ui_select_mode_get(pd->parent);
@@ -150,9 +151,9 @@ _item_select(Eo *obj, Efl_Ui_Item_Data *pd)
150 151
151 ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd); 152 ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd);
152 153
153 pd->selected = EINA_TRUE; 154 Eina_Bool tmp = pd->selected = EINA_TRUE;
154 edje_object_signal_emit(wd->resize_obj, "efl,state,selected", "efl"); 155 edje_object_signal_emit(wd->resize_obj, "efl,state,selected", "efl");
155 efl_event_callback_call(obj, EFL_UI_EVENT_ITEM_SELECTED, NULL); 156 efl_event_callback_call(obj, EFL_UI_EVENT_SELECTED_CHANGED, &tmp);
156} 157}
157 158
158static void 159static void
@@ -161,9 +162,9 @@ _item_unselect(Eo *obj, Efl_Ui_Item_Data *pd)
161 if (!pd->selected) return; 162 if (!pd->selected) return;
162 ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd); 163 ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd);
163 164
164 pd->selected = EINA_FALSE; 165 Eina_Bool tmp = pd->selected =EINA_FALSE;
165 edje_object_signal_emit(wd->resize_obj, "efl,state,unselected", "efl"); 166 edje_object_signal_emit(wd->resize_obj, "efl,state,unselected", "efl");
166 efl_event_callback_call(obj, EFL_UI_EVENT_ITEM_UNSELECTED, NULL); 167 efl_event_callback_call(obj, EFL_UI_EVENT_SELECTED_CHANGED, &tmp);
167} 168}
168 169
169/* Mouse Controls */ 170/* Mouse Controls */
@@ -242,7 +243,7 @@ _efl_ui_item_index_get(const Eo *obj, Efl_Ui_Item_Data *pd)
242} 243}
243 244
244EOLIAN static void 245EOLIAN static void
245_efl_ui_item_selected_set(Eo *obj, Efl_Ui_Item_Data *pd, Eina_Bool select) 246_efl_ui_item_efl_ui_selectable_selected_set(Eo *obj, Efl_Ui_Item_Data *pd, Eina_Bool select)
246{ 247{
247 Eina_Bool selected = !!select; 248 Eina_Bool selected = !!select;
248 ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd); 249 ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd);
@@ -253,7 +254,7 @@ _efl_ui_item_selected_set(Eo *obj, Efl_Ui_Item_Data *pd, Eina_Bool select)
253} 254}
254 255
255EOLIAN static Eina_Bool 256EOLIAN static Eina_Bool
256_efl_ui_item_selected_get(const Eo *obj EINA_UNUSED, Efl_Ui_Item_Data *pd) 257_efl_ui_item_efl_ui_selectable_selected_get(const Eo *obj EINA_UNUSED, Efl_Ui_Item_Data *pd)
257{ 258{
258 return pd->selected; 259 return pd->selected;
259} 260}
@@ -271,3 +272,4 @@ _efl_ui_item_container_get(const Eo *obj EINA_UNUSED, Efl_Ui_Item_Data *pd)
271} 272}
272 273
273#include "efl_ui_item.eo.c" 274#include "efl_ui_item.eo.c"
275#include "efl_ui_selectable.eo.c"
diff --git a/src/lib/elementary/efl_ui_item.eo b/src/lib/elementary/efl_ui_item.eo
index 331f48a8e1..51c9100fec 100644
--- a/src/lib/elementary/efl_ui_item.eo
+++ b/src/lib/elementary/efl_ui_item.eo
@@ -1,4 +1,4 @@
1abstract @beta Efl.Ui.Item extends Efl.Ui.Layout_Base implements Efl.Ui.Container_Selectable, Efl.Input.Clickable 1abstract @beta Efl.Ui.Item extends Efl.Ui.Layout_Base implements Efl.Ui.Selectable, Efl.Input.Clickable
2{ 2{
3 [[Selectable Item abstraction. 3 [[Selectable Item abstraction.
4 4
@@ -6,7 +6,7 @@ abstract @beta Efl.Ui.Item extends Efl.Ui.Layout_Base implements Efl.Ui.Containe
6 like @Efl.Ui.List or @Efl.Ui.Grid, for example. 6 like @Efl.Ui.List or @Efl.Ui.Grid, for example.
7 @Efl.Ui.Item provides user interaction through the @Efl.Input.Clickable mixin. 7 @Efl.Ui.Item provides user interaction through the @Efl.Input.Clickable mixin.
8 Items can be pressed, long-pressed, etc, and appropriate events are generated. 8 Items can be pressed, long-pressed, etc, and appropriate events are generated.
9 @Efl.Ui.Item also implements the @Efl.Ui.Container_Selectable interface, meaning that "selected" and 9 @Efl.Ui.Item also implements the @Efl.Ui.Selectable interface, meaning that "selected" and
10 "unselected" events are automatically generated. 10 "unselected" events are automatically generated.
11 11
12 Classes inheriting from this one only need to deal with the visual representation of the widget. 12 Classes inheriting from this one only need to deal with the visual representation of the widget.
@@ -15,8 +15,8 @@ abstract @beta Efl.Ui.Item extends Efl.Ui.Layout_Base implements Efl.Ui.Containe
15 Some events are converted to edje signals so the theme can react to them: 15 Some events are converted to edje signals so the theme can react to them:
16 @[Efl.Input.Clickable.pressed] -> "efl,state,pressed", 16 @[Efl.Input.Clickable.pressed] -> "efl,state,pressed",
17 @[Efl.Input.Clickable.unpressed] -> "efl,state,unpressed", 17 @[Efl.Input.Clickable.unpressed] -> "efl,state,unpressed",
18 @[Efl.Ui.Container_Selectable.item,selected] -> "efl,state,selected", 18 @[Efl.Ui.Selectable.selected,changed] (true) -> "efl,state,selected",
19 @[Efl.Ui.Container_Selectable.item,unselected] -> "efl,state,unselected". 19 @[Efl.Ui.Selectable.selected,changed] (false) -> "efl,state,unselected".
20 ]] 20 ]]
21 methods { 21 methods {
22 @property index { 22 @property index {
@@ -28,16 +28,6 @@ abstract @beta Efl.Ui.Item extends Efl.Ui.Layout_Base implements Efl.Ui.Containe
28 index : int; [[The index where to find this item in its $container.]] 28 index : int; [[The index where to find this item in its $container.]]
29 } 29 }
30 } 30 }
31 @property selected {
32 [[Item selected state.
33
34 The visual representation of the item will be adjusted accordingly to the new state.
35 This property is also automatically modified in response to user actions.
36 ]]
37 values {
38 select: bool; [[Whether this item is selected or not.]]
39 }
40 }
41 @property container { 31 @property container {
42 [[The container this object is part of. 32 [[The container this object is part of.
43 33
@@ -55,5 +45,6 @@ abstract @beta Efl.Ui.Item extends Efl.Ui.Layout_Base implements Efl.Ui.Containe
55 Efl.Object.constructor; 45 Efl.Object.constructor;
56 Efl.Object.finalize; 46 Efl.Object.finalize;
57 Efl.Object.destructor; 47 Efl.Object.destructor;
48 Efl.Ui.Selectable.selected {get; set;}
58 } 49 }
59} 50}
diff --git a/src/lib/elementary/efl_ui_selectable.eo b/src/lib/elementary/efl_ui_selectable.eo
new file mode 100644
index 0000000000..66a83ee347
--- /dev/null
+++ b/src/lib/elementary/efl_ui_selectable.eo
@@ -0,0 +1,21 @@
1interface Efl.Ui.Selectable {
2 [[Selectable interface for ui objects
3
4 A object implementing this can be selected. When the selected property of this object changes, the selected,changed event is emitted.
5 ]]
6 event_prefix: efl_ui;
7 methods {
8 @property selected {
9 [[The selected state of this object
10
11 A change to this property emits the changed event.
12 ]]
13 values {
14 selected : bool; [[The selected state of this object]]
15 }
16 }
17 }
18 events {
19 selected,changed : bool; [[Called when the selected state has changed]]
20 }
21}
diff --git a/src/lib/elementary/meson.build b/src/lib/elementary/meson.build
index 0ca268998b..8f0c85a12a 100644
--- a/src/lib/elementary/meson.build
+++ b/src/lib/elementary/meson.build
@@ -182,6 +182,7 @@ pub_eo_files = [
182 'efl_ui_position_manager_entity.eo', 182 'efl_ui_position_manager_entity.eo',
183 'efl_ui_position_manager_list.eo', 183 'efl_ui_position_manager_list.eo',
184 'efl_ui_position_manager_grid.eo', 184 'efl_ui_position_manager_grid.eo',
185 'efl_ui_selectable.eo',
185] 186]
186 187
187foreach eo_file : pub_eo_files 188foreach eo_file : pub_eo_files