Skip to content
This repository was archived by the owner on Sep 4, 2024. It is now read-only.

Commit e7d5a5d

Browse files
committed
Fixes issue rendering when node is collapsed and text has new lines
It happens when text doesn't exceed the maxwidth and we have multiple lines because the new lines
1 parent 1525ea5 commit e7d5a5d

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

TestApps/Samples/Samples/TreeViewEvents.cs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public TreeViewEvents ()
4848
tree.Columns.Add (col);
4949

5050
var node = store.AddNode ().SetValue (nodeField, new TextNode ("Root 1"));
51-
var child = node.AddChild ().SetValue (nodeField, new TextNode ("Very long text. Very long text. Very long text. Very long text. Very long text. Very long text. Very long text. Very long text."));
51+
var child = node.AddChild ().SetValue (nodeField, new TextNode ("Very long text with NewLines. \n\nVery long text with NewLines.\n\nVery long text. Very long text. Very long text. Very long text."));
5252
node = store.AddNode ().SetValue (nodeField, new TextNode ("Root 2"));
5353
child = node.AddChild ().SetValue (nodeField, new TextNode ("Short text. Short text. Short text."));
5454
child.AddChild ().SetValue (nodeField, new TextNode ("Very long text. Very long text. Very long text. Very long text. Very long text. Very long text. Very long text. Very long text."));
@@ -113,18 +113,26 @@ protected override Size OnGetRequiredSize ()
113113
var node = GetValue (NodeField);
114114
var status = GetViewStatus (node);
115115

116-
TextLayout layout = new TextLayout ();
117-
layout.Text = node.Text;
116+
var layout = new TextLayout ();
117+
118+
var index = node.Text.IndexOf('\n');
119+
if (!status.Expanded && index > -1) {
120+
layout.Text = node.Text.Substring(0, index);
121+
} else {
122+
layout.Text = node.Text;
123+
}
124+
118125
var textSize = layout.GetSize ();
119126

120127
// When in expanded mode, the height of the row depends on the width. Since we don't know the width,
121128
// let's use the last width that was used for rendering.
122129

123-
if (status.Expanded && status.LastRenderWidth != 0 && layout.GetSize ().Width > status.LastRenderWidth) {
130+
if (status.Expanded && status.LastRenderWidth != 0 && textSize.Width > status.LastRenderWidth) {
124131
layout.Width = status.LastRenderWidth - addImage.Width - MoreLinkSpacing;
125132
textSize = layout.GetSize ();
126133
}
127134

135+
//in cases when there are multiple lines and they don't execeed the max width we need to care height include the expand
128136
status.LastCalculatedHeight = textSize.Height;
129137

130138
return new Size (30, textSize.Height);
@@ -147,9 +155,14 @@ protected override void OnDraw (Context ctx, Rectangle cellArea)
147155
layout.SetBackground (Colors.LightBlue, Math.Min (selectionStart, selectionEnd), Math.Abs (selectionEnd - selectionStart));
148156

149157
// Text doesn't fit. We need to render the expand icon
158+
if (textSize.Width > cellArea.Width || textSize.Height > cellArea.Height) {
159+
160+
layout.Width = Math.Max(1, cellArea.Width - addImage.Width - MoreLinkSpacing);
161+
162+
if (textSize.Height > cellArea.Height) {
163+
layout.Height = cellArea.Height;
164+
}
150165

151-
if (textSize.Width > cellArea.Width) {
152-
layout.Width = Math.Max (1, cellArea.Width - addImage.Width - MoreLinkSpacing);
153166
if (!status.Expanded)
154167
layout.Trimming = TextTrimming.WordElipsis;
155168
else

0 commit comments

Comments
 (0)