Hello RASHAD.
At first glance, it appears to me like a bug. Am I simply doing something wrong ?
Code: Select all
; source : RASHAD
; https://www.purebasic.fr/english/viewtopic.php?f=12&t=72996&p=537864#p537864
;- constants
Enumeration
#BUTTON_go = 5 : #BUTTON_bye : #font_LABEL : #font_SiZE : #padding_CHOICE
EndEnumeration
Define fontSize = 32
Procedure Three_strings(abc.s)
#minFONT = 6
#maxFONT = 120
Shared fontSize
fontSize = Val(GetGadgetText(#font_SiZE))
If fontSize < #minFONT : fontSize = #minFONT : SetGadgetText(#font_SiZE, Str(#minFONT))
ElseIf fontSize > #maxFONT : fontSize = #maxFONT : SetGadgetText(#font_SiZE, Str(#maxFONT))
EndIf
LoadFont(0,"Tahoma",fontSize)
Protected wPadding, hPadding
If GetGadgetState(#padding_CHOICE)
wPadding = 1 + fontSize*0.6 ; what would be a smarter value here ?
hPadding = wPadding/3
Else
wPadding = 0
hPadding = 2
EndIf
;- 1 ****
StringGadget(1, 10,10,1200,2,ABC)
SetGadgetFont(1,FontID(0))
h = GadgetHeight(1,#PB_Gadget_RequiredSize)
ResizeGadget(1,#PB_Ignore,#PB_Ignore,#PB_Ignore,h+2)
;- 2 ****
#dY = 6
StringGadget(2, 10,GadgetY(1)+h+#dY,2,2,abc)
SetGadgetFont(2,FontID(0))
dummy = TextGadget(#PB_Any,0,0,0,0,abc)
SetGadgetFont(dummy,FontID(0))
h = hPadding + GadgetHeight(dummy, #PB_Gadget_RequiredSize)
w = hPadding + GadgetWidth(dummy, #PB_Gadget_RequiredSize)
FreeGadget(dummy)
ResizeGadget(2,#PB_Ignore,#PB_Ignore,w,h)
;- 3 ****
StringGadget(3, 10,GadgetY(2)+h+#dY,w+wPadding,h,abc)
SetGadgetFont(3,FontID(0))
EndProcedure
OpenWindow(0, 0, 0, 1220, 600, "StringGadget ", #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget)
SetWindowColor(0,#White)
Define gX, gY, gW, gH
gH = 24 : gW = 100
gY = WindowHeight(0) - gH - 10
gX = 10
Define gFont = LoadFont(1,"Arial", 11)
SetGadgetFont(#PB_Default, gFont)
gX = 10
TextGadget(#font_LABEL, gX,gY,gW,gH,"Font size : ", #SS_CENTERIMAGE|#PB_Text_Right)
SetGadgetColor(#font_LABEL, #PB_Gadget_BackColor, #White)
gX + gW
StringGadget(#font_SiZE, gX,gY,48,gH,Str(fontSize), #PB_String_Numeric)
gX + 54 : gW = 175
CheckBoxGadget(#padding_CHOICE, gX,gY,gW,gH,"pad the StringGadgets")
gX + gW + 10 : gW = 100
ButtonGadget(#BUTTON_go, gX,gY,gW,gH,"test it", #PB_Button_Default)
AddKeyboardShortcut(0,#PB_Shortcut_Return, #BUTTON_go)
gX + gW + 10
ButtonGadget(#BUTTON_bye, gX,gY,gW,gH,"Bye Bye !")
Three_strings("ABC pyj_WXYZ")
Repeat
event = WaitWindowEvent()
Select event
Case #PB_Event_CloseWindow : End
Case #PB_Event_Gadget, #PB_Event_Menu
Select EventGadget()
Case #BUTTON_go
Three_strings("ABC pyj_WXYZ")
Case #BUTTON_bye : Break
EndSelect
EndSelect
ForEver
End