Basic noob question about setting up different app "pages"


#1

Hi all,

I’m trying to create a really simple app that has a few different “screens” or “pages” - basic app flow is

  1. Main page comes up with a few buttons you can click on
  2. Depending on what button you click, you go to another page
  3. One of these pages will be fairly CPU-intensive and involve a lot of DSP

What’s the best way to set this up? Here seem to be the five options

  1. Give the MainWindow one ContentComponent, and give that ContentComponent a few different children, one for each “page.” Just change which one is visible when you click a button.
  2. Give the MainWindow one ContentComponent. Create several children but give the ContentComponent only one - for every button click, detach the current child and attach the new one and make it visible.
  3. Give the MainWindow several ContentComponents, and change which one is visible when you click a button.
  4. Create several ContentComponents but give the MainWindow only one - for every button click, detach the current ContentComponent and attach the new one and make it visible.
  5. Do any of the above, but instead of just making the children components visible or invisible, actually create and delete them anew each time.

Does anyone have any advice on how is best or the “canonical” way to accomplish this objective? I assume I’ll want to use ApplicationCommandManager, which is fine. My only concern is that I don’t want the CPU-intensive DSP page to keep chugging along if it’s not actually the visible window. Being as I’m new to JUCE, I’m not sure which of the above solutions is most elegant.

Thanks all, your help is muchly appreciated.


#2

None of the options you’ve listed is wrong or right! How you do it is just down to your own needs/taste, really.

I tend to delete/re-create components when they’re needed rather than keeping a bunch of them alive and swapping them over - mainly because taking that approach encourages you to keep your program logic in your model classes and to keep your UI classes light. (But again, that might not be appropriate in your case)


#3

Thank you Jules, very helpful indeed! In general, I find that with many libraries, it’s all about “doing things the canonical way” or else you find yourself kicking yourself months down the road as your codebase becomes unmanageable… good to know that JUCE is flexible.


#4

[quote=“jules”]None of the options you’ve listed is wrong or right! How you do it is just down to your own needs/taste, really.

I tend to delete/re-create components when they’re needed rather than keeping a bunch of them alive and swapping them over - mainly because taking that approach encourages you to keep your program logic in your model classes and to keep your UI classes light. (But again, that might not be appropriate in your case)[/quote]

interesting way.
I’m often do that in Max5 UI design too.

question:
when you create a component with a button that provide value change of a variable in the code, if you kill that component (containing that button), I guess it let the variable value like it was when you kill the component right?
I guess, because it only binds it & listen it when you create it etc