-
-
Notifications
You must be signed in to change notification settings - Fork 387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scrollable text input #9393
base: master
Are you sure you want to change the base?
Scrollable text input #9393
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @felix642 , I put few comments here. Would you mind to check them?
src/fheroes2/gui/ui_text.cpp
Outdated
while ( _textOffset + maxCharacterCount <= _cursorPosition ) { | ||
// If the cursor is to the right of the textBox | ||
++_textOffset; | ||
maxCharacterCount = getMaxCharacterCount( reinterpret_cast<const uint8_t *>( _text.data() + _textOffset ), static_cast<int32_t>( _text.size() - _textOffset ), | ||
charHandler, maxWidth ); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it correct to say that the complexity of this loop is O(N * (N / 2)) where N is the number of characters present in the string? Is there a way to avoid recalculating all the character lengths?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we could always call getMaxCharacterCount()
right before the while loop and then compute the new maximum character count using the characters' width at the beginning / end of the loop. This should give us better performances.
I don't know if the added complexity is really needed though. This while loop is only used to make sure that the cursor is always visible if it overflows to the right. This means that the while loop should, on average, be executed only once or twice (moving the view by one character should be enough for most scenarios).
The only cases where the while loop might be executed more than once is when a large character is added to the right of the string and small characters are removed to the left.
4c9760a
to
6209461
Compare
c619c4e
to
f829da9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, @felix642, the scrollable text input is an important improvement to fheroes2 GUI and for the save file dialog it works good. 👍
- Unfortunately the Virtual Keyboard has not left/right arrow keys so an Android user will not be able to scroll the text.
- Also now we lack of
...
and there is no extra symbol to show user that there is some text beyond the input text border.
We can try to make it a bit better. :)
What do you think about the next logic?
- If the cursor will be positioned less than 4 chars (this value is discussible) closer to the field border then scroll the text so that the cursor will be the 4th character from that border. (If there is no text to scroll then place the cursor at its place closer to the border).
- When there is more then one char beyond the input field then display
...
. (We will need to take its width into account in setting cursor position when...
is displayed at the beginning).
Improved the editable text field in the save menu. When overflowing, the textbox would previously display the beginning of the text and complete with '...' for the overflowing text. The user could continue typing but would not get any feedback. With those changes the input box now scrolls when the text overflows.
save.webm
The changes were also applied to the virtual keyboard, but since this keyboard does not have any arrow key the user is not able to scroll left or right. This is still an improvement from the current implementation since the user it at least able to see what he is typing, but ideally we should also add some arrow keys or similar feature to be able to move the cursor left and right.
The changes are related to : #7275 and #1318 both issues are already fixed but with the current feedback it's hard to know the actual character limit.