Align baselines of 2 fields

classic Classic list List threaded Threaded
26 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Align baselines of 2 fields

Monte Goulding via use-livecode
I have a user customizable stack that has a label field, then just to the right of that a field with user content. The user is able to customize the font and size of both the label field and the content field individually. Both fields are just 1 line. Is there a way to calculate where the baselines of these 2 fields are so that I can align them automatically (without user interaction)?

Thanks,
Marty
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Align baselines of 2 fields

Monte Goulding via use-livecode
Hi.

Do you mean the bottom of the field control, or the baseline of the text?
All are doable.

Craig Newman



--
Sent from: http://runtime-revolution.278305.n4.nabble.com/Revolution-User-f278306.html

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Align baselines of 2 fields

Monte Goulding via use-livecode
The baseline of the text.

Marty

> On Jun 20, 2018, at 2:32 PM, dunbarxx via use-livecode <[hidden email]> wrote:
>
> Hi.
>
> Do you mean the bottom of the field control, or the baseline of the text?
> All are doable.
>
> Craig Newman
>
>
>
> --
> Sent from: http://runtime-revolution.278305.n4.nabble.com/Revolution-User-f278306.html
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Align baselines of 2 fields

Monte Goulding via use-livecode
In reply to this post by Monte Goulding via use-livecode
I am sure that with the margins, textHeight and textSize properties you can
calculate how to set the text baseline of one field to that of another. A
small textSize will require a smaller third margin, for example, and that
must take into account the textHeight as a further component.

Craig



--
Sent from: http://runtime-revolution.278305.n4.nabble.com/Revolution-User-f278306.html

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Align baselines of 2 fields

Monte Goulding via use-livecode
In reply to this post by Monte Goulding via use-livecode
I checked the dictionary. There is no entry for the baseline of anything.

Bob S


> On Jun 20, 2018, at 14:34 , Knapp Martin via use-livecode <[hidden email]> wrote:
>
> The baseline of the text.
>
> Marty
>
>> On Jun 20, 2018, at 2:32 PM, dunbarxx via use-livecode <[hidden email]> wrote:
>>
>> Hi.
>>
>> Do you mean the bottom of the field control, or the baseline of the text?
>> All are doable.
>>
>> Craig Newman
>>
>>
>>
>> --
>> Sent from: http://runtime-revolution.278305.n4.nabble.com/Revolution-User-f278306.html
>>
>> _______________________________________________
>> use-livecode mailing list
>> [hidden email]
>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Align baselines of 2 fields

Monte Goulding via use-livecode
Right. I do not think there is a "baseLine" property.

But again, if you play around with the properties I mentioned above, all of
which are in pixels, I bet you can create a handler that will determine the
"baseLineV" of any text in a field, and you can then match two fields
together.

This would be useful, since the fields could have different textSizes and
such, and still match their vertical value.

Craig



--
Sent from: http://runtime-revolution.278305.n4.nabble.com/Revolution-User-f278306.html

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Align baselines of 2 fields

Monte Goulding via use-livecode
So I played around just a little.

Make a new field and set its Textheight property. For the first line, this
will be a certain number of pixels below the top of the field. Each
subsequent line will be a multiple of that value. So if you know the
baseLine of any line of text, and you know the top, you can either position
the field so that the baseLine attains a certain Y value, or you can adjust
the baseline to any Y value.

Do the same for the other field, and you can align the text.

Craig



--
Sent from: http://runtime-revolution.278305.n4.nabble.com/Revolution-User-f278306.html

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Align baselines of 2 fields

Monte Goulding via use-livecode
In reply to this post by Monte Goulding via use-livecode
Hi Mary,

I suppose you want to center those fields around a common horizontal baseline.

You might try this if that is what you want. Should work with different fonts and sizes.

Two fields, one button.

Kind regards
Bernd

----------------------------------------------------------
on mouseUp
   local tDescent1, tDescent2, tBot1, tBot2, tDiff1, tDiff2, tRef
   local fFormattedBottom1, fFormattedBottom2
   
   put 120 into tRef

   put item 4 of the formattedRect of line 1 of field 1 into fFormattedBottom1
   put item 4 of the formattedRect of line 1 of field 2 into fFormattedBottom2
   
   put item 4 of measureText(line 1 of field 1, field 1 ,"bounds") into tDescent1
   put item 4 measureText(line 1 of field 2, field 2 ,"bounds") into tDescent2

   put the bottom of field 1 into tBot1
   put the bottom of field 2 into tBot2
   
   put tBot1 - fFormattedBottom1 + tDescent1 into tDiff1
   put tBot2 - fFormattedBottom2 + tDescent2 into tDiff2
   
   set the bottom of field 1 to tRef + tDiff1
   set the bottom of field 2 to tRef + tDiff2
