From 1b75cbdcc93ebe63c4eae9e12107ce3ebf8ca7a6 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Mon, 20 Aug 2012 20:41:38 +0100 Subject: [PATCH] Limit on text width in textboxes --- src/interface/Textbox.cpp | 7 +++++-- src/preview/PreviewView.cpp | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/interface/Textbox.cpp b/src/interface/Textbox.cpp index 341e4f5dc..57f9a26ac 100644 --- a/src/interface/Textbox.cpp +++ b/src/interface/Textbox.cpp @@ -361,7 +361,10 @@ void Textbox::OnVKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool cursor = getLowerSelectionBound(); } - if(limit==std::string::npos || backingText.length() < limit) + int regionWidth = Size.X; + if(Appearance.icon) + regionWidth -= 17; + if((limit==std::string::npos || backingText.length() < limit) && (Graphics::textwidth((char*)std::string(backingText+char(character)).c_str()) <= regionWidth || multiline || limit!=std::string::npos)) { if(cursor == backingText.length()) { @@ -371,8 +374,8 @@ void Textbox::OnVKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool { backingText.insert(cursor, 1, (char)character); } + cursor++; } - cursor++; changed = true; ClearSelection(); } diff --git a/src/preview/PreviewView.cpp b/src/preview/PreviewView.cpp index 762cf8034..5b7952b23 100644 --- a/src/preview/PreviewView.cpp +++ b/src/preview/PreviewView.cpp @@ -169,7 +169,7 @@ void PreviewView::commentBoxAutoHeight() if(!addCommentBox) return; int textWidth = Graphics::textwidth(addCommentBox->GetText().c_str()); - if(textWidth+5 > Size.X-(XRES/2)-48) + if(textWidth+10 > Size.X-(XRES/2)-48) { commentBoxHeight = 59; addCommentBox->SetMultiline(true);