EditableText::new method to set initial text#23702
EditableText::new method to set initial text#23702ickshonpe wants to merge 6 commits intobevyengine:mainfrom
EditableText::new method to set initial text#23702Conversation
…nput already containing some text.
|
Might be worth adding a comment that it sets the cursor to start of text |
Ah yeah that's a good point, I hadn't thought about the initial cursor position. I think that for |
…s created using `new`
EditableText new method to make it easier to construct text inputs with an initial value.EditableText::new method to set initial text
|
Another option is to initially have all the text selected. You often see this in prompt dialogs, where the text input is filled with some default string, but as soon as the user starts typing, the text is replaced. Of course, the reason we even need any of this is because our text input is an uncontrolled widget. With controlled widgets, the buffer state is external and supplied by the user, so they can initialize it to whatever they want. For example, in the feathers color picker, the source of truth is not the text buffer, but the rgb value in the resource, which updates the buffer via change detection. And since change detection runs on initial creation, the text input gets initialized as we would want it to. The downside of uncontrolled widgets is twofold:
In the documentation for headless widgets, it says that widgets are controlled, but I specifically call out an exception for text inputs, because I know that making them controlled is a problem. |
|
Yes Parley's PlainEditor is inherently stateful, so I guess we can only really work around it for the moment. |
Objective
It should be simple to set an initial value for
EditableText's text buffer.Otherwise I can see users struggling with this and using some ghastly construction like a run once system in
Updateto set initial text.Solution
New
EditableText::newmethod. The value of the text buffer is set immediately and aTextEdit::TextEnd(false)edit is queued to move the cursor to the end of the text.Testing
Added some initial text to the multiple text example: