TextNode and Finding the Overflow


#1

I’m trying to find a means of getting the “overflow” text from a TextNode–or another means of achieving what I have in mind.

To explain:

My game has a number of in-game documents that the player can read, each potentially consisting of multiple pages. Each page may have multiple paragraphs, each of which is held in a TextNode.

Naturally, any one page will only hold so much text.

Up until now I’ve dealt with this during construction of the document by simply checking whether the current paragraph overruns the bottom of the page, and if so, shunting it onto the next page.

This works–but doesn’t look great, I feel. What I would prefer is that, when a paragraph overruns the bottom of the page, it’s split at the last “valid” line, and the remainder is placed on the next page in a new paragraph-object.

The problem, then, is how to do this.

I can, I think, find the index of the last “valid” line in an overflowing paragraph by finding out what percentage of the TextNode is within the page, and dividing that by the line-height. (And then flooring that value to get an integer.) I can also get the paragraph-text split into word-wrapped lines from the TextNode. I could perhaps separate that using “\n”-characters. But given that my text may in original form contain “\n”-characters, I’m not sure of how safe to the structure of the text it might be to attempt to reassemble it from these word-wrapped strings.

TextNode does, however, seem to have the facility to handle these matters itself: given a maximum number of rows, it will automatically cut overflowing text, and set a flag to indicate that overflow, I believe. That sounds like just what I want!

The problem is that, as far as I gather, it just throws away the overflow, and doesn’t seem to keep a record of the splitting-point.

Right now, the only idea that I have for getting that overflowed text would be to search for the contents of the TextNode in the original paragraph-string, which doesn’t sound terribly elegant…

Does anyone have any thoughts?


#2

What I’m wondering is… does it matter that what you’re setting on the second TextNode is not the original pre-wrapped string? Assuming the pages are the same width, you only need to apply the wordwrapping once, then just split the string after the desired number of rows, and feed it to a next TextNode; for display, it shouldn’t matter that the remainder you get from that already has word-wrapping applied.

If you are OK with digging down into the TextAssembler, there are methods that will tell you more, though. You can use calc_index(r, c) to get the index of the character corresponding to the Nth row, and there’s another pair of methods that do the reverse, though I must admit that I’m not 100% sure that this index corresponds to the index into the original string.


#3

Hmm… Interesting.

I think that I considered using the word-wrapped string, but didn’t know how TextNode would handle that. I don’t want to end up with extra line-breaks, or find further down the line that, if a line has a specific number of characters it ends up pushing the trailing break onto another line, or something like that.

But based on what you say, maybe it’s worth a try.

And if that fails, thank you for pointing me to the “calc_index” method–I looked briefly at TextAssembler, but didn’t spot that! If called for, I can experiment with that, I imagine.

Thank you for the help! :slight_smile:


#4

I don’t see the issue with just passing in the word-wrapped string to the other pages. The word-wrapping shouldn’t suddenly start introducing extra linewraps since it’s already wrapped to the desired width. Just to be sure, you could just disable the wordwrapping on the TextNode for the subsquent pages.


#5

Fair enough, and thank you for both the reassurance and for pointing out that I could disable word-wrapping (something that, for some reason, didn’t occur to me ^^; ). :slight_smile: