-
Notifications
You must be signed in to change notification settings - Fork 16
/
list_item_click.c
63 lines (52 loc) · 1.73 KB
/
list_item_click.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
/**
* File: basic.c
* Author: AWTK Develop Team
* Brief: demo for open window and install event handlers
*
* Copyright (c) 2018 - 2021 Guangzhou ZHIYUAN Electronics Co.,Ltd.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* License file for more details.
*
*/
/**
* History:
* ================================================================
* 2018-08-18 Li XianJing <xianjimli@hotmail.com> created
*
*/
#include "awtk.h"
#define WIDGET_CUSTOM_PROP_INDEX "index"
static ret_t on_click(void* ctx, event_t* e) {
widget_t* item = WIDGET(ctx);
dialog_info("info", item->name);
log_debug("clicked item index=%d\n", widget_get_prop_int(item, WIDGET_CUSTOM_PROP_INDEX, -1));
return RET_OK;
}
ret_t application_init() {
uint32_t i = 0;
uint32_t n = 100;
widget_t* win = window_create(NULL, 0, 0, 0, 0);
widget_t* list_view = list_view_create(win, 0, 0, win->w, win->h);
widget_t* scroll_view = scroll_view_create(list_view, 0, 0, win->w - 10, win->h);
widget_t* scroll_bar = scroll_bar_create_mobile(list_view, win->w - 10, 0, 10, win->h);
list_view_set_item_height(list_view, 30);
for (i = 0; i < n; i++) {
char text[32] = {0};
widget_t* item = list_item_create(scroll_view, 0, 0, 0, 0);
tk_snprintf(text, sizeof(text), "%d", i);
widget_set_text_utf8(item, text);
widget_set_name(item, text);
widget_on(item, EVT_CLICK, on_click, item);
/*demo custom prop*/
widget_set_prop_int(item, WIDGET_CUSTOM_PROP_INDEX, i);
}
return RET_OK;
}
ret_t application_exit() {
log_debug("application_exit\n");
return RET_OK;
}
#include "awtk_main.inc"