remove image if exists

This commit is contained in:
2026-01-01 16:48:36 +05:00
parent 51ff8ae6e1
commit 0d29dc3d7e

17
main.c
View File

@@ -3,22 +3,23 @@
typedef struct{
GtkApplication *app;
GtkWidget *window;
GtkWidget *box;
GtkWidget *input;
GtkWidget *window , *box ,*input, *image;
char dir[256];
} Appdata;
static void load_image(Appdata *data){
GError *error = NULL;
if (data->image != NULL){
gtk_box_remove(data->box,GTK_WIDGET(data->image));
}
GdkPixbuf *pix = gdk_pixbuf_new_from_file (("%s", data->dir), &error);
if (pix == NULL) {
g_printerr ("Error loading file: #%d %s\n", error->code, error->message);
g_error_free (error);
if (pix == NULL){
g_printerr("Error loading file: #%d %s\n", error->code, error->message);
g_error_free(error);
exit (1);
}
GtkWidget *widget = gtk_image_new_from_pixbuf (pix);
gtk_box_append(GTK_BOX(data->box),widget);
data->image = gtk_image_new_from_pixbuf(pix);
gtk_box_append(GTK_BOX(data->box),data->image);
}
// activates after enter dir in input