Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Scrollable chatbox/log box  (Read 3109 times)

0 Members and 2 Guests are viewing this topic.

Jackieryder

  • Newbie
  • *
  • Posts: 15
    • View Profile
    • Email
Scrollable chatbox/log box
« 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

dabbertorres

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • website/blog
Re: Scrollable chatbox/log box
« Reply #1 on: April 23, 2014, 06:08:15 am »
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)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Scrollable chatbox/log box
« Reply #2 on: April 23, 2014, 08:51:33 am »
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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Jackieryder

  • Newbie
  • *
  • Posts: 15
    • View Profile
    • Email
Re: Scrollable chatbox/log box
« Reply #3 on: April 24, 2014, 01:36:31 am »
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
« Last Edit: April 24, 2014, 01:54:33 am by Jackieryder »

dabbertorres

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • website/blog
Re: Scrollable chatbox/log box
« Reply #4 on: April 24, 2014, 02:41:56 am »
Why would that be terrible? It sounds valid to me.

Jackieryder

  • Newbie
  • *
  • Posts: 15
    • View Profile
    • Email
Re: Scrollable chatbox/log box
« Reply #5 on: April 24, 2014, 03:37:13 am »
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

 

anything