ftk学习记(combox篇)

Posted lytwajue

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ftk学习记(combox篇)相关的知识,希望对你有一定的参考价值。

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


    上一篇文章谈到了多窗体,还是依照约定看一下效果是什么样的。


技术分享


    假设大家细心一点。就会发现窗体中的label显示为window01,这事实上是由于我们已经添加了一个窗体,有兴趣的朋友能够尝试编译一下。如题所看到的,今天讨论的是combox。所谓的combox,事实上就是从给出的若干个选择挑选出一个就可以。

闲话少说,还是看代码。


#include "ftk.h"

#define IDC_TEST_BUTTON 1000
static Ret button_quit_clicked(void* ctx, void* obj)
{
	ftk_quit();

	return RET_OK;
}

int FTK_MAIN(int argc, char* argv[])
{
	int width = 0;
	int height = 0;
	FtkWidget* win = NULL;
	FtkWidget* button = NULL;
	FtkWidget* combo_box = NULL;

	ftk_init(argc, argv);
	
	win = ftk_app_window_create();
	width = ftk_widget_width(win);
	height = ftk_widget_height(win);
	
	width = width/2 - 10;
	combo_box = ftk_combo_box_create(win, 0, height/4, width, 50);
	ftk_combo_box_set_text(combo_box, "1 second");
	ftk_combo_box_append(combo_box, NULL, "1 second");
	ftk_combo_box_append(combo_box, NULL, "2 seconds");
	ftk_combo_box_append(combo_box, NULL, "3 seconds");
	combo_box = ftk_combo_box_create(win, width + 10, height/4, width, 50);
	ftk_combo_box_set_text(combo_box, "1 second");
	ftk_combo_box_append(combo_box, NULL, "1 second");
	ftk_combo_box_append(combo_box, NULL, "2 seconds");
	ftk_combo_box_append(combo_box, NULL, "3 seconds");
	ftk_combo_box_append(combo_box, NULL, "4 seconds");
	ftk_combo_box_append(combo_box, NULL, "5 seconds");
	ftk_combo_box_append(combo_box, NULL, "6 seconds");
	ftk_combo_box_append(combo_box, NULL, "7 seconds");
	ftk_combo_box_append(combo_box, NULL, "8 seconds");
	ftk_combo_box_append(combo_box, NULL, "9 seconds");
	ftk_combo_box_append(combo_box, NULL, "0 seconds");
	ftk_combo_box_append(combo_box, NULL, "0 seconds");

	button = ftk_button_create(win, width/2, height/2, width, 60);
	ftk_widget_set_text(button, "quit");
	ftk_button_set_clicked_listener(button, button_quit_clicked, win);
	ftk_window_set_focus(win, button);

	combo_box = ftk_combo_box_create(win, 0, 3*height/4+5, width, 50);
	ftk_combo_box_set_text(combo_box, "1 second");
	ftk_combo_box_append(combo_box, NULL, "1 second");
	ftk_combo_box_append(combo_box, NULL, "2 seconds");
	ftk_combo_box_append(combo_box, NULL, "3 seconds");
	combo_box = ftk_combo_box_create(win, width + 10, 3*height/4+5, width, 50);
	ftk_combo_box_set_text(combo_box, "1 second");
	ftk_combo_box_append(combo_box, NULL, "1 second");
	ftk_combo_box_append(combo_box, NULL, "2 seconds");
	ftk_combo_box_append(combo_box, NULL, "3 seconds");
	ftk_combo_box_append(combo_box, NULL, "4 seconds");
	ftk_combo_box_append(combo_box, NULL, "5 seconds");
	ftk_combo_box_append(combo_box, NULL, "6 seconds");
	ftk_combo_box_append(combo_box, NULL, "7 seconds");
	ftk_combo_box_append(combo_box, NULL, "8 seconds");
	ftk_combo_box_append(combo_box, NULL, "9 seconds");
	ftk_combo_box_append(combo_box, NULL, "0 seconds");
	ftk_combo_box_append(combo_box, NULL, "0 seconds");
	
	ftk_widget_set_text(win, "ComboBox Demo");
	ftk_widget_show_all(win, 1);
	ftk_widget_set_attr(win, FTK_ATTR_QUIT_WHEN_CLOSE);

	ftk_run();

	return 0;
}

    相信大家看了上面的代码就不操心了。假设想创建combox,直接调用函数ftk_combo_box_create就可以;假设须要加入条目,调用函数ftk_combo_box_append就可以;假设须要设定默认选项,调用ftk_combo_box_set_text函数就可以。就是这么简单。


    下次看效果图。














以上是关于ftk学习记(combox篇)的主要内容,如果未能解决你的问题,请参考以下文章

ftk学习记(label篇)

ftk学习记(label篇)

ftk学习记(首篇)

ftk学习记(输入框篇)

Atom编辑器折腾记_(15)JS代码片段补全(插件:javascript-snippets)

浙大学习记之学习篇一