From 70ad528943bd5953fb5fef835402841b281cf69c Mon Sep 17 00:00:00 2001 From: John Scipione Date: Thu, 19 Oct 2017 16:07:34 -0700 Subject: [PATCH] Deskbar: Position clock & replicants better This fixes some subtle layout issues. The replicant icon positions and clock position has been made more consistent in both vertical mode, and horizontal mode. There is a fixed amount of space between the last replicant and the clock before it wraps to next row. This now works at different font sizes. Use matching 3px of space between the clock and the dragger on one side and and between the replicant and the dragger on the other side. Reparent ResizeControl from ReplicantTray onto DragRegion and readjust everything. --- src/apps/deskbar/BarView.cpp | 38 ++++++++++++++++++++++++--------- src/apps/deskbar/StatusView.cpp | 27 +++++++++++------------ src/apps/deskbar/StatusView.h | 1 + src/apps/deskbar/TimeView.cpp | 8 +++---- 4 files changed, 45 insertions(+), 29 deletions(-) diff --git a/src/apps/deskbar/BarView.cpp b/src/apps/deskbar/BarView.cpp index 8f57856dcd..64f478d6e7 100644 --- a/src/apps/deskbar/BarView.cpp +++ b/src/apps/deskbar/BarView.cpp @@ -160,16 +160,22 @@ TBarView::TBarView(BRect frame, bool vertical, bool left, bool top, fBarMenuBar = new TBarMenuBar(menuFrame, "BarMenuBar", this); AddChild(fBarMenuBar); - // create and add the status tray + // create the status tray fReplicantTray = new TReplicantTray(this, fVertical); + + // create the resize control + fResizeControl = new TResizeControl(this); + + // create the drag region and add the resize control + // and replicant tray to it fDragRegion = new TDragRegion(this, fReplicantTray); + fDragRegion->AddChild(fResizeControl); fDragRegion->AddChild(fReplicantTray); + + // Add the drag region if (fTrayLocation != 0) AddChild(fDragRegion); - fResizeControl = new TResizeControl(this); - fReplicantTray->AddChild(fResizeControl); - // create and add the application menubar fExpandoMenuBar = new TExpandoMenuBar(this, fVertical); fInlineScrollView = new TInlineScrollView(fExpandoMenuBar, @@ -455,15 +461,27 @@ TBarView::PlaceTray(bool vertSwap, bool leftSwap) fReplicantTray->SetMultiRow(fVertical); fReplicantTray->RealignReplicants(); fDragRegion->ResizeToPreferred(); + // also resizes replicant tray - fResizeControl->ResizeTo(kDragWidth, fDragRegion->Bounds().Height()); + fResizeControl->ResizeTo(kDragWidth, fDragRegion->Bounds().Height() + - 2); // make room for top and bottom border if (fVertical) { if (fResizeControl->IsHidden()) fResizeControl->Show(); - // move replicant tray past dragger width on left - // also down 1 pixel so that it won't cover the border - fReplicantTray->MoveTo(fLeft ? kDragWidth + kGutter : 0, kGutter); + + if (fLeft) { + // move replicant tray past dragger width on left + // also down 1px so it won't cover the border + fReplicantTray->MoveTo(kDragWidth + kGutter, kGutter); + + // shrink width by same amount + fReplicantTray->ResizeBy(-(kDragWidth + kGutter), 0); + } else { + // move replicant tray down 1px so it won't cover the border + fReplicantTray->MoveTo(0, kGutter); + } + statusLoc.x = 0; statusLoc.y = fBarMenuBar->Frame().bottom + 1; } else { @@ -481,9 +499,9 @@ TBarView::PlaceTray(bool vertSwap, bool leftSwap) fDragRegion->Invalidate(); if (fVertical && fLeft) - fResizeControl->MoveTo(fReplicantTray->Bounds().right - 3, 0); + fResizeControl->MoveTo(fDragRegion->Bounds().right - kDragWidth, 1); else - fResizeControl->MoveTo(0, 0); + fResizeControl->MoveTo(0, 1); fResizeControl->Invalidate(); } diff --git a/src/apps/deskbar/StatusView.cpp b/src/apps/deskbar/StatusView.cpp index 5fd30a02ba..112ce979e0 100644 --- a/src/apps/deskbar/StatusView.cpp +++ b/src/apps/deskbar/StatusView.cpp @@ -173,11 +173,7 @@ TReplicantTray::AttachedToWindow() AddChild(fTime); - float deltaX = Bounds().right - fTime->Bounds().Width() - 1; - if (fBarView->Vertical() && !fBarView->Left()) - deltaX -= kDragWidth; - - fTime->MoveTo(deltaX, 2); + fTime->MoveTo(Bounds().right - fTime->Bounds().Width() - kTrayPadding, 2); if (!((TBarApp*)be_app)->Settings()->showClock) fTime->Hide(); @@ -234,7 +230,7 @@ TReplicantTray::GetPreferredSize(float* preferredWidth, float* preferredHeight) width = fRightBottomReplicant.right + 12 + fTime->Frame().Width(); } else - width = fRightBottomReplicant.right + 3; + width = fRightBottomReplicant.right + kIconGap + kGutter; } // this view has a fixed minimum width @@ -1156,11 +1152,12 @@ TReplicantTray::AcceptAddon(BRect replicantFrame, BMessage* message) BPoint TReplicantTray::LocationForReplicant(int32 index, float width) { - BPoint loc(kIconGap + 1, kGutter + 1); - if (fBarView->Vertical() && !fBarView->Left()) - loc.x += kDragWidth; - else if (!fBarView->Vertical()) - loc.x += kGutter; + BPoint loc(kTrayPadding, 2); + if (fBarView->Vertical()) { + if (!fBarView->Left()) + loc.x += kDragWidth; // move past dragger + } else + loc.x += 1; // keeps everything lined up nicely if (fMultiRowMode) { // try to find free space in every row @@ -1168,11 +1165,11 @@ TReplicantTray::LocationForReplicant(int32 index, float width) // determine free space in this row BRect rect(loc.x, loc.y, loc.x + static_cast(be_app)->Settings()->width - - kDragRegionWidth - kGutter, + - kDragRegionWidth * 2, loc.y + kMaxReplicantHeight); if (row == 0 && !fTime->IsHidden()) { - rect.right -= fTime->Frame().Width() + kDragRegionWidth - + kIconGap + kDragWidth; + rowRect.right -= kClockMargin + fTime->Frame().Width() + + kTrayPadding; } for (int32 i = 0; i < index; i++) { @@ -1347,7 +1344,7 @@ TDragRegion::GetPreferredSize(float* width, float* height) void -TDragRegion::Draw(BRect) +TDragRegion::Draw(BRect updateRect) { rgb_color menuColor = ViewColor(); rgb_color hilite = tint_color(menuColor, B_DARKEN_1_TINT); diff --git a/src/apps/deskbar/StatusView.h b/src/apps/deskbar/StatusView.h index 888989a048..6c1761f66a 100644 --- a/src/apps/deskbar/StatusView.h +++ b/src/apps/deskbar/StatusView.h @@ -53,6 +53,7 @@ const int32 kMinimumReplicantCount = 6; const int32 kIconGap = 2; const int32 kGutter = 1; const int32 kDragRegionWidth = 6; +const int32 kTrayPadding = 3; // 1 pixel for left gutter // space for replicant tray (6 items) diff --git a/src/apps/deskbar/TimeView.cpp b/src/apps/deskbar/TimeView.cpp index b811ce762a..4187a916ab 100644 --- a/src/apps/deskbar/TimeView.cpp +++ b/src/apps/deskbar/TimeView.cpp @@ -178,13 +178,13 @@ TTimeView::GetPreferredSize(float* width, float* height) GetCurrentTime(); + float timeWidth = StringWidth(fCurrentTimeStr); + // TODO: SetOrientation never gets called, fix that when in vertical mode, // we want to limit the width so that it can't overlap the bevels in the // parent view. - *width = fOrientation - ? std::min(fMaxWidth - kHMargin, - kHMargin + StringWidth(fCurrentTimeStr)) - : kHMargin + StringWidth(fCurrentTimeStr); + *width = fOrientation ? std::min(fMaxWidth - kHMargin, timeWidth) + : timeWidth; }