| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- using UnitTests;
- using Xunit.Abstractions;
- namespace ViewBaseTests.Adornments;
- public class AdornmentSubViewTests (ITestOutputHelper output)
- {
- private readonly ITestOutputHelper _output = output;
- [Fact]
- public void Setting_Thickness_Causes_Adornment_SubView_Layout ()
- {
- var view = new View ();
- var subView = new View ();
- view.Padding!.Add (subView);
- view.BeginInit ();
- view.EndInit ();
- var raised = false;
- subView.SubViewLayout += LayoutStarted;
- view.Padding.Thickness = new (1, 2, 3, 4);
- view.Layout ();
- Assert.True (raised);
- return;
- void LayoutStarted (object? sender, LayoutEventArgs e)
- {
- raised = true;
- }
- }
- [Theory]
- [InlineData (0, 0, false)] // Padding has no thickness, so false
- [InlineData (0, 1, false)] // Padding has no thickness, so false
- [InlineData (1, 0, true)]
- [InlineData (1, 1, true)]
- [InlineData (2, 1, true)]
- public void Adornment_WithSubView_Finds (int viewPadding, int subViewPadding, bool expectedFound)
- {
- IApplication? app = Application.Create ();
- Runnable<bool> runnable = new ()
- {
- Width = 10,
- Height = 10
- };
- app.Begin (runnable);
- runnable.Padding!.Thickness = new (viewPadding);
- // Turn of TransparentMouse for the test
- runnable.Padding!.ViewportSettings = ViewportSettingsFlags.None;
- var subView = new View ()
- {
- X = 0,
- Y = 0,
- Width = 5,
- Height = 5
- };
- subView.Padding!.Thickness = new (subViewPadding);
- // Turn of TransparentMouse for the test
- subView.Padding!.ViewportSettings = ViewportSettingsFlags.None;
- runnable.Padding!.Add (subView);
- runnable.Layout ();
- View? foundView = runnable.GetViewsUnderLocation (new (0, 0), ViewportSettingsFlags.None).LastOrDefault ();
- bool found = foundView == subView || foundView == subView.Padding;
- Assert.Equal (expectedFound, found);
- }
- [Fact]
- public void Adornment_WithNonVisibleSubView_Finds_Adornment ()
- {
- IApplication? app = Application.Create ();
- Runnable<bool> runnable = new ()
- {
- Width = 10,
- Height = 10
- };
- app.Begin (runnable);
- runnable.Padding!.Thickness = new Thickness (1);
- var subView = new View ()
- {
- X = 0,
- Y = 0,
- Width = 1,
- Height = 1,
- Visible = false
- };
- runnable.Padding.Add (subView);
- runnable.Layout ();
- Assert.Equal (runnable.Padding, runnable.GetViewsUnderLocation (new Point (0, 0), ViewportSettingsFlags.None).LastOrDefault ());
- }
-
- [Fact]
- public void Button_With_Opaque_ShadowStyle_In_Border_Should_Draw_Shadow ()
- {
- // Arrange
- using IApplication app = Application.Create ();
- app.Init ("fake");
- app.Driver?.SetScreenSize (1, 4);
- app.Driver!.Force16Colors = true;
- using Runnable window = new ();
- window.Width = Dim.Fill ();
- window.Height = Dim.Fill ();
- window.Text = @"XXXXXX";
- window.SetScheme (new (new Attribute (Color.Black, Color.White)));
- // Setup padding with some thickness so we have space for the button
- window.Border!.Thickness = new (0, 3, 0, 0);
- // Add a button with a transparent shadow to the Padding adornment
- Button buttonInBorder = new ()
- {
- X = 0,
- Y = 0,
- Text = "B",
- NoDecorations = true,
- NoPadding = true,
- ShadowStyle = ShadowStyle.Opaque,
- };
- window.Border.Add (buttonInBorder);
- app.Begin (window);
- DriverAssert.AssertDriverOutputIs ("""
- \x1b[30m\x1b[107mB▝ \x1b[97m\x1b[40mX
- """,
- _output,
- app.Driver);
- }
- [Fact]
- public void Button_With_Opaque_ShadowStyle_In_Padding_Should_Draw_Shadow ()
- {
- // Arrange
- using IApplication app = Application.Create ();
- app.Init ("fake");
- app.Driver?.SetScreenSize (1, 4);
- app.Driver!.Force16Colors = true;
- using Runnable window = new ();
- window.Width = Dim.Fill ();
- window.Height = Dim.Fill ();
- window.Text = @"XXXXXX";
- window.SetScheme (new (new Attribute (Color.Black, Color.White)));
- // Setup padding with some thickness so we have space for the button
- window.Padding!.Thickness = new (0, 3, 0, 0);
- // Add a button with a transparent shadow to the Padding adornment
- Button buttonInPadding = new ()
- {
- X = 0,
- Y = 0,
- Text = "B",
- NoDecorations = true,
- NoPadding = true,
- ShadowStyle = ShadowStyle.Opaque,
- };
- window.Padding.Add (buttonInPadding);
- app.Begin (window);
- DriverAssert.AssertDriverOutputIs ("""
- \x1b[97m\x1b[40mB\x1b[30m\x1b[107m▝ \x1b[97m\x1b[40mX
- """,
- _output,
- app.Driver);
- }
- }
|