diff options
author | Robert Müller <robytemueller@gmail.com> | 2022-04-23 12:04:46 +0200 |
---|---|---|
committer | Robert Müller <robytemueller@gmail.com> | 2023-06-16 20:49:40 +0200 |
commit | 257de7e2e4a0a6fde3564ce60c73e42ebb8b9265 (patch) | |
tree | c2b536f51f10efcb9bb8c4be67c0e64e20f7d968 | |
parent | f65e0527531657b3013af6d302a67f0fc3517152 (diff) |
Implement smooth vertical scrolling for chat input
-rw-r--r-- | src/game/client/components/chat.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/game/client/components/chat.cpp b/src/game/client/components/chat.cpp index 15f29a370..d6fcac9b8 100644 --- a/src/game/client/components/chat.cpp +++ b/src/game/client/components/chat.cpp @@ -928,6 +928,7 @@ void CChat::OnRender() pCursor->m_MaxWidth = Width-190.0f-s_CategoryCursor.Width(); float ScrollOffset = m_Input.GetScrollOffset(); + float ScrollOffsetChange = m_Input.GetScrollOffsetChange(); pCursor->MoveTo(CursorPosition.x, CursorPosition.y - ScrollOffset); pCursor->m_MaxLines = -1; pCursor->m_Flags = TEXTFLAG_WORD_WRAP; @@ -977,11 +978,16 @@ void CChat::OnRender() Graphics()->ClipDisable(); // scroll to keep the caret inside the clipping rect - const float CaretPositionY = m_Input.GetCaretPosition().y + InputFontSize * 0.5f; + const float CaretPositionY = m_Input.GetCaretPosition().y + InputFontSize * 0.5f - ScrollOffsetChange; if(CaretPositionY < ClippingRect.y) - m_Input.SetScrollOffset(maximum(0.0f, ScrollOffset - InputFontSize)); + ScrollOffsetChange -= InputFontSize; else if(CaretPositionY + InputFontSize * 0.35f > ClippingRect.y + ClippingRect.h) - m_Input.SetScrollOffset(ScrollOffset + InputFontSize); + ScrollOffsetChange += InputFontSize; + + UI()->DoSmoothScrollLogic(&ScrollOffset, &ScrollOffsetChange, ClippingRect.h, pCursor->BoundingBox().h); + + m_Input.SetScrollOffset(ScrollOffset); + m_Input.SetScrollOffsetChange(ScrollOffsetChange); } } |