From ecfad70850a4501179b5c05b48c97d1400fc861a Mon Sep 17 00:00:00 2001 From: Marek Bereza Date: Wed, 14 Aug 2013 14:37:29 +0900 Subject: [PATCH] using custom font is a bit better --- example-textInput/src/testApp.cpp | 7 ++++--- src/ofxTextInputFieldFontRenderer.h | 11 ++++------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/example-textInput/src/testApp.cpp b/example-textInput/src/testApp.cpp index b8f1783..00e1393 100644 --- a/example-textInput/src/testApp.cpp +++ b/example-textInput/src/testApp.cpp @@ -7,7 +7,8 @@ void testApp::setup() { monoLineTextInput.text = "hello world"; monoLineTextInput.bounds.x = 100; monoLineTextInput.bounds.y = 100; - + monoLineTextInput.bounds.height = 40; + monoLineTextInput.bounds.width = 188; multilineTextInput.setup(); multilineTextInput.text = "0: #include \"testApp.h\"\n" @@ -33,8 +34,8 @@ void testApp::setup() { multilineTextInput.bounds.width = 400; multilineTextInput.bounds.height = 500; multilineTextInput.multiline = true; - font.loadFont(OF_TTF_MONO, 10); - multilineTextInput.setFont(font); + font.loadFont(OF_TTF_SERIF, 18); + monoLineTextInput.setFont(font); } diff --git a/src/ofxTextInputFieldFontRenderer.h b/src/ofxTextInputFieldFontRenderer.h index b8eee8e..a6da5e8 100644 --- a/src/ofxTextInputFieldFontRenderer.h +++ b/src/ofxTextInputFieldFontRenderer.h @@ -63,17 +63,14 @@ namespace ofxTextInput { float spacesWidth(const string &str) { - int c = 0; - for(int i =0; i < str.size(); i++) { - if(str[i]==' ') { - c++; - } + if(str.size()>0 && str[str.size()-1]==' ') { + return renderer->getSpaceSize()*renderer->getSize(); } - return c * renderer->getSpaceSize()*renderer->getSize(); + return 0; } float stringWidth(const string &str) { - return renderer->stringWidth(str) + spacesWidth(str); + return renderer->stringWidth(str) + spacesWidth(str) + 3; } };