-
Notifications
You must be signed in to change notification settings - Fork 241
Fixes issue rendering when node is collapsed and text has new lines #794
base: main
Are you sure you want to change the base?
Conversation
@@ -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.")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just use "\n", no need to embed a call to Environment.NewLine.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be simplified. If there are multiple lines, just measure the height of the first line.
public ExpandableTextCellView () | ||
{ | ||
var defaultLayout = new TextLayout() { Text = "A" }; | ||
defaultHeight = defaultLayout.GetSize().Height; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't work correctly. Because it doesn't take all possible glyphs into account. For example the height of A
is smaller than the height of Ag
. It's not possible to measure the final height at this point.
Better measure the first line, as proposed here: https://github.com/mono/xwt/pull/794/files#r172651546
@@ -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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this check again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ups! probably do it at the end of the day could be a great reason :)
It happens when text doesn't exceed the maxwidth and we have multiple lines because the new lines
3f791fb
to
e7d5a5d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's better now 👍
What should we do about this PR? |
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