TGUI Forum

General Category => Help requests => Topic started by: r4gTime on 24 May 2020, 17:01:48

Title: ChatBox : Line Spacing and selection
Post by: r4gTime on 24 May 2020, 17:01:48
Hello, I have 2 questions about chatboxes :

1 - Is there any way to change the line spacing ? With the font I use, the line spacing between 2 lines is 0 and the line spacing between two rows of the same line is huge (see attachments)

2 - Is there any way to select text in the chat box in order to copy / paste ?

(Bonus question) How do you remove chatbox background ? With theme only ?

Thanks !
Title: Re: ChatBox : Line Spacing and selection
Post by: texus on 24 May 2020, 17:19:19
1) No, the line spacing is taken from the font. The distance between 2 lines could be controlled by TGUI code, but the distance between two rows on the same line is controlled by SFML. So you will have to use a different font.

When the renderers are changed to no longer use SFML code then this would become possible, but even if this happens then it would still require a rewrite in some parts of the code, so there won't be a fix for this soon.

2) No, ChatBox is read-only. What you are asking for is essentially a RichTextBox, and that widget shouldn't be expected anywhere in the near future (unless someone would contribute it).

Bonus) To remove the background you can call the following:
Title: Re: ChatBox : Line Spacing and selection
Post by: r4gTime on 24 May 2020, 19:04:23
Thank for your reply !

Another cool feature would be to have a different color for the message itself and the name. (because basically you prefer to have a different color for every chatter but the same for the message itself).

A line could be defined by two elements :
- Pseudo (string, color)
- Message (string, color)
The chatbox could as well set the separation symbol (symbol, color) : it could be " : " , " - " or nothing...

I will try to do that someday when I'd figured out how to create classes from other people's library :)
Title: Re: ChatBox : Line Spacing and selection
Post by: texus on 24 May 2020, 19:27:32
If a RichLabel would exist then you would easily be able to build chat box functionality on top of that widget and you would have freedom as to how each line looks. When I created the ChatBox I knew that a RichLabel wasn't going to be added soon (it was too much work), so I ended up writing the ChatBox widget to provide a minimal support for such use cases. Years have passed since then and the situation hasn't really improved: ChatBox is still the only widget with multiple colored texts and RichLabel still isn't expected anywhere soon.

Although adapting the ChatBox to display the name and text in different colors would be easier than implementing a real RichLabel class (that can change its color arbitrarily in the text), it does have similar difficulties. Single lines of texts are easy to render, but to use 2 colors you need to draw each line using up to 3 text objects which have to be carefully positioned (one for the name, one for the remainder of the line and one for other rows if the text doesn't fit on a same row).
This kind of code already exists in TextBox of course (which draws the text in up to 5 parts when multiple lines are selected), but TextBox is one of the most complex classes for a reason.