I am trying to create a widget derived from Gtk::DrawingArea. It should always expand to the full width of the parent, and it should have a height which is computed from the width (let’s say with a function my_height(int width). However, running my_height(int width) is expensive, so I can only run this for the particular width available to the widget. The content does not have a concept of “natural height” or “minimal height”.
How do I go about doing this? I have tried various ways of overriding get_preferred_width_for_height_vfunc, on_size_allocate and others, but I can’t get this to work. Thanks!
(For completeness: I have looked at the documentation at Custom Containers but that seems to do far more than I can do with my single my_height(int width) function, not to mention that it is rather complex for what I think is a rather simple requirement on widget size).
If I just set the hexpand property, GTK will not know how high to make the widget. So then in on_size_allocate, I get passed the maximal width (good) and a height of 1 (bad). If I do a set_size_request inside the on_size_allocate, nothing happens, and neither does adding a queue_resize call in there.
So in other words: the problem is to make GTK understand how high the widget should be, it can indeed figure out the required width by itself already.