setContentComponent with resizeToFit strips border


#1

With the following code:

class DummyWindow : public DocumentWindow { public: DummyWindow() : DocumentWindow(T("Dummy"), Colours::white, DocumentWindow::allButtons) { DummyComponent* dummy = new DummyComponent(); dummy->setSize(200, 100); setContentComponent(dummy, true, true); } };
the DummyComponent comes out with a size of 194px x 94px, because JUCE internally subtracts the 3px border of the DocumentWindow somehow from the DummyComponents size.

If the setSize and setContentComponent gets swaped it works like it should, so in this example there is no real problem. But if the DummyComponent sets it desired size in its constructor (like some of mine do) they end with the wrong size.

// Edit:
And I just noticed that it’s possible to force a DocumentWindow this way to become smaller than its minimal size.


#2

I think this works OK if you set the window to a non-zero size first.

Matt


#3

Well I just tried this code and it came out correctly at 200x100, so can’t think why it’d be different for you. Are you sure you’re not accidentally setting the window’s size later on?

And the window’s minimum size is only there for use by the resizer components - it’s always possible to make it any size you want by a direct call to a setBounds method.


#4

Ups, my fault. I didn’t test the given example and I missed the critical line of code in it.

class DummyWindow : public DocumentWindow { public: DummyWindow() : DocumentWindow(T("Dummy"), Colours::white, DocumentWindow::allButtons) { DummyComponent* dummy = new DummyComponent(); dummy->setSize(200, 100); setContentComponent(dummy, true, true); setResizable(true, false); } };
The setResizable call makes the difference. If the setResizable call is made after the setContentComponent call the DummyComponent becomes the wrong size in the end (194px x 94px), because the resizable border “grows” to the inside of the DocumentWindow and reduces the DummyComponents size.
If the setResizable call is made befor the setContentComponent call the resizable border is already there when the content component gets set and the DummyComponent becomes the right size.


#5

Ah, I see.

Well this tweak at the end of ResizableWindow::setResizable() should sort that out:

[code]…
deleteAndZero (resizableCorner);
deleteAndZero (resizableBorder);
}

childBoundsChanged (contentComponent);
resized();

}[/code]


#6

That fixed it.


#7