Allow for auto-scaling of image in Gtk4

In the following MWE, we can resize the window and the contained image fills out the space accordingly (while retaining the aspect ratio):

using Gtk4, GtkObservables
using Colors

win = GtkWindow("Example")
h = 100
c = canvas(h, h)
f = GtkAspectFrame(h, h, 1, false)
f[] = c.widget
push!(win, f)
img = Observable(rand(RGB, h, h))
redraw = Gtk4.draw(c, img) do cnvs, img
    copy!(cnvs, img)
end

But if I want to add more components (e.g. dropdown), and to that end I put the image in a GtkBox:

win = GtkWindow("Example")
win[] = bx = GtkBox(:v) # this will contain my image AND my dropdown
h = 100
c = canvas(h, h)
f = GtkAspectFrame(h, h, 1, false)
f[] = c.widget
push!(bx, f) # let's put that image in that container
img = Observable(rand(RGB, h, h))
redraw = Gtk4.draw(c, img) do cnvs, img
    copy!(cnvs, img)
end

This breaks. The image is static and does not expand to the resized window.

How can I get this to work?

The issue is that GtkDrawingArea’s properties “vexpand” and “hexpand” are false by default.

Try

widget(c).hexpand = widget(c).vexpand = true

I think most often people want the canvas to expand, so maybe we should set these properties to true by default in GtkObservable’s canvas.

That worked! Thanks!

we should set these properties to true by default in GtkObservable’s canvas.

In hopes of crating a PR to fix this, I tried to find where in Gtk4 or GtkObservables hexpand and vexpand are set to false but I only found instances in examples, documentations, and a player widget. Where exactly do you suggest this default should be set?

The properties are not currently set by the package, so they use the default settings from GTK4. I would put it in the constructor for GtkObservables. I’m trying to keep Gtk4 fairly close to GTK4 as far as defaults are concerned.