Resize DrawableText

Hi,

my DrawableText is created from an svg and its size is calculated from Font and Text metrics.

If, at a later point in Time, I want to replace the Text I also need to resize the DrawableText (at least if the new Text is wider), or it will be squeezed into the originally given size.

setSize() doesnt seem to have any affect. Probably because the text could be transformed.

I see that setBoundingBox() affects the size, but I don't understand how I simply apply this method (or any other more adequate) to only resize the text field, so the new text fits.

Thanks for any hints!

Cheers,

raketa

... thats what I thought...

is setBoundingBox() at least the right approach?

thanks,

raketa.

I don't want to be irritant but whats so difficult about anwering this simple question?

(Its OK to say something like: "its not possible. What you are trying is completely nuts. A DrawableText is not intended for resizing - thats completely out of the concept of a DrawableText..." or something similar.)

Its not pretty straightforward to me how the Bounding stuff and the Positioner actually work...

Cheers,

raketa

 

Apologies it took so long, we missed your other posts!

I agree that this isn't too intuitive, so thank you for your feedback. I've written some code for you that explains things for you (assume drawableText is an instance of DrawableText)...

MainContentComponent::MainContentComponent()
{
    addAndMakeVisible (&drawableText);

    drawableText.setText ("Test!");
    drawableText.setColour(Colour (0xff00ff50));

    setSize (600, 400);
}

MainContentComponent::~MainContentComponent()
{

}

void MainContentComponent::paint (Graphics& g)
{
    g.fillAll (Colour (0xff001F36));
    drawableText.draw (g, 1.0f);
}

void MainContentComponent::resized()
{
    // these dimensions are used to draw the text
    // the reason setBounds doesn't work in this context is
    // because the MainContentComponent is drawing it using a
    // Graphics& object within its own bounds
    drawableText.setBoundingBox
    (
        RelativeParallelogram
        (
            Rectangle<float> (0, 0, getWidth(), getHeight())
        )
    );

    // set your font height here!
    drawableText.setFontHeight (getHeight());
}

Hope this helps! :)

Thanks,

that was the direction I needed to look into!

Since I have my DrawableText paint()ed by the Juce Component your code would repositioning it on the right top of the Window.

 

Here is my adaption to keep it at the current position:

drawableText.setText(text);
juce::Rectangle<float>bounds = drawableText.getBoundingBox().getBounds(nullptr);
bounds.setWidth(drawableText.getFont().getStringWidth(label));
drawableText.setBoundingBox(juce::RelativeParallelogram(bounds));

Cheers,

raketa