Skip to content

Commit

Permalink
Merge pull request ddnet#7359 from Robyt3/Lineinput-IME-Alignment
Browse files Browse the repository at this point in the history
Improve positioning of IME candidate window for multi-line text
  • Loading branch information
def- authored Oct 20, 2023
2 parents 5987d8d + 1fde694 commit 09978f3
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/game/client/lineinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,9 +494,13 @@ STextBoundingBox CLineInput::Render(const CUIRect *pRect, float FontSize, int Al

m_CaretPosition = Cursor.m_CursorRenderedPosition;

STextBoundingBox CaretBoundingBox = TextRender()->TextBoundingBox(FontSize, pDisplayStr, DisplayCursorOffset, LineWidth);
CaretBoundingBox.MoveBy(CursorPos);
SetCompositionWindowPosition(vec2(CaretBoundingBox.Right(), CaretBoundingBox.Bottom()), CaretBoundingBox.m_H);
CTextCursor CaretCursor;
TextRender()->SetCursor(&CaretCursor, CursorPos.x, CursorPos.y, FontSize, 0);
CaretCursor.m_LineWidth = LineWidth;
CaretCursor.m_CursorMode = TEXT_CURSOR_CURSOR_MODE_SET;
CaretCursor.m_CursorCharacter = str_utf8_offset_bytes_to_chars(pDisplayStr, DisplayCursorOffset);
TextRender()->TextEx(&CaretCursor, pDisplayStr);
SetCompositionWindowPosition(CaretCursor.m_CursorRenderedPosition + vec2(0.0f, CaretCursor.m_AlignedFontSize / 2.0f), CaretCursor.m_AlignedFontSize);
}
else
{
Expand Down Expand Up @@ -609,7 +613,7 @@ void CLineInput::SetCompositionWindowPosition(vec2 Anchor, float LineHeight)
const vec2 ScreenScale = vec2(ScreenWidth / (ScreenX1 - ScreenX0), ScreenHeight / (ScreenY1 - ScreenY0));
ms_CompositionWindowPosition = Anchor * ScreenScale;
ms_CompositionLineHeight = LineHeight * ScreenScale.y;
Input()->SetCompositionWindowPosition(ms_CompositionWindowPosition.x, ms_CompositionWindowPosition.y - ms_CompositionLineHeight, ms_CompositionLineHeight);
Input()->SetCompositionWindowPosition(ms_CompositionWindowPosition.x, ms_CompositionWindowPosition.y, ms_CompositionLineHeight);
}

void CLineInput::Activate(EInputPriority Priority)
Expand Down

0 comments on commit 09978f3

Please sign in to comment.