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?
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.
Local w:TGadget=CreateWindow("test textarea",100,100,500,300) Local ta:TGadget=CreateTextArea(0,0,500,150,w) Local b:TGadget = CreateButton("Size = 8" , 0 , 150 , 100 ,50 , w) Local b2:TGadget = CreateButton("Size = 12" , 150 , 150 , 100 , 50 , w) Local b3:TGadget = CreateButton("Tabsize = 4", 300 , 150, 100,50,w) f:TGUIFont=LoadGuiFont("Courier New",12) f2:TGUIFont=LoadGuiFont("Courier New",8) SetTextAreaFont ta , f SetTextAreaText ta , "Const TOOLRESET:Int=~t~t0~nConst TOOLSHOW:Int=~t~t1~nConst TOOLREFRESH:Int=~t~t2~nConst TOOLNEW:Int=~t~t3~nConst TOOLOPEN:Int=~t~t4~nConst TOOLCLOSE:Int=~t~t5" Repeat WaitEvent() Select EventSource() Case b ; SetTextAreaFont ta , f2 Case b2 ; SetTextAreaFont ta , f Case b3 ; SetTextAreaTabs ta , 4 Case w If EventID()=EVENT_WINDOWCLOSE Then End End Select Forever End
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.
void Win32TextArea::setTabs( int tabs ){ BBFont *bbf ; int tabTwips = 1440*8/ GetDeviceCaps( GetDC(0) , LOGPIXELSX ) * tabs ; PARAFORMAT pf={sizeof(pf)}; pf.dwMask=PFM_TABSTOPS; pf.cTabCount=MAX_TAB_STOPS; for( int k=0;k<MAX_TAB_STOPS;++k ) pf.rgxTabs[k]=k*tabTwips; lockAll(); SendMessage( _gadget.hwnd(),EM_SETPARAFORMAT,0,(LPARAM)&pf ); unlock(); }
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?