Group Weights: How do they work?
-
On 11/04/2013 at 12:17, xxxxxxxx wrote:
User Information:
Cinema 4D Version: 13
Platform: Windows ;
Language(s) : C++ ;---------
Hi,I'm trying to use the weights option for laying out GeDialog gizmos (trying to learn what they are capable of) But they are not working for me.
I'm trying to use the weights to position one gizmo in relation to another gizmo. But nothing happens.
No matter what I set the values to. The gizmos don't change in my plugin.
Maybe I'm misunderstanding what they do?Here's the relevant parts of the plugin code:
enum { EDTEXT_1 = 1001, EDTEXT_2 = 1002, EDARROWS = 1003, GRP_MAIN = 2000, GRP_SUB1 = 2001, _dummy }; class MyDialog : public GeDialog { private: myDialog *dlg; BaseContainer weights; Bool weights_saved; public: myDialog(void); etc... }; MyDialog::myDialog(void) { weights_saved = FALSE; } Bool MyDialog::CreateLayout(void) { Bool res = TRUE; res = LoadDialogResource(IDS_RESDIALOG,NULL,0); GroupBegin(GRP_MAIN,BFH_SCALEFIT,0,0,"Main Group",0); GroupBorder(BORDER_BLACK); { GroupBegin(GRP_SUB1,BFH_LEFT,0,3,"Sub Group", BFV_GRIDGROUP_ALLOW_WEIGHTS); GroupBorder(BORDER_BLACK); { AddEditText(EDTEXT_1, BFH_LEFT,100,15,0); AddEditText(EDTEXT_2, BFH_LEFT,100,15,0); AddEditNumberArrows(EDARROWS,BFH_LEFT); } if (!weights_saved) { // initialization code // set the rows weights.SetLong(GROUPWEIGHTS_PERCENT_H_CNT,3); // number of rows - has to be equal to the given layout weights.SetReal(GROUPWEIGHTS_PERCENT_H_VAL+0,-10.0); // weight for row 1 weights.SetReal(GROUPWEIGHTS_PERCENT_H_VAL+1,330.0); // weight for row 2 weights.SetReal(GROUPWEIGHTS_PERCENT_H_VAL+2,50.0); // weight for row 3 weights_saved = TRUE; } GroupWeightsLoad(GRP_SUB1,weights); GroupEnd(); //End the sub group } GroupEnd(); //End the main group return res; } LONG MyDialog::Message(const BaseContainer &msg, BaseContainer &result) { switch(msg.GetId()) { case BFM_WEIGHTS_CHANGED: //If the weights change because of user interaction you will get notified if (msg.GetLong(BFM_WEIGHTS_CHANGED)==GRP_SUB1) GroupWeightsSave(GRP_SUB1, weights); break; } return GeDialog::Message(msg,result); }
Why don't my gizmos change?
-ScottA
-
On 11/04/2013 at 12:54, xxxxxxxx wrote:
The only change that I would make is to put the weights stuff after all of the layout grouping, like below. One problem is that this weighting might not work on basic elements. If my correction does not work, you may want to put each element into its own group and see if that works.
Bool MyDialog::CreateLayout(void) { Bool res = TRUE; res = LoadDialogResource(IDS_RESDIALOG,NULL,0); GroupBegin(GRP_MAIN,BFH_SCALEFIT,0,0,"Main Group",0); GroupBorder(BORDER_BLACK); { GroupBegin(GRP_SUB1,BFH_LEFT,0,3,"Sub Group", BFV_GRIDGROUP_ALLOW_WEIGHTS); GroupBorder(BORDER_BLACK); { AddEditText(EDTEXT_1, BFH_LEFT,100,15,0); AddEditText(EDTEXT_2, BFH_LEFT,100,15,0); AddEditNumberArrows(EDARROWS,BFH_LEFT); } GroupEnd(); //End the sub group } GroupEnd(); //End the main group // Do this after group layout! if (!weights_saved) { // initialization code // set the rows weights.SetLong(GROUPWEIGHTS_PERCENT_H_CNT,3); // number of rows - has to be equal to the given layout weights.SetReal(GROUPWEIGHTS_PERCENT_H_VAL+0,-10.0); // weight for row 1 weights.SetReal(GROUPWEIGHTS_PERCENT_H_VAL+1,330.0); // weight for row 2 weights.SetReal(GROUPWEIGHTS_PERCENT_H_VAL+2,50.0); // weight for row 3 weights_saved = TRUE; } GroupWeightsLoad(GRP_SUB1,weights); return res; }
-
On 11/04/2013 at 13:22, xxxxxxxx wrote:
it is the official maxon code example scott posted there (more or less) and i also got
the python dialog weights code example never to work. i considered it as broken and
moved on -
On 11/04/2013 at 14:31, xxxxxxxx wrote:
At first. I thought the weights were used as a Group-to-Group layout thing.
But when I saw the code in the docs. It seems show that it somehow controls the columns and/or rows inside of a group.I'm glad I'm not the only one having problems with this.
I guess we could all use a better explanation about what this option does. And how to use it.-ScottA
-
On 11/04/2013 at 17:05, xxxxxxxx wrote:
I have it working for my general HelpDialog code for most of my plugins. It doesn't save the weights inbetween C4D sessions but the changes remain while in a session (because I don't save them like to the PluginPrefs container).
Where you are failing (and probably you too, littledevil) is that the second argument for weights.SetReal() isn't a location. It is a percentage for the column over the full width or vertical items over the full height. So, all of your weights should add up to 100.0. That should help you get it working.
// set the columns // - number of columns - has to be equal to the given layout weights.SetLong(GROUPWEIGHTS_PERCENT_W_CNT, 2L); // - weight for col 1 weights.SetReal(GROUPWEIGHTS_PERCENT_W_VAL+0L, 20.0); // - weight for col 2 weights.SetReal(GROUPWEIGHTS_PERCENT_W_VAL+1L, 80.0); weights_saved = TRUE;
-
On 11/04/2013 at 18:18, xxxxxxxx wrote:
I think I've figured it out.
The problem is the docs don't tell you what type of effect this produces. So I had no idea what to expect from it.
I thought it might move gizmos around. But as it turns out...It creates this sort of stretchy ability on them. Sort of similar to how you can re-size a window.
Or how you can pull on the edges of cells in MS Excel to make the cells taller or longer.Some quick initial observations:
-Using it on gizmos on the main group works fine. But not in a group within a group (I need to investigate this more why this is happening)-It seems to require the flag BFH_SCALEFIT | BFV_SCALEFIT to work.
Flags like BFH_LEFT, etc. don't seem to work with this. But I have to do more tests.-The values are critical
For example: If you have three rows and want the middle row to be bigger than the other two rows. Then you set the middle row's value to something like -150. And the other two rows to something low like zero.I will have to play around with this some more to get a better idea on what is, and what isn't allowed to be used with this option. But at least I've got a result happening now.
-ScottA
-
On 11/04/2013 at 18:34, xxxxxxxx wrote:
at least in python the sum of the weights does not have to be 100. i tried sum 100, sum 1.0
and free. the python docs state :_If a element has a bigger minimum size the given weight will be ignored. The sum of the weights do _
not need to be 100.the python maxon example uses only the scalefit flag and does not work. but i also played
with the default height / width values and scale flags of the elements and got some changes,
but i never found any pattern. -
On 11/04/2013 at 18:59, xxxxxxxx wrote:
I haven't gotten a chance to try it in Python yet. I only got it working in C++ a few minutes ago.
But when it come to the values. It seems that the numbers themselves aren't as important as the ratio of the values of each gizmo.
In other words. Don't think in terms of 0-100%.
It's the ratio of each gizmo's value compared to the other gizmos using the weights option that's important.
You can have values like this:
-row1 = 1.5
-row2 = 3.0 //This gizmo will be twice as tall as the other ones
-row3 = 1.5They should call this the "Elastic border option" so people know what it does when they see it in the docs.
-ScottA
-
On 11/04/2013 at 19:10, xxxxxxxx wrote:
So the values might be relative but they are related in a proportional way interdependently no matter how you want to 'divvy' them up.
Yes, this is an 'elastic border option'. Once you add the weights the user can then adjust each groupweight section (sort of like the way you can do the same in Visual Studio to the Solution Explorer, Output, Editor, and other sections - or like the way you can do the same in Cinema 4D's interface).