diff --git a/controlgallery/AtomUIGallery/ShowCases/Views/DataEntry/LineEditShowCase.axaml b/controlgallery/AtomUIGallery/ShowCases/Views/DataEntry/LineEditShowCase.axaml index bab51c75a..43b565f99 100644 --- a/controlgallery/AtomUIGallery/ShowCases/Views/DataEntry/LineEditShowCase.axaml +++ b/controlgallery/AtomUIGallery/ShowCases/Views/DataEntry/LineEditShowCase.axaml @@ -348,20 +348,20 @@ Title="With character counting" Description="Show character counting."> - + - - - - - - - - + + + + + + + + + + + diff --git a/src/AtomUI.Desktop.Controls/Input/ResizeHandle.cs b/src/AtomUI.Desktop.Controls/Input/ResizeHandle.cs index b322d14ba..2cea39417 100644 --- a/src/AtomUI.Desktop.Controls/Input/ResizeHandle.cs +++ b/src/AtomUI.Desktop.Controls/Input/ResizeHandle.cs @@ -16,8 +16,9 @@ internal class ResizeHandle : TemplatedControl protected override void OnPointerPressed(PointerPressedEventArgs e) { base.OnPointerPressed(e); - e.Handled = true; - _lastPoint = e.GetPosition(TopLevel.GetTopLevel(this)); + e.Handled = true; + _lastPoint = e.GetPosition(TopLevel.GetTopLevel(this)); + e.Pointer.Capture(this); } protected override void OnPointerReleased(PointerReleasedEventArgs e) @@ -26,9 +27,10 @@ internal class ResizeHandle : TemplatedControl if (_lastPoint.HasValue) { Owner?.NotifyResizeCompleted(); - e.Handled = true; - _lastPoint = null; - _dragging = false; + e.Handled = true; + _lastPoint = null; + _dragging = false; + e.Pointer.Capture(null); } } diff --git a/src/AtomUI.Desktop.Controls/Input/TextArea.cs b/src/AtomUI.Desktop.Controls/Input/TextArea.cs index 8fe586cc7..a63fb5306 100644 --- a/src/AtomUI.Desktop.Controls/Input/TextArea.cs +++ b/src/AtomUI.Desktop.Controls/Input/TextArea.cs @@ -185,6 +185,8 @@ public class TextArea : AvaloniaTextBox, private ResizeHandle? _resizeHandle; private CompositeDisposable? _contentRightAddOnBindings; private double? _originHeight; // 拖动改变高度的初始值 + private double _minResizeHeight; // 拖动改变高度时允许的最小 TextArea.Height + private double _maxResizeHeight; // 拖动改变高度时允许的最大 TextArea.Height static TextArea() { @@ -323,14 +325,8 @@ public class TextArea : AvaloniaTextBox, { if (Lines > 0 && double.IsNaN(Height)) { - var height = double.NaN; Lines = Math.Max(Lines, MinLines); - var fontSize = FontSize; - var typeface = new Typeface(FontFamily, FontStyle, FontWeight, FontStretch); - var paragraphProperties = TextLayoutReflectionExtensions.CreateTextParagraphProperties(typeface, fontSize, null, default, default, null, default, LineHeight, default, FontFeatures); - var textLayout = new TextLayout(new LineTextSource(Lines), paragraphProperties); - var verticalSpace = this.GetVerticalSpaceBetweenScrollViewerAndPresenter(); - height = Math.Ceiling(textLayout.Height + verticalSpace); + var height = CalculateScrollViewerHeight(Lines); _scrollViewer.SetCurrentValue(MinHeightProperty, height); _scrollViewer.SetCurrentValue(MaxHeightProperty, height); } @@ -338,6 +334,16 @@ public class TextArea : AvaloniaTextBox, } return size; } + + private double CalculateScrollViewerHeight(int lines) + { + var fontSize = FontSize; + var typeface = new Typeface(FontFamily, FontStyle, FontWeight, FontStretch); + var paragraphProperties = TextLayoutReflectionExtensions.CreateTextParagraphProperties(typeface, fontSize, null, default, default, null, default, LineHeight, default, FontFeatures); + var textLayout = new TextLayout(new LineTextSource(lines), paragraphProperties); + var verticalSpace = this.GetVerticalSpaceBetweenScrollViewerAndPresenter(); + return Math.Ceiling(textLayout.Height + verticalSpace); + } private void ConfigureEffectiveShowClearButton() { @@ -384,32 +390,33 @@ public class TextArea : AvaloniaTextBox, internal void NotifyAboutToResize() { + _originHeight = Bounds.Height; + SetCurrentValue(HeightProperty, Bounds.Height); if (_scrollViewer != null) { - if (!double.IsNaN(Height)) - { - _scrollViewer.SetCurrentValue(HeightProperty, _scrollViewer.Bounds.Height); - } - var minHeight = _scrollViewer.MinHeight; - var height = _scrollViewer.Height; - if (double.IsNaN(height)) - { - height = minHeight; - } - _originHeight = height; - SetCurrentValue(HeightProperty, double.NaN); + var overhead = Math.Max(0, Bounds.Height - _scrollViewer.Bounds.Height); + var minScrollHeight = MinLines > 0 ? CalculateScrollViewerHeight(MinLines) : 0; + _minResizeHeight = overhead + minScrollHeight; + _maxResizeHeight = MaxLines > 0 + ? overhead + CalculateScrollViewerHeight(MaxLines) + : double.PositiveInfinity; + _scrollViewer.ClearValue(MinHeightProperty); + _scrollViewer.ClearValue(MaxHeightProperty); + } + else + { + _minResizeHeight = 0; + _maxResizeHeight = double.PositiveInfinity; } } internal void NotifyResizing(Point delta) { - if (_scrollViewer != null && _originHeight != null) + if (_originHeight != null) { - var minHeight = _scrollViewer.MinHeight; - var maxHeight = _scrollViewer.MaxHeight; var height = _originHeight.Value + delta.Y; - height = Math.Max(minHeight, Math.Min(height, maxHeight)); - _scrollViewer.SetCurrentValue(HeightProperty, height); + height = Math.Max(_minResizeHeight, Math.Min(height, _maxResizeHeight)); + SetCurrentValue(HeightProperty, height); } } diff --git a/src/AtomUI.Desktop.Controls/Input/Themes/TextAreaTheme.axaml b/src/AtomUI.Desktop.Controls/Input/Themes/TextAreaTheme.axaml index 75f58f759..e96063f0c 100644 --- a/src/AtomUI.Desktop.Controls/Input/Themes/TextAreaTheme.axaml +++ b/src/AtomUI.Desktop.Controls/Input/Themes/TextAreaTheme.axaml @@ -103,6 +103,7 @@ Value="{atom:SharedTokenResource ColorTextPlaceholder}" /> +