end mouseUp
----------------------------------------------------------



_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Align baselines of 2 fields

Monte Goulding via use-livecode
Thanks Craig and Bernd, I’ll tinker with this and see how it goes.

Marty

> On Jun 21, 2018, at 4:37 AM, Niggemann, Bernd via use-livecode <[hidden email]> wrote:
>
> Hi Mary,
>
> I suppose you want to center those fields around a common horizontal baseline.
>
> You might try this if that is what you want. Should work with different fonts and sizes.
>
> Two fields, one button.
>
> Kind regards
> Bernd
>
> ----------------------------------------------------------
> on mouseUp
>   local tDescent1, tDescent2, tBot1, tBot2, tDiff1, tDiff2, tRef
>   local fFormattedBottom1, fFormattedBottom2
>
>   put 120 into tRef
>
>   put item 4 of the formattedRect of line 1 of field 1 into fFormattedBottom1
>   put item 4 of the formattedRect of line 1 of field 2 into fFormattedBottom2
>
>   put item 4 of measureText(line 1 of field 1, field 1 ,"bounds") into tDescent1
>   put item 4 measureText(line 1 of field 2, field 2 ,"bounds") into tDescent2
>
>   put the bottom of field 1 into tBot1
>   put the bottom of field 2 into tBot2
>
>   put tBot1 - fFormattedBottom1 + tDescent1 into tDiff1
>   put tBot2 - fFormattedBottom2 + tDescent2 into tDiff2
>
>   set the bottom of field 1 to tRef + tDiff1
>   set the bottom of field 2 to tRef + tDiff2
> end mouseUp
> ----------------------------------------------------------
>
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Align baselines of 2 fields

Monte Goulding via use-livecode
In reply to this post by Monte Goulding via use-livecode
Or better yet: (should probably be submitted to the Master Library). Trouble with this is that it relocates both fields. It should probably only move pField2.

on alignFieldBaselines pField1, pField2
   local tDescent1, tDescent2, tBot1, tBot2, tDiff1, tDiff2, tRef
   local fFormattedBottom1, fFormattedBottom2
   
   put 120 into tRef
   
   put item 4 of the formattedRect of line 1 of pField1 into fFormattedBottom1
   put item 4 of the formattedRect of line 1 of pField2 into fFormattedBottom2
   
   put item 4 of measureText(line 1 of pField1, pField1 ,"bounds") into tDescent1
   put item 4 measureText(line 1 of pField2, pField2 ,"bounds") into tDescent2
   
   put the bottom of pField1 into tBot1
   put the bottom of pField2 into tBot2
   
   put tBot1 - fFormattedBottom1 + tDescent1 into tDiff1
   put tBot2 - fFormattedBottom2 + tDescent2 into tDiff2
   
   set the bottom of pField1 to tRef + tDiff1
   set the bottom of pField2 to tRef + tDiff2  
end alignFieldBaselines

Bob S


> On Jun 21, 2018, at 04:37 , Niggemann, Bernd via use-livecode <[hidden email]> wrote:
>
> Hi Mary,
>
> I suppose you want to center those fields around a common horizontal baseline.
>
> You might try this if that is what you want. Should work with different fonts and sizes.
>
> Two fields, one button.
>
> Kind regards
> Bernd
>
> ----------------------------------------------------------
> on mouseUp
>   local tDescent1, tDescent2, tBot1, tBot2, tDiff1, tDiff2, tRef
>   local fFormattedBottom1, fFormattedBottom2
>
>   put 120 into tRef
>
>   put item 4 of the formattedRect of line 1 of field 1 into fFormattedBottom1
>   put item 4 of the formattedRect of line 1 of field 2 into fFormattedBottom2
>
>   put item 4 of measureText(line 1 of field 1, field 1 ,"bounds") into tDescent1
>   put item 4 measureText(line 1 of field 2, field 2 ,"bounds") into tDescent2
>
>   put the bottom of field 1 into tBot1
>   put the bottom of field 2 into tBot2
>
>   put tBot1 - fFormattedBottom1 + tDescent1 into tDiff1
>   put tBot2 - fFormattedBottom2 + tDescent2 into tDiff2
>
>   set the bottom of field 1 to tRef + tDiff1
>   set the bottom of field 2 to tRef + tDiff2
> end mouseUp
> ----------------------------------------------------------
>
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Align baselines of 2 fields

