Procedural UI element creation: v2

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
Old 03 March 2013   #1
Procedural UI element creation: v2

http://forums.cgsociety.org/showthread.php?t=899869
I found this one, but it has been closed for a couple of years...

I tried creating a UI that should create layouts and fill them with new controls on the fly....
Surprise, surprise, I can't get it to work!
I'd appreciate any help or suggestions I can get!

Heres the block of code.
I've edited this pretty much by now, so things might not make sense
But just to clarify:
I'm creating one master formlayout
then 2 children form layouts that are supposed to be attached horizontally 50%
One on the left side and one on the right....right?

The idea is to populate these children form layouts with procedurally generated form layouts which in turn holds the checkbox control.

The checkboxcontrol lack good flags for aligning it so that's why I'm forcing it into a layout which is autoadjustable.
Makes sense?

Anyway, here's the code as of now. I've been editing pretty hard, so I might have missed some important things along the way...Hopefully some things should make sense







if (`window -exists myWindow`)deleteUI myWindow;
 {
 window -t "My Window" myWindow;
 
global string $dag_EditShelvesChkBoxArray1[]={};
int $incr = 0;
int $i=0;
string $shelf="";
global string $dag_EditShelvesChkBoxArray2[0];
string $childForm;
string $childForms[]={};
string $shelvesLeft[] = {"General", "Curves", "Deformation", "Subdivs", "Fur", "Toon", "Custom" };
string $shelvesRight[] = {"Dag", "Polytools", "Texturing", "GoZbrush", "Rigging", "Skinning", "Effects" };

string $masterForm = `formLayout`;
string $col1 = `formLayout`;
setParent $masterForm;
string $col2 = `formLayout`;
setParent $masterForm;
string $btn = `button -bgc 0.9 0.1 0.1 -vis 1 -h 30 -l ("")`;
string $btn2 = `button -bgc 0.9 0.1 0.1 -vis 1 -h 30 -l ("")`;
string $btn3 = `button -bgc 0.9 0.1 0.1 -vis 1 -h 30 -l ("")`;

setParent $col1;

//For Maya Customs
for ($i=0; $i<`size($shelvesLeft)`; $i++){

$shelf = `checkBox
            -l ($shelvesLeft[$i])
            -v 0
            `;

$dag_EditShelvesChkBoxArray1[$i] = $shelf;
setParent $col1;
$childForms[$i] = `rowColumnLayout -nc 2`;
print ($shelf+"\n");
$incr +=1;
print $incr;
}







formLayout -e
    	-af $col1 "top" 0 
    	-ac $col1 "bottom" 0 $btn
    	-ap $col1 "left" 5 15
    	-ap $col1 "right" 0 50     
    	
    	-af $col2 "top" 0 
    	-ac $col2 "bottom" 0 $btn
    	-ap $col2 "left" 0 50
    	-af $col2 "right" 0
    	
    	-an $btn "top" 
    	-ac $btn "bottom" 0 $btn2
    	-af $btn "left" 0
    	-af $btn "right" 0

    	-an $btn2 "top" 
    	-ac $btn2 "bottom" 0 $btn3
    	-af $btn2 "left" 0
    	-af $btn2 "right" 0
    	
    	-an $btn3 "top" 
    	-af $btn3 "bottom" 0
    	-af $btn3 "left" 0
    	-af $btn3 "right" 0    	    	
		$masterForm;



float $space = 100/$incr;
for ($i=0; $i<$incr; $i++){
                    
    if ($i==0){
        formLayout  -e
                    -ap $childForms[$i] top 0 0 
                    -ap $childForms[$i] bottom 0 (70)
                    -ap $childForms[$i] left 0 20
                    -ap $childForms[$i] right 0 50 
                    $col1;        
                    }
                    
    if ($i>=1 && $i<$incr){
        formLayout  -e
                    -ap $childForms[$i] top 0 ($space*$i) 
                    -ap $childForms[$i] bottom 0 (($space*$i))
                    -ap $childForms[$i] left 0 20
                    -ap $childForms[$i] right 0 50 
                    $col1;
                    }
		}
	
window -e -w 350 -h 200 myWindow;
showWindow myWindow;
}
 
 
 


Thanks for reading!

EDIT: Actually found some issues myself. Changed, but it's not done yet.
Pfffttt.....I guess this is as close I'm getting. Can't understand what is wrong with it....

Last edited by Geuse : 03 March 2013 at 10:34 AM.
 
Old 03 March 2013   #2
Originally Posted by Geuse: The checkboxcontrol lack good flags for aligning it so that's why I'm forcing it into a layout which is autoadjustable.
Makes sense?

No, not really. Why not just position the checkboxes in the formLayout? There seems no point complicating it with the rowColumnLayouts.

Its hard to comment further, since your code runs without errors and creates a window with checkboxes and buttons. What part did you want to change? Maybe you can post a mockup (picture) of your intended layout.

One more suggestion. Where possible, instead of those setParent commands I would use the -parent flag when creating a button, checkbox or any UI element really. I find it becomes easier to read later.

