I want to match the height of the text with the TextField.
I set the height of the TextField to 80 in the code.
I also set the font size to 20.
This should fit the TextField in 4 rows. But the result is only 3 rows.
How can I:
-Reliably display fonts in 20 pixels.
Or
-Get the height of the entire text in pixels.
Then adjust the TextField to the same height.
-Or is there any other solution?
My testing environment:
unity2020.3.4f1 windows
var textField = new TextField("");
textField.multiline = true;
textField.style.width = 200;
textField.style.height =80;
foreach (VisualElement child in textField.Children())
{
child.style.unityTextAlign = new StyleEnum<TextAnchor>(TextAnchor.UpperLeft);
child.style.fontSize = 20;
}
textField.RegisterValueChangedCallback(evt =>
{
var cnt = textField.text.ToList().Where(c => c.Equals('\n')).Count();
textField.style.height = new StyleLength(20 + (cnt * 20));
});
Thank you.