SetTextAlignment for label - test 1
BlitzMax Forums/MaxGUI Module/SetTextAlignment for label - test 1
| ||
| Hi I've made some changes to MaxGUI to change the label-text alignment. In MaxGUI.bmx Rem bbdoc: Set Alignment of the text End Rem Function SetGadgetAlignment(gadget:tgadget,alignment:Int) gadget.SetAlignment alignment End Function This is to add in FLTKGUI.bmx in the type Type TFLLabel Extends TFLGadget Method SetAlignment(_align:Int) Local tmpAlignment = FL_ALIGN_WRAP|FL_ALIGN_INSIDE|FL_ALIGN_CLIP Select _align Case LABEL_LEFT tmpAlignment:|FL_ALIGN_LEFT Case LABEL_CENTER tmpAlignment:|FL_ALIGN_CENTER Case LABEL_RIGHT tmpAlignment:|FL_ALIGN_RIGHT EndSelect flSetAlign WidgetHandle(),tmpAlignment Redraw() End Method I'm working on the Win32 version, but I'm at a dead point... This is in Win32MaxGUIEx.bmx in the type Type TWindowsLabel Extends TWindowsGadget Method SetAlignment(_align:Int) Local wstyle:Int wstyle=WS_CHILD|SS_NOPREFIX|WS_CLIPSIBLINGS|SS_NOTIFY Select _align&24 Case LABEL_LEFT wstyle:|SS_LEFT Case LABEL_RIGHT wstyle:|SS_RIGHT Case LABEL_CENTER wstyle:|SS_CENTER End Select SendMessageW _hwnd,WM_SETTEXT,0,wstyle End Method this is a working example (tested with FLTK under win32)
' createwindow.bmx
' on FLTK (tested Win32) is OK
Import MaxGui.FLTKMaxGUI
'Import maxgui.drivers
SuperStrict
Local window:TGadget = CreateWindow( "Test alignment", 100, 100, 320, 240, Null, WINDOW_TITLEBAR|WINDOW_CENTER )
Local lbl:tgadget=CreateLabel("test",10,10,300,20,window,LABEL_SUNKENFRAME)
SetGadgetAlignment lbl,LABEL_center
Local btn_left:tgadget=CreateButton("left" ,5,50,100,20,window)
Local btn_center:tgadget=CreateButton("center" ,110,50,100,20,window)
Local btn_right:tgadget=CreateButton("right" ,215,50,100,20,window)
Repeat
WaitEvent()
Select EventID()
Case EVENT_GADGETACTION
Select EventSource()
Case btn_left
SetGadgetAlignment lbl,LABEL_LEFT
Print "LEFT"
Case btn_CENTER
SetGadgetAlignment lbl,LABEL_CENTER
Print "CENTER"
Case btn_RIGHT
SetGadgetAlignment lbl,LABEL_RIGHT
Print "RIGHT"
End Select
Case EVENT_APPTERMINATE, EVENT_WINDOWCLOSE
End
End Select
Forever
PS: the name SetGadgetAlignment is not very intelligent... maybe SetLabelAlignment ? |
| ||
| Isn't this already supported? |
| ||
| Really? How do you change a text alignment in a label? I missed something during all this time? |
| ||
| Won't this function do it? CreateLabel:TGadget( name$,x,y,w,h,group:TGadget,style=LABEL_LEFT) |
| ||
| I think degac meant to change the alignment after the creation, because there is no command yet. |
| ||
| I'm guessing you should be using GetWindowLong() and SetWindowLong instead of the SendMessage call, if that's any help. |
| ||
| @Seb: thanks for the advice. |
| ||
Ok, after some test for win32 MaxGUI I've got thisMethod SetAlignment(_align:Int) Desensitize() 'Local wstyle:Int 'wstyle=WS_CHILD|SS_NOPREFIX|WS_CLIPSIBLINGS|SS_NOTIFY Local style = GetWindowLongW(_hwnd, GWL_STYLE) 'style=style~SS_LEFT~SS_RIGHT~SS_CENTER Select _align&24 Case LABEL_LEFT style:|SS_LEFT Case LABEL_RIGHT style:|SS_RIGHT Case LABEL_CENTER style:|SS_CENTER End Select SetWindowLongW(_hwnd, GWL_STYLE, style) Sensitize() End Method This code works only the first time... I suspect I need to 'remove' some previous style but nothing seems to happen. If anyone know the solutions... |
| ||
style=style~SS_LEFT~SS_RIGHT~SS_CENTER That looks like it should do it. |
| ||
| style=style~SS_LEFT~SS_RIGHT~SS_CENTER I'm not entirely sure what you're trying to do here, but... style:&~(SS_LEFT|SS_RIGHT|SS_CENTER)...is what you need if you want to remove all the flags before you set the new one. :-) |
| ||
| Hurra! Thanks anyone very much! Here the final code for Win32 SetTextAlignment Method SetAlignment(_align:Int) Local style = GetWindowLongW(_hwnd, GWL_STYLE) style:&~(SS_LEFT|SS_RIGHT|SS_CENTER) Select _align&24 Case LABEL_LEFT style:|SS_LEFT Case LABEL_RIGHT style:|SS_RIGHT Case LABEL_CENTER style:|SS_CENTER End Select SetWindowLongW(_hwnd, GWL_STYLE, style) RedrawGadget(Self) End Method I discovered I need to use RedrawGadget() to see the effects. Well, another platform gone, next target MacOS-Aqua. |