Page 2 of 2

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

Posted: Wed Jun 12, 2019 4:36 pm
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.

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

Posted: Wed Jun 12, 2019 5:21 pm
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


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

Posted: Wed Jun 12, 2019 5:27 pm
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.

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

Posted: Wed Jun 12, 2019 6:04 pm
by Thorsten1867
StringEx - Module
(I have added a attribute for padding)

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

Posted: Wed Jun 12, 2019 6:28 pm
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