ftk学习记(combox篇)

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


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


ftk学习记(combox篇)_第1张图片


    如果大家细心一点,就会发现窗口中的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篇))