6671: Ensure line inputs are deactivated when they are not rendered r=def- a=Robyt3

Check if the active line input was not rendered and deactivate it in that case.

This can happen e.g. when an input in the ingame menu is active and the menu is closed or when switching between menu and editor with an active input.

This was causing the IME candidate list to be rendered ingame after closing the menu. Closes #6666.

## Checklist

- [X] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Robert Müller <robytemueller@gmail.com>
This commit is contained in:
bors[bot] 2023-05-26 22:26:18 +00:00 committed by GitHub
commit 144bb1dd7f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View file

@ -34,6 +34,7 @@ void CLineInput::SetBuffer(char *pStr, size_t MaxSize, size_t MaxChars)
m_Hidden = false;
m_pEmptyText = nullptr;
m_MouseSelection.m_Selecting = false;
m_WasRendered = false;
}
if(m_pStr && m_pStr != pLastStr)
UpdateStrData();
@ -401,6 +402,8 @@ bool CLineInput::ProcessInput(const IInput::CEvent &Event)
STextBoundingBox CLineInput::Render(const CUIRect *pRect, float FontSize, int Align, bool Changed, float LineWidth)
{
m_WasRendered = true;
const char *pDisplayStr = GetDisplayedString();
const bool HasComposition = Input()->HasComposition();
@ -528,6 +531,23 @@ STextBoundingBox CLineInput::Render(const CUIRect *pRect, float FontSize, int Al
void CLineInput::RenderCandidates()
{
// Check if the active line input was not rendered and deactivate it in that case.
// This can happen e.g. when an input in the ingame menu is active and the menu is
// closed or when switching between menu and editor with an active input.
CLineInput *pActiveInput = GetActiveInput();
if(pActiveInput != nullptr)
{
if(pActiveInput->m_WasRendered)
{
pActiveInput->m_WasRendered = false;
}
else
{
pActiveInput->Deactivate();
return;
}
}
if(!Input()->HasComposition() || !Input()->GetCandidateCount())
return;

View file

@ -73,6 +73,7 @@ private:
const char *m_pEmptyText;
FClipboardLineCallback m_pfnClipboardLineCallback;
bool m_WasChanged;
bool m_WasRendered;
char m_ClearButtonId;