efl/src/examples/elementary/efl_ui_list_view_example_1.c

91 lines
2.3 KiB
C
Raw Normal View History

// gcc -o efl_ui_list_view_example_1 efl_ui_list_view_example_1.c `pkg-config --cflags --libs elementary`
2017-12-12 16:59:48 -08:00
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#else
# define EFL_BETA_API_SUPPORT 1
#endif
#include <Efl_Ui.h>
2017-12-12 16:59:48 -08:00
#include <Elementary.h>
#include <Efl.h>
#include <Eio.h>
#include <stdio.h>
#define NUM_ITEMS 400
static void
_realized_cb(void *data EINA_UNUSED, const Efl_Event *event)
2017-12-12 16:59:48 -08:00
{
Efl_Gfx_Entity *layout = event->info;
2017-12-12 16:59:48 -08:00
elm_object_focus_allow_set(layout, EINA_TRUE);
}
static Efl_Model*
_make_model(Evas_Object *win)
2017-12-12 16:59:48 -08:00
{
Eina_Value vtext;
efl_model : rename all efl_model based classes. Summary: As the result of discussion in T7458, we need to rename all efl_model based classes with efl_XXX_Model sequence. I've run few vote for this, see V42, V43 few classes are totally renamed as our consideration of misnaming. | Efl.Model_Loop | Efl.Loop_Model | | Efl.Model_Item | Efl.Generic_Model | | Efl.Model_Container | Efl.Container_Model | | Efl.Model_Container_Item | Efl.Container_Model_Item | | Efl.Model_Composite | Efl.Composite_Model | | Efl.Model_Composite_Boolean | Efl.Boolean_Model | | Efl.Model_Composite_Boolean_Chlidren | Efl.Boolean_Model_Item | | Efl.Model_Composite_Selection | Efl.Select_Model | | Efl.Model_Composite_Selection_Chlidren | Efl.Select_Model_Item | | Efl.Model_View | Efl.View_Model | | Eio.Model | Efl.Io.Model | | Efl.Ui.Model_State | Efl.Ui.State_Model | | Efl.Ui.Model_Size | Efl.Ui.Size_Model | | Efl.Ui.Model_Exact | Efl.Ui.Exact_Model | | Efl.Ui.Model_Average | Efl.Ui.Average_Model | | Efl.Ui.Model_Homogeneous | Efl.Ui.Homogeneous_Model | I worried about Efl.Io.Model changes, cause it is widely used, but as I tested, there is no issue found yet. Eldbus.Model also may can changed Efl.Dbus.Model, but I cannot found any class who using Efl.Dbus namespace, so I left it future work. Test Plan: Run the Make Test, it works well except Efl test about selection. there are class inheritance problem exist in select_model, I reported it and will fix it in another patch. Reviewers: cedric, felipealmeida, woohyun, Hermet Reviewed By: cedric Subscribers: lauromoura Tags: #efl, #do_not_merge Differential Revision: https://phab.enlightenment.org/D7533
2019-01-30 20:35:34 -08:00
Efl_Generic_Model *model, *child;
unsigned int i;
2017-12-12 16:59:48 -08:00
char buf[256];
efl_model : rename all efl_model based classes. Summary: As the result of discussion in T7458, we need to rename all efl_model based classes with efl_XXX_Model sequence. I've run few vote for this, see V42, V43 few classes are totally renamed as our consideration of misnaming. | Efl.Model_Loop | Efl.Loop_Model | | Efl.Model_Item | Efl.Generic_Model | | Efl.Model_Container | Efl.Container_Model | | Efl.Model_Container_Item | Efl.Container_Model_Item | | Efl.Model_Composite | Efl.Composite_Model | | Efl.Model_Composite_Boolean | Efl.Boolean_Model | | Efl.Model_Composite_Boolean_Chlidren | Efl.Boolean_Model_Item | | Efl.Model_Composite_Selection | Efl.Select_Model | | Efl.Model_Composite_Selection_Chlidren | Efl.Select_Model_Item | | Efl.Model_View | Efl.View_Model | | Eio.Model | Efl.Io.Model | | Efl.Ui.Model_State | Efl.Ui.State_Model | | Efl.Ui.Model_Size | Efl.Ui.Size_Model | | Efl.Ui.Model_Exact | Efl.Ui.Exact_Model | | Efl.Ui.Model_Average | Efl.Ui.Average_Model | | Efl.Ui.Model_Homogeneous | Efl.Ui.Homogeneous_Model | I worried about Efl.Io.Model changes, cause it is widely used, but as I tested, there is no issue found yet. Eldbus.Model also may can changed Efl.Dbus.Model, but I cannot found any class who using Efl.Dbus namespace, so I left it future work. Test Plan: Run the Make Test, it works well except Efl test about selection. there are class inheritance problem exist in select_model, I reported it and will fix it in another patch. Reviewers: cedric, felipealmeida, woohyun, Hermet Reviewed By: cedric Subscribers: lauromoura Tags: #efl, #do_not_merge Differential Revision: https://phab.enlightenment.org/D7533
2019-01-30 20:35:34 -08:00
model = efl_add(EFL_GENERIC_MODEL_CLASS, win);
2017-12-12 16:59:48 -08:00
eina_value_setup(&vtext, EINA_VALUE_TYPE_STRING);
for (i = 0; i < (NUM_ITEMS); i++)
{
child = efl_model_child_add(model);
snprintf(buf, sizeof(buf), "Item # %i", i);
eina_value_set(&vtext, buf);
efl_model_property_set(child, "title", &vtext);
2017-12-12 16:59:48 -08:00
}
eina_value_flush(&vtext);
return model;
}
EAPI_MAIN int
elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
2017-12-12 16:59:48 -08:00
{
Efl_Ui_Factory *factory;
Evas_Object *win, *li;
2017-12-12 16:59:48 -08:00
Eo *model;
Efl_Ui_Select_Model *selmodel;
2017-12-12 16:59:48 -08:00
win = elm_win_util_standard_add("list_view", "List_View");
2017-12-12 16:59:48 -08:00
elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
elm_win_autodel_set(win, EINA_TRUE);
model = _make_model(win);
selmodel = efl_add(EFL_UI_SELECT_MODEL_CLASS, efl_main_loop_get()
, efl_ui_view_model_set(efl_added, model)
);
2017-12-12 16:59:48 -08:00
factory = efl_add(EFL_UI_LAYOUT_FACTORY_CLASS, win);
efl_ui_widget_factory_item_class_set(factory, EFL_UI_LIST_DEFAULT_ITEM_CLASS);
efl_ui_property_bind(factory, "efl.text", "title");
2017-12-12 16:59:48 -08:00
li = efl_add(EFL_UI_LIST_VIEW_CLASS, win,
efl_ui_collection_view_factory_set(efl_added, factory),
efl_ui_view_model_set(efl_added, selmodel));
2017-12-12 16:59:48 -08:00
efl_event_callback_add(li, EFL_UI_COLLECTION_VIEW_EVENT_ITEM_REALIZED, _realized_cb, NULL);
2017-12-12 16:59:48 -08:00
elm_win_resize_object_add(win, li);
evas_object_size_hint_weight_set(li, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(li, EVAS_HINT_FILL, EVAS_HINT_FILL);
//showall
evas_object_show(li);
evas_object_resize(win, 320, 320);
evas_object_show(win);
elm_run();
return 0;
}
ELM_MAIN()