![]() |
Kodi Documentation 22.0
Kodi is an open source media player and entertainment hub.
|
Class for rendering text labels. Handles alignment and rendering of text within a control. More...
#include <GUILabel.h>
Public Types | |
enum | COLOR { COLOR_TEXT = 0 , COLOR_SELECTED , COLOR_FOCUSED , COLOR_DISABLED , COLOR_INVALID } |
allowed color categories for labels, as defined by the skin More... | |
enum | OVER_FLOW { OVER_FLOW_TRUNCATE = 0 , OVER_FLOW_SCROLL , OVER_FLOW_WRAP , OVER_FLOW_CLIP , OVER_FLOW_TRUNCATE_LEFT } |
allowed overflow handling techniques for labels, as defined by the skin More... | |
Public Member Functions | |
CGUILabel (float posX, float posY, float width, float height, const CLabelInfo &labelInfo, OVER_FLOW overflow=OVER_FLOW_TRUNCATE) | |
CGUILabel (const CGUILabel &label) | |
virtual | ~CGUILabel ()=default |
bool | Process (unsigned int currentTime) |
Process the label. | |
void | Render () |
Render the label on screen. | |
bool | SetMaxRect (float x, float y, float w, float h) |
Set the maximal extent of the label Sets the maximal size and positioning that the label may render in. Note that textwidth> can override this, and <textoffsetx> and <textoffsety> may also allow the label to be moved outside this rectangle. | |
bool | SetAlign (uint32_t align) |
bool | SetText (const std::string &label) |
Set the text to be displayed in the label Updates the label control and recomputes final position and size. | |
bool | SetTextW (const std::wstring &label) |
Set the text to be displayed in the label Updates the label control and recomputes final position and size. | |
bool | SetStyledText (const vecText &text, const std::vector< KODI::UTILS::COLOR::Color > &colors) |
Set styled text to be displayed in the label Updates the label control and recomputes final position and size. | |
bool | SetColor (COLOR color) |
Set the color to use for the label Sets the color to be used for this label. Takes effect at the next render. | |
void | SetRenderRect (const CRect &rect) |
Set the final layout of the current text Overrides the calculated layout of the current text, forcing a particular size and position. | |
bool | SetScrolling (bool scrolling) |
Set whether or not this label control should scroll. | |
void | SetScrollLoopCount (unsigned int loopCount) |
Set max. text scroll count. | |
bool | SetOverflow (OVER_FLOW overflow) |
Set how this label should handle overflowing text. | |
void | SetInvalid () |
Set this label invalid. Forces an update of the control. | |
bool | UpdateColors () |
Update this labels colors. | |
const CRect & | GetRenderRect () const |
Returns the precalculated final layout of the current text. | |
float | GetTextWidth () const |
Returns the precalculated full width of the current text, regardless of layout. | |
float | GetMaxWidth () const |
Returns the maximal width that this label can render into. | |
float | CalcTextWidth (const std::wstring &text) const |
Calculates the width of some text. | |
const CLabelInfo & | GetLabelInfo () const |
CLabelInfo & | GetLabelInfo () |
Static Public Member Functions | |
static bool | CheckAndCorrectOverlap (CGUILabel &label1, CGUILabel &label2) |
Check a left aligned and right aligned label for overlap and cut the labels off so that no overlap occurs. | |
Protected Member Functions | |
KODI::UTILS::COLOR::Color | GetColor () const |
void | UpdateRenderRect () |
Computes the final layout of the text Uses the maximal position and width of the text, as well as the text length and alignment to compute the final render rect of the text. | |
Class for rendering text labels. Handles alignment and rendering of text within a control.
,
enum CGUILabel::COLOR |
enum CGUILabel::OVER_FLOW |
CGUILabel::CGUILabel | ( | float | posX, |
float | posY, | ||
float | width, | ||
float | height, | ||
const CLabelInfo & | labelInfo, | ||
CGUILabel::OVER_FLOW | overflow = OVER_FLOW_TRUNCATE ) |
CGUILabel::CGUILabel | ( | const CGUILabel & | label | ) |
|
virtualdefault |
|
inline |
Calculates the width of some text.
text | std::wstring of text whose width we want |
Check a left aligned and right aligned label for overlap and cut the labels off so that no overlap occurs.
If a left-aligned label occupies some of the same space on screen as a right-aligned label, then we may be able to correct for this by restricting the width of one or both of them. This routine checks two labels to see whether they satisfy this assumption and, if so, adjusts the render rect of both labels so that they no longer do so. The order of the two labels is not important, but we do assume that the left-aligned label is also the left-most on screen, and that the right-aligned label is the right most on-screen, so that they overlap due to the fact that one or both of the labels are longer than anticipated. In the following diagram, [R...[R R] refers to the maximal allowed and actual space occupied by the right label. Similarly, [L L]...L] refers to the maximal and actual space occupied by the left label. | refers to the central cutting point, i.e. the point that would divide the maximal allowed overlap perfectly in two. There are 3 scenarios to consider:
cut [L [R...[R L].|..........L] R] left label ends to the left of the cut -> just crop the left label. [L [R.....[R | L]..L] R] both left and right labels occupy more than the cut allows, so crop both. [L [R..........|.[R L]..L] R] right label ends to the right of the cut -> just crop the right label.
label1 | First label to check |
label2 | Second label to check |
|
protected |
|
inline |
|
inline |
float CGUILabel::GetMaxWidth | ( | ) | const |
Returns the maximal width that this label can render into.
|
inline |
Returns the precalculated final layout of the current text.
|
inline |
Returns the precalculated full width of the current text, regardless of layout.
Process the label.
void CGUILabel::Render | ( | ) |
Render the label on screen.
bool CGUILabel::SetAlign | ( | uint32_t | align | ) |
Set the color to use for the label Sets the color to be used for this label. Takes effect at the next render.
color | color to be used for the label |
void CGUILabel::SetInvalid | ( | ) |
Set this label invalid. Forces an update of the control.
bool CGUILabel::SetMaxRect | ( | float | x, |
float | y, | ||
float | w, | ||
float | h ) |
Set the maximal extent of the label Sets the maximal size and positioning that the label may render in. Note that textwidth>
can override this, and <textoffsetx>
and <textoffsety>
may also allow the label to be moved outside this rectangle.
Set how this label should handle overflowing text.
overflow | the overflow type |
Set the final layout of the current text Overrides the calculated layout of the current text, forcing a particular size and position.
rect | CRect containing the extents of the current text |
Set whether or not this label control should scroll.
scrolling | true if this label should scroll. |
bool CGUILabel::SetStyledText | ( | const vecText & | text, |
const std::vector< KODI::UTILS::COLOR::Color > & | colors ) |
bool CGUILabel::SetText | ( | const std::string & | label | ) |
Set the text to be displayed in the label Updates the label control and recomputes final position and size.
text | std::string to set as this labels text |
bool CGUILabel::SetTextW | ( | const std::wstring & | label | ) |
Set the text to be displayed in the label Updates the label control and recomputes final position and size.
text | std::wstring to set as this labels text |
bool CGUILabel::UpdateColors | ( | ) |
Update this labels colors.
|
protected |
Computes the final layout of the text Uses the maximal position and width of the text, as well as the text length and alignment to compute the final render rect of the text.