Page 1 of 1

different text alignment in the same field

Posted: Mon Jul 22, 2013 8:58 pm
by SteveTX
Is it possible to have a set of works on line 1 of a field to align left, and the other words on line 1 align right?

Re: different text alignment in the same field

Posted: Mon Jul 22, 2013 9:21 pm
by Simon
Isn't this possible with a <div align> and setting the htmlText of a field?
It's been ages since I did any html

Simon
EDIT: Oh htmlText does not support align

Re: different text alignment in the same field

Posted: Mon Jul 22, 2013 10:11 pm
by dunbarx
Simpler than that.

Set the textAlign of line "yourLine" of fld "yourField" to {left|center|right}

You can mix and match at will.

Craig Newman

Re: different text alignment in the same field

Posted: Mon Jul 22, 2013 11:05 pm
by SteveTX
Craig, I want half the line aligned left, the other half aligned right, not one or the other.

Re: different text alignment in the same field

Posted: Mon Jul 22, 2013 11:09 pm
by Simon
I think you will have to break it into 2 fields.

Simon

Re: different text alignment in the same field

Posted: Mon Jul 22, 2013 11:57 pm
by dunbarx
Hi.

Ah.

This will be more difficult unless you use a monospaced font. But let's say you do, like courier. I did the following just because I was intrigued by your question. I left all the test and development code in my experiment. Not that this is too big a deal. Make a reasonably sized field (field "f9")on a card. Put this into a button script:

Code: Select all

on mouseUp
   put "aaa bbb" & "," & "ccc ddd" into fld "f9"
   put the formattedWidth of line 1 of fld "f9" into wholeWidth
   put the formattedwidth of item 1 of line 1 of fld "f9" into leftWidth
   put the formattedwidth of item 2 of line 1 of fld "f9" into rightWidth
   
   put the width of fld "f9" into fldWidth
   put the length of line 1 of fld "f9" into charWidth
   put  (the width of fld "f9" / the length of line 1 of fld "f9") into charWidth
   put the formattedWidth of char 1 of fld "f9" into charWidth
   put round(the width of fld "f9" / charwidth) into sepWidth
   
   put "leftWidth" && leftWidth into line 3 of fld "f9"
   put "rightWidth" && rightWidth into line 4 of fld "f9"
   put "wholeWidth" && wholewidth into line 5 of fld "f9"
   put "fieldWidth" && the width of fld "f9" into line 6 of fld "f9"
   put "charWidth" & charwidth into line 7 of fld "f9"
   put sepWidth - the length of item 1 of line 1 of fld "f9" - the length of item 2 of line 1 of fld "f9"
   repeat sepWidth - the length of item 1 of line 1 of fld "f9" - the length of item 2 of line 1 of fld "f9" - 2
      put space after separator
   end repeat
   put item 1 of line 1 of fld "f9" & separator &  item 2 of line 1 of fld "f9" into line 9 of fld "f9"
   
end mouseUp
Line 9 contains your separated text. Like I said, I left the test stuff in. If you change the text in the first line on either side of the tab, it works pretty well. Just an example of text massaging.

To do this with a proportional font is much dicier.

EDIT. This was improved a lot over the half hour I first posted.
EDIT. Things go south if your field is not wide enough for the text of interest to sit comfortably on one line.
Craig Newman

Re: different text alignment in the same field

Posted: Wed Jul 24, 2013 1:12 pm
by dunbarx
The process is actually fairly straightforward even with proportional fonts. Since the formattedWidth of each char in any font can be obtained, it is only a matter of creating a lookup table for each character, and looping through the text in question to obtain the total pixel width of each block. The string of spaces (the formattedWidth of the space char can also be determined) can then be assembled and inserted between the blocks as in the previous example.

Craig Newman