Jamba C++ API  4.0.0
SwitchViewContainer.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 pongasoft
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  *
16  * @author Yan Pujante
17  */
18 #pragma once
19 
21 
23 
46 class SwitchViewContainer : public CustomViewAdapter<CViewContainer>, IViewContainerListenerAdapter
47 {
48 public:
49  // Lifecycle
50  explicit SwitchViewContainer(const CRect &iSize);
51  ~SwitchViewContainer() override;
52 
54  virtual void setSwitchControlTag (ParamID iTag) { fSwitchControlTag = iTag; };
55 
59  ParamID getSwitchControlTag () const { return fSwitchControlTag; }
60 
63  const std::vector<std::string> &getTemplateNames() const { return fTemplateNames; }
64  void setTemplateNames(const std::vector<std::string> &iNames) { fTemplateNames = iNames; switchCurrentView(); }
65 
66  // registerParameters
67  void registerParameters() override;
68 
69  // afterCreate
70  virtual void afterCreate(IUIDescription const *iDescription, IController *iController);
71 
72  // onParameterChange
73  void onParameterChange(ParamID iParamID) override;
74 
75 protected:
81  void viewContainerViewAdded(CViewContainer *container, CView *view) override;
82 
85  virtual void switchCurrentView();
86 
91  virtual void setCurrentView(CView *iCurrentView);
92 
96  virtual std::string computeTemplateName(int iIndex);
97 
98 protected:
99  IUIDescription const *fUIDescription{};
100  IController *fUIController{};
101 
104 
105  std::vector<std::string> fTemplateNames;
106 
107  CView *fCurrentView{};
108  std::string fCurrentTemplateName{};
109 
110 public:
111  class Creator : public CustomViewCreator<SwitchViewContainer, CustomViewAdapter<CViewContainer>>
112  {
113  public:
114  explicit Creator(char const *iViewName = nullptr, char const *iDisplayName = nullptr) :
115  CustomViewCreator(iViewName, iDisplayName)
116  {
119  }
120  };
121 };
122 
127 template<>
129  const UIAttributes &iAttributes,
130  const IUIDescription *iDescription);
131 
132 }
ParamID getSwitchControlTag() const
id for the parameter tied to switching.
Definition: SwitchViewContainer.h:59
Inherit from this class to provide the factory for a custom view.
Definition: CustomViewCreator.h:1311
SwitchViewContainer(const CRect &iSize)
Definition: SwitchViewContainer.cpp:26
virtual void switchCurrentView()
Called whenever something has changed to switch to a new current view.
Definition: SwitchViewContainer.cpp:67
const std::vector< std::string > & getTemplateNames() const
A comma separated list of template names.
Definition: SwitchViewContainer.h:63
This view offers dynamic switching between multiple views.
Definition: SwitchViewContainer.h:46
std::string fCurrentTemplateName
Definition: SwitchViewContainer.h:108
void viewContainerViewAdded(CViewContainer *container, CView *view) override
The only purpose of this callback (from IViewContainerListenerAdapter) is to catch the unavoidable ca...
Definition: SwitchViewContainer.cpp:113
IController * fUIController
Definition: SwitchViewContainer.h:100
GUIOptionalParam< int32 > fControlSwitch
Definition: SwitchViewContainer.h:103
void registerTagAttribute(std::string const &iName, typename TagAttribute::Getter iGetter, typename TagAttribute::Setter iSetter)
Registers a tag attribute with the given name and getter/setter.
Definition: CustomViewCreator.h:1047
virtual void setSwitchControlTag(ParamID iTag)
Attribute switch-control-tag
Definition: SwitchViewContainer.h:54
virtual void setCurrentView(CView *iCurrentView)
Sets the current view to the one provided (remove previous view from container children and add this ...
Definition: SwitchViewContainer.cpp:96
This class can be used to extend VSTGUI classes directly while still benefiting from the extensions a...
Definition: CustomView.h:335
virtual void afterCreate(IUIDescription const *iDescription, IController *iController)
Definition: SwitchViewContainer.cpp:43
IUIDescription const * fUIDescription
Definition: SwitchViewContainer.h:99
~SwitchViewContainer() override
Definition: SwitchViewContainer.cpp:34
ParamID fSwitchControlTag
Definition: SwitchViewContainer.h:102
Definition: CustomController.h:24
void registerParameters() override
Subclasses should override this method to register each parameter.
Definition: SwitchViewContainer.cpp:52
std::vector< std::string > fTemplateNames
Definition: SwitchViewContainer.h:105
Creator(char const *iViewName=nullptr, char const *iDisplayName=nullptr)
Definition: SwitchViewContainer.h:114
SwitchViewContainer * createCustomView< SwitchViewContainer >(CRect const &iSize, const UIAttributes &iAttributes, const IUIDescription *iDescription)
This specialization is required to inject the IUIDescription object used to dynamically create a view...
Definition: SwitchViewContainer.cpp:138
void onParameterChange(ParamID iParamID) override
This is the callback that should be implemented to handle parameter changes.
Definition: SwitchViewContainer.cpp:86
void registerVectorStringAttribute(std::string const &iName, typename VectorStringAttribute::Getter iGetter, typename VectorStringAttribute::Setter iSetter, char iDelimiter=',', bool iSkipEmptyEntries=false)
Registers a Range attribute with the given name and getter/setter.
Definition: CustomViewCreator.h:1010
void setTemplateNames(const std::vector< std::string > &iNames)
Definition: SwitchViewContainer.h:64
CView * fCurrentView
Definition: SwitchViewContainer.h:107
constexpr ParamID UNDEFINED_PARAM_ID
Constant used throughout the code to test whether the ParamID represents a valid id or an undefined o...
Definition: Types.h:47
virtual std::string computeTemplateName(int iIndex)
Lookup the name of the template in the vector.
Definition: SwitchViewContainer.cpp:125