From acacc3f2e855f1b6c3ca05035100dafb95a04aa2 Mon Sep 17 00:00:00 2001 From: Rafal Kupiec Date: Mon, 1 Jan 2024 23:02:27 +0100 Subject: [PATCH] Fix input field text positioning --- xtldr2/textui.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/xtldr2/textui.c b/xtldr2/textui.c index 2496027..5141a33 100644 --- a/xtldr2/textui.c +++ b/xtldr2/textui.c @@ -881,6 +881,7 @@ BlpDrawDialogInputField(IN PXTBL_DIALOG_HANDLE Handle, WCHAR InputField[XTBL_TUI_MAX_DIALOG_WIDTH]; ULONG InputColor, TextColor; UINT_PTR Index, Position; + SIZE_T Length; /* Set dialog button colors */ if(Handle->Attributes & XTBL_TUI_DIALOG_ACTIVE_INPUT) @@ -922,9 +923,27 @@ BlpDrawDialogInputField(IN PXTBL_DIALOG_HANDLE Handle, BlDisableConsoleCursor(); BlConsoleWrite(InputField); + /* Check input field text length */ + Length = RtlWideStringLength(InputFieldText, 0); + if(Length > (Handle->Width - 9)) + { + /* Text longer than input field width, display only part of it */ + Length = Handle->Width - 9; + } + + /* Copy a part of input field text to input field */ + for(Index = 0; Index < Length; Index++) + { + /* Write input field text */ + InputField[Index] = InputFieldText[Index]; + } + + /* Add null terminator to the end of the line */ + InputField[Handle->Width] = 0; + /* Write input field text */ BlSetCursorPosition(Handle->PosX + 4, Handle->PosY + Handle->Height - Position); - BlConsoleWrite(InputFieldText); + BlConsoleWrite(InputField); /* Check if this is an active input field */ if(Handle->Attributes & XTBL_TUI_DIALOG_ACTIVE_INPUT) @@ -1178,21 +1197,18 @@ BlDisplayInputDialog(IN PWCHAR Caption, /* Other key pressed, add character to the buffer */ if(Handle.Attributes & XTBL_TUI_DIALOG_ACTIVE_INPUT && Key.UnicodeChar != 0) { - if(InputFieldLength < Handle.Width - 8 - 1 && TextPosition < Handle.Width - 8 - 1) - { - RtlMoveMemory(InputFieldBuffer + TextPosition + 1, InputFieldBuffer + TextPosition, (InputFieldLength - TextPosition) * sizeof(WCHAR)); - InputFieldBuffer[TextPosition] = Key.UnicodeChar; - TextPosition++; - InputFieldLength++; - InputFieldBuffer[InputFieldLength] = 0; - } + RtlMoveMemory(InputFieldBuffer + TextPosition + 1, InputFieldBuffer + TextPosition, (InputFieldLength - TextPosition) * sizeof(WCHAR)); + InputFieldBuffer[TextPosition] = Key.UnicodeChar; + TextPosition++; + InputFieldLength++; + InputFieldBuffer[InputFieldLength] = 0; } } - if(TextPosition > (Handle.Width - 8)) + if(TextPosition > (Handle.Width - 9)) { - TextIndex = TextPosition - (Handle.Width - 8); - TextCursorPosition = Handle.Width - 8; + TextIndex = TextPosition - (Handle.Width - 9); + TextCursorPosition = Handle.Width - 9; } else {