Skip to content

MVP for Multi-Line Textbox #6564

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

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

minetoblend
Copy link

@minetoblend minetoblend commented Apr 10, 2025

A MVP implementation for a multi-line text box. This is still a bit messy and incomplete, but I wanted to see if this approach is generally a step in the right direction before going further.

I opted for splitting the text into words & putting them as individual DrawableSprites into a FillFlowContainer for the layout, and compute a small index from that to help with converting between draw-position and text-positions whenever the layout gets recalculated.
I also attempted to extract a TextSelection class from the selection handling in TextBox, so that the selection behavior could be shared between the classes without relying on inheritance.

There's still a couple bugs that I'm aware of

  • Multiple line breaks in a row get treated like a single line break.
  • Line breaks at the end of the string don't show up
  • Selection from mouse-down throws sometimes after the line count has changed, likely caused by a bug in the LineInfo calculation leading to null items in the Lines array
2025-04-10.03-34-38.mp4

Closes #1618

@Joehuu
Copy link
Member

Joehuu commented Apr 10, 2025

This will close #1618 (can't edit OP).

@Joehuu Joehuu added the area:UI label Apr 10, 2025
@frenzibyte
Copy link
Member

frenzibyte commented Apr 10, 2025

This looks pretty interesting on a quick glimpse. Without diving in details, has there been any exploration or intention to merge this together with TextBox, if so, what's the end result of having that? The amount of logic copied across between TextBox and this new TextArea component feels too rough to accept as coexisting together.

I'm also curious to know what sparked this much effort out of nowhere, has this been discussed somewhere else or just pushed out like this?

@minetoblend
Copy link
Author

minetoblend commented Apr 10, 2025

has there been any exploration or intention to merge this together with TextBox, if so, what's the end result of having that? The amount of logic copied across between TextBox and this new TextArea component feels too rough to accept as coexisting together.

The TextSelection class is about as far as I went with that, though I didn't want to alter the TextBox class to make use of it too before seeing if this is the way to go about things. I think relying on inheritance is an easy way to shoot yourself in the foot with 2 components as complex as this, so the goal was to favor composition over inheritance here. Also makes it much easier to test these things in isolation.
The same approach could be used for other parts of the TextBox too.

I'm also curious to know what sparked this much effort out of nowhere

For the most part just boredom, though I know that at some point I'll need a multiline text box for my typescript port of osu-framework, so I figured I might as well just make it for osu-framework first since it seems like a useful component to have.
I'm also interested in eventually seeing a ModdingV2 integration in lazer (see ppy/osu-web#11113), and having a multiline text box is kind of a requirement for that.

has this been discussed somewhere else or just pushed out like this?

There's a brief exchange on discord from earlier today but nothing besides that.

@minetoblend
Copy link
Author

minetoblend commented Apr 10, 2025

Couple more thoughts on the whole thing

It'd probably make sense to add entries for the following 2 actions to PlatformAction

  • Vertical text navigation (up/down keys)
  • Go to text start/end (ctrl+home/end on windows)

I think naming of Select/MoveForwardLine should be reconsidered, something like SelectLineStart/End maybe. Those names are pretty ambiguous if you can also navigate up/down between lines. Without context I'd assume they're for vertical navigation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add MultilineTextBox component
3 participants