Monte Goulding via use-livecode
I modified as follows, but pField2 is one pixel high. Not sure why.

Bob S

on alignFieldBaselines pField1, pField2
   local tDescent1, tDescent2, tBot1, tBot2, tDiff1, tDiff2, tRef
   local fFormattedBottom1, fFormattedBottom2
   
   -- put 120 into tRef
   
   put item 4 of the formattedRect of line 1 of pField1 into fFormattedBottom1
   put item 4 of the formattedRect of line 1 of pField2 into fFormattedBottom2
   
   put item 4 of measureText(line 1 of pField1, pField1 ,"bounds") into tDescent1
   put item 4 measureText(line 1 of pField2, pField2 ,"bounds") into tDescent2
   
   put the bottom of pField1 into tBot1
   put the bottom of pField2 into tBot2
   
   put tBot1 - fFormattedBottom1 + tDescent1 into tDiff1
   put tBot2 - fFormattedBottom2 + tDescent2 into tDiff2
   
   -- set the bottom of pField1 to tRef + tDiff1
   set the bottom of pField2 to tBot1 + tDiff2  
end alignFieldBaselines


> On Jun 21, 2018, at 10:09 , Bob Sneidar via use-livecode <[hidden email]> wrote:
>
> Or better yet: (should probably be submitted to the Master Library). Trouble with this is that it relocates both fields. It should probably only move pField2.
>
> on alignFieldBaselines pField1, pField2
>   local tDescent1, tDescent2, tBot1, tBot2, tDiff1, tDiff2, tRef
>   local fFormattedBottom1, fFormattedBottom2
>
>   put 120 into tRef
>
>   put item 4 of the formattedRect of line 1 of pField1 into fFormattedBottom1
>   put item 4 of the formattedRect of line 1 of pField2 into fFormattedBottom2
>
>   put item 4 of measureText(line 1 of pField1, pField1 ,"bounds") into tDescent1
>   put item 4 measureText(line 1 of pField2, pField2 ,"bounds") into tDescent2
>
>   put the bottom of pField1 into tBot1
>   put the bottom of pField2 into tBot2
>
>   put tBot1 - fFormattedBottom1 + tDescent1 into tDiff1
>   put tBot2 - fFormattedBottom2 + tDescent2 into tDiff2
>
>   set the bottom of pField1 to tRef + tDiff1
>   set the bottom of pField2 to tRef + tDiff2  
> end alignFieldBaselines
>
> Bob S
>
>
>> On Jun 21, 2018, at 04:37 , Niggemann, Bernd via use-livecode <[hidden email]> wrote:
>>
>> Hi Mary,
>>
>> I suppose you want to center those fields around a common horizontal baseline.
>>
>> You might try this if that is what you want. Should work with different fonts and sizes.
>>
>> Two fields, one button.
>>
>> Kind regards
>> Bernd
>>
>> ----------------------------------------------------------
>> on mouseUp
>>  local tDescent1, tDescent2, tBot1, tBot2, tDiff1, tDiff2, tRef
>>  local fFormattedBottom1, fFormattedBottom2
>>
>>  put 120 into tRef
>>
>>  put item 4 of the formattedRect of line 1 of field 1 into fFormattedBottom1
>>  put item 4 of the formattedRect of line 1 of field 2 into fFormattedBottom2
>>
>>  put item 4 of measureText(line 1 of field 1, field 1 ,"bounds") into tDescent1
>>  put item 4 measureText(line 1 of field 2, field 2 ,"bounds") into tDescent2
>>
>>  put the bottom of field 1 into tBot1
>>  put the bottom of field 2 into tBot2
>>
>>  put tBot1 - fFormattedBottom1 + tDescent1 into tDiff1
>>  put tBot2 - fFormattedBottom2 + tDescent2 into tDiff2
>>
>>  set the bottom of field 1 to tRef + tDiff1
>>  set the bottom of field 2 to tRef + tDiff2
>> end mouseUp
>> ----------------------------------------------------------
>>
>>
>>
>> _______________________________________________
>> use-livecode mailing list
>> [hidden email]
>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Align baselines of 2 fields

Monte Goulding via use-livecode
This works for me, assuming you want to leave field 1 where it is and align field 2:

