kodi
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
83  {
84  OVER_FLOW_TRUNCATE = 0, // Truncated text from right (text end with ellipses)
85  OVER_FLOW_SCROLL,
86  OVER_FLOW_WRAP,
87  OVER_FLOW_CLIP,
88  OVER_FLOW_TRUNCATE_LEFT // Truncated text from left (text start with ellipses)
89  };
90 
91  CGUILabel(float posX, float posY, float width, float height, const CLabelInfo& labelInfo, OVER_FLOW overflow = OVER_FLOW_TRUNCATE);
92  CGUILabel(const CGUILabel& label);
93 
94  virtual ~CGUILabel() = default;
95 
99  bool Process(unsigned int currentTime);
100 
103  void Render();
104 
109  bool SetMaxRect(float x, float y, float w, float h);
110 
111  bool SetAlign(uint32_t align);
112 
118  bool SetText(const std::string &label);
119 
125  bool SetTextW(const std::wstring &label);
126 
133  bool SetStyledText(const vecText& text, const std::vector<UTILS::COLOR::Color>& colors);
134 
139  bool SetColor(COLOR color);
140 
146  void SetRenderRect(const CRect& rect) { m_renderRect = rect; }
147 
151  bool SetScrolling(bool scrolling);
152 
155  void SetScrollLoopCount(unsigned int loopCount) { m_maxScrollLoops = loopCount; }
156 
161  bool SetOverflow(OVER_FLOW overflow);
162 
165  void SetInvalid();
166 
169  bool UpdateColors();
170 
175  const CRect& GetRenderRect() const { return m_renderRect; }
176 
181  float GetTextWidth() const { return m_textLayout.GetTextWidth(); }
182 
188  float GetMaxWidth() const;
189 
195  float CalcTextWidth(const std::wstring& text) const { return m_textLayout.GetTextWidth(text); }
196 
197  const CLabelInfo& GetLabelInfo() const { return m_label; }
198  CLabelInfo& GetLabelInfo() { return m_label; }
199 
220  static bool CheckAndCorrectOverlap(CGUILabel &label1, CGUILabel &label2);
221 
222 protected:
223  UTILS::COLOR::Color GetColor() const;
224 
230  void UpdateRenderRect();
231 
232 private:
233  CLabelInfo m_label;
234  CGUITextLayout m_textLayout;
235 
236  bool m_scrolling;
237  OVER_FLOW m_overflowType;
238  CScrollInfo m_scrollInfo;
239  CRect m_renderRect;
240  CRect m_maxRect;
241  bool m_invalid = true;
242  COLOR m_color = COLOR_TEXT;
243  unsigned int m_maxScrollLoops = ~0U;
244 };
constexpr int XBFONT_LEFT
Align X left.
Definition: GUIFont.h:39
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:195
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:146
Definition: GUIFont.h:61
Definition: GUITextLayout.h:56
float GetTextWidth() const
Returns the precalculated full width of the current text, regardless of layout.
Definition: GUILabel.h:181
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:175
void SetScrollLoopCount(unsigned int loopCount)
Set max. text scroll count.
Definition: GUILabel.h:155
Definition: GUIFont.h:110
Definition: GUIInfoColor.h:30