Highlighted

ScriptUI dynamic orientation problem

Explorer ,
May 13, 2020

Copy link to clipboard

Copied

Hi everyone

 

I want to make a script which contains  a list of buttons and make the orientation dynamically adapted to the panel resize action. And I found a way in ScriptUI for Dummies doc.

 

This works as expected:

 

w = new Window('palette', 'Test', undefined, { resizeable: true });

w.alignChildren = ['left', 'top'];
w.orientation = 'row';
w.add('button {text: "1",preferredSize:[32,32]}');
w.add('button {text: "2",preferredSize:[32,32]}');
w.add('button {text: "3",preferredSize:[32,32]}');
w.add('button {text: "4",preferredSize:[32,32]}');
w.add('button {text: "5",preferredSize:[32,32]}');

w.layout.layout(true);
w.layout.resize();
w.onResizing = w.onResize = function () {
    w.orientation = w.size.width > w.size.height ? 'row' : 'column';
    w.layout.resize();
}
w.onShow = function () {
    w.layout.resize();
}

w.show();

 

 

But typically I use resource string. In the resource string way, the orientation doesn't change. Code below:

w = new Window('palette', 'Test', undefined, { resizeable: true });

var res =
    "Group{alignChildren:['left','top'],\
    bt1: Button{text: '1',preferredSize:[32,32]},\
    bt2: Button{text: '2',preferredSize:[32,32]},\
    bt3: Button{text: '3',preferredSize:[32,32]},\
    bt4: Button{text: '4',preferredSize:[32,32]},\
    bt5: Button{text: '5',preferredSize:[32,32]},\
  }"

var mainGrp = w.add(res);

// w.alignChildren = ['left', 'top'];
// w.orientation = 'row';
// w.add('button {text: "1",preferredSize:[32,32]}');
// w.add('button {text: "2",preferredSize:[32,32]}');
// w.add('button {text: "3",preferredSize:[32,32]}');
// w.add('button {text: "4",preferredSize:[32,32]}');
// w.add('button {text: "5",preferredSize:[32,32]}');

w.layout.layout(true);
w.layout.resize();
w.onResizing = w.onResize = function () {
    w.orientation = w.size.width > w.size.height ? 'row' : 'column';
    w.layout.resize();
}
w.onShow = function () {
    w.layout.resize();
}

w.show();

 

You can see it does't change orientation:

Aaron_Ecthelion_0-1589359994982.png

 

What do I need to do to make this work in resource string way?

 

TOPICS
Error or problem, How to, Scripting, User interface or workspaces

Views

195

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

ScriptUI dynamic orientation problem

Explorer ,
May 13, 2020

Copy link to clipboard

Copied

Hi everyone

 

I want to make a script which contains  a list of buttons and make the orientation dynamically adapted to the panel resize action. And I found a way in ScriptUI for Dummies doc.

 

This works as expected:

 

w = new Window('palette', 'Test', undefined, { resizeable: true });

w.alignChildren = ['left', 'top'];
w.orientation = 'row';
w.add('button {text: "1",preferredSize:[32,32]}');
w.add('button {text: "2",preferredSize:[32,32]}');
w.add('button {text: "3",preferredSize:[32,32]}');
w.add('button {text: "4",preferredSize:[32,32]}');
w.add('button {text: "5",preferredSize:[32,32]}');

w.layout.layout(true);
w.layout.resize();
w.onResizing = w.onResize = function () {
    w.orientation = w.size.width > w.size.height ? 'row' : 'column';
    w.layout.resize();
}
w.onShow = function () {
    w.layout.resize();
}

w.show();

 

 

But typically I use resource string. In the resource string way, the orientation doesn't change. Code below:

w = new Window('palette', 'Test', undefined, { resizeable: true });

var res =
    "Group{alignChildren:['left','top'],\
    bt1: Button{text: '1',preferredSize:[32,32]},\
    bt2: Button{text: '2',preferredSize:[32,32]},\
    bt3: Button{text: '3',preferredSize:[32,32]},\
    bt4: Button{text: '4',preferredSize:[32,32]},\
    bt5: Button{text: '5',preferredSize:[32,32]},\
  }"

var mainGrp = w.add(res);

// w.alignChildren = ['left', 'top'];
// w.orientation = 'row';
// w.add('button {text: "1",preferredSize:[32,32]}');
// w.add('button {text: "2",preferredSize:[32,32]}');
// w.add('button {text: "3",preferredSize:[32,32]}');
// w.add('button {text: "4",preferredSize:[32,32]}');
// w.add('button {text: "5",preferredSize:[32,32]}');

w.layout.layout(true);
w.layout.resize();
w.onResizing = w.onResize = function () {
    w.orientation = w.size.width > w.size.height ? 'row' : 'column';
    w.layout.resize();
}
w.onShow = function () {
    w.layout.resize();
}

w.show();

 

You can see it does't change orientation:

Aaron_Ecthelion_0-1589359994982.png

 

What do I need to do to make this work in resource string way?

 

TOPICS
Error or problem, How to, Scripting, User interface or workspaces

Views

196

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
May 13, 2020 0

Have something to add?

Join the conversation