Hi.
Currently im able to render bitmapped text in straight line using a for loop. But now I need to implement text wrapping inside a rectangle.
Both immediate mode and retained mode solutions are welcome.
Regards
How to implement Text Wrapping in my Custom GUI
-
- Gnoblar
- Posts: 12
- Joined: Tue Mar 08, 2011 11:36 am
-
- Gremlin
- Posts: 154
- Joined: Fri Jun 24, 2011 3:50 am
- Location: 192.168.0.1
- x 3
Re: How to implement Text Wrapping in my Custom GUI
That depends on how your for loop works. The way I understand your post, you place letters at a certain x coordinate relative to the last letter placed, and you loop over a char* or something like that.
If that's the case, either the letters would have to be the same x width or you would have to at the very least keep track of the right edge of the letter. What you could do is just have your algorithm have access to the x width of whatever rectangle this is (sorry I can't be more specific, I am not familiar with your code structure) and increment the y coordinate to place the text on whenever the right bound of the letter crosses that line.
Now that's rudamentary. If you come to the end of the line in the middle of the word it would take the next letter to the next line. You could get more advanced by saving a char[] that buffers the next word's worth (use stdlib.h and string.h if c/c++ if you want it simpler, otherwise nested for()s could get the job done), and calculate the needed length of the word. You could then loop through word by word, looping each word letter by letter in nested for()s.
I hope this helps. Your post was very unspecific. If you can provide more information, I'm sure I could be more helpful.
If that's the case, either the letters would have to be the same x width or you would have to at the very least keep track of the right edge of the letter. What you could do is just have your algorithm have access to the x width of whatever rectangle this is (sorry I can't be more specific, I am not familiar with your code structure) and increment the y coordinate to place the text on whenever the right bound of the letter crosses that line.
Now that's rudamentary. If you come to the end of the line in the middle of the word it would take the next letter to the next line. You could get more advanced by saving a char[] that buffers the next word's worth (use stdlib.h and string.h if c/c++ if you want it simpler, otherwise nested for()s could get the job done), and calculate the needed length of the word. You could then loop through word by word, looping each word letter by letter in nested for()s.
I hope this helps. Your post was very unspecific. If you can provide more information, I'm sure I could be more helpful.
Sass not tolerated
LAY DOWN THE LAW!
When I don't understand a problem, I punch it in the face and try again.
LAY DOWN THE LAW!
When I don't understand a problem, I punch it in the face and try again.