[MEL] attrFieldGrp - popupMenu parent to individual fields?


#1

Hi,

I need a bit help with making UI…
Would anyone know if it’s possible, and if so, how to parent popupMenu to individual fields of attrFieldGrp?

A simple example where you can do popupMenu -parent to attrFieldGrp but the probem is that the same popupMenu is showing on each field i click while i would like to have separate and different popupMenu for each field.


string $objectCreate[] = `sphere`;
window;
columnLayout;
    attrFieldGrp -l "Translate  " -attribute ($objectCreate[0] + ".translate") translate;
    popupMenu -parent translate;
    menuItem -l "Do something";
showWindow;

Here it the rough concept how it would be cool if it works like that…


string $objectCreate[] = `sphere`;
window;
columnLayout;
    attrFieldGrp -l "Translate  " -attribute ($objectCreate[0] + ".translate") translate;
    
    popupMenu -parent Translate Label;
      menuItem -l "Do something on Label" -c "";
    popupMenu -parent translateX field;
      menuItem -l "Do something to X" -c "";
    popupMenu -parent translateY field;
      menuItem -l "Do something to Y" -c "";
    popupMenu -parent translateZ field;
      menuItem -l "Do something to Z" -c ""; 
showWindow;

Is something like this even possible?

Thanks!


#2

Yes it is possible.
I use it all the time.
Sometimes I use even labels as buttons by adding popupMenus to compact UI. :smiley:
Here is an example.

intField
	-value 1024
	-minValue 1
	-maxValue 16384
BKMPUD_LayoutResX;

	popupMenu
		-button 3;

		menuItem
			-label "64"
			-command "BKMPUD_StateResX(64)";

		menuItem
			-label "128"
			-command "BKMPUD_StateResX(128)";

		menuItem
			-label "256"
			-command "BKMPUD_StateResX(256)";

intField
	-value 1024
	-minValue 1
	-maxValue 16384
BKMPUD_LayoutResY;

	popupMenu
		-button 3;

		menuItem
			-label "64"
			-command "BKMPUD_StateResY(64)";

		menuItem
			-label "128"
			-command "BKMPUD_StateResY(128)";

		menuItem
			-label "256"
			-command "BKMPUD_StateResY(256)";

#3

Thanks a lot for the reply!

Unfortunately, that is exactly what i wanted. I also know how to parent popupMenu to certain
int or float field or slider, button or anything similar like that wich has just one field or just one slider or button.

I need here specifically for “attrFieldGrp” which has label and then 3 fields for x, y and z.
The question is whether it is possible to parent only the label or certain field in attrFieldGrp.

On the example i posted the popup menu will show when you RMB anywhere on the control
where i want for popup menu to show only when RMB click on, for example, translateX


string $objectCreate[] = `sphere`;
window;
columnLayout;
    attrFieldGrp -l "Translate  " -attribute ($objectCreate[0] + ".translate") translate;
    popupMenu -parent translate;
    menuItem -l "Do something";
showWindow;


#4

Does it have to be the right mouse button that triggers the menu?
If the middle mouse button is okay as well, you could use the

-dragCallback

.
It will give you the mouse position on the UI element which makes it easy to figure out where the user clicked.


global proc callbackProc(string $dragControl, int $x, int $y, int $mods) 
{
    // $dragControl will contain the full path name of the attrFieldGrp
    if ($x <= 100) { 
        // hit the lable
    } else if ($x <= 200) { 
        // hit the first field
    } else if ($x <= 300) { 
        // hit the second field
    } else if ($x <= 400) { 
        // hit the third field
    }
}

string $objectCreate[] = `sphere`;
window;
columnLayout;
    attrFieldGrp -l "Translate  " -attribute ($objectCreate[0] + ".translate") 
           -columnWidth4 100 100 100 100
           -dragCallback "callbackProc" 
           -en false
           translate;
showWindow;


#5

Interesting workaround. I’ll try something maybe in that direction, we’ll see…

Thank you very much!