DrawableButton Edge Indent with ImageOnButtonBackground


Is there any special reason why we can’t set an edge indent with the ImageOnButtonBackground style? I’ve had a number of cases where I don’t want extremely large icons on buttons and it seems a bit long winded to create a subclass for a simple one line change.

I know just adding a reduction in resized(): if (style == ImageOnButtonBackground) would mess with existing code but you could just set the edgeIndent to 0 in the constructor if this style is being used.

Or is there a simple alternative that I’m missing?


Can you suggest a change that’d do what you need?


This does what I need but it may confuse existing code if people change button styles after creation as the edge indent will have already been set.

DrawableButton::DrawableButton (const String& name, const DrawableButton::ButtonStyle buttonStyle) : Button (name), style (buttonStyle), currentImage (nullptr), edgeIndent (buttonStyle == ImageOnButtonBackground ? 0 : 3) // change this {

[code]void DrawableButton::resized()

if (currentImage != nullptr)
    if (style == ImageRaw)
        currentImage->setOriginWithOriginalSize (Point<float>());
        Rectangle<int> imageSpace;

        if (style == ImageOnButtonBackground)
            imageSpace = getLocalBounds().reduced (getWidth() / 4, getHeight() / 4);
            imageSpace.reduce (edgeIndent, edgeIndent);                         // add this



Ok, I’ve given the class a bit of a spring-clean too. For the indent, I’ve made it use the indent only if it’s greater than the default indent that it would have used previously, so old code should also still look the same.


Cheers! This does exactly what I need now.