From 3bf0075206f18e997ea704e7ed4cdf9b10509d83 Mon Sep 17 00:00:00 2001 From: MattN-L Date: Wed, 13 Mar 2024 07:29:59 -0400 Subject: [PATCH] Improved keyboard navigation --- PCK-Studio/Forms/Editor/TextureAtlasEditor.cs | 45 ++++++++----------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/PCK-Studio/Forms/Editor/TextureAtlasEditor.cs b/PCK-Studio/Forms/Editor/TextureAtlasEditor.cs index 12ed5b6e..b2ebaca2 100644 --- a/PCK-Studio/Forms/Editor/TextureAtlasEditor.cs +++ b/PCK-Studio/Forms/Editor/TextureAtlasEditor.cs @@ -76,7 +76,17 @@ namespace PckStudio.Forms.Editor private int SelectedIndex { - set => SetImageDisplayed(value); + set { + if (value < 0) + { + value = _tiles.Count + value; + } + else if (value >= _tiles.Count) + { + value = value - _tiles.Count; + } + SetImageDisplayed(value); + } } private const ImageLayoutDirection _imageLayout = ImageLayoutDirection.Horizontal; @@ -348,34 +358,17 @@ namespace PckStudio.Forms.Editor switch (keyData) { case Keys.Left: - if (_tiles.IndexInRange(_selectedTile.Index - 1)) - { - SelectedIndex = _selectedTile.Index - 1; - return true; - } - break; + SelectedIndex = _selectedTile.Index - 1; + return true; case Keys.Right: - if (_tiles.IndexInRange(_selectedTile.Index + 1)) - { - SelectedIndex = _selectedTile.Index + 1; - return true; - } - break; + SelectedIndex = _selectedTile.Index + 1; + return true; case Keys.Up: - if (_tiles.IndexInRange(_selectedTile.Index - _rowCount)) - { - SelectedIndex = _selectedTile.Index - _rowCount; - return true; - } - break; - + SelectedIndex = _selectedTile.Index - _rowCount; + return true; case Keys.Down: - if (_tiles.IndexInRange(_selectedTile.Index + _rowCount)) - { - SelectedIndex = _selectedTile.Index + _rowCount; - return true; - } - break; + SelectedIndex = _selectedTile.Index + _rowCount; + return true; } return false;