David
__________________
http://www.djx.com.au
 
Old 03 March 2013   #3
Why thanks David!
Yeah i was so up in my mind I forgot to explain what is wrong with the execution. The first item seems to be parented to the master layout since it doesn't align with the others. Could it look different at your end?
I'm browsing my phone and sadly dont have access to Maya for a few days. But I'll post a screenshot and mockup after the weekend.

Thanks for the answer and I'll look into the -parent flag.
I've coded some UI:s but have obviously never used that before. Also I can understand you don't need to do it like this but I really like the nice look of adjustable UI.
Thanks David!

PS. Yeah that rowcolumnlayout was unintended. It was one of my edits. I actually used a formlayout for each checkbox. :-)
 
Old 03 March 2013   #4
Originally Posted by Geuse: I actually used a formlayout for each checkbox. :-)

Either way, I still don't think you need to. The checkboxes will respect any or the master formLayout flags, -ap, -af, -ac etc. I don't see any advantage of nesting them deeper than needed.

David
__________________
http://www.djx.com.au
 
Old 03 March 2013   #5
Ah. The reason for that was to adjust the parent layout to the master layout so I could adjust the position very carefully, but I will look into that. Still I can't understand why my first checkbox falls outside pf its intended layout or that layout doesn't get any positional arguments for to the master layout.

Thanks.
 
Old 03 March 2013   #6
Since I need the practice anyway, I reworked your code and got this...

 if (`window -exists myWindow`)deleteUI myWindow;
 
 {
 window -t "My Window" myWindow;
  
 string $dag_EditShelvesChkBoxArray1[];
 string $dag_EditShelvesChkBoxArray2[];
 string $shelvesLeft[] = {"General", "Curves", "Deformation", "Subdivs", "Fur", "Toon", "Custom" };
 string $shelvesRight[] = {"Dag", "Polytools", "Texturing", "GoZbrush", "Rigging", "Skinning", "Effects" };
 
 string $masterForm = `formLayout -p myWindow`;
 string $col1 = `formLayout -p $masterForm`;
 string $col2 = `formLayout -p $masterForm`;
 
 string $btn = `button -p $masterForm -bgc 0.9 0.1 0.1 -vis 1 -h 30 -l ("")`;
 string $btn2 = `button -p $masterForm -bgc 0.9 0.1 0.1 -vis 1 -h 30 -l ("")`;
 string $btn3 = `button -p $masterForm -bgc 0.9 0.1 0.1 -vis 1 -h 30 -l ("")`;
 
 formLayout -e
 		-af $col1 "top" 0 
 		-ac $col1 "bottom" 0 $btn
 		-ap $col1 "left" 5 15
 		-ap $col1 "right" 0 50	 
 		
 		-af $col2 "top" 0 
 		-ac $col2 "bottom" 0 $btn
 		-ap $col2 "left" 0 50
 		-af $col2 "right" 0
 		
 		-ac $btn "bottom" 0 $btn2
 		-af $btn "left" 0
 		-af $btn "right" 0
 
 		-ac $btn2 "bottom" 0 $btn3
 		-af $btn2 "left" 0
 		-af $btn2 "right" 0
 		
 		-af $btn3 "bottom" 0
 		-af $btn3 "left" 0
 		-af $btn3 "right" 0				
 		$masterForm;
 
 for ($i=0; $i<`size($shelvesLeft)`; $i++){
 	$dag_EditShelvesChkBoxArray1[$i] = `checkBox -p $col1 -l ($shelvesLeft[$i]) -v 0`;
 }
 
 
 int $v = size($dag_EditShelvesChkBoxArray1);
 for ($i=0; $i<$v; $i++){
 	int $offset = -$i*5/$v;
 	int $pos = $i*100/$v;	
 	formLayout  -e
 				-ap $dag_EditShelvesChkBoxArray1[$i] "top" $offset $pos
 				-ap $dag_EditShelvesChkBoxArray1[$i] "left" 0 20
 				$col1;							
 }
 
 for ($i=0; $i<`size($shelvesRight)`; $i++){
 	$dag_EditShelvesChkBoxArray2[$i] = `checkBox -p $col2 -l ($shelvesRight[$i]) -v 0`;
 }
 
 int $v = size($dag_EditShelvesChkBoxArray2);
 for ($i=0; $i<$v; $i++){
 	int $offset = -$i*5/$v;
 	int $pos = $i*100/$v;	
 	formLayout  -e
 				-ap $dag_EditShelvesChkBoxArray2[$i] "top" $offset $pos
 				-ap $dag_EditShelvesChkBoxArray2[$i] "left" 0 20
 				$col2;							
 }
 
 window -e -w 350 -h 200 myWindow;
 showWindow myWindow;
 }
 


cheers
David
__________________
http://www.djx.com.au
 
Old 03 March 2013   #7
Damn you rock!
Sorry for the late reply, but THANK YOU!

That was exactly what I was going for!
 
Old 03 March 2013   #8
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 02:41 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.