Updating Custom UI When Parameters Changed

Hi all,

I have a component with the following paint code:

void UIComponent::paint(juce::Graphics& g) {
    param = audioProcessor.param->get();
    
    lineLength = 100 * param;

    g.setColour(juce::Colours::black);

    g.drawLine(32, 32, 32 + lineLength, 32);
}

However, changes to the parameter are not reflected in the UI…until the UI is resized. I would like the UI to update smoothly, without manual resizing. I have tried forcing draw calls, using parameter attachments, using parameter listeners, and none of these work. There seems to be some weird drawLine caching that prevents my UI from updating. Does anyone know what could be causing this?

What is currently triggering the repaint()? Have you tried printing the param value to debug output, and drawing text with the value in the paint routine? Is it definitely the drawline call?

Ah. I did more digging and this one is quite embarrassing.

The UIComponent class was originally intended to serve not as a proper component, but as a set of convenience methods for draw functions in my actual components. In other words, the paint() function under UIComponent was manually called by other components, rather than by JUCE. When I changed UIComponent into a “real” component, I forgot to remove the manual paint() calls and add an addAndMakeVisible(). This made all the difference.

Once again, a pretty embarrassing mistake. Happy that I caught it though. Hopefully useful to anyone else in a similar situation.