efl: split Efl.Ui.Factory.create stage into constructing and building
authorMarcel Hollerbach <mail@marcel-hollerbach.de>
Tue, 3 Sep 2019 12:48:58 +0000 (14:48 +0200)
committerJongmin Lee <jm105.lee@samsung.com>
Tue, 24 Sep 2019 21:47:13 +0000 (06:47 +0900)
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

src/lib/efl/interfaces/efl_interfaces_main.c
src/lib/efl/interfaces/efl_ui_factory.eo
src/lib/elementary/efl_ui_caching_factory.c
src/lib/elementary/efl_ui_image_factory.c
src/lib/elementary/efl_ui_image_factory.eo
src/lib/elementary/efl_ui_layout_factory.c
src/lib/elementary/efl_ui_layout_factory.eo
src/lib/elementary/efl_ui_widget_factory.c
src/lib/elementary/efl_ui_widget_factory.eo

index 36e962b..4f144be 100644 (file)
@@ -118,15 +118,11 @@ __efl_internal_init(void)
 static Eina_Value
 _efl_ui_view_factory_item_created(Eo *factory, void *data EINA_UNUSED, const Eina_Value v)
 {
-   Efl_Ui_Factory_Item_Created_Event event = { NULL, NULL };
+   Efl_Gfx_Entity *item;
    int len, i;
 
-   EINA_VALUE_ARRAY_FOREACH(&v, len, i, event.item)
-     {
-        event.model = efl_ui_view_model_get(event.item);
-
-        efl_event_callback_call(factory, EFL_UI_FACTORY_EVENT_CREATED, &event);
-     }
+   EINA_VALUE_ARRAY_FOREACH(&v, len, i, item)
+     efl_event_callback_call(factory, EFL_UI_FACTORY_EVENT_ITEM_CREATED, item);
 
    return v;
 }
index eded76f..bd3d84f 100644 (file)
@@ -11,6 +11,8 @@ interface @beta Efl.Ui.Factory extends Efl.Ui.Property_Bind, Efl.Ui.Factory_Bind
      This object represents a Factory in the factory pattern. Objects should be created via the method
      @Efl.Ui.View_Factory.create_with_event, which will in turn call the necessary APIs from this interface.
      Objects created this way should be removed using @.release.
+
+     It is recommended to not create your own @Efl.Ui.Factory and use event handler as much as possible.
    ]]
    methods {
       create @protected {
@@ -31,18 +33,12 @@ interface @beta Efl.Ui.Factory extends Efl.Ui.Property_Bind, Efl.Ui.Factory_Bind
             ui_view: Efl.Gfx.Entity; [[Object to remove.]]
          }
       }
-      building @const {
-         [[This function is called during the creation of an UI object between the @Efl.Object.constructor and
-           @Efl.Object.finalize call.
-
-           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.]]
-         params {
-            ui_view: Efl.Gfx.Entity; [[The UI object being created.]]
-         }
-      }
    }
    events {
-      created: Efl.Ui.Factory_Item_Created_Event; [[Event triggered when an item has been successfully created.]]
+      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).
+                                         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.]]
+      item,building: Efl.Gfx.Entity; [[Event triggered when an item has processed @Efl.Object.finalize, but before all the factory are done building it.
+                                     Note: if the @Efl.Ui.Factory does keep a cache of object, this will be called when object are pulled out of the cache.]]
+      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.]]
    }
 }
index 09ec342..843871e 100644 (file)
@@ -246,8 +246,9 @@ _efl_ui_caching_factory_efl_ui_factory_create(Eo *obj,
         EINA_ITERATOR_FOREACH(models, model)
           {
              w = efl_add(pd->klass, parent,
-                         efl_ui_factory_building(obj, efl_added),
-                         efl_ui_view_model_set(efl_added, model));
+                         efl_ui_view_model_set(efl_added, model),
+                         efl_event_callback_call(obj, EFL_UI_FACTORY_EVENT_ITEM_CONSTRUCTING, efl_added));
+             efl_event_callback_call(obj, EFL_UI_FACTORY_EVENT_ITEM_BUILDING, w);
              eina_value_array_append(&gr->done, w);
           }
 
index 0010570..615f202 100644 (file)
@@ -15,12 +15,23 @@ typedef struct _Efl_Ui_Image_Factory_Data
     Eina_Stringshare *property;
 } Efl_Ui_Image_Factory_Data;
 
