Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clipping of SmartHint when FloatingScale > 1 #3544

Merged
merged 3 commits into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/MainDemo.Wpf/Domain/SmartHintViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ internal class SmartHintViewModel : ViewModelBase
private Thickness _outlineStyleActiveBorderThickness = new(2);

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(0, -16), new Point(16, -16), new Point(-16, -16), new Point(0, -50)];
public IEnumerable<double> FloatingScaleOptions { get; } = [0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0];
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), new Point(-50, -50), new Point(50, -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;

namespace MaterialDesignThemes.Wpf.Converters;

public class FloatingHintClippingGridConverter : IValueConverter
{
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) =>
value switch
{
double actualWidth => new RectangleGeometry(new Rect(new Point(0, 0), new Size(actualWidth, double.MaxValue))),
_ => null
};

public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
=> throw new NotImplementedException();
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ public class FloatingHintContainerMarginConverter : IMultiValueConverter

public object? Convert(object?[]? values, Type targetType, object? parameter, CultureInfo culture)
{
if (values is [double scale, Thickness floatingMargin])
if (values is [double scale, Thickness floatingMargin, double floatingScale])
{
return floatingMargin with
{
Left = floatingMargin.Left * scale,
Top = floatingMargin.Top * scale,
Right = floatingMargin.Right * scale,
Bottom = floatingMargin.Bottom * scale,
Left = (floatingMargin.Left * scale) / floatingScale,
Top = (floatingMargin.Top * scale) / floatingScale,
Right = (floatingMargin.Right * scale) / floatingScale,
Bottom = (floatingMargin.Bottom * scale) / floatingScale
};
}
return EmptyThickness;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="clr-namespace:MaterialDesignThemes.Wpf.Converters"
xmlns:system="clr-namespace:System;assembly=mscorlib"
Expand All @@ -16,6 +16,7 @@
<converters:FloatingHintScaleTransformConverter x:Key="FloatingHintScaleTransformConverter" />
<converters:FloatingHintContainerMarginConverter x:Key="FloatingHintContainerMarginConverter" />
<converters:FloatingHintTextBlockMarginConverter x:Key="FloatingHintTextBlockMarginConverter" />
<converters:FloatingHintClippingGridConverter x:Key="FloatingHintClippingGridConverter" />
</Style.Resources>
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="HorizontalContentAlignment" Value="Left" />
Expand Down Expand Up @@ -142,8 +143,7 @@
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<wpf:ScaleHost x:Name="ScaleHost" />
<Grid x:Name="HintClippingGrid"
ClipToBounds="True">
<Grid Clip="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ActualWidth, Converter={StaticResource FloatingHintClippingGridConverter}}">
<Grid.RenderTransform>
<MultiBinding Converter="{StaticResource FloatingHintTranslateTransformConverter}">
<Binding ElementName="ScaleHost" Path="Scale" />
Expand Down Expand Up @@ -200,6 +200,7 @@
<MultiBinding Converter="{StaticResource FloatingHintContainerMarginConverter}">
<Binding ElementName="ScaleHost" Path="Scale" />
<Binding Path="FloatingMargin" RelativeSource="{RelativeSource TemplatedParent}" />
<Binding Path="FloatingScale" RelativeSource="{RelativeSource TemplatedParent}" />
</MultiBinding>
</ContentControl.Margin>
</ContentControl>
Expand Down
Loading