Textarea tab widths "broken"

BlitzMax Forums/MaxGUI Module/Textarea tab widths "broken"

Mark Tiffany(Posted 2007) [#1]
This definitely applies to win32, not sure about other platforms.

Currently, maxgui textarea tab widths are set to a set number of PIXELS, not a set number of CHARACTERS. This is contrary to expectations, and results in the bug illustrated by the example below: when changing font size, the overall layout of text with tabs should remain the same, but it does not.



I've tracked this down to win32textarea2.cpp, but my limited C++ skills fail me. I believe the culprit to be the hard coded 8 in the code below when calculating TWIPS. This figure should be the width of the gadget's font.


It will probably also be necessary to ensure that this method gets called when the font is changed, in order to ensure that the tabs are correctly sited.

It is arguable that current behaviour is useful (e.g. if using a variable width font?), maybe a little extra logic, or an option on SetTextAreaTabs is in order?


skidracer(Posted 2007) [#2]
Currently, maxgui textarea tab widths are set to a set number of PIXELS


Sorry, I don't see how this is a bug.

Tabs are pixel based, if you want them to be based on font size then there is nothing stopping you setting the tab size to something based on the current font size when you set the font from the confines of your own app.


Mark Tiffany(Posted 2007) [#3]
TBH, I wasn't sure: my natural instinct is that tabs are a number of characters. You're absolutely right though, I can make it behave how *I* want it to by setting the tab size based on the font width.

So, maybe not a bug, but how about updating the docs for it to make this clear?


Brucey(Posted 2007) [#4]
um... did you say that tab size is not the number of characters? Like, if I set the tab size to 4, it won't be 4 characters wide, but only 4 pixels?

Or am I missing something?

Cuz using my assumption, I've coded both my GUI modules to have tabsize work on 4 tab spaces = 4 characters. (I resize the actual tabsize (in pixels) based on the current font for the textarea...

:-(


Mark Tiffany(Posted 2007) [#5]
Yup Brucey, that's what *I* expected it to do. But it doesn't (at least on win32, but from what skid says, everywhere else), the tabs always keep the same screen size. Try the example above and you'll see it happening if you select one of the tabs in the textbox.

I think what skid's saying is right for proportional fonts. I think you do want the tab size to be based on a screen size, and for that size to be fixed and not vary with font size. It's a bit more questionable for fixed width fonts, but probably stil correct.

I think the ideal would be to be able to choose whether it is working in pixels, or in characters. At the moment, it's neither! If I set it to 4, I get an approx 30-40 pixel wide tab. So what does "4" mean?

I'd personally like to see a SetTextAreaTabs size , format option, where I can specify if the tab is based on pixels, or characters. However, I can work around this by setting the tab size based on the current font width (and multiplying it by some magic number, yet to be determined).


Brucey(Posted 2007) [#6]
Heh... for Qt I had to divide the font "pixelSize" by something like 1.7 and multiply that value by the requested Tab size to get something that looked right...

On GTK I had to jump through some hoops, multiplying the font size by 1024 (and then multiplying that number by the tab size) !!

At the end of the day, I suppose it all *looks* kind of similar. I guess it depends on how exact you need it to be??

..or you just make it up as you go ;-)


Mark Tiffany(Posted 2007) [#7]
At the end of the day, I suppose it all *looks* kind of similar. I guess it depends on how exact you need it to be??

Try my sample code in the first post. That's why it needs to be based on the font width, else your code formatting spews!


Mark Tiffany(Posted 2007) [#8]
Arghhh, the font width isn't exposed by BlitzMax!

I tried exposing the win32 width, but it didn't seem to vary at all when I changed font sizes in the above code, and hence doesn't help. It almost seems like the code is half there for exposing the font width...

Therefore, mr skidracer, I am still unable to set up tabs that are a fixed number of characters (like what you actually want in an IDE). Any chance you could sort out fontwidth? Pretty please? ;-)