How to Force a Widget to Take a Specified Size When Possible and Shrink Otherwise in libadwaita 1.7?

This is how previously I was supposed to make a widget to take as much space as possible, but be constrained to a specified size before. By placing vertical Adw.Clamp inside of horizontal Adw.Clamp and using tighting-threshold to make a widget to take a full given space of Adw.Clamp

Adw.Dialog quick_edit_dialog {
  can-close: true;

  Adw.Clamp {
    orientation: horizontal;
    maximum-size: 500;
    tightening-threshold: 500;

    Adw.Clamp {
      orientation: vertical;
      maximum-size: 600;
      tightening-threshold: 600;

      Adw.ToastOverlay quck_editor_toast_overlay {
        Adw.ToolbarView {
          margin-bottom: 12;
          margin-end: 12;
          margin-start: 12;
          margin-top: 12;

          [top]
          Adw.HeaderBar {
            Label quick_editor_label {
              label: _("Quick Editor");
              ellipsize: end;

              styles ["title-3"]
            }
          }

          ScrolledWindow {
            TextView quick_edit_text_view {
              right-margin: 4;
              bottom-margin: 4;
              top-margin: 4;
              left-margin: 4;

              styles ["rounded-frame"]
            }
          }

          [bottom]
          Box {
            orientation: horizontal;
            margin-top: 4;
            halign: end;

            Button quick_edit_copy_button {
              label: _("Copy to clipboard");
              clicked => $copy_quick_editor_text();

              styles ["suggested-action"]
            }
          }
        }
      }
    }
  }
}

In libadwaita 1.7 released in GNOME Platform 48 this behavior was changed


I don’t know any other way how to force widget to take specified size when it is possible and to shrink when there’s not enough size. Maybe you will?

max-content-width and max-content-height on your scrolled window? Or content-width and content-height on your dialog. Or a widget that propagates minimum size but sets a fixed natural size.

In general, what you want here is a fixed natural size. But that’s not what clamp does. Clamp… clamps the child’s natural size, i.e. shrinks it. It could increase it previously, but like I said in my blog post, that behavior was a bug.

1 Like

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