From d8b517b50f1a5a04e959ec2bfb0011b07f931793 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 9 Sep 2015 20:43:48 +0200 Subject: [PATCH] Tracker: made title view height depend on font size. * It now uses a font that's 3/4 the size of the plain font; ie. there shouldn't be any change with the default font size. * Also cleaned up some weird layout code on the way. --- src/kits/tracker/ContainerWindow.cpp | 14 ++++--------- src/kits/tracker/FilePanelPriv.cpp | 7 +------ src/kits/tracker/PoseView.cpp | 2 +- src/kits/tracker/TitleView.cpp | 31 +++++++++++++++++++++++----- src/kits/tracker/TitleView.h | 6 +++++- 5 files changed, 37 insertions(+), 23 deletions(-) diff --git a/src/kits/tracker/ContainerWindow.cpp b/src/kits/tracker/ContainerWindow.cpp index 2f7218468a..abc50c1469 100644 --- a/src/kits/tracker/ContainerWindow.cpp +++ b/src/kits/tracker/ContainerWindow.cpp @@ -953,18 +953,12 @@ BContainerWindow::Init(const BMessage* message) void BContainerWindow::InitLayout() { - BLayoutItem* item - = fBorderedView->GroupLayout()->AddView(0, fPoseView->TitleView()); - BSize minSize = item->MinSize(); - BSize maxSize = item->MaxSize(); - item->SetExplicitMinSize(BSize(minSize.Width(), kTitleViewHeight)); - item->SetExplicitMaxSize(BSize(maxSize.Width(), kTitleViewHeight)); + fBorderedView->GroupLayout()->AddView(0, fPoseView->TitleView()); - item = fCountContainer->GroupLayout()->AddView(fPoseView->CountView()); - minSize = item->MinSize(); - maxSize = item->MaxSize(); + BLayoutItem* item = fCountContainer->GroupLayout()->AddView( + fPoseView->CountView()); item->SetExplicitMinSize(BSize(kCountViewWidth, B_H_SCROLL_BAR_HEIGHT)); - item->SetExplicitMaxSize(BSize(kCountViewWidth, maxSize.Height())); + item->SetExplicitMaxSize(BSize(kCountViewWidth, B_SIZE_UNSET)); // Eliminate the extra borders fMenuContainer->GroupLayout()->SetInsets(0, 0, -1, 0); diff --git a/src/kits/tracker/FilePanelPriv.cpp b/src/kits/tracker/FilePanelPriv.cpp index de0469fcf6..4616e43531 100644 --- a/src/kits/tracker/FilePanelPriv.cpp +++ b/src/kits/tracker/FilePanelPriv.cpp @@ -899,12 +899,7 @@ TFilePanel::RestoreState() } // Finish UI creation now that the PoseView is initialized - BLayoutItem* item - = fBorderedView->GroupLayout()->AddView(0, fPoseView->TitleView()); - BSize minSize = item->MinSize(); - BSize maxSize = item->MaxSize(); - item->SetExplicitMinSize(BSize(minSize.Width(), kTitleViewHeight)); - item->SetExplicitMaxSize(BSize(maxSize.Width(), kTitleViewHeight)); + fBorderedView->GroupLayout()->AddView(0, fPoseView->TitleView()); BRect rect(fBorderedView->Frame()); rect.right = rect.left + kCountViewWidth; diff --git a/src/kits/tracker/PoseView.cpp b/src/kits/tracker/PoseView.cpp index 0245e8b828..8195ca94d9 100644 --- a/src/kits/tracker/PoseView.cpp +++ b/src/kits/tracker/PoseView.cpp @@ -9911,7 +9911,7 @@ BPoseView::CheckAutoScroll(BPoint mouseLoc, bool shouldScroll) border.bottom = border.top; border.top -= kBorderHeight; if (ViewMode() == kListMode) - border.top -= kTitleViewHeight; + border.top -= TitleView()->Bounds().Height(); bool selectionScrolling = fSelectionRectInfo.isDragging; diff --git a/src/kits/tracker/TitleView.cpp b/src/kits/tracker/TitleView.cpp index bf9adb02c1..01b407a53b 100644 --- a/src/kits/tracker/TitleView.cpp +++ b/src/kits/tracker/TitleView.cpp @@ -124,9 +124,13 @@ BTitleView::BTitleView(BPoseView* view) #endif BFont font(be_plain_font); - font.SetSize(9); + font.SetSize(floorf(be_plain_font->Size() * 0.75f)); SetFont(&font); + font_height height; + GetFontHeight(&height); + fPreferredHeight = ceilf(height.ascent + height.descent) + 2; + Reset(); } @@ -190,6 +194,20 @@ BTitleView::RemoveTitle(BColumn* column) } +BSize +BTitleView::MinSize() +{ + return BSize(16, fPreferredHeight); +} + + +BSize +BTitleView::MaxSize() +{ + return BSize(B_SIZE_UNLIMITED, fPreferredHeight); +} + + void BTitleView::Draw(BRect rect) { @@ -215,8 +233,8 @@ BTitleView::Draw(BRect /*updateRect*/, bool useOffscreen, bool updateOnly, view->SetOrigin(-bounds.left, 0); view->SetLowColor(LowColor()); view->SetHighColor(HighColor()); - BFont font(be_plain_font); - font.SetSize(9); + BFont font; + GetFont(&font); view->SetFont(&font); } else view = this; @@ -452,7 +470,7 @@ BRect BColumnTitle::Bounds() const { BRect bounds(fColumn->Offset() - kTitleColumnLeftExtraMargin, 0, 0, - kTitleViewHeight); + fParent->Bounds().Height()); bounds.right = bounds.left + fColumn->Width() + kTitleColumnExtraMargin; return bounds; @@ -463,7 +481,10 @@ void BColumnTitle::Draw(BView* view, bool pressed) { BRect bounds(Bounds()); - BPoint loc(0, bounds.bottom - 4); + + font_height height; + view->GetFontHeight(&height); + BPoint loc(0, bounds.top + ceilf(height.ascent) + 2); if (pressed) { bounds.bottom--; diff --git a/src/kits/tracker/TitleView.h b/src/kits/tracker/TitleView.h index 959632e098..4ce1b4fb19 100644 --- a/src/kits/tracker/TitleView.h +++ b/src/kits/tracker/TitleView.h @@ -50,7 +50,6 @@ class BColumnTitle; class ColumnTrackState; class OffscreenBitmap; -const int32 kTitleViewHeight = 16; const int32 kEdgeSize = 6; const int32 kTitleColumnLeftExtraMargin = 11; const int32 kTitleColumnRightExtraMargin = 5; @@ -70,6 +69,9 @@ public: virtual void MouseUp(BPoint where); virtual void Draw(BRect updateRect); + virtual BSize MinSize(); + virtual BSize MaxSize(); + void Draw(BRect, bool useOffscreen = false, bool updateOnly = true, const BColumnTitle* pressedColumn = 0, @@ -90,9 +92,11 @@ private: BColumnTitle* InColumnResizeArea(BPoint) const; BColumnTitle* FindColumnTitle(const BColumn*) const; +private: BPoseView* fPoseView; BObjectList fTitleList; BCursor fHorizontalResizeCursor; + float fPreferredHeight; BColumnTitle* fPreviouslyClickedColumnTitle; bigtime_t fPreviousLeftClickTime;