-
-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Make RichTextLabel's text represent the tag stack
#114787
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
base: master
Are you sure you want to change the base?
Conversation
0758f36 to
f7967cf
Compare
|
Hypothetically this structure can also resolve #100772. The problem occurring there is that
Changing the set text call in Notification Enter Tree to _set_text(text + leading_text + terminating_text) would not discard any information that was added before the Node entered tree, and would behave the same in all other cases as far as I understand. |
4efc754 to
043e966
Compare
|
Just pushed more functionality for this.
Sample Test Case: Original BBCode String: "It's also possible to include [img=24x25]res://unicorn_icon.png[/img] [font_size=24]custom images[/font_size], as well as [color=aqua][url=https://godotengine.org]custom URLs[/url][/color]. [hint=This displays a hint.]Hover this to display a tooltip![/hint]" GDScript recreation Code: Generated BBScript String: "It's also...[img color=ffffffff height=25.0 width=24.0 region=0.0,0.0,0.0,0.0 pad=false tooltip= valign=c,c alt=]res://unicorn_icon.png[/img] [font_size=24]custom images[/font_size]as well as [color=00ffffff][url=https://godotengine.org]custom URLs[/url][/color]. [hint="This displays a hint"]Hover this[/hint]" |
043e966 to
10a49ca
Compare
|
Just pushed a 'finished' build and removed the Draft Flag from this PR. The code should be able to generate correct BBCode for all Items, and in my testing so far it has. Updated the top-level comment with current info/description. |
Adds code for all RichTextLabel Items to generate appropriate BBCode tags for themselves. The RichTextLabel utilizes this behavior to keep a stack of the BBCode generated by push/pop calls without overwriting any user-generated BBCode Text
10a49ca to
076c168
Compare
RichTextLabel's text represent the tag stack
Resolves:
RichTextLabeldocumentation may need to mention thatpush_bbcodedoesn't affecttext#79420textproperty doesn't return actual text #61260Also Resolves:
Implements:
Godot's RichTextLabels parse and convert BBCode Text into a TagStack / ItemTree. Since Godot 4.0 (?), rendering / logic is primarily driven by this Tag Stack / Item Tree; the Text Property exists mostly for inspector convenience, and the occasional hard overwrite via code. This frequently leads to confusion when scripts modify a Label via Add_text and the such, but the changes are not reflected in the Text property. See the 6 open Duplicate Issue reports linked above, and the numerous notes about the text property being out of sync in the RichTextLabel documentation.
This PR seeks to address this issue by having the RichTextLabel update the Text Property as the ItemTree is modified to keep the two in sync. I accomplish this by:
push_*() & pop()calls. Whenever a user interacts with the Text property, they are actually interacting with the concatenation of text + sync_text.internal_stack_editingflag makes it clear when the items being added are not directly from user-written text.I have verified most simple behaviors produce correct BBCode - I may have missed some edge cases, but in the current build, every time I read the Text property it contained exactly the full BBCode I expected, and if I pasted the output back into another RichTextLabel node, they displayed identically.
Existing Behaviors Changed:
Extremely open to feedback - is this the right approach? Is it performant enough? Are there edge cases that keeping Sync_Text does not account for? Should this be pursued at all?