-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RichTextLabel Highlighting, Redacting #35608
Conversation
Don't forget to merge the commits together as it requested by our workflow, see http://docs.godotengine.org/en/latest/community/contributing/pr_workflow.html#mastering-the-pr-workflow-the-rebase |
Also, the code for parsing BB tags is duplicated in the following file. 😞 Lines 1391 to 1400 in 5db45fb
|
Please note for the PR to work for 3.2; change the parse_color function to below. As the current state of the PR is assuming the changes made to
|
In the second and third conditions, instead of |
I changed the selection behavior of the |
This pull request is now updated and It should work with all of the characters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feature looks good to me. We'll need it at some point to improve the display of the built-in editor help (e.g. making inline code stand out more).
Make sure to update the class reference XML to document the newly added methods.
I am unsure what I did, but I just wanted to request review, not remove one. Sorry. |
To draw redacted text that cannot be retrieved by external means, it's likely better to replace the text with a Unicode character (and keep spaces as-is if desired). This ensures screen readers and the like can't access the text (once screen reader support is implemented). |
Yes, by defining a fallback font that contains the character you need. It will be used if the main font doesn't contain the glyph in question. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an issue with this approach (drawing highlights for each glyph individually) if you are using font/script with the overlapping glyphs.
On the screenshot, semi transparent bgcolor
is covering part of the text.
For this reason, text selection is fully drawn before drawing any text(see lines 940-953), same should be done for highlights:
- Draw selection and
bgcolor
rectangles. - Draw text outlines.
- Draw main text.
- Draw
fgcolor
rectangles.
Text server have dedicated for this specific purpose, which return non overlapping highlight/selection ranges for the portion of text:
Vector<Vector2> range = TS->shaped_text_get_selection(rid, start_position, end_position);
I believe it is now working as expected. Here is my test text
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using over glyph array won't work if there are writing direction changes in the middle of highlight, using character range instead should work.
It worked! For reference here is my test text where I believe exactly what you describe happens:
and here is the result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CI log:
scene/gui/rich_text_label.cpp:4187:32: error: 'INT_MAX' was not declared in this scope
4187 | Vector2i fbg_index = Vector2i(INT_MAX, INT_MIN);
| ^~~~~~~
scene/gui/rich_text_label.cpp:46:1: note: 'INT_MAX' is defined in header '<climits>'; did you forget to '#include <climits>'?
45 | #include "editor/editor_scale.h"
+++ |+#include <climits>
46 | #endif
scene/gui/rich_text_label.cpp:4187:41: error: 'INT_MIN' was not declared in this scope
4187 | Vector2i fbg_index = Vector2i(INT_MAX, INT_MIN);
| ^~~~~~~
scene/gui/rich_text_label.cpp:4187:41: note: 'INT_MIN' is defined in header '<climits>'; did you forget to '#include <climits>'?
scene/gui/rich_text_label.cpp:4218:13: error: declaration of 'i' shadows a previous local [-Werror=shadow=local]
4218 | for (int i = 0; i < sel.size(); i++) {
| ^
scene/gui/rich_text_label.cpp:4191:11: note: shadowed declaration is here
4191 | for (int i = start; i < end; i++) {
| ^
Thanks! And congrats for your first merged Godot contribution 🎉 |
Any chance to have this back-ported to 3.x? It would be very useful to have this available while 4.x releases and catches up in stability/production-usability. |
Backporting efforts are welcome, but this requires an entirely different implementation in |
This was first written it was in 3.x, but was creating the box per glyph; which lead to issues with international alphabets and wasn't great at identifying the proper offsets for the line it was filling. Subsequently, the PR was entirely rewritten using the |
This pull request addresses godotengine/godot-proposals#367 by adding highlighting and redacting capabilities to RichTextLabel with the tags bgcolor= and fgcolor=
Edit: Removed outdated information