How to set widget width to Adw.Clamp size?

In this code of Adw.NavigationPage Box widget is always fixed size, even with hexpand property, but it should have 400px width in bigger window sizes and less than 400px when Adw.Clamp shrinks it size.


This is how it looks when width-request is set for controls (and how it should look without width-request)

Adw.NavigationPage sync_navigation_page {
  title: _("Syncing");

  Adw.ToolbarView {
    [top]
    Adw.HeaderBar {
      show-end-title-buttons: false;
    }

    [top]
    Adw.Clamp {
      maximum-size: 400;
      orientation: horizontal;

      Box {
        orientation: horizontal;
        halign: center;
        valign: start;
        spacing: 8;
        vexpand: true;
        hexpand: true;
        margin-top: 12;

        styles ["card"]

        Image sync_page_cover {
          icon-name: "note-placeholder";
          pixel-size: 100;
          overflow: hidden;

          styles ["rounded"]
        }

        Box {
          orientation: vertical;
          vexpand: true;
          spacing: 2;
          margin-top: 8;

          Inscription sync_page_title {
            text: "Unknown";
            text-overflow: ellipsize_end;

            styles ["heading"]
          }

          Inscription sync_page_artist {
            text: "Unknown";
            text-overflow: ellipsize_end;

            styles ["heading"]
          }

          Box {
            margin-top: 4;
            margin-end: 8;
            spacing: 4;

            MediaControls controls {
            }

            ToggleButton toggle_repeat_button {
              tooltip-text: _("Toggle song repeat");
              icon-name: "toggle-repeat-symbolic";
              active: false;
              halign: center;
            }
          }
        }
      }
    }
  }
}

Your code snippet shows your using vexpand instead of hexpand in the box inside clamp. This mistype is probably your issue?

That was just a mistype, I just forgot to paste the version with hexpand. Even with hexpand set to true nothing changes.

I just took a closer look at your code.

The issue in question is the halign. Normally, a Gtk widget will be drawn on all available space, unless you specify otherwise, like with an align. By setting halign: center, you tell the Box to only use as much space as needed in the center of the allocated space.
So, drop the halign, and it should use all space granted by the clamp.

On another note: Actually, you can drop all aligns and expands in this code snippet. You should only need an hexpand in the MediaControls widget.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.