awtk/demos/demo1_app.c

144 lines
4.0 KiB
C
Raw Normal View History

2018-02-21 19:36:38 +08:00
/**
* File: demo1_app.c
* Author: Li XianJing <xianjimli@hotmail.com>
* Brief: basic class of all widget
*
* Copyright (c) 2018 - 2018 Li XianJing <xianjimli@hotmail.com>
*
* 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"
2018-02-21 19:36:38 +08:00
#include "base/button.h"
#include "base/check_button.h"
#include "base/dialog.h"
#include "base/image.h"
2018-02-21 19:36:38 +08:00
#include "base/image_manager.h"
#include "base/label.h"
#include "base/mem.h"
2018-02-21 19:36:38 +08:00
#include "base/progress_bar.h"
#include "base/utils.h"
2018-03-09 21:54:46 +08:00
#include "base/utf8.h"
#include "base/window.h"
2018-03-10 22:01:10 +08:00
#include "common.c"
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-03-17 07:40:02 +08:00
widget_t* win = dialog_create(NULL, 0, 0, 240, 160);
2018-02-21 19:36:38 +08:00
dialog_t* dialog = DIALOG(win);
widget_set_text(win, L"Dialog");
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-03-31 13:48:18 +08:00
widget_use_style(ok, "1:green_btn");
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-31 13:48:18 +08:00
widget_use_style(cancel, "2:red_btn");
2018-02-21 19:36:38 +08:00
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);
2018-03-09 21:54:46 +08:00
widget_to_xml(win);
2018-02-21 19:36:38 +08:00
code = dialog_modal(win);
2018-03-09 21:54:46 +08:00
log_debug("code=%d\n", code);
2018-02-21 19:36:38 +08:00
widget_destroy(win);
mem_info_dump();
(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;
widget_t* progress_bar = NULL;
widget_t* check_button = NULL;
widget_t* radio_button = NULL;
widget_t* show_dialog = NULL;
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);
image_set_image_name(image, "earth");
2018-02-21 19:36:38 +08:00
2018-03-31 18:41:33 +08:00
image = image_create(win, 100, 230, 200, 200);
2018-03-31 17:37:14 +08:00
image_set_image_name(image, "earth");
2018-03-31 19:48:56 +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-03-31 13:48:18 +08:00
widget_use_style(label, "2:left");
2018-02-21 19:36:38 +08:00
label = label_create(win, 100, 40, 80, 30);
widget_set_text(label, L"Center");
2018-03-31 13:48:18 +08:00
widget_use_style(label, "3:center");
2018-02-21 19:36:38 +08:00
label = label_create(win, 200, 40, 80, 30);
widget_set_text(label, L"Right");
2018-03-31 13:48:18 +08:00
widget_use_style(label, "4:right");
2018-02-21 19:36:38 +08:00
progress_bar = progress_bar_create(win, 10, 80, 168, 30);
widget_set_value(progress_bar, 40);
2018-03-18 11:29:31 +08:00
timer_add(on_timer, progress_bar, 200);
2018-03-11 14:21:19 +08:00
// progress_bar_set_show_text(progress_bar, TRUE);
2018-02-21 19:36:38 +08:00
progress_bar = progress_bar_create(win, 260, 80, 30, 118);
widget_set_value(progress_bar, 40);
progress_bar_set_vertical(progress_bar, TRUE);
2018-03-18 17:02:10 +08:00
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-03-09 21:54:46 +08:00
widget_to_xml(win);
2018-02-21 19:36:38 +08:00
return RET_OK;
}