on alignFieldBaselines pField1, pField2
  local tDescent1, tDescent2, tBot1, tBot2, tDiff1, tDiff2, tRef
  local fFormattedBottom1, fFormattedBottom2

  put item 4 of the formattedRect of line 1 of fld pField1 into fFormattedBottom1
  put item 4 of the formattedRect of line 1 of fld pField2 into fFormattedBottom2

  put item 4 of measureText(line 1 of fld pField1, fld pField1 ,"bounds") into tDescent1
  put item 4 measureText(line 1 of fld pField2, fld pField2 ,"bounds") into tDescent2

  put the bottom of fld pField1 into tBot1
  put the bottom of fld pField2 into tBot2

  put tBot1 - fFormattedBottom1 + tDescent1 into tDiff1
  put tBot2 - fFormattedBottom2 + tDescent2 into tDiff2

  put the bottom of fld pField1 -(tDiff1 - tDiff2) into tRef

  set the bottom of fld pField2 to tRef  
end alignFieldBaselines
---
Marty

> On Jun 21, 2018, at 10:24 AM, Bob Sneidar via use-livecode <[hidden email]> wrote:
>
> I modified as follows, but pField2 is one pixel high. Not sure why.
>
> Bob S
>
> on alignFieldBaselines pField1, pField2
>   local tDescent1, tDescent2, tBot1, tBot2, tDiff1, tDiff2, tRef
>   local fFormattedBottom1, fFormattedBottom2
>
>   -- put 120 into tRef
>
>   put item 4 of the formattedRect of line 1 of pField1 into fFormattedBottom1
>   put item 4 of the formattedRect of line 1 of pField2 into fFormattedBottom2
>
>   put item 4 of measureText(line 1 of pField1, pField1 ,"bounds") into tDescent1
>   put item 4 measureText(line 1 of pField2, pField2 ,"bounds") into tDescent2
>
>   put the bottom of pField1 into tBot1
>   put the bottom of pField2 into tBot2
>
>   put tBot1 - fFormattedBottom1 + tDescent1 into tDiff1
>   put tBot2 - fFormattedBottom2 + tDescent2 into tDiff2
>
>   -- set the bottom of pField1 to tRef + tDiff1
>   set the bottom of pField2 to tBot1 + tDiff2  
> end alignFieldBaselines
>
>
>> On Jun 21, 2018, at 10:09 , Bob Sneidar via use-livecode <[hidden email]> wrote:
>>
>> Or better yet: (should probably be submitted to the Master Library). Trouble with this is that it relocates both fields. It should probably only move pField2.
>>
>> on alignFieldBaselines pField1, pField2
>>  local tDescent1, tDescent2, tBot1, tBot2, tDiff1, tDiff2, tRef
>>  local fFormattedBottom1, fFormattedBottom2
>>
>>  put 120 into tRef
>>
>>  put item 4 of the formattedRect of line 1 of pField1 into fFormattedBottom1
>>  put item 4 of the formattedRect of line 1 of pField2 into fFormattedBottom2
>>
>>  put item 4 of measureText(line 1 of pField1, pField1 ,"bounds") into tDescent1
>>  put item 4 measureText(line 1 of pField2, pField2 ,"bounds") into tDescent2
>>
>>  put the bottom of pField1 into tBot1
>>  put the bottom of pField2 into tBot2
>>
>>  put tBot1 - fFormattedBottom1 + tDescent1 into tDiff1
>>  put tBot2 - fFormattedBottom2 + tDescent2 into tDiff2
>>
>>  set the bottom of pField1 to tRef + tDiff1
>>  set the bottom of pField2 to tRef + tDiff2  
>> end alignFieldBaselines
>>
>> Bob S
>>
>>
>>> On Jun 21, 2018, at 04:37 , Niggemann, Bernd via use-livecode <[hidden email]> wrote:
>>>
>>> Hi Mary,
>>>
>>> I suppose you want to center those fields around a common horizontal baseline.
>>>
>>> You might try this if that is what you want. Should work with different fonts and sizes.
>>>
>>> Two fields, one button.
>>>
>>> Kind regards
>>> Bernd
>>>
>>> ----------------------------------------------------------
>>> on mouseUp
>>> local tDescent1, tDescent2, tBot1, tBot2, tDiff1, tDiff2, tRef
>>> local fFormattedBottom1, fFormattedBottom2
>>>
>>> put 120 into tRef
>>>
>>> put item 4 of the formattedRect of line 1 of field 1 into fFormattedBottom1
>>> put item 4 of the formattedRect of line 1 of field 2 into fFormattedBottom2
>>>
>>> put item 4 of measureText(line 1 of field 1, field 1 ,"bounds") into tDescent1
>>> put item 4 measureText(line 1 of field 2, field 2 ,"bounds") into tDescent2
>>>
>>> put the bottom of field 1 into tBot1
>>> put the bottom of field 2 into tBot2
>>>
>>> put tBot1 - fFormattedBottom1 + tDescent1 into tDiff1
>>> put tBot2 - fFormattedBottom2 + tDescent2 into tDiff2
>>>
>>> set the bottom of field 1 to tRef + tDiff1
>>> set the bottom of field 2 to tRef + tDiff2
>>> end mouseUp
>>> ----------------------------------------------------------
>>>
>>>
>>>
>>> _______________________________________________
>>> use-livecode mailing list
>>> [hidden email]
>>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
>>
>> _______________________________________________
>> use-livecode mailing list
>> [hidden email]
>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Align baselines of 2 fields

