Skip to content

Commit

Permalink
- add ability to create dynamic components from encoded dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
christoph-hart committed Jan 23, 2025
1 parent 0a39f3d commit 47f6a50
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
40 changes: 34 additions & 6 deletions hi_tools/hi_multipage/PageFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Component> dynamicContent;

Result checkGlobalState(var state) override { return Result::ok(); }

String classId;
Expand Down
2 changes: 2 additions & 0 deletions hi_tools/hi_multipage/State.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ class State: public Thread,
logMessage(MessageType::Hlac, message);
jassertfalse;
}

std::function<Component*(const String&)> dynamicComponentFactory;

ScopedPointer<ApiProviderBase> stateProvider;

Expand Down

0 comments on commit 47f6a50

Please sign in to comment.