How to make a component persistant?


can someone please have a look at this and tell me what I’m doing is right or wrong?
Let’s say I want to have the Juce Demo Examples such that a demo is persistent, in a way that e.g. the slider in the Widgets demo keep their position when switching back and forth between the demos.

So instead of

Component* createWidgetsDemo() { return new WidgetsDemo(); }

I create an instance of WidgetsDemo in the ContentComp class, and addAndMakeVisible()
and modify void ContentComp::showDemo (Component* demoComp)

to this

void ContentComp::showDemo_test (Component* demoComp) { currentDemo = demoComp; currentDemo->toFront (true); resized(); }

And, instead of declaring

I can use this?

It works but I’m not sure if this the right way.
Some comments are highly appreciated


Erm… No, sounds like you’re floundering a bit there. Maybe do some reading about model-view-controller architecture. You need to understand that your UI and your data model are very different and must be separated.


This first step was already wrong?

Or, how do you do it?


I don’t really know how to answer… Obviously instead of deleting/re-creating a component, you could just keep a pointer to it somewhere. Just like any other kind of object…?