Skip to content
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

Make RichTextLabel "Text" property return the whole bbcode text, instead of raw text added from the inspector window #8739

Open
Lucchettinni opened this issue Dec 28, 2023 · 11 comments
Labels
breaks compat Proposal will inevitably break compatibility topic:gui

Comments

@Lucchettinni
Copy link

Describe the project you are working on

Just prototyping

Describe the problem or limitation you are having in your project

So, I'm using a RichTextLabel Node for an online chat I'm prototyping. And I can't sync the content between peers because the "Text" property only syncs raw text written from the inspector window. Anything else I add during run-time with append_text() doesn't get returned. Thus, messages are never in-sync.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

By making the text property return the current bbcode the node is holding at the moment, synchronization would be easier to implement. Besides, people who use this type of node are most likely to use bbcode anyway.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

print( RichTextLabel.text ) <---- Returns the current bbcode either appended and/or written from the inspector window.

RichTextLabel_1.text = RichTextLabel_2.text <------ This should clone the formatted text. Currently it just clones the raw text written from the inspector. If you append_text() and then do that assignment, you will still get the stuff before runtime and not the appended text.

If this enhancement will not be used often, can it be worked around with a few lines of script?

not that I'm aware of? Couldn't find anything on the 4.x docs.

Is there a reason why this should be core and not an add-on in the asset library?

It's a rich text label, clue's on the name. Why does a property that's supposed to return text, doesn't return the text it currently holds. It's insane.

I've seen that in godot 3.x it used to have a property to access the bbcode text. In Godot 4.x it's not mentioned anymore in the documentation. So it's either missing or it was removed. But this should be a core feature for such a node since it's pretty much what it does anyway.

@AThousandShips AThousandShips added topic:gui breaks compat Proposal will inevitably break compatibility labels Dec 29, 2023
@AThousandShips
Copy link
Member

AThousandShips commented Dec 29, 2023

The text not being updated by the oprerations was AFAIK done by design, I think instead there should be a companion method to get_parsed_text to return the raw code instead, that avoids breaking compatibility

See also:

@Lucchettinni
Copy link
Author

There's something I don't understand tho.

If I write text on the inspector (like this)
image_2023-12-29_123204566

And then I try to "clone" the richtextlabel content to another one like this
image
it works without a problem...

However, If I write something at runtime (like this:)
image
and then try to "clone" that content into another richtextlabel node, it doesn't.

it's as if "get_text()" only returns whatever it's on the node before runtime, or at least whatever it was written with the inspector tooltip and not everything else that comes after, while running the scene.

Why doesn't "get_text()" return, well, the node's text?

image

@AThousandShips
Copy link
Member

See the linked issue and discussion 🙂 that's part of the reason behind this

@inhalt120g
Copy link

Why does a property that's supposed to return text, doesn't return the text it currently holds. It's insane.

It's actually really practical when, for example, making a typewriter effect for a textbox and similar. And I assume it's useful for other cases too.

@Calinou Calinou changed the title Make RichTextLabel "Text" property return the whole bbcode text, instead of raw text added from the inspector window. Make RichTextLabel "Text" property return the whole bbcode text, instead of raw text added from the inspector window Jan 3, 2024
@Lucchettinni
Copy link
Author

Why does a property that's supposed to return text, doesn't return the text it currently holds. It's insane.

It's actually really practical when, for example, making a typewriter effect for a textbox and similar. And I assume it's useful for other cases too.

So... Not being able to capture the node's text information at runtime to send it somewhere else, clone it, or manipulate it, is somehow practical... I'm at loss here. I think it may be me just confusing the real use for this node at this point. So I'm just gonna blame it on myself xD

In any case, I figured a way to do what I wanted to do for my prototype.
I'm capturing the whole text history by saving it on an auxiliary variable. Whenever I need to sync text I clear() the client's richtextlabel and appendtext( text_history ) being text_history a variable that holds the whole chat's message history with bbcode included.

Not really practical, since richtextlabel already holds that information. And saving it twice on another variable seems like a waste. But it works for me heh

@kromenak
Copy link

I ran into this myself - and I agree it is "insane" (or at least incredibly unintuitive) that the "get_text" method for a label class doesn't return the text of the label.

Really, just think about the API for this class: functions called "add_text" or "append_text" put text in the label...but "get_text" doesn't return the text that was added. Regardless of the intention behind that, the naming of these functions is misleading and unclear. (Don't get me started on the "clear" function not actually clearing the label...jeez.)

@Lucchettinni
Copy link
Author

I ran into this myself - and I agree it is "insane" (or at least incredibly unintuitive) that the "get_text" method for a label class doesn't return the text of the label.

Really, just think about the API for this class: functions called "add_text" or "append_text" put text in the label...but "get_text" doesn't return the text that was added. Regardless of the intention behind that, the naming of these functions is misleading and unclear. (Don't get me started on the "clear" function not actually clearing the label...jeez.)

I think there are two major issues here. The first one being the naming on that function not explicitly telling the developer what's going to return. But that's not the main issue here. the REAL problem here is the lack of a function for returning plain text as a string. I find it odd that a node that works around text doesn't even have a string getter property or function. Maybe there is, but then again, there's no documentation about it. (It's been 2 months, almost 3 since I've last posted here and I haven't checked since then, so I may be wrong with that last statment)

but in case this goes nowhere and whoever's reading this needs a way to get over this problem, an easy way of doing so is saving the text on an auxiliary variable. It's not pretty at all and not a good practice... but it does the job.

@Calinou
Copy link
Member

Calinou commented Apr 27, 2024

the REAL problem here is the lack of a function for returning plain text as a string.

See #5056.

@NuclearPhoenixx
Copy link

A function like this would've been really helpful for me debugging a RichTextLabel that doesn't behave correctly when doing something like remove_paragraph(0). In general, this would be so helpful for debugging, just to inspect the BBCode to see what's going on. Please tell me there is a function to get that kind of info, it's just not implemented in the get_parsed_text() func.

@andrea-calligaris

This comment was marked as off-topic.

@Calinou
Copy link
Member

Calinou commented Jul 3, 2024

@andrea-calligaris Please don't bump issues without contributing significant new information. Use the 👍 reaction button on the first post instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaks compat Proposal will inevitably break compatibility topic:gui
Projects
None yet
Development

No branches or pull requests

7 participants