[haiku-commits] haiku: hrev52063 - src/apps/deskbar

  • From: waddlesplash <waddlesplash@xxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 4 Jul 2018 08:31:27 -0400 (EDT)

hrev52063 adds 1 changeset to branch 'master'
old head: f5face4114b1fad794b65e355b58586bad21713e
new head: 1dd1976fbaa9dae0f91b69ed608452de11c71083
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=1dd1976fbaa9+%5Ef5face4114b1

----------------------------------------------------------------------------

1dd1976fbaa9: 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
  573f748c5f8fb7ed75beb0ceb7eb097d3ab0c038 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.

                                     [ John Scipione <jscipione@xxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev52063
Commit:      1dd1976fbaa9dae0f91b69ed608452de11c71083
URL:         https://git.haiku-os.org/haiku/commit/?id=1dd1976fbaa9
Author:      John Scipione <jscipione@xxxxxxxxx>
Date:        Thu Jan  4 05:50:22 2018 UTC
Committer:   waddlesplash <waddlesplash@xxxxxxxxx>
Commit-Date: Wed Jul  4 12:31:23 2018 UTC

Ticket:      https://dev.haiku-os.org/ticket/8641

----------------------------------------------------------------------------

4 files changed, 36 insertions(+), 18 deletions(-)
src/apps/deskbar/BarView.cpp    | 21 ++++++++++++---------
src/apps/deskbar/StatusView.cpp |  1 +
src/apps/deskbar/StatusView.h   |  1 +
src/apps/deskbar/TimeView.cpp   | 31 ++++++++++++++++++++++---------

----------------------------------------------------------------------------

diff --git a/src/apps/deskbar/BarView.cpp b/src/apps/deskbar/BarView.cpp
index 9f46a53e61..b9ba42a4f3 100644
--- a/src/apps/deskbar/BarView.cpp
+++ b/src/apps/deskbar/BarView.cpp
@@ -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();
+                               }
                        }
                }
        }
diff --git a/src/apps/deskbar/StatusView.cpp b/src/apps/deskbar/StatusView.cpp
index 5a9d2fc093..cc3ed6e632 100644
--- a/src/apps/deskbar/StatusView.cpp
+++ b/src/apps/deskbar/StatusView.cpp
@@ -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();
diff --git a/src/apps/deskbar/StatusView.h b/src/apps/deskbar/StatusView.h
index 14f06e5665..ccaf881929 100644
--- a/src/apps/deskbar/StatusView.h
+++ b/src/apps/deskbar/StatusView.h
@@ -167,6 +167,7 @@ private:
                                status_t                        _SaveSettings();
 
        friend class TReplicantShelf;
+       friend class TBarView;
 
                                TTimeView*                      fTime;
                                TBarView*                       fBarView;
diff --git a/src/apps/deskbar/TimeView.cpp b/src/apps/deskbar/TimeView.cpp
index 4fb05facac..5ea67ea13b 100644
--- a/src/apps/deskbar/TimeView.cpp
+++ b/src/apps/deskbar/TimeView.cpp
@@ -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();


Other related posts:

  • » [haiku-commits] haiku: hrev52063 - src/apps/deskbar - waddlesplash