Discussion
Loading...

Post

Log in
  • About
  • Code of conduct
  • Privacy
  • Users
  • Instances
  • About Bonfire
Sergey Bugaev
Sergey Bugaev
@bugaevc@floss.social  ·  activity timestamp last week

#GTK gtk has a powerful layout system... unfortunately, one of the common things people try to do with it, which is to make their widget have a fixed aspect ratio, perhaps square, like this:

measure (...) {
*minimum = *natural = for_size;
}

does not work like that at all. In fact, ensuring a fixed aspect ratio is non-trivial, even more so if your contents themselves have a minimum size which varies with the available space along the other orientation.

  • Copy link
  • Flag this post
  • Block
Sergey Bugaev
Sergey Bugaev
@bugaevc@floss.social replied  ·  activity timestamp last week

What many folks don't know is that in fact there's a ready-made widget inside GTK for doing just that, and that's Gtk.AspectFrame! You give it a child widget and a desired aspect ratio, and it ensures the child's allocation is proportional to that.

But... it's an old widget, and turns out, it wasn't implemented correctly at all, either. (At least not by GTK 4 layout rules; perhaps what it did could be fine in the past.)

  • Copy link
  • Flag this comment
  • Block
Sergey Bugaev
Sergey Bugaev
@bugaevc@floss.social replied  ·  activity timestamp last week

So I went and rewrote it. And hopefully it should work properly once the branch is merged.

So please, if you want something to always have a specific aspect ratio, don't attempt to do that thing above which doesn't work, just use Gtk.AspectFrame 😀

  • Copy link
  • Flag this comment
  • Block

bonfire.cafe

A space for Bonfire maintainers and contributors to communicate

bonfire.cafe: About · Code of conduct · Privacy · Users · Instances
Bonfire social · 1.0.1-beta.35 no JS en
Automatic federation enabled
Log in
  • Explore
  • About
  • Members
  • Code of Conduct