From eb3933b636bea07a7a06e1e9994738f590d319cf Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Thu, 17 Jun 2021 15:56:39 +0100 Subject: [PATCH 1/8] fix order of operations, set Offset before setting Extent --- src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs b/src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs index b0b52812b9..e3783febdd 100644 --- a/src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs +++ b/src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs @@ -511,8 +511,8 @@ namespace Avalonia.Controls.Presenters else if (scrollable.IsLogicalScrollEnabled) { Viewport = scrollable.Viewport; - Extent = scrollable.Extent; Offset = scrollable.Offset; + Extent = scrollable.Extent; } } From 87639cab8ee433dcc27f6f7f408871f5a0cab802 Mon Sep 17 00:00:00 2001 From: FoggyFinder Date: Sat, 26 Jun 2021 18:59:08 +0300 Subject: [PATCH 2/8] adjust checking --- src/Avalonia.Controls.DataGrid/DataGridRows.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Controls.DataGrid/DataGridRows.cs b/src/Avalonia.Controls.DataGrid/DataGridRows.cs index a69b8eafe1..4bfbd7d818 100644 --- a/src/Avalonia.Controls.DataGrid/DataGridRows.cs +++ b/src/Avalonia.Controls.DataGrid/DataGridRows.cs @@ -425,7 +425,7 @@ namespace Avalonia.Controls UpdateDisplayedRows(DisplayData.FirstScrollingSlot, CellsHeight); } - if (DisplayData.FirstScrollingSlot < slot && DisplayData.LastScrollingSlot > slot) + if (DisplayData.FirstScrollingSlot < slot && (DisplayData.LastScrollingSlot > slot || DisplayData.LastScrollingSlot == -1)) { // The row is already displayed in its entirety return true; From f94e4eb9e75d69f3b12b436f2d036331f4d4a0d9 Mon Sep 17 00:00:00 2001 From: Giuseppe Lippolis Date: Tue, 29 Jun 2021 16:54:29 +0200 Subject: [PATCH 3/8] fixes(ComboBox): Closing window on Alt+F4 KeyDown when ComboBox is focused --- src/Avalonia.Controls/ComboBox.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/ComboBox.cs b/src/Avalonia.Controls/ComboBox.cs index f8728af87f..dd2109e6cd 100644 --- a/src/Avalonia.Controls/ComboBox.cs +++ b/src/Avalonia.Controls/ComboBox.cs @@ -205,7 +205,7 @@ namespace Avalonia.Controls if (e.Handled) return; - if (e.Key == Key.F4 || + if ((e.Key == Key.F4 && e.KeyModifiers.HasAllFlags(KeyModifiers.Alt) == false) || ((e.Key == Key.Down || e.Key == Key.Up) && e.KeyModifiers.HasAllFlags(KeyModifiers.Alt))) { IsDropDownOpen = !IsDropDownOpen; From 83c141172f17de098907b7b207f4300f35e8ba73 Mon Sep 17 00:00:00 2001 From: Giuseppe Lippolis Date: Tue, 29 Jun 2021 16:55:09 +0200 Subject: [PATCH 4/8] feat(tests): Add test to check closing window on Alt+F4 KeyDown when ComboBox is focused --- .../ComboBoxTests.cs | 61 ++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/tests/Avalonia.Controls.UnitTests/ComboBoxTests.cs b/tests/Avalonia.Controls.UnitTests/ComboBoxTests.cs index 8f9c7fdb0b..cb2fd11175 100644 --- a/tests/Avalonia.Controls.UnitTests/ComboBoxTests.cs +++ b/tests/Avalonia.Controls.UnitTests/ComboBoxTests.cs @@ -201,6 +201,65 @@ namespace Avalonia.Controls.UnitTests } - } + } + + [Fact] + public void Close_Window_On_Alt_F4_When_ComboBox_Is_Focus() + { + var inputManagerMock = new Moq.Mock(); + var services = TestServices.StyledWindow.With(inputManager: inputManagerMock.Object); + + using (UnitTestApplication.Start(TestServices.StyledWindow)) + { + var window = new Window(); + + window.KeyDown += (s, e) => + { + if (e.Handled == false + && e.KeyModifiers.HasAllFlags(KeyModifiers.Alt) == true + && e.Key == Key.F4 ) + { + e.Handled = true; + window.Close(); + } + }; + + var count = 0; + + var target = new ComboBox + { + Items = new[] { new Canvas() }, + SelectedIndex = 0, + Template = GetTemplate(), + }; + + window.Content = target; + + + window.Closing += + (sender, e) => + { + count++; + }; + + window.Show(); + + target.Focus(); + + _helper.Down(target); + _helper.Up(target); + Assert.True(target.IsDropDownOpen); + + target.RaiseEvent(new KeyEventArgs + { + RoutedEvent = InputElement.KeyDownEvent, + KeyModifiers = KeyModifiers.Alt, + Key = Key.F4 + }); + + + Assert.Equal(1, count); + } + } } } From 5bea0e4791e284829b53fae2935a26de4e86a6ea Mon Sep 17 00:00:00 2001 From: Luis von der Eltz Date: Fri, 2 Jul 2021 14:44:04 +0200 Subject: [PATCH 5/8] Add "Star" static to GridLength --- src/Avalonia.Controls/GridLength.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Avalonia.Controls/GridLength.cs b/src/Avalonia.Controls/GridLength.cs index b8418949d9..ee6a146d61 100644 --- a/src/Avalonia.Controls/GridLength.cs +++ b/src/Avalonia.Controls/GridLength.cs @@ -77,6 +77,12 @@ namespace Avalonia.Controls /// public static GridLength Auto => new GridLength(0, GridUnitType.Auto); + /// + /// Gets an instance of that indicates that a row or column should + /// fill its content. + /// + public static GridLength Star => new GridLength(1, GridUnitType.Star); + /// /// Gets the unit of the . /// From fa3f2c89327b3c31f9dc737fe15152fe184c365c Mon Sep 17 00:00:00 2001 From: Luis von der Eltz Date: Fri, 2 Jul 2021 15:49:19 +0200 Subject: [PATCH 6/8] Adding more ToString() overloads to support DevTools --- src/Avalonia.Controls/RowDefinitions.cs | 8 +++-- src/Avalonia.Visuals/Media/BoxShadow.cs | 41 ++++++++++++++++++++++++ src/Avalonia.Visuals/Media/BoxShadows.cs | 20 +++++++++++- 3 files changed, 66 insertions(+), 3 deletions(-) diff --git a/src/Avalonia.Controls/RowDefinitions.cs b/src/Avalonia.Controls/RowDefinitions.cs index 02ab12b5af..a5ed6ae09d 100644 --- a/src/Avalonia.Controls/RowDefinitions.cs +++ b/src/Avalonia.Controls/RowDefinitions.cs @@ -1,5 +1,4 @@ using System.Linq; -using Avalonia.Collections; namespace Avalonia.Controls { @@ -25,6 +24,11 @@ namespace Avalonia.Controls AddRange(GridLength.ParseLengths(s).Select(x => new RowDefinition(x))); } + public override string ToString() + { + return string.Join(",", this.Select(x => x.Height)); + } + /// /// Parses a string representation of row definitions collection. /// @@ -32,4 +36,4 @@ namespace Avalonia.Controls /// The . public static RowDefinitions Parse(string s) => new RowDefinitions(s); } -} \ No newline at end of file +} diff --git a/src/Avalonia.Visuals/Media/BoxShadow.cs b/src/Avalonia.Visuals/Media/BoxShadow.cs index 69395fd3b8..7696c6c34b 100644 --- a/src/Avalonia.Visuals/Media/BoxShadow.cs +++ b/src/Avalonia.Visuals/Media/BoxShadow.cs @@ -1,5 +1,6 @@ using System; using System.Globalization; +using System.Text; using Avalonia.Animation.Animators; using Avalonia.Utilities; @@ -75,6 +76,46 @@ namespace Avalonia.Media return rv; } } + + public override string ToString() + { + var sb = new StringBuilder(); + + if (IsEmpty) + { + return "none"; + } + + if (IsInset) + { + sb.Append("inset"); + } + + if (OffsetX != 0.0) + { + sb.Append($" {OffsetX}"); + } + + if (OffsetY != 0.0) + { + sb.Append($" {OffsetY}"); + } + + if (Blur != 0.0) + { + sb.Append($" {Blur}"); + } + + if (Spread != 0.0) + { + sb.Append($" {Spread}"); + } + + sb.Append($" {Color.ToString()}"); + + return sb.ToString(); + } + public static unsafe BoxShadow Parse(string s) { if(s == null) diff --git a/src/Avalonia.Visuals/Media/BoxShadows.cs b/src/Avalonia.Visuals/Media/BoxShadows.cs index 9e4d6aacb0..6e1b0e7f7d 100644 --- a/src/Avalonia.Visuals/Media/BoxShadows.cs +++ b/src/Avalonia.Visuals/Media/BoxShadows.cs @@ -1,6 +1,6 @@ using System; -using System.Collections.Generic; using System.ComponentModel; +using System.Text; using Avalonia.Animation.Animators; namespace Avalonia.Media @@ -43,6 +43,24 @@ namespace Avalonia.Media } } + public override string ToString() + { + var sb = new StringBuilder(); + + if (Count == 0) + { + return "none"; + } + + foreach (var boxShadow in this) + { + sb.Append(boxShadow + " "); + } + + return sb.ToString(); + + } + [EditorBrowsable(EditorBrowsableState.Never)] public struct BoxShadowsEnumerator { From 40e6282375b3fc9ae56464b39eb2421df3c8a3b6 Mon Sep 17 00:00:00 2001 From: Luis von der Eltz Date: Fri, 2 Jul 2021 15:51:47 +0200 Subject: [PATCH 7/8] Use interpolation string --- src/Avalonia.Visuals/Media/BoxShadows.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Visuals/Media/BoxShadows.cs b/src/Avalonia.Visuals/Media/BoxShadows.cs index 6e1b0e7f7d..2b1714aded 100644 --- a/src/Avalonia.Visuals/Media/BoxShadows.cs +++ b/src/Avalonia.Visuals/Media/BoxShadows.cs @@ -54,7 +54,7 @@ namespace Avalonia.Media foreach (var boxShadow in this) { - sb.Append(boxShadow + " "); + sb.Append($"{boxShadow} "); } return sb.ToString(); From cddae052e87ce0b06839cee7b8ed4c32d63fa058 Mon Sep 17 00:00:00 2001 From: Luis von der Eltz Date: Fri, 2 Jul 2021 16:46:10 +0200 Subject: [PATCH 8/8] Don't box params, prevent creating temporary string --- src/Avalonia.Visuals/Media/BoxShadow.cs | 10 +++++----- src/Avalonia.Visuals/Media/BoxShadows.cs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Avalonia.Visuals/Media/BoxShadow.cs b/src/Avalonia.Visuals/Media/BoxShadow.cs index 7696c6c34b..50f75365b0 100644 --- a/src/Avalonia.Visuals/Media/BoxShadow.cs +++ b/src/Avalonia.Visuals/Media/BoxShadow.cs @@ -93,25 +93,25 @@ namespace Avalonia.Media if (OffsetX != 0.0) { - sb.Append($" {OffsetX}"); + sb.AppendFormat(" {0}", OffsetX.ToString()); } if (OffsetY != 0.0) { - sb.Append($" {OffsetY}"); + sb.AppendFormat(" {0}", OffsetY.ToString()); } if (Blur != 0.0) { - sb.Append($" {Blur}"); + sb.AppendFormat(" {0}", Blur.ToString()); } if (Spread != 0.0) { - sb.Append($" {Spread}"); + sb.AppendFormat(" {0}", Spread.ToString()); } - sb.Append($" {Color.ToString()}"); + sb.AppendFormat(" {0}", Color.ToString()); return sb.ToString(); } diff --git a/src/Avalonia.Visuals/Media/BoxShadows.cs b/src/Avalonia.Visuals/Media/BoxShadows.cs index 2b1714aded..810ac70b99 100644 --- a/src/Avalonia.Visuals/Media/BoxShadows.cs +++ b/src/Avalonia.Visuals/Media/BoxShadows.cs @@ -54,7 +54,7 @@ namespace Avalonia.Media foreach (var boxShadow in this) { - sb.Append($"{boxShadow} "); + sb.AppendFormat("{0} ", boxShadow.ToString()); } return sb.ToString();