SFML community forums

Help => General => Topic started by: drakelord on July 09, 2009, 09:25:12 pm

Title: Editable textboxes and you~
Post by: drakelord on July 09, 2009, 09:25:12 pm
This isn't so much of a "I don't know how to do it" thread as it is more of a general discussion thread regarding this subject.

I currently have a textbox, that is selectable, and editable.  This part is cake.  But for the next part, I do not know enough about SFML itself yet to determine the most optimal route.

1)  Displaying the flashing | glyph at the edit point.
The only way I know to do this right now with SFML is to calculate the width of each individual character and how far it is in, and place it inbetween the two characters manually.  Annoying in a way.  

2)  Being able to set an edit point by clicking in the middle of a textbox somewhere.
Once again, this goes back to the previous situation.  I can manually calculate the position on the screen, the width of each character, and determine if the spot is within the string... but it seems like a pain in the arse, ;)

Is there an easier way that this can be done?
Title: Editable textboxes and you~
Post by: Laurent on July 09, 2009, 10:09:41 pm
You can use sf::String::GetCharacterPos for both problems.
Title: Editable textboxes and you~
Post by: drakelord on July 10, 2009, 01:04:41 am
I'm going to assume that GetCharacterPos() returns the top-left position of the character as other get position functions defaults to?

IE, if I set the string position as 100 px by 60 px, then go to the 3rd character, the returned position will be 100 + some number by 60px?

EDIT:  Also, I see in the documentation that it doesn't not apply scale.  So does that mean if the string is scaled down 50%, that it will still return the position as if it were not scaled at all?
Title: Editable textboxes and you~
Post by: venomj on July 10, 2009, 04:47:20 am
I got the same problems when I made a small gui lib before.
I don't think there's another way around.
You need to do the work yourself.
Title: Editable textboxes and you~
Post by: Laurent on July 10, 2009, 07:40:16 am
Quote
I'm going to assume that GetCharacterPos() returns the top-left position of the character as other get position functions defaults to?

Probably. Or the left-baseline position, I don't remember :lol:

Quote
IE, if I set the string position as 100 px by 60 px, then go to the 3rd character, the returned position will be 100 + some number by 60px?

EDIT: Also, I see in the documentation that it doesn't not apply scale. So does that mean if the string is scaled down 50%, that it will still return the position as if it were not scaled at all?

The point returned is in local coordinates, and you can easily get global coordinates using String::TransformToGlobal.
Title: Editable textboxes and you~
Post by: Andershizzle on September 06, 2009, 08:30:10 pm
Mind postin up your code for your textbox? :D