-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 48f6c91
Showing
17 changed files
with
1,751 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.vs/ | ||
obj/ | ||
bin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2024 Melissa Geels <[email protected]> | ||
Copyright (c) 2016 Andrew Richards <[email protected]> | ||
Copyright (c) 2014 Leonard Ritter <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the “Software”), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Nimble.Layout\Nimble.Layout.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
namespace Nimble.Layout.Benchmark | ||
{ | ||
internal class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
Console.WriteLine("Running..."); | ||
|
||
const int numRuns = 100_000; | ||
|
||
double totalTime = 0; | ||
|
||
for (int i = 0; i < numRuns; i++) { | ||
var start = DateTime.Now; | ||
var root = ConstructNestedBoxes(); | ||
for (int j = 0; j < 5; j++) { | ||
root.Run(); | ||
} | ||
totalTime += (DateTime.Now - start).TotalMilliseconds; | ||
} | ||
|
||
Console.WriteLine($"Total time: {totalTime}"); | ||
Console.WriteLine($" Avg time: {totalTime / numRuns}"); | ||
Console.ReadKey(); | ||
} | ||
|
||
static LayoutItem ConstructNestedBoxes() | ||
{ | ||
const int numRows = 5; | ||
// One of the rows is "fake" and will have 0 units tall height | ||
const int numRowsWithHeight = numRows - 1; | ||
|
||
var root = new LayoutItem { | ||
Size = new(70, numRowsWithHeight * 10 + 2 * 10), | ||
}; | ||
|
||
var mainChild = new LayoutItem { | ||
Margins = new(10), | ||
Contain = ContainFlags.Column, | ||
Behave = BehaveFlags.Fill, | ||
}; | ||
root.AddChild(mainChild); | ||
|
||
var rows = new LayoutItem[numRows]; | ||
|
||
// Auto-filling columns-in-row, each one should end up being 10 units wide | ||
rows[0] = new LayoutItem { | ||
Contain = ContainFlags.Row, | ||
Behave = BehaveFlags.Fill, | ||
}; | ||
var cols1 = new LayoutItem[5]; | ||
for (int i = 0; i < cols1.Length; i++) { | ||
cols1[i] = new LayoutItem { | ||
Behave = BehaveFlags.Fill, | ||
}; | ||
} | ||
rows[0].AddChildren(cols1); | ||
|
||
rows[1] = new LayoutItem { | ||
Contain = ContainFlags.Row, | ||
Behave = BehaveFlags.VFill, | ||
}; | ||
var cols2 = new LayoutItem[5]; | ||
for (int i = 0; i < cols2.Length; i++) { | ||
// Fixed-size horizontally, fill vertically | ||
cols2[i] = new LayoutItem { | ||
Size = new(10, 0), | ||
Behave = BehaveFlags.VFill, | ||
}; | ||
} | ||
rows[1].AddChildren(cols2); | ||
|
||
// These columns have an inner item which sizes them | ||
rows[2] = new LayoutItem { | ||
Contain = ContainFlags.Row, | ||
}; | ||
var cols3 = new LayoutItem[2]; | ||
for (int i = 0; i < cols3.Length; i++) { | ||
var col = new LayoutItem { | ||
Behave = BehaveFlags.Bottom, | ||
}; | ||
var innerSize = new LayoutItem { | ||
Size = new(25, 10 * i), | ||
}; | ||
col.AddChild(innerSize); | ||
cols3[i] = col; | ||
} | ||
rows[2].AddChildren(cols3); | ||
|
||
// Row 4 should end up being 0 units tall after layout | ||
rows[3] = new LayoutItem { | ||
Contain = ContainFlags.Row, | ||
Behave = BehaveFlags.HFill, | ||
}; | ||
var cols4 = new LayoutItem[99]; | ||
for (int i = 0; i < cols4.Length; i++) { | ||
cols4[i] = new LayoutItem(); | ||
} | ||
rows[3].AddChildren(cols4); | ||
|
||
// row 5 should be 10 pixels tall after layout, and each of its columns should be 1 pixel wide | ||
rows[4] = new LayoutItem { | ||
Contain = ContainFlags.Row, | ||
Behave = BehaveFlags.Fill, | ||
}; | ||
var cols5 = new LayoutItem[50]; | ||
for (int i = 0; i < cols5.Length; i++) { | ||
cols5[i] = new LayoutItem { | ||
Behave = BehaveFlags.Fill, | ||
}; | ||
} | ||
rows[4].AddChildren(cols5); | ||
|
||
mainChild.AddChildren(rows); | ||
|
||
return root; | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Nimble.Layout\Nimble.Layout.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.