-
-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Aspect ratio calculations fixes and refactoring
- Loading branch information
Showing
9 changed files
with
148 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using Avalonia.Input; | ||
|
||
namespace PicView.Avalonia.CustomControls; | ||
|
||
public class NumTextBox : FuncTextBox | ||
{ | ||
public NumTextBox() | ||
{ | ||
KeyDown += (_, e) => OnKeyDownVerifyInput(e); | ||
} | ||
|
||
private void OnKeyDownVerifyInput(KeyEventArgs e) | ||
{ | ||
switch (e.Key) | ||
{ | ||
case Key.D0: | ||
case Key.D1: | ||
case Key.D2: | ||
case Key.D3: | ||
case Key.D4: | ||
case Key.D5: | ||
case Key.D6: | ||
case Key.D7: | ||
case Key.D8: | ||
case Key.D9: | ||
case Key.NumPad0: | ||
case Key.NumPad1: | ||
case Key.NumPad2: | ||
case Key.NumPad3: | ||
case Key.NumPad4: | ||
case Key.NumPad5: | ||
case Key.NumPad6: | ||
case Key.NumPad7: | ||
case Key.NumPad8: | ||
case Key.NumPad9: | ||
case Key.Back: | ||
case Key.Delete: | ||
break; // Allow numbers and basic operations | ||
|
||
case Key.Left: | ||
case Key.Right: | ||
case Key.Tab: | ||
case Key.OemBackTab: | ||
break; // Allow navigation keys | ||
|
||
case Key.A: | ||
case Key.C: | ||
case Key.X: | ||
case Key.V: | ||
if (e.KeyModifiers == KeyModifiers.Control) | ||
{ | ||
// Allow Ctrl + A, Ctrl + C, Ctrl + X, and Ctrl + V (paste) | ||
break; | ||
} | ||
|
||
e.Handled = true; // Only allow with Ctrl | ||
return; | ||
|
||
case Key.Oem5: // Key for `%` symbol (may vary based on layout) | ||
break; // Allow the percentage symbol (%) | ||
|
||
case Key.Escape: // Handle Escape key | ||
Focus(); | ||
e.Handled = true; | ||
return; | ||
|
||
case Key.Enter: | ||
return; | ||
|
||
default: | ||
e.Handled = true; // Block all other inputs | ||
return; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.