Monte Goulding via use-livecode
I changed the font of one of the fields to something with a different descent, and it doesn't seem to work.

Bob S


> On Jun 21, 2018, at 10:28 , Knapp Martin via use-livecode <[hidden email]> wrote:
>
> This works for me, assuming you want to leave field 1 where it is and align field 2:
>
> on alignFieldBaselines pField1, pField2
>  local tDescent1, tDescent2, tBot1, tBot2, tDiff1, tDiff2, tRef
>  local fFormattedBottom1, fFormattedBottom2
>
>  put item 4 of the formattedRect of line 1 of fld pField1 into fFormattedBottom1
>  put item 4 of the formattedRect of line 1 of fld pField2 into fFormattedBottom2
>
>  put item 4 of measureText(line 1 of fld pField1, fld pField1 ,"bounds") into tDescent1
>  put item 4 measureText(line 1 of fld pField2, fld pField2 ,"bounds") into tDescent2
>
>  put the bottom of fld pField1 into tBot1
>  put the bottom of fld pField2 into tBot2
>
>  put tBot1 - fFormattedBottom1 + tDescent1 into tDiff1
>  put tBot2 - fFormattedBottom2 + tDescent2 into tDiff2
>
>  put the bottom of fld pField1 -(tDiff1 - tDiff2) into tRef
>
>  set the bottom of fld pField2 to tRef  
> end alignFieldBaselines
> ---
> Marty
>
>> On Jun 21, 2018, at 10:24 AM, Bob Sneidar via use-livecode <[hidden email]> wrote:
>>
>> I modified as follows, but pField2 is one pixel high. Not sure why.
>>
>> Bob S
>>
>> on alignFieldBaselines pField1, pField2
>>  local tDescent1, tDescent2, tBot1, tBot2, tDiff1, tDiff2, tRef
>>  local fFormattedBottom1, fFormattedBottom2
>>
>>  -- put 120 into tRef
>>
>>  put item 4 of the formattedRect of line 1 of pField1 into fFormattedBottom1
>>  put item 4 of the formattedRect of line 1 of pField2 into fFormattedBottom2
>>
>>  put item 4 of measureText(line 1 of pField1, pField1 ,"bounds") into tDescent1
>>  put item 4 measureText(line 1 of pField2, pField2 ,"bounds") into tDescent2
>>
>>  put the bottom of pField1 into tBot1
>>  put the bottom of pField2 into tBot2
>>
>>  put tBot1 - fFormattedBottom1 + tDescent1 into tDiff1
>>  put tBot2 - fFormattedBottom2 + tDescent2 into tDiff2
>>
>>  -- set the bottom of pField1 to tRef + tDiff1
>>  set the bottom of pField2 to tBot1 + tDiff2  
>> end alignFieldBaselines
>>
>>
>>> On Jun 21, 2018, at 10:09 , Bob Sneidar via use-livecode <[hidden email]> wrote:
>>>
>>> Or better yet: (should probably be submitted to the Master Library). Trouble with this is that it relocates both fields. It should probably only move pField2.
>>>
>>> on alignFieldBaselines pField1, pField2
>>> local tDescent1, tDescent2, tBot1, tBot2, tDiff1, tDiff2, tRef
>>> local fFormattedBottom1, fFormattedBottom2
>>>
>>> put 120 into tRef
>>>
>>> put item 4 of the formattedRect of line 1 of pField1 into fFormattedBottom1
>>> put item 4 of the formattedRect of line 1 of pField2 into fFormattedBottom2
>>>
>>> put item 4 of measureText(line 1 of pField1, pField1 ,"bounds") into tDescent1
>>> put item 4 measureText(line 1 of pField2, pField2 ,"bounds") into tDescent2
>>>
>>> put the bottom of pField1 into tBot1
>>> put the bottom of pField2 into tBot2
>>>
>>> put tBot1 - fFormattedBottom1 + tDescent1 into tDiff1
>>> put tBot2 - fFormattedBottom2 + tDescent2 into tDiff2
>>>
>>> set the bottom of pField1 to tRef + tDiff1
>>> set the bottom of pField2 to tRef + tDiff2  
>>> end alignFieldBaselines
>>>
>>> Bob S
>>>
>>>
>>>> On Jun 21, 2018, at 04:37 , Niggemann, Bernd via use-livecode <[hidden email]> wrote:
>>>>
>>>> Hi Mary,
>>>>
>>>> I suppose you want to center those fields around a common horizontal baseline.
>>>>
>>>> You might try this if that is what you want. Should work with different fonts and sizes.
>>>>
>>>> Two fields, one button.
>>>>
>>>> Kind regards
>>>> Bernd
>>>>
>>>> ----------------------------------------------------------
>>>> on mouseUp
>>>> local tDescent1, tDescent2, tBot1, tBot2, tDiff1, tDiff2, tRef
>>>> local fFormattedBottom1, fFormattedBottom2
>>>>
>>>> put 120 into tRef
>>>>
>>>> put item 4 of the formattedRect of line 1 of field 1 into fFormattedBottom1
>>>> put item 4 of the formattedRect of line 1 of field 2 into fFormattedBottom2
>>>>
>>>> put item 4 of measureText(line 1 of field 1, field 1 ,"bounds") into tDescent1
>>>> put item 4 measureText(line 1 of field 2, field 2 ,"bounds") into tDescent2
>>>>
>>>> put the bottom of field 1 into tBot1
>>>> put the bottom of field 2 into tBot2
>>>>
>>>> put tBot1 - fFormattedBottom1 + tDescent1 into tDiff1
>>>> put tBot2 - fFormattedBottom2 + tDescent2 into tDiff2
>>>>
>>>> set the bottom of field 1 to tRef + tDiff1
>>>> set the bottom of field 2 to tRef + tDiff2
>>>> end mouseUp
>>>> ----------------------------------------------------------
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> use-livecode mailing list
>>>> [hidden email]
>>>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>>
>>>
>>> _______________________________________________
>>> use-livecode mailing list
>>> [hidden email]
>>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
>>
>> _______________________________________________
>> use-livecode mailing list
>> [hidden email]
>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Align baselines of 2 fields