+static void
+_efl_ui_image_factory_building(void *data, const Efl_Event *ev)
+{
+   Efl_Ui_Image_Factory_Data *pd = data;
+   Efl_Gfx_Entity *ui_view = ev->info;
+
+   efl_ui_property_bind(ui_view, "filename", pd->property);
+}
+
 EOLIAN static Eo *
 _efl_ui_image_factory_efl_object_constructor(Eo *obj, Efl_Ui_Image_Factory_Data *pd)
 {
    obj = efl_constructor(efl_super(obj, MY_CLASS));
    efl_ui_widget_factory_item_class_set(obj, EFL_UI_IMAGE_CLASS);
 
+   efl_event_callback_add(obj, EFL_UI_FACTORY_EVENT_ITEM_BUILDING, _efl_ui_image_factory_building, pd);
+
    pd->property = NULL;
 
    return obj;
@@ -35,14 +46,6 @@ _efl_ui_image_factory_efl_object_destructor(Eo *obj EINA_UNUSED, Efl_Ui_Image_Fa
    efl_destructor(efl_super(obj, MY_CLASS));
 }
 
-EOLIAN static void
-_efl_ui_image_factory_efl_ui_factory_building(const Eo *obj EINA_UNUSED, Efl_Ui_Image_Factory_Data *pd, Efl_Gfx_Entity *ui_view)
-{
-   efl_ui_property_bind(ui_view, "filename", pd->property);
-
-   efl_ui_factory_building(efl_super(obj, EFL_UI_IMAGE_FACTORY_CLASS), ui_view);
-}
-
 EOLIAN static Eina_Future *
 _efl_ui_image_factory_efl_ui_factory_create(Eo *obj, Efl_Ui_Image_Factory_Data *pd,
                                             Eina_Iterator *models, Efl_Gfx_Entity *parent)
index 57acc7e..5ebcc1c 100644 (file)
@@ -5,7 +5,6 @@ class @beta Efl.Ui.Image_Factory extends Efl.Ui.Caching_Factory
       Efl.Object.constructor;
       Efl.Object.destructor;
       Efl.Ui.Factory.create;
-      Efl.Ui.Factory.building;
       Efl.Ui.Property_Bind.property_bind;
    }
 }
index ed9d975..cfc2749 100644 (file)
@@ -44,6 +44,22 @@ _factory_bind(const Eina_Hash *hash EINA_UNUSED, const void *key, void *data, vo
    return EINA_TRUE;
 }
 
