Kodi Documentation 22.0
Kodi is an open source media player and entertainment hub.
Loading...
Searching...
No Matches
CGUILabel Class Reference

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 CRectGetRenderRect () 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 CLabelInfoGetLabelInfo () const
 
CLabelInfoGetLabelInfo ()
 

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.
 

Detailed Description

Class for rendering text labels. Handles alignment and rendering of text within a control.

,

Member Enumeration Documentation

◆ COLOR

allowed color categories for labels, as defined by the skin

Enumerator
COLOR_TEXT 
COLOR_SELECTED 
COLOR_FOCUSED 
COLOR_DISABLED 
COLOR_INVALID 

◆ OVER_FLOW

allowed overflow handling techniques for labels, as defined by the skin

Enumerator
OVER_FLOW_TRUNCATE 
OVER_FLOW_SCROLL 
OVER_FLOW_WRAP 
OVER_FLOW_CLIP 
OVER_FLOW_TRUNCATE_LEFT 

Constructor & Destructor Documentation

◆ CGUILabel() [1/2]

CGUILabel::CGUILabel ( float posX,
float posY,
float width,
float height,
const CLabelInfo & labelInfo,
CGUILabel::OVER_FLOW overflow = OVER_FLOW_TRUNCATE )

◆ CGUILabel() [2/2]

CGUILabel::CGUILabel ( const CGUILabel & label)

◆ ~CGUILabel()

virtual CGUILabel::~CGUILabel ( )
virtualdefault

Member Function Documentation

◆ CalcTextWidth()

float CGUILabel::CalcTextWidth ( const std::wstring & text) const
inline

Calculates the width of some text.

Parameters
textstd::wstring of text whose width we want
Returns
width of the given text
See also
GetTextWidth

◆ CheckAndCorrectOverlap()

bool CGUILabel::CheckAndCorrectOverlap ( CGUILabel & label1,
CGUILabel & label2 )
static

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.

Parameters
label1First label to check
label2Second label to check

◆ GetColor()

KODI::UTILS::COLOR::Color CGUILabel::GetColor ( ) const
protected

◆ GetLabelInfo() [1/2]

CLabelInfo & CGUILabel::GetLabelInfo ( )
inline

◆ GetLabelInfo() [2/2]

const CLabelInfo & CGUILabel::GetLabelInfo ( ) const
inline

◆ GetMaxWidth()

float CGUILabel::GetMaxWidth ( ) const

Returns the maximal width that this label can render into.

Returns
Maximal width that this label can render into. Note that this may differ from the amount given in SetMaxRect as offsets and text width overrides have been taken into account.
See also
SetMaxRect

◆ GetRenderRect()

const CRect & CGUILabel::GetRenderRect ( ) const
inline

Returns the precalculated final layout of the current text.

Returns
CRect containing the extents of the current text
See also
SetRenderRect, UpdateRenderRect

◆ GetTextWidth()

float CGUILabel::GetTextWidth ( ) const
inline

Returns the precalculated full width of the current text, regardless of layout.

Returns
full width of the current text
See also
CalcTextWidth

◆ Process()

bool CGUILabel::Process ( unsigned int currentTime)

Process the label.

Returns
bool stating if process caused control to change
Todo
Add the correct processing

◆ Render()

void CGUILabel::Render ( )

Render the label on screen.

◆ SetAlign()

bool CGUILabel::SetAlign ( uint32_t align)

◆ SetColor()

bool CGUILabel::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.

Parameters
colorcolor to be used for the label

◆ SetInvalid()

void CGUILabel::SetInvalid ( )

Set this label invalid. Forces an update of the control.

◆ SetMaxRect()

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.

◆ SetOverflow()

bool CGUILabel::SetOverflow ( OVER_FLOW overflow)

Set how this label should handle overflowing text.

Parameters
overflowthe overflow type
See also
OVER_FLOW

◆ SetRenderRect()

void CGUILabel::SetRenderRect ( const CRect & rect)
inline

Set the final layout of the current text Overrides the calculated layout of the current text, forcing a particular size and position.

Parameters
rectCRect containing the extents of the current text
See also
GetRenderRect, UpdateRenderRect

◆ SetScrolling()

bool CGUILabel::SetScrolling ( bool scrolling)

Set whether or not this label control should scroll.

Parameters
scrollingtrue if this label should scroll.

◆ SetScrollLoopCount()

void CGUILabel::SetScrollLoopCount ( unsigned int loopCount)
inline

Set max. text scroll count.

◆ SetStyledText()

bool CGUILabel::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.

Parameters
textstyled text to set.
colorscolors referenced in the styled text.
See also
SetText, SetTextW

◆ SetText()

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.

Parameters
textstd::string to set as this labels text
See also
SetTextW, SetStyledText

◆ SetTextW()

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.

Parameters
textstd::wstring to set as this labels text
See also
SetText, SetStyledText

◆ UpdateColors()

bool CGUILabel::UpdateColors ( )

Update this labels colors.

◆ UpdateRenderRect()

void CGUILabel::UpdateRenderRect ( )
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.

See also
GetRenderRect, SetRenderRect

The documentation for this class was generated from the following files: