What is the value _G.fontSize?
Is there a reason you have a global version of this and a local version?
What is the value of display.contentScaleY and your fontSize calculation?
What is the value _G.fontSize?
Is there a reason you have a global version of this and a local version?
What is the value of display.contentScaleY and your fontSize calculation?
I built this code:
local fontSize = 22 / display.contentScaleY \_G.fontSize = fontSize print(fontSize) print(display.contentScaleY) local yearIF = native.newTextField( (display.contentWidth / 2), 180, (display.contentWidth\*0.45), fontSize\*3) yearIF.font = native.newFont( native.systemFont, \_G.fontSize ) yearIF.size = fontSize yearIF.text = "" yearIF:setTextColor( 81/255, 81/255, 81/255 ) yearIF.inputType = "number"
For my Nexus 7 running 4.4 and the text fits the box perfectly. I used an 800x1200 content area.
Rob
Hi Rob,
very frustrating. On my Nexus 4 running 5.0 (same with 4.4) the text is cut off half way.
The calculated fontSize = 21.12 and display.contentScaleY = 1.04
So every device is different? Or the content scaling has some influence? We have different behaviours on different device resolutions.
Can you post a screen shot from the device?
Also what is the value of that global variable version of fontSize?
Rob
It’s been a year and a half since I joined this thread. It’s really disappointing when people join it, acknowledging that this is still such a problem. I still don’t have every device covered in my app (I gave up). At least have some kind of official triggered shim input where you don’t even render the real input box, since at least that would be something Corona-controlled without these gymnastics.
Sorry Rob,
i do not see any possibility to upload an attachment on this forum. If i click on “My Media” i have no button to upload anything. how can i upload screen shots?
Hi @toga,
You can upload images by clicking “More Reply Options” (instead of just “Post”). Then, on the next screen, you’ll see an option to choose a file and upload it.
Brent
Also post your config.lua please.
Rob
Engineering made a suggestion:
– Determine the content height for the following font size.
local fontSize = 22
local textToMeasure = display.newText(“X”, 0, 0, native.systemFont, fontSize)
local textHeight = textToMeasure.contentHeight
textToMeasure.removeSelf()
textToMeasure = nil
Then use textHeight + some padding for native.newTextField(). I’ve not tried this, but then it’s not an issue on my devices.
Rob
config.lua:
application = { content = { width = 800, height = 1200, scale = "letterBox", }, }
main.lua:
local fontSize = 22 local textToMeasure = display.newText("X", 0, 0, native.systemFont, fontSize) local textHeight = textToMeasure.contentHeight textToMeasure:removeSelf() textToMeasure = nil textHeight = textHeight + 40 local yearIF = native.newTextField( (display.contentWidth / 2), 180, (display.contentWidth\*0.5), textHeight) yearIF.font = native.newFont( native.systemFont, fontSize) --yearIF.size = fontSize yearIF.text = "" yearIF:setTextColor( 81/255, 81/255, 81/255 )
Here is my testresult.
Thanks,
Thomas
I’m at a loss. That code runs perfectly on my Nexus 7 and Kindle Fire. I looked around for a device setting that might impact it and didn’t find any thing. Let me share this screen shot with the Engineers and see if they have any ideas.
Thanks
Rob
Oh, try changing your “letterBox” to “letterbox” and see if that has any impact.
Hi Rob,
thanks for your help. changing “letterBox” to “letterbox” did not help. If i change the config.lua to 320x480 the result is perfect. Please see attachment. (and textHeight was only textHeight + 10).
Can you also get the values for these:
system.getInfo(“androidDisplayApproximateDpi”)
system.getInfo(“androidDisplayWidthInInches”)
system.getInfo(“androidDisplayHeightInInches”)
system.getInfo(“androidDisplayXDpi”)
system.getInfo(“androidDisplayYDpi”)
Rob
code:
local fontSize = 22 local textToMeasure = display.newText("TEST0123456", (display.contentWidth / 2), 100, native.systemFont, fontSize) local textHeight = textToMeasure.contentHeight --textToMeasure:removeSelf() --textToMeasure = nil local function onComplete( event ) if event.action == "clicked" then local i = event.index if i == 1 then -- Do nothing; dialog will simply dismiss end end end local output = system.getInfo("androidDisplayApproximateDpi") .. ", " .. system.getInfo("androidDisplayWidthInInches") .. ", " .. system.getInfo("androidDisplayHeightInInches") .. ", " .. system.getInfo("androidDisplayXDpi") .. ", " .. system.getInfo("androidDisplayYDpi") local alert = native.showAlert( "Corona", output, { "OK" }, onComplete ) textHeight = textHeight + 60 local yearIF = native.newTextField( (display.contentWidth / 2), 180, (display.contentWidth\*0.5), textHeight) yearIF.font = native.newFont( native.systemFont, fontSize) yearIF.size = fontSize yearIF.text = "" yearIF:setTextColor( 81/255, 81/255, 81/255 ) --yearIF.inputType = "number"
Results see attachments.
If i add a value of 60 to tHeight the text is perfect. but why is my Input text so much higher than the text in Display.newText (same font size for both)? It seems to me that the Input text “thinks” that i have only 320x480 resolution.
But I’m testing it on a 800x1200 content area just like you are and it’s working. Your Nexus 4 is a 320 dot per inch device, where my Nexus 7 is more like 213.
Hi Rob,
i have the same issue on my oneplus one (dpi is 403). But on my Samsung galaxy tab S (dpi 286) it is working.
When i change the content area to 320x480 then it works on all 3 devices. Looks like a very strange scaling bug in corona.
Actually has to do with scaling, or more precisely the lack of scaling. Engineering worked out some Lua code to make it fit but it has some restrictions. They think there are some things that they can do to fix this, but it will likely be a breaking change so they are trying to figure out the best way to handle it.
fontSize = fontSize / (system.getInfo(“androidDisplayApproximateDpi”) / 160)
yearIF.font = native.newFont( native.systemFont, fontSize)
Can you try that and see if it’s any better?
Hi Rob,
i tried it and there is no improvement. But the not scaling native textfield is not my real problem. With some calculations it is possible to calculate the font size for the different content sizes. But the big issue is the textHeight of the native textfield. there is no correct calculation for that. Sometimes i have to take textHeight = 4 x fontSize. Why?? sometimes it is ok wenn i only add (textHeight + 15) some litle padding. If i have the resolution 320x480 only adding some constant values of 15 works great for all fontSizes. But in 800x1200 for every fontsize and devices you need different text heights. Why. that makes no sense for me and therefore i think it is a Corona bug. Perhaps corona scales something (font size) in native.newTextField but does not scale the height of the Input field?
So to sum up. I need no scaling for the native.newTextField. I only need a predictable text height for content areas bigger than 320x480.
Ok, i give up. I have no idea what corona is doing internally when executing native.newTextField.
I have tried the following simple code on my 2 devices (Nexus 4 and Samsung galaxy Tabs) with the 2 resolutions 320x480 and 800x1200. Please see attached results. Does this make any sense?
local fontSize = 22
textHeight = fontSize + 20
local yearIF = native.newTextField( (display.contentWidth / 2), 180, (display.contentWidth*0.5), textHeight)
yearIF.font = native.newFont( native.systemFont, fontSize)