diff --git a/samples/AtomUI.Demo.Desktop/ShowCase/LineEditShowCase.axaml b/samples/AtomUI.Demo.Desktop/ShowCase/LineEditShowCase.axaml index 4f53664..9d35873 100644 --- a/samples/AtomUI.Demo.Desktop/ShowCase/LineEditShowCase.axaml +++ b/samples/AtomUI.Demo.Desktop/ShowCase/LineEditShowCase.axaml @@ -18,9 +18,9 @@ Title="Three sizes of Input" Description="There are three sizes of an Input box: large (40px), default (32px) and small (24px)."> - - - + + + @@ -40,7 +40,7 @@ - @@ -80,8 +80,8 @@ Description="Add a prefix or suffix icons inside input."> + InnerLeftContent="{atom:IconProvider Kind=UserOutlined, NormalFilledColor=#D7D7D7}" + InnerRightContent="{atom:IconProvider Kind=InfoCircleOutlined, NormalFilledColor=#8C8C8C}"/> @@ -93,14 +93,14 @@ - - + + - - + + - - + + diff --git a/src/AtomUI.Controls/Input/LineEdit.cs b/src/AtomUI.Controls/Input/LineEdit.cs index 775ff28..742ef94 100644 --- a/src/AtomUI.Controls/Input/LineEdit.cs +++ b/src/AtomUI.Controls/Input/LineEdit.cs @@ -172,7 +172,6 @@ public class LineEdit : TextBox #endregion - private readonly BorderRenderHelper _borderRenderHelper; private ContentPresenter? _leftAddOnPresenter; private ContentPresenter? _rightAddOnPresenter; private Border? _lineEditKernelDecorator; @@ -183,12 +182,7 @@ public class LineEdit : TextBox AffectsRender(BorderBrushProperty, BackgroundProperty); AffectsMeasure(LeftAddOnProperty, RightAddOnProperty); } - - public LineEdit() - { - _borderRenderHelper = new BorderRenderHelper(); - } - + protected override void OnApplyTemplate(TemplateAppliedEventArgs e) { base.OnApplyTemplate(e); @@ -225,6 +219,17 @@ public class LineEdit : TextBox if (change.Property == StatusProperty) { UpdatePseudoClasses(); } + + if (change.Property == InnerLeftContentProperty || + change.Property == InnerRightContentProperty) { + if (change.OldValue is Control oldControl) { + UIStructureUtils.SetTemplateParent(oldControl, null); + } + + if (change.NewValue is Control newControl) { + UIStructureUtils.SetTemplateParent(newControl, this); + } + } } private void SetupAddOnBorderInfo() diff --git a/src/AtomUI.Controls/Input/LineEditTheme.cs b/src/AtomUI.Controls/Input/LineEditTheme.cs index 7b00d9d..59752e3 100644 --- a/src/AtomUI.Controls/Input/LineEditTheme.cs +++ b/src/AtomUI.Controls/Input/LineEditTheme.cs @@ -372,6 +372,15 @@ internal class LineEditTheme : BaseControlTheme var revealButtonStyle = new Style(selector => selector.Nesting().Template().Name(RevealButtonPart)); revealButtonStyle.Add(ToggleIconButton.PaddingProperty, LineEditResourceKey.RightInnerAddOnMargin); commonStyle.Add(revealButtonStyle); + + { + // 左右 inner icon 的大小 + var innerContentIconStyle = new Style(selector => Selectors.Or(selector.Nesting().Template().Name(LeftInnerContentPart).Descendant().OfType(), + selector.Nesting().Template().Name(RightInnerContentPart).Descendant().OfType())); + innerContentIconStyle.Add(PathIcon.WidthProperty, GlobalResourceKey.IconSize); + innerContentIconStyle.Add(PathIcon.HeightProperty, GlobalResourceKey.IconSize); + commonStyle.Add(innerContentIconStyle); + } var largeStyle = new Style(selector => selector.Nesting().PropertyEquals(LineEdit.SizeTypeProperty, SizeType.Large)); @@ -460,6 +469,12 @@ internal class LineEditTheme : BaseControlTheme } { var errorStyle = new Style(selector => selector.Nesting().Class(LineEdit.ErrorPC)); + { + var innerContentIconStyle = new Style(selector => Selectors.Or(selector.Nesting().Template().Name(LeftInnerContentPart).Descendant().OfType(), + selector.Nesting().Template().Name(RightInnerContentPart).Descendant().OfType())); + innerContentIconStyle.Add(PathIcon.NormalFilledBrushProperty, GlobalResourceKey.ColorError); + errorStyle.Add(innerContentIconStyle); + } var editKernelDecoratorStyle = new Style(selector => selector.Nesting().Template().Name(LineEditKernelDecoratorPart)); @@ -480,6 +495,13 @@ internal class LineEditTheme : BaseControlTheme { var warningStyle = new Style(selector => selector.Nesting().Class(LineEdit.WarningPC)); + { + var innerContentIconStyle = new Style(selector => Selectors.Or(selector.Nesting().Template().Name(LeftInnerContentPart).Descendant().OfType(), + selector.Nesting().Template().Name(RightInnerContentPart).Descendant().OfType())); + innerContentIconStyle.Add(PathIcon.NormalFilledBrushProperty, GlobalResourceKey.ColorWarning); + warningStyle.Add(innerContentIconStyle); + } + var editKernelDecoratorStyle = new Style(selector => selector.Nesting().Template().Name(LineEditKernelDecoratorPart)); editKernelDecoratorStyle.Add(Border.BorderBrushProperty, GlobalResourceKey.ColorWarning); @@ -504,9 +526,15 @@ internal class LineEditTheme : BaseControlTheme var borderlessStyle = new Style(selector => selector.Nesting() .PropertyEquals(LineEdit.StyleVariantProperty, TextBoxVariant.Borderless)); - + { var errorStyle = new Style(selector => selector.Nesting().Class(LineEdit.ErrorPC)); + { + var innerContentIconStyle = new Style(selector => Selectors.Or(selector.Nesting().Template().Name(LeftInnerContentPart).Descendant().OfType(), + selector.Nesting().Template().Name(RightInnerContentPart).Descendant().OfType())); + innerContentIconStyle.Add(PathIcon.NormalFilledBrushProperty, GlobalResourceKey.ColorError); + errorStyle.Add(innerContentIconStyle); + } var scrollViewerStyle = new Style(selector => selector.Nesting().Template().Name(LineEditKernelDecoratorPart) .Descendant().OfType()); scrollViewerStyle.Add(ScrollViewer.ForegroundProperty, GlobalResourceKey.ColorErrorText); @@ -516,6 +544,12 @@ internal class LineEditTheme : BaseControlTheme { var warningStyle = new Style(selector => selector.Nesting().Class(LineEdit.WarningPC)); + { + var innerContentIconStyle = new Style(selector => Selectors.Or(selector.Nesting().Template().Name(LeftInnerContentPart).Descendant().OfType(), + selector.Nesting().Template().Name(RightInnerContentPart).Descendant().OfType())); + innerContentIconStyle.Add(PathIcon.NormalFilledBrushProperty, GlobalResourceKey.ColorWarning); + warningStyle.Add(innerContentIconStyle); + } var scrollViewerStyle = new Style(selector => selector.Nesting().Template().Name(LineEditKernelDecoratorPart) .Descendant().OfType()); scrollViewerStyle.Add(ScrollViewer.ForegroundProperty, GlobalResourceKey.ColorWarningText); @@ -553,6 +587,13 @@ internal class LineEditTheme : BaseControlTheme { var errorStyle = new Style(selector => selector.Nesting().Class(LineEdit.ErrorPC)); + { + var innerContentIconStyle = new Style(selector => Selectors.Or(selector.Nesting().Template().Name(LeftInnerContentPart).Descendant().OfType(), + selector.Nesting().Template().Name(RightInnerContentPart).Descendant().OfType())); + innerContentIconStyle.Add(PathIcon.NormalFilledBrushProperty, GlobalResourceKey.ColorError); + errorStyle.Add(innerContentIconStyle); + } + var editKernelDecoratorStyle = new Style(selector => selector.Nesting().Template().Name(LineEditKernelDecoratorPart)); @@ -582,6 +623,13 @@ internal class LineEditTheme : BaseControlTheme { var warningStyle = new Style(selector => selector.Nesting().Class(LineEdit.WarningPC)); + + { + var innerContentIconStyle = new Style(selector => Selectors.Or(selector.Nesting().Template().Name(LeftInnerContentPart).Descendant().OfType(), + selector.Nesting().Template().Name(RightInnerContentPart).Descendant().OfType())); + innerContentIconStyle.Add(PathIcon.NormalFilledBrushProperty, GlobalResourceKey.ColorWarning); + warningStyle.Add(innerContentIconStyle); + } var editKernelDecoratorStyle = new Style(selector => selector.Nesting().Template().Name(LineEditKernelDecoratorPart)); @@ -597,6 +645,14 @@ internal class LineEditTheme : BaseControlTheme var focusStyle = new Style(selector => selector.Nesting().Class(StdPseudoClass.FocusWithIn)); focusStyle.Add(Border.BorderBrushProperty, GlobalResourceKey.ColorWarning); focusStyle.Add(Border.BackgroundProperty, LineEditResourceKey.ActiveBg); + + { + var innerContentIconStyle = new Style(selector => Selectors.Or(selector.Nesting().Template().Name(LeftInnerContentPart).Descendant().OfType(), + selector.Nesting().Template().Name(RightInnerContentPart).Descendant().OfType())); + innerContentIconStyle.Add(PathIcon.NormalFilledBrushProperty, GlobalResourceKey.ColorWarning); + focusStyle.Add(innerContentIconStyle); + } + editKernelDecoratorStyle.Add(focusStyle); var scrollViewerStyle = new Style(selector => selector.Nesting().Template().Name(LineEditKernelDecoratorPart)