diff --git a/samples/AtomUI.Demo.Desktop/ShowCase/LineEditShowCase.axaml b/samples/AtomUI.Demo.Desktop/ShowCase/LineEditShowCase.axaml index a7bb32d..6dde7c8 100644 --- a/samples/AtomUI.Demo.Desktop/ShowCase/LineEditShowCase.axaml +++ b/samples/AtomUI.Demo.Desktop/ShowCase/LineEditShowCase.axaml @@ -14,5 +14,25 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/AtomUI.Controls/Input/LineEdit.cs b/src/AtomUI.Controls/Input/LineEdit.cs index 74f3ad4..722bdcd 100644 --- a/src/AtomUI.Controls/Input/LineEdit.cs +++ b/src/AtomUI.Controls/Input/LineEdit.cs @@ -86,7 +86,7 @@ public class LineEdit : TextBox static LineEdit() { - AffectsRender(BorderBrushProperty); + AffectsRender(BorderBrushProperty, BackgroundProperty); AffectsMeasure(LeftAddOnProperty, RightAddOnProperty); } @@ -106,8 +106,15 @@ public class LineEdit : TextBox if (Transitions is null) { Transitions = new Transitions(); Transitions.Add(AnimationUtils.CreateTransition(BorderBrushProperty)); + Transitions.Add(AnimationUtils.CreateTransition(BackgroundProperty)); } } + + protected override Size MeasureOverride(Size availableSize) + { + var size = base.MeasureOverride(availableSize); + return size.Inflate(BorderThickness); + } public override void Render(DrawingContext context) { @@ -116,10 +123,10 @@ public class LineEdit : TextBox using var state = context.PushTransform(Matrix.CreateTranslation(borderRect.X, borderRect.Y)); _borderRenderHelper.Render(context, borderThickness: BorderThickness, - backgroundSizing: BackgroundSizing.OuterBorderEdge, + backgroundSizing: BackgroundSizing.InnerBorderEdge, finalSize: borderRect.Size, cornerRadius: borderRadius, - background: null, + background: Background, borderBrush: BorderBrush, boxShadows: new BoxShadows()); } @@ -151,6 +158,7 @@ public class LineEdit : TextBox { var offsetStart = 0d; var offsetEnd = 0d; + var bounds = Bounds.Deflate(BorderThickness); if (_leftAddOnPresenter is not null && _leftAddOnPresenter.IsVisible) { offsetStart += _leftAddOnPresenter.DesiredSize.Width; } @@ -158,7 +166,9 @@ public class LineEdit : TextBox offsetEnd += _rightAddOnPresenter.DesiredSize.Width; } - return new Rect(new Point(offsetStart, Bounds.Y), - new Size(Bounds.Width - offsetStart + offsetEnd, Bounds.Height)); + return new Rect(new Point(offsetStart + BorderThickness.Left, BorderThickness.Top), + new Size(bounds.Width - offsetStart - offsetEnd, + bounds.Height)); } + } \ No newline at end of file diff --git a/src/AtomUI.Controls/Input/LineEditTheme.cs b/src/AtomUI.Controls/Input/LineEditTheme.cs index a5c7318..60e683d 100644 --- a/src/AtomUI.Controls/Input/LineEditTheme.cs +++ b/src/AtomUI.Controls/Input/LineEditTheme.cs @@ -1,6 +1,8 @@ using AtomUI.Data; using AtomUI.Theme; +using AtomUI.Theme.Data; using AtomUI.Theme.Styling; +using AtomUI.Theme.Utils; using Avalonia.Controls; using Avalonia.Controls.Presenters; using Avalonia.Controls.Templates; @@ -213,6 +215,7 @@ internal class LineEditTheme : BaseControlTheme { BuildFixedStyle(); BuildCommonStyle(); + BuildFilledStyle(); BuildOutLineStyle(); } @@ -272,4 +275,23 @@ internal class LineEditTheme : BaseControlTheme Add(outlineStyle); } + private void BuildFilledStyle() + { + var filledStyle = new Style(selector => selector.Nesting().PropertyEquals(LineEdit.StyleVariantProperty, TextBoxVariant.Filled)); + + filledStyle.Add(LineEdit.BorderBrushProperty, GlobalResourceKey.ColorTransparent); + filledStyle.Add(LineEdit.BackgroundProperty, GlobalResourceKey.ColorFillTertiary); + + var hoverStyle = new Style(selector => selector.Nesting().Class(StdPseudoClass.PointerOver)); + hoverStyle.Add(LineEdit.BackgroundProperty, GlobalResourceKey.ColorFillSecondary); + filledStyle.Add(hoverStyle); + + var focusStyle = new Style(selector => selector.Nesting().Class(StdPseudoClass.FocusWithIn)); + focusStyle.Add(LineEdit.BorderBrushProperty, LineEditResourceKey.ActiveBorderColor); + focusStyle.Add(LineEdit.BackgroundProperty, LineEditResourceKey.ActiveBg); + filledStyle.Add(focusStyle); + + Add(filledStyle); + } + } \ No newline at end of file diff --git a/src/AtomUI.Controls/Input/LineEditToken.cs b/src/AtomUI.Controls/Input/LineEditToken.cs index d0b75c9..a49eaf1 100644 --- a/src/AtomUI.Controls/Input/LineEditToken.cs +++ b/src/AtomUI.Controls/Input/LineEditToken.cs @@ -88,6 +88,7 @@ internal class LineEditToken : AbstractControlDesignToken { base.CalculateFromAlias(); var fontSize = _globalToken.FontToken.FontSize; + var fontSizeLG = _globalToken.FontToken.FontSizeLG; var lineHeight = _globalToken.FontToken.LineHeight; var lineHeightLG = _globalToken.FontToken.LineHeightLG; var lineWidth = _globalToken.SeedToken.LineWidth; @@ -96,7 +97,7 @@ internal class LineEditToken : AbstractControlDesignToken PaddingSM = new Thickness(_globalToken.ControlPaddingSM - lineWidth, Math.Round(((_globalToken.HeightToken.ControlHeightSM - fontSize * lineHeight) / 2) * 10) / 10 - lineWidth); PaddingLG = new Thickness(_globalToken.ControlPadding - lineWidth, - Math.Ceiling(((_globalToken.HeightToken.ControlHeightLG - fontSize * lineHeightLG) / 2) * 10) / 10 - lineWidth); + Math.Ceiling(((_globalToken.HeightToken.ControlHeightLG - fontSizeLG * lineHeightLG) / 2) * 10) / 10 - lineWidth); AddonBg = _globalToken.ColorFillAlter; ActiveBorderColor = _globalToken.ColorToken.ColorPrimaryToken.ColorPrimary;