Reputation: 791
I am trying to have a TMP Input Field with multiline (wrapped) placeholder. The input field has its content type set to Integer Number
. Placeholder text has some string as text and has wrapping set to "enabled". In prefab editor, it looks ok (text is wrapped). However, when the scene loads, placeholder text immediately has its wrapping reset to "disabled".
The problem: I assume Input field resets the wrapping to disabled
on child text, because its content is not multiline, as specified here. I can't set the input field to accept multiline - the option is not in inspector; I can see it if I switch to Debug mode, but as soon as I set it to multiline it switches back to single line. So, how do I set the wrapping on placeholder to enabled without it getting switched back to disabled in runtime? Or, alternatively, how do I set my InputFiled to be multiline (I assume that will fix the wrapping on the placeholder)?
What I have for now:
I have an input field that works like this: when it's not focused, there is a multiline text, for example: "Write your\nnumber here!". When focused, it's replaced by empty line and user can enter an integer number. On finishing input (OnEndEdit
) I use the input to spawn some GameObjects and then replace the text again with "Write your\nnumber here!". Editor screenshot:
Right now it works as I expect. However, now I want to dynamically change the placeholder text, so I don't know where the newline will be and I would like for TMP to wrap the text for me, same as it does in Text component with Wrapping enabled.
So: how do I use TMP's wrapping - enabled on InputField without it getting reset to disabled? Either both the user input and placeholder, or just on placeholder itself - doesn't matter.
Upvotes: 0
Views: 3728
Reputation: 90769
MultiLine
is only available if the Content Type
is set to Standard
or Auto Corrected
.
As soon as you set the input type to Integer Number
it basically behaves just like an integer field in the Unity Inspector: No line wrapping but rather overfloating and scrolling to the right.
Alternatively if you need multi lines you could set the Content Type
to Custom
and then fully flexible adjust it to your needs like e.g.
And in general: Of course you also can't set a text to an input field that only accepts integer numbers ;) Rather set your placeholder text in the Placeholder
object!
Anything that is applied to the Placeholder
will be displayed automatically as long as there is no value typed in the input field!
Upvotes: 1