BR: drawDrawableButton draws underneath the drawable

I am trying to overlay text over a DrawableButton. Someone else tried here and was told to override LookAndFeel to do so. I tried overriding drawDrawableButton but this does not work because of the order of events when painting the component:

  • Component gets painted
  • drawDrawableButton gets called, text is drawn
  • Component children get painted over the top of component, covering the text
  • paintOverChildren gets called (empty function body in base class)

If there was something to the effect of paintOverChildren in LookAndFeel, it would not be necessary to subclass DrawableButton and override paintOverChildren to overlay text. It does seem like DrawableButton was intended to be able to handle overlaying text via LookAndFeel.

Please consider either adding to LookAndFeel or adding an option to DrawableButton to overlay text as suggested in this other post.

I had to read the sources of DrawableButton:

The DrawableButton sets the Drawable as child component, so the LookAndFeelMethod drawDrawableButton() has no chance drawing on top of the drawable.

Since the Drawables are scheduled in JUCE 9 to be no Components, this has to be changed anyway.

I would suggest to change the DrawableButton to call in the LookAndFeel:

button.getCurrentDrawable()->drawWithin (g, ...);

g.drawFittedText (button.getButtonText(), ...);

This allows in juce 9 to continue using the Drawable or use a new SVG class, if it will be replaced.

1 Like