How can a palette resize itself?

I am trying to improve my Anchors Palette so that it increases its height as the number of anchors to be shown is greater than 4. I tried several techniques but none of them work.

Any ideas how I can achieve that?

1 Like

The palettes use auto layout. I saw that vanilla has some support for it now but I never tried it myself. And I don’t know if it works in the versions that still supports python 2.7.

If you the view that is added has no layout constrains, the system will add default constraints. Those prevent the view from chaining size later on.

You could try to set the autoresizing mask just after you created it, before it is added to a superview.


Or do the whole thing without vanilla with a .xib in Xcode (then I could help you better).

1 Like

Thanks for your hints. Somehow, self.paletteView.getNSView() is not possible as Window only has getNSWindowController() and getNSWindow().

I tried to apply setAutoresizingMask_() to, and to self.paletteView.getNSWindow().contentView(), without success.

I’ll give it a go with Interface Builder.

I was wondering why you use a window in the first place. Shouldn’t that be a view?

The code is based on this example from the Glyphs SDK.

This is really surprisingly tricky. All I want it to re-size a palette, and I have spent hours trying to achieve this, without success.

I just updated the Anchors Palette, using a nib with auto layout. Still, self.setCurrentHeight_() for the palette has absolutely no effect.

@GeorgSeifert Any ideas? Thanks!

I have fixed it.

The self.setCurrentHeight_method is not really useful here (and I implemented it quite a long time ago). It can be used for manually resizable panels like the Layers. Here we need to set the height based one something else.

How does it work.

  • add a layout constraint
  • add an outlet to it.
  • in the update method, set the constant property of the constraint to the desired height.

If the constant is set on the animator()-proxy, it moves up and down instead of jumping around

1 Like

Excellent, thanks a lot! Didn’t know that the constraints can be linked to the Python code so easily.

I reduced the frequency of height changes as overly frequent changes could be very distracting e.g. as we step through glyphs in edit view.

I added a note in the palette plugin readme.