From 1af661666abfff628857a554f84b29ef524c7694 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Sat, 1 Aug 2020 08:47:52 +0800 Subject: [PATCH 01/23] add InnerLeftContent and InnerRightContent --- src/Avalonia.Controls/TextBox.cs | 18 ++++++ src/Avalonia.Themes.Fluent/TextBox.xaml | 80 +++++++------------------ 2 files changed, 39 insertions(+), 59 deletions(-) diff --git a/src/Avalonia.Controls/TextBox.cs b/src/Avalonia.Controls/TextBox.cs index 87a674fabd..0a785c3b36 100644 --- a/src/Avalonia.Controls/TextBox.cs +++ b/src/Avalonia.Controls/TextBox.cs @@ -95,6 +95,12 @@ namespace Avalonia.Controls AvaloniaProperty.RegisterDirect(nameof(NewLine), textbox => textbox.NewLine, (textbox, newline) => textbox.NewLine = newline); + public static readonly StyledProperty InnerLeftContentProperty = + AvaloniaProperty.Register(nameof(InnerLeftContent)); + + public static readonly StyledProperty InnerRightContentProperty = + AvaloniaProperty.Register(nameof(InnerRightContent)); + struct UndoRedoState : IEquatable { public string Text { get; } @@ -326,6 +332,18 @@ namespace Avalonia.Controls set { SetValue(UseFloatingWatermarkProperty, value); } } + public object InnerLeftContent + { + get { return GetValue(InnerLeftContentProperty); } + set { SetValue(InnerLeftContentProperty, value); } + } + + public object InnerRightContent + { + get { return GetValue(InnerRightContentProperty); } + set { SetValue(InnerRightContentProperty, value); } + } + public TextWrapping TextWrapping { get { return GetValue(TextWrappingProperty); } diff --git a/src/Avalonia.Themes.Fluent/TextBox.xaml b/src/Avalonia.Themes.Fluent/TextBox.xaml index a72c7586e9..847248bafa 100644 --- a/src/Avalonia.Themes.Fluent/TextBox.xaml +++ b/src/Avalonia.Themes.Fluent/TextBox.xaml @@ -1,4 +1,5 @@ - + 0,0,0,4 @@ -8,7 +9,7 @@ - + @@ -18,73 +19,34 @@ - + - + - + - + - - - - + + + + - - - - - - - + + + + + + + + + + From 35a46626172935ece3ce7aafdc54f62f6d51b996 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Sat, 1 Aug 2020 08:55:47 +0800 Subject: [PATCH 02/23] test --- samples/ControlCatalog/Pages/TextBoxPage.xaml | 79 ++++++++++--------- src/Avalonia.Controls/TextBox.cs | 13 +-- src/Avalonia.Themes.Fluent/TextBox.xaml | 6 +- 3 files changed, 51 insertions(+), 47 deletions(-) diff --git a/samples/ControlCatalog/Pages/TextBoxPage.xaml b/samples/ControlCatalog/Pages/TextBoxPage.xaml index 64118a00b4..cc0e86b904 100644 --- a/samples/ControlCatalog/Pages/TextBoxPage.xaml +++ b/samples/ControlCatalog/Pages/TextBoxPage.xaml @@ -1,58 +1,61 @@ + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="ControlCatalog.Pages.TextBoxPage"> TextBox A control into which the user can input text - + - - - + + + - + - - + + + + + resm fonts + + + + + + + + res fonts + + + + - - resm fonts - - - - - - - - res fonts - - - - - + + + + + + + + Test + + + diff --git a/src/Avalonia.Controls/TextBox.cs b/src/Avalonia.Controls/TextBox.cs index 0a785c3b36..2508915fa4 100644 --- a/src/Avalonia.Controls/TextBox.cs +++ b/src/Avalonia.Controls/TextBox.cs @@ -13,6 +13,7 @@ using Avalonia.Metadata; using Avalonia.Data; using Avalonia.Layout; using Avalonia.Utilities; +using Avalonia.Controls.Templates; namespace Avalonia.Controls { @@ -95,11 +96,11 @@ namespace Avalonia.Controls AvaloniaProperty.RegisterDirect(nameof(NewLine), textbox => textbox.NewLine, (textbox, newline) => textbox.NewLine = newline); - public static readonly StyledProperty InnerLeftContentProperty = - AvaloniaProperty.Register(nameof(InnerLeftContent)); + public static readonly StyledProperty InnerLeftContentProperty = + AvaloniaProperty.Register(nameof(InnerLeftContent)); - public static readonly StyledProperty InnerRightContentProperty = - AvaloniaProperty.Register(nameof(InnerRightContent)); + public static readonly StyledProperty InnerRightContentProperty = + AvaloniaProperty.Register(nameof(InnerRightContent)); struct UndoRedoState : IEquatable { @@ -332,13 +333,13 @@ namespace Avalonia.Controls set { SetValue(UseFloatingWatermarkProperty, value); } } - public object InnerLeftContent + public IControlTemplate InnerLeftContent { get { return GetValue(InnerLeftContentProperty); } set { SetValue(InnerLeftContentProperty, value); } } - public object InnerRightContent + public IControlTemplate InnerRightContent { get { return GetValue(InnerRightContentProperty); } set { SetValue(InnerRightContentProperty, value); } diff --git a/src/Avalonia.Themes.Fluent/TextBox.xaml b/src/Avalonia.Themes.Fluent/TextBox.xaml index 847248bafa..99d8d613eb 100644 --- a/src/Avalonia.Themes.Fluent/TextBox.xaml +++ b/src/Avalonia.Themes.Fluent/TextBox.xaml @@ -38,14 +38,14 @@ - - + + - + From 88a63dde2c4d68cef09cbd8c0b131445e57133f6 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Sat, 1 Aug 2020 09:03:30 +0800 Subject: [PATCH 03/23] use contentpresenter --- samples/ControlCatalog/Pages/TextBoxPage.xaml | 4 +- src/Avalonia.Controls/TextBox.cs | 13 ++-- src/Avalonia.Themes.Fluent/TextBox.xaml | 73 +++++++++++++++---- 3 files changed, 65 insertions(+), 25 deletions(-) diff --git a/samples/ControlCatalog/Pages/TextBoxPage.xaml b/samples/ControlCatalog/Pages/TextBoxPage.xaml index cc0e86b904..83378963e8 100644 --- a/samples/ControlCatalog/Pages/TextBoxPage.xaml +++ b/samples/ControlCatalog/Pages/TextBoxPage.xaml @@ -44,9 +44,9 @@ diff --git a/src/Avalonia.Controls/TextBox.cs b/src/Avalonia.Controls/TextBox.cs index 2508915fa4..0a785c3b36 100644 --- a/src/Avalonia.Controls/TextBox.cs +++ b/src/Avalonia.Controls/TextBox.cs @@ -13,7 +13,6 @@ using Avalonia.Metadata; using Avalonia.Data; using Avalonia.Layout; using Avalonia.Utilities; -using Avalonia.Controls.Templates; namespace Avalonia.Controls { @@ -96,11 +95,11 @@ namespace Avalonia.Controls AvaloniaProperty.RegisterDirect(nameof(NewLine), textbox => textbox.NewLine, (textbox, newline) => textbox.NewLine = newline); - public static readonly StyledProperty InnerLeftContentProperty = - AvaloniaProperty.Register(nameof(InnerLeftContent)); + public static readonly StyledProperty InnerLeftContentProperty = + AvaloniaProperty.Register(nameof(InnerLeftContent)); - public static readonly StyledProperty InnerRightContentProperty = - AvaloniaProperty.Register(nameof(InnerRightContent)); + public static readonly StyledProperty InnerRightContentProperty = + AvaloniaProperty.Register(nameof(InnerRightContent)); struct UndoRedoState : IEquatable { @@ -333,13 +332,13 @@ namespace Avalonia.Controls set { SetValue(UseFloatingWatermarkProperty, value); } } - public IControlTemplate InnerLeftContent + public object InnerLeftContent { get { return GetValue(InnerLeftContentProperty); } set { SetValue(InnerLeftContentProperty, value); } } - public IControlTemplate InnerRightContent + public object InnerRightContent { get { return GetValue(InnerRightContentProperty); } set { SetValue(InnerRightContentProperty, value); } diff --git a/src/Avalonia.Themes.Fluent/TextBox.xaml b/src/Avalonia.Themes.Fluent/TextBox.xaml index 99d8d613eb..ec232b33ae 100644 --- a/src/Avalonia.Themes.Fluent/TextBox.xaml +++ b/src/Avalonia.Themes.Fluent/TextBox.xaml @@ -1,5 +1,4 @@ - + 0,0,0,4 @@ -9,7 +8,7 @@ - + @@ -19,33 +18,75 @@ - + - + - + - + - - - - + + + + - + - + - + - + - + From 13ad0bf9a2d73c6bdd97e78b1aea72ea530064f0 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Sat, 1 Aug 2020 09:04:50 +0800 Subject: [PATCH 04/23] move it up --- samples/ControlCatalog/Pages/TextBoxPage.xaml | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/samples/ControlCatalog/Pages/TextBoxPage.xaml b/samples/ControlCatalog/Pages/TextBoxPage.xaml index 83378963e8..795e675f70 100644 --- a/samples/ControlCatalog/Pages/TextBoxPage.xaml +++ b/samples/ControlCatalog/Pages/TextBoxPage.xaml @@ -1,6 +1,23 @@ + + + + + + + Test + + + TextBox A control into which the user can input text @@ -40,21 +57,6 @@ - - - - - - Test - - From 06d93f32161011d6b57466b66d7e8bbc9996dff7 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Sat, 1 Aug 2020 09:06:45 +0800 Subject: [PATCH 05/23] test --- samples/ControlCatalog/Pages/TextBoxPage.xaml | 4 ++-- src/Avalonia.Themes.Fluent/TextBox.xaml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/ControlCatalog/Pages/TextBoxPage.xaml b/samples/ControlCatalog/Pages/TextBoxPage.xaml index 795e675f70..093e3087e5 100644 --- a/samples/ControlCatalog/Pages/TextBoxPage.xaml +++ b/samples/ControlCatalog/Pages/TextBoxPage.xaml @@ -6,9 +6,9 @@ diff --git a/src/Avalonia.Themes.Fluent/TextBox.xaml b/src/Avalonia.Themes.Fluent/TextBox.xaml index ec232b33ae..4e96751bc6 100644 --- a/src/Avalonia.Themes.Fluent/TextBox.xaml +++ b/src/Avalonia.Themes.Fluent/TextBox.xaml @@ -86,7 +86,7 @@ HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> - + From ad78086d0a091b184cde7abc279b532791f26a5f Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Sat, 1 Aug 2020 09:22:00 +0800 Subject: [PATCH 06/23] fix padding --- src/Avalonia.Themes.Fluent/TextBox.xaml | 85 +++++++++++++------------ 1 file changed, 43 insertions(+), 42 deletions(-) diff --git a/src/Avalonia.Themes.Fluent/TextBox.xaml b/src/Avalonia.Themes.Fluent/TextBox.xaml index 4e96751bc6..5278e5d3d0 100644 --- a/src/Avalonia.Themes.Fluent/TextBox.xaml +++ b/src/Avalonia.Themes.Fluent/TextBox.xaml @@ -37,31 +37,30 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + Margin="0 1 0 0" + Text="{TemplateBinding Text, Mode=TwoWay}" + CaretIndex="{TemplateBinding CaretIndex}" + SelectionStart="{TemplateBinding SelectionStart}" + SelectionEnd="{TemplateBinding SelectionEnd}" + TextAlignment="{TemplateBinding TextAlignment}" + TextWrapping="{TemplateBinding TextWrapping}" + PasswordChar="{TemplateBinding PasswordChar}" + SelectionBrush="{TemplateBinding SelectionBrush}" + SelectionForegroundBrush="{TemplateBinding SelectionForegroundBrush}" + CaretBrush="{TemplateBinding CaretBrush}" + HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" + VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> - - - - - + + + + + + + From 9ca05ec23dc6cf15e2518e807f242c8cd5a8e3af Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Sat, 1 Aug 2020 09:25:41 +0800 Subject: [PATCH 07/23] update textboxpage --- samples/ControlCatalog/Pages/TextBoxPage.xaml | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/samples/ControlCatalog/Pages/TextBoxPage.xaml b/samples/ControlCatalog/Pages/TextBoxPage.xaml index 093e3087e5..348a285f44 100644 --- a/samples/ControlCatalog/Pages/TextBoxPage.xaml +++ b/samples/ControlCatalog/Pages/TextBoxPage.xaml @@ -2,21 +2,24 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="ControlCatalog.Pages.TextBoxPage"> - - - - - - Test - - + + + + TextBox A control into which the user can input text @@ -39,6 +42,8 @@ + + resm fonts From 32a34117e75f735245797390a2308987b9aceab3 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Sat, 1 Aug 2020 10:19:06 +0800 Subject: [PATCH 08/23] prototype --- samples/ControlCatalog/Pages/TextBoxPage.xaml | 20 ++++++++----- src/Avalonia.Controls/TextBox.cs | 28 +++++++++++++++++-- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/samples/ControlCatalog/Pages/TextBoxPage.xaml b/samples/ControlCatalog/Pages/TextBoxPage.xaml index 348a285f44..d6fc234f17 100644 --- a/samples/ControlCatalog/Pages/TextBoxPage.xaml +++ b/samples/ControlCatalog/Pages/TextBoxPage.xaml @@ -4,21 +4,26 @@ + + TextBox @@ -31,7 +36,8 @@ - + + @@ -42,8 +48,8 @@ - - + + resm fonts diff --git a/src/Avalonia.Controls/TextBox.cs b/src/Avalonia.Controls/TextBox.cs index 0a785c3b36..23728d7997 100644 --- a/src/Avalonia.Controls/TextBox.cs +++ b/src/Avalonia.Controls/TextBox.cs @@ -101,6 +101,9 @@ namespace Avalonia.Controls public static readonly StyledProperty InnerRightContentProperty = AvaloniaProperty.Register(nameof(InnerRightContent)); + public static readonly StyledProperty ShowPasswordProperty = + AvaloniaProperty.Register(nameof(ShowPassword)); + struct UndoRedoState : IEquatable { public string Text { get; } @@ -129,6 +132,10 @@ namespace Avalonia.Controls static TextBox() { FocusableProperty.OverrideDefaultValue(typeof(TextBox), true); + ShowPasswordProperty.Changed.Subscribe((x)=> + { + + }); } public TextBox() @@ -291,7 +298,7 @@ namespace Avalonia.Controls else { HandleTextInput(value); - } + } _undoRedoHelper.Snapshot(); } } @@ -344,6 +351,16 @@ namespace Avalonia.Controls set { SetValue(InnerRightContentProperty, value); } } + public bool ShowPassword + { + get { return GetValue(ShowPasswordProperty); } + set + { + + SetValue(ShowPasswordProperty, value); + } + } + public TextWrapping TextWrapping { get { return GetValue(TextWrappingProperty); } @@ -774,7 +791,7 @@ namespace Avalonia.Controls // if it did not, we change the selection to where the user clicked var firstSelection = Math.Min(SelectionStart, SelectionEnd); var lastSelection = Math.Max(SelectionStart, SelectionEnd); - var didClickInSelection = SelectionStart != SelectionEnd && + var didClickInSelection = SelectionStart != SelectionEnd && caretIndex >= firstSelection && caretIndex <= lastSelection; if (!didClickInSelection) { @@ -821,6 +838,11 @@ namespace Avalonia.Controls } } + public void Clear() + { + Text = string.Empty; + } + private int DeleteCharacter(int index) { var start = index + 1; @@ -1086,7 +1108,7 @@ namespace Avalonia.Controls SelectionEnd = CaretIndex; } - private bool IsPasswordBox => PasswordChar != default(char); + private bool IsPasswordBox => ShowPassword && PasswordChar != default(char); UndoRedoState UndoRedoHelper.IUndoRedoHost.UndoRedoState { From a899f4040e22c333ddbbc2135566288fea047f4e Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Sat, 1 Aug 2020 10:26:38 -0300 Subject: [PATCH 09/23] use two way binding. --- samples/ControlCatalog/Pages/TextBoxPage.xaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/ControlCatalog/Pages/TextBoxPage.xaml b/samples/ControlCatalog/Pages/TextBoxPage.xaml index d6fc234f17..cae3d20169 100644 --- a/samples/ControlCatalog/Pages/TextBoxPage.xaml +++ b/samples/ControlCatalog/Pages/TextBoxPage.xaml @@ -20,7 +20,7 @@ From ffa8fa7262ebc13672dd926656a6ca16e5cd5fd2 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Wed, 12 Aug 2020 20:31:06 +0800 Subject: [PATCH 10/23] implement ShowPassword Property in textpresenter and forward from textbox --- samples/ControlCatalog/Pages/TextBoxPage.xaml | 2 +- .../Presenters/TextPresenter.cs | 15 +++++++++++--- src/Avalonia.Controls/TextBox.cs | 20 ++++++------------- src/Avalonia.Themes.Fluent/TextBox.xaml | 10 +++++++++- 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/samples/ControlCatalog/Pages/TextBoxPage.xaml b/samples/ControlCatalog/Pages/TextBoxPage.xaml index cae3d20169..55231363d2 100644 --- a/samples/ControlCatalog/Pages/TextBoxPage.xaml +++ b/samples/ControlCatalog/Pages/TextBoxPage.xaml @@ -36,7 +36,7 @@ - + diff --git a/src/Avalonia.Controls/Presenters/TextPresenter.cs b/src/Avalonia.Controls/Presenters/TextPresenter.cs index 6e534bbb2a..ef33ac19f6 100644 --- a/src/Avalonia.Controls/Presenters/TextPresenter.cs +++ b/src/Avalonia.Controls/Presenters/TextPresenter.cs @@ -14,6 +14,9 @@ namespace Avalonia.Controls.Presenters o => o.CaretIndex, (o, v) => o.CaretIndex = v); + public static readonly StyledProperty ShowPasswordCharProperty = + AvaloniaProperty.Register(nameof(ShowPasswordChar), true); + public static readonly StyledProperty PasswordCharProperty = AvaloniaProperty.Register(nameof(PasswordChar)); @@ -75,7 +78,7 @@ namespace Avalonia.Controls.Presenters static TextPresenter() { AffectsRender(SelectionBrushProperty); - AffectsMeasure(TextProperty, PasswordCharProperty, + AffectsMeasure(TextProperty, PasswordCharProperty, ShowPasswordCharProperty, TextAlignmentProperty, TextWrappingProperty, TextBlock.FontSizeProperty, TextBlock.FontStyleProperty, TextBlock.FontWeightProperty, TextBlock.FontFamilyProperty); @@ -84,7 +87,7 @@ namespace Avalonia.Controls.Presenters TextBlock.FontSizeProperty.Changed, TextBlock.FontStyleProperty.Changed, TextBlock.FontWeightProperty.Changed, TextBlock.FontFamilyProperty.Changed, SelectionStartProperty.Changed, SelectionEndProperty.Changed, - SelectionForegroundBrushProperty.Changed, PasswordCharProperty.Changed + SelectionForegroundBrushProperty.Changed, PasswordCharProperty.Changed, ShowPasswordCharProperty.Changed ).AddClassHandler((x, _) => x.InvalidateFormattedText()); CaretIndexProperty.Changed.AddClassHandler((x, e) => x.CaretIndexChanged((int)e.NewValue)); @@ -210,6 +213,12 @@ namespace Avalonia.Controls.Presenters set => SetValue(PasswordCharProperty, value); } + public bool ShowPasswordChar + { + get => GetValue(ShowPasswordCharProperty); + set => SetValue(ShowPasswordCharProperty, value); + } + public IBrush SelectionBrush { get => GetValue(SelectionBrushProperty); @@ -426,7 +435,7 @@ namespace Avalonia.Controls.Presenters var text = Text; - if (PasswordChar != default(char)) + if (PasswordChar != default(char) && ShowPasswordChar) { result = CreateFormattedTextInternal(_constraint, new string(PasswordChar, text?.Length ?? 0)); } diff --git a/src/Avalonia.Controls/TextBox.cs b/src/Avalonia.Controls/TextBox.cs index 23728d7997..08e4e923f5 100644 --- a/src/Avalonia.Controls/TextBox.cs +++ b/src/Avalonia.Controls/TextBox.cs @@ -101,8 +101,8 @@ namespace Avalonia.Controls public static readonly StyledProperty InnerRightContentProperty = AvaloniaProperty.Register(nameof(InnerRightContent)); - public static readonly StyledProperty ShowPasswordProperty = - AvaloniaProperty.Register(nameof(ShowPassword)); + public static readonly StyledProperty ShowPasswordCharProperty = + AvaloniaProperty.Register(nameof(ShowPasswordChar)); struct UndoRedoState : IEquatable { @@ -132,10 +132,6 @@ namespace Avalonia.Controls static TextBox() { FocusableProperty.OverrideDefaultValue(typeof(TextBox), true); - ShowPasswordProperty.Changed.Subscribe((x)=> - { - - }); } public TextBox() @@ -351,14 +347,10 @@ namespace Avalonia.Controls set { SetValue(InnerRightContentProperty, value); } } - public bool ShowPassword + public bool ShowPasswordChar { - get { return GetValue(ShowPasswordProperty); } - set - { - - SetValue(ShowPasswordProperty, value); - } + get { return GetValue(ShowPasswordCharProperty); } + set { SetValue(ShowPasswordCharProperty, value); } } public TextWrapping TextWrapping @@ -1108,7 +1100,7 @@ namespace Avalonia.Controls SelectionEnd = CaretIndex; } - private bool IsPasswordBox => ShowPassword && PasswordChar != default(char); + private bool IsPasswordBox => PasswordChar != default(char); UndoRedoState UndoRedoHelper.IUndoRedoHost.UndoRedoState { diff --git a/src/Avalonia.Themes.Fluent/TextBox.xaml b/src/Avalonia.Themes.Fluent/TextBox.xaml index 5278e5d3d0..0735b83014 100644 --- a/src/Avalonia.Themes.Fluent/TextBox.xaml +++ b/src/Avalonia.Themes.Fluent/TextBox.xaml @@ -79,6 +79,7 @@ TextAlignment="{TemplateBinding TextAlignment}" TextWrapping="{TemplateBinding TextWrapping}" PasswordChar="{TemplateBinding PasswordChar}" + ShowPasswordChar="{TemplateBinding ShowPasswordChar}" SelectionBrush="{TemplateBinding SelectionBrush}" SelectionForegroundBrush="{TemplateBinding SelectionForegroundBrush}" CaretBrush="{TemplateBinding CaretBrush}" @@ -142,7 +143,6 @@ - @@ -151,4 +151,12 @@ + + From e8d3ad9d3f381c54383a0a532038e0440f868030 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Wed, 12 Aug 2020 20:40:30 +0800 Subject: [PATCH 11/23] revert unnecessary changes --- samples/ControlCatalog/Pages/TextBoxPage.xaml | 77 ++++++++++--------- 1 file changed, 40 insertions(+), 37 deletions(-) diff --git a/samples/ControlCatalog/Pages/TextBoxPage.xaml b/samples/ControlCatalog/Pages/TextBoxPage.xaml index 55231363d2..8dc947c298 100644 --- a/samples/ControlCatalog/Pages/TextBoxPage.xaml +++ b/samples/ControlCatalog/Pages/TextBoxPage.xaml @@ -1,7 +1,7 @@ + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + x:Class="ControlCatalog.Pages.TextBoxPage"> - - + - TextBox A control into which the user can input text - + - + - - + - + - - + + + - - resm fonts - - - - - - - - res fonts - - - - + + resm fonts + + + + + + + + res fonts + + + + + - - - - From 661480e55c957295aebdabd7374ae197dae6a6d4 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Wed, 12 Aug 2020 20:59:01 +0800 Subject: [PATCH 12/23] polish --- samples/ControlCatalog/Pages/TextBoxPage.xaml | 21 ++--------- .../Presenters/TextPresenter.cs | 16 ++++---- src/Avalonia.Controls/TextBox.cs | 10 ++--- src/Avalonia.Themes.Fluent/TextBox.xaml | 37 +++++++++++++++++-- 4 files changed, 49 insertions(+), 35 deletions(-) diff --git a/samples/ControlCatalog/Pages/TextBoxPage.xaml b/samples/ControlCatalog/Pages/TextBoxPage.xaml index 8dc947c298..256212eaf1 100644 --- a/samples/ControlCatalog/Pages/TextBoxPage.xaml +++ b/samples/ControlCatalog/Pages/TextBoxPage.xaml @@ -2,22 +2,6 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="ControlCatalog.Pages.TextBoxPage"> - - - - TextBox A control into which the user can input text @@ -36,6 +20,7 @@ @@ -54,8 +39,8 @@ - - + + resm fonts diff --git a/src/Avalonia.Controls/Presenters/TextPresenter.cs b/src/Avalonia.Controls/Presenters/TextPresenter.cs index ef33ac19f6..1cd7e11564 100644 --- a/src/Avalonia.Controls/Presenters/TextPresenter.cs +++ b/src/Avalonia.Controls/Presenters/TextPresenter.cs @@ -14,8 +14,8 @@ namespace Avalonia.Controls.Presenters o => o.CaretIndex, (o, v) => o.CaretIndex = v); - public static readonly StyledProperty ShowPasswordCharProperty = - AvaloniaProperty.Register(nameof(ShowPasswordChar), true); + public static readonly StyledProperty ShowPasswordTextProperty = + AvaloniaProperty.Register(nameof(ShowPasswordText)); public static readonly StyledProperty PasswordCharProperty = AvaloniaProperty.Register(nameof(PasswordChar)); @@ -78,7 +78,7 @@ namespace Avalonia.Controls.Presenters static TextPresenter() { AffectsRender(SelectionBrushProperty); - AffectsMeasure(TextProperty, PasswordCharProperty, ShowPasswordCharProperty, + AffectsMeasure(TextProperty, PasswordCharProperty, ShowPasswordTextProperty, TextAlignmentProperty, TextWrappingProperty, TextBlock.FontSizeProperty, TextBlock.FontStyleProperty, TextBlock.FontWeightProperty, TextBlock.FontFamilyProperty); @@ -87,7 +87,7 @@ namespace Avalonia.Controls.Presenters TextBlock.FontSizeProperty.Changed, TextBlock.FontStyleProperty.Changed, TextBlock.FontWeightProperty.Changed, TextBlock.FontFamilyProperty.Changed, SelectionStartProperty.Changed, SelectionEndProperty.Changed, - SelectionForegroundBrushProperty.Changed, PasswordCharProperty.Changed, ShowPasswordCharProperty.Changed + SelectionForegroundBrushProperty.Changed, PasswordCharProperty.Changed, ShowPasswordTextProperty.Changed ).AddClassHandler((x, _) => x.InvalidateFormattedText()); CaretIndexProperty.Changed.AddClassHandler((x, e) => x.CaretIndexChanged((int)e.NewValue)); @@ -213,10 +213,10 @@ namespace Avalonia.Controls.Presenters set => SetValue(PasswordCharProperty, value); } - public bool ShowPasswordChar + public bool ShowPasswordText { - get => GetValue(ShowPasswordCharProperty); - set => SetValue(ShowPasswordCharProperty, value); + get => GetValue(ShowPasswordTextProperty); + set => SetValue(ShowPasswordTextProperty, value); } public IBrush SelectionBrush @@ -435,7 +435,7 @@ namespace Avalonia.Controls.Presenters var text = Text; - if (PasswordChar != default(char) && ShowPasswordChar) + if (PasswordChar != default(char) && !ShowPasswordText) { result = CreateFormattedTextInternal(_constraint, new string(PasswordChar, text?.Length ?? 0)); } diff --git a/src/Avalonia.Controls/TextBox.cs b/src/Avalonia.Controls/TextBox.cs index 08e4e923f5..489937147f 100644 --- a/src/Avalonia.Controls/TextBox.cs +++ b/src/Avalonia.Controls/TextBox.cs @@ -101,8 +101,8 @@ namespace Avalonia.Controls public static readonly StyledProperty InnerRightContentProperty = AvaloniaProperty.Register(nameof(InnerRightContent)); - public static readonly StyledProperty ShowPasswordCharProperty = - AvaloniaProperty.Register(nameof(ShowPasswordChar)); + public static readonly StyledProperty ShowPasswordTextProperty = + AvaloniaProperty.Register(nameof(ShowPasswordText)); struct UndoRedoState : IEquatable { @@ -347,10 +347,10 @@ namespace Avalonia.Controls set { SetValue(InnerRightContentProperty, value); } } - public bool ShowPasswordChar + public bool ShowPasswordText { - get { return GetValue(ShowPasswordCharProperty); } - set { SetValue(ShowPasswordCharProperty, value); } + get { return GetValue(ShowPasswordTextProperty); } + set { SetValue(ShowPasswordTextProperty, value); } } public TextWrapping TextWrapping diff --git a/src/Avalonia.Themes.Fluent/TextBox.xaml b/src/Avalonia.Themes.Fluent/TextBox.xaml index 0735b83014..3b66e7f09e 100644 --- a/src/Avalonia.Themes.Fluent/TextBox.xaml +++ b/src/Avalonia.Themes.Fluent/TextBox.xaml @@ -1,6 +1,14 @@ 0,0,0,4 + + + + + + + + - + + + + + From 2a11f6801ca791152f4d910288cd25a7d5a221df Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Wed, 12 Aug 2020 21:35:59 +0800 Subject: [PATCH 13/23] address review --- samples/ControlCatalog/Pages/TextBoxPage.xaml | 5 ++-- .../Presenters/TextPresenter.cs | 16 ++++++------- src/Avalonia.Controls/TextBox.cs | 10 ++++---- src/Avalonia.Themes.Fluent/TextBox.xaml | 24 +++++++------------ 4 files changed, 23 insertions(+), 32 deletions(-) diff --git a/samples/ControlCatalog/Pages/TextBoxPage.xaml b/samples/ControlCatalog/Pages/TextBoxPage.xaml index 256212eaf1..099d40b3de 100644 --- a/samples/ControlCatalog/Pages/TextBoxPage.xaml +++ b/samples/ControlCatalog/Pages/TextBoxPage.xaml @@ -20,7 +20,7 @@ @@ -39,8 +39,7 @@ - - + resm fonts diff --git a/src/Avalonia.Controls/Presenters/TextPresenter.cs b/src/Avalonia.Controls/Presenters/TextPresenter.cs index 1cd7e11564..0841030aaa 100644 --- a/src/Avalonia.Controls/Presenters/TextPresenter.cs +++ b/src/Avalonia.Controls/Presenters/TextPresenter.cs @@ -14,8 +14,8 @@ namespace Avalonia.Controls.Presenters o => o.CaretIndex, (o, v) => o.CaretIndex = v); - public static readonly StyledProperty ShowPasswordTextProperty = - AvaloniaProperty.Register(nameof(ShowPasswordText)); + public static readonly StyledProperty RevealPasswordTextProperty = + AvaloniaProperty.Register(nameof(RevealPasswordText)); public static readonly StyledProperty PasswordCharProperty = AvaloniaProperty.Register(nameof(PasswordChar)); @@ -78,7 +78,7 @@ namespace Avalonia.Controls.Presenters static TextPresenter() { AffectsRender(SelectionBrushProperty); - AffectsMeasure(TextProperty, PasswordCharProperty, ShowPasswordTextProperty, + AffectsMeasure(TextProperty, PasswordCharProperty, RevealPasswordTextProperty, TextAlignmentProperty, TextWrappingProperty, TextBlock.FontSizeProperty, TextBlock.FontStyleProperty, TextBlock.FontWeightProperty, TextBlock.FontFamilyProperty); @@ -87,7 +87,7 @@ namespace Avalonia.Controls.Presenters TextBlock.FontSizeProperty.Changed, TextBlock.FontStyleProperty.Changed, TextBlock.FontWeightProperty.Changed, TextBlock.FontFamilyProperty.Changed, SelectionStartProperty.Changed, SelectionEndProperty.Changed, - SelectionForegroundBrushProperty.Changed, PasswordCharProperty.Changed, ShowPasswordTextProperty.Changed + SelectionForegroundBrushProperty.Changed, PasswordCharProperty.Changed, RevealPasswordTextProperty.Changed ).AddClassHandler((x, _) => x.InvalidateFormattedText()); CaretIndexProperty.Changed.AddClassHandler((x, e) => x.CaretIndexChanged((int)e.NewValue)); @@ -213,10 +213,10 @@ namespace Avalonia.Controls.Presenters set => SetValue(PasswordCharProperty, value); } - public bool ShowPasswordText + public bool RevealPasswordText { - get => GetValue(ShowPasswordTextProperty); - set => SetValue(ShowPasswordTextProperty, value); + get => GetValue(RevealPasswordTextProperty); + set => SetValue(RevealPasswordTextProperty, value); } public IBrush SelectionBrush @@ -435,7 +435,7 @@ namespace Avalonia.Controls.Presenters var text = Text; - if (PasswordChar != default(char) && !ShowPasswordText) + if (PasswordChar != default(char) && !RevealPasswordText) { result = CreateFormattedTextInternal(_constraint, new string(PasswordChar, text?.Length ?? 0)); } diff --git a/src/Avalonia.Controls/TextBox.cs b/src/Avalonia.Controls/TextBox.cs index 489937147f..0e0d053d88 100644 --- a/src/Avalonia.Controls/TextBox.cs +++ b/src/Avalonia.Controls/TextBox.cs @@ -101,8 +101,8 @@ namespace Avalonia.Controls public static readonly StyledProperty InnerRightContentProperty = AvaloniaProperty.Register(nameof(InnerRightContent)); - public static readonly StyledProperty ShowPasswordTextProperty = - AvaloniaProperty.Register(nameof(ShowPasswordText)); + public static readonly StyledProperty RevealPasswordTextProperty = + AvaloniaProperty.Register(nameof(RevealPasswordText)); struct UndoRedoState : IEquatable { @@ -347,10 +347,10 @@ namespace Avalonia.Controls set { SetValue(InnerRightContentProperty, value); } } - public bool ShowPasswordText + public bool RevealPasswordText { - get { return GetValue(ShowPasswordTextProperty); } - set { SetValue(ShowPasswordTextProperty, value); } + get { return GetValue(RevealPasswordTextProperty); } + set { SetValue(RevealPasswordTextProperty, value); } } public TextWrapping TextWrapping diff --git a/src/Avalonia.Themes.Fluent/TextBox.xaml b/src/Avalonia.Themes.Fluent/TextBox.xaml index 8bc8d38c01..bd10fbbe51 100644 --- a/src/Avalonia.Themes.Fluent/TextBox.xaml +++ b/src/Avalonia.Themes.Fluent/TextBox.xaml @@ -10,11 +10,11 @@ 0,0,0,4 - + - + @@ -96,7 +96,7 @@ TextAlignment="{TemplateBinding TextAlignment}" TextWrapping="{TemplateBinding TextWrapping}" PasswordChar="{TemplateBinding PasswordChar}" - ShowPasswordText="{TemplateBinding ShowPasswordText}" + RevealPasswordText="{TemplateBinding RevealPasswordText}" SelectionBrush="{TemplateBinding SelectionBrush}" SelectionForegroundBrush="{TemplateBinding SelectionForegroundBrush}" CaretBrush="{TemplateBinding CaretBrush}" @@ -166,28 +166,20 @@ - - - - - + + + + + + + + + + + + + From 913958732ea144e5221e67cbc0e1962a02d565d2 Mon Sep 17 00:00:00 2001 From: Maksym Katsydan Date: Thu, 13 Aug 2020 21:53:15 -0400 Subject: [PATCH 17/23] Fluent TextBox: Add PasswordBoxRevealButton style --- src/Avalonia.Themes.Fluent/TextBox.xaml | 85 ++++++++++++++++--------- 1 file changed, 56 insertions(+), 29 deletions(-) diff --git a/src/Avalonia.Themes.Fluent/TextBox.xaml b/src/Avalonia.Themes.Fluent/TextBox.xaml index 0fe5f9061f..d73704f64c 100644 --- a/src/Avalonia.Themes.Fluent/TextBox.xaml +++ b/src/Avalonia.Themes.Fluent/TextBox.xaml @@ -11,16 +11,10 @@ 0,0,0,4 - M1169 1024l879 -879l-145 -145l-879 879l-879 -879l-145 145l879 879l-879 879l145 145l879 -879l879 879l145 -145z - - - - - - - - + M 11.416016,10 20,1.4160156 18.583984,0 10,8.5839846 1.4160156,0 0,1.4160156 8.5839844,10 0,18.583985 1.4160156,20 10,11.416015 18.583984,20 20,18.583985 Z + m10.051 7.0032c2.215 0 4.0105 1.7901 4.0105 3.9984s-1.7956 3.9984-4.0105 3.9984c-2.215 0-4.0105-1.7901-4.0105-3.9984s1.7956-3.9984 4.0105-3.9984zm0 1.4994c-1.3844 0-2.5066 1.1188-2.5066 2.499s1.1222 2.499 2.5066 2.499 2.5066-1.1188 2.5066-2.499-1.1222-2.499-2.5066-2.499zm0-5.0026c4.6257 0 8.6188 3.1487 9.7267 7.5613 0.10085 0.40165-0.14399 0.80877-0.54686 0.90931-0.40288 0.10054-0.81122-0.14355-0.91208-0.54521-0.94136-3.7492-4.3361-6.4261-8.2678-6.4261-3.9334 0-7.3292 2.6792-8.2689 6.4306-0.10063 0.40171-0.50884 0.64603-0.91177 0.54571s-0.648-0.5073-0.54737-0.90901c1.106-4.4152 5.1003-7.5667 9.728-7.5667z + - @@ -190,20 +180,36 @@ + + - + - - - - - - From e5644c0b72303aefe6acd06b77a8b41f69b28bbc Mon Sep 17 00:00:00 2001 From: Maksym Katsydan Date: Thu, 13 Aug 2020 22:02:52 -0400 Subject: [PATCH 18/23] Fluent TextBox: Remove multibinding from floatingWatermark Also rename floatingWatermark and watermark --- src/Avalonia.Themes.Fluent/TextBox.xaml | 35 +++++++++++-------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/Avalonia.Themes.Fluent/TextBox.xaml b/src/Avalonia.Themes.Fluent/TextBox.xaml index d73704f64c..c661162e5c 100644 --- a/src/Avalonia.Themes.Fluent/TextBox.xaml +++ b/src/Avalonia.Themes.Fluent/TextBox.xaml @@ -54,27 +54,17 @@ - - - - - - - - + - - @@ -135,7 +125,7 @@ - @@ -144,7 +134,7 @@ - @@ -161,6 +151,13 @@ + + + - @@ -120,7 +121,7 @@ - @@ -138,17 +139,17 @@ - - - From a887e3e50e0b9b9d020db50e32f8ecf9042893ec Mon Sep 17 00:00:00 2001 From: Maksym Katsydan Date: Thu, 13 Aug 2020 22:41:45 -0400 Subject: [PATCH 20/23] Fluent TextBox: Return "Hide" password button icon --- src/Avalonia.Themes.Fluent/TextBox.xaml | 45 ++++++++++++++++++------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/src/Avalonia.Themes.Fluent/TextBox.xaml b/src/Avalonia.Themes.Fluent/TextBox.xaml index 515cdccd2c..5eddd54226 100644 --- a/src/Avalonia.Themes.Fluent/TextBox.xaml +++ b/src/Avalonia.Themes.Fluent/TextBox.xaml @@ -13,6 +13,7 @@ 0,0,0,4 M 11.416016,10 20,1.4160156 18.583984,0 10,8.5839846 1.4160156,0 0,1.4160156 8.5839844,10 0,18.583985 1.4160156,20 10,11.416015 18.583984,20 20,18.583985 Z m10.051 7.0032c2.215 0 4.0105 1.7901 4.0105 3.9984s-1.7956 3.9984-4.0105 3.9984c-2.215 0-4.0105-1.7901-4.0105-3.9984s1.7956-3.9984 4.0105-3.9984zm0 1.4994c-1.3844 0-2.5066 1.1188-2.5066 2.499s1.1222 2.499 2.5066 2.499 2.5066-1.1188 2.5066-2.499-1.1222-2.499-2.5066-2.499zm0-5.0026c4.6257 0 8.6188 3.1487 9.7267 7.5613 0.10085 0.40165-0.14399 0.80877-0.54686 0.90931-0.40288 0.10054-0.81122-0.14355-0.91208-0.54521-0.94136-3.7492-4.3361-6.4261-8.2678-6.4261-3.9334 0-7.3292 2.6792-8.2689 6.4306-0.10063 0.40171-0.50884 0.64603-0.91177 0.54571s-0.648-0.5073-0.54737-0.90901c1.106-4.4152 5.1003-7.5667 9.728-7.5667z + m0.21967 0.21965c-0.26627 0.26627-0.29047 0.68293-0.07262 0.97654l0.07262 0.08412 4.0346 4.0346c-1.922 1.3495-3.3585 3.365-3.9554 5.7495-0.10058 0.4018 0.14362 0.8091 0.54543 0.9097 0.40182 0.1005 0.80909-0.1436 0.90968-0.5455 0.52947-2.1151 1.8371-3.8891 3.5802-5.0341l1.8096 1.8098c-0.70751 0.7215-1.1438 1.71-1.1438 2.8003 0 2.2092 1.7909 4 4 4 1.0904 0 2.0788-0.4363 2.8004-1.1438l5.9193 5.9195c0.2929 0.2929 0.7677 0.2929 1.0606 0 0.2663-0.2662 0.2905-0.6829 0.0726-0.9765l-0.0726-0.0841-6.1135-6.1142 0.0012-0.0015-1.2001-1.1979-2.8699-2.8693 2e-3 -8e-4 -2.8812-2.8782 0.0012-0.0018-1.1333-1.1305-4.3064-4.3058c-0.29289-0.29289-0.76777-0.29289-1.0607 0zm7.9844 9.0458 3.5351 3.5351c-0.45 0.4358-1.0633 0.704-1.7392 0.704-1.3807 0-2.5-1.1193-2.5-2.5 0-0.6759 0.26824-1.2892 0.7041-1.7391zm1.7959-5.7655c-1.0003 0-1.9709 0.14807-2.8889 0.425l1.237 1.2362c0.5358-0.10587 1.0883-0.16119 1.6519-0.16119 3.9231 0 7.3099 2.6803 8.2471 6.4332 0.1004 0.4018 0.5075 0.6462 0.9094 0.5459 0.4019-0.1004 0.6463-0.5075 0.5459-0.9094-1.103-4.417-5.0869-7.5697-9.7024-7.5697zm0.1947 3.5093 3.8013 3.8007c-0.1018-2.0569-1.7488-3.7024-3.8013-3.8007z - @@ -240,7 +251,8 @@ @@ -253,9 +265,9 @@ @@ -265,4 +277,11 @@ + + + From 23713366fa02544ee7a994adec943a1525fc7c60 Mon Sep 17 00:00:00 2001 From: Jumar Macato Date: Fri, 14 Aug 2020 11:54:09 +0800 Subject: [PATCH 21/23] add support for default theme --- src/Avalonia.Themes.Default/TextBox.xaml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Avalonia.Themes.Default/TextBox.xaml b/src/Avalonia.Themes.Default/TextBox.xaml index 6a746dda30..8384cccada 100644 --- a/src/Avalonia.Themes.Default/TextBox.xaml +++ b/src/Avalonia.Themes.Default/TextBox.xaml @@ -35,14 +35,16 @@ - - + + + + IsVisible="{TemplateBinding Text, Converter={x:Static StringConverters.IsNullOrEmpty}}" + Grid.Column="1" Grid.ColumnSpan="1"/> - + CaretBrush="{TemplateBinding CaretBrush}" + Grid.Column="1" Grid.ColumnSpan="1"/> + + From ba11b5d8d0f26267a2a7d7a0eb2cae576c832739 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Fri, 14 Aug 2020 10:15:53 +0100 Subject: [PATCH 22/23] add failing unit test, for pw reveal getting reset on focus lost. --- .../TextBoxTests.cs | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/Avalonia.Controls.UnitTests/TextBoxTests.cs b/tests/Avalonia.Controls.UnitTests/TextBoxTests.cs index 217dec2d6d..af3b68f4a0 100644 --- a/tests/Avalonia.Controls.UnitTests/TextBoxTests.cs +++ b/tests/Avalonia.Controls.UnitTests/TextBoxTests.cs @@ -521,6 +521,40 @@ namespace Avalonia.Controls.UnitTests Assert.Equal(1, lfcount); } } + + [Fact] + public void TextBox_Reveal_Password_Reset_When_Lost_Focus() + { + using (UnitTestApplication.Start(FocusServices)) + { + var target1 = new TextBox + { + Template = CreateTemplate(), + Text = "1234", + PasswordChar = '*' + }; + var target2 = new TextBox + { + Template = CreateTemplate(), + Text = "5678" + }; + var sp = new StackPanel(); + sp.Children.Add(target1); + sp.Children.Add(target2); + + target1.ApplyTemplate(); + target2.ApplyTemplate(); + + var root = new TestRoot { Child = sp }; + + target1.Focus(); + target1.RevealPassword = true; + + target2.Focus(); + + Assert.False(target1.RevealPassword); + } + } [Fact] public void Setting_Bound_Text_To_Null_Works() From 03cc2dfff7d646cbc342764a16ab93502fff447b Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Fri, 14 Aug 2020 10:16:11 +0100 Subject: [PATCH 23/23] clear reveal password when lose focus. --- src/Avalonia.Controls/TextBox.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Avalonia.Controls/TextBox.cs b/src/Avalonia.Controls/TextBox.cs index 0ad2a55f19..7e28d88581 100644 --- a/src/Avalonia.Controls/TextBox.cs +++ b/src/Avalonia.Controls/TextBox.cs @@ -413,6 +413,7 @@ namespace Avalonia.Controls SelectionStart = 0; SelectionEnd = 0; _presenter?.HideCaret(); + RevealPassword = false; } protected override void OnTextInput(TextInputEventArgs e)