Not a solution for your problem, but if you use a non-proportional font where all letters have the same width, it’s quite easy to truncate the text to the amount of letters that only fill 2 lines.
I think this is the procedure you want. I’ve not tested any of this.
declare a char* end which is null
Call nvgTextBreakLines passing in an array of 3 NVGtextRow structs and a maxRows value of 3.
If the return value is greater than 1 then
end = rows[1].end
pass that end variable as the last parameter into your nvgTextBox call.
NB I am assuming here that the value of label.c_str() is stable between calls so long as you don’t modify the label object. I don’t know std::string well enough to be sure of that.
edit: Apparently this c style string representation is guaranteed to remain valid while the std::string is not modified.