Extract CScrollRegion::HEIGHT_MAGIC_FIX

Currently this must be added when calculating the required height of a UI rect for a scroll region to get a perfect fit.

It is extracted into a constant so it can be used in other parts to get list boxes with the perfect size.
This commit is contained in:
Robert Müller 2023-06-06 23:46:42 +02:00
parent abfafa314a
commit f16974d1a9
2 changed files with 6 additions and 2 deletions

View file

@ -184,8 +184,8 @@ void CScrollRegion::End()
bool CScrollRegion::AddRect(const CUIRect &Rect, bool ShouldScrollHere)
{
m_LastAddedRect = Rect;
// Round up and add 1 to fix pixel clipping at the end of the scrolling area
m_ContentH = maximum(std::ceil(Rect.y + Rect.h - (m_ClipRect.y + m_ContentScrollOff.y)) + 1.0f, m_ContentH);
// Round up and add magic to fix pixel clipping at the end of the scrolling area
m_ContentH = maximum(std::ceil(Rect.y + Rect.h - (m_ClipRect.y + m_ContentScrollOff.y)) + HEIGHT_MAGIC_FIX, m_ContentH);
if(ShouldScrollHere)
ScrollHere();
return !IsRectClipped(Rect);

View file

@ -89,6 +89,10 @@ Usage:
class CScrollRegion : private CUIElementBase
{
public:
// TODO: Properly fix whatever is causing the 1-pixel discrepancy in scrolling rect height and remove this magic value.
// Currently this must be added when calculating the required height of a UI rect for a scroll region to get a perfect fit.
static constexpr float HEIGHT_MAGIC_FIX = 1.0f;
enum EScrollRelative
{
SCROLLRELATIVE_UP = -1,