Forums > Dev

Inspector with attributes that depend on each other (like filtergraph~)

December 2, 2010 | 1:33 pm

For a UI object I am working on, I need to have attributes that depend on each other. Much like filtergraph~, where changing the value for Active Filter(s) changes the number of items in the Currently Selected Filter popup, and changing the latter updates the Filter Type.

This presumably makes use of object notification. The documentation here leaves some questions open… is there any source code available on how to do this sort of thing? Sample code would be a big help.


December 2, 2010 | 2:52 pm

filtergraph~ uses attributes with custom setters and gettrs to set and get the value of specific filter parameters depending on the state of other attributes. Changing active filters only changes the number of items in the enum values for the other edit_filter attribute. Is that what you need to achieve?


December 2, 2010 | 4:38 pm

That, plus a behavior exactly like the relationship between Current Selection and Active Filter. When Current Selection is changed, the selected item in Active Filter is updated to reflect the change.

Is this all done with custom get/set methods?


December 2, 2010 | 6:05 pm

To change the enum values you need to change the enumvals attribute of the attribute. That’s what we do in filtergraph~:


t_object *efattr = object_attr_get((t_object *)x, gensym("edit_filter"));

for (i = 0; i < x->x_nfilters; i++) {
sprintf(str," %ld",i);
strcat(nums,str);
}
object_attr_setparse(efattr, gensym("enumvals"), nums);

For the rest, it’s all done with the custom get/set methods. So when you change the current filter, you set the values of the edit_whatever attributes (using object_attr_setvalueof to notify the attributes so the inspector redraws, not by accessing directly to their values in the object structure). Hope this makes sense.


December 2, 2010 | 7:05 pm

Sure, doing this with getters/setters makes sense enough, and seems more straight-forward that what I was originally thinking. Off to try to get this working.

Je t’remercie pour l’aide.


Viewing 5 posts - 1 through 5 (of 5 total)