Skip to content

Commit 4bd28ab

Browse files
committed
Added padding and margin
1 parent d92e8e9 commit 4bd28ab

File tree

10 files changed

+81
-22
lines changed

10 files changed

+81
-22
lines changed

VisualDebug.Models/RenderRepresentation.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ public class RenderRepresentation
1919

2020
public RenderBounds Bounds { get; set; }
2121

22+
public RenderThickness Margin { get; set; }
23+
24+
public RenderThickness Padding { get; set; }
25+
2226
[Newtonsoft.Json.JsonProperty(DefaultValueHandling = Newtonsoft.Json.DefaultValueHandling.Ignore, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore, PropertyName = "children", Required = Newtonsoft.Json.Required.AllowNull)]
2327
[System.Runtime.Serialization.DataMember(EmitDefaultValue = false, IsRequired = false, Name = "children")]
2428
public List<RenderRepresentation> Children { get; set; }

VisualDebug.Models/RenderThickness.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace VisualDebug.Models
2+
{
3+
public class RenderThickness
4+
{
5+
public double Bottom { get; set; }
6+
public double Right { get; set; }
7+
public double Top { get; set; }
8+
public double Left { get; set; }
9+
10+
public override string ToString()
11+
{
12+
return $"{{Left={Left} Top={Top} Right={Right} Bottom={Bottom}}}";
13+
}
14+
}
15+
}

