From 7bc98762baaa4ea49ae8a31e83759dcc2300bf7f Mon Sep 17 00:00:00 2001 From: chinboy Date: Thu, 13 Nov 2025 17:15:43 +0800 Subject: [PATCH] Add Resize support for TextArea --- .../TokenResourceConst.g.cs | 2 + src/AtomUI.Controls/Input/ResizeHandle.cs | 52 +++++++ src/AtomUI.Controls/Input/TextArea.cs | 96 ++++++++++++ .../Input/TextAreaDecoratedBox.cs | 58 +++++++ src/AtomUI.Controls/Input/TextAreaToken.cs | 19 ++- src/AtomUI.Controls/Input/TextBox.cs | 42 +++++ .../Input/Themes/InputThemeConstants.cs | 3 +- .../Input/Themes/InputThemes.axaml | 1 + .../Input/Themes/LineEditTheme.axaml | 7 +- .../Input/Themes/ResizeHandleTheme.axaml | 18 +++ .../Themes/TextAreaDecoratedBoxTheme.axaml | 75 ++++----- .../Input/Themes/TextAreaTheme.axaml | 146 ++++++++++-------- .../Input/Themes/TextBoxTheme.axaml | 9 +- .../TimePicker/TimePickerFlyout.cs | 14 +- 14 files changed, 427 insertions(+), 115 deletions(-) create mode 100644 src/AtomUI.Controls/Input/ResizeHandle.cs create mode 100644 src/AtomUI.Controls/Input/Themes/ResizeHandleTheme.axaml diff --git a/src/AtomUI.Controls/GeneratedFiles/AtomUI.Generator/AtomUI.Generator.TokenResourceKeyGenerator/TokenResourceConst.g.cs b/src/AtomUI.Controls/GeneratedFiles/AtomUI.Generator/AtomUI.Generator.TokenResourceKeyGenerator/TokenResourceConst.g.cs index 20ee1a0f6..d116bff6b 100644 --- a/src/AtomUI.Controls/GeneratedFiles/AtomUI.Generator/AtomUI.Generator.TokenResourceKeyGenerator/TokenResourceConst.g.cs +++ b/src/AtomUI.Controls/GeneratedFiles/AtomUI.Generator/AtomUI.Generator.TokenResourceKeyGenerator/TokenResourceConst.g.cs @@ -392,6 +392,8 @@ namespace AtomUI.Controls.DesignTokens public static readonly TokenResourceKey FontSize = new TokenResourceKey("TextArea.FontSize"); public static readonly TokenResourceKey FontSizeLG = new TokenResourceKey("TextArea.FontSizeLG"); public static readonly TokenResourceKey FontSizeSM = new TokenResourceKey("TextArea.FontSizeSM"); + public static readonly TokenResourceKey ResizeHandleSize = new TokenResourceKey("TextArea.ResizeHandleSize"); + public static readonly TokenResourceKey ResizeIndicatorLineColor = new TokenResourceKey("TextArea.ResizeIndicatorLineColor"); } public static class ListTokenKey diff --git a/src/AtomUI.Controls/Input/ResizeHandle.cs b/src/AtomUI.Controls/Input/ResizeHandle.cs new file mode 100644 index 000000000..768bace7b --- /dev/null +++ b/src/AtomUI.Controls/Input/ResizeHandle.cs @@ -0,0 +1,52 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Controls.Primitives; +using Avalonia.Input; + +namespace AtomUI.Controls; + +internal class ResizeHandle : TemplatedControl +{ + internal TextArea? Owner { get; set; } + + private Point? _lastPoint; + private bool _dragging; + + protected override void OnPointerPressed(PointerPressedEventArgs e) + { + base.OnPointerPressed(e); + e.Handled = true; + _lastPoint = e.GetPosition(TopLevel.GetTopLevel(this)); + } + + protected override void OnPointerReleased(PointerReleasedEventArgs e) + { + base.OnPointerReleased(e); + if (_lastPoint.HasValue) + { + Owner?.NotifyResizeCompleted(); + e.Handled = true; + _lastPoint = null; + _dragging = false; + } + } + + protected override void OnPointerMoved(PointerEventArgs e) + { + base.OnPointerMoved(e); + if (_lastPoint.HasValue && e.Properties.IsLeftButtonPressed) + { + var delta = e.GetPosition(TopLevel.GetTopLevel(this)) - _lastPoint.Value; + var manhattanDistance = Math.Abs(delta.X) + Math.Abs(delta.Y); + if (manhattanDistance > Constants.DragThreshold) + { + if (!_dragging) + { + Owner?.NotifyAboutToResize(); + _dragging = true; + } + Owner?.NotifyResizing(delta); + } + } + } +} \ No newline at end of file diff --git a/src/AtomUI.Controls/Input/TextArea.cs b/src/AtomUI.Controls/Input/TextArea.cs index ec11014a7..e72df3452 100644 --- a/src/AtomUI.Controls/Input/TextArea.cs +++ b/src/AtomUI.Controls/Input/TextArea.cs @@ -6,6 +6,7 @@ using Avalonia; using Avalonia.Controls; using Avalonia.Controls.Primitives; using Avalonia.Controls.Templates; +using Avalonia.Input; using Avalonia.Media; using Avalonia.Media.TextFormatting; @@ -25,7 +26,13 @@ public class TextArea : AvaloniaTextBox, public static readonly StyledProperty IsAutoSizeProperty = AvaloniaProperty.Register(nameof(IsAutoSize), false); + + public static readonly StyledProperty IsShowCountProperty = + AvaloniaProperty.Register(nameof(IsShowCount)); + public static readonly StyledProperty IsResizableProperty = + AvaloniaProperty.Register(nameof(IsResizable)); + public static readonly StyledProperty StyleVariantProperty = AddOnDecoratedBox.StyleVariantProperty.AddOwner