I see there’s a nice solution here:
But I wanted to check if anything has been added to the official api. Thanks!
mawa
February 24, 2023, 10:51am
2
I’m afraid not. I did suggest it (a couple or more times) but so far, looks like we are not there yet (unless I missed it which would be terrible). Did I? …Let’s just ask BJS team’s GUI angel @carolhmj
Yup we don’t have anything on the API yet, sorry
aWeirdo
February 24, 2023, 1:08pm
4
There was a PR for something simular once… seems closed but never merged though.
BabylonJS:master
← cronvel:cronvel-gui-structuredtext
opened 11:26AM - 04 Nov 21 UTC
Following [this forum post](https://forum.babylonjs.com/t/multiple-colors-styles… -in-one-textblock/24680/18), here is the PR with the *Structured Text* implementation for `TextBlock` (GUI 2D).
This is a working implementation but should be considered as a base to iterate over.
**TLDR:**  This image was produced with a single `TextBlock` with word-wrapping and mixing color, bold, italic, underline and line-through.
**API:** instead of doing `textBlock.text = "My text"`...
... one would do `textBlock.structuredText = [ { text: "My text " } , { text: "with bold" , fontWeight: "bold" } ]`.
This is the simplest structure.
### Currently supported attributes:
* color (string | ICanvasGradient)
* underline (boolean)
* lineThrough (boolean)
* fontStyle (string)
* fontWeight (string)
* outlineWidth (number)
* outlineColor (string)
* shadowColor (string)
* shadowBlur (number)
* shadowOffsetX (number)
* shadowOffsetY (number)
### Few notes:
1. For instance, I coded it so it doesn't change the older `TextBlock` code. So there is 2 codepath ATM. BTW I think the non-structured-text code should be completely removed, except for the `.text` API.
2. Also I noted that the `TextBlock` is often fully recomputed for no reason.
E.g. simply opening dev-tools (which resize the screen but not the size of the `TextBlock`) have to compute word-wrapping again (which make a lot of `context.measureText()` calls).
Maybe it would be better to have more level of dirtiness, e.g. have a .`_innerContentIsDirty` property, and only recompute lines when the text have changed (or the `TextBlock` bounding box size).
3. I would also advocate for some alternate properties for structured text input, e.g. `bold: true` would convert to `fontWeight: bold`, for instance I've tried to keep the API close to the existing API and internal stuff. But I think it would be better to feed the `TextBlock` with more intuitive attribute.
4. The current code of this PR is not perfect with the `context.save()` and `context.restore()` things.
5. Font-size and font-family are not supported, and don't know if it makes sense, and it make things more complicated (e.g.: computing line-height. It's not that hard, but I don't think it's worth the trouble, it looks like a *niche* use-case to me)
It's my first time writing TypeScript, so maybe there are few things off.
mawa
February 25, 2023, 12:45pm
5
Yes, that’s the one I was ‘challenging’ and using as a base to try revive the topic (in a more ‘focused’ version) and as part of the ‘official’. But from @carolhmj response, it looks like this is still not on the menu yet. May be some day?