add imageviewer (GTK) newapi

Sun, 20 Oct 2024 10:42:13 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 20 Oct 2024 10:42:13 +0200
branch
newapi
changeset 340
2dd42bd4fe5d
parent 339
b68b5f984074
child 341
c7427cadabd3

add imageviewer (GTK)

application/main.c file | annotate | diff | comparison | revisions
ui/gtk/image.c file | annotate | diff | comparison | revisions
--- 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");
         }
     }
     
--- 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);
     }
 
     

mercurial