awtk/demos/preview_ui.c

82 lines
2.1 KiB
C
Raw Normal View History

2018-03-11 11:26:12 +08:00
/**
* File: demo_main.c
2018-05-15 09:31:58 +08:00
* Author: AWTK Develop Team
2018-03-11 11:26:12 +08:00
* Brief: demo main
*
2018-05-08 10:22:32 +08:00
* Copyright (c) 2018 - 2018 Guangzhou ZHIYUAN Electronics Co.,Ltd.
2018-03-11 11:26:12 +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-06-19 16:29:23 +08:00
#include "tk.h"
2018-03-11 11:26:12 +08:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
2018-06-08 17:03:06 +08:00
#include "base/fs.h"
2018-03-11 11:26:12 +08:00
#include "base/mem.h"
2018-06-19 16:29:23 +08:00
#include "base/utils.h"
#include "resource.h"
2018-07-28 19:45:28 +08:00
#include "base/widget_factory.h"
#include "rich_text/rich_text.h"
2018-03-11 11:26:12 +08:00
#include "ui_loader/ui_loader_xml.h"
2018-06-08 17:03:06 +08:00
#include "ui_loader/ui_loader_default.h"
2018-03-11 11:26:12 +08:00
#include "ui_loader/ui_builder_default.h"
2018-06-08 17:03:06 +08:00
widget_t* preview_ui(const char* filename) {
2018-03-11 11:26:12 +08:00
uint32_t size = 0;
2018-06-15 19:12:34 +08:00
char name[NAME_LEN + 1];
ui_builder_t* builder = NULL;
2018-06-08 17:03:06 +08:00
uint8_t* content = (uint8_t*)fs_read_file(filename, &size);
ui_loader_t* loader = strstr(filename, ".bin") != NULL ? default_ui_loader() : xml_ui_loader();
2018-06-15 19:12:34 +08:00
filename_to_name(filename, name, NAME_LEN);
builder = ui_builder_default(name);
2018-03-11 11:26:12 +08:00
printf("preview %s\n", filename);
2018-03-11 14:21:19 +08:00
return_value_if_fail(content != NULL, NULL);
2018-03-11 11:26:12 +08:00
ui_loader_load(loader, content, size, builder);
2018-06-06 15:57:15 +08:00
TKMEM_FREE(content);
2018-03-11 11:26:12 +08:00
return builder->root;
}
2018-07-28 19:45:28 +08:00
static ret_t register_ext_widgets() {
widget_factory_register(widget_factory(), "rich_text", rich_text_create);
return RET_OK;
}
2018-03-11 11:26:12 +08:00
#if defined(WIN32)
#include <windows.h>
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow) {
int argc = 1;
const char* filename = (lpcmdline && *lpcmdline) ? lpcmdline : "../tools/ui_gen/window1.xml";
#else
#include "base/mem.h"
int main(int argc, char* argv[]) {
const char* filename = argc == 1 ? "../tools/ui_gen/window1.xml" : argv[1];
#endif
widget_t* win = NULL;
2018-05-12 18:28:38 +08:00
tk_init(320, 480);
2018-03-11 11:26:12 +08:00
resource_init();
2018-07-28 19:45:28 +08:00
register_ext_widgets();
2018-06-08 17:03:06 +08:00
win = preview_ui(filename);
2018-04-27 11:23:09 +08:00
tk_run();
2018-03-11 11:26:12 +08:00
return 0;
}