-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglist.c
144 lines (111 loc) · 3.29 KB
/
glist.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
* glist.c
*
* Created on: May 26, 2020
* Author: inv
*/
#include <efl_extension.h>
#include <dlog.h>
#include "glist.h"
#include "motorica.h"
/*
* Free glist item data with given free function
*/
static void
items_data_free(glist_s *glist, free_func_t free_func);
/*
* Circle general list create
*/
static Evas_Object *
circle_glist_create(Evas_Object *list, Eext_Circle_Surface *circle_surface);
/*-*/
Elm_Object_Item *
glist_append(glist_s *glist, const char *style, Elm_Gen_Item_Text_Get_Cb text_get_cb, void *item_data) {
if (glist->list == NULL) {
dlog_print(DLOG_ERROR, LOG_TAG, "glist->list is NULL");
return NULL;
}
if (style == NULL) {
dlog_print(DLOG_ERROR, LOG_TAG, "style is NULL");
return NULL;
}
Elm_Genlist_Item_Class *itc = elm_genlist_item_class_new();
itc->item_style = style;
itc->func.text_get = text_get_cb;
Elm_Object_Item* item = elm_genlist_item_append(
glist->list, itc, item_data, NULL, ELM_GENLIST_ITEM_NONE, NULL, NULL
);
elm_genlist_item_class_free(itc);
return item;
}
Elm_Object_Item *
glist_insert_after_first(glist_s *glist, const char *style, Elm_Gen_Item_Text_Get_Cb text_get_cb, void *item_data) {
if (glist->list == NULL) {
dlog_print(DLOG_ERROR, LOG_TAG, "glist->list is NULL");
return NULL;
}
if (style == NULL) {
dlog_print(DLOG_ERROR, LOG_TAG, "style is NULL");
return NULL;
}
Elm_Widget_Item* first = elm_genlist_first_item_get(glist->list);
if (first == NULL) {
dlog_print(DLOG_ERROR, LOG_TAG, "elm_genlist_first_item_get is NULL");
return NULL;
}
Elm_Genlist_Item_Class *itc = elm_genlist_item_class_new();
itc->item_style = style;
itc->func.text_get = text_get_cb;
Elm_Object_Item* item = elm_genlist_item_insert_after(
glist->list, itc, item_data, NULL, first, ELM_GENLIST_ITEM_NONE, NULL, NULL
);
elm_genlist_item_class_free(itc);
return item;
}
static Evas_Object *
circle_glist_create(Evas_Object *list, Eext_Circle_Surface *circle_surface) {
Evas_Object *circle_list = eext_circle_object_genlist_add(list, circle_surface);
eext_circle_object_genlist_scroller_policy_set(
circle_list, ELM_SCROLLER_POLICY_OFF, ELM_SCROLLER_POLICY_AUTO
);
eext_rotary_object_event_activated_set(circle_list, EINA_TRUE);
return circle_list;
}
glist_s*
glist_create(Evas_Object *parent, Eext_Circle_Surface *circle_surface,
Evas_Smart_Cb clicked_cb, void *cb_data) {
glist_s *retval = malloc(sizeof(glist_s));
if (retval == NULL) {
dlog_print(DLOG_ERROR, LOG_TAG, "[malloc] failed");
return NULL;
}
retval->list = elm_genlist_add(parent);
retval->circle_list = circle_glist_create(retval->list, circle_surface);
if (clicked_cb != NULL)
evas_object_smart_callback_add(
retval->list, "clicked,double", clicked_cb, cb_data
);
evas_object_show(retval->list);
return retval;
}
static void
items_data_free(glist_s *glist, free_func_t free_func) {
if (free_func != NULL) {
Elm_Widget_Item *it = elm_genlist_first_item_get(glist->list);
while (it != NULL) {
void *data = elm_object_item_data_get(it);
free_func(data);
it = elm_genlist_item_next_get(it);
}
}
}
void
glist_clear(glist_s *glist, free_func_t free_func) {
items_data_free(glist, free_func);
elm_genlist_clear(glist->list);
}
void
glist_free(glist_s *glist, free_func_t free_func) {
items_data_free(glist, free_func);
free(glist);
}