I'm putting together a virtual keypad component for numeric text entry in my mobile app. This is so I have full control over it, I want to move away from OS-provided soft keyboards.
I have a simple component that contains the keypad buttons. This is generating characters which are sent to an editor component. The editor component has 3 editable Labels. However, if the user clicks on the keypad button, the editor component label loses focus and the label's TextEditor component disappears.
I've set the editor component's labels to ```setWantsKeyboardFocus (true)```, and for each button in the keypad component I've set both ```setMouseClickGrabsKeyboardFocus (false)``` and ```setWantsKeyboardFocus (false)```
I'm using a callback function thats called whenever a keypad button is pressed. Its able to see that the focused component is a label, but can't find its TextEditor, I'm guessing because its already disappeared at that point.
void MyEditor::keyInput(char key)
{
if (Component* focusComp = getCurrentlyFocusedComponent())
{
if (focusComp == label1 || focusComp == label2 || focusComp == label3)
{
// Reaches here
TextEditor* textEditor = dynamic_cast<Label*> (focusComp)->getCurrentTextEditor();
if (textEditor != nullptr)
textEditor->insertTextAtCaret (String (key)); // <-- does not reach here
}
}
}
Is there a way to keep the TextEditor alive while clcking other buttons?
