[Disclaimer: All Rights Reserved. You are welcome to reprint it. Do not use it for commercial purposes. Contact Email: feixiaoxing @ 163.com]
Before starting today's article, let's take a look at the previous section.
You can refer to the previous section to see if such a button exists, whether such a wait_box control exists, and whether the wait_box activity is visible. Of course, it is best for qualified friends to compile the demo code and debug each line of code by step.
Today, as shown in the title, we are learning the content of the icon. Simply put, the main purpose of this operation is to display the icon image content in the window. As for how to display the demo code, let's take a look at how the demo code is compiled.
#include "ftk.h"#define IDC_TEST_BUTTON 1000static Ret button_quit_clicked(void* ctx, void* obj){ftk_quit();return RET_OK;}static int i = 0;static Ret button_more_clicked(void* ctx, void* obj){int j = 0;FtkIconViewItem item;FtkWidget* icon_view = ftk_widget_lookup(ctx, 100);item.icon = ftk_theme_load_image(ftk_default_theme(), "flag-32.png");for(j=0; j < 4; j++){char text[100] = {0};ftk_snprintf(text, sizeof(text), "%d", i);item.text = text;ftk_bitmap_ref(item.icon);item.user_data = (void*)i;ftk_icon_view_add(icon_view, &item);i+=1000;}ftk_bitmap_unref(item.icon);return RET_OK;}static Ret item_clicked(void* ctx, void* obj){FtkIconViewItem* item = obj;ftk_logd("%s: %s: user_data=%d\n", __func__, item->text, item->user_data);return RET_OK;}int FTK_MAIN(int argc, char* argv[]){int width = 0;int height = 0;FtkWidget* win = NULL;FtkWidget* button = NULL;FtkWidget* icon_view = NULL;FtkIconViewItem item;ftk_init(argc, argv);win = ftk_app_window_create();width = ftk_widget_width(win);height = ftk_widget_height(win);button = ftk_button_create(win, 10, 0, width/3-10, 60);ftk_widget_set_text(button, "more");ftk_button_set_clicked_listener(button, button_more_clicked, win);ftk_window_set_focus(win, button);button = ftk_button_create(win, 2*width/3, 0, width/3-10, 60);ftk_widget_set_text(button, "quit");ftk_button_set_clicked_listener(button, button_quit_clicked, win);ftk_window_set_focus(win, button);item.icon = ftk_theme_load_image(ftk_default_theme(), "flag-32.png");icon_view = ftk_icon_view_create(win, 5, 70, width-10, height-80);ftk_widget_set_id(icon_view, 100);ftk_icon_view_set_clicked_listener(icon_view, item_clicked, win);for(; i < 4; i++){char text[100] = {0};ftk_snprintf(text, sizeof(text), "%d", i);item.text = text;item.user_data = (void*)i;ftk_icon_view_add(icon_view, &item);}ftk_bitmap_unref(item.icon);ftk_widget_set_text(win, "icon view demo");ftk_widget_show_all(win, 1);ftk_widget_set_attr(win, FTK_ATTR_QUIT_WHEN_CLOSE);ftk_run();return 0;}
As shown in the Code, after necessary initialization, the system immediately creates buttons, icon_view, item, and other objects. Button Object, which we have discussed many times before, is ignored this time. This article mainly learns the icon_view object. Its main purpose is to create an icon_view space in the window. After the space is created successfully, we can add an item object to it through the ftk_icon_view_add function. Is it easy? So what is the role of the button here? We can continue to look at it. If you take a closer look, you can find that the content in button_more_clicked is similar to that in the main function. It is nothing more than adding several items to the icon_view object. Of course, when each item is selected, the system will call the call back function item_clicked to perform necessary additional operations.
To see how it works, and listen to the next decomposition.