manually build a string of numerical digits, filtering out everything else
| 101 | |
| 102 | // manually build a string of numerical digits, filtering out everything else |
| 103 | void iosKeyboardApp::processNumerical( const KeyEvent &event ) |
| 104 | { |
| 105 | if( event.getCode() == KeyEvent::KEY_BACKSPACE && ! mNumericalTextView.mText.empty() ) |
| 106 | mNumericalTextView.mText.pop_back(); |
| 107 | else if( isdigit( event.getChar() ) ) { |
| 108 | mNumericalTextView.mText.push_back( event.getChar() ); |
| 109 | Rectf fitRect = mNumericalTextView.getTextBounds(); |
| 110 | TextBox tbox = TextBox().font( mFont ).text( mNumericalTextView.mText ).size( TextBox::GROW, TextBox::GROW ); |
| 111 | vec2 size = tbox.measure(); |
| 112 | |
| 113 | if( size.x > fitRect.getWidth() ) { |
| 114 | console() << "OVERFLOW" << endl; |
| 115 | mNumericalTextView.mText.pop_back(); |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | // Don't return on enter here, which allows the KEY_RETURN to be interpreted as a newline. |
| 121 | // Instead, grab the internal keyboard string, which can also handle complex character sequences, such as kanji or emoji |