Redraw UI Object on Attribute Change?

Joe Kaplan's icon

Greetings!

I have a UI object with some attributes to control colors of text and various other things that the object paints.

Something I'm noticing is that updating the attribute doesn't immediately trigger redraw(). So I don't get the common Max experience of dragging the color swatch around and watching the object change in real time.

If I update the attribute and then do something in the object that would ordinarily trigger a redraw() then the new colors appear. But that's not how Max objects typically behave.

Is there a way to get my UI objects to redraw() when an attribute gets updated?

I am writing my object with MinDevkit in case it matters.

Thanks for any input!

TFL's icon

At first I thought you were speaking about a jsui/v8ui object, in which case I would have tell you to "define a custom setter function for your attribute, and call redraw() in that setter function", but then I realized you are using MinDevKit, which I'm unfamiliar with. But it seems my answer would still stand: you can find an example of a custom setter function in the Attributes section of this page.

Joe Kaplan's icon

Thanks TFL,

I found that page just as you posted. Adding a setter argument to the attribute and putting redraw() inside worked like a charm.

Good to go. Thanks!

Joe Kaplan's icon

Just reporting back that I ran into a number of issues with this approach. After reviewing textslider.cpp, I found the appropriate way to do this:

It looks like when an attribute changes the object sends a notification to itself. Which you can access with the m_notify message. Adding this to the external made colors work like a charm.

    message<> m_notify{ this, "notify",
        MIN_FUNCTION {
            notification n { args };
            symbol attr_name { n.attr_name() };
            if (attr_name != k_sym__empty) {
                redraw();
            }
            return {};
        }
    };