Monte Goulding via use-livecode
In reply to this post by Monte Goulding via use-livecode
Hi Marty,

depending how liberal you are in letting users choose fonts and sizes you might get "unexpected" results by aligning to field 1


try this stress test


---------------------------------
on mouseUp
   lock screen
   set the textfont of field 1 to any line of the fontNames
   set the textfont of field 2 to any line of the fontNames
   set the textSize of field 1 to random(20) + 10
   set the textSize of field 2 to random(20) + 10
  -- put the textFont of field 1 into field "Font1"
  -- put the textFont of field 2 into field "Font2"
   unlock screen
end mouseUp
---------------------------------

then align via your script
Your layout can start "moving"

Additionally not all fonts report proper ascents and descents



Kind regards
Bernd

> Marty wrote:
> This works for me, assuming you want to leave field 1 where it is and align field 2:
>
> on alignFieldBaselines pField1, pField2
>  local tDescent1, tDescent2, tBot1, tBot2, tDiff1, tDiff2, tRef
>  local fFormattedBottom1, fFormattedBottom2
>
>  put item 4 of the formattedRect of line 1 of fld pField1 into fFormattedBottom1
>  put item 4 of the formattedRect of line 1 of fld pField2 into fFormattedBottom2
>
>  put item 4 of measureText(line 1 of fld pField1, fld pField1 ,"bounds") into tDescent1
>  put item 4 measureText(line 1 of fld pField2, fld pField2 ,"bounds") into tDescent2
>
>  put the bottom of fld pField1 into tBot1
>  put the bottom of fld pField2 into tBot2
>
>  put tBot1 - fFormattedBottom1 + tDescent1 into tDiff1
>  put tBot2 - fFormattedBottom2 + tDescent2 into tDiff2
>
>  put the bottom of fld pField1 -(tDiff1 - tDiff2) into tRef
>
>  set the bottom of fld pField2 to tRef  
> end alignFieldBaselines

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Align baselines of 2 fields

