Modifying a button at runtime creates visual artifacts

In some scripts, I sometimes need to change a button's appearance and properties at runtime. I used to rely on markup controls to emulate buttons, and that worked fine. But now that buttons have gotten a level up, I switched to using them directly. However, I've noticed that when I try to apply the same approach, they show some visual artifacts, which go away once you move the mouse over the button.

Since Control.autosize() has an effect that don't really work well in this context, I resort to a few tricks to adjust just the width based on the content.

Maybe there's a better way to do this, but for now, with this workaround, something like this happens:


dlg_test_btn_artifacts.opusscriptinstall (2.0 KB)

The example changes (based on selection) the button's width, icon, and label, and also repositions the control to its side. But it looks like the button doesn't pick up on these changes and starts showing artifacts.

EDIT: I remember that doing something similar with markup controls would also create similar visual artifacts.

1 Like

Have you tried to force a refresh/redraw of the button after modifying it (Control.redraw = true)?

Yes.
I've found a workaround, but hopefully you can reproduce the issue.
Not a priority at all, but it would be nice to be able to do stuff like this in a more approachable way.

This was fixed in recent betas and should work now. (Seems good in my tests, at least. Let us know if there is still any issue.)

1 Like