Trouble with simple ShapeButton


#1

I’m not sure what I’m missing here, but my ShapeButton does not want to appear.
Here’s the code:

// initialisation
              recordButton ("Record",
                      Colours::red,
                      Colours::red.brighter(),
                      Colours::red.darker()),
//////////////////

        Path recordPath;
        float shapeButtonSize = getHeight()/12;
        recordPath.addEllipse(0, 0, shapeButtonSize, shapeButtonSize);
        recordButton.setShape(recordPath, false, true, false);
        recordButton.setBounds (0, 0, 50, 50);
        addAndMakeVisible (&recordButton);

I’ve tested with g.fillPath(recordPath) in my paint method and it works there… any ideas?


#2

Where in your project are you running this code from? If it’s in the constructor of a parent Component you’ll want to make sure that you’ve given it a size before with a call to setSize()

Ed


#3

Found it, there was a subtle clue there…

float shapeButtonSize = getHeight()/12;

getHeight returns 0 as the component does not have a height yet, so yes I need to set this in resized() instead of the constructor!