Page 1 of 1

Simple TextGadget with centered Hal & Val text

Posted: Wed Sep 20, 2017 11:27 pm
by RASHAD
- Any font size
- Single or Multi line
- Cross Platform (not tested :) )
I have a feeling that I am not the first one :P
I like PB it has a lot of tools you can craft with it almost any thing

Code: Select all

 LoadFont(0,"Tahoma",14)
  If OpenWindow(0, 0, 0, 270, 160, "TextGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ContainerGadget(0,10,10,250,100,#PB_Container_Flat)
      TextGadget(1, 0,  0, 250, 60, "TextGadget Center"+#CRLF$+"Second Line", #PB_Text_Center)
    CloseGadgetList()
    HideGadget(0,1)
    SetGadgetFont(1,FontID(0))    
    SetGadgetColor( 0,#PB_Gadget_BackColor,$D0FEFE)
    SetGadgetColor( 1,#PB_Gadget_BackColor,$D0FEFE)
    SetGadgetColor( 1,#PB_Gadget_FrontColor,$2128FE)   
    th = GadgetHeight(1,#PB_Gadget_RequiredSize)
    dth = GadgetHeight(0)/2 - th/2
    ResizeGadget(1,0,dth,250,th)
    HideGadget(0,0)
    
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
  EndIf

Re: Simple TextGadget with centered Hal & Val text

Posted: Wed Sep 20, 2017 11:49 pm
by jack
thank you RASHAD :)
works ok on my Mac

Re: Simple TextGadget with centered Hal & Val text

Posted: Thu Sep 21, 2017 3:50 am
by VB6_to_PBx
thanks RASHAD !!!
works perfectly .

Re: Simple TextGadget with centered Hal & Val text

Posted: Thu Sep 21, 2017 7:07 am
by davido
@RASHAD,
Exellent!
Very clever use of an existing function.
Now all my ugly text gadgets can be transformed, as if by magic!
Thank you :D

Re: Simple TextGadget with centered Hal & Val text

Posted: Thu Sep 21, 2017 8:55 am
by Mesa
Excellent, but it doesn't work with very big font, like LoadFont(0,"Tahoma",38), on my MSwindows.

M.

Re: Simple TextGadget with centered Hal & Val text

Posted: Thu Sep 21, 2017 9:40 am
by walbus
@Mesa
This works ever, you must only make the gadgets larger
So you should making a procedure for the functions call
Also its available for searching the largest output line with StringField() and TextWidth(), then auto resizing the boxes
The same for the needed hight and other little cosmetic, as sample a automatic font size dependent distance to the edges
This are simple stepps
Is it needed, i think, RASHAD add this and that

Re: Simple TextGadget with centered Hal & Val text

Posted: Thu Sep 21, 2017 12:17 pm
by RASHAD
Tanks guys
Sorry Mesa
Revised version

Code: Select all

LoadFont(0,"Georgia",64)
 padw = 30  ;Hal padding
 padh = 10  ;Val padding
 
If OpenWindow(0, 0, 0, 0, 0, "TextGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ContainerGadget(0,10,10,10,10,#PB_Container_Flat)
    TextGadget(1, 0,  0, 0, 0, "TextGadget Center"+#CRLF$+"Second Line", #PB_Text_Center)
  CloseGadgetList()
  HideGadget(0,1)
  SetGadgetFont(1,FontID(0))
  gw = GadgetWidth(1,#PB_Gadget_RequiredSize)
  gh = GadgetHeight(1,#PB_Gadget_RequiredSize)   
  SetGadgetColor( 0,#PB_Gadget_BackColor,$D0FEFE)
  SetGadgetColor( 1,#PB_Gadget_BackColor,$D0FEFE)
  SetGadgetColor( 1,#PB_Gadget_FrontColor,$2128FE)
  ResizeWindow(0,0,0,gw+padw*2+20,gh+padh*2+20)
  HideWindow(0,0,#PB_Window_ScreenCentered)
  ResizeGadget(0,10,10,gw+padw*2,gh+padh*2)
  ResizeGadget(1,0,padh,gw+padw*2,gh)
  HideGadget(0,0)
 
  Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

Re: Simple TextGadget with centered Hal & Val text

Posted: Fri Sep 22, 2017 9:26 am
by Mesa
Thanks a lot Rashad, it's perfect.

M.