+static void
+_efl_ui_layout_factory_building(void *data, const Efl_Event *event)
+{
+   Efl_Ui_Layout_Factory_Data *pd = data;
+   Efl_Gfx_Entity *ui_view = event->info;
+
+   if (pd->klass || pd->group || pd->style)
+     efl_ui_layout_theme_set(ui_view, pd->klass, pd->group, pd->style);
+
+   eina_hash_foreach(pd->bind.properties, _property_bind, ui_view);
+   eina_hash_foreach(pd->bind.factories, _factory_bind, ui_view);
+
+   efl_gfx_hint_weight_set(ui_view, EFL_GFX_HINT_EXPAND, 0);
+   efl_gfx_hint_fill_set(ui_view, EINA_TRUE, EINA_TRUE);
+}
+
 EOLIAN static Eo *
 _efl_ui_layout_factory_efl_object_constructor(Eo *obj, Efl_Ui_Layout_Factory_Data *pd)
 {
@@ -54,6 +70,8 @@ _efl_ui_layout_factory_efl_object_constructor(Eo *obj, Efl_Ui_Layout_Factory_Dat
    pd->bind.properties = eina_hash_stringshared_new(EINA_FREE_CB(eina_stringshare_del));
    pd->bind.factories = eina_hash_stringshared_new(EINA_FREE_CB(efl_unref));
 
+   efl_event_callback_add(obj, EFL_UI_FACTORY_EVENT_ITEM_BUILDING, _efl_ui_layout_factory_building, pd);
+
    return obj;
 }
 
@@ -70,21 +88,6 @@ _efl_ui_layout_factory_efl_object_destructor(Eo *obj, Efl_Ui_Layout_Factory_Data
    efl_destructor(efl_super(obj, MY_CLASS));
 }
 
-static void
-_efl_ui_layout_factory_efl_ui_factory_building(const Eo *obj, Efl_Ui_Layout_Factory_Data *pd, Efl_Gfx_Entity *ui_view)
-{
-   if (pd->klass || pd->group || pd->style)
-     efl_ui_layout_theme_set(ui_view, pd->klass, pd->group, pd->style);
-
-   eina_hash_foreach(pd->bind.properties, _property_bind, ui_view);
-   eina_hash_foreach(pd->bind.factories, _factory_bind, ui_view);
-
-   efl_gfx_hint_weight_set(ui_view, EFL_GFX_HINT_EXPAND, 0);
-   efl_gfx_hint_fill_set(ui_view, EINA_TRUE, EINA_TRUE);
-
-   efl_ui_factory_building(efl_super(obj, EFL_UI_LAYOUT_FACTORY_CLASS), ui_view);
-}
-
 EOLIAN static void
 _efl_ui_layout_factory_efl_ui_factory_bind_factory_bind(Eo *obj EINA_UNUSED, Efl_Ui_Layout_Factory_Data *pd,
                                                         const char *key, Efl_Ui_Factory *factory)
index 0d35d21..ac15fcc 100644 (file)
@@ -15,7 +15,6 @@ class @beta Efl.Ui.Layout_Factory extends Efl.Ui.Caching_Factory
    implements {
       Efl.Object.constructor;
       Efl.Object.destructor;
-      Efl.Ui.Factory.building;
       Efl.Ui.Property_Bind.property_bind;
       Efl.Ui.Factory_Bind.factory_bind;
    }
index ffb0275..0d6f641 100644 (file)
@@ -69,8 +69,20 @@ _efl_ui_widget_factory_item_class_get(const Eo *obj EINA_UNUSED,
 }
 
 static void
-_efl_ui_widget_factory_efl_ui_factory_building(const Eo *factory EINA_UNUSED, Efl_Ui_Widget_Factory_Data *pd, Efl_Gfx_Entity *ui_view)
+_efl_ui_widget_factory_constructing(void *data EINA_UNUSED, const Efl_Event *ev)
 {
+   Efl_Gfx_Entity *ui_view = ev->info;
+
+   /* NOP */
+   (void)(ui_view);
+}
+
+
+static void
+_efl_ui_widget_factory_building(void *data, const Efl_Event *ev)
+{
+   Efl_Gfx_Entity *ui_view = ev->info;
+   Efl_Ui_Widget_Factory_Data *pd = data;
    const Efl_Model *model;
    Eina_Value *property, *width, *height;
    Efl_Ui_Bind_Part_Data *bpd;
@@ -122,6 +134,21 @@ _efl_ui_widget_factory_efl_ui_factory_building(const Eo *factory EINA_UNUSED, Ef
    eina_value_free(property);
 }
 
+EFL_CALLBACKS_ARRAY_DEFINE(item_callbacks,
+                           { EFL_UI_FACTORY_EVENT_ITEM_CONSTRUCTING, _efl_ui_widget_factory_constructing },
+                           { EFL_UI_FACTORY_EVENT_ITEM_BUILDING, _efl_ui_widget_factory_building })
+
+static Eo *
+_efl_ui_widget_factory_efl_object_constructor(Efl_Ui_Widget_Factory *obj,
+                                              Efl_Ui_Widget_Factory_Data *pd)
+{
+   obj = efl_constructor(efl_super(obj, EFL_UI_WIDGET_FACTORY_CLASS));
+
+   efl_event_callback_array_add(obj, item_callbacks(), pd);
+
+   return obj;
+}
+
 static Efl_Ui_Widget *
 _efl_ui_widget_create(const Efl_Ui_Factory *factory,
                       const Efl_Class *klass, Eo *parent,
@@ -131,7 +158,8 @@ _efl_ui_widget_create(const Efl_Ui_Factory *factory,
 
    w = efl_add(klass, parent,
                efl_ui_view_model_set(efl_added, model),
-               efl_ui_factory_building(factory, efl_added));
+               efl_event_callback_call((Efl_Ui_Factory *) factory, EFL_UI_FACTORY_EVENT_ITEM_CONSTRUCTING, efl_added));
+   efl_event_callback_call((Efl_Ui_Factory *) factory, EFL_UI_FACTORY_EVENT_ITEM_BUILDING, w);
    return w;
 }
 
index fdf537c..c00775a 100644 (file)
@@ -4,7 +4,6 @@ class @beta Efl.Ui.Widget_Factory extends Efl.Loop_Consumer implements Efl.Ui.Fa
 
      This factory is designed to build @Efl.Ui.Widget and optionally set their
      @Efl.Ui.Widget.style if it was connected with @Efl.Ui.Property_Bind.property_bind "$style".
-
    ]]
    methods {
       @property item_class {
@@ -18,9 +17,9 @@ class @beta Efl.Ui.Widget_Factory extends Efl.Loop_Consumer implements Efl.Ui.Fa
    }
 
    implements {
+      Efl.Object.constructor;
       Efl.Ui.Factory.create;
       Efl.Ui.Factory.release;
-      Efl.Ui.Factory.building;
       Efl.Ui.Property_Bind.property_bind;
       Efl.Part.part_get;
    }