Resizing plugin by scaling

Hi, I’m trying to perform the following:

  1. Have a resizable window
  2. When the window size changes calculate a scale factor and then scale the window
  3. Calculate the new bounds of the window and set the window size

Is this a method other people use? Having trouble getting this up and running.

thx

You should not scale the window itself but a component inside the window.
You may need to put all your widget inside this dummy wrapper component.

As well, put a ComponentBoundsConstrainer to keep your window ratio
see setFixedAspectRatio

1 Like

Hi, thanks. I’ll give that a go.

Hi, I tried this and it basically works, but as I’m resizing the main window, it jumps around in size quite a bit. is there anything recommended to stop this? thx

I think this is related to the bound constrainer with the ratio.

1 Like

got ya - so there’s nothing to be done?

Not that I know of but I may be just unaware of the fix.

1 Like

Interestingly enough, this jumping around only appears to happen on Mac, not on Windows…

I’m not sure what you meant by ‘by scaling’, so sorry if this is not what you meant.

You should only have to scale a parent, and all the children will all scale with it.

My editor is very thin and has a full size child that I scale in resize()
‘backgroundSize’ is the back panel dimensions.
As you can see I set the aspect ratio, because I want my circles to stay circles.

EdtorBase is a child of MyPluginEditor, and holds all of the plug-in’s components.

I apologise if things are in the wrong order for you, but it works. :slightly_smiling_face:


MyPlugEditor::MyPlugEditor(MyPlugAudioProcessor& p) : AudioProcessorEditor (&p), processor (p)
{
	editorBase = std::make_unique<EditorBase>(p);
	editorBase->setBounds(0, 0, editorBase->backgroundSize.getX(), editorBase->backgroundSize.getY());
.
	// Aspect ratio stuff...
	sizeRatio = (float)editorBase->backgroundSize.getX() / (float)(editorBase->backgroundSize.getY());
	getConstrainer()->setFixedAspectRatio(sizeRatio);
.
    // Set this parent's size...
    setSize(backgroundSize.getX() / 2, backgroundSize.getY() / 2);
	setResizable(true, true);
	setResizeLimits(256, 256, editorBase->backgroundSize.getX() , editorBase->backgroundSize.getY());
	addAndMakeVisible(editorBase.get());

And resize does just this:


void MyPlugEditor::resized()
{
	auto area = getLocalBounds();
	float sc = (float)area.getWidth() / editorBase->backgroundSize.getX();
	editorBase->setTransform(AffineTransform::scale(sc));
}   

Now I can rescale the plugin and all the children will rescale with it. Which is amazingly useful, as this is only place I scale. Whereas before, I was scaling everything by hand, on each level. This is WAY faster.

3 Likes