XamarinForms.VisualDebug.App/renderer/chart.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var orgChart = (function () {
1919
/* Configuration */
2020
_duration = 750, /* Duration of the animations */
2121
_rectW = 180, /* Width of the rectangle */
22-
_rectH = 120, /* Height of the rectangle */
22+
_rectH = 150, /* Height of the rectangle */
2323
_rectSpacing = 120, /* Spacing between the rectangles */
2424
_fixedDepth = 200, /* Height of the line for child nodes */
2525
_mode = "line", /* Choose the values "line" or "diagonal" */
@@ -184,6 +184,36 @@ var orgChart = (function () {
184184
return "Height:" + d.Bounds.Height;
185185
});
186186

187+
currentYOffset += _labelSize + _labelMargin;
188+
nodeEnter.append("text")
189+
.attr("x", 5)
190+
.attr("y", currentYOffset)
191+
.attr("dy", _labelSize + "px")
192+
.attr("text-anchor", "left")
193+
.style("cursor", function (d) { return (d.children || d._children || d.hasChild) ? "pointer" : "default"; })
194+
.text(function (d) {
195+
if (d.Margin === null || d.Margin === undefined) {
196+
return "Margin: N/A";
197+
}
198+
199+
return "Margin:" + d.Margin.Left + "," + d.Margin.Top + "," + d.Margin.Right + "," + d.Margin.Bottom;
200+
});
201+
202+
currentYOffset += _labelSize + _labelMargin;
203+
nodeEnter.append("text")
204+
.attr("x", 5)
205+
.attr("y", currentYOffset)
206+
.attr("dy", _labelSize + "px")
207+
.attr("text-anchor", "left")
208+
.style("cursor", function (d) { return (d.children || d._children || d.hasChild) ? "pointer" : "default"; })
209+
.text(function (d) {
210+
if (d.Padding === null || d.Padding === undefined) {
211+
return "Padding: N/A";
212+
}
213+
214+
return "Padding:" + d.Padding.Left + "," + d.Padding.Top + "," + d.Padding.Right + "," + d.Padding.Bottom;
215+
});
216+
187217
nodeEnter.append("image")
188218
.attr("x", _rectW)
189219
.attr("y", 0)

XamarinForms.VisualDebug.Core/Sender.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class Sender
1515

1616
private static readonly System.Net.Http.HttpClient httpClient = new System.Net.Http.HttpClient(httpClientHandler);
1717

18-
public async System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> SendToServer(string packet, string ip = "192.168.1.153", string port = "3000")
18+
public async System.Threading.Tasks.Task<System.Net.Http.HttpResponseMessage> SendToServer(string packet, string ip = "", string port = "3000")
1919
{
2020
if(string.IsNullOrWhiteSpace(ip))
2121
{

XamarinForms.VisualDebug.Core/TreeRenderer.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public static string RenderVisualHeirarchyToJson(VisualElement element)
7979

8080
private static RenderRepresentation ToRenderRepresentation(VisualElement element)
8181
{
82-
return new RenderRepresentation()
82+
var rep = new RenderRepresentation()
8383
{
8484
ElementId = element.Id,
8585
VisualTypeName = element.GetType().Name,
@@ -95,6 +95,32 @@ private static RenderRepresentation ToRenderRepresentation(VisualElement element
9595
Width = element.Bounds.Width
9696
}
9797
};
98+
99+
if (element is View repv)
100+
{
101+
rep.Margin = new RenderThickness
102+
{
103+
Left = repv.Margin.Left,
104+
Top = repv.Margin.Top,
105+
Right = repv.Margin.Right,
106+
Bottom = repv.Margin.Bottom
107+
};
108+
}
109+
110+
var paddingProp = element.GetType().GetProperty("Padding");
111+
if (!(paddingProp is null))
112+
{
113+
var padding = (Thickness)paddingProp.GetValue(element);
114+
rep.Padding = new RenderThickness
115+
{
116+
Left = padding.Left,
117+
Top = padding.Top,
118+
Right = padding.Right,
119+
Bottom = padding.Bottom
120+
};
121+
}
122+
123+
return rep;
98124
}
99125

100126

XamarinForms.VisualDebug.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<metadata>
44
<id>XamarinForms.VisualDebug</id>
55
<title>XamarinForms.VisualDebug</title>
6-
<version>0.0.1</version>
6+
<version>0.0.2</version>
77
<authors>David Thompson</authors>
88
<owners>David Thompson</owners>
99
<projectUrl>https://github.com/Pepsi1x1/XamarinForms.VisualDebug</projectUrl>

XamarinForms.VisualDebug/XamarinForms.VisualDebug/App.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ private void Current_PageAppearing(object sender, Page e)
3030
ip = XamarinForms.VisualDebug.Constants.IPConstant.LocalIP;
3131
}
3232

33-
var response = await Sender.SendToServer(rep).ConfigureAwait(false);
33+
var response = await Sender.SendToServer(rep, ip).ConfigureAwait(false);
3434
if (response.IsSuccessStatusCode)
3535
{
3636
Console.WriteLine("Success!");

XamarinForms.VisualDebug/XamarinForms.VisualDebug/IPConstant.cs

Lines changed: 0 additions & 8 deletions
This file was deleted.

XamarinForms.VisualDebug/XamarinForms.VisualDebug/IPConstant.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace XamarinForms.VisualDebug.Constants
88
public const string LocalIP =<# // This code runs in the text template:
99
foreach (System.Net.NetworkInformation.NetworkInterface ni in System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces())
1010
{
11-
if (ni.NetworkInterfaceType == System.Net.NetworkInformation.NetworkInterfaceType.Ethernet)
11+
if (ni.NetworkInterfaceType == System.Net.NetworkInformation.NetworkInterfaceType.Wireless80211)
1212
{
1313
foreach (System.Net.NetworkInformation.UnicastIPAddressInformation ip in ni.GetIPProperties().UnicastAddresses)
1414
{

XamarinForms.VisualDebug/XamarinForms.VisualDebug/XamarinForms.VisualDebug.Sample.csproj

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,6 @@
3434
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
3535
</ItemGroup>
3636

37-
<ItemGroup>
38-
<Compile Update="IPConstant.cs">
39-
<DesignTime>True</DesignTime>
40-
<AutoGen>True</AutoGen>
41-
<DependentUpon>IPConstant.tt</DependentUpon>
42-
</Compile>
43-
</ItemGroup>
44-
4537
<ItemGroup>
4638
<EmbeddedResource Update="RenderSamples.xaml">
4739
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>

0 commit comments

Comments
 (0)