Fixes #3127 - View Layout improvements - Redefines how LayoutStyle works. Fixes AutoSize etc... (#3130)

* Removes CheckAbsoulte and updates unit tests to match

* Fixed code that was dependent on ToString behavior vs. direct test for null

* Dim/Pos != null WIP

* Moved AutoSize specific tests out of Pos/Dim tests

* Broke out AutoSize = false tests to new file

* Commented test TODOs

* New test

* Removed unused API and cleaned up code

* Removed unused API and cleaned up code

* Cleaned up code

* Cleaned up code

* reorg'd Toplevel tests

* Fixed Create and related unit tests

* Added test from #3136

* Removed TopLevel.Create

* Fixed SetCurrentOverlappedAsTop

* Updated pull request template

* Updated pull request template

* Revert "Updated pull request template"

This reverts commit d807190dd9.

* reverting

* re-reverting

* Fixed every thing but autosize scenarios??

* Fixed hexview

* Fixed contextmenu

* Fixed more minor issues in tests

* Fixed more minor issues in tests

* Debugging Dialog test failure

* Fixed bad Dialog test. Was cleary invalid

* Fixed OnResizeNeeded bug

* Fixed OnResizeNeeded bug

* Fixed UICatalog to not eat exceptions

* Fixed TextView

* Removed Frame overrides

* Made Frame non-virtual

* Fixed radioGroup

* Fixed TabView

* Hcked ScrolLBarView unit tests to pass

* All AutoSize tests pass!

* All tests pass!!!!!!!

* Updated API docs. Cleaned up code.

* Fixed ColorPicker

* Added 'Bounds =' unit tests

* Refactored TextFormatter.Size setting logic

* Cleaned up OnResizeNeeded (api docs and usages)

* Merges in #3019 changes. Makes OnResizeNeeded non-virtual. If we find a use-case where someone wants to override it we can change this back.

* Fixed FileDialog bounds warning

* Removed resharper settings from editorconfig

* Added Pos.Center test to AllViewsTests.cs.
Modernized RadioGroup.
Fixed ProgressBar.

* Reverted formatting

* Reverted formatting

* Reverted formatting

* Reverted formatting

* Reverted formatting

* Reverted formatting

* Reverted formatting

* Code cleanup

* Code cleanup

* Code cleanup

* Code cleanup

* Code cleanup

* Code cleanup

* Code cleanup

* Code cleanup

* Reverted formatting
This commit is contained in:
Tig
2024-01-12 17:43:35 -07:00
committed by GitHub
parent 4cc6339192
commit d2ad11248f
78 changed files with 21739 additions and 20765 deletions

View File

@@ -1,11 +1,9 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Xunit;
using System.IO;
using System.Text;
using Microsoft.VisualStudio.TestPlatform.Utilities;
using Xunit.Abstractions;
namespace Terminal.Gui.ViewsTests;
@@ -14,22 +12,62 @@ public class AllViewsTests {
public AllViewsTests (ITestOutputHelper output)
{
this._output = output;
_output = output;
}
[Fact]
public void AllViews_Center_Properly ()
{
// See https://github.com/gui-cs/Terminal.Gui/issues/3156
foreach (var type in GetAllViewClasses ()) {
Application.Init (new FakeDriver ());
var view = CreateViewFromType (type, type.GetConstructor (Array.Empty<Type> ()));
if (view == null) {
_output.WriteLine ($"Ignoring {type} - It's a Generic");
Application.Shutdown ();
continue;
}
view.X = Pos.Center ();
view.Y = Pos.Center ();
// Ensure the view has positive dimensions
view.Width = 10;
view.Height = 10;
var frame = new View () {
X = 0,
Y = 0,
Width = 50,
Height = 50,
};
frame.Add (view);
frame.BeginInit ();
frame.EndInit ();
frame.LayoutSubviews ();
// What's the natural width/height?
var expectedX = (frame.Frame.Width - view.Frame.Width) / 2;
var expectedY = (frame.Frame.Height - view.Frame.Height) / 2;
Assert.True (view.Frame.Left == expectedX, $"{view} did not center horizontally. Expected: {expectedX}. Actual: {view.Frame.Left}");
Assert.True (view.Frame.Top == expectedY, $"{view} did not center vertically. Expected: {expectedY}. Actual: {view.Frame.Top}");
Application.Shutdown ();
}
}
[Fact]
public void AllViews_Tests_All_Constructors ()
{
Application.Init (new FakeDriver ());
foreach (var type in GetAllViewClasses ()) {
Assert.True (Constructors_FullTest (type));
Assert.True (Test_All_Constructors_Of_Type (type));
}
Application.Shutdown ();
}
[Fact]
public void AllViews_Enter_Leave_Events ()
{
@@ -39,8 +77,9 @@ public class AllViewsTests {
Application.Init (new FakeDriver ());
var top = Application.Top;
var vType = GetTypeInitializer (type, type.GetConstructor (Array.Empty<Type> ()));
var vType = CreateViewFromType (type, type.GetConstructor (Array.Empty<Type> ()));
if (vType == null) {
_output.WriteLine ($"Ignoring {type} - It's a Generic");
Application.Shutdown ();
continue;
}
@@ -102,10 +141,10 @@ public class AllViewsTests {
// }
//}
public bool Constructors_FullTest (Type type)
public bool Test_All_Constructors_Of_Type (Type type)
{
foreach (var ctor in type.GetConstructors ()) {
var view = GetTypeInitializer (type, ctor);
var view = CreateViewFromType (type, ctor);
if (view != null) {
Assert.True (type.FullName == view.GetType ().FullName);
}
@@ -114,7 +153,7 @@ public class AllViewsTests {
return true;
}
private static View GetTypeInitializer (Type type, ConstructorInfo ctor)
private static View CreateViewFromType (Type type, ConstructorInfo ctor)
{
View viewType = null;
@@ -166,6 +205,8 @@ public class AllViewsTests {
return viewType;
}
// BUGBUG: This is a hack. We should figure out how to dynamically
// create the right type of argument for the constructor.
private static void AddArguments (Type paramType, List<object> pTypes)
{
if (paramType == typeof (Rect)) {