DEV Community

Discussion on: Text wrap with SkiaSharp

Collapse
 
iains1986 profile image
Iain • Edited

There's a bug in your logic here that means you won't render the last line of text.

You add the text to the 'wrappedLines' everytime the string goes over the edge, but the last line doesn't get added so won't get drawn.

Need a simple, 'wrappedLines.Add(line);' after the foreach loop.

Also FYI for people reading, I'm sure you'll be aware, but ideally you want this logic calculating once in a different location than during the actual render - otherwise it could get expensive to continuously measure the lines to calculate the word wrap and do this again and again even though it keeps working it out the same.