Set Center Align in StringGadget : Vertical 'n' Horizontal

Just starting out? Need help? Post your questions and find answers here.
User avatar
Blue
Addict
Addict
Posts: 886
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: Set Center Align in StringGadget : Vertical 'n' Horizont

Post by Blue »

Thank you for your input and interest, RASHAD.
RASHAD wrote:...you are depending on the font Size which can not be perfect
I realize that, but I arrived at that solution by trial and error. No great math theory or understanding behind what I'm doing here. It just works for 99.5% of the cases.
RASHAD wrote:For comparing between StringGadget() 2 & 3 I did not notice any difference
The reason you see no great difference is, of course, because of the corrective padding I apply when re-fitting the StringGadget(). My mistake. Since I wanted you to see the difference, i should have left out the padding entirely.
RASHAD wrote:...please put your Procedures out of the main gui just for me
Sorry, I don't know what you mean here.

But I've re-organized the code in a cleaner way and I've added a checkbox so you can see the difference with/without additional padding.
"That's not a bug..." said the programmer. "it's a feature! "
"Oh! I see..." replied the blind man.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4663
Joined: Sun Apr 12, 2009 6:27 am

Re: Set Center Align in StringGadget : Vertical 'n' Horizont

Post by RASHAD »

For vPadding & hPadding I do the same trial and error
For Procedure staff ,but I will not insist on that :mrgreen:

Code: Select all

Procedure
EndProcedure

Procedure
EndProcedure

LoadFont(0,"Tahoma",14)
OpenWindow(0, 0, 0, 600, 400, "StringGadget ", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
StringGadget(1, 10,10,580,40,"ABCDEJQ")

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow

Egypt my love
User avatar
Blue
Addict
Addict
Posts: 886
Joined: Fri Oct 06, 2006 4:41 am
Location: Canada

Re: Set Center Align in StringGadget : Vertical 'n' Horizont

Post by Blue »

OK, now I understand. :D

In my defense, i had corrected the code before you said anything. But I have a very good excuse for the sloppy posting of last night : it was 3h15 in the morning and I had both eyes in a single hole, looking no further than the tip of my nose.

Thanks RASHAD
Always enlightening to exchange with you.
"That's not a bug..." said the programmer. "it's a feature! "
"Oh! I see..." replied the blind man.
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: Set Center Align in StringGadget : Vertical 'n' Horizont

Post by Thorsten1867 »

StringEx - Module
(I have added a attribute for padding)
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4663
Joined: Sun Apr 12, 2009 6:27 am

Re: Set Center Align in StringGadget : Vertical 'n' Horizont

Post by RASHAD »

Hi Blue
I feel free after you informed me that you are Windows user
Next is what I think it is the proper alignment for StringGadget()

Code: Select all

Global h,w

Procedure CharH(gadget,font , text$)
  hdc = GetDC_(GadgetID(gadget))
  SelectObject_(hdc, FontID(font))
  GetTextMetrics_(hdc, @tm.TEXTMETRIC)
  h = tm\tmHeight + tm\tmInternalLeading + tm\tmExternalLeading
  GetTextExtentPoint32_(hdc , @text$ ,Len(text$),@s.SIZE)
  w = s\cx+tm\tmAveCharWidth
  ReleaseDC_(GadgetID(gadget), hdc)
EndProcedure

LoadFont(0,"Tahoma",14)
text$ = "ABCDEJQ"+" " ;Remember to add a space
OpenWindow(0, 0, 0, 600, 400, "StringGadget ", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
SetWindowColor(0,#White)
StringGadget(1, 10,10,580,40,Text$)
SetGadgetFont(1,FontID(0))
CharH(1,0 ,text$)

ResizeGadget(1,10,10,w,h)

Repeat

Until WaitWindowEvent() = #PB_Event_CloseWindow
Egypt my love
Post Reply