text field alignment

Hey guys, i really appreciate that you accept me as part of your beta testers group. I find XOJO very interesting, i am sure that many people will use it more than the xcode.

i have a suggestion for the textfields and labels, why not add a justify alignment option. xcode have something similar, but doesn’t works, it has character wrap, word wrap, but nothing like justify.

I agree that a justify option would be a great feature to have.

For Cocoa target you can do it with declares:

[code]Sub AlignJustified(t as TextArea)

#if TargetCocoa

declare function documentView lib "Cocoa" selector "documentView" (obj_id as Integer) as Ptr
declare sub alignJustified lib "Cocoa" selector "alignJustified:" (obj_id as Ptr, sender as Ptr)

alignJustified(documentView(t.Handle), nil)


#pragma unused t


End Sub

Thanks Massimo.

I have just been testing this and it works fine as long as TextArea.Styled is set to off. If Styled is on, then it doesn’t do anything. Which is consistent with the known bug with TextArea alignment <https://xojo.com/issue/22051>.

Well now I now why …:frowning:
I wasted 1/2 a day trying to get alignment to work (not to mention the docs are wrong to start with)

I can’t remember if this workaround is applicable, but there’s some bug with alignment that can be dealt with by setting the alignment at runtime instead of in the form editor. I’m not saying it shouldn’t be fixed, just that there might be a workaround.

Thanks… but that won’t work as it is a “tiny” text editor where the user needs to decide what the text looks like and how/if it is aligned other than “left”…

And unless I do something super kludgy… this might delay deployment of this project … as for me this is a show stopper

Okay, at the risk of sounding dense, let me try to recap what your situation is:

  1. You’re using the Cocoa framework with 2013r1.
  2. You’re using a TextArea with the Styled property set to True.
  3. You’re trying to align all of the text, not just the selection, to be center, right, etc.

Is that correct?

1 and 2 are true
3 is False

I want to align the selected “paragraph”

this is an example of what I expect to be able to do

[quote=15316:@Dave S]1 and 2 are true
3 is False

I want to align the selected “paragraph”[/quote]

Have you tried SelAlignment? That sounds like what you really want.

yes… and neither seem to work

here the code the is called from the toolbar in the image above

  Dim p As Integer
  Dim i As Integer
  Dim ss As Integer
  ' get paragraph # 
  For i=0 To TextArea1.StyledText.ParagraphCount
    If ss>=TextArea1.StyledText.Paragraph(i).StartPos Then p=i
  Next i
  Select Case btn.Tag
  Case cmd_TXTBOLD
    textarea1.SelBold=Not textarea1.SelBold
  Case cmd_TXTITALIC
    textarea1.SelItalic=Not textarea1.SelItalic
  Case cmd_TXTUNDER
    textarea1.SelUnderline=Not textarea1.SelUnderline
  Case cmd_TXTLEFT
  Case cmd_TXTCENTER
  Case cmd_TXTRIGHT
  Case Else
    myMsgBox "Warning [W02]^btn="+btn.tag,32
  End Select

Perhaps I found the problem…

My edit box above uses a CLONE of the styled text, and when done puts the Editted cloned data back into the orignal ST object

Originally I was cloning via StyleRuns (see another recent post about this)

So I changed the clone code to be



Master.RTFData = \uc0 \ql\f0\fs20 Enter Text Here\par \qc b\par \ql c
Clone.RTFData = \uc0 \ql\f0\fs20 Enter Text Here\par b\par c

Note the \qc and \ql got dropped during the assignment (qc=align center)

This thread is old. But maybe this could help others who find it.

The following code from Dave S cannot work:

It gives 0 every time.

It should be <=TextArea1.StyledText.Paragraph(i).EndPos !!!

I also had to consider that the paragraphs stuff only works with English Keyboard.
For international characters I had to write a workaround.
This was discussed in 2011 in:
There also seemed to be a bug report as Markus Winter wrote:
But nothing seems to change as I tested with Xojo 2015r4 now.

FWIW Axel Schneider posted 8 months ago a subclass of TextArea for OS X which supports styled justification through declares.