Monte Goulding via use-livecode
Sorry my bad. I modified your script to expect the long id of a field, but your second edition still expected short names. I can work around that later.

So your new script works,  except the second field may be one pixel too high, depending on the font. Not sure there is a workaround for this, but this is still very useful.

Bob S


>
>
>> Marty wrote:
>> This works for me, assuming you want to leave field 1 where it is and align field 2:
>>
>> on alignFieldBaselines pField1, pField2
>> local tDescent1, tDescent2, tBot1, tBot2, tDiff1, tDiff2, tRef
>> local fFormattedBottom1, fFormattedBottom2
>>
>> put item 4 of the formattedRect of line 1 of fld pField1 into fFormattedBottom1
>> put item 4 of the formattedRect of line 1 of fld pField2 into fFormattedBottom2
>>
>> put item 4 of measureText(line 1 of fld pField1, fld pField1 ,"bounds") into tDescent1
>> put item 4 measureText(line 1 of fld pField2, fld pField2 ,"bounds") into tDescent2
>>
>> put the bottom of fld pField1 into tBot1
>> put the bottom of fld pField2 into tBot2
>>
>> put tBot1 - fFormattedBottom1 + tDescent1 into tDiff1
>> put tBot2 - fFormattedBottom2 + tDescent2 into tDiff2
>>
>> put the bottom of fld pField1 -(tDiff1 - tDiff2) into tRef
>>
>> set the bottom of fld pField2 to tRef  
>> end alignFieldBaselines
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Align baselines of 2 fields

Monte Goulding via use-livecode
Okay new version. This adds an offset parameter for those cases where the baselines do not exactly align due to font weirdnesses. I also added the ability to pass a short name of a field, or else the long ID. Enjoy!

Bob S


on alignFieldBaselines pField1, pField2, pOffset
   local tDescent1, tDescent2, tBot1, tBot2, tDiff1, tDiff2, tRef
   local fFormattedBottom1, fFormattedBottom2
   
   -- check passed parameters
   try
      if word 1 to 2 of pField1 is not "Field ID" then put the long id of field pField1 into pField1
      if word 1 to 2 of pField2 is not "Field ID" then put the long id of field pField2 into pField2
      if pOffset is empty then put 0 into pOffset
   catch theError
      return "Invalid parameter passed."
   end try
   
   -- get the formatted bottoms of both fields
   put item 4 of the formattedRect of line 1 of pField1 into fFormattedBottom1
   put item 4 of the formattedRect of line 1 of pField2 into fFormattedBottom2
   
   -- calculate the descents of both fields
   put item 4 of measureText(line 1 of pField1, pField1 ,"bounds") into tDescent1
   put item 4 measureText(line 1 of pField2, pField2 ,"bounds") into tDescent2
   
   -- get the bottom of both fields
   put the bottom of pField1 into tBot1
   put the bottom of pField2 into tBot2
   
   -- calculate the differences
   put tBot1 - fFormattedBottom1 + tDescent1 into tDiff1
   put tBot2 - fFormattedBottom2 + tDescent2 into tDiff2
   
   -- calculate and set the new bottom for field 2
   put the bottom of pField1 -(tDiff1 - tDiff2) into tRef
   set the bottom of pField2 to tRef  + pOffset
end alignFieldBaselines
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Align baselines of 2 fields

Monte Goulding via use-livecode
In reply to this post by Monte Goulding via use-livecode
Bernd,
I ran this at least 50 times and in the vast majority of cases the baselines align. In a few cases, as Bob noted, it was off by 1 pixel. But that will be OK for my use. I let users pick any font but sizes are limited from 8 to 20.

Thanks you guys. A very resourceful group, as usual!

Marty

