Appearance: Use a dynamic instead of fixed size for the text preview area.

Fixes #17872.
This commit is contained in:
Augustin Cavalier
2022-09-09 17:37:42 -04:00
parent 66af664352
commit 86da03857d
2 changed files with 9 additions and 11 deletions
@@ -16,6 +16,7 @@
#include <Box.h> #include <Box.h>
#include <Catalog.h> #include <Catalog.h>
#include <ControlLook.h>
#include <GroupLayoutBuilder.h> #include <GroupLayoutBuilder.h>
#include <LayoutItem.h> #include <LayoutItem.h>
#include <Locale.h> #include <Locale.h>
@@ -41,7 +42,6 @@
static const float kMinSize = 8.0; static const float kMinSize = 8.0;
static const float kMaxSize = 72.0; static const float kMaxSize = 72.0;
static const float kPreviewTextWidth = 350.0;
static const char* kPreviewText = B_TRANSLATE_COMMENT( static const char* kPreviewText = B_TRANSLATE_COMMENT(
"The quick brown fox jumps over the lazy dog.", "The quick brown fox jumps over the lazy dog.",
@@ -133,13 +133,15 @@ FontSelectionView::FontSelectionView(const char* name,
fPreviewTextView->MakeEditable(false); fPreviewTextView->MakeEditable(false);
fPreviewTextView->MakeSelectable(false); fPreviewTextView->MakeSelectable(false);
fPreviewTextView->SetInsets(0, 0, 0, 0); fPreviewTextView->SetInsets(0, 0, 0, 0);
fPreviewTextView->SetViewColor(ViewColor()); fPreviewTextView->SetViewUIColor(ViewUIColor());
fPreviewTextView->SetLowColor(LowColor()); fPreviewTextView->SetLowUIColor(LowUIColor());
fPreviewTextView->SetHighUIColor(HighUIColor());
// determine initial line count using fCurrentFont // determine initial line count using fCurrentFont
fPreviewTextWidth = be_control_look->DefaultLabelSpacing() * 58.0f;
float lineCount = ceilf(fCurrentFont.StringWidth(kPreviewText) float lineCount = ceilf(fCurrentFont.StringWidth(kPreviewText)
/ kPreviewTextWidth); / fPreviewTextWidth);
fPreviewTextView->SetExplicitSize(BSize(kPreviewTextWidth, fPreviewTextView->SetExplicitSize(BSize(fPreviewTextWidth,
fPreviewTextView->LineHeight(0) * lineCount)); fPreviewTextView->LineHeight(0) * lineCount));
// box around preview // box around preview
@@ -304,7 +306,7 @@ FontSelectionView::_UpdateFontPreview()
#endif #endif
fPreviewTextView->SetFontAndColor(&fCurrentFont); fPreviewTextView->SetFontAndColor(&fCurrentFont);
fPreviewTextView->SetExplicitSize(BSize(kPreviewTextWidth, fPreviewTextView->SetExplicitSize(BSize(fPreviewTextWidth,
fPreviewTextView->LineHeight(0) * fPreviewTextView->CountLines())); fPreviewTextView->LineHeight(0) * fPreviewTextView->CountLines()));
} }
@@ -447,10 +449,6 @@ FontSelectionView::UpdateFontsMenu()
continue; continue;
} }
float width = font.StringWidth(family);
if (width > fMaxFontNameWidth)
fMaxFontNameWidth = width;
BMenu* stylesMenu = new BMenu(family); BMenu* stylesMenu = new BMenu(family);
stylesMenu->SetRadioMode(true); stylesMenu->SetRadioMode(true);
stylesMenu->SetFont(&font); stylesMenu->SetFont(&font);
@@ -66,10 +66,10 @@ protected:
BBox* fPreviewBox; BBox* fPreviewBox;
BTextView* fPreviewTextView; BTextView* fPreviewTextView;
float fPreviewTextWidth;
BFont fSavedFont; BFont fSavedFont;
BFont fCurrentFont; BFont fCurrentFont;
float fMaxFontNameWidth;
}; };
#endif // FONT_SELECTION_VIEW_H #endif // FONT_SELECTION_VIEW_H