I’ve recently got access to the daily builds and finally I’m able to play with the new native.newTextField() (font) sizing features.
Unfortunately I’m not able to make it quite work. I’m trying to make three objects:
A display.newText() object, a native.newTextField() object and a native.newTextBox() object having the same font size.
The display.newText() and the native.newTextBox() seems to show the same font size, but the
The tutorial is a bit fuzzy when it comes to font priority sizing, it says:
The second function (object:resizeHeightToFitFont()) is useful when the font size is the higher priority, and the field can be a variable size to accommodate the font size.
local textField = native.newTextField( 160, 240, 280, 40 ) textField.text = "Hello World"
Ok…
-- Change the text field's font size to the system default textField.size = 60
This part makes no sense to me. How is setting the height to 60 making the field use the system default font?
-- Resize the text field's height to best fit the font textField:resizeHeightToFitFont()
Ok.
In the docs for object:resizeHeightToFitFont() it says:
-- Change the text field's font size to the system default textField.size = nil
Trying to understand as best as I can I take it that there is an error in the tutorial and that the docs are right: That to make the field resize to the font is done by setting the size to nil and then call resizeHeightToFitFont().
But I’ve tried this and it doesn’t seem to work, so I’m a bit confused. Heres my complete test app code:
\_W = display.contentWidth \_H = display.contentHeight local widget = require("widget") label = display.newText("Label:", \_W\*0.1, \_H\*0.3, native.systemFont, 40) label.anchorX = 0.0 textField = native.newTextField(\_W\*0.1, \_H\*0.35, \_W\*0.4, 150) textField.font = native.newFont(native.systemFont, 40) textField.size = nil textField:resizeHeightToFitFont() textField.anchorX = 0.0 textBox = native.newTextBox(\_W/2, \_H\*0.4, \_W\*0.8, \_H\*0.2) textBox.font = native.newFont(native.systemFont, 40) textBox.isEditable = true textBox.anchorY = 0.0
When I run this on an (Android) device I get the attached screen (after entering “Label” in the edit field/box):

Is the tutorial or the docs right? What am I doing wrong?