From a431f44be88d3d0f1748a1fe032c1159dab8d11c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sat, 1 Sep 2007 12:51:59 +0000 Subject: [PATCH] * make the text view layouting more robust, draw the frame around the text view, ignore the divider for this (application code could layout the textview itself, and fDivider might not be maintained) * change Draw() and TextInput::MakeFocus() accordingly this fixes the weird placement of text controls in Beam git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22134 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/os/interface/TextControl.h | 1 + src/kits/interface/TextControl.cpp | 44 ++++++++++++++++++++---------- src/kits/interface/TextInput.cpp | 3 +- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/headers/os/interface/TextControl.h b/headers/os/interface/TextControl.h index 86755d149c..6f4af72c73 100644 --- a/headers/os/interface/TextControl.h +++ b/headers/os/interface/TextControl.h @@ -101,6 +101,7 @@ class BTextControl : public BControl { void _InitData(const char* label, const char* initialText, BMessage* archive = NULL); void _ValidateLayout(); + void _LayoutTextView(); void _UpdateFrame(); private: diff --git a/src/kits/interface/TextControl.cpp b/src/kits/interface/TextControl.cpp index 050cccb426..6784a07787 100644 --- a/src/kits/interface/TextControl.cpp +++ b/src/kits/interface/TextControl.cpp @@ -252,14 +252,9 @@ BTextControl::GetAlignment(alignment* _label, alignment* _text) const void BTextControl::SetDivider(float dividingLine) { - dividingLine = floorf(dividingLine + 0.5); + fDivider = floorf(dividingLine + 0.5); - float dx = fDivider - dividingLine; - - fDivider = dividingLine; - - fText->MoveBy(-dx, 0.0f); - fText->ResizeBy(dx, 0.0f); + _LayoutTextView(); if (Window()) { fText->Invalidate(); @@ -295,8 +290,8 @@ BTextControl::Draw(BRect updateRect) // outer bevel - BRect rect = Bounds(); - rect.left = fDivider; + BRect rect = fText->Frame(); + rect.InsetBy(-2, -2); if (enabled) SetHighColor(darken1); @@ -363,7 +358,7 @@ BTextControl::Draw(BRect updateRect) ceilf(fontHeight.ascent + fontHeight.descent) + 1); if (x < fDivider && updateRect.Intersects(labelArea)) { labelArea.right = fDivider; - + BRegion clipRegion(labelArea); ConstrainClippingRegion(&clipRegion); SetHighColor(IsEnabled() ? ui_color(B_CONTROL_TEXT_COLOR) @@ -434,7 +429,7 @@ BTextControl::GetPreferredSize(float *_width, float *_height) GetFontHeight(&fontHeight); float labelHeight = ceil(fontHeight.ascent + fontHeight.descent + fontHeight.leading); - float textHeight = fText->LineHeight(0) + 4.0; + float textHeight = ceilf(fText->LineHeight(0)) + 4.0; *_height = max_c(labelHeight, textHeight); } @@ -765,14 +760,35 @@ BTextControl::_ValidateLayout() ResizeTo(Bounds().Width(), height); - float lineHeight = ceil(fText->LineHeight(0)); - fText->ResizeTo(fText->Bounds().Width(), lineHeight); - fText->MoveTo(fText->Frame().left, (height - lineHeight) / 2); + _LayoutTextView(); fPreviousHeight = Bounds().Height(); } +void +BTextControl::_LayoutTextView() +{ + BRect frame = Bounds(); + frame.left = fDivider; + // we are stroking the frame around the text view, which + // is 2 pixels wide + frame.InsetBy(2.0, 2.0); + fText->MoveTo(frame.left, frame.top); + fText->ResizeTo(frame.Width(), frame.Height()); + + BRect textRect(frame.OffsetToCopy(B_ORIGIN)); + + // the label font could require the control to be higher than + // necessary for the text view, we compensate this by layouting + // the text rect to be in the middle, normally this means there + // is one pixel spacing on each side + float lineHeight = ceilf(fText->LineHeight(0)); + textRect.InsetBy(1, floorf((frame.Height() - lineHeight) / 2)); + fText->SetTextRect(textRect); +} + + void BTextControl::_UpdateFrame() { diff --git a/src/kits/interface/TextInput.cpp b/src/kits/interface/TextInput.cpp index 767cd3d86f..9b92d7ea13 100644 --- a/src/kits/interface/TextInput.cpp +++ b/src/kits/interface/TextInput.cpp @@ -141,8 +141,7 @@ _BTextInput_::MakeFocus(bool state) // I'm leaving this in, but it looks suspicious... :-) Invalidate(Bounds()); if (BTextControl* parent = dynamic_cast(Parent())) { - BRect frame = parent->Bounds(); - frame.left = parent->Divider(); + BRect frame = Frame(); frame.InsetBy(-1.0, -1.0); parent->Invalidate(frame); }