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

List:       haiku-commits
Subject:    [haiku-commits] Change in haiku[master]: Appearance: Set a fixed preview text width and wrap
From:       Gerrit <review () review ! haiku-os ! org>
Date:       2022-07-24 17:57:57
Message-ID: 301a1437276f0f17f1a098fca7f92f3e34d2fc90-HTML () review ! haiku-os ! org
[Download RAW message or body]

From John Scipione <jscipione@gmail.com>:

John Scipione has uploaded this change for review. ( \
https://review.haiku-os.org/c/haiku/+/5501 )


Change subject: Appearance: Set a fixed preview text width and wrap
......................................................................

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
---
M src/preferences/appearance/FontSelectionView.cpp
M src/preferences/appearance/FontSelectionView.h
2 files changed, 37 insertions(+), 18 deletions(-)



  git pull ssh://git.haiku-os.org:22/haiku refs/changes/01/5501/1

diff --git a/src/preferences/appearance/FontSelectionView.cpp \
b/src/preferences/appearance/FontSelectionView.cpp index f9f6242..a1fd250 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;

-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 @@
 		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);
+	// 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());

-	fPreviewTextView->SetFont(&fCurrentFont);
-	fPreviewTextView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
+	// 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 @@
 	}
 }

+
 BView*
 FontSelectionView::GetPreviewBox() const
 {
@@ -275,18 +295,17 @@
 	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 215206a..3bcf788 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 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 @@
 			BSpinner*			fFontSizeSpinner;

 			BBox*				fPreviewBox;
-			BStringView*		fPreviewTextView;
+			BTextView*			fPreviewTextView;

 			BFont				fSavedFont;
 			BFont				fCurrentFont;

--
To view, visit https://review.haiku-os.org/c/haiku/+/5501
To unsubscribe, or for help writing mail filters, visit \
https://review.haiku-os.org/settings

Gerrit-Project: haiku
Gerrit-Branch: master
Gerrit-Change-Id: I5850374f0fc917176927010d8e50b44033d366b1
Gerrit-Change-Number: 5501
Gerrit-PatchSet: 1
Gerrit-Owner: John Scipione <jscipione@gmail.com>
Gerrit-MessageType: newchange


[Attachment #3 (text/html)]

<p>John Scipione has uploaded this change for <strong>review</strong>.</p><p><a \
href="https://review.haiku-os.org/c/haiku/+/5501">View Change</a></p><pre \
style="font-family: monospace,monospace; white-space: pre-wrap;">Appearance: Set a \
fixed preview text width and wrap<br><br>Larger font sizes and translations make the \
window too wide, grow<br>window vertically instead by wrapping.<br><br>Change-Id: \
I5850374f0fc917176927010d8e50b44033d366b1<br>---<br>M \
src/preferences/appearance/FontSelectionView.cpp<br>M \
src/preferences/appearance/FontSelectionView.h<br>2 files changed, 37 insertions(+), \
18 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; \
white-space: pre-wrap;">git pull ssh://git.haiku-os.org:22/haiku \
refs/changes/01/5501/1</pre><pre style="font-family: monospace,monospace; \
white-space: pre-wrap;"><span>diff --git \
a/src/preferences/appearance/FontSelectionView.cpp \
b/src/preferences/appearance/FontSelectionView.cpp</span><br><span>index \
f9f6242..a1fd250 100644</span><br><span>--- \
a/src/preferences/appearance/FontSelectionView.cpp</span><br><span>+++ \
b/src/preferences/appearance/FontSelectionView.cpp</span><br><span>@@ -1,5 +1,5 \
@@</span><br><span> /*</span><br><span style="color: hsl(0, 100%, 40%);">- * \
Copyright 2001-2015, Haiku.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \
Copyright 2001-2022 Haiku, Inc. All rights reserved.</span><br><span>  * Distributed \
under the terms of the MIT License.</span><br><span>  *</span><br><span>  * \
Authors:</span><br><span>@@ -8,6 +8,7 @@</span><br><span>  *		Axel Dörfler, \
axeld@pinc-software.de</span><br><span>  *		Philippe Saint-Pierre, \
stpere@gmail.com</span><br><span>  *		Stephan Aßmus \
&lt;superstippi@gmx.de&gt;</span><br><span style="color: hsl(120, 100%, 40%);">+ \
*		John Scipione, jscipione@gmail.com</span><br><span>  */</span><br><span> \
</span><br><span> </span><br><span>@@ -22,7 +23,7 @@</span><br><span> #include \
&lt;MenuItem.h&gt;</span><br><span> #include &lt;PopUpMenu.h&gt;</span><br><span> \
#include &lt;String.h&gt;</span><br><span style="color: hsl(0, 100%, 40%);">-#include \
&lt;StringView.h&gt;</span><br><span style="color: hsl(120, 100%, 40%);">+#include \
&lt;TextView.h&gt;</span><br><span> #include &lt;Spinner.h&gt;</span><br><span> \
</span><br><span> #include &lt;FontPrivate.h&gt;</span><br><span>@@ -40,8 +41,9 \
@@</span><br><span> </span><br><span> static const float kMinSize = \
8.0;</span><br><span> static const float kMaxSize = 72.0;</span><br><span \
style="color: hsl(120, 100%, 40%);">+static const float kPreviewTextWidth = \
350;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-static \
const char *kPreviewText = B_TRANSLATE_COMMENT(</span><br><span style="color: \
hsl(120, 100%, 40%);">+static const char* kPreviewText = \
B_TRANSLATE_COMMENT(</span><br><span> 	&quot;The quick brown fox jumps over the lazy \
dog.&quot;,</span><br><span> 	&quot;Don&#39;t translate this literally ! Use a phrase \
showing all chars &quot;</span><br><span> 	&quot;from A to \
Z.&quot;);</span><br><span>@@ -118,18 +120,35 @@</span><br><span> \
fontSizeMessage);</span><br><span> </span><br><span> \
fFontSizeSpinner-&gt;SetRange(kMinSize, kMaxSize);</span><br><span style="color: \
hsl(0, 100%, 40%);">-	fFontSizeSpinner-&gt;SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, \
B_SIZE_UNSET));</span><br><span style="color: hsl(120, 100%, \
40%);">+	fFontSizeSpinner-&gt;SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED,</span><br><span \
style="color: hsl(120, 100%, 40%);">+		B_SIZE_UNSET));</span><br><span> \
</span><br><span> 	// preview</span><br><span style="color: hsl(0, 100%, \
40%);">-	fPreviewTextView = new BStringView(&quot;preview text&quot;, \
kPreviewText);</span><br><span style="color: hsl(120, 100%, 40%);">+	// A string view \
would be enough if only it handled word-wrap.</span><br><span style="color: hsl(120, \
100%, 40%);">+	fPreviewTextView = new BTextView(&quot;preview \
text&quot;);</span><br><span style="color: hsl(120, 100%, \
40%);">+	fPreviewTextView-&gt;SetFontAndColor(&amp;fCurrentFont);</span><br><span \
style="color: hsl(120, 100%, \
40%);">+	fPreviewTextView-&gt;SetText(kPreviewText);</span><br><span style="color: \
hsl(120, 100%, 40%);">+	fPreviewTextView-&gt;MakeResizable(false);</span><br><span \
style="color: hsl(120, 100%, \
40%);">+	fPreviewTextView-&gt;SetWordWrap(true);</span><br><span style="color: \
hsl(120, 100%, 40%);">+	fPreviewTextView-&gt;MakeEditable(false);</span><br><span \
style="color: hsl(120, 100%, \
40%);">+	fPreviewTextView-&gt;MakeSelectable(false);</span><br><span style="color: \
hsl(120, 100%, 40%);">+	fPreviewTextView-&gt;SetInsets(0, 0, 0, 0);</span><br><span \
style="color: hsl(120, 100%, \
40%);">+	fPreviewTextView-&gt;SetViewColor(ViewColor());</span><br><span \
style="color: hsl(120, 100%, \
40%);">+	fPreviewTextView-&gt;SetLowColor(LowColor());</span><br><span> \
</span><br><span style="color: hsl(0, 100%, \
40%);">-	fPreviewTextView-&gt;SetFont(&amp;fCurrentFont);</span><br><span \
style="color: hsl(0, 100%, \
40%);">-	fPreviewTextView-&gt;SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, \
B_SIZE_UNSET));</span><br><span style="color: hsl(120, 100%, 40%);">+	// determine \
initial line count using fCurrentFont</span><br><span style="color: hsl(120, 100%, \
40%);">+	float lineCount = \
ceilf(fCurrentFont.StringWidth(kPreviewText)</span><br><span style="color: hsl(120, \
100%, 40%);">+		/ kPreviewTextWidth);</span><br><span style="color: hsl(120, 100%, \
40%);">+	fPreviewTextView-&gt;SetExplicitSize(BSize(kPreviewTextWidth,</span><br><span \
style="color: hsl(120, 100%, 40%);">+		fPreviewTextView-&gt;LineHeight(0) * \
lineCount));</span><br><span> </span><br><span> 	// box around \
preview</span><br><span> 	fPreviewBox = new BBox(&quot;preview box&quot;, B_WILL_DRAW \
| B_FRAME_EVENTS);</span><br><span style="color: hsl(0, 100%, \
40%);">-	fPreviewBox-&gt;AddChild(BGroupLayoutBuilder(B_HORIZONTAL)</span><br><span \
style="color: hsl(0, 100%, 40%);">-		.Add(fPreviewTextView)</span><br><span \
style="color: hsl(120, 100%, \
40%);">+	fPreviewBox-&gt;AddChild(BGroupLayoutBuilder(B_VERTICAL)</span><br><span \
style="color: hsl(120, 100%, 40%);">+		.AddGroup(B_HORIZONTAL, 0)</span><br><span \
style="color: hsl(120, 100%, 40%);">+			.Add(fPreviewTextView)</span><br><span \
style="color: hsl(120, 100%, 40%);">+			.AddGlue()</span><br><span style="color: \
hsl(120, 100%, 40%);">+			.End()</span><br><span> 		.SetInsets(B_USE_SMALL_SPACING, \
B_USE_SMALL_SPACING,</span><br><span> 			B_USE_SMALL_SPACING, \
B_USE_SMALL_SPACING)</span><br><span> 		.TopView()</span><br><span>@@ -221,6 +240,7 \
@@</span><br><span> 	}</span><br><span> }</span><br><span> </span><br><span \
style="color: hsl(120, 100%, 40%);">+</span><br><span> BView*</span><br><span> \
FontSelectionView::GetPreviewBox() const</span><br><span> {</span><br><span>@@ \
-275,18 +295,17 @@</span><br><span> \
fFontSizeSpinner-&gt;SetValue((int32)fCurrentFont.Size());</span><br><span> \
}</span><br><span> </span><br><span style="color: hsl(120, 100%, \
40%);">+</span><br><span> void</span><br><span> \
FontSelectionView::_UpdateFontPreview()</span><br><span> {</span><br><span \
style="color: hsl(0, 100%, 40%);">-	const BRect textFrame = \
fPreviewTextView-&gt;Bounds();</span><br><span style="color: hsl(0, 100%, \
40%);">-	BString text = BString(kPreviewText);</span><br><span style="color: hsl(0, \
100%, 40%);">-	fCurrentFont.TruncateString(&amp;text, B_TRUNCATE_END, \
textFrame.Width());</span><br><span style="color: hsl(0, 100%, \
40%);">-	fPreviewTextView-&gt;SetFont(&amp;fCurrentFont);</span><br><span \
style="color: hsl(0, 100%, \
40%);">-	fPreviewTextView-&gt;SetText(text);</span><br><span style="color: hsl(0, \
100%, 40%);">-</span><br><span> #ifdef INSTANT_UPDATE</span><br><span> \
_UpdateSystemFont();</span><br><span> #endif</span><br><span style="color: hsl(120, \
100%, 40%);">+</span><br><span style="color: hsl(120, 100%, \
40%);">+	fPreviewTextView-&gt;SetFontAndColor(&amp;fCurrentFont);</span><br><span \
style="color: hsl(120, 100%, \
40%);">+	fPreviewTextView-&gt;SetExplicitSize(BSize(kPreviewTextWidth,</span><br><span \
style="color: hsl(120, 100%, 40%);">+		fPreviewTextView-&gt;LineHeight(0) * \
fPreviewTextView-&gt;CountLines()));</span><br><span> }</span><br><span> \
</span><br><span> </span><br><span>diff --git \
a/src/preferences/appearance/FontSelectionView.h \
b/src/preferences/appearance/FontSelectionView.h</span><br><span>index \
215206a..3bcf788 100644</span><br><span>--- \
a/src/preferences/appearance/FontSelectionView.h</span><br><span>+++ \
b/src/preferences/appearance/FontSelectionView.h</span><br><span>@@ -1,5 +1,5 \
@@</span><br><span> /*</span><br><span style="color: hsl(0, 100%, 40%);">- * \
Copyright 2001-2009, Haiku.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \
Copyright 2001-2022 Haiku, Inc. All rights reserved.</span><br><span>  * Distributed \
under the terms of the MIT License.</span><br><span>  *</span><br><span>  * \
Authors:</span><br><span>@@ -18,8 +18,8 @@</span><br><span> class \
BBox;</span><br><span> class BMenuField;</span><br><span> class \
BPopUpMenu;</span><br><span style="color: hsl(0, 100%, 40%);">-class \
BStringView;</span><br><span> class BSpinner;</span><br><span style="color: hsl(120, \
100%, 40%);">+class BTextView;</span><br><span> </span><br><span> static const int32 \
kMsgSetFamily = &#39;fmly&#39;;</span><br><span> static const int32 kMsgSetStyle = \
&#39;styl&#39;;</span><br><span>@@ -65,7 +65,7 @@</span><br><span> \
BSpinner*			fFontSizeSpinner;</span><br><span> </span><br><span> \
BBox*				fPreviewBox;</span><br><span style="color: hsl(0, 100%, \
40%);">-			BStringView*		fPreviewTextView;</span><br><span style="color: hsl(120, \
100%, 40%);">+			BTextView*			fPreviewTextView;</span><br><span> </span><br><span> \
BFont				fSavedFont;</span><br><span> \
BFont				fCurrentFont;</span><br><span></span><br></pre><p>To view, visit <a \
href="https://review.haiku-os.org/c/haiku/+/5501">change 5501</a>. To unsubscribe, or \
for help writing mail filters, visit <a \
href="https://review.haiku-os.org/settings">settings</a>.</p><div itemscope \
itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" \
itemtype="http://schema.org/ViewAction"><link itemprop="url" \
href="https://review.haiku-os.org/c/haiku/+/5501"/><meta itemprop="name" \
content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: haiku </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: \
I5850374f0fc917176927010d8e50b44033d366b1 </div> <div style="display:none"> \
Gerrit-Change-Number: 5501 </div> <div style="display:none"> Gerrit-PatchSet: 1 \
</div> <div style="display:none"> Gerrit-Owner: John Scipione \
&lt;jscipione@gmail.com&gt; </div> <div style="display:none"> Gerrit-MessageType: \
newchange </div>



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

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