AE Scripting : How to create a button in ExtendScript that stretches along with the width of panel in real time?

做~自己de王妃 提交于 2020-03-05 06:06:31

问题


As we cant set the width in percentage in ExtendScript.

I am finding a way where my button can be stretch/resize in realtime while resizing the panel size.

I tried setting the fill value -

Button.preferredSize.width = 200;
Button.preferredSize.height = 80;
saveButton.alignment = ['fill', 'fill'];

Didn't worked. Tried matching button width to panel width

Button.preferredSize.width = panel.width;

Didn't worked.


回答1:


Just set it's alignment to fill horizontally.

You can also specify it's size/ preferredSize and change it's default height.

Also, in order the UI to resize you need to add "onResizing/ onResize" event listeners and tell the layout to resize with resize().

Here's an example:

function myPanel (thisObj)
{
  var win = {};

  win.pal = thisObj instanceof Panel ? thisObj : new Window('palette', '', undefined, {resizeable: true});

  if (win.pal === null) return win.pal;

  var res = "Group {orientation: 'column', alignment: ['fill', 'fill'], preferredSize: [128, 64], \
    myButton: Button {text: 'My Button Name', alignment: ['fill', 'center']}\
  }";

  win.ui = win.pal.add(res);
  win.ui.myButton.minimumSize = [128, 32];

  win.pal.layout.layout(true);

  win.pal.onResizing = win.pal.onResize = function ()
  {
    this.layout.resize();
  };

  if (win.pal !== null && win.pal instanceof Window)
  {
    win.pal.show();
  }

  return win;
}

myPanel(this);

EDIT: You can set the button's width in percentage too, by taking it's container size. E.g.: win.ui.myButton.size = [ 0.9 * win.ui.size[0], 32];



来源:https://stackoverflow.com/questions/60009871/ae-scripting-how-to-create-a-button-in-extendscript-that-stretches-along-with

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!