just wrote a very messy text wrapping function. (keep going, don't look back edition)
4 comments
but right now, there's some quick and dirty unsafe hidden in there. I'm pretty sure it's sound, but I actually think it shouldn't be necessary, once I realize there's a std library function that does exactly that. once I manage to take the unsafe out I'll put up a link to that little bit's source perhaps I'll even put up an unlisted repo for the project's state, tonight. we'll see current mood: enjoying the opening disclaimer of the rustonomicon > THE KNOWLEDGE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF UNLEASHING INDESCRIBABLE HORRORS THAT SHATTER YOUR PSYCHE AND SET YOUR MIND ADRIFT IN THE UNKNOWABLY INFINITE COSMOS. |
there's a fun little struct called `WrappedText(String)` that I created for this. the only way to construct it is by giving the unwrapped &str and the desired width, along with the font to consider for calculating widths.
from that, it will wrap the text, placing the final String into the struct's field.
that means that the wrapping occurs once, on construction, and that types that require pre-wrapped text to work (efficiently) can rely on it being wrapped.