Skip to content

Commit

Permalink
Merge pull request #40 from DHancock/Dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
DHancock authored Dec 1, 2023
2 parents 9668905 + 470b27c commit f2a9b18
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions WinUI3Controls/SimpleColorPicker/SimpleColorPicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -200,22 +200,20 @@ 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);
// 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;
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(newPos.X == Grid.GetColumn(newSelection));
Debug.Assert(newPos.Y == Grid.GetRow(newSelection));
}

if (newSelection is not null)
Expand Down Expand Up @@ -531,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);
Expand Down

0 comments on commit f2a9b18

Please sign in to comment.