Page 1 of 1

How do I centre text in StringGadget (OSX)?

Posted: Mon Aug 01, 2016 2:50 pm
by HarrysLad
The Windows version of the PureBasic compiler accepts #PB_Text_Center or #PB_Text_Right flags to justify the text to the centre or right position respectively - much like the TextGadget counterpart - although this behaviour seems to be undocumented.
This fails under OSX though. i.e.,
applying the #PB_Text_Center flag leaves justification as left-hand and makes the StringGadget un-selectable whereas the #PB_Text_Right flag still leaves the justification as left-hand and puts the StringGadget into 'password' mode. :shock:

Can anyone suggest how to make the StringGadget display right-justification or - more critically - centre-justification?

TIA
Dave

Re: How do I centre text in StringGadget (OSX)?

Posted: Mon Aug 01, 2016 2:53 pm
by Keya
try

Code: Select all

CocoaMessage(0, GadgetID(mygadget), "setAlignment:", 2)
This fails under OSX though. i.e.,
applying the #PB_Text_Center flag leaves justification as left-hand and makes the StringGadget un-selectable whereas the #PB_Text_Right flag still leaves the justification as left-hand and puts the StringGadget into 'password' mode.
btw i just had a look at those controls in the Form Designer on 5.42LTS x64 OSX ...
- the Editor gadget doesn't have any checkboxes for alignment
- the String gadget doesn't have any checkboxes for alignment
- the Text/label gadget does have alignment, and when i tried the Centered one it worked fine
so I'm not too sure which OSX controls actually support alignments, but that CocoaMessage seemed fine last time i tested it!

Re: How do I centre text in StringGadget (OSX)?

Posted: Mon Aug 01, 2016 3:17 pm
by HarrysLad
Thanks for that Keya, wonderful stuff.

ATB
Dave

Re: How do I centre text in StringGadget (OSX)?

Posted: Mon Aug 01, 2016 5:04 pm
by WilliamL
http://www.purebasic.fr/english/viewtop ... 31#p390031

Code: Select all

;set string gadget to right-justified
    #NSRightTextAlignment = 1 ; for right align string gadget
    CocoaMessage(0,GadgetID(2),"setAlignment:", #NSRightTextAlignment)

Re: How do I centre text in StringGadget (OSX)?

Posted: Tue Aug 02, 2016 7:31 am
by Shardik
You may also take a look into this cross-platform example which demonstrates how to right-justify text in a StringGadget and which is also listed in my collection of cross-platform examples.

Re: How do I centre text in StringGadget (OSX)?

Posted: Sat Nov 11, 2023 6:44 pm
by dibor
Hello.
Tnx for the trick.
But on latest Mac OS

Code: Select all

CocoaMessage(0, GadgetID(mygadget), "setAlignment:", 1) ; - for Center align.
CocoaMessage(0, GadgetID(mygadget), "setAlignment:", 2) ; - for right align.
:)