完成三种模式

完成三种模式
This commit is contained in:
polarboy 2024-08-06 15:28:17 +08:00
parent 1241e98f5c
commit b2c0cbfb91
4 changed files with 59 additions and 6 deletions

View File

@ -14,5 +14,25 @@
<atom:LineEdit Watermark="Basic usage"/>
</showcase:ShowCaseItem>
<showcase:ShowCaseItem
Title="Three sizes of Input"
Description="There are three sizes of an Input box: large (40px), default (32px) and small (24px).">
<StackPanel Orientation="Vertical" Spacing="10">
<atom:LineEdit Watermark="Large" SizeType="Large"/>
<atom:LineEdit Watermark="Middle" SizeType="Middle"/>
<atom:LineEdit Watermark="Small" SizeType="Small"/>
</StackPanel>
</showcase:ShowCaseItem>
<showcase:ShowCaseItem
Title="Variants"
Description="Variants of Input.">
<StackPanel Orientation="Vertical" Spacing="10">
<atom:LineEdit Watermark="Outlined" StyleVariant="Outline"/>
<atom:LineEdit Watermark="Filled" StyleVariant="Filled"/>
<atom:LineEdit Watermark="Borderless" StyleVariant="Borderless"/>
</StackPanel>
</showcase:ShowCaseItem>
</showcase:ShowCasePanel>
</UserControl>

View File

@ -86,7 +86,7 @@ public class LineEdit : TextBox
static LineEdit()
{
AffectsRender<LineEdit>(BorderBrushProperty);
AffectsRender<LineEdit>(BorderBrushProperty, BackgroundProperty);
AffectsMeasure<LineEdit>(LeftAddOnProperty, RightAddOnProperty);
}
@ -106,8 +106,15 @@ public class LineEdit : TextBox
if (Transitions is null) {
Transitions = new Transitions();
Transitions.Add(AnimationUtils.CreateTransition<SolidColorBrushTransition>(BorderBrushProperty));
Transitions.Add(AnimationUtils.CreateTransition<SolidColorBrushTransition>(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));
}
}

View File

@ -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);
}
}

View File

@ -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;