drawableButton bug

since this commit, my drawable buttons aren’t drawn correctly.

class NewProjectAudioProcessorEditor    : public juce::AudioProcessorEditor
{
public:
    NewProjectAudioProcessorEditor (NewProjectAudioProcessor& p)
    : AudioProcessorEditor (&p)
    {
        setSize (400, 300);

        juce::DrawablePath drawablePath;
        drawablePath.setPath (getCrossShape());
        drawablePath.setFill (juce::Colours::red);
        button.setImages (&drawablePath);
        addAndMakeVisible (button);
    }

    void paint (juce::Graphics& g) override
    {
        g.fillAll (juce::Colours::grey);
    }

    void resized() override
    {
        button.setBounds (20, 20, 40, 40);
    }

    juce::Path getCrossShape()
    {
        static const unsigned char pathData[] = { 110,109,51,51,255,66,0,0,0,0,108,205,204,13,67,51,51,99,65,108,0,0,170,66,205,204,141,66,108,51,179,13,67,52,51,255,66,108,0,0,255,
            66,205,204,13,67,108,205,204,141,66,0,0,170,66,108,52,51,99,65,51,179,13,67,108,0,0,0,0,51,51,255,66,108,205,204,98,66, 204,204,141,66,108,0,0,0,0,51,51,99,65,108,51,51,
            99,65,0,0,0,0,108,205,204,141,66,205,204,98,66,108,51,51,255,66,0,0,0,0,99,101,0,0 };

        juce::Path path;
        path.loadPathFromData (pathData, sizeof (pathData));
        return path;
    }

    juce::DrawableButton button { "", juce::DrawableButton::ImageFitted };
};


1 Like

I don’t know if it solves your problem, but you should call setSize() at the end of your constructor, not at the beginning.

The reason is, that it will call resized() syncronously. The setBounds() in the resized() will then also trigger a repaint.

By moving the setSize() to the end, the drawing happens after all other setup (in your case setting the path to the button and addMakeVisible) has finished.

Thanks Daniel, but that won’t fix it I’m affraid.

Thank you for reporting this. A fix for this issue has been released on develop

I think you are confused here. The repaint is 100% NOT happening while the constructor is still running.

Given that both transforms can’t be applied simultaneously, does that also apply to its parents? So if the whole editor is being transformed (window scaling), and you use a Drawable with a “drawableTransform”, does it all work correctly?

The setBounds will call repaint() if the size has changed. The actual paint will of course happen later asynchronously.
But you are right, the problem couldn’t be related with the placement of setSize.

It’s not even added to the parent, yet. All the “repaint” call will do is set a flag. And even if you changed the call order, it would still not change the outcome.

The restriction doesn’t apply to parents or children.

Using setDrawableTransform() will itself result in calls to setTransform() so both function is trying to modify the same underlying field, which is why when calling both you can’t know which one will eventually take effect.