# HG changeset patch # User Olaf Wintermann # Date 1729413733 -7200 # Node ID 2dd42bd4fe5d0871da0153defbd8e9e3b8dce780 # Parent b68b5f984074a560986a0b4a0ad4cf3155fb1032 add imageviewer (GTK) diff -r b68b5f984074 -r 2dd42bd4fe5d application/main.c --- a/application/main.c Sun Oct 13 21:28:09 2024 +0200 +++ b/application/main.c Sun Oct 20 10:42:13 2024 +0200 @@ -231,7 +231,7 @@ } ui_tab(obj, "Tab 5") { ui_button(obj, .label = "Test Button", .icon = "application-x-generic", .onclick = action_button); - ui_imageviewer(obj, .varname = "image"); + ui_imageviewer(obj, .varname = "image", .style_class = "imageviewer"); } } diff -r b68b5f984074 -r 2dd42bd4fe5d ui/gtk/image.c --- a/ui/gtk/image.c Sun Oct 13 21:28:09 2024 +0200 +++ b/ui/gtk/image.c Sun Oct 20 10:42:13 2024 +0200 @@ -37,11 +37,17 @@ UiObject *current = uic_current_obj(obj); GtkWidget *scrolledwindow = SCROLLEDWINDOW_NEW(); +#if GTK_CHECK_VERSION(4, 0, 0) + GtkWidget *image = gtk_picture_new(); +#else GtkWidget *image = gtk_image_new(); +#endif + + ui_set_name_and_style(image, args.name, args.style_class); #if GTK_MAJOR_VERSION < 4 GtkWidget *eventbox = gtk_event_box_new(); - SCROLLEDWINDOW_SET_CHILD(scrolledwindow, event_box); + SCROLLEDWINDOW_SET_CHILD(scrolledwindow, eventbox); gtk_container_add(GTK_CONTAINER(eventbox), image); #else SCROLLEDWINDOW_SET_CHILD(scrolledwindow, image); @@ -68,7 +74,7 @@ } void* ui_imageviewer_get(UiGeneric *g) { - + return g->value; } const char* ui_imageviewer_get_type(UiGeneric *g) { @@ -87,12 +93,16 @@ GdkPixbuf *pixbuf = value; if(pixbuf) { + int width, height; #if GTK_CHECK_VERSION(4, 12, 0) GdkTexture *texture = gdk_texture_new_for_pixbuf(pixbuf); - gtk_image_set_from_paintable(GTK_IMAGE(g->obj), GDK_PAINTABLE(texture)); + gtk_picture_set_paintable(GTK_PICTURE(g->obj), GDK_PAINTABLE(texture)); + width = gdk_texture_get_width(texture); + height = gdk_texture_get_height(texture); #else gtk_image_set_from_pixbuf(GTK_IMAGE(g->obj), pixbuf); #endif + gtk_widget_set_size_request(g->obj, width, height); }