Hi guys, I’m using an OpenGL renderer to paint my components, but every time a resize happens the components kind of stutter and jump a few times before ending up in the right position (even for simple components like Label and TextButton). This is my code, and a video demonstrating the strange resizing behaviour.
#include "../JuceLibraryCode/JuceHeader.h"
#include "MainComponent.h"
class IntrojucerTestsApplication : public JUCEApplication
{
public:
IntrojucerTestsApplication() {}
const String getApplicationName() override { return ProjectInfo::projectName; }
const String getApplicationVersion() override { return ProjectInfo::versionString; }
bool moreThanOneInstanceAllowed() override { return true; }
void initialise (const String& commandLine) override
{
mainWindow = new MainWindow (getApplicationName());
mainWindow->setResizeLimits(300, 300, 100000, 100000);
mainWindow->setResizable(true, false);
}
void shutdown() override
{
mainWindow = nullptr; // (deletes our window)
}
void systemRequestedQuit() override
{
quit();
}
void anotherInstanceStarted (const String& commandLine) override
{
}
class MainWindow : public DocumentWindow
{
public:
MainWindow (String name) : DocumentWindow (name,
Colours::lightgrey,
DocumentWindow::allButtons)
{
setUsingNativeTitleBar (true);
setContentOwned (new MainContentComponent(), true);
centreWithSize (getWidth(), getHeight());
setVisible (true);
}
void closeButtonPressed() override
{
JUCEApplication::getInstance()->systemRequestedQuit();
}
private:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainWindow)
};
private:
ScopedPointer<MainWindow> mainWindow;
};
START_JUCE_APPLICATION (IntrojucerTestsApplication)
#include "MainComponent.h"
MainContentComponent::MainContentComponent()
{
label.setColour(Label::ColourIds::textColourId, Colours::white);
label.setText("Label", juce::NotificationType::dontSendNotification);
addAndMakeVisible(label);
button.setButtonText("Button");
addAndMakeVisible(button);
setSize(300, 300);
#ifdef USE_GL
juceContext.attachTo(*this);
#endif
}
MainContentComponent::~MainContentComponent()
{
#ifdef USE_GL
juceContext.detach();
#endif
}
void MainContentComponent::paint (Graphics& g)
{
g.fillAll (Colour (0xff001F36));
g.setFont (Font (16.0f));
g.setColour (Colours::white);
g.drawText ("Hello World!", getLocalBounds(), Justification::centred, true);
}
void MainContentComponent::resized()
{
label.setBounds(0, 0, 150, 50);
button.setBounds(150, 0, 150, 50);
}
#ifndef MAINCOMPONENT_H_INCLUDED
#define MAINCOMPONENT_H_INCLUDED
//#define USE_GL
#include "../JuceLibraryCode/JuceHeader.h"
class MainContentComponent : public Component
{
public:
MainContentComponent();
~MainContentComponent();
void paint (Graphics&) override;
void resized() override;
#ifdef USE_GL
OpenGLContext juceContext;
#endif
private:
TextButton button;
Label label;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainContentComponent)
};
#endif