dropdownview[i8320]

阅读更多

基本上是从widget_demo中搞出来的。
具体效果参见我发的那个华容道游戏GtkWidget* dropdownview = gtk_drop_down_view_new();

    GtkWidget* option;

    GtkWidget* option_item;

    GtkWidget* label;

 

option_item = gtk_drop_down_item_new();

    label = gtk_label_new("");

    gtk_drop_down_item_set_widget(GTK_DROP_DOWN_ITEM(option_item), label);//这个将一个widget加入到item,必须加。

    gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);//设置对齐方式

    gtk_drop_down_item_set_headline_with_alignment(GTK_DROP_DOWN_ITEM(option_item), "过关记录",0,0);

    gtk_drop_down_view_add_item (GTK_DROP_DOWN_VIEW(dropdownview), GTK_DROP_DOWN_ITEM(option_item), NULL, TRUE);

    g_object_set(option_item, "drop-down-item-style", HORIZONTAL_STYLE, NULL);

 

    GtkBorder border;

    border.left = 0;

    border.right = 0;

    border.top = 0;

    border.bottom = 0;//这个东西搞过CSS的应该知道,我解释不清。 通过样的设置可以将slide_button移上来。

    option_item = gtk_drop_down_item_new();

    g_object_set(option_item,"inner-border",&border,NULL);

    GtkWidget *switch_button = gtk_slide_button_new_with_label("背景音乐");

    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(switch_button), musicOn);

    gtk_drop_down_item_set_widget(GTK_DROP_DOWN_ITEM(option_item), switch_button);

    gtk_drop_down_view_add_item(GTK_DROP_DOWN_VIEW(dropdownview), GTK_DROP_DOWN_ITEM(option_item), NULL, FALSE);

    g_signal_connect(switch_button,"toggled",slide_btn_clicked_cb,NULL);

 

 

option_item = gtk_drop_down_item_new();

    label = gtk_label_new("");

    gtk_drop_down_item_set_widget(GTK_DROP_DOWN_ITEM(option_item), label);

    gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);

    gtk_drop_down_item_set_headline_with_alignment(GTK_DROP_DOWN_ITEM(option_item), "退出游戏",0,0);

    gtk_drop_down_view_add_item (GTK_DROP_DOWN_VIEW(dropdownview), GTK_DROP_DOWN_ITEM(option_item), NULL, TRUE);

 

g_signal_connect(GTK_OBJECT(dropdownview), "clicked-item", G_CALLBACK(drop_down_item_pressed_cb), form);

//添加点击回调。这些不是展开的事件。

 

g_signal_connect (dropdownview, "item-collapsed", G_CALLBACK(drop_down_item_collapsed),NULL);//这个是收缩的事件。

g_signal_connect (dropdownview, "item-expanded", G_CALLBACK(drop_down_item_expanded),NULL);//这个展开的。

 

 

gtk_container_add(GTK_CONTAINER(form), dropdownview);//将他加到form里。 当然如果内容多的话就要加一下可以滚动的scrolled window.
下面是回调函数的实现。得到点击选项事件。void drop_down_item_pressed_cb(GtkDropDownView *view, GtkWidget* item,gpointer data)

//我是直接通过比较headline来确定的。哪位若有更好的方法可以告诉我下。

gchar *headline = gtk_drop_down_item_get_headline(GTK_DROP_DOWN_ITEM(item));

if(strcmp(headline, "退出游戏") == 0)

    {

        exit_app(item,data);

    }

你可能感兴趣的:(游戏,音乐,CSS)