Skip to main content
scottm29310603
Inspiring
February 12, 2020
Answered

.bounds newline Script UI

  • February 12, 2020
  • 1 reply
  • 1664 views

I've created an array of buttons.

 

var b = new Array(); for(var i = 0; i < dataField.length ; i++ ){ if(dataField[i][1].indexOf("DA ") > -1){ b[i] = groupOne.add ('iconbutton', undefined, undefined, {name:'Blue', style: 'toolbutton'}); b[i].bounds = [0,0,30,20]; b[i].fillBrush = b[i].graphics.newBrush(b[i].graphics.BrushType.SOLID_COLOR,dataField[i][0]); b[i].onDraw = customDraw; function customDraw() { with( this ) { graphics.drawOSControl(); graphics.rectPath(0,0,size[0],size[1]); graphics.fillPath(fillBrush); if( text ) graphics.drawString(text,textPen,(size[0]-graphics.measureString (text,graphics.font,size[0])[0])/2,3,graphics.font); }} } }

This all works fine.

However. What I want is, when I resize my panel. The buttons to go onto a newline. I know a way to create lines of so many, but it would be nice to have something that automatically creates new lines.

This topic has been closed for replies.
Correct answer Tomas Sinkunas

Here's a snippet by @zack_lovatt how to implement Responsive UI:

https://bitbucket.org/snippets/zlovatt/XKb7k/extendscript-responsive-layout

 

1 reply

Mylenium
Legend
February 12, 2020

That's quite general a limitation of pretty much any Adobe panel. They are state-based, not auto-reflow. Not sure if they'll ever change it.

 

Mylenium

scottm29310603
Inspiring
February 12, 2020

I'm looking at someone elses script and this is what they use to auto-reflow. I understand so much of it, but I don't know how to get it to work for me with buttons. There's obviously more to the script, but this is the section for relayering.

// Callback function for laying out the buttons in the panel
function swatchYouWant_doResizePanel()
{
var pal = swatchPal;
 
var btnSize = swatchYouWantData.swatchSize;
var btnOffset = btnSize + 1;
var maxRightEdge = pal.size.width - btnSize;
var leftEdge = 1;
var topEdge = 1;
 
// Reset the background group container's bounds
pal.btnGroup.bounds = [0, 0, pal.size.width, pal.size.height];
 
// Reset each button's layer bounds
var newLine = true;
for (var i=0; i<swatchYouWantData.colors.length; i++)
{
pal.swatches[i].bounds = [leftEdge, topEdge, leftEdge+btnSize, topEdge+btnSize];
newLine = false;
 
leftEdge += btnOffset;
 
// Create a new row if no more columns available in the current row of buttons
if (leftEdge > maxRightEdge)
{
leftEdge = 1;
topEdge += btnOffset;
newLine = true;
}
}
 
// The settings and help buttons go into the next "slot"
leftEdge = 1;
if (!newLine)
topEdge += btnOffset;
topEdge += (($.os.indexOf("Windows") != -1) ? 0 : 5);// add 5 more pixels to the gap on Mac (because of its margin when disabled)
btnSize = 30;
pal.settingsBtn.bounds = [leftEdge, topEdge, leftEdge+btnSize, topEdge+20];
leftEdge += btnSize + 1;
if (leftEdge > (pal.size.width - btnSize))
{
leftEdge = 1;
topEdge += 20 + 1;
}
pal.helpBtn.bounds = [leftEdge, topEdge, leftEdge+btnSize, topEdge+20];
}