# setTransformToFit documentation suggestion

**URL:** <https://forum.juce.com/t/settransformtofit-documentation-suggestion/43256>\
**Category:** General JUCE discussion\
**Created:** [December 15, 2020, 11:24am UTC](https://forum.juce.com/t/settransformtofit-documentation-suggestion/43256 "2020-12-15T11:24:03Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimc/32/16067_2.png) [@jimc](https://forum.juce.com/u/jimc)\
**Post date:** [December 15, 2020, 11:24am UTC](https://forum.juce.com/t/settransformtofit-documentation-suggestion/43256/1 "2020-12-15T11:24:03Z")

</div>

I had to do this to position my SVG …

Even if you take out the centering stuff it’s still pretty bizarre unless you have a fairly deep understanding of what’s going on.

Could we get a simple example added to the docs for Drawable::setTransformToFit ?

```
static void positionDrawable(Drawable& drawable, float x, float centerY, float height, bool alignRight)
{
    auto b = drawable.getDrawableBounds();
    auto aspect = b.getAspectRatio();

    auto r = Rectangle(aspect * height, height).withCentre({0.0f, centerY});

    if (alignRight)
        r = r.withRightX(x);
    else
        r = r.withX(x);

    drawable.setTransformToFit(r, RectanglePlacement::centred);
    drawable.setBounds(b.getSmallestIntegerContainer());
}

```

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [December 15, 2020, 11:35am UTC](https://forum.juce.com/t/settransformtofit-documentation-suggestion/43256/2 "2020-12-15T11:35:44Z")

</div>

Honestly there should be a way to do this in one step using the RectanglePlacement flags, but I can never figure it out without trial and error:

What is the opposite to RectanglePlacement::fillDestination i.e. letterboxed, maximum size without cropping while keeping the aspect ratio?  
If possible it would be great to have an alias, like RectanglePlacement::centred is an alias.

---

<div class="post-metadata">

**Author:** ![jimc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimc/32/16067_2.png) [@jimc](https://forum.juce.com/u/jimc)\
**Post date:** [December 15, 2020, 11:46am UTC](https://forum.juce.com/t/settransformtofit-documentation-suggestion/43256/3 "2020-12-15T11:46:43Z")

</div>

Yeah, it needs a whole new function though, as the setTransformToFit/setBounds dance is really non-standard for something that ought to be simple!

---

<div class="post-metadata">

**Author:** ![alatar](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@alatar](https://forum.juce.com/u/alatar)\
**Post date:** [December 15, 2020, 1:08pm UTC](https://forum.juce.com/t/settransformtofit-documentation-suggestion/43256/4 "2020-12-15T13:08:30Z")

</div>

Ok, interesting.

I have to admit, I only use `drawable.setTransformToFit(Rectangle(x, y, width, height), Rectangleplacement)` when I want to position an SVG.

Is it necessary to additionally use `setBounds()`?

But yes, I have seen that my SVGs are sometimes positioned a bit strangely (They can be a bit too small or slightly too big sometimes). So I have some trial and error, too.

---

<div class="post-metadata">

**Author:** ![jimc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimc/32/16067_2.png) [@jimc](https://forum.juce.com/u/jimc)\
**Post date:** [December 15, 2020, 1:26pm UTC](https://forum.juce.com/t/settransformtofit-documentation-suggestion/43256/5 "2020-12-15T13:26:36Z")

</div>

Oh right, maybe I didn’t need setBounds at all…?

---

<div class="post-metadata">

**Author:** ![alatar](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@alatar](https://forum.juce.com/u/alatar)\
**Post date:** [December 15, 2020, 2:09pm UTC](https://forum.juce.com/t/settransformtofit-documentation-suggestion/43256/6 "2020-12-15T14:09:44Z")

</div>

You don’t need `setBounds` to display the SVG.  
But maybe it makes it easier to position it?  
Hmmm…

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [December 15, 2020, 2:19pm UTC](https://forum.juce.com/t/settransformtofit-documentation-suggestion/43256/7 "2020-12-15T14:19:50Z")

</div>

IIUC you need the setBounds to control the drawables paint() method, while for the draw() you might not need it.  
But in the past I had often unexpected results because of this duality between Drawable and Component. Seems the setBoundsToFit and other methods that modify the transformation moves the result out of the setBounds() area. I know that is to be expected, but I didn’t understand how it is used in a controlled manner (and unusally I have no trouble understanding matrices and transformations).

This is the second reason why I filed this feature request, feel free to support it here:

> [@Make Drawables not inherit Component](https://forum.juce.com/t/make-drawables-not-inherit-component/36191):
>
> Since Drawables inherit Component, they are often limited to be used on the message thread. Feature request: Move the Drawable functionality to independent classes, maybe DrawPrimitive or whatever name, and make the Drawable and it’s descentants a wrapper around that new classes for backward compatibility.

---

<div class="post-metadata">

**Author:** ![alatar](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@alatar](https://forum.juce.com/u/alatar)\
**Post date:** [December 15, 2020, 2:26pm UTC](https://forum.juce.com/t/settransformtofit-documentation-suggestion/43256/8 "2020-12-15T14:26:12Z")

</div>

I agree.  
Drawables are a bit confusing to position.

---

<div class="post-metadata">

**Author:** ![jimc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimc/32/16067_2.png) [@jimc](https://forum.juce.com/u/jimc)\
**Post date:** [April 15, 2023, 2:05pm UTC](https://forum.juce.com/t/settransformtofit-documentation-suggestion/43256/9 "2023-04-15T14:05:47Z")

</div>

Three years later this is still driving me crazy - maybe someone at JUCE HQ could make this easier! 🙂
