Browse Source
* Added WatermarkForeground property * Added samples * Added unit tests * Added render tests * Fix merge issues * Updated render tests * Standardize watermark foreground naming * Pending changes * More changes * Use UseFloatingPlaceholder * Fix testspull/20531/merge
committed by
GitHub
50 changed files with 844 additions and 316 deletions
@ -1,6 +1,6 @@ |
|||
<Window xmlns="https://github.com/avaloniaui" |
|||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
|||
x:Class="Sample.App.NoNamedControls"> |
|||
<TextBox Watermark="Username input" |
|||
UseFloatingWatermark="True" /> |
|||
<TextBox Placeholder="Username input" |
|||
UseFloatingPlaceholder="True" /> |
|||
</Window> |
|||
@ -0,0 +1,135 @@ |
|||
using System.Threading.Tasks; |
|||
using Avalonia.Controls; |
|||
using Avalonia.Controls.Presenters; |
|||
using Avalonia.Controls.Templates; |
|||
using Avalonia.Layout; |
|||
using Avalonia.Media; |
|||
using Xunit; |
|||
|
|||
namespace Avalonia.Skia.RenderTests |
|||
{ |
|||
public class TextBoxTests : TestBase |
|||
{ |
|||
public TextBoxTests() |
|||
: base(@"Controls\TextBox") |
|||
{ |
|||
} |
|||
|
|||
private static IControlTemplate CreateTextBoxTemplate() |
|||
{ |
|||
return new FuncControlTemplate<TextBox>((textBox, scope) => |
|||
{ |
|||
var border = new Border |
|||
{ |
|||
Background = textBox.Background, |
|||
BorderBrush = Brushes.Gray, |
|||
BorderThickness = new Thickness(1), |
|||
Padding = new Thickness(4), |
|||
}; |
|||
|
|||
var panel = new Panel(); |
|||
|
|||
// Use Antialias mode
|
|||
TextOptions.SetTextRenderingMode(panel, TextRenderingMode.Antialias); |
|||
|
|||
var placeholder = new TextBlock |
|||
{ |
|||
Name = "PART_Placeholder", |
|||
[!TextBlock.TextProperty] = textBox[!TextBox.PlaceholderTextProperty], |
|||
[!TextBlock.ForegroundProperty] = textBox[!TextBox.PlaceholderForegroundProperty], |
|||
FontFamily = textBox.FontFamily, |
|||
FontSize = textBox.FontSize, |
|||
VerticalAlignment = VerticalAlignment.Center, |
|||
Opacity = 0.5, |
|||
}.RegisterInNameScope(scope); |
|||
|
|||
var presenter = new TextPresenter |
|||
{ |
|||
Name = "PART_TextPresenter", |
|||
[!TextPresenter.TextProperty] = textBox[!TextBox.TextProperty], |
|||
[!TextPresenter.CaretIndexProperty] = textBox[!TextBox.CaretIndexProperty], |
|||
FontFamily = textBox.FontFamily, |
|||
FontSize = textBox.FontSize, |
|||
}.RegisterInNameScope(scope); |
|||
|
|||
panel.Children.Add(placeholder); |
|||
panel.Children.Add(presenter); |
|||
border.Child = panel; |
|||
|
|||
return border; |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Placeholder_With_Red_Foreground() |
|||
{ |
|||
var target = new Border |
|||
{ |
|||
Padding = new Thickness(8), |
|||
Width = 200, |
|||
Height = 50, |
|||
Background = Brushes.White, |
|||
Child = new TextBox |
|||
{ |
|||
Template = CreateTextBoxTemplate(), |
|||
FontFamily = TestFontFamily, |
|||
FontSize = 12, |
|||
Background = Brushes.White, |
|||
PlaceholderText = "Red placeholder", |
|||
PlaceholderForeground = Brushes.Red, |
|||
} |
|||
}; |
|||
|
|||
await RenderToFile(target); |
|||
CompareImages(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Placeholder_With_Blue_Foreground() |
|||
{ |
|||
var target = new Border |
|||
{ |
|||
Padding = new Thickness(8), |
|||
Width = 200, |
|||
Height = 50, |
|||
Background = Brushes.White, |
|||
Child = new TextBox |
|||
{ |
|||
Template = CreateTextBoxTemplate(), |
|||
FontFamily = TestFontFamily, |
|||
FontSize = 12, |
|||
Background = Brushes.White, |
|||
PlaceholderText = "Blue placeholder", |
|||
PlaceholderForeground = Brushes.Blue, |
|||
} |
|||
}; |
|||
|
|||
await RenderToFile(target); |
|||
CompareImages(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Placeholder_With_Default_Foreground() |
|||
{ |
|||
var target = new Border |
|||
{ |
|||
Padding = new Thickness(8), |
|||
Width = 200, |
|||
Height = 50, |
|||
Background = Brushes.White, |
|||
Child = new TextBox |
|||
{ |
|||
Template = CreateTextBoxTemplate(), |
|||
FontFamily = TestFontFamily, |
|||
FontSize = 12, |
|||
Background = Brushes.White, |
|||
PlaceholderText = "Default placeholder", |
|||
PlaceholderForeground = Brushes.Gray, |
|||
} |
|||
}; |
|||
|
|||
await RenderToFile(target); |
|||
CompareImages(); |
|||
} |
|||
} |
|||
} |
|||
|
After Width: | Height: | Size: 1.6 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
Loading…
Reference in new issue