Jamba C++ API  4.1.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 
66  const std::vector<std::string> &getTemplateNames() const { return fTemplateNames; }
67  void setTemplateNames(const std::vector<std::string> &iNames) { fTemplateNames = iNames; switchCurrentView(); }
68 
69  // registerParameters
70  void registerParameters() override;
71 
72  // afterCreate
73  virtual void afterCreate(IUIDescription const *iDescription, IController *iController);
74 
75  // onParameterChange
76  void onParameterChange(ParamID iParamID) override;
77 
78 protected:
84  void viewContainerViewAdded(CViewContainer *container, CView *view) override;
85 
88  virtual void switchCurrentView();
89 
94  virtual void setCurrentView(CView *iCurrentView);
95 
99  virtual std::string computeTemplateName(int iIndex);
100 
101 protected:
102  IUIDescription const *fUIDescription{};
103  IController *fUIController{};
104 
107 
108  std::vector<std::string> fTemplateNames;
109 
110  CView *fCurrentView{};
111  std::string fCurrentTemplateName{};
112 
113 public:
114  class Creator : public CustomViewCreator<SwitchViewContainer, CustomViewAdapter<CViewContainer>>
115  {
116  public:
117  explicit Creator(char const *iViewName = nullptr, char const *iDisplayName = nullptr) :
118  CustomViewCreator(iViewName, iDisplayName)
119  {
122  }
123  };
124 };
125 
130 template<>
132  const UIAttributes &iAttributes,
133  const IUIDescription *iDescription);
134 
135 }
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:66
This view offers dynamic switching between multiple views.
Definition: SwitchViewContainer.h:46
std::string fCurrentTemplateName
Definition: SwitchViewContainer.h:111
void viewContainerViewAdded(CViewContainer *container, CView *view) override
The only purpose of this callback (from IViewContainerListenerAdapter) is to catch the unavoidable ca...
Definition: SwitchViewContainer.cpp:112
IController * fUIController
Definition: SwitchViewContainer.h:103
GUIOptionalParam< int32 > fControlSwitch
Definition: SwitchViewContainer.h:106
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:95
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:102
~SwitchViewContainer() override
Definition: SwitchViewContainer.cpp:34
ParamID fSwitchControlTag
Definition: SwitchViewContainer.h:105
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:108
Creator(char const *iViewName=nullptr, char const *iDisplayName=nullptr)
Definition: SwitchViewContainer.h:117
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:137
void onParameterChange(ParamID iParamID) override
This is the callback that should be implemented to handle parameter changes.
Definition: SwitchViewContainer.cpp:85
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:67
CView * fCurrentView
Definition: SwitchViewContainer.h:110
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:124