[FR] DrawableButton style for image on background, but without resizing image

DrawableButton::ButtonStyle::ImageOnButtonBackground draws an image on the background of the button, but the image is resized to match the button’s proportions, which isn’t always desired. I believe it’s a relatively common use case not wanting to resize the image, e.g., when getting an image with the correct size from a UI designer, but still wanting to use the default button borders (making DrawableButton::ButtonStyle::ImageRaw an invalid alternative).

It would be nice to have a style which keeps the original image size. The code change would be minimal; for the new style, the DrawableButton::resized function would have to pass into setTransformToFit the RectanglePlacement::doNotResize flag in addition to the existing RectanglePlacement::centred flag.

Currently, I worked around this by overriding DrawableButton::getImageBounds() instead.

1 Like

Awesome response time, thanks @ed95!

I think both DrawableButton::getImageBounds() and DrawableButton::paintButton() also need to be adjusted to account for the new style

What do you think needs to be changed? It seems to be working correctly with my above changes but I might have missed something.

When I tested it, the borders didn’t draw correctly without adding the new style to the if condition in the paintButton() function. Similarly, adding the new style to the condition for calculating the insets in getImageBounds() might be needed, not sure.

Ah yeah, of course. I’ve pushed that here - thanks!

2 Likes