Switching Template

I have defined two templates in the GUI Editor : MainWindow and SettingsWindow.

Then there is a button on MainWindow for which i have a separate Subcontroller as follows

IController* MainController::createSubController(UTF8StringPtr _name, 
          const VSTGUI::IUIDescription* /*description*/,VSTGUI::VST3Editor* editor)
 {
        ConstString name(_name);
   	if (name == "ButtonController")
 	 {
 		 return new ButtonController(editor);
 	  }
 	return nullptr;
 }

Here’s the ButtonController class which responds to button click

class ButtonController : public VSTGUI::DelegationController
	{
	public:
		ButtonController(VSTGUI::IController* parent) : DelegationController(parent) {};
		~ButtonController();
		IControlListener* getControlListener(VSTGUI::UTF8StringPtr controlTagName)	override {	return this;}
		void valueChanged(VSTGUI::CControl* pControl)	
        { 
            //how do I switch the template from MainWindow to SettingsWindow here ?
        }
	};

how do I switch the template from MainWindow to SettingsWindow in valueChanged code above.

I tried it like mainController_->createView("SettingsWindow");

and then in my mainController createview I tried something like this

IPlugView* PLUGIN_API MainController::createView (FIDString name)
{
	// Here the Host wants to open your editor (if you have one)
	if (FIDStringsEqual (name, Vst::ViewType::kEditor))
	{
		auto* view = new VSTGUI::VST3Editor (this, "MainWindow", "myplugineditor.uidesc");
		return view;
	}
	 if (FIDStringsEqual(name, "SettingsWindow"))
	{
	auto* view = new VSTGUI::VST3Editor(this, "SettingsWindow", "myplugineditor.uidesc");
         return view;
	}
	return nullptr;
}

But this is not switching the template. How can I switch the template please ?

You just need to call the exchangeView of the vst3editor you’ve created in EditController::createView.

1 Like