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

Commit

Permalink
Fixes issue rendering when node is collapsed and text has new lines
Browse files Browse the repository at this point in the history
It happens when text doesn't exceed the maxwidth and we have
multiple lines because the new lines
  • Loading branch information
netonjm committed Mar 6, 2018
1 parent 1525ea5 commit 3f791fb
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions TestApps/Samples/Samples/TreeViewEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public TreeViewEvents ()
tree.Columns.Add (col);

var node = store.AddNode ().SetValue (nodeField, new TextNode ("Root 1"));
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."));
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."));
node = store.AddNode ().SetValue (nodeField, new TextNode ("Root 2"));
child = node.AddChild ().SetValue (nodeField, new TextNode ("Short text. Short text. Short text."));
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."));
Expand Down Expand Up @@ -100,6 +100,17 @@ class ViewStatus
TextNode selectionRow;
bool dragging;

//defines the default height size based in the current font
//if will work if you use same font size in every row,
//if not, you'll need check in every OnGetRequiredSize
double defaultHeight;

public ExpandableTextCellView ()
{
var defaultLayout = new TextLayout() { Text = "A" };
defaultHeight = defaultLayout.GetSize().Height;
}

ViewStatus GetViewStatus (TextNode node)
{
ViewStatus status;
Expand All @@ -125,9 +136,15 @@ protected override Size OnGetRequiredSize ()
textSize = layout.GetSize ();
}

status.LastCalculatedHeight = textSize.Height;
//in cases when there are multiple lines and they don't execeed the max width we need to care height include the expand
double height = textSize.Height;
if (!status.Expanded && textSize.Height > defaultHeight) {
height = defaultHeight;
}

status.LastCalculatedHeight = height;

return new Size (30, textSize.Height);
return new Size (30, height);
}

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

// Text doesn't fit. We need to render the expand icon
if (textSize.Width > cellArea.Width || textSize.Height > cellArea.Height) {

if (textSize.Width > cellArea.Width || textSize.Height > cellArea.Height) {
layout.Width = Math.Max(1, cellArea.Width - addImage.Width - MoreLinkSpacing);

if (textSize.Height > cellArea.Height) {
layout.Height = cellArea.Height;
}
}

if (textSize.Width > cellArea.Width) {
layout.Width = Math.Max (1, cellArea.Width - addImage.Width - MoreLinkSpacing);
if (!status.Expanded)
layout.Trimming = TextTrimming.WordElipsis;
else
Expand Down

0 comments on commit 3f791fb

Please sign in to comment.