コード例 #1
0
// manually build a string of numerical digits, filtering out everything else
void iosKeyboardApp::processNumerical( const KeyEvent &event )
{
	if( event.getCode() == KeyEvent::KEY_BACKSPACE && ! mNumericalTextView.mText.empty() )
		mNumericalTextView.mText.pop_back();
	else if( isdigit( event.getChar() ) ) {
		mNumericalTextView.mText.push_back( event.getChar() );
		Rectf fitRect = mNumericalTextView.getTextBounds();
		TextBox tbox = TextBox().font( mFont ).text( mNumericalTextView.mText ).size( TextBox::GROW, TextBox::GROW );
		vec2 size = tbox.measure();

		if( size.x > fitRect.getWidth() ) {
			console() << "OVERFLOW" << endl;
			mNumericalTextView.mText.pop_back();
		}
	}
}
コード例 #2
0
void iosKeyboardApp::drawTextView( const TextView &textView )
{
	gl::color( Color( "PowderBlue" ) );
	gl::drawSolidRect( textView.mBounds );

	Color borderColor = textView.mIsSelected ? Color( "DodgerBlue" ) : Color( "DarkGray" );
	gl::color( borderColor );
	gl::drawStrokedRect( textView.mBounds );

	Rectf fitRect = textView.getTextBounds();
	vec2 offset( 0.0f, mFont.getAscent() );

	TextBox tbox = TextBox().font( mFont ).size( fitRect.getWidth(), fitRect.getHeight() ).premultiplied();

	if( textView.mText.empty() && ! textView.mIsSelected ) {
		tbox.color( Color::gray( 0.6f ) ).text( textView.mPlacerholderText );
	}
	else {
		tbox.color( Color( "FireBrick" ) ).text( textView.mText );
	}
	gl::color( Color::white() );
	gl::draw( tbox.render(), fitRect.getUpperLeft() );
}