AntonioND / nitro-engine

3D engine for the Nintendo DS
150 stars 10 forks source link

Rich text: Add methods for getting string width/height, limiting text to a box/to certain num of chars #27

Open WiIIiam278 opened 5 months ago

WiIIiam278 commented 5 months ago

I'd like to draw text using rich text's quad drawing mode within a specific box region on a screen (ideally, wrapping the text if it goes over). With the monospace NE_Text.h API I could do NE_TextPrintBox/NE_TextPrintBoxFree to do this, or implement my own thing using NE_TextPrintFree since characters were of a constant known width.

Since rich text is VWF and box drawing isn't a thing in NE_RichText, this isn't quite possible. It'd be great to expose a method to get the length of a string, as DSF exposes DSF_StringRenderDryRun for this purpose, but the handle needed to call DSF methods is abstracted away by Nitro-Engine :).

Similarly, an option to limit the number of characters to draw is no longer present (though of course this isn't a big deal as you can just trim the string before passing it). Still, it'd be nice to have this option.

AntonioND commented 5 months ago

Hi, thanks for the suggestions!

Regarding the idea of rendering to a text box is okay, but the problem is determining where to cut the text. The monospaced functions just cut it whenever, but that is a pretty bad idea with VWF, I'd say...

For now, I've exposed DSF_StringRenderDryRun in https://github.com/AntonioND/nitro-engine/commit/5ce71a9b02e74defa557ba5dc0f2f5244723f799 so that at least there is that option (I forgot to do it when I added the other functions!).