diff --git a/clap-libs/clap-helpers b/clap-libs/clap-helpers index 2bb43c1..b101259 160000 --- a/clap-libs/clap-helpers +++ b/clap-libs/clap-helpers @@ -1 +1 @@ -Subproject commit 2bb43c18788c689708ead6f127a2d75e772ab389 +Subproject commit b101259ae06964c76c6806f02ec07847acb7b6dc diff --git a/src/wrapper/clap-juce-wrapper.cpp b/src/wrapper/clap-juce-wrapper.cpp index 87a4fd1..e1b6737 100644 --- a/src/wrapper/clap-juce-wrapper.cpp +++ b/src/wrapper/clap-juce-wrapper.cpp @@ -108,6 +108,10 @@ JUCE_BEGIN_IGNORE_WARNINGS_MSVC(4996) // allow strncpy #define CLAP_MISBEHAVIOUR_HANDLER_LEVEL "Ignore" #endif +// This is useful for debugging overrides +// #undef CLAP_MISBEHAVIOUR_HANDLER_LEVEL +// #define CLAP_MISBEHAVIOUR_HANDLER_LEVEL Terminate + /* * A little class that sets an atomic bool to a value across its lifetime and * restores it on exit. @@ -992,6 +996,7 @@ class ClapJuceWrapper : public clap::helpers::Plugin< return editor->isResizable(); return true; } + bool guiAdjustSize(uint32_t *w, uint32_t *h) noexcept override { if (!editor) @@ -1000,7 +1005,42 @@ class ClapJuceWrapper : public clap::helpers::Plugin< if (!editor->isResizable()) return false; - editor->setSize(static_cast(*w), static_cast(*h)); + auto cst = editor->getConstrainer(); + + if (!cst) + return true; // we have no constraints. Whaever is fine! + + auto minW = (uint32_t)cst->getMinimumWidth(); + auto maxW = (uint32_t)cst->getMaximumWidth(); + auto minH = (uint32_t)cst->getMinimumHeight(); + auto maxH = (uint32_t)cst->getMaximumHeight(); + + auto width = std::clamp(*w, minW, maxW); + auto height = std::clamp(*h, minH, maxH); + + auto aspectRatio = (float)cst->getFixedAspectRatio(); + + if (aspectRatio != 0.0) + { + // This is an unsatisfactory but stable algorithm + width = aspectRatio * height; + } + + *w = width; + *h = height; + + return true; + } + + bool guiSetSize(uint32_t width, uint32_t height) noexcept override + { + if (!editor) + return false; + + if (!editor->isResizable()) + return false; + + editor->setSize(static_cast(width), static_cast(height)); return true; }