display.newText and monospaced font numbers are

Hi,

I am developing a calculator. the numbers must be of course right aligned on the display. i am using the font courier, because i thought with monospaced fonts i don’t run into trouble. On the simulator all is fine, but on device the numbers are moving everytime i am making display output with display.newText between i think 1 or 3 pixels to the left or the right. the most wiggle i see if the output changes from 9 to 10 numbers.

With this bug corona isn’t usable for my opinion. Anyone have an idea how can this be fixed ?

Thans in advanced
Klaus
[import]uid: 5456 topic_id: 7773 reply_id: 307773[/import]

Check the WordWrap code in the code exchange. It handles all sorts of font kerning. [import]uid: 3953 topic_id: 7773 reply_id: 27720[/import]

thanks, but doesn’t help.

I tried it with a static display position (x) and a static string length, filling up the string with leading spaces.

:-(( [import]uid: 5456 topic_id: 7773 reply_id: 27803[/import]

have you tried using a ui label instead of a display.newText?

carlos has somewhere posted that, in order to include an empty character (space), you have to use empty=" " (2 empty characters instead of 1)

[import]uid: 6459 topic_id: 7773 reply_id: 27812[/import]

Hi,

i record the efect right now, click below. i was made in the x-code simulator, same on device.

click me

Klaus [import]uid: 5456 topic_id: 7773 reply_id: 27815[/import]

yes tried it with ui.label ! same problem
2 spaces … is empty=" " a function ?
2 trailing spaces for one character doubles the spaces … tried it, no success [import]uid: 5456 topic_id: 7773 reply_id: 27818[/import]

Klaus,

if you use newText, then every time you set a new text, you have to reset the reference point and the x coordinate (which depends on the width of the text). that’s why i suggested the ui label
the third alternative, the native text box, cannot be inserted in a group…

i use this function to insert leading spaces:

local empty,characters=" ",10  
local function leadingSpaces(n)  
 local str=tostring(n)  
 for i=1,characters-#str do  
 str=empty..str  
 end  
 return str  
end  

set the text param of the label equal to leadingSpaces(the_number_to_display)

it works OK for integers (though not pixel perfect), but i haven’t tried it with floats
and you don’t have to use courier, use any font you like

[import]uid: 6459 topic_id: 7773 reply_id: 27833[/import]

Hi,

thanks for help, but this also doesn’t work. i tried ui.newLabel and newText, both have the same effect which you can see in the youtube video. ui.newLabel without static lenght its not so good as static lenght with leading spaces. compared display.newText with ui.newLabel there is no difference.

Klaus

[import]uid: 5456 topic_id: 7773 reply_id: 27857[/import]

This is 17 months late, but here’s the answer for reference:

Every time you change the text, you have to re-define the reference point and the position.

If you set up your text like this:

myText = display.newText( "Number: "… myNumber, 0, 0, “Helvetica”, 16 )
myText:setReferencePoint(display.TopLeftReferencePoint)

Then updating it becomes a 3-step process:

myText.text = "Number: "… myNumber --change the text
myText:setReferencePoint(display.TopLeftReferencePoint) --reset the display point
myText.x = 0 --redefine the position

The text now stays in the top-left corner.

note that in my example, the y coordinate did not change; only the x. This is because i did not change the size of my font; just the length of my string. [import]uid: 79674 topic_id: 7773 reply_id: 48004[/import]

John,

Can you help me with my issue using the new text field? I am trying to do a subtraction problem and I want to type in the first number and then subtract the second number from that and display the answer below. This is my link to the other thread where this is going on.
https://developer.anscamobile.com/forum/2011/08/08/text-field

[import]uid: 72372 topic_id: 7773 reply_id: 50042[/import]