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

**URL:** <https://forum.juce.com/t/fr-drawablebutton-style-for-image-on-background-but-without-resizing-image/34051>\
**Category:** Feature Requests\
**Created:** [June 23, 2019, 10:30am UTC](https://forum.juce.com/t/fr-drawablebutton-style-for-image-on-background-but-without-resizing-image/34051 "2019-06-23T10:30:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![danradix](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/danradix/32/1113_2.png) [@danradix](https://forum.juce.com/u/danradix)\
**Post date:** [June 23, 2019, 10:30am UTC](https://forum.juce.com/t/fr-drawablebutton-style-for-image-on-background-but-without-resizing-image/34051/1 "2019-06-23T10:30:02Z")

</div>

`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.

---

<div class="post-metadata">

**Author:** ![ed95](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/ed95/32/7635_2.png) [@ed95](https://forum.juce.com/u/ed95)\
**Post date:** [June 24, 2019, 11:13am UTC](https://forum.juce.com/t/fr-drawablebutton-style-for-image-on-background-but-without-resizing-image/34051/2 "2019-06-24T11:13:28Z")

</div>

> <https://github.com/WeAreROLI/JUCE/commit/b5a2d03a8c98a1a9986306d0ab44f5db2d11cd9b>

---

<div class="post-metadata">

**Author:** ![danradix](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/danradix/32/1113_2.png) [@danradix](https://forum.juce.com/u/danradix)\
**Post date:** [June 24, 2019, 12:09pm UTC](https://forum.juce.com/t/fr-drawablebutton-style-for-image-on-background-but-without-resizing-image/34051/3 "2019-06-24T12:09:32Z")

</div>

Awesome response time, thanks @ed95!

---

<div class="post-metadata">

**Author:** ![danradix](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/danradix/32/1113_2.png) [@danradix](https://forum.juce.com/u/danradix)\
**Post date:** [June 24, 2019, 12:29pm UTC](https://forum.juce.com/t/fr-drawablebutton-style-for-image-on-background-but-without-resizing-image/34051/4 "2019-06-24T12:29:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ed95](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/ed95/32/7635_2.png) [@ed95](https://forum.juce.com/u/ed95)\
**Post date:** [June 24, 2019, 2:42pm UTC](https://forum.juce.com/t/fr-drawablebutton-style-for-image-on-background-but-without-resizing-image/34051/5 "2019-06-24T14:42:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![danradix](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/danradix/32/1113_2.png) [@danradix](https://forum.juce.com/u/danradix)\
**Post date:** [June 24, 2019, 4:48pm UTC](https://forum.juce.com/t/fr-drawablebutton-style-for-image-on-background-but-without-resizing-image/34051/6 "2019-06-24T16:48:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ed95](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/ed95/32/7635_2.png) [@ed95](https://forum.juce.com/u/ed95)\
**Post date:** [June 25, 2019, 10:16am UTC](https://forum.juce.com/t/fr-drawablebutton-style-for-image-on-background-but-without-resizing-image/34051/7 "2019-06-25T10:16:51Z")

</div>

Ah yeah, of course. I’ve pushed that [here](https://github.com/WeAreROLI/JUCE/commit/718712a5a555c6e98c9f9b44b91eb2ab31e00ba7) - thanks!
