From cabb396c838fa8aceab5c79833ab93dca0343d58 Mon Sep 17 00:00:00 2001 From: reuk Date: Tue, 29 Apr 2025 20:29:40 +0100 Subject: [PATCH] PIP: Respect screen safe areas for demo projects --- extras/Build/CMake/PIPComponent.cpp.in | 34 ++++++++++++++++-- .../Projucer/JuceLibraryCode/BinaryData.cpp | 36 ++++++++++++++++--- extras/Projucer/JuceLibraryCode/BinaryData.h | 2 +- 3 files changed, 64 insertions(+), 8 deletions(-) diff --git a/extras/Build/CMake/PIPComponent.cpp.in b/extras/Build/CMake/PIPComponent.cpp.in index 662c11d290..270629335e 100644 --- a/extras/Build/CMake/PIPComponent.cpp.in +++ b/extras/Build/CMake/PIPComponent.cpp.in @@ -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 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 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 content; + }; + + void parentSizeChanged() override + { + if (auto* c = getContentComponent()) + c->resized(); + } + #endif + private: JUCEApplication& app; diff --git a/extras/Projucer/JuceLibraryCode/BinaryData.cpp b/extras/Projucer/JuceLibraryCode/BinaryData.cpp index 5e57dde1b8..9599699c4f 100644 --- a/extras/Projucer/JuceLibraryCode/BinaryData.cpp +++ b/extras/Projucer/JuceLibraryCode/BinaryData.cpp @@ -114,7 +114,7 @@ static const unsigned char temp_binary_data_4[] = "\r\n" " void initialise (const juce::String&) override\r\n" " {\r\n" -" mainWindow.reset (new MainWindow (\"${JUCE_PIP_NAME}\", new ${JUCE_PIP_MAIN_CLASS}, *this));\r\n" +" mainWindow.reset (new MainWindow (\"${JUCE_PIP_NAME}\", std::make_unique<${JUCE_PIP_MAIN_CLASS}>(), *this));\r\n" " }\r\n" "\r\n" " void shutdown() override { mainWindow = nullptr; }\r\n" @@ -123,18 +123,19 @@ static const unsigned char temp_binary_data_4[] = " class MainWindow : public juce::DocumentWindow\r\n" " {\r\n" " public:\r\n" -" MainWindow (const juce::String& name, juce::Component* c, JUCEApplication& a)\r\n" +" MainWindow (const juce::String& name, std::unique_ptr c, JUCEApplication& a)\r\n" " : DocumentWindow (name, juce::Desktop::getInstance().getDefaultLookAndFeel()\r\n" " .findColour (ResizableWindow::backgroundColourId),\r\n" " juce::DocumentWindow::allButtons),\r\n" " app (a)\r\n" " {\r\n" " setUsingNativeTitleBar (true);\r\n" -" setContentOwned (c, true);\r\n" "\r\n" " #if JUCE_ANDROID || JUCE_IOS\r\n" +" setContentOwned (new SafeAreaComponent { std::move (c) }, true);\r\n" " setFullScreen (true);\r\n" " #else\r\n" +" setContentOwned (c.release(), true);\r\n" " setResizable (true, false);\r\n" " setResizeLimits (300, 250, 10000, 10000);\r\n" " centreWithSize (getWidth(), getHeight());\r\n" @@ -148,6 +149,33 @@ static const unsigned char temp_binary_data_4[] = " app.systemRequestedQuit();\r\n" " }\r\n" "\r\n" +" #if JUCE_ANDROID || JUCE_IOS\r\n" +" class SafeAreaComponent : public juce::Component\r\n" +" {\r\n" +" public:\r\n" +" explicit SafeAreaComponent (std::unique_ptr c)\r\n" +" : content (std::move (c))\r\n" +" {\r\n" +" addAndMakeVisible (*content);\r\n" +" }\r\n" +"\r\n" +" void resized() override\r\n" +" {\r\n" +" if (const auto* d = Desktop::getInstance().getDisplays().getDisplayForRect (getLocalBounds()))\r\n" +" content->setBounds (d->safeAreaInsets.subtractedFrom (getLocalBounds()));\r\n" +" }\r\n" +"\r\n" +" private:\r\n" +" std::unique_ptr content;\r\n" +" };\r\n" +"\r\n" +" void parentSizeChanged() override\r\n" +" {\r\n" +" if (auto* c = getContentComponent())\r\n" +" c->resized();\r\n" +" }\r\n" +" #endif\r\n" +"\r\n" " private:\r\n" " JUCEApplication& app;\r\n" "\r\n" @@ -8988,7 +9016,7 @@ const char* getNamedResource (const char* resourceNameUTF8, int& numBytes) case 0x31d21131: numBytes = 1042; return LaunchScreen_storyboard; case 0x24e5a04d: numBytes = 483; return PIPAudioProcessor_cpp_in; case 0x956e0109: numBytes = 689; return PIPAudioProcessorWithARA_cpp_in; - case 0xd572ce5a: numBytes = 2275; return PIPComponent_cpp_in; + case 0xd572ce5a: numBytes = 3231; return PIPComponent_cpp_in; case 0x1a77c680: numBytes = 299; return PIPConsole_cpp_in; case 0xa41e649d: numBytes = 2842; return RecentFilesMenuTemplate_nib; case 0x667fbbb3: numBytes = 6424; return UnityPluginGUIScript_cs_in; diff --git a/extras/Projucer/JuceLibraryCode/BinaryData.h b/extras/Projucer/JuceLibraryCode/BinaryData.h index ccb8811769..e1dab7b59f 100644 --- a/extras/Projucer/JuceLibraryCode/BinaryData.h +++ b/extras/Projucer/JuceLibraryCode/BinaryData.h @@ -21,7 +21,7 @@ namespace BinaryData const int PIPAudioProcessorWithARA_cpp_inSize = 689; extern const char* PIPComponent_cpp_in; - const int PIPComponent_cpp_inSize = 2275; + const int PIPComponent_cpp_inSize = 3231; extern const char* PIPConsole_cpp_in; const int PIPConsole_cpp_inSize = 299;