Hi.
Is it possible under OSX to vertically center text in a text gadget? Horizontal centering is handled by #PB_Text_Center, but if I change the font from the default and increase its size, the vertical centering is off (it is too high), making the display not quite perfect.
Any thoughts? Ideally something cross-platform would be great but I suspect this will be platform specific.
Thanks .. mark.
Text Gadget --- Vertical Center?
Re: Text Gadget --- Vertical Center?
It may be the best to center the gadget yourself inside a container gadget (resize the Window to see it):
Works also with StringGadget:
Code: Select all
Procedure OnResize()
ResizeGadget(0,0,0,WindowWidth(0),WindowHeight(0))
ResizeGadget(1,GadgetWidth(0)*0.5 - GadgetWidth(1)*0.5,
GadgetHeight(0)*0.5 - GadgetHeight(1)*0.5,#PB_Ignore,#PB_Ignore)
EndProcedure
If OpenWindow(0, 0, 0, 800, 600, "TextGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
ContainerGadget(0,0,0,800,600)
TextGadget(1, 0, 0, 0, 0, "TextGadget Center"+#CRLF$+"Line 2",#PB_Text_Center)
CloseGadgetList()
SetGadgetFont(1,LoadFont(0,"Arial",48))
CocoaMessage(0, GadgetID(1), "sizeToFit")
ResizeGadget(1,GadgetWidth(0)*0.5 - GadgetWidth(1)*0.5,
GadgetHeight(0)*0.5 - GadgetHeight(1)*0.5,#PB_Ignore,#PB_Ignore)
BindEvent(#PB_Event_SizeWindow,@OnResize(),0)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Code: Select all
Procedure OnResize()
ResizeGadget(0,0,0,WindowWidth(0),WindowHeight(0))
ResizeGadget(1,GadgetWidth(0)*0.5 - GadgetWidth(1)*0.5,
GadgetHeight(0)*0.5 - GadgetHeight(1)*0.5,#PB_Ignore,#PB_Ignore)
EndProcedure
Procedure OnStringChanged()
CocoaMessage(0, GadgetID(1), "sizeToFit")
ResizeGadget(1,GadgetWidth(0)*0.5 - GadgetWidth(1)*0.5,
GadgetHeight(0)*0.5 - GadgetHeight(1)*0.5,#PB_Ignore,#PB_Ignore)
EndProcedure
If OpenWindow(0, 0, 0, 800, 600, "StringGadget AutoFit", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
ContainerGadget(0,0,0,800,600)
StringGadget(1, 0, 0, 0, 0, "StringGadget Center")
CloseGadgetList()
SetGadgetFont(1,LoadFont(0,"Arial",48))
CocoaMessage(0, GadgetID(1), "sizeToFit")
ResizeGadget(1,GadgetWidth(0)*0.5 - GadgetWidth(1)*0.5,
GadgetHeight(0)*0.5 - GadgetHeight(1)*0.5,#PB_Ignore,#PB_Ignore)
BindGadgetEvent(1,@OnStringChanged(),#PB_EventType_Change)
BindEvent(#PB_Event_SizeWindow,@OnResize(),0)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Re: Text Gadget --- Vertical Center?
Many thanks, Danilo, I'll check it out.Danilo wrote:It may be the best to center the gadget yourself inside a container gadget (resize the Window to see it)
.. mark.