diff --git a/Terminal.Gui/Drawing/Aligner.cs b/Terminal.Gui/Drawing/Aligner.cs index 1c96a2ac0..47b4109f8 100644 --- a/Terminal.Gui/Drawing/Aligner.cs +++ b/Terminal.Gui/Drawing/Aligner.cs @@ -108,10 +108,11 @@ public class Aligner : INotifyPropertyChanged spacesToGive = containerSize - totalItemsSize; } + AlignmentModes mode = alignmentMode & ~AlignmentModes.AddSpaceBetweenItems; // copy to avoid modifying the original switch (alignment) { case Alignment.Start: - switch (alignmentMode & ~AlignmentModes.AddSpaceBetweenItems) + switch (mode) { case AlignmentModes.StartToEnd: return Start (in sizesCopy, maxSpaceBetweenItems, spacesToGive); @@ -129,7 +130,7 @@ public class Aligner : INotifyPropertyChanged break; case Alignment.End: - switch (alignmentMode & ~AlignmentModes.AddSpaceBetweenItems) + switch (mode) { case AlignmentModes.StartToEnd: return End (in sizesCopy, containerSize, totalItemsSize, maxSpaceBetweenItems, spacesToGive); @@ -147,7 +148,8 @@ public class Aligner : INotifyPropertyChanged break; case Alignment.Center: - switch (alignmentMode & ~AlignmentModes.AddSpaceBetweenItems) + mode &= ~AlignmentModes.IgnoreFirstOrLast; + switch (mode) { case AlignmentModes.StartToEnd: return Center (in sizesCopy, containerSize, totalItemsSize, maxSpaceBetweenItems, spacesToGive); @@ -159,7 +161,8 @@ public class Aligner : INotifyPropertyChanged break; case Alignment.Fill: - switch (alignmentMode & ~AlignmentModes.AddSpaceBetweenItems) + mode &= ~AlignmentModes.IgnoreFirstOrLast; + switch (mode) { case AlignmentModes.StartToEnd: return Fill (in sizesCopy, containerSize, totalItemsSize); @@ -260,7 +263,8 @@ public class Aligner : INotifyPropertyChanged var currentPosition = 0; if (totalItemsSize > containerSize) { - currentPosition = containerSize - totalItemsSize - spacesToGive; + // Don't allow negative positions + currentPosition = int.Max(0, containerSize - totalItemsSize - spacesToGive); } for (var i = 0; i < sizes.Length; i++) diff --git a/UnitTests/Drawing/AlignerTests.cs b/UnitTests/Drawing/AlignerTests.cs index cc9d1c92b..ecbe91c58 100644 --- a/UnitTests/Drawing/AlignerTests.cs +++ b/UnitTests/Drawing/AlignerTests.cs @@ -218,7 +218,7 @@ public class AlignerTests (ITestOutputHelper output) [InlineData (Alignment.Start, AlignmentModes.StartToEnd | AlignmentModes.AddSpaceBetweenItems | AlignmentModes.IgnoreFirstOrLast, new [] { 1, 2, 3 }, 9, new [] { 0, 2, 6 })] [InlineData (Alignment.Start, AlignmentModes.StartToEnd | AlignmentModes.AddSpaceBetweenItems | AlignmentModes.IgnoreFirstOrLast, new [] { 1, 2, 3 }, 10, new [] { 0, 2, 7 })] [InlineData (Alignment.Start, AlignmentModes.StartToEnd | AlignmentModes.AddSpaceBetweenItems | AlignmentModes.IgnoreFirstOrLast, new [] { 1, 2, 3 }, 11, new [] { 0, 2, 8 })] - [InlineData (Alignment.Start, AlignmentModes.StartToEnd | AlignmentModes.AddSpaceBetweenItems | AlignmentModes.IgnoreFirstOrLast, new [] { 1, 2, 3 }, 5, new [] { -1, 0, 2 })] // 5 is too small to fit the items. The first item is at -1.})] + [InlineData (Alignment.Start, AlignmentModes.StartToEnd | AlignmentModes.AddSpaceBetweenItems | AlignmentModes.IgnoreFirstOrLast, new [] { 1, 2, 3 }, 5, new [] { 0, 1, 2 })] [InlineData (Alignment.Start, AlignmentModes.StartToEnd | AlignmentModes.AddSpaceBetweenItems | AlignmentModes.IgnoreFirstOrLast, new [] { 1, 2, 3, 4 }, 10, new [] { 0, 1, 3, 6 })] [InlineData (Alignment.Start, AlignmentModes.StartToEnd | AlignmentModes.AddSpaceBetweenItems | AlignmentModes.IgnoreFirstOrLast, new [] { 1, 2, 3, 4 }, 11, new [] { 0, 2, 4, 7 })] [InlineData (Alignment.Start, AlignmentModes.StartToEnd | AlignmentModes.AddSpaceBetweenItems | AlignmentModes.IgnoreFirstOrLast, new [] { 3, 3, 3 }, 21, new [] { 0, 4, 18 })] diff --git a/UnitTests/Views/ShortcutTests.cs b/UnitTests/Views/ShortcutTests.cs index a3b934626..efd1bd432 100644 --- a/UnitTests/Views/ShortcutTests.cs +++ b/UnitTests/Views/ShortcutTests.cs @@ -22,20 +22,20 @@ public class ShortcutTests } [Theory] - [InlineData ("", "", KeyCode.Null, 0)] + [InlineData ("", "", KeyCode.Null, 2)] [InlineData ("C", "", KeyCode.Null, 3)] - [InlineData ("", "H", KeyCode.Null, 3)] - [InlineData ("", "", KeyCode.K, 3)] + [InlineData ("", "H", KeyCode.Null, 5)] + [InlineData ("", "", KeyCode.K, 5)] [InlineData ("C", "", KeyCode.K, 6)] [InlineData ("C", "H", KeyCode.Null, 6)] - [InlineData ("", "H", KeyCode.K, 6)] + [InlineData ("", "H", KeyCode.K, 8)] [InlineData ("C", "H", KeyCode.K, 9)] public void NaturalSize (string command, string help, Key key, int expectedWidth) { Shortcut shortcut = new Shortcut () { Title = command, - Text = help, + HelpText = help, Key = key, }; @@ -79,7 +79,7 @@ public class ShortcutTests } [Fact] - public void CommandView_Text_And_Title_Are_The_Same () + public void CommandView_Text_And_Title_Track () { Shortcut shortcut = new Shortcut () { @@ -88,12 +88,6 @@ public class ShortcutTests Assert.Equal (shortcut.Title, shortcut.CommandView.Text); - shortcut = new Shortcut () - { - }; - shortcut.CommandView.Text = "T"; - Assert.Equal (shortcut.Title, shortcut.CommandView.Text); - shortcut = new Shortcut () { };