Merge pull request #4689 from jmarshallnz/label_auto_width_fix
[vuplus_xbmc] / xbmc / guilib / GUILabelControl.cpp
index e896858..19b14ca 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "GUILabelControl.h"
 #include "utils/CharsetConverter.h"
+#include "utils/StringUtils.h"
 
 using namespace std;
 
@@ -160,7 +161,7 @@ void CGUILabelControl::UpdateInfo(const CGUIListItem *item)
         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
@@ -168,7 +169,7 @@ void CGUILabelControl::UpdateInfo(const CGUIListItem *item)
     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)
@@ -243,10 +244,7 @@ void CGUILabelControl::SetAlignment(uint32_t align)
 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;
 }
 
@@ -273,7 +271,7 @@ bool CGUILabelControl::OnMessage(CGUIMessage& message)
 
 CStdString CGUILabelControl::ShortenPath(const CStdString &path)
 {
-  if (m_width == 0 || path.IsEmpty())
+  if (m_width == 0 || path.empty())
     return path;
 
   char cDelim = '\0';
@@ -294,7 +292,8 @@ CStdString CGUILabelControl::ShortenPath(const CStdString &path)
   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);