Jamba C++ API  6.0.0
TextEditView.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-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 
20 #include <vstgui4/vstgui/lib/controls/ctextedit.h>
21 #include <vstgui4/vstgui/lib/controls/icontrollistener.h>
23 
25 
26 using namespace VSTGUI;
27 using namespace Params;
28 
31 class TextEdit : public CTextEdit
32 {
33 public:
34  explicit TextEdit(const CRect &iSize) : CTextEdit(iSize, nullptr, UNDEFINED_PARAM_ID) {};
35 };
36 
46 class TextEditView : public CustomViewAdapter<TextEdit>
47 {
48 public:
49  // Constructor
50  explicit TextEditView(const CRect &iSize) : CustomViewAdapter(iSize), fOnChangeListener{new CLabelListener(fText)}
51  {
52  registerControlListener(fOnChangeListener.get());
53  }
54 
55  // registerParameters
56  void registerParameters() override;
57 
58  // setListener
59  void setListener(IControlListener *l) override;
60 
61 protected:
62  // the underlying jmb parameter of type UTF8String
64 
65 private:
67  struct CLabelListener : public IControlListener {
68  CLabelListener(GUIJmbParam<UTF8String> &iText) : fText{iText} {}
69  void valueChanged(CControl *pControl) override;
71  };
72 
73  std::unique_ptr<CLabelListener> fOnChangeListener;
74 
75 
76 public:
77  class Creator : public CustomViewCreator<TextEditView, CustomViewAdapter<TextEdit>>
78  {
79  public:
80  explicit Creator(char const *iViewName = nullptr, char const *iDisplayName = nullptr) :
81  CustomViewCreator(iViewName, iDisplayName, VSTGUI::UIViewCreator::kCTextEdit)
82  {
83  }
84  };
85 };
86 
87 }
88 
Inherit from this class to provide the factory for a custom view.
Definition: CustomViewCreator.h:1314
std::unique_ptr< CLabelListener > fOnChangeListener
Definition: TextEditView.h:73
Creator(char const *iViewName=nullptr, char const *iDisplayName=nullptr)
Definition: TextEditView.h:80
This class can be used to extend VSTGUI classes directly while still benefiting from the extensions a...
Definition: CustomView.h:335
Definition: Types.h:29
Definition: CustomController.h:24
GUIJmbParam< UTF8String > & fText
Definition: TextEditView.h:70
TextEdit(const CRect &iSize)
Definition: TextEditView.h:34
The purpose of this class is to adapt the constructor signature to a single element,...
Definition: TextEditView.h:31
TextEditView(const CRect &iSize)
Definition: TextEditView.h:50
CLabelListener(GUIJmbParam< UTF8String > &iText)
Definition: TextEditView.h:68
Control listener to handle changes to the CTextLabel and propagates to fText
Definition: TextEditView.h:67
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
Extends the CTextEdit view to tie it to a GUIJmbParam<UTF8String>.
Definition: TextEditView.h:46