Merge pull request #4689 from jmarshallnz/label_auto_width_fix
authorjmarshallnz <jcmarsha@gmail.com>
Mon, 12 May 2014 09:48:41 +0000 (21:48 +1200)
committerTrent Nelson <trent.nelson@pivosgroup.com>
Sat, 7 Jun 2014 05:27:34 +0000 (13:27 +0800)
[gui] fix auto-width labels not wrapping properly with <wrapmultiline>

xbmc/guilib/GUILabelControl.cpp
xbmc/guilib/GUILabelControl.h

index 2b79838..19b14ca 100644 (file)
@@ -161,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
@@ -169,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)
@@ -244,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;
 }
 
index 09bfe56..b8eddec 100644 (file)
@@ -68,6 +68,11 @@ protected:
   bool UpdateColors();
   CStdString ShortenPath(const CStdString &path);
 
+  /*! \brief Return the maximum width of this label control.
+   \return Return the width of the control if available, else the width of the current text.
+   */
+  float GetMaxWidth() const { return m_width ? m_width : m_label.GetTextWidth(); }
+
   CGUILabel m_label;
 
   bool m_bHasPath;