Deskbar: update time width based on Deskbar orientation.
Fixes #8641
To fix this bug first I had to fix a long-standing todo:
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.
I made TBarView a friend class of TReplicantTray and called
fReplicantTray->fTime->SetOrientation() when switching between
horizontal and vertical mode. I could have added a setter method
instead but I didn't feel like it was worth it.
SetOrientation calls ResizedToPreferred which calls GetPreferredSize,
which resizes the text width, then it calls CalculateTextPlacement
which places the time string correctly.
Removed GetCurrentTime invocation from GetPreferredSize since that
happens in Update already. Was added in
573f748c5f originally.
Also need to call SetOrientation in TReplicantTray::AttachedToWindow
just after creating the TTime object in order for it to resize the
time view correctly on startup in horizontal mode. It needs to know
that it is horizontal so that it will expand to fit longer than
default time string.
This commit is contained in:
committed by
waddlesplash
parent
f5face4114
commit
1dd1976fba
@@ -733,15 +733,18 @@ TBarView::_ChangeState(BMessage* message)
|
||||
// Send a message to the preferences window to let it know to
|
||||
// enable or disable preference items.
|
||||
|
||||
if (vertSwap && fExpandoMenuBar != NULL) {
|
||||
if (fVertical) {
|
||||
fInlineScrollView->SetOrientation(B_VERTICAL);
|
||||
fExpandoMenuBar->SetMenuLayout(B_ITEMS_IN_COLUMN);
|
||||
fExpandoMenuBar->StartMonitoringWindows();
|
||||
} else {
|
||||
fInlineScrollView->SetOrientation(B_HORIZONTAL);
|
||||
fExpandoMenuBar->SetMenuLayout(B_ITEMS_IN_ROW);
|
||||
fExpandoMenuBar->StopMonitoringWindows();
|
||||
if (vertSwap) {
|
||||
fReplicantTray->fTime->SetOrientation(fVertical);
|
||||
if (fExpandoMenuBar != NULL) {
|
||||
if (fVertical) {
|
||||
fInlineScrollView->SetOrientation(B_VERTICAL);
|
||||
fExpandoMenuBar->SetMenuLayout(B_ITEMS_IN_COLUMN);
|
||||
fExpandoMenuBar->StartMonitoringWindows();
|
||||
} else {
|
||||
fInlineScrollView->SetOrientation(B_HORIZONTAL);
|
||||
fExpandoMenuBar->SetMenuLayout(B_ITEMS_IN_ROW);
|
||||
fExpandoMenuBar->StopMonitoringWindows();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,6 +175,7 @@ TReplicantTray::AttachedToWindow()
|
||||
AddChild(fTime);
|
||||
|
||||
fTime->MoveTo(Bounds().right - fTime->Bounds().Width() - kTrayPadding, 2);
|
||||
fTime->SetOrientation(fMultiRowMode);
|
||||
|
||||
if (!((TBarApp*)be_app)->Settings()->showClock)
|
||||
fTime->Hide();
|
||||
|
||||
@@ -167,6 +167,7 @@ private:
|
||||
status_t _SaveSettings();
|
||||
|
||||
friend class TReplicantShelf;
|
||||
friend class TBarView;
|
||||
|
||||
TTimeView* fTime;
|
||||
TBarView* fBarView;
|
||||
|
||||
@@ -51,6 +51,8 @@ All rights reserved.
|
||||
#include <Screen.h>
|
||||
#include <Window.h>
|
||||
|
||||
#include "BarApp.h"
|
||||
#include "StatusView.h"
|
||||
#include "CalendarMenuWindow.h"
|
||||
|
||||
|
||||
@@ -149,8 +151,8 @@ TTimeView::AttachedToWindow()
|
||||
} else
|
||||
SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
|
||||
|
||||
CalculateTextPlacement();
|
||||
ResizeToPreferred();
|
||||
CalculateTextPlacement();
|
||||
}
|
||||
|
||||
|
||||
@@ -182,15 +184,14 @@ TTimeView::GetPreferredSize(float* width, float* height)
|
||||
{
|
||||
*height = fHeight;
|
||||
|
||||
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, timeWidth)
|
||||
: timeWidth;
|
||||
if (fOrientation) {
|
||||
float appWidth = static_cast<TBarApp*>(be_app)->Settings()->width;
|
||||
*width = fMaxWidth
|
||||
= std::min(appWidth - (kDragRegionWidth + kHMargin) * 2, timeWidth);
|
||||
} else
|
||||
*width = fMaxWidth = timeWidth;
|
||||
}
|
||||
|
||||
|
||||
@@ -312,6 +313,7 @@ void
|
||||
TTimeView::SetOrientation(bool orientation)
|
||||
{
|
||||
fOrientation = orientation;
|
||||
ResizeToPreferred();
|
||||
CalculateTextPlacement();
|
||||
Invalidate();
|
||||
}
|
||||
@@ -459,6 +461,17 @@ TTimeView::CalculateTextPlacement()
|
||||
|
||||
fTimeLocation.y = fDateLocation.y = ceilf((bounds.Height()
|
||||
- rectArray[0].Height() + 1.0) / 2.0 - rectArray[0].top);
|
||||
|
||||
if (fOrientation) {
|
||||
float timeWidth = StringWidth(fCurrentTimeStr);
|
||||
if (timeWidth > fMaxWidth) {
|
||||
// time does not fit, push it over to truncate the left side
|
||||
// to see the entire time string you must make the window wider
|
||||
float difference = timeWidth - fMaxWidth;
|
||||
fDateLocation.x -= difference;
|
||||
fTimeLocation.x -= difference;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -496,8 +509,8 @@ TTimeView::Update()
|
||||
GetCurrentDate();
|
||||
SetToolTip(fCurrentDateStr);
|
||||
|
||||
CalculateTextPlacement();
|
||||
ResizeToPreferred();
|
||||
CalculateTextPlacement();
|
||||
|
||||
if (fParent != NULL)
|
||||
fParent->Invalidate();
|
||||
|
||||
Reference in New Issue
Block a user