Fix input field text positioning
All checks were successful
Builds / ExectOS (amd64) (push) Successful in 27s
Builds / ExectOS (i686) (push) Successful in 26s

This commit is contained in:
Rafal Kupiec 2024-01-01 23:02:27 +01:00
parent 46253c0503
commit acacc3f2e8
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4

View File

@ -881,6 +881,7 @@ BlpDrawDialogInputField(IN PXTBL_DIALOG_HANDLE Handle,
WCHAR InputField[XTBL_TUI_MAX_DIALOG_WIDTH]; WCHAR InputField[XTBL_TUI_MAX_DIALOG_WIDTH];
ULONG InputColor, TextColor; ULONG InputColor, TextColor;
UINT_PTR Index, Position; UINT_PTR Index, Position;
SIZE_T Length;
/* Set dialog button colors */ /* Set dialog button colors */
if(Handle->Attributes & XTBL_TUI_DIALOG_ACTIVE_INPUT) if(Handle->Attributes & XTBL_TUI_DIALOG_ACTIVE_INPUT)
@ -922,9 +923,27 @@ BlpDrawDialogInputField(IN PXTBL_DIALOG_HANDLE Handle,
BlDisableConsoleCursor(); BlDisableConsoleCursor();
BlConsoleWrite(InputField); 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 */ /* Write input field text */
BlSetCursorPosition(Handle->PosX + 4, Handle->PosY + Handle->Height - Position); BlSetCursorPosition(Handle->PosX + 4, Handle->PosY + Handle->Height - Position);
BlConsoleWrite(InputFieldText); BlConsoleWrite(InputField);
/* Check if this is an active input field */ /* Check if this is an active input field */
if(Handle->Attributes & XTBL_TUI_DIALOG_ACTIVE_INPUT) if(Handle->Attributes & XTBL_TUI_DIALOG_ACTIVE_INPUT)
@ -1177,8 +1196,6 @@ BlDisplayInputDialog(IN PWCHAR Caption,
{ {
/* Other key pressed, add character to the buffer */ /* Other key pressed, add character to the buffer */
if(Handle.Attributes & XTBL_TUI_DIALOG_ACTIVE_INPUT && Key.UnicodeChar != 0) 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)); RtlMoveMemory(InputFieldBuffer + TextPosition + 1, InputFieldBuffer + TextPosition, (InputFieldLength - TextPosition) * sizeof(WCHAR));
InputFieldBuffer[TextPosition] = Key.UnicodeChar; InputFieldBuffer[TextPosition] = Key.UnicodeChar;
@ -1187,12 +1204,11 @@ BlDisplayInputDialog(IN PWCHAR Caption,
InputFieldBuffer[InputFieldLength] = 0; InputFieldBuffer[InputFieldLength] = 0;
} }
} }
}
if(TextPosition > (Handle.Width - 8)) if(TextPosition > (Handle.Width - 9))
{ {
TextIndex = TextPosition - (Handle.Width - 8); TextIndex = TextPosition - (Handle.Width - 9);
TextCursorPosition = Handle.Width - 8; TextCursorPosition = Handle.Width - 9;
} }
else else
{ {