#include "GUILabelControl.h"
#include "utils/CharsetConverter.h"
+#include "utils/StringUtils.h"
using namespace std;
m_startHighlight = m_endHighlight = 0;
m_startSelection = m_endSelection = 0;
m_minWidth = 0;
- if ((labelInfo.align & XBFONT_RIGHT) && m_width)
- m_posX -= m_width;
}
CGUILabelControl::~CGUILabelControl(void)
ch |= (3 << 16);
text.insert(text.begin() + m_iCursorPos, ch);
}
- changed |= m_label.SetMaxRect(m_posX, m_posY, GetWidth(), m_height);
+ changed |= m_label.SetMaxRect(m_posX, m_posY, GetMaxWidth(), m_height);
changed |= m_label.SetStyledText(text, colors);
}
else
if (m_bHasPath)
label = ShortenPath(label);
- changed |= m_label.SetMaxRect(m_posX, m_posY, GetWidth(), m_height);
+ changed |= m_label.SetMaxRect(m_posX, m_posY, GetMaxWidth(), m_height);
changed |= m_label.SetText(label);
}
if (changed)
void CGUILabelControl::SetLabel(const string &strLabel)
{
- m_infoLabel.SetLabel(strLabel, "", GetParentID());
- if (m_iCursorPos > (int)strLabel.size())
- m_iCursorPos = strLabel.size();
+ // NOTE: this optimization handles fixed labels only (i.e. not info labels).
+ // One way it might be extended to all labels would be for GUIInfoLabel ( or here )
+ // to store the label prior to parsing, and then compare that against what you're setting.
+ if (m_infoLabel.GetLabel(GetParentID(), false) != strLabel)
+ {
+ m_infoLabel.SetLabel(strLabel, "", GetParentID());
+ if (m_iCursorPos > (int)strLabel.size())
+ m_iCursorPos = strLabel.size();
- SetInvalid();
+ SetInvalid();
+ }
}
void CGUILabelControl::SetWidthControl(float minWidth, bool bScroll)
float CGUILabelControl::GetWidth() const
{
if (m_minWidth && m_minWidth != m_width)
- {
- float maxWidth = m_width ? m_width : m_label.GetTextWidth();
- return CLAMP(m_label.GetTextWidth(), m_minWidth, maxWidth);
- }
+ return CLAMP(m_label.GetTextWidth(), m_minWidth, GetMaxWidth());
return m_width;
}
CStdString CGUILabelControl::ShortenPath(const CStdString &path)
{
- if (m_width == 0 || path.IsEmpty())
+ if (m_width == 0 || path.empty())
return path;
char cDelim = '\0';
CStdString workPath(path);
// remove trailing slashes
if (workPath.size() > 3)
- if (workPath.Right(3).Compare("://") != 0 && workPath.Right(2).Compare(":\\") != 0)
+ if (!StringUtils::EndsWith(workPath, "://") &&
+ !StringUtils::EndsWith(workPath, ":\\"))
if (nPos == workPath.size() - 1)
{
workPath.erase(workPath.size() - 1);