awtk/demos/demo1_app.c

187 lines
5.3 KiB
C
Raw Normal View History

2018-02-21 19:36:38 +08:00
/**
* File: demo1_app.c
2018-05-15 09:31:58 +08:00
* Author: AWTK Develop Team
2019-08-08 10:53:54 +08:00
* Brief: basic demo
2018-02-21 19:36:38 +08:00
*
2020-01-01 11:27:36 +08:00
* Copyright (c) 2018 - 2020 Guangzhou ZHIYUAN Electronics Co.,Ltd.
2018-02-21 19:36:38 +08:00
*
* 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-02-16 Li XianJing <xianjimli@hotmail.com> created
*
*/
2018-02-22 09:04:05 +08:00
#include "base/timer.h"
2018-03-09 21:54:46 +08:00
#include "base/enums.h"
#include "widgets/button.h"
#include "base/dialog.h"
#include "widgets/image.h"
#include "widgets/label.h"
#include "tkc/mem.h"
#include "tkc/utils.h"
#include "tkc/utf8.h"
#include "base/window.h"
#include "widgets/slider.h"
#include "widgets/group_box.h"
#include "widgets/check_button.h"
2018-05-13 07:49:39 +08:00
#include "base/image_manager.h"
#include "widgets/progress_bar.h"
2018-05-13 07:49:39 +08:00
2018-05-12 18:28:38 +08:00
#include "common.inc"
2018-02-21 19:36:38 +08:00
static ret_t on_show_dialog(void* ctx, event_t* e) {
uint32_t code = 0;
widget_t* ok = NULL;
2018-03-09 21:54:46 +08:00
widget_t* label = NULL;
2018-02-21 19:36:38 +08:00
widget_t* cancel = NULL;
2018-07-14 11:35:40 +08:00
widget_t* win = dialog_create_simple(NULL, 0, 0, 240, 160);
2018-02-21 19:36:38 +08:00
dialog_t* dialog = DIALOG(win);
2018-07-14 11:35:40 +08:00
widget_set_text(dialog->title, L"Dialog");
2018-02-21 19:36:38 +08:00
2018-03-17 07:40:02 +08:00
ok = button_create(dialog->client, 20, 80, 80, 30);
2018-03-09 21:54:46 +08:00
widget_set_text(ok, L"Go");
2018-02-21 19:36:38 +08:00
2018-03-17 07:40:02 +08:00
cancel = button_create(dialog->client, 140, 80, 80, 30);
2018-02-21 19:36:38 +08:00
widget_set_text(cancel, L"Cancel");
2018-03-17 07:40:02 +08:00
label = label_create(dialog->client, 10, 30, 200, 30);
2018-03-09 21:54:46 +08:00
widget_set_text(label, L"Are you ready!");
2018-02-21 19:36:38 +08:00
widget_on(ok, EVT_CLICK, on_ok, dialog);
widget_on(cancel, EVT_CLICK, on_cancel, dialog);
code = dialog_modal(win);
2018-05-24 11:18:46 +08:00
log_debug("code=%d\n", (int)code);
2018-02-21 19:36:38 +08:00
2018-08-25 17:30:33 +08:00
(void)code;
tk_mem_dump();
2018-02-21 19:36:38 +08:00
(void)e;
return RET_OK;
}
ret_t application_init() {
widget_t* image = NULL;
widget_t* ok = NULL;
widget_t* label = NULL;
widget_t* cancel = NULL;
2018-04-02 17:35:20 +08:00
widget_t* slider = NULL;
2018-02-21 19:36:38 +08:00
widget_t* progress_bar = NULL;
widget_t* check_button = NULL;
widget_t* radio_button = NULL;
widget_t* show_dialog = NULL;
2018-04-01 19:44:39 +08:00
widget_t* group_box = NULL;
2018-02-21 19:36:38 +08:00
widget_t* win = window_create(NULL, 0, 0, 0, 0);
ok = button_create(win, 10, 5, 80, 30);
widget_set_text(ok, L"Inc");
cancel = button_create(win, 100, 5, 80, 30);
widget_set_text(cancel, L"Dec");
show_dialog = button_create(win, 190, 5, 80, 30);
widget_set_text(show_dialog, L"Dialog");
2018-03-31 18:41:33 +08:00
image = image_create(win, 10, 230, 100, 100);
2018-10-21 12:21:53 +08:00
image_set_image(image, "earth");
2018-07-17 11:27:14 +08:00
image_set_draw_type(image, IMAGE_DRAW_ICON);
2018-02-21 19:36:38 +08:00
2018-09-30 11:37:50 +08:00
image = image_create(win, 100, 230, 100, 100);
2018-10-21 12:21:53 +08:00
image_set_image(image, "earth");
2018-03-31 19:48:56 +08:00
image_set_draw_type(image, IMAGE_DRAW_SCALE);
2018-09-30 11:37:50 +08:00
image = image_create(win, 10, 360, 100, 100);
2018-10-21 12:21:53 +08:00
image_set_image(image, "bricks");
2018-09-30 11:37:50 +08:00
image_set_draw_type(image, IMAGE_DRAW_ICON);
image = image_create(win, 100, 360, 100, 100);
2018-10-21 12:21:53 +08:00
image_set_image(image, "bricks");
2018-09-30 11:37:50 +08:00
image_set_draw_type(image, IMAGE_DRAW_SCALE);
2018-02-21 19:36:38 +08:00
label = label_create(win, 10, 40, 80, 30);
widget_set_text(label, L"Left");
2018-07-17 11:27:14 +08:00
widget_use_style(label, "left");
2018-02-21 19:36:38 +08:00
label = label_create(win, 100, 40, 80, 30);
2018-04-15 17:58:24 +08:00
widget_set_text(label, L"C enter");
2018-05-09 18:15:24 +08:00
#ifdef WITH_STB_FONT
2018-07-17 11:27:14 +08:00
widget_use_style(label, "center");
2018-04-01 19:44:39 +08:00
#else
2018-07-17 11:27:14 +08:00
widget_use_style(label, "center-ap");
2018-04-01 19:44:39 +08:00
#endif
2018-02-21 19:36:38 +08:00
2018-04-01 19:44:39 +08:00
label = label_create(win, 190, 40, 80, 30);
2018-02-21 19:36:38 +08:00
widget_set_text(label, L"Right");
2018-07-17 11:27:14 +08:00
widget_use_style(label, "right");
2018-02-21 19:36:38 +08:00
2018-04-02 17:35:20 +08:00
progress_bar = progress_bar_create(win, 10, 80, 168, 20);
2018-02-21 19:36:38 +08:00
widget_set_value(progress_bar, 40);
2018-05-14 11:53:05 +08:00
timer_add(on_timer, progress_bar, 500);
2018-02-21 19:36:38 +08:00
2018-05-13 07:49:39 +08:00
#ifdef WITH_STB_FONT
2018-04-02 17:35:20 +08:00
progress_bar_set_show_text(progress_bar, TRUE);
#endif
slider = slider_create(win, 10, 105, 168, 20);
widget_set_value(slider, 40);
progress_bar = progress_bar_create(win, 260, 80, 20, 118);
2018-02-21 19:36:38 +08:00
widget_set_value(progress_bar, 40);
progress_bar_set_vertical(progress_bar, TRUE);
2019-11-06 09:19:25 +08:00
timer_add(on_timer, progress_bar, 500);
2018-03-18 17:02:10 +08:00
2018-04-02 17:35:20 +08:00
slider = slider_create(win, 230, 80, 20, 118);
widget_set_value(slider, 40);
slider_set_vertical(slider, TRUE);
2018-03-18 11:29:31 +08:00
widget_on(ok, EVT_CLICK, on_inc, progress_bar);
widget_on(cancel, EVT_CLICK, on_dec, progress_bar);
widget_on(show_dialog, EVT_CLICK, on_show_dialog, NULL);
2018-02-21 19:36:38 +08:00
check_button = check_button_create(win, 10, 150, 80, 30);
widget_set_text(check_button, L"Book");
check_button = check_button_create(win, 100, 150, 80, 30);
widget_set_text(check_button, L"Food");
2018-03-04 08:32:52 +08:00
radio_button = check_button_create_radio(win, 10, 200, 80, 30);
2018-02-21 19:36:38 +08:00
widget_set_text(radio_button, L"Book");
2018-03-04 08:32:52 +08:00
radio_button = check_button_create_radio(win, 100, 200, 80, 30);
2018-02-21 19:36:38 +08:00
widget_set_text(radio_button, L"Food");
2018-03-04 08:32:52 +08:00
radio_button = check_button_create_radio(win, 190, 200, 80, 30);
2018-02-21 19:36:38 +08:00
widget_set_text(radio_button, L"Pencil");
widget_set_value(radio_button, TRUE);
2018-04-01 19:44:39 +08:00
group_box = group_box_create(win, 10, 300, 32 * 3, 32);
2018-07-17 11:27:14 +08:00
widget_use_style(group_box, "box");
2018-04-01 19:44:39 +08:00
radio_button = check_button_create_radio(group_box, 0, 0, 32, 32);
2018-07-17 11:27:14 +08:00
widget_use_style(radio_button, "left");
2018-04-01 19:44:39 +08:00
radio_button = check_button_create_radio(group_box, 32, 0, 32, 32);
2018-07-17 11:27:14 +08:00
widget_use_style(radio_button, "middle");
2018-04-01 19:44:39 +08:00
radio_button = check_button_create_radio(group_box, 64, 0, 32, 32);
2018-07-17 11:27:14 +08:00
widget_use_style(radio_button, "right");
2018-04-01 19:44:39 +08:00
check_button = check_button_create(win, 108, 300, 32, 32);
2018-07-17 11:27:14 +08:00
widget_use_style(check_button, "mute");
2018-04-01 19:44:39 +08:00
2018-02-21 19:36:38 +08:00
return RET_OK;
}
2020-03-19 11:11:32 +08:00
ret_t application_exit() {
log_debug("application_exit\n");
return RET_OK;
}
#include "awtk_main.inc"