优化 lineedit 布局

优化 lineedit 布局
This commit is contained in:
polarboy 2024-08-07 11:08:39 +08:00
parent c8e3e7badc
commit e23b2ffc87
5 changed files with 219 additions and 125 deletions

View File

@ -119,6 +119,8 @@ namespace AtomUI.Theme.Styling
public static readonly TokenResourceKey AddOnPadding = new TokenResourceKey("LineEdit.AddOnPadding");
public static readonly TokenResourceKey AddOnPaddingSM = new TokenResourceKey("LineEdit.AddOnPaddingSM");
public static readonly TokenResourceKey AddOnPaddingLG = new TokenResourceKey("LineEdit.AddOnPaddingLG");
public static readonly TokenResourceKey LeftInnerAddOnMargin = new TokenResourceKey("LineEdit.LeftInnerAddOnMargin");
public static readonly TokenResourceKey RightInnerAddOnMargin = new TokenResourceKey("LineEdit.RightInnerAddOnMargin");
}
public static class LoadingIndicatorResourceKey

View File

@ -7,6 +7,7 @@ using Avalonia.Controls;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Primitives;
using Avalonia.Data;
using Avalonia.Input;
namespace AtomUI.Controls;
@ -80,36 +81,54 @@ public class LineEdit : TextBox
internal static readonly StyledProperty<CornerRadius> EditKernelCornerRadiusProperty =
AvaloniaProperty.Register<LineEdit, CornerRadius>(nameof(EditKernelCornerRadius));
internal static readonly StyledProperty<CornerRadius> LeftAddOnCornerRadiusProperty =
AvaloniaProperty.Register<LineEdit, CornerRadius>(nameof(LeftAddOnCornerRadius));
internal static readonly StyledProperty<CornerRadius> RightAddOnCornerRadiusProperty =
AvaloniaProperty.Register<LineEdit, CornerRadius>(nameof(RightAddOnCornerRadius));
internal static readonly StyledProperty<Thickness> LeftAddOnBorderThicknessProperty =
AvaloniaProperty.Register<LineEdit, Thickness>(nameof(LeftAddOnBorderThickness));
internal static readonly StyledProperty<Thickness> RightAddOnBorderThicknessProperty =
AvaloniaProperty.Register<LineEdit, Thickness>(nameof(RightAddOnBorderThickness));
internal CornerRadius EditKernelCornerRadius
{
get => GetValue(EditKernelCornerRadiusProperty);
set => SetValue(EditKernelCornerRadiusProperty, value);
}
internal static readonly StyledProperty<CornerRadius> LeftAddOnCornerRadiusProperty =
AvaloniaProperty.Register<LineEdit, CornerRadius>(nameof(LeftAddOnCornerRadius));
internal CornerRadius LeftAddOnCornerRadius
{
get => GetValue(LeftAddOnCornerRadiusProperty);
set => SetValue(LeftAddOnCornerRadiusProperty, value);
}
internal static readonly StyledProperty<CornerRadius> RightAddOnCornerRadiusProperty =
AvaloniaProperty.Register<LineEdit, CornerRadius>(nameof(RightAddOnCornerRadius));
internal CornerRadius RightAddOnCornerRadius
{
get => GetValue(RightAddOnCornerRadiusProperty);
set => SetValue(RightAddOnCornerRadiusProperty, value);
}
internal Thickness LeftAddOnBorderThickness
{
get => GetValue(LeftAddOnBorderThicknessProperty);
set => SetValue(LeftAddOnBorderThicknessProperty, value);
}
internal Thickness RightAddOnBorderThickness
{
get => GetValue(RightAddOnBorderThicknessProperty);
set => SetValue(RightAddOnBorderThicknessProperty, value);
}
#endregion
private readonly BorderRenderHelper _borderRenderHelper;
private ContentPresenter? _leftAddOnPresenter;
private ContentPresenter? _rightAddOnPresenter;
private LineEditKernel? _lineEditKernel;
private Border? _lineEditKernelDecorator;
static LineEdit()
@ -130,7 +149,7 @@ public class LineEdit : TextBox
BindingPriority.Template, new RenderScaleAwareThicknessConfigure(this));
_leftAddOnPresenter = e.NameScope.Find<ContentPresenter>(LineEditTheme.LeftAddOnPart);
_rightAddOnPresenter = e.NameScope.Find<ContentPresenter>(LineEditTheme.RightAddOnPart);
_lineEditKernel = e.NameScope.Find<LineEditKernel>(LineEditTheme.LineEditKernelPart);
_lineEditKernelDecorator = e.NameScope.Find<Border>(LineEditTheme.LineEditKernelDecoratorPart);
SetupEditKernelCornerRadius();
}
@ -144,18 +163,23 @@ public class LineEdit : TextBox
}
}
if (change.Property == CornerRadiusProperty) {
SetupAddOnCornerRadius();
if (change.Property == CornerRadiusProperty || change.Property == BorderThicknessProperty) {
SetupAddOnBorderInfo();
}
}
private void SetupAddOnCornerRadius()
private void SetupAddOnBorderInfo()
{
var topLeftRadius = CornerRadius.TopLeft;
var topRightRadius = CornerRadius.TopRight;
var bottomLeftRadius = CornerRadius.BottomLeft;
var bottomRightRadius = CornerRadius.BottomRight;
var topThickness = BorderThickness.Top;
var rightThickness = BorderThickness.Right;
var bottomThickness = BorderThickness.Bottom;
var leftThickness = BorderThickness.Left;
LeftAddOnCornerRadius = new CornerRadius(topLeft: topLeftRadius,
topRight: 0,
bottomLeft:bottomLeftRadius,
@ -164,6 +188,9 @@ public class LineEdit : TextBox
topRight: topRightRadius,
bottomLeft:0,
bottomRight:bottomRightRadius);
LeftAddOnBorderThickness = new Thickness(top: topThickness, right:0, bottom:bottomThickness, left: leftThickness);
RightAddOnBorderThickness = new Thickness(top: topThickness, right:rightThickness, bottom:bottomThickness, left: 0);
}
private void SetupEditKernelCornerRadius()
@ -188,34 +215,25 @@ public class LineEdit : TextBox
bottomRight:bottomRightRadius);
}
protected override Size MeasureOverride(Size availableSize)
{
return base.MeasureOverride(new Size(availableSize.Width - BorderThickness.Left - BorderThickness.Right, availableSize.Height));
}
protected override Size ArrangeOverride(Size finalSize)
{
var offsetLeft = 0d;
var offsetRight = finalSize.Width;
var controlRect = new Rect(new Point(0, 0), finalSize);
if (_leftAddOnPresenter is not null && _leftAddOnPresenter.IsVisible) {
offsetLeft += _leftAddOnPresenter.DesiredSize.Width - BorderThickness.Left;
_leftAddOnPresenter.Arrange(controlRect);
return base.ArrangeOverride(new Size(finalSize.Width - BorderThickness.Left - BorderThickness.Right, finalSize.Height));
}
protected override void OnPointerPressed(PointerPressedEventArgs e)
{
if (_lineEditKernelDecorator is null) {
return;
}
if (_rightAddOnPresenter is not null && _rightAddOnPresenter.IsVisible) {
offsetRight -= _rightAddOnPresenter.DesiredSize.Width - BorderThickness.Right;
_rightAddOnPresenter.Arrange(controlRect);
var targetRect = new Rect(_lineEditKernelDecorator.DesiredSize);
if (!targetRect.Contains(e.GetPosition(_lineEditKernelDecorator))) {
return;
}
if (_lineEditKernel is not null) {
var width = offsetRight - offsetLeft;
if (_leftAddOnPresenter is not null && _leftAddOnPresenter.IsVisible) {
offsetLeft -= BorderThickness.Left;
width += BorderThickness.Left;
}
if (_rightAddOnPresenter is not null && _rightAddOnPresenter.IsVisible) {
width += BorderThickness.Right;
}
_lineEditKernel.Arrange(new Rect(new Point(offsetLeft, 0), new Size(width, finalSize.Height)));
}
return finalSize;
base.OnPointerPressed(e);
}
}

View File

@ -4,10 +4,11 @@ using Avalonia;
using Avalonia.Animation;
using Avalonia.Controls;
using Avalonia.Controls.Presenters;
using Avalonia.Layout;
namespace AtomUI.Controls;
internal class LineEditKernel : Border
internal class LineEditKernel : Panel
{
#region
public static readonly DirectProperty<LineEditKernel, ContentPresenter?> LeftInnerContentProperty =
@ -81,12 +82,8 @@ internal class LineEditKernel : Border
TextPresenterProperty);
}
private Panel _layout;
public LineEditKernel()
{
_layout = new Panel();
Child = _layout;
Focusable = true;
}
@ -96,95 +93,116 @@ internal class LineEditKernel : Border
if (change.Property == LeftInnerContentProperty) {
var oldLeftInnerContent = change.GetOldValue<ContentPresenter?>();
if (oldLeftInnerContent is not null) {
_layout.Children.Remove(oldLeftInnerContent);
Children.Remove(oldLeftInnerContent);
}
if (LeftInnerContent is not null) {
_layout.Children.Add(LeftInnerContent);
Children.Add(LeftInnerContent);
}
} else if (change.Property == RightInnerContentProperty) {
var oldRightInnerContent = change.GetOldValue<ContentPresenter?>();
if (oldRightInnerContent is not null) {
_layout.Children.Remove(oldRightInnerContent);
Children.Remove(oldRightInnerContent);
}
if (RightInnerContent is not null) {
_layout.Children.Add(RightInnerContent);
Children.Add(RightInnerContent);
}
} else if (change.Property == ClearButtonProperty) {
var oldClearButton = change.GetOldValue<IconButton?>();
if (oldClearButton is not null) {
_layout.Children.Remove(oldClearButton);
Children.Remove(oldClearButton);
}
if (ClearButton is not null) {
_layout.Children.Add(ClearButton);
Children.Add(ClearButton);
}
} else if (change.Property == RevealButtonProperty) {
var oldRevealButton = change.GetOldValue<ToggleIconButton?>();
if (oldRevealButton is not null) {
_layout.Children.Remove(oldRevealButton);
Children.Remove(oldRevealButton);
}
if (RevealButton is not null) {
_layout.Children.Add(RevealButton);
Children.Add(RevealButton);
}
} else if (change.Property == TextPresenterProperty) {
var oldTextPresenter = change.GetOldValue<ScrollViewer?>();
if (oldTextPresenter is not null) {
_layout.Children.Remove(oldTextPresenter);
Children.Remove(oldTextPresenter);
}
if (TextPresenter is not null) {
_layout.Children.Add(TextPresenter);
Children.Add(TextPresenter);
}
}
}
protected override Size MeasureOverride(Size availableSize)
{
var size = base.MeasureOverride(availableSize);
return new Size(availableSize.Width, size.Height);
// 不考虑任何 border 和 Padding外层的 Decorator 已经考虑
var height = 0d;
var remainWidth = availableSize.Width;
if (LeftInnerContent is not null && LeftInnerContent.IsVisible) {
LeftInnerContent.Measure(availableSize);
height = Math.Max(height, LeftInnerContent.DesiredSize.Height);
remainWidth -= LeftInnerContent.DesiredSize.Width;
}
if (RightInnerContent is not null && RightInnerContent.IsVisible) {
RightInnerContent.Measure(availableSize);
height = Math.Max(height, RightInnerContent.DesiredSize.Height);
remainWidth -= RightInnerContent.DesiredSize.Width;
}
if (RevealButton is not null && RevealButton.IsVisible) {
RevealButton.Measure(availableSize);
height = Math.Max(height, RevealButton.DesiredSize.Height);
remainWidth -= RevealButton.DesiredSize.Width;
}
if (ClearButton is not null && ClearButton.IsVisible) {
ClearButton.Measure(availableSize);
height = Math.Max(height, ClearButton.DesiredSize.Height);
remainWidth -= ClearButton.DesiredSize.Width;
}
if (TextPresenter is not null && TextPresenter.IsVisible) {
TextPresenter.Measure(new Size(remainWidth, availableSize.Height));
height = Math.Max(height, TextPresenter.DesiredSize.Height);
}
return new Size(availableSize.Width, height);
}
protected override Size ArrangeOverride(Size finalSize)
{
var offsetLeft = Padding.Left;
if (LeftInnerContent is not null) {
var offsetLeft = 0d;
if (LeftInnerContent is not null && LeftInnerContent.IsVisible) {
offsetLeft += LeftInnerContent.DesiredSize.Width;
LeftInnerContent.Arrange(new Rect(new Point(offsetLeft, (finalSize.Height - LeftInnerContent.DesiredSize.Height) / 2), LeftInnerContent.DesiredSize));
}
var offsetRight = finalSize.Width - Padding.Right;
if (RightInnerContent is not null) {
var offsetRight = finalSize.Width;
if (RightInnerContent is not null && RightInnerContent.IsVisible) {
offsetRight -= RightInnerContent.DesiredSize.Width;
RightInnerContent.Arrange(new Rect(new Point(offsetRight, (finalSize.Height - RightInnerContent.DesiredSize.Height) / 2), RightInnerContent.DesiredSize));
}
if (RevealButton is not null) {
if (RevealButton is not null && RevealButton.IsVisible) {
offsetRight -= RevealButton.DesiredSize.Width;
RevealButton.Arrange(new Rect(new Point(offsetRight, (finalSize.Height - RevealButton.DesiredSize.Height) / 2), RevealButton.DesiredSize));
}
if (ClearButton is not null) {
if (ClearButton is not null && ClearButton.IsVisible) {
offsetRight -= ClearButton.DesiredSize.Width;
ClearButton.Arrange(new Rect(new Point(offsetRight, (finalSize.Height - ClearButton.DesiredSize.Height) / 2), ClearButton.DesiredSize));
}
if (TextPresenter is not null) {
if (TextPresenter is not null && TextPresenter.IsVisible) {
TextPresenter.Arrange(new Rect(new Point(offsetLeft, 0), new Size(offsetRight - offsetLeft, finalSize.Height)));
}
return new Size(finalSize.Width - BorderThickness.Left - BorderThickness.Right, finalSize.Height);
}
public override void ApplyTemplate()
{
base.ApplyTemplate();
if (Transitions is null) {
Transitions = new Transitions();
Transitions.Add(AnimationUtils.CreateTransition<SolidColorBrushTransition>(BorderBrushProperty));
Transitions.Add(AnimationUtils.CreateTransition<SolidColorBrushTransition>(BackgroundProperty));
}
return new Size(finalSize.Width, finalSize.Height);
}
}

View File

@ -1,12 +1,14 @@
using AtomUI.Data;
using AtomUI.Media;
using AtomUI.Theme;
using AtomUI.Theme.Data;
using AtomUI.Theme.Styling;
using AtomUI.Theme.Utils;
using AtomUI.Utils;
using Avalonia;
using Avalonia.Animation;
using Avalonia.Controls;
using Avalonia.Controls.Presenters;
using Avalonia.Controls.Shapes;
using Avalonia.Controls.Templates;
using Avalonia.Data;
using Avalonia.Data.Converters;
@ -19,17 +21,18 @@ namespace AtomUI.Controls;
[ControlThemeProvider]
internal class LineEditTheme : BaseControlTheme
{
public const string MainLayoutPart = "PART_FrameDecorator";
public const string TextPresenterPart = "PART_TextPresenter";
public const string WatermarkPart = "PART_Watermark";
public const string ScrollViewerPart = "PART_ScrollViewer";
public const string LeftAddOnPart = "PART_LeftAddOn";
public const string RightAddOnPart = "PART_RightAddOn";
public const string LeftInnerContentPart = "PART_LeftInnerContent";
public const string RightInnerContentPart = "PART_RightInnerContent";
public const string ClearButtonPart = "PART_ClearButton";
public const string RevealButtonPart = "PART_RevealButton";
public const string LineEditKernelPart = "PART_LineEditKernel";
public const string MainLayoutPart = "PART_FrameDecorator";
public const string TextPresenterPart = "PART_TextPresenter";
public const string WatermarkPart = "PART_Watermark";
public const string ScrollViewerPart = "PART_ScrollViewer";
public const string LeftAddOnPart = "PART_LeftAddOn";
public const string RightAddOnPart = "PART_RightAddOn";
public const string LeftInnerContentPart = "PART_LeftInnerContent";
public const string RightInnerContentPart = "PART_RightInnerContent";
public const string ClearButtonPart = "PART_ClearButton";
public const string RevealButtonPart = "PART_RevealButton";
public const string LineEditKernelPart = "PART_LineEditKernel";
public const string LineEditKernelDecoratorPart = "PART_LineEditKernelDecorator";
public LineEditTheme() : base(typeof(LineEdit)) { }
@ -37,23 +40,29 @@ internal class LineEditTheme : BaseControlTheme
{
return new FuncControlTemplate<LineEdit>((lineEdit, scope) =>
{
var mainLayout = new Panel()
var mainLayout = new Grid()
{
Name = MainLayoutPart
Name = MainLayoutPart,
ColumnDefinitions = new ColumnDefinitions()
{
new ColumnDefinition(GridLength.Auto),
new ColumnDefinition(GridLength.Star),
new ColumnDefinition(GridLength.Auto)
}
};
BuildGridChildren(lineEdit, mainLayout, scope);
return mainLayout;
});
}
protected virtual void BuildGridChildren(LineEdit lineEdit, Panel layout, INameScope scope)
protected virtual void BuildGridChildren(LineEdit lineEdit, Grid layout, INameScope scope)
{
BuildLeftAddOn(layout, scope);
BuildLineEditKernel(lineEdit, layout, scope);
BuildRightAddOn(layout, scope);
}
protected virtual void BuildLeftAddOn(Panel layout, INameScope scope)
protected virtual void BuildLeftAddOn(Grid layout, INameScope scope)
{
var leftAddOnContentPresenter = new ContentPresenter()
{
@ -65,7 +74,7 @@ internal class LineEditTheme : BaseControlTheme
};
CreateTemplateParentBinding(leftAddOnContentPresenter, ContentPresenter.ContentProperty, LineEdit.LeftAddOnProperty);
CreateTemplateParentBinding(leftAddOnContentPresenter, ContentPresenter.BorderThicknessProperty, LineEdit.BorderThicknessProperty);
CreateTemplateParentBinding(leftAddOnContentPresenter, ContentPresenter.BorderThicknessProperty, LineEdit.LeftAddOnBorderThicknessProperty);
CreateTemplateParentBinding(leftAddOnContentPresenter, ContentPresenter.CornerRadiusProperty, LineEdit.LeftAddOnCornerRadiusProperty);
CreateTemplateParentBinding(leftAddOnContentPresenter, ContentPresenter.IsVisibleProperty, LineEdit.LeftAddOnProperty,
BindingMode.Default, ObjectConverters.IsNotNull);
@ -78,8 +87,20 @@ internal class LineEditTheme : BaseControlTheme
layout.Children.Add(leftAddOnContentPresenter);
}
protected virtual void BuildLineEditKernel(LineEdit lineEdit, Panel layout, INameScope scope)
protected virtual void BuildLineEditKernel(LineEdit lineEdit, Grid layout, INameScope scope)
{
var kernelDecorator = new Border()
{
Name = LineEditKernelDecoratorPart,
Transitions = new Transitions()
{
AnimationUtils.CreateTransition<SolidColorBrushTransition>(Border.BorderBrushProperty),
AnimationUtils.CreateTransition<SolidColorBrushTransition>(Border.BackgroundProperty)
}
};
kernelDecorator.RegisterInNameScope(scope);
var kernelLayout = new LineEditKernel()
{
Name = LineEditKernelPart,
@ -87,19 +108,21 @@ internal class LineEditTheme : BaseControlTheme
Cursor = new Cursor(StandardCursorType.Ibeam)
};
CreateTemplateParentBinding(kernelLayout, LineEditKernel.BorderThicknessProperty, LineEdit.BorderThicknessProperty);
CreateTemplateParentBinding(kernelLayout, LineEditKernel.CornerRadiusProperty, LineEdit.EditKernelCornerRadiusProperty);
CreateTemplateParentBinding(kernelDecorator, Border.BorderThicknessProperty, LineEdit.BorderThicknessProperty);
CreateTemplateParentBinding(kernelDecorator, Border.CornerRadiusProperty, LineEdit.EditKernelCornerRadiusProperty);
BuildInnerLeftContent(kernelLayout, scope);
BuildTextPresenter(lineEdit, kernelLayout, scope);
BuildClearButton(kernelLayout, scope);
BuildRevealButton(kernelLayout, scope);
BuildInnerRightContent(kernelLayout, scope);
layout.Children.Add(kernelLayout);
kernelLayout.RegisterInNameScope(scope);
kernelDecorator.Child = kernelLayout;
layout.Children.Add(kernelDecorator);
Grid.SetColumn(kernelDecorator, 1);
}
protected virtual void BuildRightAddOn(Panel layout, INameScope scope)
protected virtual void BuildRightAddOn(Grid layout, INameScope scope)
{
var rightAddOnContentPresenter = new ContentPresenter()
{
@ -110,7 +133,7 @@ internal class LineEditTheme : BaseControlTheme
Focusable = false
};
CreateTemplateParentBinding(rightAddOnContentPresenter, ContentPresenter.ContentProperty, LineEdit.RightAddOnProperty);
CreateTemplateParentBinding(rightAddOnContentPresenter, ContentPresenter.BorderThicknessProperty, LineEdit.BorderThicknessProperty);
CreateTemplateParentBinding(rightAddOnContentPresenter, ContentPresenter.BorderThicknessProperty, LineEdit.RightAddOnBorderThicknessProperty);
CreateTemplateParentBinding(rightAddOnContentPresenter, ContentPresenter.CornerRadiusProperty, LineEdit.RightAddOnCornerRadiusProperty);
CreateTemplateParentBinding(rightAddOnContentPresenter, ContentPresenter.IsVisibleProperty, LineEdit.RightAddOnProperty,
BindingMode.Default, ObjectConverters.IsNotNull);
@ -120,6 +143,7 @@ internal class LineEditTheme : BaseControlTheme
rightAddOnContentPresenter.RegisterInNameScope(scope);
layout.Children.Add(rightAddOnContentPresenter);
Grid.SetColumn(rightAddOnContentPresenter, 2);
}
protected virtual void BuildInnerLeftContent(LineEditKernel layout, INameScope scope)
@ -214,7 +238,8 @@ internal class LineEditTheme : BaseControlTheme
{
var clearButton = new IconButton()
{
Name = ClearButtonPart
Name = ClearButtonPart,
IsVisible = false
};
clearButton.RegisterInNameScope(scope);
layout.ClearButton = clearButton;
@ -224,7 +249,8 @@ internal class LineEditTheme : BaseControlTheme
{
var revealButton = new ToggleIconButton()
{
Name = RevealButtonPart
Name = RevealButtonPart,
IsVisible = false
};
revealButton.RegisterInNameScope(scope);
layout.RevealButton = revealButton;
@ -253,11 +279,28 @@ internal class LineEditTheme : BaseControlTheme
var commonStyle = new Style(selector => selector.Nesting());
commonStyle.Add(LineEdit.ForegroundProperty, GlobalResourceKey.ColorText);
// 输入框左右小组件的 margin 设置
var leftInnerContentStyle = new Style(selector => selector.Nesting().Template().Name(LeftInnerContentPart));
leftInnerContentStyle.Add(ContentPresenter.PaddingProperty, LineEditResourceKey.LeftInnerAddOnMargin);
commonStyle.Add(leftInnerContentStyle);
var rightInnerContentStyle = new Style(selector => selector.Nesting().Template().Name(RightInnerContentPart));
rightInnerContentStyle.Add(ContentPresenter.PaddingProperty, LineEditResourceKey.RightInnerAddOnMargin);
commonStyle.Add(rightInnerContentStyle);
var clearButtonStyle = new Style(selector => selector.Nesting().Template().Name(ClearButtonPart));
clearButtonStyle.Add(IconButton.PaddingProperty, LineEditResourceKey.RightInnerAddOnMargin);
commonStyle.Add(clearButtonStyle);
var revealButtonStyle = new Style(selector => selector.Nesting().Template().Name(RevealButtonPart));
revealButtonStyle.Add(ToggleIconButton.PaddingProperty, LineEditResourceKey.RightInnerAddOnMargin);
commonStyle.Add(revealButtonStyle);
var largeStyle = new Style(selector => selector.Nesting().PropertyEquals(LineEdit.SizeTypeProperty, SizeType.Large));
{
var editKernelStyle = new Style(selector => selector.Nesting().Template().Name(LineEditKernelPart));
editKernelStyle.Add(LineEditKernel.PaddingProperty, LineEditResourceKey.PaddingLG);
largeStyle.Add(editKernelStyle);
var editKernelDecoratorStyle = new Style(selector => selector.Nesting().Template().Name(LineEditKernelDecoratorPart));
editKernelDecoratorStyle.Add(Border.PaddingProperty, LineEditResourceKey.PaddingLG);
largeStyle.Add(editKernelDecoratorStyle);
}
{
@ -274,9 +317,9 @@ internal class LineEditTheme : BaseControlTheme
var middleStyle = new Style(selector => selector.Nesting().PropertyEquals(LineEdit.SizeTypeProperty, SizeType.Middle));
{
var editKernelStyle = new Style(selector => selector.Nesting().Template().Name(LineEditKernelPart));
editKernelStyle.Add(LineEditKernel.PaddingProperty, LineEditResourceKey.Padding);
middleStyle.Add(editKernelStyle);
var editKernelDecoratorStyle = new Style(selector => selector.Nesting().Template().Name(LineEditKernelDecoratorPart));
editKernelDecoratorStyle.Add(Border.PaddingProperty, LineEditResourceKey.Padding);
middleStyle.Add(editKernelDecoratorStyle);
}
{
@ -293,9 +336,9 @@ internal class LineEditTheme : BaseControlTheme
var smallStyle = new Style(selector => selector.Nesting().PropertyEquals(LineEdit.SizeTypeProperty, SizeType.Small));
{
var editKernelStyle = new Style(selector => selector.Nesting().Template().Name(LineEditKernelPart));
editKernelStyle.Add(LineEditKernel.PaddingProperty, LineEditResourceKey.PaddingSM);
smallStyle.Add(editKernelStyle);
var editKernelDecoratorStyle = new Style(selector => selector.Nesting().Template().Name(LineEditKernelDecoratorPart));
editKernelDecoratorStyle.Add(Border.PaddingProperty, LineEditResourceKey.PaddingSM);
smallStyle.Add(editKernelDecoratorStyle);
}
{
@ -316,18 +359,18 @@ internal class LineEditTheme : BaseControlTheme
{
var outlineStyle = new Style(selector => selector.Nesting().PropertyEquals(LineEdit.StyleVariantProperty, TextBoxVariant.Outline));
var editKernelStyle = new Style(selector => selector.Nesting().Template().Name(LineEditKernelPart));
editKernelStyle.Add(LineEditKernel.BorderBrushProperty, GlobalResourceKey.ColorBorder);
var editKernelDecoratorStyle = new Style(selector => selector.Nesting().Template().Name(LineEditKernelDecoratorPart));
editKernelDecoratorStyle.Add(Border.BorderBrushProperty, GlobalResourceKey.ColorBorder);
var hoverStyle = new Style(selector => selector.Nesting().Class(StdPseudoClass.PointerOver));
hoverStyle.Add(LineEditKernel.BorderBrushProperty, LineEditResourceKey.HoverBorderColor);
editKernelStyle.Add(hoverStyle);
hoverStyle.Add(Border.BorderBrushProperty, LineEditResourceKey.HoverBorderColor);
editKernelDecoratorStyle.Add(hoverStyle);
var focusStyle = new Style(selector => selector.Nesting().Class(StdPseudoClass.FocusWithIn));
focusStyle.Add(LineEditKernel.BorderBrushProperty, LineEditResourceKey.ActiveBorderColor);
editKernelStyle.Add(focusStyle);
focusStyle.Add(Border.BorderBrushProperty, LineEditResourceKey.ActiveBorderColor);
editKernelDecoratorStyle.Add(focusStyle);
outlineStyle.Add(editKernelStyle);
outlineStyle.Add(editKernelDecoratorStyle);
Add(outlineStyle);
}
@ -336,22 +379,22 @@ internal class LineEditTheme : BaseControlTheme
var filledStyle = new Style(selector => selector.Nesting().PropertyEquals(LineEdit.StyleVariantProperty, TextBoxVariant.Filled));
var editKernelStyle = new Style(selector => selector.Nesting().Template().Name(LineEditKernelPart));
var editKernelDecoratorStyle = new Style(selector => selector.Nesting().Template().Name(LineEditKernelDecoratorPart));
editKernelStyle.Add(LineEditKernel.BorderBrushProperty, GlobalResourceKey.ColorTransparent);
editKernelStyle.Add(LineEditKernel.BackgroundProperty, GlobalResourceKey.ColorFillTertiary);
filledStyle.Add(editKernelStyle);
editKernelDecoratorStyle.Add(Border.BorderBrushProperty, GlobalResourceKey.ColorTransparent);
editKernelDecoratorStyle.Add(Border.BackgroundProperty, GlobalResourceKey.ColorFillTertiary);
filledStyle.Add(editKernelDecoratorStyle);
var hoverStyle = new Style(selector => selector.Nesting().Class(StdPseudoClass.PointerOver));
hoverStyle.Add(LineEditKernel.BackgroundProperty, GlobalResourceKey.ColorFillSecondary);
editKernelStyle.Add(hoverStyle);
hoverStyle.Add(Border.BackgroundProperty, GlobalResourceKey.ColorFillSecondary);
editKernelDecoratorStyle.Add(hoverStyle);
var focusStyle = new Style(selector => selector.Nesting().Class(StdPseudoClass.FocusWithIn));
focusStyle.Add(LineEditKernel.BorderBrushProperty, LineEditResourceKey.ActiveBorderColor);
focusStyle.Add(LineEditKernel.BackgroundProperty, LineEditResourceKey.ActiveBg);
editKernelStyle.Add(focusStyle);
focusStyle.Add(Border.BorderBrushProperty, LineEditResourceKey.ActiveBorderColor);
focusStyle.Add(Border.BackgroundProperty, LineEditResourceKey.ActiveBg);
editKernelDecoratorStyle.Add(focusStyle);
filledStyle.Add(editKernelStyle);
filledStyle.Add(editKernelDecoratorStyle);
Add(filledStyle);
}

View File

@ -99,6 +99,16 @@ internal class LineEditToken : AbstractControlDesignToken
/// </summary>
public Thickness AddOnPaddingLG { get; set; }
/// <summary>
/// 左边内部小组件的边距
/// </summary>
public Thickness LeftInnerAddOnMargin { get; set; }
/// <summary>
/// 右边内部小组件的边距
/// </summary>
public Thickness RightInnerAddOnMargin { get; set; }
internal override void CalculateFromAlias()
{
base.CalculateFromAlias();
@ -140,5 +150,8 @@ internal class LineEditToken : AbstractControlDesignToken
InputFontSize = _globalToken.FontToken.FontSize;
InputFontSizeLG = _globalToken.FontToken.FontSizeLG;
InputFontSizeSM = _globalToken.FontToken.FontSizeSM;
LeftInnerAddOnMargin = new Thickness(0, 0, _globalToken.MarginXXS, 0);
RightInnerAddOnMargin = new Thickness(_globalToken.MarginXXS, 0, 0, 0);
}
}