Skip to content

Commit

Permalink
Post SmartHint adoption cleanup (#3540)
Browse files Browse the repository at this point in the history
* Replicate TextBox style in AutoSuggestBox template

* Remove unused constants

* Drop default HintOffset to (0,0)

The HintOffset is now only used if explicitly set to a value other than the default; thus a default of (0,0) seems appropriate.

* Obsolete not needed assist classes

* Obsolete/delete unused converters

* Add delay to AutoSuggestBox test to make it less fragile.

* Ensure SUT is displayed in the middle of the window.
Filling the height of the host window is problematic when a Popup needs to be shown below the control. This causes the window to increase in size and does not really imitate real life usage.
  • Loading branch information
nicolaihenriksen authored Apr 26, 2024
1 parent a47b242 commit 93784df
Show file tree
Hide file tree
Showing 25 changed files with 410 additions and 509 deletions.
1 change: 0 additions & 1 deletion MainDemo.Wpf/ComboBoxes.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@
</smtx:XamlDisplay>
<smtx:XamlDisplay UniqueKey="comboboxes_8">
<ComboBox MinWidth="72"
materialDesign:HintAssist.FloatingOffset="0, -24"
materialDesign:HintAssist.FloatingScale="1.5"
materialDesign:HintAssist.Hint="(large float hint)"
ItemsSource="{Binding LongIntegerList}"
Expand Down
4 changes: 2 additions & 2 deletions MainDemo.Wpf/Domain/SmartHintViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace MaterialDesignDemo.Domain;

internal class SmartHintViewModel : ViewModelBase
{
public static Point DefaultFloatingOffset { get; } = new(0, -16);
public static Point DefaultFloatingOffset { get; } = new(0, 0);
public static FontFamily DefaultFontFamily = (FontFamily)new MaterialDesignFontExtension().ProvideValue(null!);

private bool _floatHint = true;
Expand Down Expand Up @@ -46,7 +46,7 @@ internal class SmartHintViewModel : ViewModelBase

public IEnumerable<FloatingHintHorizontalAlignment> HorizontalAlignmentOptions { get; } = Enum.GetValues(typeof(FloatingHintHorizontalAlignment)).OfType<FloatingHintHorizontalAlignment>();
public IEnumerable<double> FloatingScaleOptions { get; } = [0.25, 0.5, 0.75, 1.0];
public IEnumerable<Point> FloatingOffsetOptions { get; } = [DefaultFloatingOffset, new Point(0, -25), new Point(16, -16), new Point(-16, -16), new Point(0, -50)];
public IEnumerable<Point> FloatingOffsetOptions { get; } = [DefaultFloatingOffset, new Point(0, -25), new Point(0, -16), new Point(16, -16), new Point(-16, -16), new Point(0, -50)];
public IEnumerable<string> ComboBoxOptions { get; } = ["Option 1", "Option 2", "Option 3"];
public IEnumerable<Thickness> CustomPaddingOptions { get; } = [new Thickness(0), new Thickness(5), new Thickness(10), new Thickness(15)];
public IEnumerable<double> CustomHeightOptions { get; } = [double.NaN, 50, 75, 100, 150];
Expand Down
13 changes: 5 additions & 8 deletions MainDemo.Wpf/Pickers.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,7 @@
HorizontalAlignment="Left"
UniqueKey="pickers_unchanging_borderthickness">
<DatePicker Width="140"
materialDesign:DatePickerAssist.OutlinedBorderInactiveThickness="2"
materialDesign:HintAssist.FloatingOffset="0,-22"
BorderThickness="2"
materialDesign:HintAssist.HelperText="Helper text"
materialDesign:HintAssist.Hint="Pick Date"
Style="{StaticResource MaterialDesignOutlinedDatePicker}" />
Expand All @@ -184,9 +183,8 @@
HorizontalAlignment="Left"
UniqueKey="pickers_14_custom_borderthickness">
<DatePicker Width="140"
materialDesign:DatePickerAssist.OutlinedBorderActiveThickness="3"
materialDesign:DatePickerAssist.OutlinedBorderInactiveThickness="3"
materialDesign:HintAssist.FloatingOffset="0,-23"
materialDesign:TextFieldAssist.OutlinedBorderActiveThickness="3"
BorderThickness="3"
materialDesign:HintAssist.HelperText="Helper text"
materialDesign:HintAssist.Hint="Pick Date"
Style="{StaticResource MaterialDesignOutlinedDatePicker}" />
Expand All @@ -206,11 +204,10 @@
HorizontalAlignment="Left"
UniqueKey="pickers_time_custom_borderthickness">
<materialDesign:TimePicker Width="140"
materialDesign:HintAssist.FloatingOffset="0,-23"
materialDesign:HintAssist.HelperText="Helper text"
materialDesign:HintAssist.Hint="Pick Time"
materialDesign:TimePickerAssist.OutlinedBorderActiveThickness="3"
materialDesign:TimePickerAssist.OutlinedBorderInactiveThickness="3"
materialDesign:TextFieldAssist.OutlinedBorderActiveThickness="3"
BorderThickness="3"
Is24Hours="True"
Style="{StaticResource MaterialDesignOutlinedTimePicker}" />
</smtx:XamlDisplay>
Expand Down
1 change: 0 additions & 1 deletion MaterialDesign3.Demo.Wpf/ComboBoxes.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@
</smtx:XamlDisplay>
<smtx:XamlDisplay UniqueKey="comboboxes_8">
<ComboBox MinWidth="72"
materialDesign:HintAssist.FloatingOffset="0, -24"
materialDesign:HintAssist.FloatingScale="1.5"
materialDesign:HintAssist.Hint="(large float hint)"
ItemsSource="{Binding LongListToTestComboVirtualization}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ await Wait.For(async () =>
var bananas = await suggestionListBox.GetElement<ListBoxItem>("/ListBoxItem[0]");
await bananas.MoveCursorTo();
await bananas.LeftClick();

// Wait for the text to be updated
await Task.Delay(50);

var suggestBoxText = await suggestBox.GetText();
//Validate that the current text is the same as the selected item
Assert.Equal("Bananas", suggestBoxText);
Expand Down
6 changes: 4 additions & 2 deletions MaterialDesignThemes.UITests/XamlTestExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,11 @@ public static async Task<IVisualElement> CreateWindowWithUserControl(this IApp a
Title=""Test Window""
Topmost=""False""
WindowStartupLocation=""CenterScreen"">
<local:{userControlType.Name} />
<Grid>
<local:{userControlType.Name} x:Name=""Container"" VerticalAlignment=""Center"" />
</Grid>
</Window>";
IWindow window = await app.CreateWindow(windowXaml);
return await window.GetElement(".Content.Content");
return await window.GetElement("Container.Content");
}
}
16 changes: 1 addition & 15 deletions MaterialDesignThemes.Wpf/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,13 @@ public static class Constants
{
public static readonly Thickness TextBoxDefaultPadding = new(0, 4, 0, 4);
public static readonly Thickness FloatingTextBoxDefaultPadding = new(0, 12, 0, 4);
public static readonly Thickness FilledTextBoxDefaultPadding = new(16, 8, 12, 8);
public static readonly Thickness FilledTextBoxDefaultPadding = new(16, 16, 12, 8);
public static readonly Thickness OutlinedTextBoxDefaultPadding = new(16, 16, 12, 16);
public static readonly Thickness DefaultTextBoxViewMargin = new(1, 0, 1, 0);
public static readonly Thickness DefaultTextBoxViewMarginStretch = new(1, 18, 1, 0);
public static readonly Thickness DefaultTextBoxViewMarginEmbedded = new(0);
public static readonly Thickness DefaultOutlinedBorderInactiveThickness = new(1);
public static readonly Thickness DefaultOutlinedBorderActiveThickness = new(2);
public const double TextBoxNotEnabledOpacity = 0.56;
public const double TextBoxInnerButtonSpacing = 2;
public const double ComboBoxArrowSize = 8;

/// <summary>
/// Contains temporary constants needed until all styles leveraging SmartHint adopt the new approach.
/// At that point, they should all use the constants above, the values should be changed to the ones in this class,
/// and the class can be deleted.
///
/// NOTE: XAML bindings only work on public properties/fields, so to make these fields "internal", wrapping them
/// in an internal class is an acceptable compromise.
/// </summary>
internal static class TemporaryConstants
{
public static readonly Thickness FilledTextBoxDefaultPaddingNew = new(16, 16, 12, 8);
}
}
21 changes: 0 additions & 21 deletions MaterialDesignThemes.Wpf/Converters/DoubleToThicknessConverter.cs

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

namespace MaterialDesignThemes.Wpf.Converters;

/* TODO: Should be obsoleted when both TimePicker and DatePicker have adopted the new SmartHint. */
//[Obsolete("This class is obsolete and will be removed in a future version. Please use the more generic-named OutlinedStyleActiveBorderMarginCompensationConverter instead.")]
[Obsolete("This class is obsolete and will be removed in a future version. Please use the more generic-named OutlinedStyleActiveBorderMarginCompensationConverter instead.")]
public class OutlinedDateTimePickerActiveBorderThicknessConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace MaterialDesignThemes.Wpf.Converters;

[Obsolete("This class is obsolete and will be removed in a future version.")]
public class OutlinedStyleFloatingHintBackgroundConverter : IMultiValueConverter
{
public object? Convert(object[]? values, Type targetType, object? parameter, CultureInfo culture)
Expand Down
37 changes: 0 additions & 37 deletions MaterialDesignThemes.Wpf/Converters/SizeToRectConverter.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace MaterialDesignThemes.Wpf.Converters;

[Obsolete("This class is obsolete and will be removed in a future version.")]
public class TimeToVisibilityConverter : MarkupExtension, IValueConverter
{
public override object ProvideValue(IServiceProvider serviceProvider)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace MaterialDesignThemes.Wpf.Converters;

// TODO: This converter can be obsoleted/deleted when the new SmartHint approach from TextBox style is applied throughout.
[Obsolete("This class is obsolete and will be removed in a future version.")]
public class VerticalAlignmentConverter : IValueConverter
{
public VerticalAlignment StretchReplacement { get; set; } = VerticalAlignment.Top;
Expand Down
3 changes: 1 addition & 2 deletions MaterialDesignThemes.Wpf/DatePickerAssist.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace MaterialDesignThemes.Wpf;

/* TODO: We should obsolete this class in favor of the TextBoxAssist equivalents. */
//[Obsolete("This class is obsolete and will be removed in a future version. Please use the TextBoxAssist equivalents instead. For OutlinedBorderInactiveThickness, simply use BorderThickness property instead.")]
[Obsolete("This class is obsolete and will be removed in a future version. Please use the TextBoxAssist equivalents instead. For OutlinedBorderInactiveThickness, simply use BorderThickness property instead.")]
public static class DatePickerAssist
{
public static readonly DependencyProperty OutlinedBorderInactiveThicknessProperty = DependencyProperty.RegisterAttached(
Expand Down
2 changes: 1 addition & 1 deletion MaterialDesignThemes.Wpf/HintAssist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public static class HintAssist
{
private const double DefaultFloatingScale = 0.74;
private const double DefaultHintOpacity = 0.56;
internal static readonly Point DefaultFloatingOffset = new(0, -16);
internal static readonly Point DefaultFloatingOffset = new(0, 0);
internal static readonly Brush DefaultBackground = new SolidColorBrush(Colors.Transparent);
private static readonly double DefaultHelperTextFontSize = 10;

Expand Down
2 changes: 1 addition & 1 deletion MaterialDesignThemes.Wpf/SmartHint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public double FloatingScale
}

public static readonly DependencyProperty FloatingOffsetProperty = DependencyProperty.Register(
nameof(FloatingOffset), typeof(Point), typeof(SmartHint), new PropertyMetadata(new Point(1, -16)));
nameof(FloatingOffset), typeof(Point), typeof(SmartHint), new PropertyMetadata(HintAssist.DefaultFloatingOffset));

public Point FloatingOffset
{
Expand Down
Loading

0 comments on commit 93784df

Please sign in to comment.