ASPiK SDK
ctextlabel.h
1 // This file is part of VSTGUI. It is subject to the license terms
2 // in the LICENSE file found in the top-level directory of this
3 // distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
4 
5 #ifndef __ctextlabel__
6 #define __ctextlabel__
7 
8 #include "cparamdisplay.h"
9 #include "../cstring.h"
10 
11 namespace VSTGUI {
12 
13 //-----------------------------------------------------------------------------
14 // CLabel Declaration
17 //-----------------------------------------------------------------------------
18 class CTextLabel : public CParamDisplay
19 {
20 public:
21  CTextLabel (const CRect& size, UTF8StringPtr txt = nullptr, CBitmap* background = nullptr, const int32_t style = 0);
22  CTextLabel (const CTextLabel& textLabel);
23 
24  //-----------------------------------------------------------------------------
26  //-----------------------------------------------------------------------------
28  virtual void setText (const UTF8String& txt);
29  virtual const UTF8String& getText () const;
30 
35  };
36 
37  virtual void setTextTruncateMode (TextTruncateMode mode);
38  TextTruncateMode getTextTruncateMode () const { return textTruncateMode; }
39  const UTF8String& getTruncatedText () const { return truncatedText; }
40 
41 
42  static IdStringPtr kMsgTruncatedTextChanged;
43 
44  void draw (CDrawContext* pContext) override;
45  bool sizeToFit () override;
46  void setViewSize (const CRect& rect, bool invalid = true) override;
47  void drawStyleChanged () override;
48  void valueChanged () override;
49 
50  CLASS_METHODS(CTextLabel, CParamDisplay)
51 protected:
52  ~CTextLabel () noexcept override = default;
53  void freeText ();
54  void calculateTruncatedText ();
55 
56  bool onWheel (const CPoint& where, const float& distance, const CButtonState& buttons) override { return false; }
57  bool onWheel (const CPoint& where, const CMouseWheelAxis& axis, const float& distance, const CButtonState& buttons) override { return false; }
58 
59  TextTruncateMode textTruncateMode;
60  UTF8String text;
61  UTF8String truncatedText;
62 };
63 
64 //-----------------------------------------------------------------------------
69 {
70 public:
71  CMultiLineTextLabel (const CRect& size);
72  CMultiLineTextLabel (const CMultiLineTextLabel&) = default;
73 
74  enum class LineLayout {
75  clip,
76  truncate,
77  wrap
78  };
79  void setLineLayout (LineLayout layout);
80  LineLayout getLineLayout () const { return lineLayout; }
81 
85  void setAutoHeight (bool state);
87  bool getAutoHeight () const { return autoHeight; }
88 
90  CCoord getMaxLineWidth ();
91 
92  void drawRect (CDrawContext* pContext, const CRect& updateRect) override;
93  bool sizeToFit () override;
94  void setText (const UTF8String& txt) override;
95  void setViewSize (const CRect& rect, bool invalid = true) override;
96  void setTextTruncateMode (TextTruncateMode mode) override;
97  void setValue (float val) override;
98 private:
99  void drawStyleChanged () override;
100  void recalculateLines (CDrawContext* context);
101  void recalculateHeight ();
102 
103  bool autoHeight {false};
104  LineLayout lineLayout {LineLayout::clip};
105 
106  struct Line
107  {
108  CRect r;
109  UTF8String str;
110  };
111  using Lines = std::vector<Line>;
112  Lines lines;
113 };
114 
115 } // namespace
116 
117 #endif
no characters will be removed
Definition: ctextlabel.h:32
Rect structure.
Definition: crect.h:17
LineLayout
Definition: ctextlabel.h:74
a text label
Definition: ctextlabel.h:18
virtual void setTextTruncateMode(TextTruncateMode mode)
set text truncate mode
Definition: ctextlabel.cpp:55
void draw(CDrawContext *pContext) override
called if the view should draw itself
Definition: ctextlabel.cpp:91
characters will be removed from the beginning of the text
Definition: ctextlabel.h:33
virtual const UTF8String & getText() const
read only access to text
Definition: ctextlabel.cpp:85
A drawing context encapsulates the drawing context of the underlying OS.
Definition: cdrawcontext.h:29
Definition: ctextlabel.h:68
void valueChanged() override
notifies listener and dependent objects
Definition: ctextlabel.cpp:138
CCoord getMaxLineWidth()
Definition: ctextlabel.cpp:197
clip lines overflowing the view size width
Encapsulates various platform depended kinds of bitmaps.
Definition: cbitmap.h:21
Definition: customcontrols.cpp:8
bool onWheel(const CPoint &where, const CMouseWheelAxis &axis, const float &distance, const CButtonState &buttons) override
called if a mouse wheel event is happening over this view
Definition: ctextlabel.h:57
void setViewSize(const CRect &rect, bool invalid=true) override
set views size
Definition: ctextlabel.cpp:290
virtual void setText(const UTF8String &txt)
set text
Definition: ctextlabel.cpp:44
Button and Modifier state.
Definition: cbuttonstate.h:34
bool sizeToFit() override
resize view to optimal size
Definition: ctextlabel.cpp:256
bool sizeToFit() override
resize view to optimal size
Definition: ctextlabel.cpp:99
truncate lines overflowing the view size width
void setViewSize(const CRect &rect, bool invalid=true) override
set views size
Definition: ctextlabel.cpp:117
bool getAutoHeight() const
Definition: ctextlabel.h:87
void drawRect(CDrawContext *pContext, const CRect &updateRect) override
called if the view should draw itself
Definition: ctextlabel.cpp:211
void setText(const UTF8String &txt) override
set text
Definition: ctextlabel.cpp:262
const UTF8String & getTruncatedText() const
get the truncated text
Definition: ctextlabel.h:39
TextTruncateMode
Definition: ctextlabel.h:31
holds an UTF8 encoded string and a platform representation of it
Definition: cstring.h:56
bool onWheel(const CPoint &where, const float &distance, const CButtonState &buttons) override
called if a mouse wheel event is happening over this view
Definition: ctextlabel.h:56
virtual void invalid()
mark whole view as invalid
Definition: cview.h:63
TextTruncateMode getTextTruncateMode() const
get text truncate mode
Definition: ctextlabel.h:38
Point structure.
Definition: cpoint.h:17
characters will be removed from the end of the text
Definition: ctextlabel.h:34
CTextLabel(const CRect &size, UTF8StringPtr txt=nullptr, CBitmap *background=nullptr, const int32_t style=0)
Definition: ctextlabel.cpp:28
a parameter display
Definition: cparamdisplay.h:24
void setTextTruncateMode(TextTruncateMode mode) override
set text truncate mode
Definition: ctextlabel.cpp:171
wrap overflowing words to next line
static IdStringPtr kMsgTruncatedTextChanged
message which is send to dependent objects when the truncated text changes
Definition: ctextlabel.h:42
void setAutoHeight(bool state)
Definition: ctextlabel.cpp:187