[SOLVED] resizable windows (how to)


#1

I am trying to add the ability to resize my os x application, as well as remove the full-screen button.   Every since I added the setFullScreen() and setResizable() calls in my MainWindow constructor, the application triggers a jassert() in juce_ResizableWindow.cpp

 

class MainWindow    : public DocumentWindow

    {

    public:

        MainWindow (String name)  : DocumentWindow (name,

                                                    Colours::lightgrey,

                                                    DocumentWindow::allButtons)

        {

            setUsingNativeTitleBar (true);

            MainContentComponent* mcc = new MainContentComponent();

            centreWithSize (getWidth(), getHeight());

            setContentOwned (mcc, true);

            

            

            this->setFullScreen(false);

            

            this->setResizable(true, true);

            int maxHeight = Desktop::getInstance().getDisplays().getMainDisplay().userArea.getHeight();

            this->setResizeLimits(1024, 512,

                                  1310,

                                  maxHeight );

            setVisible (true);

            

           // mcc->setMainWindow(this);

            

            

        }

What am I doing wrong?   it seems the setContentOwned() is where everything goes downhill and causes the problems.  


#2

Just checked your code on OSX Yosemite and didn't get any asserts... 

(created a new GUI application in Introjucer and just copypasted your code into the MainWindow constructor)

What assert are you hitting exactly, and are you sure it's not caused by something else?


#3

The jassert's here are getting caught: 

 

void ResizableWindow::childBoundsChanged (Component* child)

{

    if ((child == contentComponent) && (child != nullptr) && resizeToFitContent)

    {

        // not going to look very good if this component has a zero size..

        jassert (child->getWidth() > 0);

        jassert (child->getHeight() > 0);


        const BorderSize<int> borders (getContentComponentBorder());


        setSize (child->getWidth() + borders.getLeftAndRight(),

                 child->getHeight() + borders.getTopAndBottom());

    }

}

edit:  

looks like I had setSize() in my MainContentComponent commented out!!!  arghh!!!!  problem solved. 


#4

One thing I particularly like about JUCE is that usually, the asserts are telling you pretty exactly what went wrong :-)