Skip to content

Commit 96b8086

Browse files
committed
feat(showlocalvisualtree): Improved the display of .ShowLocalVisualTree() by adding details about Grid/Canvas positioning.
1 parent 6ed4ac1 commit 96b8086

File tree

5 files changed

+56
-6
lines changed

5 files changed

+56
-6
lines changed

src/Uno.UI/Extensions/UIViewExtensions.iOSmacOS.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,7 @@ StringBuilder AppendView(_View innerView)
639639
.Append(uiElement != null ? $" AvailableSize={uiElement.LastAvailableSize}" : "")
640640
.Append(uiElement?.NeedsClipToSlot ?? false ? " CLIPPED_TO_SLOT" : "")
641641
.Append(uiElement?.GetElementSpecificDetails())
642+
.Append(uiElement?.GetElementGridOrCanvasDetails())
642643
.Append(uiElement?.RenderTransform.GetTransformDetails())
643644
.AppendLine();
644645
}

src/Uno.UI/Extensions/ViewExtensions.Android.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,9 +638,11 @@ void AppendView(View innerView, string s)
638638
.Append(fe != null && fe.TryGetPadding(out var p) && p != default ? $" Padding={p}" : "")
639639
.Append(u != null ? $" DesiredSize={u.DesiredSize.ToString("F1")}" : "")
640640
.Append(u != null && u.NeedsClipToSlot ? "CLIPPED_TO_SLOT" : "")
641-
.Append(u != null && u.RenderTransform != null ? $"RENDER_TRANSFORM({u.RenderTransform.MatrixCore})" : "")
642641
.Append(u?.Clip != null ? $" Clip={u.Clip.Rect}" : "")
643642
.Append(u == null && vg != null ? $" ClipChildren={vg.ClipChildren}" : "")
643+
.Append(u?.GetElementSpecificDetails())
644+
.Append(u?.GetElementGridOrCanvasDetails())
645+
.Append(u?.RenderTransform.GetTransformDetails())
644646
.Append($" IsLayoutRequested={innerView.IsLayoutRequested}")
645647
.Append(innerView is TextBlock textBlock ? $" Text=\"{textBlock.Text}\"" : "")
646648
.AppendLine();

src/Uno.UI/Extensions/ViewExtensions.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
using System.Collections.Generic;
1414
using System.Linq;
15+
using System.Text;
1516
using Uno.Extensions;
1617
using Windows.UI.Xaml;
1718
using Windows.UI.Xaml.Controls;
@@ -41,8 +42,54 @@ internal static string GetElementSpecificDetails(this UIElement element)
4142
TextBlock textBlock => $" Text=\"{textBlock.Text}\" Foreground={textBlock.Foreground}",
4243
ScrollViewer scrollViewer => $" Extent={scrollViewer.ExtentWidth}x{scrollViewer.ExtentHeight} Offset={scrollViewer.ScrollOffsets}",
4344
Viewbox viewbox => $" Stretch={viewbox.Stretch}",
45+
SplitView splitview => $" Mode={splitview.DisplayMode}",
46+
Grid grid => GetGridDetails(grid),
4447
_ => ""
4548
};
49+
50+
string GetGridDetails(Grid grid)
51+
{
52+
string columns = default;
53+
if (grid.ColumnDefinitions.Count > 1)
54+
{
55+
columns = " Cols=" + grid.ColumnDefinitions
56+
.Select<ColumnDefinition, string>(x => x.Width.ToString())
57+
.JoinBy(",");
58+
}
59+
60+
string rows = default;
61+
if (grid.RowDefinitions.Count > 1)
62+
{
63+
rows = " Rows=" + grid.RowDefinitions
64+
.Select<RowDefinition, string>(x => x.Height.ToString())
65+
.JoinBy(",");
66+
}
67+
68+
return columns + rows;
69+
}
70+
}
71+
72+
internal static string GetElementGridOrCanvasDetails(this UIElement element)
73+
{
74+
var sb = new StringBuilder();
75+
76+
CheckProperty(Grid.ColumnProperty);
77+
CheckProperty(Grid.RowProperty);
78+
CheckProperty(Grid.ColumnSpanProperty);
79+
CheckProperty(Grid.RowSpanProperty);
80+
CheckProperty(Canvas.TopProperty);
81+
CheckProperty(Canvas.LeftProperty);
82+
CheckProperty(Canvas.ZIndexProperty);
83+
84+
void CheckProperty(DependencyProperty property)
85+
{
86+
if (element.ReadLocalValue(property) is int value)
87+
{
88+
sb.Append($" {property.OwnerType.Name}.{property.Name}={value}");
89+
}
90+
}
91+
92+
return sb.ToString();
4693
}
4794

4895
internal static string GetTransformDetails(this Transform transform)

src/Uno.UI/Extensions/ViewExtensions.netstd.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ StringBuilder AppendView(UIElement innerView)
101101
.Append(uiElement?.Clip != null ? $" Clip={uiElement.Clip.Rect}" : "")
102102
.Append(uiElement?.NeedsClipToSlot ?? false ? " CLIPPED_TO_SLOT" : "")
103103
.Append(uiElement?.GetElementSpecificDetails())
104+
.Append(uiElement?.GetElementGridOrCanvasDetails())
104105
.Append(uiElement?.RenderTransform.GetTransformDetails())
105106
.AppendLine();
106107
}

src/Uno.UI/UI/Xaml/GridLength.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,15 @@ public bool Equals(GridLength other)
133133

134134
private string DebugDisplay => ToDisplayString();
135135

136-
internal readonly string ToDisplayString()
137-
{
138-
var inner = GridUnitType switch
136+
internal readonly string ToDisplayString() => $"GridLength({this})";
137+
138+
public override string ToString() =>
139+
GridUnitType switch
139140
{
140141
GridUnitType.Auto => "Auto",
141142
GridUnitType.Pixel => $"{Value:f1}px",
142143
GridUnitType.Star => $"{Value:f1}*",
143144
_ => "invalid"
144145
};
145-
return $"GridLength({inner})";
146-
}
147146
}
148147
}

0 commit comments

Comments
 (0)