nanovg
nanovg copied to clipboard
nvgTextBreakLines ignores leading spaces?
Why is nvgTextBreakLines ignoring leading spaces at the beginning of each row? It seems to be intended and even commented: "Indicate to skip the white space at the beginning of the row." and "// Skip white space until the beginning of the line". But with that 'feature', I can't draw text boxes with lines that are indented with spaces, such as code, etc.
What am I missing?
I don't have a good reason why, it just made sense at the time of writing. My use case was usual text paragraphs, there it makes sense. I think it could make sense to keep the whitespace after a newline. What do you think the rules should be?
I was playing around with some gui code i wrote many years ago and recently ported it to nanovg. One such use case i have is a small script editor which requires indented code. I'm actually using that as a test case only and the project I'm working on will probably not need such an editor, but I'd be glad if it just works whenever I need it.
commenting out the if condition from the block of code: if (type == NVG_CHAR) {... } works, it seems, but I am not sure what else this will affect. Thoughts?
I understand that this topic is super old and probably won't change. Maybe even shouldn't change as I'm sure by now people have coded in assumptions on this behavior.
However, I think this is putting application-level logic down into the renderer. Deciding whether or not to render leading spaces should be up to the application and not the rendering engine. Or at least provide a way to turn it off.
I'm struggling with a use case right now where I need to render whitespace as part of structured content. The whitespace is at the start of each line. Having this assumption in the renderer makes it very difficult to do.
So... I think the rule should be that this is an application space problem and the renderer should draw the whitespace it is given.
Hi people, sorry for reviving old thread, I implemented custom textBox control with scrolling ability. All works fine, except missing white spaces at beginning of the line. I tried to fix nvgTextBreakLines, but there is a lot of variables inside which I don't understand. Is there somewhere any patch which can help me with this issue?
EDIT: I think I understand why is white space removed. In some cases it should stay and in others it should be removed. It is not truth that is should be removed always. Space is wanted if it is new line after \n. Maybe in other cases too
Many thanks for great tool
EDIT2:
Hm maybe I fixed it, output looks good, but maybe I bricked something...I inited ptype to NVG_NEWLINE and moved case 32: above default of the switch. I let codepoint 32 work like space if previous type was not NVG_NEWLINE
int type = NVG_SPACE, ptype = NVG_NEWLINE;//NVG_SPACE;
unsigned int pcodepoint = 0;
.......
switch (iter.codepoint) {
case 9: // \t
case 11: // \v
case 12: // \f
//case 32: // space
case 0x00a0: // NBSP
type = NVG_SPACE;
break;
case 10: // \n
type = pcodepoint == 13 ? NVG_SPACE : NVG_NEWLINE;
break;
case 13: // \r
type = pcodepoint == 10 ? NVG_SPACE : NVG_NEWLINE;
break;
case 0x0085: // NEL
type = NVG_NEWLINE;
break;
case 32:
if (ptype != NVG_NEWLINE) {
type = NVG_SPACE;
break;
}
default:
if ((iter.codepoint >= 0x4E00 && iter.codepoint <= 0x9FFF) ||
(iter.codepoint >= 0x3000 && iter.codepoint <= 0x30FF) ||
(iter.codepoint >= 0xFF00 && iter.codepoint <= 0xFFEF) ||
(iter.codepoint >= 0x1100 && iter.codepoint <= 0x11FF) ||
(iter.codepoint >= 0x3130 && iter.codepoint <= 0x318F) ||
(iter.codepoint >= 0xAC00 && iter.codepoint <= 0xD7AF))
type = NVG_CJK_CHAR;
else
type = NVG_CHAR;
break;
}