From 86da03857de7fb5714089f6851d2e28936504fd0 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Fri, 9 Sep 2022 17:37:42 -0400 Subject: [PATCH] Appearance: Use a dynamic instead of fixed size for the text preview area. Fixes #17872. --- .../appearance/FontSelectionView.cpp | 18 ++++++++---------- src/preferences/appearance/FontSelectionView.h | 2 +- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/preferences/appearance/FontSelectionView.cpp b/src/preferences/appearance/FontSelectionView.cpp index d492308b3f..bd41653d18 100644 --- a/src/preferences/appearance/FontSelectionView.cpp +++ b/src/preferences/appearance/FontSelectionView.cpp @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -41,7 +42,6 @@ static const float kMinSize = 8.0; static const float kMaxSize = 72.0; -static const float kPreviewTextWidth = 350.0; static const char* kPreviewText = B_TRANSLATE_COMMENT( "The quick brown fox jumps over the lazy dog.", @@ -133,13 +133,15 @@ FontSelectionView::FontSelectionView(const char* name, fPreviewTextView->MakeEditable(false); fPreviewTextView->MakeSelectable(false); fPreviewTextView->SetInsets(0, 0, 0, 0); - fPreviewTextView->SetViewColor(ViewColor()); - fPreviewTextView->SetLowColor(LowColor()); + fPreviewTextView->SetViewUIColor(ViewUIColor()); + fPreviewTextView->SetLowUIColor(LowUIColor()); + fPreviewTextView->SetHighUIColor(HighUIColor()); // determine initial line count using fCurrentFont + fPreviewTextWidth = be_control_look->DefaultLabelSpacing() * 58.0f; float lineCount = ceilf(fCurrentFont.StringWidth(kPreviewText) - / kPreviewTextWidth); - fPreviewTextView->SetExplicitSize(BSize(kPreviewTextWidth, + / fPreviewTextWidth); + fPreviewTextView->SetExplicitSize(BSize(fPreviewTextWidth, fPreviewTextView->LineHeight(0) * lineCount)); // box around preview @@ -304,7 +306,7 @@ FontSelectionView::_UpdateFontPreview() #endif fPreviewTextView->SetFontAndColor(&fCurrentFont); - fPreviewTextView->SetExplicitSize(BSize(kPreviewTextWidth, + fPreviewTextView->SetExplicitSize(BSize(fPreviewTextWidth, fPreviewTextView->LineHeight(0) * fPreviewTextView->CountLines())); } @@ -447,10 +449,6 @@ FontSelectionView::UpdateFontsMenu() continue; } - float width = font.StringWidth(family); - if (width > fMaxFontNameWidth) - fMaxFontNameWidth = width; - BMenu* stylesMenu = new BMenu(family); stylesMenu->SetRadioMode(true); stylesMenu->SetFont(&font); diff --git a/src/preferences/appearance/FontSelectionView.h b/src/preferences/appearance/FontSelectionView.h index 3bcf78853e..d0ec210e6c 100644 --- a/src/preferences/appearance/FontSelectionView.h +++ b/src/preferences/appearance/FontSelectionView.h @@ -66,10 +66,10 @@ protected: BBox* fPreviewBox; BTextView* fPreviewTextView; + float fPreviewTextWidth; BFont fSavedFont; BFont fCurrentFont; - float fMaxFontNameWidth; }; #endif // FONT_SELECTION_VIEW_H