feat: implement multi-styled text shape #1143
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fix #1131
The idea of this new shape is to be able to render text with multiple styles (i.e. char 0 to 10 is blue, char 10 to 20 is black and with another font size).
I've used the Text shape and updated it to be able to support this feature. I've added more types than in the text shape (i.e. in getters/setters & context types) and tried to add all methods in the class.
To apply styles to the text you need to provide
textStyles
property for each text part. I'm not sure that was the best approach, but it was the easier in my use-case and I haven't found any other easy way to do it.I don't know if @lavrton plan to merge this, but maybe it could help some people that need this feature.
Since the new shape use the same logic as the text shape (text wrapping, underline...) maybe it could be a good move to merge them.
I haven't done any tests (excepts manual ones, and everything seems to work) and I don't really plan to do any of them soon, I don't have really the time for it.
Anyone who want to improve this PR is welcomed (I've allowed maintainers to edit this PR but I also can add users to my fork is someone want to update the branch).