This commit is contained in:
Tig
2024-05-29 10:50:22 -06:00
35 changed files with 352 additions and 190 deletions

View File

@@ -671,7 +671,7 @@ public class DimAutoTests (ITestOutputHelper output)
superView.BeginInit ();
superView.EndInit ();
superView.SetRelativeLayout (superView.ContentSize);
superView.SetRelativeLayout (superView.GetContentSize ());
superView.LayoutSubviews ();
Assert.Equal (expectedSubWidth, subView.Frame.Width);
@@ -720,7 +720,7 @@ public class DimAutoTests (ITestOutputHelper output)
superView.BeginInit ();
superView.EndInit ();
superView.SetRelativeLayout (superView.ContentSize);
superView.SetRelativeLayout (superView.GetContentSize ());
superView.LayoutSubviews ();
Assert.Equal (expectedSubWidth, subView.Frame.Width);
@@ -745,7 +745,7 @@ public class DimAutoTests (ITestOutputHelper output)
super.Add (view);
Rectangle expectedViewport = new (0, 0, 8, 1);
Assert.Equal (expectedViewport.Size, view.ContentSize);
Assert.Equal (expectedViewport.Size, view.GetContentSize ());
Assert.Equal (expectedViewport, view.Frame);
Assert.Equal (expectedViewport, view.Viewport);
@@ -943,19 +943,19 @@ public class DimAutoTests (ITestOutputHelper output)
};
Assert.Equal (new Rectangle (0, 0, 5, 1), view.Frame);
Assert.Equal (new Size (5, 1), view.ContentSize);
Assert.Equal (new Size (5, 1), view.GetContentSize ());
// Change text to a longer string
view.Text = "0123456789";
Assert.Equal (new Rectangle (0, 0, 10, 1), view.Frame);
Assert.Equal (new Size (10, 1), view.ContentSize);
Assert.Equal (new Size (10, 1), view.GetContentSize ());
// If ContentSize was reset, these should cause it to update
view.Width = 5;
view.Height = 1;
Assert.Equal (new Size (5, 1), view.ContentSize);
Assert.Equal (new Size (5, 1), view.GetContentSize ());
}
// DimAutoStyle.Content tests
@@ -972,6 +972,22 @@ public class DimAutoTests (ITestOutputHelper output)
Assert.Equal (10, calculatedWidth);
}
[Fact]
public void DimAutoStyle_Content_IgnoresSubviews_When_ContentSize_Is_Set ()
{
var view = new View ();
var subview = new View () {
Frame = new Rectangle (50, 50, 1, 1)
};
view.SetContentSize (new (10, 5));
var dim = Dim.Auto (DimAutoStyle.Content);
int calculatedWidth = dim.Calculate (0, 100, view, Dimension.Width);
Assert.Equal (10, calculatedWidth);
}
[Fact]
public void DimAutoStyle_Content_IgnoresText_WhenContentSizeNotSet ()
{

View File

@@ -338,14 +338,57 @@ public class ViewportTests (ITestOutputHelper output)
}
[Fact]
public void ContentSize_Matches_ViewportSize_If_Not_Set ()
public void ContentSize_Tracks_ViewportSize_If_Not_Set ()
{
View view = new ()
{
Width = 1,
Height = 1
};
Assert.Equal (view.Viewport.Size, view.ContentSize);
Assert.True (view.ContentSizeTracksViewport);
Assert.Equal (view.Viewport.Size, view.GetContentSize ());
}
[Fact]
public void ContentSize_Ignores_ViewportSize_If_Set ()
{
View view = new ()
{
Width = 1,
Height = 1,
};
view.SetContentSize (new Size (5, 5));
Assert.False (view.ContentSizeTracksViewport);
Assert.NotEqual (view.Viewport.Size, view.GetContentSize ());
}
[Fact]
public void ContentSize_Tracks_ViewportSize_If_ContentSizeTracksViewport_Is_True ()
{
View view = new ()
{
Width = 1,
Height = 1,
};
view.SetContentSize (new Size (5, 5));
view.Viewport = new (0, 0, 10, 10);
view.ContentSizeTracksViewport = true;
Assert.Equal (view.Viewport.Size, view.GetContentSize ());
}
[Fact]
public void ContentSize_Ignores_ViewportSize_If_ContentSizeTracksViewport_Is_False ()
{
View view = new ()
{
Width = 1,
Height = 1,
};
view.SetContentSize (new Size (5, 5));
view.Viewport = new (0, 0, 10, 10);
view.ContentSizeTracksViewport = false;
Assert.NotEqual (view.Viewport.Size, view.GetContentSize ());
}
//[Theory]

View File

@@ -75,7 +75,7 @@ public class SubviewTests
w2.Dispose ();
top2.Dispose ();
}
[Fact]
[TestRespondersDisposed]
public void Initialized_Event_Comparing_With_Added_Event ()
@@ -332,4 +332,45 @@ public class SubviewTests
top.Dispose ();
view.Dispose ();
}
// TODO: Consider a feature that will change the ContentSize to fit the subviews.
[Fact]
public void Add_Does_Not_Impact_ContentSize ()
{
var view = new View ();
view.SetContentSize (new Size (1, 1));
var subview = new View ()
{
X = 10,
Y = 10
};
Assert.Equal (new Size (1, 1), view.GetContentSize ());
view.Add (subview);
Assert.Equal (new Size (1, 1), view.GetContentSize ());
}
[Fact]
public void Remove_Does_Not_Impact_ContentSize ()
{
var view = new View ();
view.SetContentSize (new Size (1, 1));
var subview = new View ()
{
X = 10,
Y = 10
};
Assert.Equal (new Size (1, 1), view.GetContentSize ());
view.Add (subview);
Assert.Equal (new Size (1, 1), view.GetContentSize ());
view.SetContentSize (new Size (5, 5));
Assert.Equal (new Size (5, 5), view.GetContentSize ());
view.Remove (subview);
Assert.Equal (new Size (5, 5), view.GetContentSize ());
}
}

View File

@@ -32,7 +32,7 @@ public class TextTests (ITestOutputHelper output)
public void TextFormatter_Size_Tracks_ContentSize (string text, int expectedW, int expectedH)
{
var view = new View ();
view.SetContentSize(new (1,1));
view.SetContentSize (new (1,1));
view.Text = text;
Assert.Equal (new (expectedW, expectedH), view.TextFormatter.Size);
}

View File

@@ -102,7 +102,7 @@ public class TitleTests (ITestOutputHelper output)
Assert.Equal (text, view.Text);
// SetupFakeDriver only create a screen with 25 cols and 25 rows
Assert.Equal (new (text.Length, 1), view.ContentSize);
Assert.Equal (new (text.Length, 1), view.GetContentSize ());
top.Dispose ();
}