Hi PB. Here's a simple workaround which can be instantiated in the same way as a standard
Code: Select all
Procedure cTextGadget(gNo, x, y, width, height, text.s, flags = 0)
sFont = FontID(LoadFont(#PB_Any, "Arial", 11))
uFont = FontID(LoadFont(#PB_Any, "Arial", 11, #PB_Font_Underline))
If flags => #PB_Text_Border And flags <= #PB_Text_Border | #PB_Text_Right
border = 1
borderOffset = 4
EndIf
CanvasGadget(gNo, x, y, width, height, border)
StartDrawing(CanvasOutput(gNo))
Box(0, 0, width, height, RGB(200, 220, 240))
DrawingMode(#PB_2DDrawing_Transparent)
DrawingFont(sFont)
x = 0: y = 0
textOffset = width - TextWidth(RemoveString(text, "&")) - borderOffset
If flags = #PB_Text_Center Or flags = #PB_Text_Border | #PB_Text_Center
x = textOffset / 2
ElseIf flags = #PB_Text_Right Or flags = #PB_Text_Border | #PB_Text_Right
x = textOffset
EndIf
For drawLoop = 1 To Len(text)
If Mid(text, drawLoop, 1) = "&"
drawLoop + 1
DrawingFont(uFont)
Else
DrawingFont(sFont)
EndIf
x = DrawText(x, y, Mid(text, drawLoop, 1), RGB(0, 0, 100))
Next drawLoop
StopDrawing()
EndProcedure
wFlags = #PB_Window_SystemMenu | #PB_Window_ScreenCentered
OpenWindow(0, 0, 0, 250, 500, "Custom TextGadget()", wFlags)
SetWindowColor(0, RGB(255, 255, 255))
cTextGadget(1, 10, 10, 230, 30, "&Custom TextGadget()")
TextGadget(2, 10, 50, 230, 30, "&Standard TextGadget()")
tbFlags = #PB_Text_Center
text.s = "Centered &Text"
cTextGadget(3, 10, 90, 230, 30, text, tbFlags)
TextGadget(4, 10, 130, 230, 30, text, tbFlags)
tbFlags = #PB_Text_Right
text = "Right-&Aligned Text"
cTextGadget(5, 10, 170, 230, 30, text, tbFlags)
TextGadget(6, 10, 210, 230, 30, text, tbFlags)
tbFlags = #PB_Text_Border
text = "TextGadget with &Border"
cTextGadget(7, 10, 250, 230, 30, text, tbFlags)
TextGadget(8, 10, 290, 230, 30, text, tbFlags)
tbFlags = #PB_Text_Center | #PB_Text_Border
text = "&Centered Text with Border"
cTextGadget(9, 10, 330, 230, 30, text, tbFlags)
TextGadget(10, 10, 370, 230, 30, text, tbFlags)
tbFlags = #PB_Text_Right | #PB_Text_Border
text = "&Right-Aligned Text with Border"
cTextGadget(11, 10, 410, 230, 30, text, tbFlags)
TextGadget(12, 10, 450, 230, 30, text, tbFlags)
sFont = FontID(LoadFont(#PB_Any, "Arial", 11))
For setFont = 2 To 12 Step 2
SetGadgetFont(setFont, sFont)
Next setFont
While WaitWindowEvent() ! #PB_Event_CloseWindow : Wend
function is fully encapsulated and can be implemented right out of the box. Hope it helps.