> On Jun 21, 2018, at 11:00 AM, Niggemann, Bernd via use-livecode <[hidden email]> wrote:
>
> Hi Marty,
>
> depending how liberal you are in letting users choose fonts and sizes you might get "unexpected" results by aligning to field 1
>
>
> try this stress test
>
>
> ---------------------------------
> on mouseUp
>   lock screen
>   set the textfont of field 1 to any line of the fontNames
>   set the textfont of field 2 to any line of the fontNames
>   set the textSize of field 1 to random(20) + 10
>   set the textSize of field 2 to random(20) + 10
>  -- put the textFont of field 1 into field "Font1"
>  -- put the textFont of field 2 into field "Font2"
>   unlock screen
> end mouseUp
> ---------------------------------
>
> then align via your script
> Your layout can start "moving"
>
> Additionally not all fonts report proper ascents and descents
>
>
>
> Kind regards
> Bernd
>
>> Marty wrote:
>> This works for me, assuming you want to leave field 1 where it is and align field 2:
>>
>> on alignFieldBaselines pField1, pField2
>> local tDescent1, tDescent2, tBot1, tBot2, tDiff1, tDiff2, tRef
>> local fFormattedBottom1, fFormattedBottom2
>>
>> put item 4 of the formattedRect of line 1 of fld pField1 into fFormattedBottom1
>> put item 4 of the formattedRect of line 1 of fld pField2 into fFormattedBottom2
>>
>> put item 4 of measureText(line 1 of fld pField1, fld pField1 ,"bounds") into tDescent1
>> put item 4 measureText(line 1 of fld pField2, fld pField2 ,"bounds") into tDescent2
>>
>> put the bottom of fld pField1 into tBot1
>> put the bottom of fld pField2 into tBot2
>>
>> put tBot1 - fFormattedBottom1 + tDescent1 into tDiff1
>> put tBot2 - fFormattedBottom2 + tDescent2 into tDiff2
>>
>> put the bottom of fld pField1 -(tDiff1 - tDiff2) into tRef
>>
>> set the bottom of fld pField2 to tRef  
>> end alignFieldBaselines
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Align baselines of 2 fields

Monte Goulding via use-livecode
In reply to this post by Monte Goulding via use-livecode
Okay a newer NEWER version. If no parameters are passed for the fields, it will use the first two hilited objects. Also, I check that pOffset is a number by adding 0 to it in a try/catch statement.


on alignFieldBaselines pField1, pField2, pOffset
  local tDescent1, tDescent2, tBot1, tBot2, tDiff1, tDiff2, tRef
  local fFormattedBottom1, fFormattedBottom2

   -- check passed parameters
   if pField1 is empty and pField2 is empty then
      put the selectedObjects into pFieldList
      put line 1 of pFieldList into pField1
      put line 2 of pFieldList into pField2
   end if
   

  -- check passed parameters
  try
     if word 1 to 2 of pField1 is not "Field ID" then put the long id of field pField1 into pField1
     if word 1 to 2 of pField2 is not "Field ID" then put the long id of field pField2 into pField2
     if pOffset is empty then put 0 into pOffset
     add 0 to pOffset
  catch theError
     return "Invalid parameter passed."
  end try

  -- get the formatted bottoms of both fields
  put item 4 of the formattedRect of line 1 of pField1 into fFormattedBottom1
  put item 4 of the formattedRect of line 1 of pField2 into fFormattedBottom2

  -- calculate the descents of both fields
  put item 4 of measureText(line 1 of pField1, pField1 ,"bounds") into tDescent1
  put item 4 measureText(line 1 of pField2, pField2 ,"bounds") into tDescent2

  -- get the bottom of both fields
  put the bottom of pField1 into tBot1
  put the bottom of pField2 into tBot2

  -- calculate the differences
  put tBot1 - fFormattedBottom1 + tDescent1 into tDiff1
  put tBot2 - fFormattedBottom2 + tDescent2 into tDiff2

  -- calculate and set the new bottom for field 2
  put the bottom of pField1 -(tDiff1 - tDiff2) into tRef
  set the bottom of pField2 to tRef  + pOffset
end alignFieldBaselines
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Align baselines of 2 fields

Monte Goulding via use-livecode
On 6/21/18 2:58 PM, Bob Sneidar via use-livecode wrote:
> Also, I check that pOffset is a number by adding 0 to it in a try/catch statement.

Or alternately, "if pOffset is a number..."

--
Jacqueline Landman Gay         |     [hidden email]
HyperActive Software           |     http://www.hyperactivesw.com

_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Align baselines of 2 fields

Monte Goulding via use-livecode
But that won't throw an error in my try catch statement. :-)

Bob S


> On Jun 21, 2018, at 13:23 , J. Landman Gay via use-livecode <[hidden email]> wrote:
>
> On 6/21/18 2:58 PM, Bob Sneidar via use-livecode wrote:
>> Also, I check that pOffset is a number by adding 0 to it in a try/catch statement.
>
> Or alternately, "if pOffset is a number..."
>
> --
> Jacqueline Landman Gay         |     [hidden email]
> HyperActive Software           |     http://www.hyperactivesw.com


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
12