]> uap-core.de Git - note.git/commitdiff
use GtkPicture instead of GtkImage for embedded images (GTK4)
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 20 Apr 2025 14:35:01 +0000 (16:35 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 20 Apr 2025 14:35:01 +0000 (16:35 +0200)
application/gtk-image.c
application/gtk-image.h

index aea45da3b76738c0c27bf08fbeeb8e3076e1a17b..fec2cd26ad16a3930f33b2ddb1633c44c4bdf52b 100644 (file)
 #if GTK_MAJOR_VERSION >= 4
 
 GtkWidget* embedded_image_create(GdkPixbuf *pix) {
+    GtkWidget *grid = gtk_grid_new();
+    gtk_widget_add_css_class(grid, "ui_test"); // TODO: replace with new class
+    
     GdkTexture *texture = gdk_texture_new_for_pixbuf(pix);
-    GtkWidget *image = gtk_image_new_from_paintable(GDK_PAINTABLE(texture));
+    GtkWidget *picture = gtk_picture_new_for_paintable(GDK_PAINTABLE(texture));
     
-    int width = gdk_texture_get_width(texture);
-    int height = gdk_texture_get_height(texture);
-    gtk_widget_set_size_request(image, width, height);
+    double width = gdk_texture_get_width(texture);
+    double height = gdk_texture_get_height(texture);
     
-    return image;
+    if(width > EDITOR_IMAGE_MAX_WIDTH) {
+        height = height * (EDITOR_IMAGE_MAX_WIDTH / width);
+        width = EDITOR_IMAGE_MAX_WIDTH;
+    }
+    
+    gtk_widget_set_size_request(picture, width, height);
+    
+    gtk_grid_attach(GTK_GRID(grid), picture, 0, 0, 1, 1);
+    
+    
+    return grid;
 }
 
 #else
index af6cb07aed38f9befd27e298f44859805de2a36a..a710d75fd13ec6fc7bea7e30ab3dec99947d0969 100644 (file)
@@ -33,6 +33,8 @@
 #include "note.h"
 #include "attachment.h"
 
+#define EDITOR_IMAGE_MAX_WIDTH 600
+
 GtkWidget* embedded_image_create(GdkPixbuf *pix);
 
 #endif /* GTK_IMAGE_H */