Skip to content

Baseline & measuring fixes

Sergey Bugaev requested to merge bugaevc/gtk:baseline-fixes into main

Here's a little reproducer:

<?xml version="1.0" encoding="UTF-8"?>
<interface>
  <object class="GtkWindow">
    <child type="titlebar">
      <object class="GtkHeaderBar">
        <child type="start">
          <object class="GtkButton">
            <property name="icon-name">system-search-symbolic</property>
          </object>
        </child>
        <property name="title-widget">
          <object class="GtkEntry">
            <property name="primary-icon-name">system-search-symbolic</property>
          </object>
        </property>
      </object>
    </child>
  </object>
</interface>

The following screenshot shows three copies of it:

  1. Without the icon in the entry
  2. With the icon added (as in the snippet above)
  3. With the icon and this MR

Screenshot_from_2023-09-02_21-48-32

As you can see, simply adding an icon to the entry causes the headerbar's height to increase by 2px, stretching buttons and other widgets. It's not caused by the icon requiring more space: it fits fine into the entry at the previous height (after all, it does fit into the button).

I traced this to a combination of two issues in measuring; fixing either one restores headerbar height to normal. First, the entry was not reporting its baseline properly in presence of icons (this is why adding an icon triggers the bug). Second, GtkCenterLayout was trying to factor that baseline into its measurements, even though nothing here is baseline-aligned.

Merge request reports