ftk学习记录(脚本文章)


【声明:版权全部,欢迎转载,请勿用于商业用途。  联系信箱:feixiaoxing @163.com】 


    上一篇说到了对话框。今天就看看结果。




    对话框不复杂,今天我们就来谈一谈脚本。有过android开发经验的朋友都知道,要想开发app,除了须要编写必要的代码,还须要编写一些脚本。脚本主要是用来描写叙述gui使用的。它告诉系统这些gui组件是怎么搭配在一起的。

<?

xml version="1.0" encoding="utf-8"?> <window value="Entry Label" animator="$FTK_ANI_TO_UP" visible="1"> <label id="1" x="5" y="5" w="$ww/4" h="30" value="Name" /> <entry id="2" x="$ww/4+5" y="5" w="3*$ww/4-15" h="30" value="Li XianJing" /> <label id="3" x="5" y="40" w="$ww/4" h="30" value="EMail" /> <entry id="4" x="$ww/4+5" y="40" w="3*$ww/4-15" h="30" value="xianjimli@hotmail.com" /> <label id="5" x="5" y="75" w="$ww/4" h="30" value="Mobile" /> <entry id="6" x="$ww/4+5" y="75" w="3*$ww/4-15" h="30" value="+8613911112222" /> <button id="99" x="5" y="3*$wh/4" w="$ww/2-5" h="50" attr="$FTK_ATTR_INSENSITIVE" value="Save" /> <button id="100" x="$ww/2" y="3*$wh/4" w="$ww/2-5" h="50" attr="$FTK_ATTR_FOCUSED" value="Quit" /> </window>

    

    上面脚本的内容事实上就是描写叙述了label、entry、button是怎么在windows中布局的。当然光有脚本也没有,它还须要代码的配合。眼下,在ftk demo中也存在这种demo代码。


#include "ftk.h"
#include "ftk_xul.h"

const char* t1 = "<window> </window>";

#define IDC_QUIT 100

static Ret button_quit_clicked(void* ctx, void* obj)
{
	ftk_quit();

	return RET_OK;
}

static FtkIconCache* g_icon_cache = NULL;
static FtkBitmap* my_load_image(const char* filename)
{
	return ftk_icon_cache_load(g_icon_cache, filename);
}

int FTK_MAIN(int argc, char* argv[])
{
	if(argc > 1)
	{
		FtkWidget* win = NULL;
		FtkWidget* quit = NULL;
		ftk_init(argc, argv);
		
		g_icon_cache = ftk_icon_cache_create(NULL, "testdata");
		win = ftk_xul_load_file(argv[1], NULL, my_load_image);
		ftk_widget_set_attr(win, FTK_ATTR_QUIT_WHEN_CLOSE);

		quit = ftk_widget_lookup(win, IDC_QUIT);
		ftk_button_set_clicked_listener(quit, button_quit_clicked, win);
		ftk_widget_show_all(win, 1);

		ftk_run();
		ftk_icon_cache_destroy(g_icon_cache);
	}
	else
	{
		ftk_logd("Usage: %s xul
", argv[0]);

		return 0;
	}

	return 0;
}

   代码中除了主要的流程之外,主要是推断程序带了几个參数。有两个參数,继续处理;否则出错返回。那么,代码中做了什么呢。事实上也就是给button加入了一个回调函数而已。


    老规矩,下次见效果图。




版权声明:本文博客原创文章。博客,未经同意,不得转载。

原文地址:https://www.cnblogs.com/zfyouxi/p/4755812.html