Incorrect TopLevelWindow size with native title bar


#1

I create a DocumentWindow, and attach a component. The component is exactly sized to 200, 200

If setUsingNativeTitleBar is false, the content area of the window is perfectly sized to 200 by 200. But if setUsingNativeTitleBar is set to true, with no other changes, the content area comes out to 208 x 234. This is making it difficult to get the window to perfectly match the component contents.

I have attached a photo to illustrate the difference.

Here is the code that constructs the window:

MainWindow::MainWindow()
: DocumentWindow (T("JuceApp")
, Colours::black
, DocumentWindow::allButtons
, false )
{
  MainComponent* const contentComponent = new MainComponent();

  setOpaque( true );
  setResizable( true, false );
  //setUsingNativeTitleBar( true );
  setDropShadowEnabled( false );

  setContentComponent (contentComponent, true, true);

  Component::addToDesktop (getDesktopWindowStyleFlags());
  centreWithSize (getWidth(), getHeight());
  setVisible (true);
}

And here is the code that constructs the content component

MainComponent::MainComponent ()
{
  setSize (200, 200);
}

[attachment=0]content.png[/attachment]


#2

Well I forgot to report the version of Juce, it is 1.51.16, sorry!

I debugged it and figured it out, it is because isUsingNativeTitleBar() returns false even though I set it to true, because the heavyweight peer hasn’t been created yet and therefore isOnDesktop() returns false.

The workaround is to add the content component after I create the window and add it to the desktop:

  MainComponent* const contentComponent = new MainComponent();

  setOpaque( true );
  setResizable( true, false );
  setUsingNativeTitleBar( true );
  setDropShadowEnabled( false );
  setMenuBar( contentComponent );

  Component::addToDesktop (getDesktopWindowStyleFlags());
  setContentComponent (contentComponent, true, true); // happens after addToDesktop()
  centreWithSize (getWidth(), getHeight());
  setVisible (true);

#3

Hmm, good point… I had a quick look at whether I could change it so that you wouldn’t have work around that, or at least to add an assertion to warn you if you do it, but can’t see any easy way of doing so…


#4

I agree, I thought to try to fix it but it would get complicated and messy. Perhaps the best solution is to just add a comment to TopLevelWindow or something describing the behavior.