/
dialog.c
80 lines (60 loc) · 2.22 KB
/
dialog.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
/**
* File: dialog.c
* Author: AWTK Develop Team
* Brief: dialog demo
*
* 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-16 Li XianJing <xianjimli@hotmail.com> created
*
*/
#include "awtk.h"
static ret_t on_dialog_btn_click(void* ctx, event_t* evt) {
widget_t* win = widget_get_window(WIDGET(evt->target));
window_close(win);
return RET_OK;
}
static ret_t on_show_dialog(void* ctx, event_t* evt) {
widget_t* ok = NULL;
widget_t* cancel = NULL;
widget_t* label = NULL;
widget_t* dlg = dialog_create_simple(NULL, 0, 0, 240, 160);
dialog_set_title(dlg, "Dialog");
ok = button_create(dialog_get_client(dlg), 20, 80, 80, 30);
widget_set_text(ok, L"Go");
cancel = button_create(dialog_get_client(dlg), 140, 80, 80, 30);
widget_set_text(cancel, L"Cancel");
label = label_create(dialog_get_client(dlg), 10, 30, 200, 30);
widget_set_text(label, L"AWTK is cool!");
widget_on(ok, EVT_CLICK, on_dialog_btn_click, (char*)NULL + 1);
widget_on(cancel, EVT_CLICK, on_dialog_btn_click, (char*)NULL + 2);
return RET_OK;
}
ret_t application_init() {
widget_t* win = window_create(NULL, 0, 0, 0, 0);
widget_t* show_dialog = button_create(win, 0, 0, 0, 0);
widget_t* show_dialog_long_press = button_create(win, 0, 0, 0, 0);
widget_set_text(show_dialog, L"Show Dialog");
widget_set_self_layout_params(show_dialog, "center", "middle:-30", "50%", "30");
widget_on(show_dialog, EVT_CLICK, on_show_dialog, NULL);
button_set_enable_long_press(show_dialog_long_press, TRUE);
widget_set_text(show_dialog_long_press, L"Show Dialog On LongPress");
widget_set_self_layout_params(show_dialog_long_press, "center", "middle:30", "80%", "30");
widget_on(show_dialog_long_press, EVT_LONG_PRESS, on_show_dialog, NULL);
widget_layout(win);
return RET_OK;
}
ret_t application_exit() {
log_debug("application_exit\n");
return RET_OK;
}
#include "awtk_main.inc"