Skip to content

Commit 7f27b72

Browse files
Smart hint and text box style refactor (#3486)
* Initial TextBox style changes added * Temporarily fix AutoSuggestBox by bringing in old converters directly in style * Add character counter toggle to demo app (cherry picked from commit 555d6f9979cb32e004ceb02a716d8fe11ec3d601) (cherry picked from commit 3b61edd) * Basics of SmartHint refactor in place - edge cases need attention * Fix "padding" issues for outlined style by letting the padding animate from 0 to desired size * Fix AcceptsReturn=True scenario for TextBox use of SmartHint * Smart hint page in demo app handles its own scrolling * Improve handling of dynamic FontSize changes * Add TextFieldAssist.IconVerticalAlignment AP to control icon placement in TextBox elements * Add APs for controlling prefix/suffix visibility and floating hint alignment behavior * DP cleanup * Smart Hint demo app page cleanup * Let hint span accross prefix/suffix texts * Update demo app Smart Hint page with selectors for new APs * Make prefix/suffix visibility converter respect new AP * Decent working state; special cases where hint should also animate horizontally not covered yet * Fix horizontal animation of hint cases * Mark converters for obsoletion/deletion * Remove no longer used converter * Move SmartHint converters into their own files * Temporarily change startup page to SmartHint * Fix FloatingHintInitialHorizontalOffsetConverter logic * Update MainDemo.Wpf/SmartHint.xaml Co-authored-by: Kevin B <[email protected]> * Update MainDemo.Wpf/SmartHint.xaml Co-authored-by: Kevin B <[email protected]> * Update MainDemo.Wpf/SmartHint.xaml Co-authored-by: Kevin B <[email protected]> * Update MainDemo.Wpf/SmartHint.xaml Co-authored-by: Kevin B <[email protected]> * Update MainDemo.Wpf/SmartHint.xaml Co-authored-by: Kevin B <[email protected]> * Update MaterialDesignThemes.Wpf/Converters/FloatingHintMarginConverter.cs Co-authored-by: Kevin B <[email protected]> * Renamed converter values * Update MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.SmartHint.xaml Co-authored-by: Kevin B <[email protected]> * Implement BooleanToDashStyleConverter.ConvertBack() * Remove dead code * Handle HasErrors=True margin correction * Fix support for TextFieldAssist.NewSpecHighlightingEnabled=True * Add TextFieldAssist.NewSpecHighlightingEnabled support on demo app SmartHint page * Add options to control scroll bar visibility on SmartHint demo page (for TextBox variants) * Slightly nicer layout for scroll bar options on SmartHint demo page * Fix "accepts return" check box to use VM binding * Temporarily add defaults to showcase the horizontal scrollbar issue * Include RD for missing static resource * PoC fix for the VerticalContentAlignment=Stretch issue * Fix demo app layout and defaults after rebase * Leverage list pattern matching in relevant converters * Cleanup constants and "hide" temporary constants in an internal class. * Fix for TextBoxTests.FilledTextBox_ValidationErrorMargin_MatchesHelperTextMargin() * Fix for TextBoxTests.HelperText_CanSetFontColorWithAttachedStyle() * Fix for TextBoxTests.OnClearButtonShown_ControlHeightDoesNotChange() * Deleted TextBoxTests.OnOutlinedTextBox_FloatingHintOffsetWithinRange() as it is no longer relevant * Fix for TextBoxTests.OnTextBoxDisabled_FloatingHintBackgroundIsOpaque() * Fix for TextBoxTests.OutlinedTextBox_ValidationErrorMargin_MatchesHelperTextMargin() * Fix for TextBoxTests.TextBox_MultiLineAndFixedHeight_RespectsVerticalContentAlignment() * Adjust default paddings to for better looks, and temporary make the UI tests comparing control heights pass. * Merge duplicate triggers * Add dedicated "MaterialDesign.Brush.TextBox.HoverBorder" brush * Use new hover brush for the filled TextBox style * Minor code cleanup * New brush is now an alternate rather than an obsolete brush * Fix issue with HintAssist.IsFloating wrongfully affecting the hint text placement * Cherry-pick FloatingHintMarginConverter from ComboBox branch * Add additional binding to use of FloatingHintMarginConverter * Add IsEditable parameter to prefix/suffix converter (taken from ComboBox branch) * Split failing default height tests into pre- and post-smarthint-refactor * Fix jumpy UI when validation errors and color hint text red * Set MinHeight=16 and separate all tests into pre-/post-refactor * Remove MaxWidth from demo app page --------- Co-authored-by: Kevin B <[email protected]> Co-authored-by: Kevin Bost <[email protected]>
1 parent e26d23d commit 7f27b72

37 files changed

+1301
-639
lines changed

MainDemo.Wpf/Domain/MainWindowViewModel.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,12 @@ private static IEnumerable<DemoItem> GenerateDemoItems(ISnackbarMessageQueue sna
454454
{
455455
DocumentationLink.DemoPageLink<SmartHint>(),
456456
DocumentationLink.StyleLink("SmartHint"),
457-
});
457+
})
458+
{
459+
//The smart hint view handles its own scrolling
460+
HorizontalScrollBarVisibilityRequirement = ScrollBarVisibility.Disabled,
461+
VerticalScrollBarVisibilityRequirement = ScrollBarVisibility.Disabled
462+
};
458463

