diff --git a/samples/Myra.Samples.Layout2D/MyraSamplesLayout2D.cs b/samples/Myra.Samples.Layout2D/MyraSamplesLayout2D.cs
index fb4511c5..c450e381 100644
--- a/samples/Myra.Samples.Layout2D/MyraSamplesLayout2D.cs
+++ b/samples/Myra.Samples.Layout2D/MyraSamplesLayout2D.cs
@@ -78,7 +78,7 @@ protected override void LoadContent()
{
Text = "Calc"
};
- btnA.Click += (object sender, EventArgs e) => { btnB.Layout2d.Expresion = (_desktop.GetWidgetByID("Expression") as TextBox).Text; _desktop.InvalidateLayout(); _desktop.UpdateLayout(); };
+ btnA.Click += (object sender, EventArgs e) => { btnB.Layout2d.Expresion = (_desktop.FindChild("Expression") as TextBox).Text; _desktop.InvalidateLayout(); _desktop.UpdateLayout(); };
panel.Widgets.Add(btnA);
g.Widgets.Add(panel);
diff --git a/src/Myra.Tests/GridTests.cs b/src/Myra.Tests/GridTests.cs
new file mode 100644
index 00000000..e22c8ceb
--- /dev/null
+++ b/src/Myra.Tests/GridTests.cs
@@ -0,0 +1,53 @@
+using Microsoft.Xna.Framework;
+using Myra.Graphics2D.UI;
+using NUnit.Framework;
+
+namespace Myra.Tests
+{
+ [TestFixture]
+ public class GridTests
+ {
+ private static Project LoadFromResource(string name)
+ {
+ var xml = typeof(GridTests).Assembly.ReadResourceAsString("Resources.GridTests." + name);
+
+ return Project.LoadFromXml(xml);
+ }
+
+ [Test]
+ public static void TestSimpleProportionsPart()
+ {
+ var project = LoadFromResource("SimpleProportionsPart.xmmp");
+ var grid = (Grid)project.Root;
+
+ grid.Arrange(new Rectangle(0, 0, 400, 400));
+
+ Assert.AreEqual(100, grid.Widgets[0].ContainerBounds.Width);
+ Assert.AreEqual(200, grid.Widgets[0].ContainerBounds.Height);
+ Assert.AreEqual(300, grid.Widgets[1].ContainerBounds.Width);
+ Assert.AreEqual(200, grid.Widgets[1].ContainerBounds.Height);
+ Assert.AreEqual(100, grid.Widgets[2].ContainerBounds.Width);
+ Assert.AreEqual(200, grid.Widgets[2].ContainerBounds.Height);
+ Assert.AreEqual(300, grid.Widgets[3].ContainerBounds.Width);
+ Assert.AreEqual(200, grid.Widgets[3].ContainerBounds.Height);
+ }
+
+ [Test]
+ public static void TestSimpleAutoFill()
+ {
+ var project = LoadFromResource("SimpleAutoFill.xmmp");
+ var grid = (Grid)project.Root;
+
+ grid.Arrange(new Rectangle(0, 0, 400, 500));
+
+ Assert.AreEqual(100, grid.Widgets[0].ContainerBounds.Width);
+ Assert.AreEqual(450, grid.Widgets[0].ContainerBounds.Height);
+ Assert.AreEqual(300, grid.Widgets[1].ContainerBounds.Width);
+ Assert.AreEqual(450, grid.Widgets[1].ContainerBounds.Height);
+ Assert.AreEqual(100, grid.Widgets[2].ContainerBounds.Width);
+ Assert.AreEqual(50, grid.Widgets[2].ContainerBounds.Height);
+ Assert.AreEqual(300, grid.Widgets[3].ContainerBounds.Width);
+ Assert.AreEqual(50, grid.Widgets[3].ContainerBounds.Height);
+ }
+ }
+}
diff --git a/src/Myra.Tests/Res.cs b/src/Myra.Tests/Res.cs
new file mode 100644
index 00000000..e7aedeff
--- /dev/null
+++ b/src/Myra.Tests/Res.cs
@@ -0,0 +1,65 @@
+using System.IO;
+using System.Reflection;
+using System;
+
+namespace Myra.Tests
+{
+ internal static class Res
+ {
+ ///
+ /// Open assembly resource stream by relative name
+ ///
+ ///
+ ///
+ ///
+ public static Stream OpenResourceStream(this Assembly assembly, string path)
+ {
+ // Once you figure out the name, pass it in as the argument here.
+ path = assembly.GetName().Name + "." + path;
+ var stream = assembly.GetManifestResourceStream(path);
+ if (stream == null)
+ {
+ throw new Exception($"Could not find resource at path '{path}'");
+ }
+
+ return stream;
+ }
+
+ ///
+ /// Reads assembly resource as byte array by relative name
+ ///
+ ///
+ ///
+ ///
+ public static byte[] ReadResourceAsBytes(this Assembly assembly, string path)
+ {
+ var ms = new MemoryStream();
+ using (var input = assembly.OpenResourceStream(path))
+ {
+ input.CopyTo(ms);
+
+ return ms.ToArray();
+ }
+ }
+
+ ///
+ /// Reads assembly resource as string by relative name
+ ///
+ ///
+ ///
+ ///
+ public static string ReadResourceAsString(this Assembly assembly, string path)
+ {
+ string result;
+ using (var input = assembly.OpenResourceStream(path))
+ {
+ using (var textReader = new StreamReader(input))
+ {
+ result = textReader.ReadToEnd();
+ }
+ }
+
+ return result;
+ }
+ }
+}
diff --git a/src/Myra.Tests/Resources/GridTests/SimpleAutoFill.xmmp b/src/Myra.Tests/Resources/GridTests/SimpleAutoFill.xmmp
new file mode 100644
index 00000000..378943f8
--- /dev/null
+++ b/src/Myra.Tests/Resources/GridTests/SimpleAutoFill.xmmp
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Myra.Tests/Resources/GridTests/SimpleProportionsPart.xmmp b/src/Myra.Tests/Resources/GridTests/SimpleProportionsPart.xmmp
new file mode 100644
index 00000000..774d1795
--- /dev/null
+++ b/src/Myra.Tests/Resources/GridTests/SimpleProportionsPart.xmmp
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Myra/Graphics2D/UI/Project.cs b/src/Myra/Graphics2D/UI/Project.cs
index 7168ba0b..69d13d06 100644
--- a/src/Myra/Graphics2D/UI/Project.cs
+++ b/src/Myra/Graphics2D/UI/Project.cs
@@ -232,7 +232,7 @@ public static Project LoadFromXml(XDocument xDoc, AssetManager assetManager =
var result = new Project();
- if (stylesheet != null)
+ if (stylesheetPathAttr != null)
{
if (assetManager == null)
{