From 47f6a506bcaa72a0ff4d5e8611d4c8e8b317c98a Mon Sep 17 00:00:00 2001 From: Christoph Hart Date: Thu, 23 Jan 2025 11:38:12 +0100 Subject: [PATCH] - add ability to create dynamic components from encoded dialogs --- hi_tools/hi_multipage/PageFactory.h | 40 ++++++++++++++++++++++++----- hi_tools/hi_multipage/State.h | 2 ++ 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/hi_tools/hi_multipage/PageFactory.h b/hi_tools/hi_multipage/PageFactory.h index e9f7c22f58..838dad69c7 100644 --- a/hi_tools/hi_multipage/PageFactory.h +++ b/hi_tools/hi_multipage/PageFactory.h @@ -260,14 +260,42 @@ struct DummyContent: public Component, void paint(Graphics& g) override { - g.fillAll(Colours::white.withAlpha(0.1f)); - g.setColour(Colours::white.withAlpha(0.7f)); - g.setFont(GLOBAL_MONOSPACE_FONT()); - g.drawRect(getLocalBounds(), 1); - g.drawText("Placeholder for " + classId, getLocalBounds().toFloat(), Justification::centred); + if(dynamicContent == nullptr) + { + g.fillAll(Colours::white.withAlpha(0.1f)); + g.setColour(Colours::white.withAlpha(0.7f)); + g.setFont(GLOBAL_MONOSPACE_FONT()); + g.drawRect(getLocalBounds(), 1); + g.drawText("Placeholder for " + classId, getLocalBounds().toFloat(), Justification::centred); + } } - void postInit() override {}; + void resized() override + { + if(dynamicContent != nullptr) + { + dynamicContent->setBounds(getLocalBounds()); + } + } + + void postInit() override + { + auto& s = rootDialog.getState(); + + if(s.dynamicComponentFactory) + { + auto newComponent = s.dynamicComponentFactory(classId); + + if(newComponent != nullptr) + { + addAndMakeVisible(dynamicContent = newComponent); + resized(); + } + } + }; + + ScopedPointer dynamicContent; + Result checkGlobalState(var state) override { return Result::ok(); } String classId; diff --git a/hi_tools/hi_multipage/State.h b/hi_tools/hi_multipage/State.h index 6ea5f9f455..ebb8c71583 100644 --- a/hi_tools/hi_multipage/State.h +++ b/hi_tools/hi_multipage/State.h @@ -272,6 +272,8 @@ class State: public Thread, logMessage(MessageType::Hlac, message); jassertfalse; } + + std::function dynamicComponentFactory; ScopedPointer stateProvider;