SFML community forums
Help => General => Topic started by: Jackieryder on April 23, 2014, 05:52:24 am
-
I'm trying to code a scrollable chatbox which include the up arrow, down arrow, and obviously a scroll inbetween the 2 to scroll the chat. Let put the detail of how I'm going to set up it aside, I'm running into a few problem on how to render the text and doing text wrap to new line.
So far I have in mind is that:
Pseudo code:
class LogMessage
public LogMessage(string msg)
{
CutMessageIntoABunchOfListBasedOnMaximumLength() // this will cut the log message into individual smaller string which is just long enough to fit in a text of the same width.
}
Draw(); // draw all the string in the list of string
I'm not so sure how to code the CutMessageIntoABunchOfListBasedOnMaximumLength at all
is there a specific way to get the amount of character in a string given a font and charactersize and the width?
THis is the first time I ever tried to recreate a scroll chatbox so my structure might be terribly bad, if you have any suggestion on how to code this, please do so
Thank you
-
The '\n' character works fine with sf::Text's. Try it, see how it works for you!
(That's what I did for my in-window terminal)
-
You'll have to check the text for it's length and break when it's too long. Quite a bit of a tedious task, but you could look at how SFGUI does it (https://github.com/TankOs/SFGUI/blob/master/src/SFGUI/Label.cpp#L69).
-
I don't think the SFGUI isn't what I was looking for. I just wanted to be able to create a text field given the width and height, then as I type in any string, it will be wrapped according to the width of the text field.
Musn't there be any other way?
EDIT:
im using SFML.net version and notice that there is a FindCharacterPos(uint index) which apparently return a vector2f of the character at that index. Is there a way to reverse doing this? Like FindPositionCharacter(vector2f loc) which return the index of the character instead
Edit 2:
I guess I could just loop through the string (start at the index 0 of the string) and loop through, add 1 to the i everytime if the FindCharacterPos.X is less than the length. and if it is bigger than the length I could create a new string based off the substring (the index, string.length)
That would work but Imo that is a terrible way of doing it. But since I don't have any other way so while im waiting for a reply im going to test it out
-
Why would that be terrible? It sounds valid to me.
-
Why would that be terrible? It sounds valid to me.
I thought because of the longer the length of the message, the longer it would take to divide it into boxes
But nevermind I was wrong, it work perfectly. What i thought is illogical since no matter what method you use the longer the message the more box is needed to be generated lol.
Yeah nevermind