From 2caf468fb42f84cc4aa4e438a84d07c090ac9a70 Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Mon, 20 Jan 2025 22:01:53 +0100 Subject: [PATCH] add mz_files_view_remove_items() for cleaning up child widgets --- mizunara/gtk-filesview.c | 10 ++++++++-- mizunara/gtk-filesview.h | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/mizunara/gtk-filesview.c b/mizunara/gtk-filesview.c index 5299b5a..0ac84dc 100644 --- a/mizunara/gtk-filesview.c +++ b/mizunara/gtk-filesview.c @@ -116,8 +116,6 @@ void mz_files_view_snapshot(GtkWidget *widget, GtkSnapshot *snapshot) { y++; } } - - //gtk_widget_size_allocate(view->items[0].image, &child_allocation, -1); // draw children GtkWidgetClass *cls = mz_files_view_parent_class; @@ -161,6 +159,7 @@ void mz_update_files_view(MzFilesView *view, FilesSection *sections, size_t nums printf("mz_update_files_view\n"); // TODO: free previous files + mz_files_view_remove_items(view); free(view->items); @@ -198,3 +197,10 @@ void mz_update_files_view(MzFilesView *view, FilesSection *sections, size_t nums gtk_widget_queue_draw(GTK_WIDGET(view)); } + +void mz_files_view_remove_items(MzFilesView *view) { + for(size_t i=0;inumitems;i++) { + gtk_widget_unparent(view->items[i].image); + gtk_widget_unparent(view->items[i].label); + } +} diff --git a/mizunara/gtk-filesview.h b/mizunara/gtk-filesview.h index f315b22..54b691b 100644 --- a/mizunara/gtk-filesview.h +++ b/mizunara/gtk-filesview.h @@ -71,6 +71,8 @@ void mz_files_view_snapshot(GtkWidget *widget, GtkSnapshot *snapshot); void mz_update_files_view(MzFilesView *view, FilesSection *sections, size_t numsections); +void mz_files_view_remove_items(MzFilesView *view); + #ifdef __cplusplus } #endif -- 2.43.5