How do I centre text in StringGadget (OSX)?

Mac OSX specific forum
HarrysLad
User
User
Posts: 57
Joined: Fri Jun 04, 2010 9:29 pm
Location: Sunny Spain

How do I centre text in StringGadget (OSX)?

Post 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
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

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

Post 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!
HarrysLad
User
User
Posts: 57
Joined: Fri Jun 04, 2010 9:29 pm
Location: Sunny Spain

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

Post by HarrysLad »

Thanks for that Keya, wonderful stuff.

ATB
Dave
WilliamL
Addict
Addict
Posts: 1214
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

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

Post 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)
MacBook Pro-M1 (2021), Sonoma 14.3.1 (CLT 15.3), PB 6.10b7 M1
User avatar
Shardik
Addict
Addict
Posts: 1989
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

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

Post 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.
dibor
Enthusiast
Enthusiast
Posts: 125
Joined: Wed May 20, 2020 5:19 pm
Location: The 3rd planet in the Solar System
Contact:

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

Post 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.
:)
Mac Studio M1Max, PB 6.03Arm64 and x64.
Macbook Air M2, PB 6.03Arm64 and x64.
Windows 10, PB 6.03 x64 and x86.
Post Reply