From 1bdc2a52032e19f602b65e92e4ee5665fcd6d9f6 Mon Sep 17 00:00:00 2001 From: Karsten Heimrich Date: Thu, 4 Sep 2008 22:05:40 +0000 Subject: [PATCH] * ResizeToPreferred und GetPreferredSize now behave more closely to R5 this fixes mostly all windows containing TextControls in ArtPaint and should fix also ticket #2543 ArtPaint was calling the BTextControl ctor with an empty rect, followed by ResizeToPreferred, which made in the best case the TextInput visible but it did not take the label into account. Should help more R5 apps. Some more tests on R5 have shown that even if you pass an extra large width, a call to ResizeToPreferred will not respect the passed width. Also the _BTextInput_ seems to grow with the length of the passed label. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27330 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/interface/TextControl.cpp | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/kits/interface/TextControl.cpp b/src/kits/interface/TextControl.cpp index ebb365a340..88ee87a41d 100644 --- a/src/kits/interface/TextControl.cpp +++ b/src/kits/interface/TextControl.cpp @@ -120,7 +120,7 @@ BTextControl::BTextControl(BMessage* archive) if (archive->HasInt32("_a_text")) archive->FindInt32("_a_text", &textAlignment); - + SetAlignment((alignment)labelAlignment, (alignment)textAlignment); if (archive->HasFloat("_divide")) @@ -432,11 +432,12 @@ BTextControl::GetPreferredSize(float *_width, float *_height) } if (_width) { - // TODO: this one I need to find out - float width = 20.0f + ceilf(StringWidth(Label())); - if (width < Bounds().Width()) - width = Bounds().Width(); - *_width = width; + *_width = Bounds().Width(); + const char* label = Label(); + if (label) { + float width = ceilf(StringWidth(label)); + *_width = (width * 1.3) + width + 4.0; + } } } @@ -444,8 +445,14 @@ BTextControl::GetPreferredSize(float *_width, float *_height) void BTextControl::ResizeToPreferred() { - // TODO: change divider? BView::ResizeToPreferred(); + + fDivider = 0.0; + const char* label = Label(); + if (label) + fDivider = ceil(StringWidth(label)) + 2.0; + + _LayoutTextView(); } @@ -752,10 +759,10 @@ BTextControl::_InitData(const char* label, const char* initialText, void BTextControl::_ValidateLayout() { - float height; - BTextControl::GetPreferredSize(NULL, &height); + float width, height; + BTextControl::GetPreferredSize(&width, &height); - ResizeTo(Bounds().Width(), height); + ResizeTo(width, height); _LayoutTextView();