-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Adding support for newlines in strings to nk_text/nk_label and family. #661
base: master
Are you sure you want to change the base?
Conversation
The new behavior is as follows: - nk_text/nk_label: One line of text will be rendered, up to the first newline - nk_text_wrap/nk_label_wrap: Multiple lines of text will be rendered, wrapping when horizontal space is exhausted (as normal), but also when a newline is reached. - nk_text_multiline/nk_label_multiline (new): Multiple lines of text will be rendered, wrapping only when a newline is reached.
I'd like to apologize for the merge errors. I originally made my changes right before you did the header split, so when I went to merge the changes back in, I had to do so manually. |
Hey @AntiBlueQuirk, Using Code used to test your implementation. nk_layout_row_static(ctx, 100, 200, 1);
nk_label_multiline(ctx, "This is a very long line to hopefully get this text to be wrapped into multiple lines to show line wrapping");
nk_layout_row_dynamic(ctx, 100, 1);
nk_label_multiline(ctx, "This is another long text to show dynamic window changes on multiline text");
nk_layout_row_static(ctx, 100, 200, 1);
nk_label_wrap(ctx, "This is a very long line\n to hopefully get this text to be wrapped into multiple lines\n to show line wrapping");
nk_layout_row_dynamic(ctx, 100, 1);
nk_label_wrap(ctx, "This is another long text to show dynamic window\n changes on multiline text"); Another problem is that your new implementation does wrapping on character basis and not word basis like previously implemented in nuklear (master): nuklear (PR): |
The multiline functions cutting off text is intentional. I added these new variants so that you can have text that only has manual line breaks. I didn't realize I broke word wrapping. I tried to be careful not to do this. I guess I'll have to look at it some more. |
Ah OK. Could you add some example code to
It is relatively simplistic word wrapping using spaces so nothing too complex. |
Okay, It turns out I just inverted the wrapping logic, so easy fix. I also added some code to the demo to show the difference in behavior. Although, in retrospect, the naming the new functions |
Speaking about word wrapping, don't forget about very long words, which won't fit in the text/label widget width. These exceptions should be character-wrapped instead of word-wrapped, otherwise (significant) part of the long word won't show up at all. |
@dumblob I only changed the breaking functions just enough to add the new behavior, so the old behavior should still be there. I checked, and it looks like very short lines still break words by character when necessary. |
Is it possible to use this function yet? |
The new behavior is as follows:
One line of text will be rendered, up to the first newline
Multiple lines of text will be rendered, wrapping when horizontal space
is exhausted (as normal), but also when a newline is reached.
Multiple lines of text will be rendered, wrapping only when a newline is reached.
This PR adds va_list functions, so it includes my pr_valist pull request (#660). If you don't want to merge pr_valist, I can provide a version without the va_list functions.
This PR should fix #532, though it does introduce a slight breaking change to nk_text and nk_text_wrap: Before those functions would render newline characters as ? symbols, and ignore them. In particular, nk_text would take entire paragraphs of text and render them on one line. Now it only renders the first line of text, and nk_text_wrap manually breaks on newlines. Since this behavior was probably undesirable, I doubt anyone is depending on it. The external behavior of these functions doesn't change, just they way they render things.