Script UI dynamic resizing
Hi,
I've written a dialog where the user can choose beetwen one of two global options, or several standard options. When one of the 2 global options are selected, the other standard options are hidden.
When the standard option panel is hidden, the dialog box stays at the same size and it just makes an empty space. I tried to dynamicaly resize the dialog with the line "myWindow.layout.layout(true);", wich works, but then I'm loosing the orientation and the alignment values of the subpanels.
I'd like to know if there is any way with the layout() method not to update the whole hierarchy.
Here is my code, you can take it and reuse it for yourself.
To check the negative effects you can uncomment the 2 lines : // myWindow.layout.layout(true);
But then you should replace the orientation values "stack" by "row", and the alignment values "fill" by "left".
Thanks,
Romain
myWindow = new Window("dialog", "Option screen");
var myPanelGlobal = myWindow.add("panel", undefined, "Global options", {borderStyle: "sunken"});
myPanelGlobal.orientation = "column";
myPanelGlobal.alignment = "top";
var myGroupABC = myPanelGlobal.add("panel");
myGroupABC.preferredSize = [260,-1];
myGroupABC.orientation = "stack";
myGroupABC.alignement = "fill";
var myGroup1ABC = myGroupABC.add("group");
myGroup1ABC.orientation = "row";
myGroup1ABC.alignment = "left";
myGroup1ABC.add("staticText", undefined, "Project 1");
var myGroup2ABC = myGroupABC.add("group");
myGroup2ABC.orientation = "row";
myGroup2ABC.alignment = "right";
var checkboxABC = myGroup2ABC.add("checkbox");
checkboxABC.value = false;
var myGroupXYZ = myPanelGlobal.add("panel");
myGroupXYZ.preferredSize = [260,-1];
myGroupXYZ.orientation = "stack";
myGroupXYZ.alignement = "fill";
var myGroup1XYZ = myGroupXYZ.add("group");
myGroup1XYZ.orientation = "row";
myGroup1XYZ.alignment = "left";
myGroup1XYZ.add("staticText", undefined, "Project 2");
var myGroup2XYZ = myGroupXYZ.add("group");
myGroup2XYZ.orientation = "row";
myGroup2XYZ.alignment = "right";
var checkboxXYZ = myGroup2XYZ.add("checkbox");
checkboxXYZ.value = false;
var myPanelStandard = myWindow.add("panel", undefined, "Standard options", {borderStyle: "sunken"});
myPanelStandard.orientation = "column";
myPanelStandard.alignment = "top";
var myGroupA = myPanelStandard.add("panel");
myGroupA.preferredSize = [260,-1];
myGroupA.orientation = "column";
myGroupA.alignment = "top";
var mySubgroupA1 = myGroupA.add("group");
mySubgroupA1.orientation = "row";
mySubgroupA1.alignment = "left";
mySubgroupA1.add("staticText", undefined, "Option 1");
var mySubgroupA2 = myGroupA.add("group");
mySubgroupA2.orientation = "stack";
mySubgroupA2.alignment = "fill";
var radioA1 = mySubgroupA2.add("radiobutton", undefined, "Yes");
radioA1.alignment = "left";
var radioA2 = mySubgroupA2.add("radiobutton", undefined, "No");
radioA2.alignment = "right";
radioA1.value = true;
var myGroupB = myPanelStandard.add("panel");
myGroupB.preferredSize = [260,-1];
myGroupB.orientation = "column";
myGroupB.alignment = "top";
var mySubgroupB1 = myGroupB.add("group");
mySubgroupB1.orientation = "row";
mySubgroupB1.alignment = "left";
mySubgroupB1.add("staticText", undefined, "Option 2");
var mySubgroupB2 = myGroupB.add("group");
mySubgroupB2.orientation = "stack";
mySubgroupB2.alignment = "fill";
var radioB1 = mySubgroupB2.add("radiobutton", undefined, "Yes");
radioB1.alignment = "left";
var radioB2 = mySubgroupB2.add("radiobutton", undefined, "No");
radioB2.alignment = "right";
radioB1.value = true;
var myGroupC = myPanelStandard.add("panel");
myGroupC.preferredSize = [260,-1];
myGroupC.orientation = "column";
myGroupC.alignment = "top";
var mySubgroupC1 = myGroupC.add("group");
mySubgroupC1.orientation = "row";
mySubgroupC1.alignment = "left";
mySubgroupC1.add("staticText", undefined, "Options 3");
var mySubgroupC2 = myGroupC.add("group");
mySubgroupC2.orientation = "stack";
mySubgroupC2.alignment = "fill";
var radioC1 = mySubgroupC2.add("radiobutton", undefined, "Yes");
radioC1.alignment = "left";
var radioC2 = mySubgroupC2.add("radiobutton", undefined, "No");
radioC2.alignment = "right";
radioC1.value = true;
var myButtonGroup = myWindow.add("group");
myButtonGroup.orientation = "row";
myButtonGroup.alignment = "top";
myButtonGroup.add ("button", undefined, "OK");
myButtonGroup.add ("button", undefined, "Cancel");
checkboxABC.onClick = function()
{
if (checkboxABC.value == true) {
myGroupXYZ.visible = false;
checkboxXYZ.value = false;
myPanelStandard.visible = false;
} else {
myGroupXYZ.visible = true;
myPanelStandard.visible = true;
}
if (myPanelStandard.visible == true) {
myPanelStandard.maximumSize = [10000,10000];
} else {
myPanelStandard.maximumSize = [0,0];
}
// myWindow.layout.layout(true);
};
checkboxXYZ.onClick = function()
{
if (checkboxXYZ.value == true) {
myGroupABC.visible = false;
checkboxABC.value = false;
myPanelStandard.visible = false;
} else {
myGroupABC.visible = true;
myPanelStandard.visible = true;
}
if (myPanelStandard.visible == true) {
myPanelStandard.maximumSize = [10000,10000];
} else {
myPanelStandard.maximumSize = [0,0];
}
// myWindow.layout.layout(true);
};
var myResultOptions = myWindow.show();
