[Test] Added tests for CUtil::SplitParams
[xbmc.git] / xbmc / guilib / GUIListLabel.cpp
blobb3138eb7aaacb318ecab8dff89ee4fde7ca11268
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "GUIListLabel.h"
11 #include "addons/Skin.h"
13 #include <limits>
15 using namespace KODI::GUILIB;
17 CGUIListLabel::CGUIListLabel(int parentID, int controlID, float posX, float posY, float width, float height,
18 const CLabelInfo& labelInfo, const GUIINFO::CGUIInfoLabel &info, CGUIControl::GUISCROLLVALUE scroll)
19 : CGUIControl(parentID, controlID, posX, posY, width, height)
20 , m_label(posX, posY, width, height, labelInfo, (scroll == CGUIControl::ALWAYS) ? CGUILabel::OVER_FLOW_SCROLL : CGUILabel::OVER_FLOW_TRUNCATE)
21 , m_info(info)
23 m_scroll = scroll;
24 if (m_info.IsConstant())
25 SetLabel(m_info.GetLabel(m_parentID, true));
26 m_label.SetScrollLoopCount(2);
27 ControlType = GUICONTROL_LISTLABEL;
30 CGUIListLabel::~CGUIListLabel(void) = default;
32 void CGUIListLabel::SetSelected(bool selected)
34 if(m_label.SetColor(selected ? CGUILabel::COLOR_SELECTED : CGUILabel::COLOR_TEXT))
35 SetInvalid();
38 void CGUIListLabel::SetFocus(bool focus)
40 CGUIControl::SetFocus(focus);
41 if (m_scroll == CGUIControl::FOCUS)
43 m_label.SetScrolling(focus);
47 CRect CGUIListLabel::CalcRenderRegion() const
49 return m_label.GetRenderRect();
52 bool CGUIListLabel::UpdateColors(const CGUIListItem* item)
54 bool changed = CGUIControl::UpdateColors(nullptr);
55 changed |= m_label.UpdateColors();
57 return changed;
60 void CGUIListLabel::Process(unsigned int currentTime, CDirtyRegionList &dirtyregions)
62 if (m_label.Process(currentTime))
63 MarkDirtyRegion();
65 CGUIControl::Process(currentTime, dirtyregions);
68 void CGUIListLabel::Render()
70 m_label.Render();
71 CGUIControl::Render();
74 void CGUIListLabel::UpdateInfo(const CGUIListItem *item)
76 if (m_info.IsConstant() && !m_bInvalidated)
77 return; // nothing to do
79 if (item)
80 SetLabel(m_info.GetItemLabel(item));
81 else
82 SetLabel(m_info.GetLabel(m_parentID, true));
85 void CGUIListLabel::SetInvalid()
87 m_label.SetInvalid();
88 CGUIControl::SetInvalid();
91 void CGUIListLabel::SetWidth(float width)
93 m_width = width;
94 if (m_label.GetLabelInfo().align & XBFONT_RIGHT)
95 m_label.SetMaxRect(m_posX - m_width, m_posY, m_width, m_height);
96 else if (m_label.GetLabelInfo().align & XBFONT_CENTER_X)
97 m_label.SetMaxRect(m_posX - m_width*0.5f, m_posY, m_width, m_height);
98 else
99 m_label.SetMaxRect(m_posX, m_posY, m_width, m_height);
100 CGUIControl::SetWidth(m_width);
103 void CGUIListLabel::SetLabel(const std::string &label)
105 m_label.SetText(label);