How to synchronously repaint layered components

We have a somewhat recent addition for this purpose, the VBlankAttachment class.

You can use this instead of a Timer and its callbacks will be synchronised with the current monitor’s refresh rate, so there is a good chance this would solve your problem.

You can add a VBlankAttachment member to the visualisation Component and have it call your Component’s update function, something like this.

class MyVisualisation  : public Component
{
public:
    // [...]

private:
    void update()
    {
        const auto needsToRepaint = updateState();
       
        if (needsToRepaint)
            repaint();
    }

    // [...]

    VBlankAttachment vBlankAttachment { this, [this] { update(); } };
};
6 Likes