1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-09 23:34:20 +00:00

PIP: Respect screen safe areas for demo projects

This commit is contained in:
reuk 2025-04-29 20:29:40 +01:00
parent 34c32cbaf0
commit cabb396c83
No known key found for this signature in database
3 changed files with 64 additions and 8 deletions

View file

@ -20,7 +20,7 @@ public:
void initialise (const juce::String&) override
{
mainWindow.reset (new MainWindow ("${JUCE_PIP_NAME}", new ${JUCE_PIP_MAIN_CLASS}, *this));
mainWindow.reset (new MainWindow ("${JUCE_PIP_NAME}", std::make_unique<${JUCE_PIP_MAIN_CLASS}>(), *this));
}
void shutdown() override { mainWindow = nullptr; }
@ -29,18 +29,19 @@ private:
class MainWindow : public juce::DocumentWindow
{
public:
MainWindow (const juce::String& name, juce::Component* c, JUCEApplication& a)
MainWindow (const juce::String& name, std::unique_ptr<juce::Component> c, JUCEApplication& a)
: DocumentWindow (name, juce::Desktop::getInstance().getDefaultLookAndFeel()
.findColour (ResizableWindow::backgroundColourId),
juce::DocumentWindow::allButtons),
app (a)
{
setUsingNativeTitleBar (true);
setContentOwned (c, true);
#if JUCE_ANDROID || JUCE_IOS
setContentOwned (new SafeAreaComponent { std::move (c) }, true);
setFullScreen (true);
#else
setContentOwned (c.release(), true);
setResizable (true, false);
setResizeLimits (300, 250, 10000, 10000);
centreWithSize (getWidth(), getHeight());
@ -54,6 +55,33 @@ private:
app.systemRequestedQuit();
}
#if JUCE_ANDROID || JUCE_IOS
class SafeAreaComponent : public juce::Component
{
public:
explicit SafeAreaComponent (std::unique_ptr<Component> c)
: content (std::move (c))
{
addAndMakeVisible (*content);
}
void resized() override
{
if (const auto* d = Desktop::getInstance().getDisplays().getDisplayForRect (getLocalBounds()))
content->setBounds (d->safeAreaInsets.subtractedFrom (getLocalBounds()));
}
private:
std::unique_ptr<Component> content;
};
void parentSizeChanged() override
{
if (auto* c = getContentComponent())
c->resized();
}
#endif
private:
JUCEApplication& app;