I’m using gotk3 GTK3 wrapper for GTK3. So yes I’m using GTK3.
I have asked Google actually I’m trying to resize it dynamically according to image box size. Google suggests using Gtk.DrawingArea instead of Gtk.Image and hooking it’s draw signal.
I can’t figure out which signal event to hook for Gtk.Image and how to handle the resize without freezing the main thread.
Also where do I keep the pixbuf everytime I resize?
I can not really help you, as I have not used GtkImage before myself, so we have to wait for other people or for Mr. Bassi again
You start learning GTK with a not that easy task. As you are using GoLang: How good are the Go GTK bindings, and does Go not support GTK4? If my memory is correct, Go has developed its own GUI toolkit, can not remember the name, something like libui? Some people suggested using that Go lib for Nim some years ago, but I have never heard about it again. So I am still struggling with my gintro GTK bindings.
Don’t worry. I can read c, c++, python3, c#, rust, go, nim, java. I’m trying to do hard tasks to try learn more stuff by solving problems rather than walking a paved path. I learn fast this way (like goku lol)
Yes I’ve seen c and c++ (gtkmm) implementations, but I find it somewhere lacking. Everyone suggest using drawing areas where’s there’s draw signal in Gtk.Image too.
I know about golang’s cross platform ui, but I want to learn something new. I’m trying out GTK3 for fun.
Ok, that accepted stackoverflow answer is the worst thing I’ve ever seen in my life.
The actual thing you need to do is to just write your own widget.
Subclass GtkWidget (or GtkDrawingArea I guess)
In your widget subclass, have some setter for the image. Preferrable always work with cairo_surface_t as that is what is being drawn in the end anyway. If you save your images as GdkPixbuf or anything else, convert them to a cairo_surface_t
Override ::draw
3.5) There is a function called gdk_cairo_set_source_pixbuf() that people love to use here. Instead of working with a cairo_surface_t, it takes a GdkPixbuf which is more common. You can do that too, but the function does nothing but convert the pixbuf to a surface and then set that as the source surface. In other words, it’s slow.
In ::draw, you can use simple cairo commands to draw your surface, and scale it using cairo_scale(). Get the size of the widget, the size of the surace, do a bit of math and voila.
DO NOT connect to size-allocate and resize a pixbuf or some garbage. That’s just hilarious.
thanks a lot for mentioning that. i was trying it with size-allocate just about now.
also, whats a faster implementation? i don’t mind using it even if its lenthy, performance matters to me.
also in golang and c/c++ where do i store the full res cairo every time i resize? do i just make it global or can i assign a custom variable to the custom widget somehow (like python has self for its classes)?
What does “load images from reddit” mean? That you’re downloading images during draw or size-allocate? Because that’s inherently broken.
You can load an image at any random point, and save it locally in a cache directory; then load the image data from disk and store it into a Cairo image surface and queue a redraw on the widget that will display the image.
I’ll make http requests when user press a button, then parse the json for preview images, then http request to get those images and store them into pixbufs (from raw http bytes).