xbmc
GUILabel.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
16 #include "GUIFont.h"
17 #include "GUITextLayout.h"
18 #include "guiinfo/GUIInfoColor.h"
19 #include "utils/ColorUtils.h"
20 #include "utils/Geometry.h"
21 
23 {
24 public:
25  CLabelInfo():
26  scrollSuffix(" | ")
27  {
28  font = NULL;
29  align = XBFONT_LEFT;
30  offsetX = offsetY = 0;
31  width = 0;
32  angle = 0;
33  scrollSpeed = CScrollInfo::defaultSpeed;
34  };
35  bool UpdateColors()
36  {
37  bool changed = false;
38 
39  changed |= textColor.Update();
40  changed |= shadowColor.Update();
41  changed |= selectedColor.Update();
42  changed |= disabledColor.Update();
43  changed |= focusedColor.Update();
44  changed |= invalidColor.Update();
45 
46  return changed;
47  };
48 
55  uint32_t align;
56  float offsetX;
57  float offsetY;
58  float width;
59  float angle;
60  CGUIFont *font;
61  int scrollSpeed;
62  std::string scrollSuffix;
63 };
64 
69 class CGUILabel
70 {
71 public:
74  enum COLOR { COLOR_TEXT = 0,
75  COLOR_SELECTED,
76  COLOR_FOCUSED,
77  COLOR_DISABLED,
78  COLOR_INVALID };
79 
82  enum OVER_FLOW { OVER_FLOW_TRUNCATE = 0,
83  OVER_FLOW_SCROLL,
84  OVER_FLOW_WRAP,
85  OVER_FLOW_CLIP };
86 
87  CGUILabel(float posX, float posY, float width, float height, const CLabelInfo& labelInfo, OVER_FLOW overflow = OVER_FLOW_TRUNCATE);
88  CGUILabel(const CGUILabel& label);
89 
90  virtual ~CGUILabel() = default;
91 
95  bool Process(unsigned int currentTime);
96 
99  void Render();
100 
105  bool SetMaxRect(float x, float y, float w, float h);
106 
107  bool SetAlign(uint32_t align);
108 
114  bool SetText(const std::string &label);
115 
121  bool SetTextW(const std::wstring &label);
122 
129  bool SetStyledText(const vecText& text, const std::vector<UTILS::COLOR::Color>& colors);
130 
135  bool SetColor(COLOR color);
136 
142  void SetRenderRect(const CRect& rect) { m_renderRect = rect; }
143 
147  bool SetScrolling(bool scrolling);
148 
151  void SetScrollLoopCount(unsigned int loopCount) { m_maxScrollLoops = loopCount; }
152 
157  bool SetOverflow(OVER_FLOW overflow);
158 
161  void SetInvalid();
162 
165  bool UpdateColors();
166 
171  const CRect& GetRenderRect() const { return m_renderRect; }
172 
177  float GetTextWidth() const { return m_textLayout.GetTextWidth(); }
178 
184  float GetMaxWidth() const;
185 
191  float CalcTextWidth(const std::wstring& text) const { return m_textLayout.GetTextWidth(text); }
192 
193  const CLabelInfo& GetLabelInfo() const { return m_label; }
194  CLabelInfo& GetLabelInfo() { return m_label; }
195 
216  static bool CheckAndCorrectOverlap(CGUILabel &label1, CGUILabel &label2);
217 
218 protected:
219  UTILS::COLOR::Color GetColor() const;
220 
226  void UpdateRenderRect();
227 
228 private:
229  CLabelInfo m_label;
230  CGUITextLayout m_textLayout;
231 
232  bool m_scrolling;
233  OVER_FLOW m_overflowType;
234  CScrollInfo m_scrollInfo;
235  CRect m_renderRect;
236  CRect m_maxRect;
237  bool m_invalid;
238  COLOR m_color;
239  unsigned int m_maxScrollLoops = ~0U;
240 };
constexpr int XBFONT_LEFT
Align X left.
Definition: GUIFont.h:38
Class for rendering text labels. Handles alignment and rendering of text within a control...
Definition: GUILabel.h:69
Definition: Texture.h:21
float CalcTextWidth(const std::wstring &text) const
Calculates the width of some text.
Definition: GUILabel.h:191
OVER_FLOW
allowed overflow handling techniques for labels, as defined by the skin
Definition: GUILabel.h:82
void SetRenderRect(const CRect &rect)
Set the final layout of the current text Overrides the calculated layout of the current text...
Definition: GUILabel.h:142
Definition: GUIFont.h:58
Definition: GUITextLayout.h:52
float GetTextWidth() const
Returns the precalculated full width of the current text, regardless of layout.
Definition: GUILabel.h:177
Definition: GUILabel.h:22
#define U(j)
uj for division
Definition: bigint.c:73
const CRect & GetRenderRect() const
Returns the precalculated final layout of the current text.
Definition: GUILabel.h:171
void SetScrollLoopCount(unsigned int loopCount)
Set max. text scroll count.
Definition: GUILabel.h:151
Definition: GUIFont.h:107
Definition: GUIInfoColor.h:30