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

Commit 3f791fb

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 3f791fb

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

TestApps/Samples/Samples/TreeViewEvents.cs

Lines changed: 29 additions & 5 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. {Environment.NewLine} Very long text with NewLines.{Environment.NewLine} Very 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."));
@@ -100,6 +100,17 @@ class ViewStatus
100100
TextNode selectionRow;
101101
bool dragging;
102102

103+
//defines the default height size based in the current font
104+
//if will work if you use same font size in every row,
105+
//if not, you'll need check in every OnGetRequiredSize
106+
double defaultHeight;
107+
108+
public ExpandableTextCellView ()
109+
{
110+
var defaultLayout = new TextLayout() { Text = "A" };
111+
defaultHeight = defaultLayout.GetSize().Height;
112+
}
113+
103114
ViewStatus GetViewStatus (TextNode node)
104115
{
105116
ViewStatus status;
@@ -125,9 +136,15 @@ protected override Size OnGetRequiredSize ()
125136
textSize = layout.GetSize ();
126137
}
127138

128-
status.LastCalculatedHeight = textSize.Height;
139+
//in cases when there are multiple lines and they don't execeed the max width we need to care height include the expand
140+
double height = textSize.Height;
141+
if (!status.Expanded && textSize.Height > defaultHeight) {
142+
height = defaultHeight;
143+
}
144+
145+
status.LastCalculatedHeight = height;
129146

130-
return new Size (30, textSize.Height);
147+
return new Size (30, height);
131148
}
132149

133150
protected override void OnDraw (Context ctx, Rectangle cellArea)
@@ -147,9 +164,16 @@ protected override void OnDraw (Context ctx, Rectangle cellArea)
147164
layout.SetBackground (Colors.LightBlue, Math.Min (selectionStart, selectionEnd), Math.Abs (selectionEnd - selectionStart));
148165

149166
// Text doesn't fit. We need to render the expand icon
167+
if (textSize.Width > cellArea.Width || textSize.Height > cellArea.Height) {
168+
169+
if (textSize.Width > cellArea.Width || textSize.Height > cellArea.Height) {
170+
layout.Width = Math.Max(1, cellArea.Width - addImage.Width - MoreLinkSpacing);
171+
172+
if (textSize.Height > cellArea.Height) {
173+
layout.Height = cellArea.Height;
174+
}
175+
}
150176

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

0 commit comments

Comments
 (0)