[prev in list] [next in list] [prev in thread] [next in thread] 

List:       haiku-commits
Subject:    [haiku-commits] haiku: hrev56313 - src/preferences/appearance
From:       John Scipione <jscipione () gmail ! com>
Date:       2022-07-25 14:07:54
Message-ID: 20220725140754.55D2B40524 () turing ! freelists ! org
[Download RAW message or body]

hrev56313 adds 1 changeset to branch 'master'
old head: 5ef3f3867788bdc2364e5d2c468cca046a29b66b
new head: f515b1c0f3ffae894605eb1bb534fe65977115cd
overview: https://git.haiku-os.org/haiku/log/?qt=range&q=f515b1c0f3ff+%5E5ef3f3867788

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

f515b1c0f3ff: Appearance: Set a fixed preview text width and wrap
  
  Larger font sizes and translations make the window too wide, grow
  window vertically instead by wrapping.
  
  Change-Id: I5850374f0fc917176927010d8e50b44033d366b1
  Reviewed-on: https://review.haiku-os.org/c/haiku/+/5501
  Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
  Reviewed-by: Adrien Destugues <pulkomandy@pulkomandy.tk>

                                     [ John Scipione <jscipione@gmail.com> ]

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

Revision:    hrev56313
Commit:      f515b1c0f3ffae894605eb1bb534fe65977115cd
URL:         https://git.haiku-os.org/haiku/commit/?id=f515b1c0f3ff
Author:      John Scipione <jscipione@gmail.com>
Date:        Fri Dec 10 22:25:43 2021 UTC

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

2 files changed, 38 insertions(+), 19 deletions(-)
src/preferences/appearance/FontSelectionView.cpp | 51 ++++++++++++++------
src/preferences/appearance/FontSelectionView.h   |  6 +--

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

diff --git a/src/preferences/appearance/FontSelectionView.cpp \
b/src/preferences/appearance/FontSelectionView.cpp index f9f6242b30..d492308b3f \
                100644
--- a/src/preferences/appearance/FontSelectionView.cpp
+++ b/src/preferences/appearance/FontSelectionView.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright 2001-2015, Haiku.
+ * Copyright 2001-2022 Haiku, Inc. All rights reserved.
  * Distributed under the terms of the MIT License.
  *
  * Authors:
@@ -8,6 +8,7 @@
  *		Axel Dörfler, axeld@pinc-software.de
  *		Philippe Saint-Pierre, stpere@gmail.com
  *		Stephan Aßmus <superstippi@gmx.de>
+ *		John Scipione, jscipione@gmail.com
  */
 
 
@@ -22,7 +23,7 @@
 #include <MenuItem.h>
 #include <PopUpMenu.h>
 #include <String.h>
-#include <StringView.h>
+#include <TextView.h>
 #include <Spinner.h>
 
 #include <FontPrivate.h>
@@ -40,8 +41,9 @@
 
 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(
+static const char* kPreviewText = B_TRANSLATE_COMMENT(
 	"The quick brown fox jumps over the lazy dog.",
 	"Don't translate this literally ! Use a phrase showing all chars "
 	"from A to Z.");
@@ -118,18 +120,35 @@ FontSelectionView::FontSelectionView(const char* name,
 		fontSizeMessage);
 
 	fFontSizeSpinner->SetRange(kMinSize, kMaxSize);
-	fFontSizeSpinner->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
+	fFontSizeSpinner->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED,
+		B_SIZE_UNSET));
 
 	// preview
-	fPreviewTextView = new BStringView("preview text", kPreviewText);
-
-	fPreviewTextView->SetFont(&fCurrentFont);
-	fPreviewTextView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
+	// A string view would be enough if only it handled word-wrap.
+	fPreviewTextView = new BTextView("preview text");
+	fPreviewTextView->SetFontAndColor(&fCurrentFont);
+	fPreviewTextView->SetText(kPreviewText);
+	fPreviewTextView->MakeResizable(false);
+	fPreviewTextView->SetWordWrap(true);
+	fPreviewTextView->MakeEditable(false);
+	fPreviewTextView->MakeSelectable(false);
+	fPreviewTextView->SetInsets(0, 0, 0, 0);
+	fPreviewTextView->SetViewColor(ViewColor());
+	fPreviewTextView->SetLowColor(LowColor());
+
+	// determine initial line count using fCurrentFont
+	float lineCount = ceilf(fCurrentFont.StringWidth(kPreviewText)
+		/ kPreviewTextWidth);
+	fPreviewTextView->SetExplicitSize(BSize(kPreviewTextWidth,
+		fPreviewTextView->LineHeight(0) * lineCount));
 
 	// box around preview
 	fPreviewBox = new BBox("preview box", B_WILL_DRAW | B_FRAME_EVENTS);
-	fPreviewBox->AddChild(BGroupLayoutBuilder(B_HORIZONTAL)
-		.Add(fPreviewTextView)
+	fPreviewBox->AddChild(BGroupLayoutBuilder(B_VERTICAL)
+		.AddGroup(B_HORIZONTAL, 0)
+			.Add(fPreviewTextView)
+			.AddGlue()
+			.End()
 		.SetInsets(B_USE_SMALL_SPACING, B_USE_SMALL_SPACING,
 			B_USE_SMALL_SPACING, B_USE_SMALL_SPACING)
 		.TopView()
@@ -221,6 +240,7 @@ FontSelectionView::MessageReceived(BMessage* msg)
 	}
 }
 
+
 BView*
 FontSelectionView::GetPreviewBox() const
 {
@@ -275,18 +295,17 @@ FontSelectionView::_SelectCurrentSize()
 	fFontSizeSpinner->SetValue((int32)fCurrentFont.Size());
 }
 
+
 void
 FontSelectionView::_UpdateFontPreview()
 {
-	const BRect textFrame = fPreviewTextView->Bounds();
-	BString text = BString(kPreviewText);
-	fCurrentFont.TruncateString(&text, B_TRUNCATE_END, textFrame.Width());
-	fPreviewTextView->SetFont(&fCurrentFont);
-	fPreviewTextView->SetText(text);
-
 #ifdef INSTANT_UPDATE
 	_UpdateSystemFont();
 #endif
+
+	fPreviewTextView->SetFontAndColor(&fCurrentFont);
+	fPreviewTextView->SetExplicitSize(BSize(kPreviewTextWidth,
+		fPreviewTextView->LineHeight(0) * fPreviewTextView->CountLines()));
 }
 
 
diff --git a/src/preferences/appearance/FontSelectionView.h \
b/src/preferences/appearance/FontSelectionView.h index 215206aede..3bcf78853e 100644
--- a/src/preferences/appearance/FontSelectionView.h
+++ b/src/preferences/appearance/FontSelectionView.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2001-2009, Haiku.
+ * Copyright 2001-2022 Haiku, Inc. All rights reserved.
  * Distributed under the terms of the MIT License.
  *
  * Authors:
@@ -18,8 +18,8 @@ class BLayoutItem;
 class BBox;
 class BMenuField;
 class BPopUpMenu;
-class BStringView;
 class BSpinner;
+class BTextView;
 
 static const int32 kMsgSetFamily = 'fmly';
 static const int32 kMsgSetStyle = 'styl';
@@ -65,7 +65,7 @@ protected:
 			BSpinner*			fFontSizeSpinner;
 
 			BBox*				fPreviewBox;
-			BStringView*		fPreviewTextView;
+			BTextView*			fPreviewTextView;
 
 			BFont				fSavedFont;
 			BFont				fCurrentFont;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic