genlist_example_02.c
//Compile with:
//gcc -g genlist_example_02.c -o genlist_example_02 `pkg-config --cflags --libs elementary`
#include <Elementary.h>
#include <time.h>
#define N_ITEMS 300
static Elm_Genlist_Item_Class *_itc = NULL;
static char *
_item_label_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part EINA_UNUSED)
{
time_t t = (time_t)ecore_time_unix_get();
char buf[256];
int i = (int)(uintptr_t)data;
if (i % 2)
{
int n;
snprintf(buf, sizeof(buf), "Very Long Item # %i - realized at %s", i, ctime(&t));
n = strlen(buf);
buf[n - 1] = '\0';
}
else
snprintf(buf, sizeof(buf), "short item # %i", i);
return strdup(buf);
}
static Evas_Object *
_item_content_get(void *data EINA_UNUSED, Evas_Object *obj, const char *part)
{
if (!strcmp(part, "elm.swallow.icon"))
elm_icon_standard_set(ic, "clock");
return ic;
}
static void
_item_sel_cb(void *data, Evas_Object *obj, void *event_info)
{
printf("sel item data [%p] on genlist obj [%p], item pointer [%p]\n",
data, obj, event_info);
}
static void
_show_status_cb(void *data, Evas_Object *o EINA_UNUSED, void *event_info EINA_UNUSED)
{
Evas_Object *list = data;
Evas_Coord x, y, w, h, mx, my;
const Eina_List *selected, *l;
Eina_List *realized;
printf("\nfirst selected item: %p\n", glit);
printf("all selected items (%d): ", eina_list_count(selected));
EINA_LIST_FOREACH(selected, l, glit)
printf("%p ", glit);
printf("\n");
printf("realized items (%d): ", eina_list_count(realized));
// The realized items list should be freed by either eina_list_free() or EINA_LIST_FREE when it is no longer needed
EINA_LIST_FREE(realized, glit)
printf("%p ", glit);
printf("\n");
printf("genlist mode: %d\n", elm_genlist_decorate_mode_get(list));
printf("mode item: %p\n", elm_genlist_decorated_item_get(list));
evas_object_geometry_get(list, &x, &y, &w, &h);
mx = w / 2 + x;
my = h / 2 + y;
glit = elm_genlist_at_xy_item_get(list, mx, my, NULL);
printf("item in the middle of the screen: %p\n", glit);
}
static void
_realize_cb(void *data, Evas_Object *o EINA_UNUSED, void *event_info EINA_UNUSED)
{
Evas_Object *list = data;
}
EAPI_MAIN int
elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
{
Evas_Object *win, *box, *hbox;
Evas_Object *list, *btn;
unsigned int i;
win = elm_win_util_standard_add("genlist", "Genlist - simple");
box = elm_box_add(win);
list = elm_genlist_add(win);
if (!_itc)
{
_itc->item_style = "default";
_itc->func.text_get = _item_label_get;
_itc->func.content_get = _item_content_get;
_itc->func.state_get = NULL;
_itc->func.del = NULL;
}
Eina_Bool hbounce, vbounce, always, no_sel;
always = no_sel = EINA_FALSE;
sel_mode = elm_genlist_select_mode_get(list);
always = EINA_TRUE;
else if (sel_mode == ELM_OBJECT_SELECT_MODE_NONE)
no_sel = EINA_TRUE;
printf("default values:\n");
printf("always select: %d\n", always);
elm_scroller_bounce_get(list, &hbounce, &vbounce);
printf("bounce - horizontal: %d, vertical: %d\n", hbounce, vbounce);
printf("homogeneous: %d\n", elm_genlist_homogeneous_get(list));
printf("horizontal mode: %d\n", elm_genlist_mode_get(list));
printf("longpress timeout: %0.3f\n",
printf("multi selection: %d\n", elm_genlist_multi_select_get(list));
printf("no selection mode: %d\n", no_sel);
elm_scroller_policy_get(list, &hp, &vp);
printf("scroller policy - horizontal: %d, vertical: %d\n", hp, vp);
printf("block count: %d\n", elm_genlist_block_count_get(list));
printf("\n");
for (i = 0; i < N_ITEMS; i++)
{
(void *)(uintptr_t)i, NULL,
_item_sel_cb, NULL);
}
elm_box_pack_end(box, list);
hbox = elm_box_add(win);
elm_box_pack_end(box, hbox);
btn = elm_button_add(win);
elm_object_text_set(btn, "Show status");
evas_object_smart_callback_add(btn, "clicked", _show_status_cb, list);
elm_box_pack_end(hbox, btn);
btn = elm_button_add(win);
elm_object_text_set(btn, "Realize");
evas_object_smart_callback_add(btn, "clicked", _realize_cb, list);
elm_box_pack_end(hbox, btn);
evas_object_resize(win, 200, 320);
return 0;
}
int Evas_Coord
Type used for coordinates (in pixels, int).
Definition: Evas_Common.h:116
#define EVAS_HINT_EXPAND
Use with evas_object_size_hint_weight_set(), evas_object_size_hint_weight_get(), evas_object_size_hin...
Definition: Evas_Common.h:297
@ EVAS_ASPECT_CONTROL_VERTICAL
Use all vertical container space to place an object, using the given aspect.
Definition: Evas_Common.h:377
#define EVAS_HINT_FILL
Use with evas_object_size_hint_align_set(), evas_object_size_hint_align_get(), evas_object_size_hint_...
Definition: Evas_Common.h:298
double ecore_time_unix_get(void)
Retrieves the current UNIX time as a floating point value in seconds.
Definition: ecore_time.c:61
static unsigned int eina_list_count(const Eina_List *list)
Gets the count of the number of items in a list.
#define EINA_LIST_FOREACH(list, l, _data)
Definition for the macro to iterate over a list.
Definition: eina_list.h:1415
#define EINA_LIST_FREE(list, data)
Definition for the macro to remove each list node while having access to each node's data.
Definition: eina_list.h:1629
#define EINA_TRUE
boolean value TRUE (numerical value 1)
Definition: eina_types.h:539
#define EINA_FALSE
boolean value FALSE (numerical value 0)
Definition: eina_types.h:533
unsigned char Eina_Bool
Type to mimic a boolean.
Definition: eina_types.h:527
#define EINA_UNUSED
Used to indicate that a function parameter is purposely unused.
Definition: eina_types.h:339
void elm_box_horizontal_set(Elm_Box *obj, Eina_Bool horizontal)
Set the horizontal orientation.
Definition: elm_box_eo.legacy.c:27
Evas_Object * elm_box_add(Evas_Object *parent)
Add a new box to the parent.
Definition: elm_box.c:363
void elm_box_pack_end(Elm_Box *obj, Efl_Canvas_Object *subobj)
Add an object at the end of the pack list.
Definition: elm_box_eo.legacy.c:57
Evas_Object * elm_button_add(Evas_Object *parent)
Add a new button to the parent's canvas.
Definition: efl_ui_button.c:459
Eo Elm_Object_Item
An Elementary Object item handle.
Definition: elm_object_item.h:6
#define ELM_MAIN()
macro to be used after the elm_main() function
Definition: elm_general.h:556
Eina_Bool elm_policy_set(unsigned int policy, int value)
Set a new policy's value (for a given policy group/identifier).
Definition: elm_main.c:1380
Elm_Object_Select_Mode
Possible values for the selection policy of some widgets.
Definition: elm_general.h:33
void elm_run(void)
Run Elementary's main loop.
Definition: elm_main.c:1357
@ ELM_POLICY_QUIT_LAST_WINDOW_CLOSED
quit when the application's last window is closed
Definition: elm_general.h:248
@ ELM_OBJECT_SELECT_MODE_NONE
no select mode.
Definition: elm_general.h:43
@ ELM_OBJECT_SELECT_MODE_DEFAULT
default select mode.
Definition: elm_general.h:34
@ ELM_OBJECT_SELECT_MODE_ALWAYS
always select mode.
Definition: elm_general.h:39
@ ELM_POLICY_QUIT
under which circumstances the application should quit automatically.
Definition: elm_general.h:227
@ ELM_LIST_LIMIT
Sets a minimum size hint on the list object, so that containers may respect it (and resize itself to ...
Definition: elm_general.h:443
Elm_Object_Select_Mode elm_genlist_select_mode_get(const Elm_Genlist *obj)
Get the genlist select mode.
Definition: elm_genlist_eo.legacy.c:21
void elm_genlist_realized_items_update(Elm_Genlist *obj)
Update the contents of all realized items.
Definition: elm_genlist_eo.legacy.c:189
Elm_Widget_Item * elm_genlist_selected_item_get(const Elm_Genlist *obj)
Get the selected item in the genlist.
Definition: elm_genlist_eo.legacy.c:153
Evas_Object * elm_genlist_add(Evas_Object *parent)
Add a new genlist widget to the given parent Elementary (container) object.
Definition: elm_genlist.c:5998
int elm_genlist_block_count_get(const Elm_Genlist *obj)
Get the maximum number of items within an item block.
Definition: elm_genlist_eo.legacy.c:105
void elm_genlist_mode_set(Elm_Genlist *obj, Elm_List_Mode mode)
This sets the horizontal stretching mode.
Definition: elm_genlist_eo.legacy.c:135
Elm_Widget_Item * elm_genlist_decorated_item_get(const Elm_Genlist *obj)
Get active genlist mode item.
Definition: elm_genlist_eo.legacy.c:147
void elm_genlist_longpress_timeout_set(Elm_Genlist *obj, double timeout)
Set the timeout in seconds for the longpress event.
Definition: elm_genlist_eo.legacy.c:39
Eina_List * elm_genlist_realized_items_get(const Elm_Genlist *obj)
Get a list of realized items in genlist.
Definition: elm_genlist_eo.legacy.c:165
Elm_Widget_Item * elm_genlist_item_append(Elm_Genlist *obj, const Elm_Genlist_Item_Class *itc, const void *data, Elm_Widget_Item *parent, Elm_Genlist_Item_Type type, Evas_Smart_Cb func, const void *func_data)
Append a new item in a given genlist widget.
Definition: elm_genlist_eo.legacy.c:243
Eina_Bool elm_genlist_homogeneous_get(const Elm_Genlist *obj)
Get whether the homogeneous mode is enabled.
Definition: elm_genlist_eo.legacy.c:9
Elm_Widget_Item * elm_genlist_at_xy_item_get(const Elm_Genlist *obj, int x, int y, int *posret)
Get the item that is at the x, y canvas coords.
Definition: elm_genlist_eo.legacy.c:201
Eina_Bool elm_genlist_multi_select_get(const Elm_Genlist *obj)
Get if multi-selection in genlist is enabled or disabled.
Definition: elm_genlist_eo.legacy.c:57
void elm_genlist_multi_select_set(Elm_Genlist *obj, Eina_Bool multi)
Enable or disable multi-selection in the genlist.
Definition: elm_genlist_eo.legacy.c:51
Elm_List_Mode elm_genlist_mode_get(const Elm_Genlist *obj)
Get the horizontal stretching mode.
Definition: elm_genlist_eo.legacy.c:141
const Eina_List * elm_genlist_selected_items_get(const Elm_Genlist *obj)
Get a list of selected items in the genlist.
Definition: elm_genlist_eo.legacy.c:171
void elm_genlist_block_count_set(Elm_Genlist *obj, int count)
Set the maximum number of items within an item block.
Definition: elm_genlist_eo.legacy.c:99
double elm_genlist_longpress_timeout_get(const Elm_Genlist *obj)
Get the timeout in seconds for the longpress event.
Definition: elm_genlist_eo.legacy.c:45
Elm_Genlist_Item_Class * elm_genlist_item_class_new(void)
Create a new genlist item class in a given genlist widget.
Definition: elm_genlist.c:8392
void elm_genlist_homogeneous_set(Elm_Genlist *obj, Eina_Bool homogeneous)
Enable/disable homogeneous mode.
Definition: elm_genlist_eo.legacy.c:3
void elm_genlist_select_mode_set(Elm_Genlist *obj, Elm_Object_Select_Mode mode)
Set the genlist select mode.
Definition: elm_genlist_eo.legacy.c:15
Eina_Bool elm_genlist_decorate_mode_get(const Elm_Genlist *obj)
Get Genlist decorate mode.
Definition: elm_genlist_eo.legacy.c:81
@ ELM_GENLIST_ITEM_NONE
Simple item.
Definition: elm_general.h:349
Eina_Bool elm_icon_standard_set(Evas_Object *obj, const char *name)
Set the icon by icon standards names.
Definition: elm_icon.c:885
Evas_Object * elm_icon_add(Evas_Object *parent)
Add a new icon object to the parent.
Definition: elm_icon.c:613
void elm_scroller_policy_set(Evas_Object *obj, Elm_Scroller_Policy policy_h, Elm_Scroller_Policy policy_v)
Set the scrollbar visibility policy.
Definition: elm_scroller.c:945
Elm_Scroller_Policy
Type that controls when scrollbars should appear.
Definition: elm_scroller_legacy.h:14
@ ELM_SCROLLER_POLICY_OFF
Never show scrollbars.
Definition: elm_scroller_legacy.h:17
@ ELM_SCROLLER_POLICY_ON
Always show scrollbars.
Definition: elm_scroller_legacy.h:16
void elm_scroller_policy_get(const Evas_Object *obj, Elm_Scroller_Policy *policy_h, Elm_Scroller_Policy *policy_v)
Get scrollbar visibility policy.
Definition: elm_scroller.c:964
void elm_scroller_bounce_set(Evas_Object *obj, Eina_Bool h_bounce, Eina_Bool v_bounce)
Set bouncing behavior.
Definition: elm_scroller.c:1050
void elm_scroller_bounce_get(const Evas_Object *obj, Eina_Bool *h_bounce, Eina_Bool *v_bounce)
Get the bounce behaviour.
Definition: elm_scroller.c:1060
Evas_Object * elm_win_util_standard_add(const char *name, const char *title)
Adds a window object with standard setup.
Definition: efl_ui_win.c:9582
void elm_win_resize_object_add(Eo *obj, Evas_Object *subobj)
Add subobj as a resize object of window obj.
Definition: efl_ui_win.c:8997
void elm_win_autodel_set(Eo *obj, Eina_Bool autodel)
Set the window's autodel state.
Definition: efl_ui_win.c:6194
EVAS_API void evas_object_show(Evas_Object *eo_obj)
Makes the given Evas object visible.
Definition: evas_object_main.c:1814
EVAS_API void evas_object_geometry_get(const Evas_Object *eo_obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
Retrieves the position and (rectangular) size of the given Evas object.
Definition: evas_object_main.c:1335
EVAS_API void evas_object_size_hint_weight_set(Evas_Object *obj, double x, double y)
Sets the hints for an object's weight.
Definition: evas_object_main.c:2638
Efl_Canvas_Object Evas_Object
An Evas Object handle.
Definition: Evas_Common.h:185
EVAS_API void evas_object_size_hint_align_set(Evas_Object *obj, double x, double y)
Sets the hints for an object's alignment.
Definition: evas_object_main.c:2650
EVAS_API void evas_object_size_hint_aspect_set(Evas_Object *obj, Evas_Aspect_Control aspect, Evas_Coord w, Evas_Coord h)
Sets the hints for an object's aspect ratio.
Definition: evas_object_main.c:2581
EVAS_API void evas_object_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
Changes the size of the given Evas object.
Definition: evas_object_main.c:1236
EVAS_API void evas_object_smart_callback_add(Evas_Object *eo_obj, const char *event, Evas_Smart_Cb func, const void *data)
Add (register) a callback function to the smart event specified by event on the smart object obj.
Definition: evas_object_smart.c:1040
Type for a generic double linked list.
Definition: eina_list.h:318
Elm_Gen_Item_State_Get_Cb state_get
State fetching class function for genlist/gengrid item classes.
Definition: elm_gen.h:101
Elm_Gen_Item_Del_Cb del
Deletion class function for genlist/gengrid item classes.
Definition: elm_gen.h:102
Elm_Gen_Item_Content_Get_Cb content_get
Content fetching class function for genlist/gengrid item classes.
Definition: elm_gen.h:100
Elm_Gen_Item_Text_Get_Cb text_get
Text fetching class function for genlist/gengrid item classes.
Definition: elm_gen.h:99
Gengrid or Genlist item class definition.
Definition: elm_gen.h:109
Elm_Gen_Item_Class_Functions func
Set of callbacks.
Definition: elm_gen.h:126
const char * item_style
Name of the visual style to use for this item.
Definition: elm_gen.h:118