From fac73debbf533c983c815723dbd85321489b1afb Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Mon, 29 Aug 2022 15:55:41 -0400 Subject: [PATCH] Deskbar: Compute basic metrics earlier, in TBarApp::InitSettings(). This way we know the minimum and maximum window width earlier and consumers of them do not come up with "0" incorrectly. Fixes #17890. --- src/apps/deskbar/BarApp.cpp | 20 ++++++++++++++++++++ src/apps/deskbar/StatusView.cpp | 22 +--------------------- src/apps/deskbar/StatusView.h | 1 + 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/apps/deskbar/BarApp.cpp b/src/apps/deskbar/BarApp.cpp index 10ae5d4536..9053f1dc32 100644 --- a/src/apps/deskbar/BarApp.cpp +++ b/src/apps/deskbar/BarApp.cpp @@ -234,6 +234,26 @@ TBarApp::SaveSettings() void TBarApp::InitSettings() { + // compute metrics + sIconGap = ceilf(be_control_look->DefaultLabelSpacing() / 3.0f); + + gDragRegionWidth = be_control_look->ComposeSpacing(B_USE_HALF_ITEM_SPACING); + gDragWidth = ceilf(gDragRegionWidth * 0.6f); + + gMinReplicantHeight = gMinReplicantWidth = + be_control_look->ComposeIconSize(B_MINI_ICON).IntegerWidth() + 1; + + // 1 pixel for left gutter + // space for replicant tray (6 items) + // 6 pixel drag region + gMinimumTrayWidth = sIconGap + gMinReplicantWidth + + (kMinimumReplicantCount * sIconGap) + + (kMinimumReplicantCount * gMinReplicantWidth) + kGutter; + + gMinimumWindowWidth = kGutter + gMinimumTrayWidth + gDragRegionWidth; + gMaximumWindowWidth = gMinimumWindowWidth * 2; + + // defaults desk_settings settings; settings.vertical = fDefaultSettings.vertical = true; settings.left = fDefaultSettings.left = false; diff --git a/src/apps/deskbar/StatusView.cpp b/src/apps/deskbar/StatusView.cpp index 3f7ff412c9..a2b07b86b6 100644 --- a/src/apps/deskbar/StatusView.cpp +++ b/src/apps/deskbar/StatusView.cpp @@ -79,7 +79,7 @@ All rights reserved. static const float kVerticalMiniMultiplier = 2.9f; -static float sIconGap = 0.0f; +float sIconGap = 0.0f; float gDragWidth, gDragRegionWidth = 0.0f; float gMinReplicantHeight, gMinReplicantWidth = 0.0f; float gMinimumTrayWidth, gMinimumWindowWidth, gMaximumWindowWidth = 0.0f; @@ -142,26 +142,6 @@ TReplicantTray::TReplicantTray(TBarView* barView) fShelf(new TReplicantShelf(this)), fAlignmentSupport(false) { - if (sIconGap == 0.0f) { - sIconGap = ceilf(be_control_look->DefaultLabelSpacing() / 3.0f); - - gDragRegionWidth = be_control_look->ComposeSpacing(B_USE_HALF_ITEM_SPACING); - gDragWidth = ceilf(gDragRegionWidth * 0.6f); - - gMinReplicantHeight = gMinReplicantWidth = - be_control_look->ComposeIconSize(B_MINI_ICON).IntegerWidth() + 1; - - // 1 pixel for left gutter - // space for replicant tray (6 items) - // 6 pixel drag region - gMinimumTrayWidth = sIconGap + gMinReplicantWidth - + (kMinimumReplicantCount * sIconGap) - + (kMinimumReplicantCount * gMinReplicantWidth) + kGutter; - - gMinimumWindowWidth = kGutter + gMinimumTrayWidth + gDragRegionWidth; - gMaximumWindowWidth = gMinimumWindowWidth * 2; - } - // scale replicants by font size fMaxReplicantHeight = std::max(gMinReplicantHeight, float(((TBarApp*)be_app)->IconSize())); diff --git a/src/apps/deskbar/StatusView.h b/src/apps/deskbar/StatusView.h index 90582eda6e..fd8c8f5f5b 100644 --- a/src/apps/deskbar/StatusView.h +++ b/src/apps/deskbar/StatusView.h @@ -54,6 +54,7 @@ const int32 kGutter = 1; const int32 kTrayPadding = B_USE_HALF_ITEM_SPACING; const int32 kClockMargin = 12; +extern float sIconGap; extern float gDragWidth, gDragRegionWidth; extern float gMinReplicantHeight, gMinReplicantWidth; extern float gMinimumTrayWidth, gMinimumWindowWidth, gMaximumWindowWidth;