tags:

views:

43

answers:

2

I'm making a game gui api and I'm wondering how to implement tabs. I'm using freetype for text. When I try to render '\t' It looks like a square. I'm wondering how tabs are implemented because they are not a fixed width.

Thanks

A: 

The simplest strategy is to swap a tab out for a some number of spaces. I.e. when the user pushes tab, pretend they pushed tab four times instead. (Or just print out four spaces, whatever works for you)

Winston Ewert
But when they press backspace how do I know how many to remove?
Milo
If the last character is '\t', remove last 4 characters (if the first 3 '\t's cannot be selected)
irrelephant
alright thanks.
Milo
+2  A: 

For a fixed-width font you could compute how many spaces to the next tab stop, but the general solution is to stop rendering when you hit a tab, move to the next tabstop, and then render the text that comes after the tab character starting from there. Where the tabstops are is up to you, but a good default is probably something like every 8 ems.

Laurence Gonsalves