RE: Vertically aligning text in a field
Hi Jaque, I needed to know where the hGrid line of line 1 shows. I did not get there by adding: top of field, topMargin, borderSize and effective textHeight. So I don't know what I missed but that calculation gives me a 7 pixel offset i.e. the position is 7 pixel below the hGrid of line 1. I don't know what these 7 pixel are. Then I went into experimentation mode and found that empiric formula. Maybe someone has an idea how to calculate the hGrid position of line 1 of an EMPTY field in a straight forward way. Kind regards Bernd -- View this message in context: http://runtime-revolution.278305.n4.nabble.com/Vertically-aligning-text-in-a-field-tp4686824p4686975.html Sent from the Revolution - User mailing list archive at Nabble.com. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Vertically aligning text in a field
On Fri, Dec 19, 2014 at 2:32 PM, BNig bernd.niggem...@uni-wh.de wrote: Hi Geoff, I think I found a solution for variable textHeight and different fonts in a field. If the formattedRect breaks on mobile, then that's a bug for the LC team, but other than that, doesn't my two-line solution work? I'm not seeing a way to break my two-line solution? What is the need for a more complex solution? ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Vertically aligning text in a field
Hi Geoff, When I plug this into my tester the text ends up at the top of the field. iMac, Yosemite, LC6.7.1 on centreTextVertically tID --THIS WORKS -- put the effective textSize of fld id tID into tTextSize -- put round (((tTextSize - 24) * 1/3)) into tOffset -- put the formattedheight of char 1 to - 1 of fld id tID into tFormattedHeight -- put round((the height of fld id tID - tFormattedHeight) / 2) into tVerticalMargins -- put tVerticalMargins - tOffset into tTopMargin -- put tVerticalMargins + tOffset into tBottomMargin -- set the margins of fld id tID to 8,tTopMargin,8,tBottomMargin --THIS WORKS -- put the effective textHeight of fld id tID into tTextHeight -- put item 2 of the loc of fld id tID into tfieldY -- put the formattedRect of line 1 to - 1 of fld id tID into tFormatRect -- put item 2 of tFormatRect into tCurrFormatTop -- put tfieldY - tCurrFormatTop into tCenterField_To_TopTextDiff -- put the number of lines of the formattedtext of fld id tID into tNoOfLines -- put (((tNoOfLInes div 2)) * tTextHeight) + (tNoOfLInes mod 2) * (tTextHeight div 2) into tOffset -- set the topMargin of fld id tID to the topMargin of fld id tID + tCenterField_To_TopTextDiff - tOffset --THIS WORKS -- put the effective textHeight of fld id tID into tTextHeight -- put item 2 of the loc of fld id tID into tfieldY -- put the formattedRect of line 1 to - 1 of fld id tID into tFormatRect -- put item 4 of tFormatRect - item 2 of tFormatRect into tFormatHeight -- put tFormatHeight div 2 into tFormatHalfHeight -- put item 2 of tFormatRect into tCurrFormatTop -- put tfieldY - tCurrFormatTop into tCenterField_To_TopTextDiff -- set the topMargin of fld id tID to the topMargin of fld id tID + tCenterField_To_TopTextDiff - tFormatHalfHeight --WITH THIS THE TEXT ENDS UP AT THE TOP OF THE FIELD put the formattedrect of line 1 to -1 of fld id tID into tFormattedRect set the topmargin of fld id tID to (the height of fld id tID - item 4 of tFormattedRect + item 2 of tFormattedRect) div 2 end centreTextVertically Don’t know why. All the best Terry On 20 Dec 2014, at 18:41, Geoff Canyon gcan...@gmail.com wrote: I'm not seeing a way to break my two-line solution? What is the need for a more complex solution? ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Vertically aligning text in a field
On 12/20/2014, 12:41 PM, Geoff Canyon wrote: If the formattedRect breaks on mobile, then that's a bug for the LC team, but other than that, doesn't my two-line solution work? I'm not seeing a way to break my two-line solution? What is the need for a more complex solution? It doesn't quite center correctly, at least not my multi-line wrapped field. It may have something to do with the calculations in the formatted* commands. I found that by adding a small number of pixels to the top margin I could get it close, which is what Bernd was doing too. I've been trying to figure out where the problem is, but like him, I don't see anything offhand. I'm pretty sure the engine must either be adding padding to the top line, or else not reporting the underhang of the last line, which makes the formattedWhatever functions not quite exact. BTW, I could reduce your calculation to a one-liner by using the formattedHeight instead of the formattedRect; it returns the same result -- which isn't quite right, but matches what you got. set the topmargin of fld 1 to the height of fld 1 - the formattedheight of line 1 to -1 of fld 1 -- Jacqueline Landman Gay | jac...@hyperactivesw.com HyperActive Software | http://www.hyperactivesw.com ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Vertically aligning text in a field
On 12/20/2014, 1:18 PM, J. Landman Gay wrote: I found that by adding a small number of pixels to the top margin I could get it close, which is what Bernd was doing too. I've been trying to figure out where the problem is, but like him, I don't see anything offhand. I'm pretty sure the engine must either be adding padding to the top line, or else not reporting the underhang of the last line, which makes the formattedWhatever functions not quite exact. On the theory that the problem isn't at the top but rather at the bottom, I calculated the amount of space occupied by the (imaginary) line 0 in the field. I think in general 2/3 of the text is placed above the baseline and 1/3 of it is placed below that. So the top line would be offset by 1/3 the textheight of the (nonexistent) line 0. This seems to come closer to what we want: put round(the effective textheight of fld 1 * .66) into tUnderHang set the topmargin of fld 1 to (the height of fld 1 - (the formattedheight of line 1 to -1 of fld 1) + tUnderHang) div 2 -- Jacqueline Landman Gay | jac...@hyperactivesw.com HyperActive Software | http://www.hyperactivesw.com ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Vertically aligning text in a field
Not sure what's up with the offset that seems constant and inherent, but this corrects for it. It does nothing about the apparent offset caused by the difference between the textheight and and textsize of the first line, because if the size varies, the textsize returns mixed. In any case, this works for me to a reasonable degree of accuracy: set the topmargin of fld 1 to (8 + the height of fld 1 - the formattedheight of line 1 to -1 of fld 1) div 2 Here's a demo stack that shows what this does. Each time you click the Test button the text changes, then vertically aligns, then puts in two equal-height boxes above and below to show the results. https://dl.dropboxusercontent.com/u/41182876/vertical%20text%20demo.livecode On Sat, Dec 20, 2014 at 11:24 AM, J. Landman Gay jac...@hyperactivesw.com wrote: On 12/20/2014, 1:18 PM, J. Landman Gay wrote: I found that by adding a small number of pixels to the top margin I could get it close, which is what Bernd was doing too. I've been trying to figure out where the problem is, but like him, I don't see anything offhand. I'm pretty sure the engine must either be adding padding to the top line, or else not reporting the underhang of the last line, which makes the formattedWhatever functions not quite exact. On the theory that the problem isn't at the top but rather at the bottom, I calculated the amount of space occupied by the (imaginary) line 0 in the field. I think in general 2/3 of the text is placed above the baseline and 1/3 of it is placed below that. So the top line would be offset by 1/3 the textheight of the (nonexistent) line 0. This seems to come closer to what we want: put round(the effective textheight of fld 1 * .66) into tUnderHang set the topmargin of fld 1 to (the height of fld 1 - (the formattedheight of line 1 to -1 of fld 1) + tUnderHang) div 2 -- Jacqueline Landman Gay | jac...@hyperactivesw.com HyperActive Software | http://www.hyperactivesw.com ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Vertically aligning text in a field
here is a definitive (as opposed to infinitive) calculation that correctly sets the positon of text vertically in a field for testing purposes it is ready to be put into a slider optionally make three graphics to get visual feedback, see below watch out for line breaks --- -- optionally have visual feedback -- make 3 horizontal line graphics, gTop, gBot, gCenter -- place them near the field on scrollbarDrag pValue -- tested with values 9 to 36 lock screen put the long id of fld fTest into myFld -- change to name of your field set the textSize of myFld to pValue CenterTextVertically myFld if there is a grc gTop AND there is a grc gBot AND there is a grc gCenter then getFeedBack myFld end if end scrollbarDrag on CenterTextVertically myFld put the effective textHeight of myFld into tTextHeight put item 2 of the loc of myFld into tfieldY put the formattedRect of line 1 to - 1 of myFld into tFormatRect put item 2 of tFormatRect into tCurrFormatTop put tfieldY - tCurrFormatTop into tCenterField_To_TopTextDiff put the number of lines of the text of myFld into tNoOfLines put (((tNoOfLInes div 2)) * tTextHeight) + (tNoOfLInes mod 2) * (tTextHeight div 2) into tOffset set the topMargin of myFld to the topMargin of myFld + tCenterField_To_TopTextDiff - tOffset end CenterTextVertically on getFeedBack myFld put the formattedRect of char 1 to - 1 of myFld into tFormatRect put item 2 of the loc of myFld into tfieldY set the top of grc gTop to item 2 of tFormatRect - 1 set the top of grc gBot to item 4 of tFormatRect - 1 set the top of grc gCenter to tFieldY - 1 end getFeedBack --- Did the code you came across not do what you wanted? Kind regards Bernd Terence Heaford wrote Is there a definitive calculation that correctly sets the position of text vertically in a field? I am using LC 6.7. I have come across a few ideas like the one below that all appear to use an arbitrary offset to the margins, is there a method to calculate this accurately? put the effective textSize of fld id tID into tTextSize -- put round (((tTextSize - 22) * 1/3)) into tOffset put round (((tTextSize - 24) * 1/3)) into tOffset put the formattedheight of char 1 to - 1 of fld id tID into tFormattedHeight put round((the height of fld id tID - tFormattedHeight) / 2) into tVerticalMargins put tVerticalMargins - tOffset into tTopMargin put tVerticalMargins + tOffset into tBottomMargin set the margins of fld id tID to 8,tTopMargin,8,tBottomMargin All the best Terry -- View this message in context: http://runtime-revolution.278305.n4.nabble.com/Vertically-aligning-text-in-a-field-tp4686824p4686954.html Sent from the Revolution - User mailing list archive at Nabble.com. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Vertically aligning text in a field
This is great! Just change text to formattedText for this line: put the number of lines of the text of myFld into tNoOfLines See below - Eric On Dec 19, 2014, at 9:32 AM, BNig bernd.niggem...@uni-wh.de wrote: here is a definitive (as opposed to infinitive) calculation that correctly sets the positon of text vertically in a field for testing purposes it is ready to be put into a slider optionally make three graphics to get visual feedback, see below watch out for line breaks --- -- optionally have visual feedback -- make 3 horizontal line graphics, gTop, gBot, gCenter -- place them near the field on scrollbarDrag pValue -- tested with values 9 to 36 lock screen put the long id of fld fTest into myFld -- change to name of your field set the textSize of myFld to pValue CenterTextVertically myFld if there is a grc gTop AND there is a grc gBot AND there is a grc gCenter then getFeedBack myFld end if end scrollbarDrag on CenterTextVertically myFld put the effective textHeight of myFld into tTextHeight put item 2 of the loc of myFld into tfieldY put the formattedRect of line 1 to - 1 of myFld into tFormatRect put item 2 of tFormatRect into tCurrFormatTop put tfieldY - tCurrFormatTop into tCenterField_To_TopTextDiff put the number of lines of the text of myFld into tNoOfLines put the number of lines of the formattedText of myFld into tNoOfLines put (((tNoOfLInes div 2)) * tTextHeight) + (tNoOfLInes mod 2) * (tTextHeight div 2) into tOffset set the topMargin of myFld to the topMargin of myFld + tCenterField_To_TopTextDiff - tOffset end CenterTextVertically on getFeedBack myFld put the formattedRect of char 1 to - 1 of myFld into tFormatRect put item 2 of the loc of myFld into tfieldY set the top of grc gTop to item 2 of tFormatRect - 1 set the top of grc gBot to item 4 of tFormatRect - 1 set the top of grc gCenter to tFieldY - 1 end getFeedBack --- Did the code you came across not do what you wanted? Kind regards Bernd Terence Heaford wrote Is there a definitive calculation that correctly sets the position of text vertically in a field? I am using LC 6.7. I have come across a few ideas like the one below that all appear to use an arbitrary offset to the margins, is there a method to calculate this accurately? put the effective textSize of fld id tID into tTextSize -- put round (((tTextSize - 22) * 1/3)) into tOffset put round (((tTextSize - 24) * 1/3)) into tOffset put the formattedheight of char 1 to - 1 of fld id tID into tFormattedHeight put round((the height of fld id tID - tFormattedHeight) / 2) into tVerticalMargins put tVerticalMargins - tOffset into tTopMargin put tVerticalMargins + tOffset into tBottomMargin set the margins of fld id tID to 8,tTopMargin,8,tBottomMargin All the best Terry -- View this message in context: http://runtime-revolution.278305.n4.nabble.com/Vertically-aligning-text-in-a-field-tp4686824p4686954.html Sent from the Revolution - User mailing list archive at Nabble.com. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Vertically aligning text in a field
Thank you very much for this code. I was surprised that LC did not have an option for vertically aligned text in a field and on searching the forum found your method. However, on my iMac the offset calculation did not seem to work precisely and I had to adjust it slightly. As I am creating a report stack for printing tables that may have different fonts and font sizes with different row(field) heights provided as parameters I was looking for a reliable way to centre text vertically with the possibility of many options. Thanks again, this really looks like the answer. I will report back if anything looks odd in testing. All the best Terry On 19 Dec 2014, at 17:32, BNig bernd.niggem...@uni-wh.de wrote: Did the code you came across not do what you wanted? ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Vertically aligning text in a field
What requirement am I missing that this isn't sufficient -- and capable of handling multiple fonts and font sizes throughout the text? get the formattedrect of line 1 to -1 of fld 1 set the topmargin of fld 1 to (the height of fld 1 - item 4 of it + item 2 of it) div 2 On Fri, Dec 19, 2014 at 1:52 PM, Terence Heaford t.heaf...@btinternet.com wrote: Thank you very much for this code. I was surprised that LC did not have an option for vertically aligned text in a field and on searching the forum found your method. However, on my iMac the offset calculation did not seem to work precisely and I had to adjust it slightly. As I am creating a report stack for printing tables that may have different fonts and font sizes with different row(field) heights provided as parameters I was looking for a reliable way to centre text vertically with the possibility of many options. Thanks again, this really looks like the answer. I will report back if anything looks odd in testing. All the best Terry On 19 Dec 2014, at 17:32, BNig bernd.niggem...@uni-wh.de wrote: Did the code you came across not do what you wanted? ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Vertically aligning text in a field
Thank Eric, Oh, I forgot about wrapping text. That is a neat addition. Actually I don't really use this myself, so I was thinking about something like small 3 - 5 lines of text in a separate field, not big wrapped text. Kind regards Bernd Eric Corbett wrote This is great! Just change text to formattedText for this line: put the number of lines of the text of myFld into tNoOfLines See below - Eric -- View this message in context: http://runtime-revolution.278305.n4.nabble.com/Vertically-aligning-text-in-a-field-tp4686824p4686958.html Sent from the Revolution - User mailing list archive at Nabble.com. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Vertically aligning text in a field
I think we are on a different wavelength here. The code I was originally using from the forum was: -- put the effective textSize of fld id tID into tTextSize -- put round (((tTextSize - 24) * 1/3)) into tOffset -- put the formattedheight of char 1 to - 1 of fld id tID into tFormattedHeight -- put round((the height of fld id tID - tFormattedHeight) / 2) into tVerticalMargins -- put tVerticalMargins - tOffset into tTopMargin -- put tVerticalMargins + tOffset into tBottomMargin -- set the margins of fld id tID to 8,tTopMargin,8,tBottomMargin This is the line I had to adjust -- put round (((tTextSize - 24) * 1/3)) into tOffset I think it was originally 22 not 24. Was this code yours or Bernd's. Not sure how I seemed to have upset you but that was not my intention. All the best Terry On 19 Dec 2014, at 19:57, Geoff Canyon gcan...@gmail.com wrote: What requirement am I missing that this isn't sufficient -- and capable of handling multiple fonts and font sizes throughout the text? ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
RE: Vertically aligning text in a field
I have been working on this for a while. I found out that the base line is different on various platforms. This makes the calculation change on various platforms. See bugs http://quality.runrev.com/show_bug.cgi?id=13551 and http://quality.runrev.com/show_bug.cgi?id=12176 . Ralph DiMola IT Director Evergreen Information Services rdim...@evergreeninfo.net -Original Message- From: use-livecode [mailto:use-livecode-boun...@lists.runrev.com] On Behalf Of Terence Heaford Sent: Friday, December 19, 2014 3:17 PM To: How to use LiveCode Subject: Re: Vertically aligning text in a field I think we are on a different wavelength here. The code I was originally using from the forum was: -- put the effective textSize of fld id tID into tTextSize -- put round (((tTextSize - 24) * 1/3)) into tOffset -- put the formattedheight of char 1 to - 1 of fld id tID into tFormattedHeight -- put round((the height of fld id tID - tFormattedHeight) / 2) into tVerticalMargins -- put tVerticalMargins - tOffset into tTopMargin -- put tVerticalMargins + tOffset into tBottomMargin -- set the margins of fld id tID to 8,tTopMargin,8,tBottomMargin This is the line I had to adjust -- put round (((tTextSize - 24) * 1/3)) into tOffset I think it was originally 22 not 24. Was this code yours or Bernd's. Not sure how I seemed to have upset you but that was not my intention. All the best Terry On 19 Dec 2014, at 19:57, Geoff Canyon gcan...@gmail.com wrote: What requirement am I missing that this isn't sufficient -- and capable of handling multiple fonts and font sizes throughout the text? ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Vertically aligning text in a field
Hi Terry: FWIW, I¹ve never been able to get the field adjustment code working for anything but default text. I¹ve pretty much given up on using fields for vertically centered text and use buttons where possible. Once you establish a topMargin offset to center the text (you can use a negative margin value via script even though the Inspector doesn¹t accept negative numbers), the text will automatically stay vertically centered, regardless of how the button is scaled. Regards, Scott Rossi Creative Director Tactile Media, UX/UI Design On 12/19/14, 11:52 AM, Terence Heaford t.heaf...@btinternet.com wrote: Thank you very much for this code. I was surprised that LC did not have an option for vertically aligned text in a field and on searching the forum found your method. However, on my iMac the offset calculation did not seem to work precisely and I had to adjust it slightly. As I am creating a report stack for printing tables that may have different fonts and font sizes with different row(field) heights provided as parameters I was looking for a reliable way to centre text vertically with the possibility of many options. Thanks again, this really looks like the answer. I will report back if anything looks odd in testing. All the best Terry On 19 Dec 2014, at 17:32, BNig bernd.niggem...@uni-wh.de wrote: Did the code you came across not do what you wanted? ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Vertically aligning text in a field
Hi Scott, Thanks for the feedback, noted to give your suggestion a try. All the best Terry On 19 Dec 2014, at 20:35, Scott Rossi sc...@tactilemedia.com wrote: FWIW, I¹ve never been able to get the field adjustment code working for anything but default text. I¹ve pretty much given up on using fields for vertically centered text and use buttons where possible. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Vertically aligning text in a field
Hi Geoff, both code versions were intended for fixedLineHeight text. But now you mention it I will try to adjust the code for variable lineHeight and varying fonts. Since am currently doing cantuccini (sort of italian cookies) I will try it a little later. I think the solution is not to rely on the textHeight but to calculate from the formattedHeight / 2 in code version 2. Put that into the offset. I have not tried it though yet. Kind regards Bernd Geoff Canyon-4 wrote What requirement am I missing that this isn't sufficient -- and capable of handling multiple fonts and font sizes throughout the text? get the formattedrect of line 1 to -1 of fld 1 set the topmargin of fld 1 to (the height of fld 1 - item 4 of it + item 2 of it) div 2 On Fri, Dec 19, 2014 at 1:52 PM, Terence Heaford lt; t.heaford@ gt; wrote: Thank you very much for this code. I was surprised that LC did not have an option for vertically aligned text in a field and on searching the forum found your method. However, on my iMac the offset calculation did not seem to work precisely and I had to adjust it slightly. As I am creating a report stack for printing tables that may have different fonts and font sizes with different row(field) heights provided as parameters I was looking for a reliable way to centre text vertically with the possibility of many options. Thanks again, this really looks like the answer. I will report back if anything looks odd in testing. All the best Terry On 19 Dec 2014, at 17:32, BNig lt; bernd.niggemann@ gt; wrote: Did the code you came across not do what you wanted? ___ use-livecode mailing list use-livecode@.runrev Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode ___ use-livecode mailing list use-livecode@.runrev Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode -- View this message in context: http://runtime-revolution.278305.n4.nabble.com/Vertically-aligning-text-in-a-field-tp4686824p4686964.html Sent from the Revolution - User mailing list archive at Nabble.com. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Vertically aligning text in a field
Hi Geoff, I think I found a solution for variable textHeight and different fonts in a field. Try this. It is now independent from the textHeight and just uses the formattedHeight. And no need to watch out for wrapped text. Should work with any text whose formattedRect and is reported correctly, which apparently according to Ralph is not always the case on mobile devices. This is again for scrollbar for a field you configure to your liking. You can optionally have visual feedback when you make 3 horizontal line graphics and name them as stated in the script. The textSize is only changed for the lines that don't have their textSize set explicitly. Uncheck fixed textHeight in the properties inspector. Not extensively tested but seems to work Kind regards Bernd as always: watch out for line breaks -- optionally have visual feedback -- make 3 horizontal line graphics, gTop, gBot, gCenter -- place them near the field on scrollbarDrag pValue -- tested with values 9 to 36 lock screen put the long id of fld fTest into myFld -- change to name of your field set the textSize of myFld to pValue -- block if you want CenterTextVertically myFld if there is a grc gTop AND there is a grc gBot AND there is a grc gCenter then getFeedBack myFld end if end scrollbarDrag on CenterTextVertically myFld put the effective textHeight of myFld into tTextHeight put item 2 of the loc of myFld into tfieldY put the formattedRect of line 1 to - 1 of myFld into tFormatRect put item 4 of tFormatRect - item 2 of tFormatRect into tFormatHeight put tFormatHeight div 2 into tFormatHalfHeight put item 2 of tFormatRect into tCurrFormatTop put tfieldY - tCurrFormatTop into tCenterField_To_TopTextDiff set the topMargin of myFld to the topMargin of myFld + tCenterField_To_TopTextDiff - tFormatHalfHeight end CenterTextVertically on getFeedBack myFld put the formattedRect of char 1 to - 1 of myFld into tFormatRect put item 2 of the loc of myFld into tfieldY set the top of grc gTop to item 2 of tFormatRect - 1 set the top of grc gBot to item 4 of tFormatRect - 1 set the top of grc gCenter to tFieldY - 1 end getFeedBack -- View this message in context: http://runtime-revolution.278305.n4.nabble.com/Vertically-aligning-text-in-a-field-tp4686824p4686967.html Sent from the Revolution - User mailing list archive at Nabble.com. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
RE: Vertically aligning text in a field
Hi Ralph, I have not tried this all on mobile devices. But on desktops the baseline of the first line is consistently found with this piece of code. I had the need for a starting point for a gradient behind the text and had difficulties finding a consitent reference point. I found the base line of line 1 and from then on the textHeight is ok. There is something in the first line that is not exactly the textHeight. Or I haven't found it. Anyways here is the code for a field with fixedTextHeight. TextHeight can be manually/by script set to be different from the automatic textHeight when choosing a textSize. Margins border are taken into account. This piece of code is surpisingly robust... this is on mouseEnter for a a field, make a horizontal line graphic gBaseLine to see where it is and turn in the Properties Inspector - Table - hGrid on to see the base lines as always watch out for line breaks - on mouseEnter -- now calculate the position of the first base line of the first line of the field. -- = first horizontal divider from top -- the gradient should go there -- find out difference between automatic textheight and manually set textHeight -- formula according to documentation put the effective textSize of me into tTextSize put trunc(4/3*tTextSize) into tRegularTextHeight put the effective textHeight of me - tRegularTextHeight into tDiff -- the first line is not the formattedHeight but changes according to the font size -- formula found by experimentation put round (((tTextSize - 22) * 1/3)) into tKorr -- NOTE added 1 to the calculated From -- the vertical coordinate of the gradient from put the top of me + the effective textSize of me + the borderWidth of me \ + the topMargin of me + tKorr + tDiff into tFirstBaseLineY put the vScroll of me into tVScroll subtract tVScroll from tYofFirstBaseLine if there is a graphic gBaseLine then set the top of grc gBaseLine to tFirstBaseLineY end if end mouseEnter - Ralph DiMola wrote I have been working on this for a while. I found out that the base line is different on various platforms. This makes the calculation change on various platforms. See bugs http://quality.runrev.com/show_bug.cgi?id=13551 and http://quality.runrev.com/show_bug.cgi?id=12176 . Ralph DiMola IT Director -- View this message in context: http://runtime-revolution.278305.n4.nabble.com/Vertically-aligning-text-in-a-field-tp4686824p4686969.html Sent from the Revolution - User mailing list archive at Nabble.com. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Vertically aligning text in a field
Hi Terry, Look at my reply to Geoff. I think this is more the solution you need because that code makes no assumptions about fixed textHeight, line wrapping and so on. It should work for any type of field and center what is visible vertically. Kind regards Bernd Terence Heaford wrote Thank you very much for this code. I was surprised that LC did not have an option for vertically aligned text in a field and on searching the forum found your method. However, on my iMac the offset calculation did not seem to work precisely and I had to adjust it slightly. As I am creating a report stack for printing tables that may have different fonts and font sizes with different row(field) heights provided as parameters I was looking for a reliable way to centre text vertically with the possibility of many options. Thanks again, this really looks like the answer. I will report back if anything looks odd in testing. All the best Terry -- View this message in context: http://runtime-revolution.278305.n4.nabble.com/Vertically-aligning-text-in-a-field-tp4686824p4686970.html Sent from the Revolution - User mailing list archive at Nabble.com. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Vertically aligning text in a field
Hi Bernd, Thanks very much for all your efforts, on first use there does not appear to be any issues. Thanks again Terry On 19 Dec 2014, at 23:02, BNig bernd.niggem...@uni-wh.de wrote: Hi Terry, Look at my reply to Geoff. ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
RE: Vertically aligning text in a field
The field topmargin maybe? On December 19, 2014 4:59:28 PM CST, BNig bernd.niggem...@uni-wh.de wrote: I have not tried this all on mobile devices. But on desktops the baseline of the first line is consistently found with this piece of code. I had the need for a starting point for a gradient behind the text and had difficulties finding a consitent reference point. I found the base line of line 1 and from then on the textHeight is ok. There is something in the first line that is not exactly the textHeight. Or I haven't found it. -- Jacqueline Landman Gay | jac...@hyperactivesw.com HyperActive Software | http://www.hyperactivesw.com ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Vertically aligning text in a field
Is there a definitive calculation that correctly sets the position of text vertically in a field? I am using LC 6.7. I have come across a few ideas like the one below that all appear to use an arbitrary offset to the margins, is there a method to calculate this accurately? put the effective textSize of fld id tID into tTextSize -- put round (((tTextSize - 22) * 1/3)) into tOffset put round (((tTextSize - 24) * 1/3)) into tOffset put the formattedheight of char 1 to - 1 of fld id tID into tFormattedHeight put round((the height of fld id tID - tFormattedHeight) / 2) into tVerticalMargins put tVerticalMargins - tOffset into tTopMargin put tVerticalMargins + tOffset into tBottomMargin set the margins of fld id tID to 8,tTopMargin,8,tBottomMargin All the best Terry ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode
Re: Vertically aligning text in a field
Hi Terry, There's a long discussion about this on the forum. I believe I did a good attempt, but Bernd's solution was probably the most reliable. -- Best regards, Mark Schonewille Economy-x-Talk Consulting and Software Engineering Homepage: http://economy-x-talk.com Twitter: http://twitter.com/xtalkprogrammer KvK: 50277553 Installer Maker for LiveCode: http://qery.us/468 Buy my new book Programming LiveCode for the Real Beginner http://qery.us/3fi LiveCode on Facebook: https://www.facebook.com/groups/runrev/ On 12/16/2014 11:54, Terence Heaford wrote: Is there a definitive calculation that correctly sets the position of text vertically in a field? I am using LC 6.7. I have come across a few ideas like the one below that all appear to use an arbitrary offset to the margins, is there a method to calculate this accurately? put the effective textSize of fld id tID into tTextSize -- put round (((tTextSize - 22) * 1/3)) into tOffset put round (((tTextSize - 24) * 1/3)) into tOffset put the formattedheight of char 1 to - 1 of fld id tID into tFormattedHeight put round((the height of fld id tID - tFormattedHeight) / 2) into tVerticalMargins put tVerticalMargins - tOffset into tTopMargin put tVerticalMargins + tOffset into tBottomMargin set the margins of fld id tID to 8,tTopMargin,8,tBottomMargin All the best Terry ___ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode