Dimming attributes in inspector

Mar 7, 2009 at 4:59pm

Dimming attributes in inspector

Hi again,

one more question today…

I see that inspectors of some objects are able to dim one of their attributes, in response to the value set for another attribute in the same inspector.

Can anybody tell me or – even better – post a code example on how to accomplish this?

Thanks a lot.

- Luigi

#42722
Mar 8, 2009 at 1:23am

You can disable an attribute like that:

object_attr_setdisabled((t_object *)x, gensym(“yourattr”), 1);

HTH,

#152940
Mar 8, 2009 at 2:55pm

Thanks Emmanuel,

so if I understand correctly, the right strategy would be to use object_attr_setdisabled in my object_notify method and check for the state of an attribute every time it changes. Depending on the state, I can use object_attr_setdisabled to dim the required attribute. Am I correct?

Also, what’s the 3rd argument of object_set_disabled?

Thanks.

- Luigi

#152941
Mar 8, 2009 at 10:42pm

The third argument is to specify the disable state, to disable:

object_attr_setdisabled((t_object *)x, gensym(“yourattr”), 1);

to enable it back:

object_attr_setdisabled((t_object *)x, gensym(“yourattr”), 0);

You can put that wherever you want. Usual cases though are in attributes accessors or notify method. For instance in the panel object, there’s a custom settr for the mode attribute, and depending on the mode state (color or gradient) the disabled state of other attributes are set.

Best,

#152942
Mar 9, 2009 at 5:11pm

Great, all is clear now.

Thank you so much, Emmanuel.

- Luigi

#152943
Nov 27, 2012 at 11:06pm

Hi,
object_attr_setdisabled method doesn’t seem to work with color attributes (we can still set the rgba value).
Do you know a method who can be used in this case? Is there a method to make an attribute visible/invisible from the object inspector ?
Thanks.

#152944
Nov 28, 2012 at 1:10am

There’s no way of doing that at the moment. object_attr_setdisabled is all there is.

#152945
Nov 28, 2012 at 12:37pm

Hi ej,
Thanks for your reply,
basically, i’m wondering if there is a way to reverse the action of object_attr_addattr_parse((t_object*)x, "myattr", "invisible", USESYM(long), 1, "1"); ?

#152946
Nov 28, 2012 at 2:54pm

Coded from the top of my head WITHOUT testing. Use with caution…

object_attr_setlong(object_attr_get(x, gensym("myattr")), gensym("invisible"), 0);

However, notice that it has nothing to do with object_attr_setdisabled().
The above code will simply make an attribute visible/invisible to the inspector, whereas object_attr_setdisabled() will dim the attribute in the inspector, but the disabled attribute will always be visible.

Also be aware that your code creates the “invisible” attribute with the ATTR_GET_OPAQUE flag set [ the 1 after USESYM(long) ], which means you cannot query the attribute either by Max message, nor C code. Make sure that’s what you want…

Hope this helps.

- Luigi

#152947
Nov 28, 2012 at 6:21pm

@luigi
Many thanks, it’s what i’m looking for.
But it bring me another problem/question :
My goal is to control the visibility of my color attribute depending on the value of an other attribute in the same object inspector.
This method works well but i need to refresh the object inspector (close and re-open it) to see changes for my color attribute !
is this normal? i dont think so !
the code i use :
in my main method :

CLASS_ATTR_LONG			(c, "togglevisibility", 0, t_myobject, togglevisibility);
CLASS_ATTR_STYLE_LABEL	(c, "togglevisibility", 0, "onoff", "Toggle Color Attr visibility");

CLASS_ATTR_RGBA			(c, "mycolor", 0, t_myobject, mycolor);
CLASS_ATTR_STYLE			(c, "mycolor", 0, "rgba");
CLASS_ATTR_INVISIBLE		(c, "mycolor", 0);

in my object notify method :

t_max_err myobject_notify(t_myobject *x, t_symbol *s, t_symbol *msg, void *sender, void *data)
{
	t_symbol *name;
	if (msg == gensym("attr_modified"))
	{
		name = (t_symbol *)object_method((t_object *)data, gensym("getname"));
		if(name == gensym("togglevisibility"))
		{
			if (x->togglevisibility) object_attr_setlong(object_attr_get(x, gensym("mycolor")), gensym("invisible"), 0);
			else object_attr_setlong(object_attr_get(x, gensym("mycolor")), gensym("invisible"), 1);
		}
	}
	return jbox_notify((t_jbox *)x, s, msg, sender, data);
}

Can someone tell me what i’m doing wrong or what i’m missing?

#152948
Nov 29, 2012 at 9:26am

Hi Eliott,

I don’t think the “invisible” attribute is meant as a way to show/hide attributes in real-time.
The most appropriate way to go in your situation would be the object_attr_setdisabled() function, but then again, it doesn’t work for color attributes.
Usually the way you refresh an attribute value in the inspector is with the object_attr_touch() function, however you are really trying to act on an attribute of an attribute, and I am pretty sure this approach won’t work.
Sorry I can’t help you any further, but what you are trying to accomplish might not be possible with the current SDK.

Having said this, I would like to be proven wrong by one of the C74 guys…

- Luigi

#152949

You must be logged in to reply to this topic.