459464
yield return new DemoItem(
460465
"PopupBox",

MainDemo.Wpf/Domain/SmartHintViewModel.cs

Lines changed: 70 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,39 @@ internal class SmartHintViewModel : ViewModelBase
2121
private bool _applyCustomPadding;
2222
private Thickness _selectedCustomPadding = new(5);
2323
private double _selectedCustomHeight = double.NaN;
24-
private VerticalAlignment _selectedVerticalAlignment = VerticalAlignment.Center;
24+
private VerticalAlignment _selectedVerticalAlignment = VerticalAlignment.Stretch;
2525
private double _selectedLeadingIconSize = 20;
2626
private double _selectedTrailingIconSize = 20;
27-
private string? _prefixText;
28-
private string? _suffixText;
27+
private VerticalAlignment _selectedIconVerticalAlignment = VerticalAlignment.Center;
28+
private string? _prefixText = "pre";
29+
private string? _suffixText = "suf";
2930
private double _selectedFontSize = double.NaN;
3031
private FontFamily? _selectedFontFamily = DefaultFontFamily;
3132
private bool _controlsEnabled = true;
3233
private bool _rippleOnFocus = false;
3334
private bool _textBoxAcceptsReturn = false;
3435
private int _maxLength;
36+
private PrefixSuffixVisibility _selectedPrefixVisibility = PrefixSuffixVisibility.WhenFocusedOrNonEmpty;
37+
private PrefixSuffixHintBehavior _selectedPrefixHintBehavior = PrefixSuffixHintBehavior.AlignWithPrefixSuffix;
38+
private PrefixSuffixVisibility _selectedSuffixVisibility = PrefixSuffixVisibility.WhenFocusedOrNonEmpty;
39+
private PrefixSuffixHintBehavior _selectedSuffixHintBehavior = PrefixSuffixHintBehavior.AlignWithPrefixSuffix;
40+
private bool _newSpecHighlightingEnabled;
41+
private ScrollBarVisibility _selectedVerticalScrollBarVisibility = ScrollBarVisibility.Auto;
42+
private ScrollBarVisibility _selectedHorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
3543

3644
public IEnumerable<FloatingHintHorizontalAlignment> HorizontalAlignmentOptions { get; } = Enum.GetValues(typeof(FloatingHintHorizontalAlignment)).OfType<FloatingHintHorizontalAlignment>();
37-
public IEnumerable<double> FloatingScaleOptions { get; } = new[] {0.25, 0.5, 0.75, 1.0};
38-
public IEnumerable<Point> FloatingOffsetOptions { get; } = new[] { DefaultFloatingOffset, new Point(0, -25), new Point(16, -16), new Point(-16, -16), new Point(0, -50) };
39-
public IEnumerable<string> ComboBoxOptions { get; } = new[] {"Option 1", "Option 2", "Option 3"};
40-
public IEnumerable<Thickness> CustomPaddingOptions { get; } = new [] { new Thickness(0), new Thickness(5), new Thickness(10), new Thickness(15) };
41-
public IEnumerable<double> CustomHeightOptions { get; } = new[] { double.NaN, 50, 75, 100 };
42-
public IEnumerable<VerticalAlignment> VerticalAlignmentOptions { get; } = (VerticalAlignment[])Enum.GetValues(typeof(VerticalAlignment));
43-
public IEnumerable<double> IconSizeOptions { get; } = new[] { 10.0, 15, 20, 30, 50, 75 };
44-
public IEnumerable<double> FontSizeOptions { get; } = new[] { double.NaN, 8, 12, 16, 20, 24, 28 };
45+
public IEnumerable<double> FloatingScaleOptions { get; } = [0.25, 0.5, 0.75, 1.0];
46+
public IEnumerable<Point> FloatingOffsetOptions { get; } = [DefaultFloatingOffset, new Point(0, -25), new Point(16, -16), new Point(-16, -16), new Point(0, -50)];
47+
public IEnumerable<string> ComboBoxOptions { get; } = ["Option 1", "Option 2", "Option 3"];
48+
public IEnumerable<Thickness> CustomPaddingOptions { get; } = [new Thickness(0), new Thickness(5), new Thickness(10), new Thickness(15)];
49+
public IEnumerable<double> CustomHeightOptions { get; } = [double.NaN, 50, 75, 100, 150];
50+
public IEnumerable<VerticalAlignment> VerticalAlignmentOptions { get; } = Enum.GetValues(typeof(VerticalAlignment)).OfType<VerticalAlignment>();
51+
public IEnumerable<double> IconSizeOptions { get; } = [10.0, 15, 20, 30, 50, 75];
52+
public IEnumerable<double> FontSizeOptions { get; } = [double.NaN, 8, 12, 16, 20, 24, 28];
4553
public IEnumerable<FontFamily> FontFamilyOptions { get; } = new FontFamily[] { DefaultFontFamily }.Concat(Fonts.SystemFontFamilies.OrderBy(f => f.Source));
54+
public IEnumerable<PrefixSuffixVisibility> PrefixSuffixVisibilityOptions { get; } = Enum.GetValues(typeof(PrefixSuffixVisibility)).OfType<PrefixSuffixVisibility>();
55+
public IEnumerable<PrefixSuffixHintBehavior> PrefixSuffixHintBehaviorOptions { get; } = Enum.GetValues(typeof(PrefixSuffixHintBehavior)).OfType<PrefixSuffixHintBehavior>();
56+
public IEnumerable<ScrollBarVisibility> ScrollBarVisibilityOptions { get; } = Enum.GetValues(typeof(ScrollBarVisibility)).OfType<ScrollBarVisibility>();
4657

4758
public bool FloatHint
4859
{
@@ -140,6 +151,12 @@ public double SelectedTrailingIconSize
140151
set => SetProperty(ref _selectedTrailingIconSize, value);
141152
}
142153

154+
public VerticalAlignment SelectedIconVerticalAlignment
155+
{
156+
get => _selectedIconVerticalAlignment;
157+
set => SetProperty(ref _selectedIconVerticalAlignment, value);
158+
}
159+
143160
public string? PrefixText
144161
{
145162
get => _prefixText;
@@ -199,4 +216,46 @@ public int MaxLength
199216
}
200217
}
201218
}
219+
220+
public PrefixSuffixVisibility SelectedPrefixVisibility
221+
{
222+
get => _selectedPrefixVisibility;
223+
set => SetProperty(ref _selectedPrefixVisibility, value);
224+
}
225+
226+
public PrefixSuffixHintBehavior SelectedPrefixHintBehavior
227+
{
228+
get => _selectedPrefixHintBehavior;
229+
set => SetProperty(ref _selectedPrefixHintBehavior, value);
230+
}
231+
232+
public PrefixSuffixVisibility SelectedSuffixVisibility
233+
{
234+
get => _selectedSuffixVisibility;
235+
set => SetProperty(ref _selectedSuffixVisibility, value);
236+
}
237+
238+
public PrefixSuffixHintBehavior SelectedSuffixHintBehavior
239+
{
240+
get => _selectedSuffixHintBehavior;
241+
set => SetProperty(ref _selectedSuffixHintBehavior, value);
242+
}
243+
244+
public bool NewSpecHighlightingEnabled
245+
{
246+
get => _newSpecHighlightingEnabled;
247+
set => SetProperty(ref _newSpecHighlightingEnabled, value);
248+
}
249+
250+
public ScrollBarVisibility SelectedVerticalScrollBarVisibility
251+
{
252+
get => _selectedVerticalScrollBarVisibility;
253+
set => SetProperty(ref _selectedVerticalScrollBarVisibility, value);
254+
}
255+
256+
public ScrollBarVisibility SelectedHorizontalScrollBarVisibility
257+
{
258+
get => _selectedHorizontalScrollBarVisibility;
259+
set => SetProperty(ref _selectedHorizontalScrollBarVisibility, value);
260+
}
202261
}

MainDemo.Wpf/Properties/launchSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"profiles": {
33
"Demo App": {
44
"commandName": "Project",
5-
"commandLineArgs": "-p Home -t Inherit -f LeftToRight"
5+
"commandLineArgs": "-p \"Smart Hint\" -t Inherit -f LeftToRight"
66
}
77
}
88
}

0 commit comments

Comments
 (0)