/* * Build: * gcc $(pkg-config --cflags gtk+-3.0) sample.c -o sample $(pkg-config --libs gtk+-3.0) */ #include enum { MODEL_NAME = 0, N_COLUMNS }; void init_list (GtkWidget *list) { PangoAttrList *attr_list; GtkCellRenderer *renderer; GtkListStore *store; attr_list = pango_attr_list_new (); pango_attr_list_insert (attr_list, pango_attr_insert_hyphens_new (FALSE)); renderer = g_object_new (GTK_TYPE_CELL_RENDERER_TEXT, "attributes", attr_list, "alignment", PANGO_ALIGN_CENTER, "wrap-width", 64, "xalign", 0.5, NULL); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (list), renderer, TRUE); gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (list), renderer, "text", MODEL_NAME); store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING); gtk_icon_view_set_model (GTK_ICON_VIEW (list), GTK_TREE_MODEL (store)); pango_attr_list_unref (attr_list); g_object_unref (store); } void add_to_list (GtkWidget *list, const gchar *str) { GtkTreeIter iter; GtkListStore *store = GTK_LIST_STORE (gtk_icon_view_get_model (GTK_ICON_VIEW (list))); gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, MODEL_NAME, str, -1); } int main (int argc, char *argv[]) { GtkWidget *window, *list; gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (window), "Sample"); gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER); gtk_container_set_border_width (GTK_CONTAINER (window), 5); gtk_window_set_default_size (GTK_WINDOW (window), 640, 480); list = gtk_icon_view_new (); gtk_container_add (GTK_CONTAINER (window), list); init_list (list); add_to_list (list, "Lorem ipsum dolor sit amet, consectetur adipiscing elit."); add_to_list (list, "Vestibulum vestibulum tortor sit amet dui bibendum convallis."); add_to_list (list, "Sed id lorem id tortor interdum sodales."); g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (gtk_main_quit), NULL); gtk_widget_show_all (window); gtk_main (); return 0; }