From 60af93106158582ed33cbf495f2ab88b657255a0 Mon Sep 17 00:00:00 2001 From: David Hancock Date: Thu, 30 Nov 2023 21:09:53 +0000 Subject: [PATCH 1/3] Use the asserts for both palette types --- WinUI3Controls/SimpleColorPicker/SimpleColorPicker.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/WinUI3Controls/SimpleColorPicker/SimpleColorPicker.cs b/WinUI3Controls/SimpleColorPicker/SimpleColorPicker.cs index ce7f2a1..12d844f 100644 --- a/WinUI3Controls/SimpleColorPicker/SimpleColorPicker.cs +++ b/WinUI3Controls/SimpleColorPicker/SimpleColorPicker.cs @@ -212,10 +212,10 @@ private void Grid_PreviewKeyDown(object sender, KeyRoutedEventArgs e) index -= newPos.Y - (last.Y + 1); newSelection = grid.Children[index] as Border; - - Debug.Assert(newSelection is not null); - Debug.Assert((Pos)newSelection.Tag == newPos); } + + Debug.Assert(newSelection is not null); + Debug.Assert((Pos)newSelection.Tag == newPos); } if (newSelection is not null) From 95625ba13a629f6396e1f2d860744b9a030de86d Mon Sep 17 00:00:00 2001 From: David Hancock Date: Thu, 30 Nov 2023 21:35:56 +0000 Subject: [PATCH 2/3] Update SimpleColorPicker.cs Tidy code up a bit --- .../SimpleColorPicker/SimpleColorPicker.cs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/WinUI3Controls/SimpleColorPicker/SimpleColorPicker.cs b/WinUI3Controls/SimpleColorPicker/SimpleColorPicker.cs index 12d844f..fa9885b 100644 --- a/WinUI3Controls/SimpleColorPicker/SimpleColorPicker.cs +++ b/WinUI3Controls/SimpleColorPicker/SimpleColorPicker.cs @@ -200,22 +200,19 @@ private void Grid_PreviewKeyDown(object sender, KeyRoutedEventArgs e) default: Debug.Fail(key.ToString()); return; } - if (PaletteOrientation == Orientation.Vertical) - newSelection = grid.Children[(grid.ColumnDefinitions.Count * newPos.Y) + newPos.X] as Border; - else + int index = (grid.ColumnDefinitions.Count * newPos.Y) + newPos.X; + + if (PaletteOrientation == Orientation.Horizontal) // the last column may be incomplete { - // the last column may be incomplete Pos last = Last(); - int index = (grid.ColumnDefinitions.Count * newPos.Y) + newPos.X; - - if (newPos.Y > (last.Y + 1)) // adjust index by the number of empty column positions above this row - index -= newPos.Y - (last.Y + 1); - - newSelection = grid.Children[index] as Border; + // adjust index by the number of empty column positions above this row + index -= Math.Max(0, newPos.Y - (last.Y + 1)); } + newSelection = grid.Children[index] as Border; + Debug.Assert(newSelection is not null); - Debug.Assert((Pos)newSelection.Tag == newPos); + Debug.Assert(((Pos)newSelection.Tag).Equals(newPos)); } if (newSelection is not null) From 470b27cfcb6df231d5c5760e96d84428aa8a47c3 Mon Sep 17 00:00:00 2001 From: David Hancock Date: Fri, 1 Dec 2023 09:38:09 +0000 Subject: [PATCH 3/3] Use Grid attached properties for x, y --- WinUI3Controls/SimpleColorPicker/SimpleColorPicker.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/WinUI3Controls/SimpleColorPicker/SimpleColorPicker.cs b/WinUI3Controls/SimpleColorPicker/SimpleColorPicker.cs index fa9885b..58dc7be 100644 --- a/WinUI3Controls/SimpleColorPicker/SimpleColorPicker.cs +++ b/WinUI3Controls/SimpleColorPicker/SimpleColorPicker.cs @@ -188,7 +188,7 @@ private void Grid_PreviewKeyDown(object sender, KeyRoutedEventArgs e) if ((newSelection is null) && (selected is not null)) { - Pos pos = (Pos)selected.Tag; + Pos pos = new Pos(Grid.GetColumn(selected), Grid.GetRow(selected)); Pos newPos; switch (key) @@ -212,7 +212,8 @@ private void Grid_PreviewKeyDown(object sender, KeyRoutedEventArgs e) newSelection = grid.Children[index] as Border; Debug.Assert(newSelection is not null); - Debug.Assert(((Pos)newSelection.Tag).Equals(newPos)); + Debug.Assert(newPos.X == Grid.GetColumn(newSelection)); + Debug.Assert(newPos.Y == Grid.GetRow(newSelection)); } if (newSelection is not null) @@ -528,7 +529,6 @@ private Border CreateBorder(int x, int y, Color color) { Border border = new Border(); - border.Tag = new Pos(x, y); border.Background = new SolidColorBrush(color); border.ScaleTransition = new Vector3Transition(); border.ScaleTransition.Duration = TimeSpan.FromMilliseconds(200);