mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-11-29 18:48:09 +08:00
add prefix_xml_ui tool and update docs
This commit is contained in:
parent
1c7f84f874
commit
ac8d7f9ebb
@ -84,6 +84,9 @@ demos\demo1
|
||||
|
||||
## 最新动态
|
||||
|
||||
* 2018/03/11
|
||||
* 增加XML界面描述文件预览工具。
|
||||
|
||||
* 2018/03/10
|
||||
* lua绑定及相关示例完成。
|
||||
* 支持从UI描述文件创建界面。
|
||||
|
6
demos/.gitignore
vendored
6
demos/.gitignore
vendored
@ -1,3 +1,5 @@
|
||||
demo1
|
||||
demo1.exp
|
||||
demo1.lib
|
||||
demoui
|
||||
prefix_xml_ui
|
||||
*.exe
|
||||
*.lib
|
||||
|
@ -4,6 +4,11 @@
|
||||
|
||||
* demo1 按传统方式创建界面。
|
||||
* demoui 从UI资源文件中创建界面。
|
||||
* ./prefix\_xml\_ui 预览XML界面描述文件。
|
||||
|
||||
```
|
||||
./prefix\_xml\_ui ../tools/ui_gen/window1.xml
|
||||
```
|
||||
|
||||
### 源代码介绍
|
||||
|
||||
|
@ -10,5 +10,8 @@ env['LINKFLAGS'] = env['OS_SUBSYSTEM_WINDOWS'] + env['LINKFLAGS'];
|
||||
env.Program('demo1', ['demo_main.c', 'demo1_app.c']);
|
||||
env.Program('demoui', ['demo_ui_app.c', 'demo_main.c']);
|
||||
|
||||
env['LIBS'] = ['xml'] + env['LIBS']
|
||||
env.Program('prefix_xml_ui', ['prefix_xml_ui.c']);
|
||||
|
||||
|
||||
|
||||
|
BIN
demos/demoui
BIN
demos/demoui
Binary file not shown.
83
demos/prefix_xml_ui.c
Normal file
83
demos/prefix_xml_ui.c
Normal file
@ -0,0 +1,83 @@
|
||||
/**
|
||||
* File: demo_main.c
|
||||
* Author: Li XianJing <xianjimli@hotmail.com>
|
||||
* Brief: demo main
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include "resource.h"
|
||||
#include "base/lftk.h"
|
||||
#include "base/mem.h"
|
||||
#include "ui_loader/ui_loader_xml.h"
|
||||
#include "ui_loader/ui_builder_default.h"
|
||||
|
||||
static uint32_t s_heap_mem[2048];
|
||||
|
||||
char* read_file(const char* file_name, uint32_t* length) {
|
||||
struct stat st = {0};
|
||||
if (stat(file_name, &st)) {
|
||||
return NULL;
|
||||
} else {
|
||||
char* buffer = (char*)MEM_ALLOC(st.st_size + 1);
|
||||
FILE* fp = fopen(file_name, "rb");
|
||||
fread(buffer, 1, st.st_size, fp);
|
||||
fclose(fp);
|
||||
buffer[st.st_size] = '\0';
|
||||
*length = st.st_size;
|
||||
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
|
||||
widget_t* prefix_xml_ui(const char* filename) {
|
||||
uint32_t size = 0;
|
||||
uint8_t* content = (uint8_t*)read_file(filename, &size);
|
||||
ui_loader_t* loader = xml_ui_loader();
|
||||
ui_builder_t* builder = ui_builder_default();
|
||||
printf("preview %s\n", filename);
|
||||
return_value_if_fail(content != NULL, NULL);
|
||||
ui_loader_load(loader, content, size, builder);
|
||||
free(content);
|
||||
|
||||
return builder->root;
|
||||
}
|
||||
|
||||
#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;
|
||||
|
||||
lftk_init(320, 480, s_heap_mem, sizeof(s_heap_mem));
|
||||
resource_init();
|
||||
win = prefix_xml_ui(filename);
|
||||
lftk_run();
|
||||
widget_destroy(win);
|
||||
|
||||
return 0;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -150,6 +150,10 @@ ret_t window_manager_on_paint_children(widget_t* widget, canvas_t* c) {
|
||||
}
|
||||
}
|
||||
|
||||
if(i < 0) {
|
||||
i = 0;
|
||||
}
|
||||
|
||||
for (; i < nr; i++) {
|
||||
widget_t* iter = (widget_t*)(widget->children->elms[i]);
|
||||
if (iter->visible) {
|
||||
|
Loading…
Reference in New Issue
Block a user