Post added GUI controls not drawing correctly
This code works perfectly for what I'm trying to do, which is add a control element upon user clicking a button. My question is in two parts...
1. If my source group that I am adding the new control to is the parent group (pal.grp), the control gets added perfectly and spaces itself out correctly. Which is the below FIG.2 code does. My issue is that I want add the control to a subgroup (pal.grp.grp1.grp2). Upon doing that, I click the add button numerous times and nothing shows, BUT as soon as I grab the corner of the window to resize it, BAM!, everything shows up and in the proper positions. So I am wondering if this is a UI drawing bug, or I'm just not getting the UI layout incorrectly recalculated? Any help appreciated.
2. My second question is whether or not you can use a resource string for the add method instead of having to hard code the element properties. (panel.add("dropdownlist", [10,10,100,30], contents)). Ideally I would like to add three elements like in FIG.1.
FIG.1
"grp1: Group{orientation:'row', alignment:['fill','fill'], alignChildren:['fill','fill'],\
dd1: DropDownList{properties:["+list+"], alignment:['right','top']},\
ddB1: Button{text:'Batch', alignment:['right','top']},\
}";
FIG.2
{
function sampleName(thisObj){
function sampleName_buildUI(thisObj){
var pal = (thisObj instanceof Panel) ? thisObj : new Window("palette", "PAL NAME", undefined, {resizeable:true});
if (pal != null){
var res ="group {orientation:'column', alignment:['fill','top'], alignChildren:['fill','top'],\
testBut1: Button{text:'Add'},\
spacerOne: Panel{},\
sourceDD: DropDownList{properties:{items:['item1', 'item2', 'item3', 'item4']}},\
grp1: Group{orientation:'column', alignment:['fill','top'], alignChildren:['left','top'],\
but1: Button{text:'sample1'},\
but2: Button{text:'sample2'},\
but3: Button{text:'sample3'},\
grp2:Group{orientation:'column', alignment:['fill','top'], alignChildren:['left','top'],\
but4: Button{text:'sample4'},\
},\
},\
}";
pal.grp = pal.add(res);
//Default source DD selection
pal.grp.sourceDD.selection = 0;
//Add new DD onClick function
pal.grp.testBut1.onClick = function (){
var list = new Array('item1', 'item2', 'item3', 'item4');
addButtons(pal.grp, list);
}
pal.layout.layout(true);
pal.layout.resize();
pal.onResizing = pal.onResize = function () {this.layout.resize();}
}
return pal;
}
// addButtons function
function addButtons(panel, contents){
try{
var newDD = panel[0] = panel.add("dropdownlist", [10,10,100,30], contents);///ARE RESOURCE STRINGS POSSIBLE FOR THIS ADD FUNCTION? (I need a dynamic size input)
newDD.selection = 0;
panel.layout.resize();
panel[0].show();
}catch(err){alert("ERROR:\nSomething went wrong, please email torno@sydefxink.com with the info below:\n--------------------------------------\nOS: "+$.os+" ("+$.locale+")\nAE: "+app.version+" ("+app.language+")\n\nError at line #"+err.line+"\n\n"+err.toString());}
}
// Build/show the user interface
var snPal = sampleName_buildUI(thisObj);
if (snPal != null){
if (snPal instanceof Window){
snPal.center();
snPal.show();
}
}
}
sampleName(this);
}