Skip to content

Commit

Permalink
feat(showlocalvisualtree): Improved the display of `.ShowLocalVisualT…
Browse files Browse the repository at this point in the history
…ree()` by adding details about Grid/Canvas positioning.
  • Loading branch information
carldebilly committed Apr 26, 2021
1 parent 6ed4ac1 commit 96b8086
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/Uno.UI/Extensions/UIViewExtensions.iOSmacOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ StringBuilder AppendView(_View innerView)
.Append(uiElement != null ? $" AvailableSize={uiElement.LastAvailableSize}" : "")
.Append(uiElement?.NeedsClipToSlot ?? false ? " CLIPPED_TO_SLOT" : "")
.Append(uiElement?.GetElementSpecificDetails())
.Append(uiElement?.GetElementGridOrCanvasDetails())
.Append(uiElement?.RenderTransform.GetTransformDetails())
.AppendLine();
}
Expand Down
4 changes: 3 additions & 1 deletion src/Uno.UI/Extensions/ViewExtensions.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -638,9 +638,11 @@ void AppendView(View innerView, string s)
.Append(fe != null && fe.TryGetPadding(out var p) && p != default ? $" Padding={p}" : "")
.Append(u != null ? $" DesiredSize={u.DesiredSize.ToString("F1")}" : "")
.Append(u != null && u.NeedsClipToSlot ? "CLIPPED_TO_SLOT" : "")
.Append(u != null && u.RenderTransform != null ? $"RENDER_TRANSFORM({u.RenderTransform.MatrixCore})" : "")
.Append(u?.Clip != null ? $" Clip={u.Clip.Rect}" : "")
.Append(u == null && vg != null ? $" ClipChildren={vg.ClipChildren}" : "")
.Append(u?.GetElementSpecificDetails())
.Append(u?.GetElementGridOrCanvasDetails())
.Append(u?.RenderTransform.GetTransformDetails())
.Append($" IsLayoutRequested={innerView.IsLayoutRequested}")
.Append(innerView is TextBlock textBlock ? $" Text=\"{textBlock.Text}\"" : "")
.AppendLine();
Expand Down
47 changes: 47 additions & 0 deletions src/Uno.UI/Extensions/ViewExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

using System.Collections.Generic;
using System.Linq;
using System.Text;
using Uno.Extensions;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
Expand Down Expand Up @@ -41,8 +42,54 @@ internal static string GetElementSpecificDetails(this UIElement element)
TextBlock textBlock => $" Text=\"{textBlock.Text}\" Foreground={textBlock.Foreground}",
ScrollViewer scrollViewer => $" Extent={scrollViewer.ExtentWidth}x{scrollViewer.ExtentHeight} Offset={scrollViewer.ScrollOffsets}",
Viewbox viewbox => $" Stretch={viewbox.Stretch}",
SplitView splitview => $" Mode={splitview.DisplayMode}",
Grid grid => GetGridDetails(grid),
_ => ""
};

string GetGridDetails(Grid grid)
{
string columns = default;
if (grid.ColumnDefinitions.Count > 1)
{
columns = " Cols=" + grid.ColumnDefinitions
.Select<ColumnDefinition, string>(x => x.Width.ToString())
.JoinBy(",");
}

string rows = default;
if (grid.RowDefinitions.Count > 1)
{
rows = " Rows=" + grid.RowDefinitions
.Select<RowDefinition, string>(x => x.Height.ToString())
.JoinBy(",");
}

return columns + rows;
}
}

internal static string GetElementGridOrCanvasDetails(this UIElement element)
{
var sb = new StringBuilder();

CheckProperty(Grid.ColumnProperty);
CheckProperty(Grid.RowProperty);
CheckProperty(Grid.ColumnSpanProperty);
CheckProperty(Grid.RowSpanProperty);
CheckProperty(Canvas.TopProperty);
CheckProperty(Canvas.LeftProperty);
CheckProperty(Canvas.ZIndexProperty);

void CheckProperty(DependencyProperty property)
{
if (element.ReadLocalValue(property) is int value)
{
sb.Append($" {property.OwnerType.Name}.{property.Name}={value}");
}
}

return sb.ToString();
}

internal static string GetTransformDetails(this Transform transform)
Expand Down
1 change: 1 addition & 0 deletions src/Uno.UI/Extensions/ViewExtensions.netstd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ StringBuilder AppendView(UIElement innerView)
.Append(uiElement?.Clip != null ? $" Clip={uiElement.Clip.Rect}" : "")
.Append(uiElement?.NeedsClipToSlot ?? false ? " CLIPPED_TO_SLOT" : "")
.Append(uiElement?.GetElementSpecificDetails())
.Append(uiElement?.GetElementGridOrCanvasDetails())
.Append(uiElement?.RenderTransform.GetTransformDetails())
.AppendLine();
}
Expand Down
9 changes: 4 additions & 5 deletions src/Uno.UI/UI/Xaml/GridLength.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,15 @@ public bool Equals(GridLength other)

private string DebugDisplay => ToDisplayString();

internal readonly string ToDisplayString()
{
var inner = GridUnitType switch
internal readonly string ToDisplayString() => $"GridLength({this})";

public override string ToString() =>
GridUnitType switch
{
GridUnitType.Auto => "Auto",
GridUnitType.Pixel => $"{Value:f1}px",
GridUnitType.Star => $"{Value:f1}*",
_ => "invalid"
};
return $"GridLength({inner})";
}
}
}

0 comments on commit 96b8086

Please sign in to comment.