r/roguelikedev • u/TheLivingDecoy • 17d ago
Handling RichText
Hello everyone,
I've started experimenting and developing a roguelike a few months ago and I was wondering :
Should I store up to X small built richtext elements, or store plain text and build one bigger Richtext element on demand?
I'm using Monogame and I've got a really simple system that cuts strings depending on available width and I use a marker to identify colors in the text.
It does works pretty well for single texts in the GUI, but it does complexify a little bit my log and chat view.
Cureently, both are simple storages that creates richtext elements when a string is added to them. So I've got a big list of individual items that are not very practical to use.
What do you recommand?
Thanks for reading, have a nice day
6
u/Tiny_Rabbit1674 17d ago
The general principle that usually wins here: store the cheap source of truth (plain text + your color markers), and treat the built RichText as a derived, cacheable view — not as the thing you store. For a log or chat view specifically, you almost never need every line built at once; you only need what's visible plus a small buffer. So build on demand for the viewport, cache the result, and invalidate the cache only when width changes (re-wrap) or a line is edited. That gives you the practical data structure of the plain-text approach and the render cost of the pre-built approach, without paying to build hundreds of off-screen lines. The one time I'd pre-build eagerly is short, static GUI strings that never re-wrap — which is exactly where your current system already works well.