summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Hollerbach <mail@marcel-hollerbach.de>2019-09-03 14:48:58 +0200
committerMarcel Hollerbach <mail@marcel-hollerbach.de>2019-09-24 09:18:47 +0200
commit759ac54e7f779456e01c194861a6d29465766275 (patch)
tree4b0fd9ca8c1eaa3abeebdded9768ee87e8c05331
parent3c0b496ad34289b9e09a1d357bea31fb0069544a (diff)
efl: split Efl.Ui.Factory.create stage into constructing and building
constructing is called during construction time, building is called after finalize. This is usefull for theme related properties that can only be set after the theme is applied, which happens during finalize. Being event allow the user of the factory to add more initialization without needing to implement any new class. Reviewed-by: Marcel Hollerbach <mail@marcel-hollerbach.de> Differential Revision: https://phab.enlightenment.org/D9952
-rw-r--r--src/lib/efl/interfaces/efl_interfaces_main.c10
-rw-r--r--src/lib/efl/interfaces/efl_ui_factory.eo18
-rw-r--r--src/lib/elementary/efl_ui_caching_factory.c5
-rw-r--r--src/lib/elementary/efl_ui_image_factory.c19
-rw-r--r--src/lib/elementary/efl_ui_image_factory.eo1
-rw-r--r--src/lib/elementary/efl_ui_layout_factory.c33
-rw-r--r--src/lib/elementary/efl_ui_layout_factory.eo1
-rw-r--r--src/lib/elementary/efl_ui_widget_factory.c32
-rw-r--r--src/lib/elementary/efl_ui_widget_factory.eo3
9 files changed, 73 insertions, 49 deletions
diff --git a/src/lib/efl/interfaces/efl_interfaces_main.c b/src/lib/efl/interfaces/efl_interfaces_main.c
index 36e962b..4f144be 100644
--- a/src/lib/efl/interfaces/efl_interfaces_main.c
+++ b/src/lib/efl/interfaces/efl_interfaces_main.c
@@ -118,15 +118,11 @@ __efl_internal_init(void)
118static Eina_Value 118static Eina_Value
119_efl_ui_view_factory_item_created(Eo *factory, void *data EINA_UNUSED, const Eina_Value v) 119_efl_ui_view_factory_item_created(Eo *factory, void *data EINA_UNUSED, const Eina_Value v)
120{ 120{
121 Efl_Ui_Factory_Item_Created_Event event = { NULL, NULL }; 121 Efl_Gfx_Entity *item;
122 int len, i; 122 int len, i;
123 123
124 EINA_VALUE_ARRAY_FOREACH(&v, len, i, event.item) 124 EINA_VALUE_ARRAY_FOREACH(&v, len, i, item)
125 { 125 efl_event_callback_call(factory, EFL_UI_FACTORY_EVENT_ITEM_CREATED, item);
126 event.model = efl_ui_view_model_get(event.item);
127
128 efl_event_callback_call(factory, EFL_UI_FACTORY_EVENT_CREATED, &event);
129 }
130 126
131 return v; 127 return v;
132} 128}
diff --git a/src/lib/efl/interfaces/efl_ui_factory.eo b/src/lib/efl/interfaces/efl_ui_factory.eo
index eded76f..bd3d84f 100644
--- a/src/lib/efl/interfaces/efl_ui_factory.eo
+++ b/src/lib/efl/interfaces/efl_ui_factory.eo
@@ -11,6 +11,8 @@ interface @beta Efl.Ui.Factory extends Efl.Ui.Property_Bind, Efl.Ui.Factory_Bind
11 This object represents a Factory in the factory pattern. Objects should be created via the method 11 This object represents a Factory in the factory pattern. Objects should be created via the method
12 @Efl.Ui.View_Factory.create_with_event, which will in turn call the necessary APIs from this interface. 12 @Efl.Ui.View_Factory.create_with_event, which will in turn call the necessary APIs from this interface.
13 Objects created this way should be removed using @.release. 13 Objects created this way should be removed using @.release.
14
15 It is recommended to not create your own @Efl.Ui.Factory and use event handler as much as possible.
14 ]] 16 ]]
15 methods { 17 methods {
16 create @protected { 18 create @protected {
@@ -31,18 +33,12 @@ interface @beta Efl.Ui.Factory extends Efl.Ui.Property_Bind, Efl.Ui.Factory_Bind
31 ui_view: Efl.Gfx.Entity; [[Object to remove.]] 33 ui_view: Efl.Gfx.Entity; [[Object to remove.]]
32 } 34 }
33 } 35 }
34 building @const {
35 [[This function is called during the creation of an UI object between the @Efl.Object.constructor and
36 @Efl.Object.finalize call.
37
38 Note: If the @Efl.Ui.Factory does keep a cache of objects, this won't be called when objects are pulled out
39 of the cache.]]
40 params {
41 ui_view: Efl.Gfx.Entity; [[The UI object being created.]]
42 }
43 }
44 } 36 }
45 events { 37 events {
46 created: Efl.Ui.Factory_Item_Created_Event; [[Event triggered when an item has been successfully created.]] 38 item,constructing: Efl.Gfx.Entity; [[Event triggered when an item is under construction (between the @Efl.Object.constructor and @Efl.Object.finalize call on the item).
39 Note: If the @Efl.Ui.Factory does keep a cache of objects, this won't be called when objects are pulled out of the cache.]]
40 item,building: Efl.Gfx.Entity; [[Event triggered when an item has processed @Efl.Object.finalize, but before all the factory are done building it.
41 Note: if the @Efl.Ui.Factory does keep a cache of object, this will be called when object are pulled out of the cache.]]
42 item,created: Efl.Gfx.Entity; [[Event triggered when an item has been successfully created by the factory and is about to be used by an @Efl.Ui.View.]]
47 } 43 }
48} 44}
diff --git a/src/lib/elementary/efl_ui_caching_factory.c b/src/lib/elementary/efl_ui_caching_factory.c
index 09ec342..843871e 100644
--- a/src/lib/elementary/efl_ui_caching_factory.c
+++ b/src/lib/elementary/efl_ui_caching_factory.c
@@ -246,8 +246,9 @@ _efl_ui_caching_factory_efl_ui_factory_create(Eo *obj,
246 EINA_ITERATOR_FOREACH(models, model) 246 EINA_ITERATOR_FOREACH(models, model)
247 { 247 {
248 w = efl_add(pd->klass, parent, 248 w = efl_add(pd->klass, parent,
249 efl_ui_factory_building(obj, efl_added), 249 efl_ui_view_model_set(efl_added, model),
250 efl_ui_view_model_set(efl_added, model)); 250 efl_event_callback_call(obj, EFL_UI_FACTORY_EVENT_ITEM_CONSTRUCTING, efl_added));
251 efl_event_callback_call(obj, EFL_UI_FACTORY_EVENT_ITEM_BUILDING, w);
251 eina_value_array_append(&gr->done, w); 252 eina_value_array_append(&gr->done, w);
252 } 253 }
253 254
diff --git a/src/lib/elementary/efl_ui_image_factory.c b/src/lib/elementary/efl_ui_image_factory.c
index 0010570..615f202 100644
--- a/src/lib/elementary/efl_ui_image_factory.c
+++ b/src/lib/elementary/efl_ui_image_factory.c
@@ -15,12 +15,23 @@ typedef struct _Efl_Ui_Image_Factory_Data
15 Eina_Stringshare *property; 15 Eina_Stringshare *property;
16} Efl_Ui_Image_Factory_Data; 16} Efl_Ui_Image_Factory_Data;
17 17
18static void
19_efl_ui_image_factory_building(void *data, const Efl_Event *ev)
20{
21 Efl_Ui_Image_Factory_Data *pd = data;
22 Efl_Gfx_Entity *ui_view = ev->info;
23
24 efl_ui_property_bind(ui_view, "filename", pd->property);
25}
26
18EOLIAN static Eo * 27EOLIAN static Eo *
19_efl_ui_image_factory_efl_object_constructor(Eo *obj, Efl_Ui_Image_Factory_Data *pd) 28_efl_ui_image_factory_efl_object_constructor(Eo *obj, Efl_Ui_Image_Factory_Data *pd)
20{ 29{
21 obj = efl_constructor(efl_super(obj, MY_CLASS)); 30 obj = efl_constructor(efl_super(obj, MY_CLASS));
22 efl_ui_widget_factory_item_class_set(obj, EFL_UI_IMAGE_CLASS); 31 efl_ui_widget_factory_item_class_set(obj, EFL_UI_IMAGE_CLASS);
23 32
33 efl_event_callback_add(obj, EFL_UI_FACTORY_EVENT_ITEM_BUILDING, _efl_ui_image_factory_building, pd);
34
24 pd->property = NULL; 35 pd->property = NULL;
25 36
26 return obj; 37 return obj;
@@ -35,14 +46,6 @@ _efl_ui_image_factory_efl_object_destructor(Eo *obj EINA_UNUSED, Efl_Ui_Image_Fa
35 efl_destructor(efl_super(obj, MY_CLASS)); 46 efl_destructor(efl_super(obj, MY_CLASS));
36} 47}
37 48
38EOLIAN static void
39_efl_ui_image_factory_efl_ui_factory_building(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Factory_Data *pd, Efl_Gfx_Entity *ui_view)
40{
41 efl_ui_property_bind(ui_view, "filename", pd->property);
42
43 efl_ui_factory_building(efl_super(obj, EFL_UI_IMAGE_FACTORY_CLASS), ui_view);
44}
45
46EOLIAN static Eina_Future * 49EOLIAN static Eina_Future *
47_efl_ui_image_factory_efl_ui_factory_create(Eo *obj, Efl_Ui_Image_Factory_Data *pd, 50_efl_ui_image_factory_efl_ui_factory_create(Eo *obj, Efl_Ui_Image_Factory_Data *pd,
48 Eina_Iterator *models, Efl_Gfx_Entity *parent) 51 Eina_Iterator *models, Efl_Gfx_Entity *parent)
diff --git a/src/lib/elementary/efl_ui_image_factory.eo b/src/lib/elementary/efl_ui_image_factory.eo
index 57acc7e..5ebcc1c 100644
--- a/src/lib/elementary/efl_ui_image_factory.eo
+++ b/src/lib/elementary/efl_ui_image_factory.eo
@@ -5,7 +5,6 @@ class @beta Efl.Ui.Image_Factory extends Efl.Ui.Caching_Factory
5 Efl.Object.constructor; 5 Efl.Object.constructor;
6 Efl.Object.destructor; 6 Efl.Object.destructor;
7 Efl.Ui.Factory.create; 7 Efl.Ui.Factory.create;
8 Efl.Ui.Factory.building;
9 Efl.Ui.Property_Bind.property_bind; 8 Efl.Ui.Property_Bind.property_bind;
10 } 9 }
11} 10}
diff --git a/src/lib/elementary/efl_ui_layout_factory.c b/src/lib/elementary/efl_ui_layout_factory.c
index ed9d975..cfc2749 100644
--- a/src/lib/elementary/efl_ui_layout_factory.c
+++ b/src/lib/elementary/efl_ui_layout_factory.c
@@ -44,6 +44,22 @@ _factory_bind(const Eina_Hash *hash EINA_UNUSED, const void *key, void *data, vo
44 return EINA_TRUE; 44 return EINA_TRUE;
45} 45}
46 46
47static void
48_efl_ui_layout_factory_building(void *data, const Efl_Event *event)
49{
50 Efl_Ui_Layout_Factory_Data *pd = data;
51 Efl_Gfx_Entity *ui_view = event->info;
52
53 if (pd->klass || pd->group || pd->style)
54 efl_ui_layout_theme_set(ui_view, pd->klass, pd->group, pd->style);
55
56 eina_hash_foreach(pd->bind.properties, _property_bind, ui_view);
57 eina_hash_foreach(pd->bind.factories, _factory_bind, ui_view);
58
59 efl_gfx_hint_weight_set(ui_view, EFL_GFX_HINT_EXPAND, 0);
60 efl_gfx_hint_fill_set(ui_view, EINA_TRUE, EINA_TRUE);
61}
62
47EOLIAN static Eo * 63EOLIAN static Eo *
48_efl_ui_layout_factory_efl_object_constructor(Eo *obj, Efl_Ui_Layout_Factory_Data *pd) 64_efl_ui_layout_factory_efl_object_constructor(Eo *obj, Efl_Ui_Layout_Factory_Data *pd)
49{ 65{
@@ -54,6 +70,8 @@ _efl_ui_layout_factory_efl_object_constructor(Eo *obj, Efl_Ui_Layout_Factory_Dat
54 pd->bind.properties = eina_hash_stringshared_new(EINA_FREE_CB(eina_stringshare_del)); 70 pd->bind.properties = eina_hash_stringshared_new(EINA_FREE_CB(eina_stringshare_del));
55 pd->bind.factories = eina_hash_stringshared_new(EINA_FREE_CB(efl_unref)); 71 pd->bind.factories = eina_hash_stringshared_new(EINA_FREE_CB(efl_unref));
56 72
73 efl_event_callback_add(obj, EFL_UI_FACTORY_EVENT_ITEM_BUILDING, _efl_ui_layout_factory_building, pd);
74
57 return obj; 75 return obj;
58} 76}
59 77
@@ -70,21 +88,6 @@ _efl_ui_layout_factory_efl_object_destructor(Eo *obj, Efl_Ui_Layout_Factory_Data
70 efl_destructor(efl_super(obj, MY_CLASS)); 88 efl_destructor(efl_super(obj, MY_CLASS));
71} 89}
72 90
73static void
74_efl_ui_layout_factory_efl_ui_factory_building(const Eo *obj, Efl_Ui_Layout_Factory_Data *pd, Efl_Gfx_Entity *ui_view)
75{
76 if (pd->klass || pd->group || pd->style)
77 efl_ui_layout_theme_set(ui_view, pd->klass, pd->group, pd->style);
78
79 eina_hash_foreach(pd->bind.properties, _property_bind, ui_view);
80 eina_hash_foreach(pd->bind.factories, _factory_bind, ui_view);
81
82 efl_gfx_hint_weight_set(ui_view, EFL_GFX_HINT_EXPAND, 0);
83 efl_gfx_hint_fill_set(ui_view, EINA_TRUE, EINA_TRUE);
84
85 efl_ui_factory_building(efl_super(obj, EFL_UI_LAYOUT_FACTORY_CLASS), ui_view);
86}
87
88EOLIAN static void 91EOLIAN static void
89_efl_ui_layout_factory_efl_ui_factory_bind_factory_bind(Eo *obj EINA_UNUSED, Efl_Ui_Layout_Factory_Data *pd, 92_efl_ui_layout_factory_efl_ui_factory_bind_factory_bind(Eo *obj EINA_UNUSED, Efl_Ui_Layout_Factory_Data *pd,
90 const char *key, Efl_Ui_Factory *factory) 93 const char *key, Efl_Ui_Factory *factory)
diff --git a/src/lib/elementary/efl_ui_layout_factory.eo b/src/lib/elementary/efl_ui_layout_factory.eo
index 0d35d21..ac15fcc 100644
--- a/src/lib/elementary/efl_ui_layout_factory.eo
+++ b/src/lib/elementary/efl_ui_layout_factory.eo
@@ -15,7 +15,6 @@ class @beta Efl.Ui.Layout_Factory extends Efl.Ui.Caching_Factory
15 implements { 15 implements {
16 Efl.Object.constructor; 16 Efl.Object.constructor;
17 Efl.Object.destructor; 17 Efl.Object.destructor;
18 Efl.Ui.Factory.building;
19 Efl.Ui.Property_Bind.property_bind; 18 Efl.Ui.Property_Bind.property_bind;
20 Efl.Ui.Factory_Bind.factory_bind; 19 Efl.Ui.Factory_Bind.factory_bind;
21 } 20 }
diff --git a/src/lib/elementary/efl_ui_widget_factory.c b/src/lib/elementary/efl_ui_widget_factory.c
index ffb0275..0d6f641 100644
--- a/src/lib/elementary/efl_ui_widget_factory.c
+++ b/src/lib/elementary/efl_ui_widget_factory.c
@@ -69,8 +69,20 @@ _efl_ui_widget_factory_item_class_get(const Eo *obj EINA_UNUSED,
69} 69}
70 70
71static void 71static void
72_efl_ui_widget_factory_efl_ui_factory_building(const Eo *factory EINA_UNUSED, Efl_Ui_Widget_Factory_Data *pd, Efl_Gfx_Entity *ui_view) 72_efl_ui_widget_factory_constructing(void *data EINA_UNUSED, const Efl_Event *ev)
73{ 73{
74 Efl_Gfx_Entity *ui_view = ev->info;
75
76 /* NOP */
77 (void)(ui_view);
78}
79
80
81static void
82_efl_ui_widget_factory_building(void *data, const Efl_Event *ev)
83{
84 Efl_Gfx_Entity *ui_view = ev->info;
85 Efl_Ui_Widget_Factory_Data *pd = data;
74 const Efl_Model *model; 86 const Efl_Model *model;
75 Eina_Value *property, *width, *height; 87 Eina_Value *property, *width, *height;
76 Efl_Ui_Bind_Part_Data *bpd; 88 Efl_Ui_Bind_Part_Data *bpd;
@@ -122,6 +134,21 @@ _efl_ui_widget_factory_efl_ui_factory_building(const Eo *factory EINA_UNUSED, Ef
122 eina_value_free(property); 134 eina_value_free(property);
123} 135}
124 136
137EFL_CALLBACKS_ARRAY_DEFINE(item_callbacks,
138 { EFL_UI_FACTORY_EVENT_ITEM_CONSTRUCTING, _efl_ui_widget_factory_constructing },
139 { EFL_UI_FACTORY_EVENT_ITEM_BUILDING, _efl_ui_widget_factory_building })
140
141static Eo *
142_efl_ui_widget_factory_efl_object_constructor(Efl_Ui_Widget_Factory *obj,
143 Efl_Ui_Widget_Factory_Data *pd)
144{
145 obj = efl_constructor(efl_super(obj, EFL_UI_WIDGET_FACTORY_CLASS));
146
147 efl_event_callback_array_add(obj, item_callbacks(), pd);
148
149 return obj;
150}
151
125static Efl_Ui_Widget * 152static Efl_Ui_Widget *
126_efl_ui_widget_create(const Efl_Ui_Factory *factory, 153_efl_ui_widget_create(const Efl_Ui_Factory *factory,
127 const Efl_Class *klass, Eo *parent, 154 const Efl_Class *klass, Eo *parent,
@@ -131,7 +158,8 @@ _efl_ui_widget_create(const Efl_Ui_Factory *factory,
131 158
132 w = efl_add(klass, parent, 159 w = efl_add(klass, parent,
133 efl_ui_view_model_set(efl_added, model), 160 efl_ui_view_model_set(efl_added, model),
134 efl_ui_factory_building(factory, efl_added)); 161 efl_event_callback_call((Efl_Ui_Factory *) factory, EFL_UI_FACTORY_EVENT_ITEM_CONSTRUCTING, efl_added));
162 efl_event_callback_call((Efl_Ui_Factory *) factory, EFL_UI_FACTORY_EVENT_ITEM_BUILDING, w);
135 return w; 163 return w;
136} 164}
137 165
diff --git a/src/lib/elementary/efl_ui_widget_factory.eo b/src/lib/elementary/efl_ui_widget_factory.eo
index fdf537c..c00775a 100644
--- a/src/lib/elementary/efl_ui_widget_factory.eo
+++ b/src/lib/elementary/efl_ui_widget_factory.eo
@@ -4,7 +4,6 @@ class @beta Efl.Ui.Widget_Factory extends Efl.Loop_Consumer implements Efl.Ui.Fa
4 4
5 This factory is designed to build @Efl.Ui.Widget and optionally set their 5 This factory is designed to build @Efl.Ui.Widget and optionally set their
6 @Efl.Ui.Widget.style if it was connected with @Efl.Ui.Property_Bind.property_bind "$style". 6 @Efl.Ui.Widget.style if it was connected with @Efl.Ui.Property_Bind.property_bind "$style".
7
8 ]] 7 ]]
9 methods { 8 methods {
10 @property item_class { 9 @property item_class {
@@ -18,9 +17,9 @@ class @beta Efl.Ui.Widget_Factory extends Efl.Loop_Consumer implements Efl.Ui.Fa
18 } 17 }
19 18
20 implements { 19 implements {
20 Efl.Object.constructor;
21 Efl.Ui.Factory.create; 21 Efl.Ui.Factory.create;
22 Efl.Ui.Factory.release; 22 Efl.Ui.Factory.release;
23 Efl.Ui.Factory.building;
24 Efl.Ui.Property_Bind.property_bind; 23 Efl.Ui.Property_Bind.property_bind;
25 Efl.Part.part_get; 24 Efl.Part.part_get;
26 } 25 }