DrawableButton Edge Indent with ImageOnButtonBackground


#1

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?


#2

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


#3

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 {
and

[code]void DrawableButton::resized()
{
Button::resized();

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

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

[/code]


#4

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.


#5

Cheers! This does exactly what I need now.