Drawable.SetVisible() not working?

Hi Guys,

I have a Drawable from an SVG.

Depending on the length of an editor I use SetVisible to make it appear and disappear.

When doing this there is no visible effect, if I minimise the window and then bring it back the SetVisible has changed correctly and it looks fine.

SetVisible is working correctly for other components here, just not for Drawables.

Anyone any ideas?



Can you share some code?

Sounds like the Component’s just not being redrawn when you call setVisible() which is why minimising/maximising the window gives the expected behaviour - because it’s forcing a repaint.

Thanks for the interest.

void CADSearchComponent::textEditorTextChanged (juce::TextEditor&)

I debugged though the code, it just heads up the component tree calling internalRepaintUnchecked()/internalRepaint(). I’m wondering if it is something to do with the cachedImage.

Possibly. Does it work as expected if you call repaint() on the Drawable after setVisible()?

m_cancelIcon->setVisible (m_textEditor.getText().length() > 0);

If you call setVisible (true); on a component, it will be repainted, if you call setVisible (false); on a component, its parent will be repainted. I don’t know how that affects cached images.

Thanks, I had tried repaint() it makes no difference.

I also checked the caching it is nothing to do with that.

I think I’m just going to render the drawable to an image and then use those in my paint()

OK, I just tried repainting the parent component after setting the visibility and that works!

1 Like

So this does the trick:

void CADSearchComponent::textEditorTextChanged (juce::TextEditor&)
  bool bHasContent = m_textEditor.getText().length();
  if(m_bShowCancel != bHasContent)
    m_bShowCancel = bHasContent;

How does cachedImage come into play? Are you setting setBufferedToImage on a Drawable?

If you do, I think that’s a bad idea. Drawing the Drawable is probably faster than the cached Image, and you get aliasing, which was the reason to switch to vector graphics in the first place.

CachedImage only came into play because I misunderstood the code!