Simple TextGadget with centered Hal & Val text

Share your advanced PureBasic knowledge/code with the community.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4659
Joined: Sun Apr 12, 2009 6:27 am

Simple TextGadget with centered Hal & Val text

Post 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
Egypt my love
jack
Addict
Addict
Posts: 1336
Joined: Fri Apr 25, 2003 11:10 pm

Re: Simple TextGadget with centered Hal & Val text

Post by jack »

thank you RASHAD :)
works ok on my Mac
User avatar
VB6_to_PBx
Enthusiast
Enthusiast
Posts: 625
Joined: Mon May 09, 2011 9:36 am

Re: Simple TextGadget with centered Hal & Val text

Post by VB6_to_PBx »

thanks RASHAD !!!
works perfectly .
 
PureBasic .... making tiny electrons do what you want !

"With every mistake we must surely be learning" - George Harrison
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Simple TextGadget with centered Hal & Val text

Post 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
DE AA EB
Mesa
Enthusiast
Enthusiast
Posts: 349
Joined: Fri Feb 24, 2012 10:19 am

Re: Simple TextGadget with centered Hal & Val text

Post by Mesa »

Excellent, but it doesn't work with very big font, like LoadFont(0,"Tahoma",38), on my MSwindows.

M.
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: Simple TextGadget with centered Hal & Val text

Post 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
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4659
Joined: Sun Apr 12, 2009 6:27 am

Re: Simple TextGadget with centered Hal & Val text

Post 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
Egypt my love
Mesa
Enthusiast
Enthusiast
Posts: 349
Joined: Fri Feb 24, 2012 10:19 am

Re: Simple TextGadget with centered Hal & Val text

Post by Mesa »

Thanks a lot Rashad, it's perfect.

M.
Post Reply