/
evo
/
Gtk4-tutorial
Обзор
Документация
Войти
/
evo
/
Gtk4-tutorial
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/misc/list3.c
65 строк
2 KB
M0JXD
Add space for all stat =g_application_run
01 ноя 2025, 03:42
01 ноя 2025, 03:42
4ddec85
Код
Авторство
О чём код?
#include <gtk/gtk.h> char * get_file_name (GtkListItem *item, GFileInfo *info) { return G_IS_FILE_INFO (info) ? g_strdup (g_file_info_get_name (info)) : NULL; } static void app_activate (GApplication *application) { GtkApplication *app = GTK_APPLICATION (application); gtk_window_present (gtk_application_get_active_window(app)); } static void app_startup (GApplication *application) { GtkApplication *app = GTK_APPLICATION (application); GtkWidget *win = gtk_application_window_new (app); gtk_window_set_default_size (GTK_WINDOW (win), 600, 400); GtkWidget *scr = gtk_scrolled_window_new (); gtk_window_set_child (GTK_WINDOW (win), scr); GFile *file = g_file_new_for_path ("."); GtkDirectoryList *dl = gtk_directory_list_new ("standard::name", file); g_object_unref (file); GtkNoSelection *ns = gtk_no_selection_new (G_LIST_MODEL (dl)); const char *ui_string = "<interface>" "<template class=\"GtkListItem\">" "<property name=\"child\">" "<object class=\"GtkLabel\">" "<binding name=\"label\">" "<closure type=\"gchararray\" function=\"get_file_name\">" "<lookup name=\"item\">GtkListItem</lookup>" "</closure>" "</binding>" "</object>" "</property>" "</template>" "</interface>" ; GBytes *gbytes = g_bytes_new_static (ui_string, strlen (ui_string)); GtkListItemFactory *factory = gtk_builder_list_item_factory_new_from_bytes (NULL, gbytes); GtkWidget *lv = gtk_list_view_new (GTK_SELECTION_MODEL (ns), factory); gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (scr), lv); } /* ----- main ----- */ #define APPLICATION_ID "com.github.ToshioCP.list3" int main (int argc, char **argv) { GtkApplication *app; int stat; app = gtk_application_new (APPLICATION_ID, G_APPLICATION_DEFAULT_FLAGS); g_signal_connect (app, "startup", G_CALLBACK (app_startup), NULL); g_signal_connect (app, "activate", G_CALLBACK (app_activate), NULL); stat = g_application_run (G_APPLICATION (app), argc, argv); g_object_unref (app); return stat; }