diff options
author | Miguel Borges de Freitas <enen92@users.noreply.github.com> | 2022-04-10 11:54:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-10 11:54:23 +0100 |
commit | 9a94d96d693897080aebf9d03a215b840185350d (patch) | |
tree | c28e38f077130c94dc24b9fe216d2088cca09ef3 | |
parent | f311298afb5910d3b0e4b9901c08156f2118c347 (diff) | |
parent | 4648c628e7fd75ead994e6f13914a3ea28ab5cac (diff) |
Merge pull request #21236 from CastagnaIT/spincontrol
[GUI][SpinControlEx] Limit max width for long text cases
-rw-r--r-- | xbmc/guilib/GUISpinControl.cpp | 59 | ||||
-rw-r--r-- | xbmc/guilib/GUISpinControlEx.cpp | 27 |
2 files changed, 54 insertions, 32 deletions
diff --git a/xbmc/guilib/GUISpinControl.cpp b/xbmc/guilib/GUISpinControl.cpp index 6b36fdf09e..f0a0f3980b 100644 --- a/xbmc/guilib/GUISpinControl.cpp +++ b/xbmc/guilib/GUISpinControl.cpp @@ -17,6 +17,12 @@ #define SPIN_BUTTON_DOWN 1 #define SPIN_BUTTON_UP 2 +namespace +{ +// Additional space between text and spin buttons +constexpr float TEXT_SPACE = 5.0f; +} // unnamed namespace + CGUISpinControl::CGUISpinControl(int parentID, int controlID, float posX, @@ -474,16 +480,15 @@ void CGUISpinControl::Process(unsigned int currentTime, CDirtyRegionList &dirtyr bool arrowsOnRight(0 != (m_label.GetLabelInfo().align & (XBFONT_RIGHT | XBFONT_CENTER_X))); if (!arrowsOnRight) { - const float space = 5; - changed |= m_imgspinDownFocus->SetPosition(m_posX + textWidth + space, m_posY); - changed |= m_imgspinDown->SetPosition(m_posX + textWidth + space, m_posY); - changed |= m_imgspinDownDisabled->SetPosition(m_posX + textWidth + space, m_posY); - changed |= m_imgspinUpFocus->SetPosition(m_posX + textWidth + space + m_imgspinDown->GetWidth(), - m_posY); - changed |= - m_imgspinUp->SetPosition(m_posX + textWidth + space + m_imgspinDown->GetWidth(), m_posY); + changed |= m_imgspinDownFocus->SetPosition(m_posX + textWidth + TEXT_SPACE, m_posY); + changed |= m_imgspinDown->SetPosition(m_posX + textWidth + TEXT_SPACE, m_posY); + changed |= m_imgspinDownDisabled->SetPosition(m_posX + textWidth + TEXT_SPACE, m_posY); + changed |= m_imgspinUpFocus->SetPosition( + m_posX + textWidth + TEXT_SPACE + m_imgspinDown->GetWidth(), m_posY); + changed |= m_imgspinUp->SetPosition(m_posX + textWidth + TEXT_SPACE + m_imgspinDown->GetWidth(), + m_posY); changed |= m_imgspinUpDisabled->SetPosition( - m_posX + textWidth + space + m_imgspinDownDisabled->GetWidth(), m_posY); + m_posX + textWidth + TEXT_SPACE + m_imgspinDownDisabled->GetWidth(), m_posY); } changed |= m_imgspinDownFocus->Process(currentTime); @@ -502,7 +507,23 @@ void CGUISpinControl::Process(unsigned int currentTime, CDirtyRegionList &dirtyr void CGUISpinControl::Render() { - if ( HasFocus() ) + if (m_label.GetLabelInfo().font) + { + float textWidth = m_label.GetTextWidth() + 2 * m_label.GetLabelInfo().offsetX; + // Position the arrows + bool arrowsOnRight(0 != (m_label.GetLabelInfo().align & (XBFONT_RIGHT | XBFONT_CENTER_X))); + + if (arrowsOnRight) + RenderText(m_posX - TEXT_SPACE - textWidth, m_posY, textWidth, m_height); + else + RenderText(m_posX + m_imgspinDown->GetWidth() + m_imgspinUp->GetWidth() + TEXT_SPACE, m_posY, + textWidth, m_height); + + // set our hit rectangle for MouseOver events + m_hitRect = m_label.GetRenderRect(); + } + + if (HasFocus()) { if (m_iSelect == SPIN_BUTTON_UP) m_imgspinUpFocus->Render(); @@ -514,7 +535,7 @@ void CGUISpinControl::Render() else m_imgspinDown->Render(); } - else if ( !HasFocus() && !IsDisabled() ) + else if (!HasFocus() && !IsDisabled()) { m_imgspinUp->Render(); m_imgspinDown->Render(); @@ -525,22 +546,6 @@ void CGUISpinControl::Render() m_imgspinDownDisabled->Render(); } - if (m_label.GetLabelInfo().font) - { - const float space = 5; - float textWidth = m_label.GetTextWidth() + 2 * m_label.GetLabelInfo().offsetX; - // Position the arrows - bool arrowsOnRight(0 != (m_label.GetLabelInfo().align & (XBFONT_RIGHT | XBFONT_CENTER_X))); - - if (arrowsOnRight) - RenderText(m_posX - space - textWidth, m_posY, textWidth, m_height); - else - RenderText(m_posX + m_imgspinDown->GetWidth() + m_imgspinUp->GetWidth() + space, m_posY, - textWidth, m_height); - - // set our hit rectangle for MouseOver events - m_hitRect = m_label.GetRenderRect(); - } CGUIControl::Render(); } diff --git a/xbmc/guilib/GUISpinControlEx.cpp b/xbmc/guilib/GUISpinControlEx.cpp index 2ed30b4d40..709c2af29e 100644 --- a/xbmc/guilib/GUISpinControlEx.cpp +++ b/xbmc/guilib/GUISpinControlEx.cpp @@ -67,7 +67,6 @@ void CGUISpinControlEx::Process(unsigned int currentTime, CDirtyRegionList &dirt void CGUISpinControlEx::Render() { - m_buttonControl.Render(); CGUISpinControl::Render(); } @@ -136,9 +135,27 @@ void CGUISpinControlEx::SetSpinPosition(float spinPosX) void CGUISpinControlEx::RenderText(float posX, float posY, float width, float height) { - const float spaceWidth = 10; - // check our limits from the button control - float x = std::max(m_buttonControl.m_label.GetRenderRect().x2 + spaceWidth, posX); + const float freeSpaceWidth{m_buttonControl.GetWidth() - GetSpinWidth() * 2}; + + // Limit right label text width to max 50% of free space + // (will be slightly shifted due to offsetX padding) + const float rightTextMaxWidth{freeSpaceWidth * 0.5f}; + + float rightTextWidth{width}; + if (rightTextWidth > rightTextMaxWidth) + { + rightTextWidth = rightTextMaxWidth - m_label.GetLabelInfo().offsetX; + } + m_label.SetScrolling(HasFocus()); - CGUISpinControl::RenderText(x, m_buttonControl.GetYPosition(), width + posX - x, m_buttonControl.GetHeight()); + // Replace posX by using our button position + posX = m_buttonControl.GetXPosition() + freeSpaceWidth - rightTextWidth - + m_label.GetLabelInfo().offsetX; + + // Limit the max width for the left label to avoid text overlapping + m_buttonControl.SetMaxWidth(posX + m_label.GetLabelInfo().offsetX); + m_buttonControl.Render(); + + CGUISpinControl::RenderText(posX, m_buttonControl.GetYPosition(), rightTextWidth, + m_buttonControl.GetHeight()); } |