From ec95eef3757dea7948153b6359672011c3013640 Mon Sep 17 00:00:00 2001 From: Alek-ban Date: Wed, 13 May 2026 12:22:54 +0300 Subject: [PATCH] feat: implement and move touch controls to separate namespace --- GSS2/Controls/TouchNumericUpDown.cs | 41 ++++++++++++++++++++++++++++ GSS2/Controls/TouchTextBox.cs | 42 +++++++++++++++++++++++++++++ GSS2/TouchNumericUpDown.cs | 22 --------------- GSS2/TouchTextBox.cs | 20 -------------- 4 files changed, 83 insertions(+), 42 deletions(-) create mode 100644 GSS2/Controls/TouchNumericUpDown.cs create mode 100644 GSS2/Controls/TouchTextBox.cs delete mode 100644 GSS2/TouchNumericUpDown.cs delete mode 100644 GSS2/TouchTextBox.cs diff --git a/GSS2/Controls/TouchNumericUpDown.cs b/GSS2/Controls/TouchNumericUpDown.cs new file mode 100644 index 0000000..49e9558 --- /dev/null +++ b/GSS2/Controls/TouchNumericUpDown.cs @@ -0,0 +1,41 @@ +using Avalonia.Controls; +using Avalonia.Input; + +using GSS2.ViewModels; +using GSS2.Views; + +namespace GSS2.Controls; + +public class TouchNumericUpDown : NumericUpDown +{ + protected override Type StyleKeyOverride => typeof(NumericUpDown); + + public TouchNumericUpDown() + : base() + { + AddHandler(PointerPressedEvent, OnPointerPressed, handledEventsToo: true); + } + + private void OnPointerPressed(object? sender, PointerPressedEventArgs ea) + { + if (ea.Pointer.Type != PointerType.Touch) + return; + var navigation = (Application.Current as Application)?.Navigation; + if (navigation is null) + return; + + var keyboardViewModel = new NumericKeyboardViewModel(navigation); + keyboardViewModel.Value = (double?)Value; + keyboardViewModel.Closes += (_, ea) => + { + if (ea is null) + return; + Value = (decimal)ea.Value; + }; + var keyboardView = new NumericKeyboardView() + { + DataContext = keyboardViewModel + }; + navigation.NavigateTo(keyboardView); + } +} diff --git a/GSS2/Controls/TouchTextBox.cs b/GSS2/Controls/TouchTextBox.cs new file mode 100644 index 0000000..0c233a4 --- /dev/null +++ b/GSS2/Controls/TouchTextBox.cs @@ -0,0 +1,42 @@ +using Avalonia.Controls; +using Avalonia.Input; + +using GSS2.ViewModels; +using GSS2.Views; + +namespace GSS2.Controls; + +public class TouchTextBox : TextBox +{ + protected override Type StyleKeyOverride => typeof(TextBox); + + public TouchTextBox() + : base() + { + AddHandler(PointerPressedEvent, OnPointerPressed, handledEventsToo: true); + } + + private void OnPointerPressed(object? sender, PointerPressedEventArgs ea) + { + // if (ea.Pointer.Type != PointerType.Touch) + // return; + var navigation = (Application.Current as Application)?.Navigation; + if (navigation is null) + return; + + var keyboardViewModel = new TextKeyboardViewModel(navigation); + keyboardViewModel.Value = Text; + keyboardViewModel.IsMultiline = AcceptsReturn; + keyboardViewModel.Closes += (_, ea) => + { + if (ea is null) + return; + Text = ea; + }; + var keyboardView = new TextKeyboardView() + { + DataContext = keyboardViewModel + }; + navigation.NavigateTo(keyboardView); + } +} diff --git a/GSS2/TouchNumericUpDown.cs b/GSS2/TouchNumericUpDown.cs deleted file mode 100644 index 4c08847..0000000 --- a/GSS2/TouchNumericUpDown.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Avalonia; -using Avalonia.Controls; -using Avalonia.Input; - -namespace GSS2; - -public class TouchNumericUpDown : NumericUpDown -{ - protected override Type StyleKeyOverride => typeof(NumericUpDown); - - public TouchNumericUpDown() - : base() - { - AddHandler(PointerPressedEvent, OnPointerPressed, handledEventsToo: true); - } - - private void OnPointerPressed(object? sender, PointerPressedEventArgs ea) - { - Console.WriteLine($"TODO: process TouchNumericUpDown.PointerPressed event"); - - } -} diff --git a/GSS2/TouchTextBox.cs b/GSS2/TouchTextBox.cs deleted file mode 100644 index 65799db..0000000 --- a/GSS2/TouchTextBox.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Avalonia.Controls; -using Avalonia.Input; - -namespace GSS2; - -public class TouchTextBox : TextBox -{ - protected override Type StyleKeyOverride => typeof(TextBox); - - public TouchTextBox() - : base() - { - AddHandler(PointerPressedEvent, OnPointerPressed, handledEventsToo: true); - } - - private void OnPointerPressed(object? sender, PointerPressedEventArgs ea) - { - Console.WriteLine($"TODO: process TouchTextBox.PointerPressed event"); - } -}