mirror of
https://github.com/AtomUI/AtomUI.git
synced 2026-10-29 15:19:12 +08:00
Refactor LineEdit
Add password RevealButton support
This commit is contained in:
@@ -6,6 +6,7 @@ using AtomUI.Theme.Utils;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Data;
|
||||
using Avalonia.Input;
|
||||
using Avalonia.Layout;
|
||||
|
||||
@@ -90,13 +91,13 @@ public class ToggleIconButton : ToggleButton,
|
||||
ApplyIconToContent();
|
||||
}
|
||||
|
||||
protected virtual void ConfigureIcon(Icon Icon)
|
||||
protected virtual void ConfigureIcon(Icon icon)
|
||||
{
|
||||
Icon.SetCurrentValue(HorizontalAlignmentProperty, HorizontalAlignment.Center);
|
||||
Icon.SetCurrentValue(VerticalAlignmentProperty, VerticalAlignment.Center);
|
||||
UIStructureUtils.SetTemplateParent(Icon, this);
|
||||
BindUtils.RelayBind(this, IconWidthProperty, Icon, WidthProperty);
|
||||
BindUtils.RelayBind(this, IconHeightProperty, Icon, HeightProperty);
|
||||
icon.SetValue(HorizontalAlignmentProperty, HorizontalAlignment.Center, BindingPriority.Template);
|
||||
icon.SetValue(VerticalAlignmentProperty, VerticalAlignment.Center, BindingPriority.Template);
|
||||
UIStructureUtils.SetTemplateParent(icon, this);
|
||||
BindUtils.RelayBind(this, IconWidthProperty, icon, WidthProperty);
|
||||
BindUtils.RelayBind(this, IconHeightProperty, icon, HeightProperty);
|
||||
}
|
||||
|
||||
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
|
||||
|
||||
@@ -57,6 +57,11 @@ public class LineEdit : TextBox,
|
||||
string IControlSharedTokenResourcesHost.TokenId => LineEditToken.ID;
|
||||
|
||||
#endregion
|
||||
|
||||
static LineEdit()
|
||||
{
|
||||
PasswordCharProperty.OverrideDefaultValue<LineEdit>('•');
|
||||
}
|
||||
|
||||
public LineEdit()
|
||||
{
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
using AtomUI.Theme.Styling;
|
||||
using AtomUI.IconPkg;
|
||||
using AtomUI.IconPkg.AntDesign;
|
||||
using AtomUI.Theme.Data;
|
||||
using AtomUI.Theme.Styling;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Templates;
|
||||
using Avalonia.Data;
|
||||
using Avalonia.Styling;
|
||||
|
||||
namespace AtomUI.Controls;
|
||||
@@ -7,10 +13,52 @@ namespace AtomUI.Controls;
|
||||
[ControlThemeProvider]
|
||||
internal class TextBoxInnerBoxTheme : AddOnDecoratedInnerBoxTheme
|
||||
{
|
||||
public const string RevealButtonPart = "PART_RevealButton";
|
||||
|
||||
public TextBoxInnerBoxTheme() : base(typeof(TextBoxInnerBox))
|
||||
{
|
||||
}
|
||||
|
||||
protected override void BuildRightAddOnItems(StackPanel layout, INameScope scope)
|
||||
{
|
||||
base.BuildRightAddOnItems(layout, scope);
|
||||
BuildRevealButtonButton(layout, scope);
|
||||
}
|
||||
|
||||
protected virtual void BuildRevealButtonButton(StackPanel addOnLayout, INameScope scope)
|
||||
{
|
||||
var eyeOutlinedIcon = AntDesignIconPackage.EyeOutlined();
|
||||
var eyeInvisibleOutlinedIcon = AntDesignIconPackage.EyeInvisibleOutlined();
|
||||
|
||||
TokenResourceBinder.CreateTokenBinding(eyeOutlinedIcon, Icon.NormalFilledBrushProperty,
|
||||
SharedTokenKey.ColorTextTertiary);
|
||||
TokenResourceBinder.CreateTokenBinding(eyeOutlinedIcon, Icon.ActiveFilledBrushProperty,
|
||||
SharedTokenKey.ColorText);
|
||||
|
||||
TokenResourceBinder.CreateTokenBinding(eyeInvisibleOutlinedIcon, Icon.NormalFilledBrushProperty,
|
||||
SharedTokenKey.ColorTextTertiary);
|
||||
TokenResourceBinder.CreateTokenBinding(eyeInvisibleOutlinedIcon, Icon.ActiveFilledBrushProperty,
|
||||
SharedTokenKey.ColorText);
|
||||
|
||||
var revealButtonIconButton = new ToggleIconButton
|
||||
{
|
||||
Name = RevealButtonPart,
|
||||
CheckedIcon = eyeOutlinedIcon,
|
||||
UnCheckedIcon = eyeInvisibleOutlinedIcon
|
||||
};
|
||||
|
||||
CreateTemplateParentBinding(revealButtonIconButton, ToggleIconButton.IsCheckedProperty, TextBoxInnerBox.IsRevealButtonCheckedProperty, BindingMode.TwoWay);
|
||||
TokenResourceBinder.CreateTokenBinding(revealButtonIconButton, ToggleIconButton.IconHeightProperty,
|
||||
SharedTokenKey.IconSize);
|
||||
TokenResourceBinder.CreateTokenBinding(revealButtonIconButton, ToggleIconButton.IconWidthProperty,
|
||||
SharedTokenKey.IconSize);
|
||||
|
||||
revealButtonIconButton.RegisterInNameScope(scope);
|
||||
CreateTemplateParentBinding(revealButtonIconButton, Visual.IsVisibleProperty,
|
||||
TextBoxInnerBox.IsRevealButtonVisibleProperty);
|
||||
addOnLayout.Children.Add(revealButtonIconButton);
|
||||
}
|
||||
|
||||
protected override void BuildDisabledStyle()
|
||||
{
|
||||
var embedModeStyle = new Style(selector =>
|
||||
|
||||
Reference in New Issue
Block a user