Skip to content
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

Rewrap ConsoleUI textbox for scrollbar and resize #3514

Merged

Conversation

HebaruSan
Copy link
Member

@HebaruSan HebaruSan commented Jan 12, 2022

Problems

  • ConsoleUI's textbox (used on the progress screen and mod info) wraps lines longer than its width at word boundaries, but unbroken words longer than its width (e.g. URLs) underlap the scrollbar if there is one, hiding one character from view
  • If you resize ConsoleUI and press Ctrl+L, the text within the textbox is still formatted according to its previous layout, which may leave big gaps or allow the text to overflow the box

Noticed while testing RP-1 express install in ConsoleUI for #3512, because a Mac user asked about RP-1 on the forum.

Causes

ConsoleTextBox performs word wrap on each line as it is added, using the full width without the scrollbar. Words longer than the textbox width are split at the width of the textbox at the time they are added. If that width later changes, by either the addition of a scrollbar or the resizing of the window, the old wrapping is retained as-is.

Changes

Now we store the original full strings in lines and the word-wrapped strings in displayLines. AddLine appends its raw input to the former and word-wraps it into the latter. A scrollbar-aware rewrapLines() function re-does this word wrapping as needed, and we call this function when we first add the scrollbar as well as anytime the textbox size changes. This will ensure that the scrollbar never overwrites characters, and the word wrap always fits the box properly.

@HebaruSan HebaruSan added Bug Something is not working as intended Enhancement New features or functionality Pull request ConsoleUI Issues affecting the interactive console UI labels Jan 12, 2022
Copy link
Member

@DasSkelett DasSkelett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Funny edge cases we have there :P
Tested with CameraToolsContinued, which has a URL in the description, and while I had to downscale the terminal window to size where it would be unusable anyway, it did display the wrapped but complete.

@DasSkelett DasSkelett merged commit 19af3dd into KSP-CKAN:master Jan 19, 2022
@HebaruSan HebaruSan deleted the fix/consoleui-textbox-scroll-wrap branch January 19, 2022 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is not working as intended ConsoleUI Issues affecting the interactive console UI Enhancement New features or functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants