diff --git a/headers/private/shared/StatusView.h b/headers/private/shared/StatusView.h new file mode 100644 index 0000000000..9a96dc5494 --- /dev/null +++ b/headers/private/shared/StatusView.h @@ -0,0 +1,5 @@ +namespace BPrivate { + +void AdoptScrollBarFontSize(BView*); + +} // namespace BPrivate diff --git a/src/apps/stylededit/StatusView.cpp b/src/apps/stylededit/StatusView.cpp index 243d333b3e..c13d39a931 100644 --- a/src/apps/stylededit/StatusView.cpp +++ b/src/apps/stylededit/StatusView.cpp @@ -9,6 +9,7 @@ #include "StatusView.h" +#include #include #include @@ -63,7 +64,7 @@ void StatusView::AttachedToWindow() { SetFont(be_plain_font); - SetFontSize(ceilf(be_plain_font->Size() * 0.83f)); + BPrivate::AdoptScrollBarFontSize(this); BMessage message(UPDATE_STATUS); message.AddInt32("line", 1); diff --git a/src/kits/shared/Jamfile b/src/kits/shared/Jamfile index aea432cbe7..bf0e23b2c4 100644 --- a/src/kits/shared/Jamfile +++ b/src/kits/shared/Jamfile @@ -59,6 +59,7 @@ for architectureObject in [ MultiArchSubDirSetup ] { SettingsHandler.cpp SettingsMessage.cpp ShakeTrackingFilter.cpp + StatusView.cpp StringForRate.cpp StringForSize.cpp StripeView.cpp diff --git a/src/kits/shared/StatusView.cpp b/src/kits/shared/StatusView.cpp new file mode 100644 index 0000000000..542799278c --- /dev/null +++ b/src/kits/shared/StatusView.cpp @@ -0,0 +1,41 @@ +/* + * Copyright 2021, Pascal R. G. Abresch, nep@packageloss.eu. + * Distributed under the terms of the MIT License. + */ + +#include +#include + + +namespace BPrivate { + + +void +AdoptScrollBarFontSize(BView* view) +{ + float maxSize = be_control_look->GetScrollBarWidth(); + BFont testFont = be_plain_font; + float currentSize; + font_height fontHeight; + + float minFontSize = 0.0f; + float maxFontSize = 48.0f; + + while (maxFontSize - minFontSize > 1.0f) { + float midFontSize = (maxFontSize + minFontSize) / 2.0f; + + testFont.SetSize(midFontSize); + testFont.GetHeight(&fontHeight); + currentSize = fontHeight.ascent + fontHeight.descent; + + if (currentSize > maxSize) + maxFontSize = midFontSize; + else + minFontSize = midFontSize; + } + + view->SetFontSize(minFontSize); +} + + +} // namespace BPrivate