AdwClamp causing GtkListView height rendering issues with GtkScrolledWindow

Hello. I’m experiencing a height rendering problem with a GtkListView inside an AdwClamp within a GtkScrolledWindow. The clamp seems to be interfering with the listview’s height calculation based on the viewport width.

My setup looks like this:

<child>
  <object class="GtkScrolledWindow" id="preview_scroller">
    <property name="hexpand">true</property>
    <property name="vexpand">true</property>
    <child>
      <object class="AdwClamp">
        <property name="maximum-size">890</property>
        <property name="tightening-threshold">560</property>
        <property name="vexpand">true</property>
        <child>
          <object class="GtkListView" id="preview_list">
            <property name="hexpand">true</property>
            <property name="vexpand">true</property>
            <style>
              <class name="preview_pane_inner"/>
            </style>
          </object>
        </child>
      </object>
    </child>
  </object>
</child>

The problem is that while the listview items are properly constrained to the width of the viewport, the overall listview height is rendering incorrectly:

  • When the pane and the listview items are narrow, the listview is too tall, leaving empty space at the bottom
  • When the pane and the listview items are wide, the listview is not tall enough, making it impossible to scroll to the end of the list

Screenshots attached below showing both cases (both are scrolled to the bottom of the viewport even though the scrollbars have automatically hidden).

This issue doesn’t happen when I don’t use the AdwClamp and let the listview items stretch to fill the entirety of the available viewport. In that case, the listview height renders correctly.

What’s the correct way to structure this hierarchy to have the clamp control the width while allowing the scrolled window to properly handle the height? Am I missing a property or using the wrong widget order?

Thanks for any help!


Use Adw.ClampScrollable instead of clamp

The technical explanation is - GtkListView is scrollable and it needs to communicate with the scrolled window. If there’s a clamp in the way (as well as an implicit GtkViewport), it can’t do that.

AdwClampScrollable is itself a scrollable, and proxies to its child, so the list view and scrolled window can talk to each other

2 Likes

Thanks. I should have said I’ve tried AdwClampScrollable as well, but I must be doing it wrong, as I don’t have any scrollbars and the pane isn’t scrollable for some reason.

<?xml version="1.0" encoding="UTF-8"?>
<interface>
  <requires lib="gtk" version="4.0"/>
  <template class="TypesetterPreview" parent="GtkBox">
    <property name="hexpand">true</property>
    <property name="vexpand">true</property>
    <property name="orientation">1</property>
    <child>
      <object class="GtkOverlay" id="preview_overlay">
        <property name="hexpand">true</property>
        <property name="vexpand">true</property>
        <style>
          <class name="preview_pane_outer"/>
        </style>
        <child>
          <object class="AdwClampScrollable" id="preview_scroller">
            <property name="maximum-size">890</property>
            <property name="tightening-threshold">560</property>
            <child>
              <object class="GtkListView" id="preview_list">
                <property name="hexpand">true</property>
                <property name="vexpand">true</property>
                <style>
                  <class name="preview_pane_inner"/>
                </style>
              </object>
            </child>
          </object>
        </child>
...
      </object>
    </child>
  </template>
</interface>

Is there an obvious mistake that I’m making here?

There’s no GtkScrolledWindow in your snippet, you still need it.

1 Like

Thank you! That was a silly mistake on my part :sweat_smile: