diff options
Diffstat (limited to 'guilib')
-rw-r--r-- | guilib/GUIEditControl.cpp | 6 | ||||
-rw-r--r-- | guilib/GUILabel.cpp | 16 | ||||
-rw-r--r-- | guilib/GUILabel.h | 13 |
3 files changed, 20 insertions, 15 deletions
diff --git a/guilib/GUIEditControl.cpp b/guilib/GUIEditControl.cpp index 28bc65995f..ec41b5112e 100644 --- a/guilib/GUIEditControl.cpp +++ b/guilib/GUIEditControl.cpp @@ -320,7 +320,7 @@ void CGUIEditControl::RecalcLabelPosition() float beforeCursorWidth = m_label.CalcTextWidth(text.Left(m_cursorPos)); float afterCursorWidth = m_label.CalcTextWidth(text.Left(m_cursorPos) + L'|'); float leftTextWidth = m_label.GetRenderRect().Width(); - float maxTextWidth = m_label.GetMaxRect().Width(); + float maxTextWidth = m_label.GetMaxWidth(); if (leftTextWidth > 0) maxTextWidth -= leftTextWidth + spaceWidth; @@ -363,8 +363,8 @@ void CGUIEditControl::RenderText() } - float posX = m_label.GetMaxRect().x1; - float maxTextWidth = m_label.GetMaxRect().Width(); + float posX = m_label.GetRenderRect().x1; + float maxTextWidth = m_label.GetMaxWidth(); // start by rendering the normal text float leftTextWidth = m_label.GetRenderRect().Width(); diff --git a/guilib/GUILabel.cpp b/guilib/GUILabel.cpp index d477e1e1fb..ef23282a76 100644 --- a/guilib/GUILabel.cpp +++ b/guilib/GUILabel.cpp @@ -109,7 +109,7 @@ void CGUILabel::UpdateColors() void CGUILabel::SetMaxRect(float x, float y, float w, float h) { - m_maxRect.SetRect(x + m_label.offsetX, y + m_label.offsetY, x + w - m_label.offsetX, y + h - m_label.offsetY); + m_maxRect.SetRect(x, y, x + w, y + h); UpdateRenderRect(); } @@ -142,17 +142,23 @@ void CGUILabel::UpdateRenderRect() // recalculate our text layout float width, height; m_textLayout.GetTextExtent(width, height); - width = std::min(width, m_maxRect.Width()); + width = std::min(width, GetMaxWidth()); if (m_label.align & XBFONT_CENTER_Y) m_renderRect.y1 = m_maxRect.y1 + (m_maxRect.Height() - height) * 0.5f; else - m_renderRect.y1 = m_maxRect.y1; + m_renderRect.y1 = m_maxRect.y1 + m_label.offsetY; if (m_label.align & XBFONT_RIGHT) - m_renderRect.x1 = m_maxRect.x2 - width; + m_renderRect.x1 = m_maxRect.x2 - width - m_label.offsetX; else if (m_label.align & XBFONT_CENTER_X) m_renderRect.x1 = m_maxRect.x1 + (m_maxRect.Width() - width) * 0.5f; else - m_renderRect.x1 = m_maxRect.x1; + m_renderRect.x1 = m_maxRect.x1 + m_label.offsetX; m_renderRect.x2 = m_renderRect.x1 + width; m_renderRect.y2 = m_renderRect.y1 + height; } + +float CGUILabel::GetMaxWidth() const +{ + if (m_label.width) return m_label.width; + return m_maxRect.Width() - 2*m_label.offsetX; +} diff --git a/guilib/GUILabel.h b/guilib/GUILabel.h index 78d8a00789..17ea9f8b26 100644 --- a/guilib/GUILabel.h +++ b/guilib/GUILabel.h @@ -92,9 +92,8 @@ public: void Render(); /*! \brief Set the maximal extent of the label - Sets the maximal size and positioning that the label may render in. Note that any offsets will be computed and applied immediately - so that subsequent calls to GetMaxRect() may not return the same values. - \sa GetMaxRect + 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. */ void SetMaxRect(float x, float y, float w, float h); @@ -153,12 +152,12 @@ public: */ float GetTextWidth() const { return m_textLayout.GetTextWidth(); }; - /*! \brief Returns the maximal text rect that this label can render into - \return CRect containing the maximal rectangle that this label can render into. May differ from - the sizing given in SetMaxRect as offsets have been applied. + /*! \brief Returns the maximal width that this label can render into + \return 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. \sa SetMaxRect */ - const CRect &GetMaxRect() const { return m_maxRect; }; + float GetMaxWidth() const; /*! \brief Calculates the width of some text \param text CStdStringW of text whose width we want |