Skip to content

Commit

Permalink
Dialogs alert icon fix
Browse files Browse the repository at this point in the history
  • Loading branch information
flarive committed Dec 3, 2023
1 parent e974849 commit f3b6b6f
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 65 deletions.
15 changes: 15 additions & 0 deletions Avalonia.Themes.Neumorphism/Dialogs/DialogHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ public static DialogButton[] CreateSimpleDialogButtons(DialogButtonsEnum cases)
}
}

/// <summary>
/// Most common dialog template containing a title with an icon and a subtitle, then the custom content
/// </summary>
/// <param name="params"></param>
/// <returns></returns>
public static IDialogWindow<DialogResult> CreateCommonDialog(CommonDialogBuilderParams @params)
{
var window = new CommonDialog();
Expand All @@ -101,6 +106,11 @@ public static IDialogWindow<DialogResult> CreateCommonDialog(CommonDialogBuilder
return new DialogWindowBase<CommonDialog, DialogResult>(window);
}

/// <summary>
/// Dialog template for info, alert, error dialogs with a big icon, a title, a subtitle then the content
/// </summary>
/// <param name="params"></param>
/// <returns></returns>
public static IDialogWindow<DialogResult> CreateAlertDialog(AlertDialogBuilderParams @params)
{
var window = new AlertDialog();
Expand All @@ -122,6 +132,11 @@ public static IDialogWindow<DialogResult> CreateAlertDialog(AlertDialogBuilderPa
return new DialogWindowBase<AlertDialog, DialogResult>(window);
}

/// <summary>
/// Dialog template for textboxes based dialogs
/// </summary>
/// <param name="params"></param>
/// <returns></returns>
public static IDialogWindow<TextFieldDialogResult> CreateTextFieldDialog(TextFieldDialogBuilderParams @params)
{
var window = new TextFieldDialog();
Expand Down
13 changes: 13 additions & 0 deletions Avalonia.Themes.Neumorphism/Dialogs/Icons/DialogIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public static readonly StyledProperty<DialogIconKind> KindProperty
public static readonly StyledProperty<StreamGeometry> DataProperty
= AvaloniaProperty.Register<DialogIcon, StreamGeometry>(nameof(Data));

public static readonly StyledProperty<string> DataPathProperty
= AvaloniaProperty.Register<DialogIcon, string>(nameof(DataPath));

public static readonly StyledProperty<bool> UseRecommendColorProperty
= AvaloniaProperty.Register<DialogIcon, bool>(nameof(UseRecommendColor), true);
static DialogIcon()
Expand All @@ -38,6 +41,15 @@ public StreamGeometry Data
private set => SetValue(DataProperty, value);
}

/// <summary>
/// Gets the icon path data for the current <see cref="Kind"/>.
/// </summary>
public string DataPath
{
get => GetValue(DataPathProperty);
private set => SetValue(DataPathProperty, value);
}

public bool UseRecommendColor
{
get => GetValue(UseRecommendColorProperty);
Expand Down Expand Up @@ -67,6 +79,7 @@ private void UpdateData()
DialogIconsDataFactory.DataIndex.Value?.TryGetValue(Kind, out data);
var g = StreamGeometry.Parse(data);
this.Data = g;
this.DataPath = data;
}

private void UpdateColor()
Expand Down
29 changes: 25 additions & 4 deletions Avalonia.Themes.Neumorphism/Dialogs/Icons/DialogIconStyle.axaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,40 @@
<Styles xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:icons="clr-namespace:Avalonia.Themes.Neumorphism.Dialogs.Icons">
xmlns:icons="clr-namespace:Avalonia.Themes.Neumorphism.Dialogs.Icons"
xmlns:controls="clr-namespace:Avalonia.Themes.Neumorphism.Controls"
xmlns:converters="clr-namespace:Avalonia.Themes.Neumorphism.Converters"
xmlns:system="clr-namespace:System;assembly=System.Runtime">

<Style Selector="icons|DialogIcon">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Viewbox Stretch="Uniform"
ClipToBounds="False"
<!--<Viewbox Stretch="Uniform" StretchDirection="Both"
ClipToBounds="True"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch">
<Path Name="PATH_DialogIconVectorPath"
Data="{TemplateBinding Data}"
Fill="{TemplateBinding Foreground}" />
</Viewbox>
</Viewbox>-->

<controls:SkiaGeometry HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0"
Stretch="Uniform"
Path="{TemplateBinding DataPath}"
ClipToBounds="True"
Fill="{TemplateBinding Foreground}">
<!--<controls:SkiaGeometry.Resources>
<converters:CustomBoxShadowsConverter x:Key="CustomBoxShadowsConverter"/>
<system:String x:Key="BoxShadowsTemplate">-5 -5 20 {MaterialDesignShadowLight}, 5 5 20 {MaterialDesignShadowDark}</system:String>
</controls:SkiaGeometry.Resources>
<controls:SkiaGeometry.BoxShadow>
<MultiBinding Converter="{StaticResource CustomBoxShadowsConverter}">
<DynamicResource ResourceKey="BoxShadowsTemplate" />
<DynamicResource ResourceKey="MaterialDesignShadowLight" />
<DynamicResource ResourceKey="MaterialDesignShadowDark" />
</MultiBinding>
</controls:SkiaGeometry.BoxShadow>-->
</controls:SkiaGeometry>
</ControlTemplate>
</Setter.Value>
</Setter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ public static IDictionary<DialogIconKind, string> Create()
},
{
DialogIconKind.Error,
"M8.6 0.999985C10.2 1.09999 11.7 1.89999 12.8 2.99999C14.1 4.39999 14.8 6.09999 14.8 8.09999C14.8 9.69999 14.2 11.2 13.2 12.5C12.2 13.7 10.8 14.6 9.2 14.9C7.6 15.2 6 15 4.6 14.2C3.2 13.4 2.1 12.2 1.5 10.7C0.899997 9.19999 0.799997 7.49999 1.3 5.99999C1.8 4.39999 2.7 3.09999 4.1 2.19999C5.4 1.29999 7 0.899985 8.6 0.999985ZM9.1 13.9C10.4 13.6 11.6 12.9 12.5 11.8C13.3 10.7 13.8 9.39999 13.7 7.99999C13.7 6.39999 13.1 4.79999 12 3.69999C11 2.69999 9.8 2.09999 8.4 1.99999C7.1 1.89999 5.7 2.19999 4.6 2.99999C3.5 3.79999 2.7 4.89999 2.3 6.29999C1.9 7.59999 1.9 8.99999 2.5 10.3C3.1 11.6 4 12.6 5.2 13.3C6.4 14 7.8 14.2 9.1 13.9ZM7.89999 7.5L10.3 5L11 5.7L8.59999 8.2L11 10.7L10.3 11.4L7.89999 8.9L5.49999 11.4L4.79999 10.7L7.19999 8.2L4.79999 5.7L5.49999 5L7.89999 7.5Z"
"M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,2C6.47,2 2,6.47 2,12C2,17.53 6.47,22 12,22C17.53,22 22,17.53 22,12C22,6.47 17.53,2 12,2M14.59,8L12,10.59L9.41,8L8,9.41L10.59,12L8,14.59L9.41,16L12,13.41L14.59,16L16,14.59L13.41,12L16,9.41L14.59,8Z"
},
{
DialogIconKind.Success,
"M5.2900313,9.8848149 L6.0000313,9.8848149 10.559941,5.3249749 9.8499413,4.6149749 5.6500313,8.8248649 3.7301413,6.9049549 3.0201413,7.6149549 5.2900313,9.8848149 z M7.6201413,0.014999887 C9.2201413,0.11500489 10.720141,0.91500489 11.820141,2.0150049 13.120141,3.4150049 13.820141,5.1150049 13.820141,7.1150049 13.820141,8.7150049 13.220141,10.215015 12.220141,11.515015 11.220141,12.715015 9.8201413,13.615015 8.2201413,13.915015 6.6201413,14.215015 5.0201413,14.015015 3.6201413,13.215015 2.2201413,12.415015 1.1201413,11.215015 0.5201413,9.7150149 -0.079861696,8.2150049 -0.1798617,6.5150049 0.3201413,5.0150049 0.8201413,3.4150049 1.7201413,2.1150049 3.1201413,1.2150049 4.4201413,0.31500489 6.0201413,-0.085000113 7.6201413,0.014999887 z M8.1201413,12.915015 C9.4201413,12.615015 10.620141,11.915015 11.520141,10.815015 12.320141,9.7150149 12.820141,8.4150049 12.720141,7.0150049 12.720141,5.4150049 12.120141,3.8150049 11.020141,2.7150049 10.020141,1.7150049 8.8201413,1.1150049 7.4201413,1.0150049 6.1201413,0.91500489 4.7201413,1.2150049 3.6201413,2.0150049 2.5201413,2.8150049 1.7201413,3.9150049 1.3201413,5.3150049 0.9201413,6.6150049 0.9201413,8.0150049 1.5201413,9.3150149 2.1201413,10.615015 3.0201413,11.615015 4.2201413,12.315015 5.4201413,13.015015 6.8201413,13.215015 8.1201413,12.915015 z"
},
{
DialogIconKind.Warning,
"M8.44 1H7.56L1 13.26L1.44 14H14.54L14.98 13.26L8.44 1ZM2.28 13L8 2.28L13.7 13H2.28ZM7.5 6H8.5V10H7.5V6ZM7.5 11H8.5V12H7.5V11Z"
"M11,15H13V17H11V15M11,7H13V13H11V7M12,2C6.47,2 2,6.5 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M12,20A8,8 0 0,1 4,12A8,8 0 0,1 12,4A8,8 0 0,1 20,12A8,8 0 0,1 12,20Z"
},
{
DialogIconKind.Info,
"M8.56838 1.03128C10.1595 1.19039 11.6436 1.90518 12.76 3.04996C13.9763 4.28555 14.6955 5.92552 14.7803 7.65726C14.8651 9.38899 14.3098 11.0913 13.2201 12.4398C12.2178 13.6857 10.8113 14.5416 9.24429 14.8594C7.67727 15.1772 6.04844 14.9369 4.64004 14.18C3.22861 13.4066 2.12677 12.1706 1.52004 10.68C0.910598 9.18166 0.829469 7.52043 1.29003 5.96988C1.7496 4.42537 2.72797 3.0868 4.06002 2.17996C5.38101 1.27892 6.97729 0.87217 8.56838 1.03128ZM9.04006 13.8799C10.3829 13.6075 11.5887 12.8756 12.45 11.81C13.3826 10.6509 13.8571 9.18961 13.7834 7.70376C13.7097 6.21792 13.0928 4.81093 12.05 3.74991C11.0949 2.77492 9.82747 2.16667 8.46932 2.0314C7.11117 1.89613 5.74869 2.24247 4.62002 3.00992C3.77045 3.59531 3.08444 4.38792 2.62691 5.31265C2.16939 6.23738 1.95553 7.26359 2.00561 8.2941C2.05568 9.3246 2.36803 10.3253 2.91305 11.2013C3.45807 12.0773 4.2177 12.7997 5.12002 13.3C6.31834 13.9467 7.7058 14.1519 9.04006 13.8799ZM8.51002 6.99997L7.51002 6.99997L7.51002 11L8.51002 11L8.51002 6.99997ZM8.51002 4.99997L7.51002 4.99997L7.51002 5.99997L8.51002 5.99997L8.51002 4.99997Z"
"M11,9H13V7H11M12,20C7.59,20 4,16.41 4,12C4,7.59 7.59,4 12,4C16.41,4 20,7.59 20,12C20,16.41 16.41,20 12,20M12,2A10,10 0 0,0 2,12A10,10 0 0,0 12,22A10,10 0 0,0 22,12A10,10 0 0,0 12,2M11,17H13V11H11V17Z"
},
{
DialogIconKind.Help,
Expand All @@ -67,7 +67,7 @@ public static IDictionary<DialogIconKind, string> CreateColor()
return new Dictionary<DialogIconKind, string>()
{
{DialogIconKind.Blocked, "#C5C5C5"},
{DialogIconKind.Error, "#F48771"},
{DialogIconKind.Error, "#E71F53"},
{DialogIconKind.Success, "#89D185"},
{DialogIconKind.Warning, "#FFCC00"},
{DialogIconKind.Info, "#75BEFF"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<DataTemplate DataType="icons:DialogIconViewModel" x:Key="DialogIcon">
<icons1:DialogIcon Kind="{CompiledBinding Kind}"/>
</DataTemplate>

<DataTemplate DataType="icons:ImageIconViewModel" x:Key="DialogImageIcon">
<Image Source="{CompiledBinding Bitmap}" Stretch="{CompiledBinding Stretch}"/>
</DataTemplate>
Expand Down
46 changes: 23 additions & 23 deletions Avalonia.Themes.Neumorphism/Dialogs/Styles/AlertDialogControl.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
</ResourceDictionary>
</Styles.Resources>

<Style Selector="controls|AlertDialogControl" x:DataType="viewModels:DialogWindowViewModel" >


<Style Selector="controls|AlertDialogControl" x:DataType="viewModels:AlertDialogViewModel">
<Setter Property="CornerRadius" Value="20"/>
<Setter Property="Template">
<ControlTemplate>
<Border Name="PART_RootBorder" CornerRadius="{TemplateBinding CornerRadius}" BorderBrush="Red" BorderThickness="2" Background="{DynamicResource MaterialDesignPaper}">
<Border Name="PART_RootBorder" CornerRadius="{TemplateBinding CornerRadius}" Background="{DynamicResource MaterialDesignPaper}">
<Border.BoxShadow>
<MultiBinding Converter="{StaticResource AutoBoxShadowsConverter}" ConverterParameter="0">
<Binding Path="Height" RelativeSource="{RelativeSource TemplatedParent}"/>
Expand All @@ -27,17 +29,27 @@
</Border.BoxShadow>
<DockPanel Name="PART_RootPanel"
Width="{CompiledBinding Width}"
MaxWidth="{CompiledBinding MaxWidth}" >
MaxWidth="{CompiledBinding MaxWidth}">

<DockPanel Name="{x:Static naming:PartNames.PartHeaderPanel}">
<ContentPresenter Name="{x:Static naming:PartNames.PartHeaderIcon}" Width="128" Height="128"

<Button Theme="{StaticResource ButtonIcon}" Width="90" Height="90" IsHitTestVisible="False" HorizontalContentAlignment="Center" VerticalContentAlignment="Center">
<ContentPresenter Name="{x:Static naming:PartNames.PartHeaderIcon}"
Content="{CompiledBinding DialogIcon}"
ContentTemplate="{StaticResource DialogHeaderIconTemplate}"
IsVisible="{CompiledBinding !!DialogIcon}" />
IsVisible="{CompiledBinding !!DialogIcon}"/>
</Button>

<StackPanel Orientation="Vertical">
<TextBlock Name="{x:Static naming:PartNames.PartHeaderText}" Foreground="{DynamicResource MaterialDesignDarkGray}"
Classes="Headline6"
Classes="Headline5" Margin="20,15,0,0" TextWrapping="Wrap"
IsVisible="{CompiledBinding !!ContentHeader.Length}"
Text="{CompiledBinding ContentHeader, FallbackValue='DIALOG_HEADER_NULL'}" />
Text="{CompiledBinding ContentHeader}" />

<ContentPresenter Name="PART_ContentPresenter" Margin="20,10,0,0" TextWrapping="Wrap"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}" />
</StackPanel>
</DockPanel>

<DockPanel Name="{x:Static naming:PartNames.PartButtonsPanel}">
Expand All @@ -59,18 +71,12 @@
ItemTemplate="{StaticResource DialogButtonTemplate}"
ItemsPanel="{StaticResource DialogButtonPlacementPanel}" />
</DockPanel>

<ContentPresenter Name="PART_ContentPresenter"
DockPanel.Dock="Left"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}" />
</DockPanel>
</Border>
</ControlTemplate>
</Setter>
</Style>

<!--??????????????????????-->
<Style Selector="controls|AlertDialogControl[CornerRadius=0] /template/ Border#PART_RootBorder">
<Setter Property="CornerRadius" Value="{TemplateBinding Height, Converter={StaticResource ControlHeightToCornerRadiusConverter}, ConverterParameter=0}"/>
</Style>
Expand All @@ -88,9 +94,9 @@
</Style>

<Style Selector="controls|AlertDialogControl /template/ ContentPresenter#PART_HeaderIcon">
<Setter Property="Width" Value="32"/>
<Setter Property="Height" Value="32"/>
<Setter Property="Margin" Value="0,0,8,0"/>
<Setter Property="Width" Value="68"/>
<Setter Property="Height" Value="68"/>
<Setter Property="Margin" Value="0"/>
</Style>

<Style Selector="controls|AlertDialogControl /template/ TextBlock#PART_HeaderText">
Expand Down Expand Up @@ -121,16 +127,10 @@


<Style Selector="controls|AlertDialogControl > ScrollViewer#PART_ScrollViewer > StackPanel#PART_ContentPanel > TextBlock#PART_SupportingText">
<Setter Property="Margin" Value="24,0"/>
<Setter Property="Margin" Value="0"/>
<Setter Property="TextWrapping" Value="Wrap"/>
</Style>

<!-- For TextField dialog -->
<Style Selector="controls|AlertDialogControl > ScrollViewer#PART_ScrollViewer > StackPanel#PART_ContentPanel > ItemsControl#PART_TextFields">
<Setter Property="Margin" Value="24,4"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
</Style>

<!-- Origin contribution by dojo90
https://github.com/AvaloniaCommunity/Material.Avalonia/pull/147 -->
<Style Selector="controls|AlertDialogControl > ScrollViewer#PART_ScrollViewer > StackPanel#PART_ContentPanel > ItemsControl#PART_TextFields ItemsPresenter">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns:viewModels="clr-namespace:Avalonia.Themes.Neumorphism.Dialogs.ViewModels" >

<StyleInclude Source="avares://Avalonia.Themes.Neumorphism/Dialogs/Styles/EmbeddedDialogControl.axaml"/>
<StyleInclude Source="avares://Avalonia.Themes.Neumorphism/Dialogs/Styles/AlertDialogControl.axaml"/>
<StyleInclude Source="avares://Avalonia.Themes.Neumorphism/Dialogs/Styles/CustomDialogControl.axaml"/>

<Style Selector="Window" x:DataType="viewModels:DialogWindowViewModel">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
</Setter>
</Style>

<!--??????????????????????-->
<Style Selector="controls|EmbeddedDialogControl[CornerRadius=0] /template/ Border#PART_RootBorder">
<Setter Property="CornerRadius" Value="{TemplateBinding Height, Converter={StaticResource ControlHeightToCornerRadiusConverter}, ConverterParameter=0}"/>
</Style>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
<Setter Property="TransparencyLevelHint" Value="Transparent" />
</Style>

<Style Selector="Window[SystemDecorations=Full] controls|EmbeddedDialogControl /template/ Border#PART_RootBorder">
<Style Selector="Window[SystemDecorations=Full] controls|EmbeddedDialogControl /template/ Border#PART_RootBorder,
Window[SystemDecorations=Full] controls|AlertDialogControl /template/ Border#PART_RootBorder,
Window[SystemDecorations=Full] controls|CustomDialogControl /template/ Border#PART_RootBorder">
<Setter Property="assist:ShadowAssist.ShadowDepth" Value="Depth0"/>
<Setter Property="CornerRadius" Value="0"/>
<Setter Property="Margin" Value="0"/>
Expand Down
14 changes: 6 additions & 8 deletions Avalonia.Themes.Neumorphism/Dialogs/Views/AlertDialog.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@
<StyleInclude Source="avares://Avalonia.Themes.Neumorphism/Dialogs/Icons/DialogIconStyle.axaml" />
</Window.Styles>

<controls:EmbeddedDialogControl>
<ScrollViewer Name="PART_ScrollView" Padding="24, 0">
<StackPanel Name="PART_ContentPanel">
<TextBlock Name="PART_SupportingText" Foreground="{DynamicResource MaterialDesignMediumGray}"
<controls:AlertDialogControl>
<StackPanel Name="PART_ContentPanel">
<TextBlock Name="PART_SupportingText" Foreground="{DynamicResource MaterialDesignMediumGray}"
Classes="Body1"
IsVisible="{CompiledBinding !!ContentMessage.Length}"
Text="{CompiledBinding ContentMessage, FallbackValue='DIALOG_SUPPORTING_TEXT'}"/>
</StackPanel>
</ScrollViewer>
</controls:EmbeddedDialogControl>
Text="{CompiledBinding ContentMessage}"/>
</StackPanel>
</controls:AlertDialogControl>
</Window>
Loading

0 comments on commit f3b6b6f

Please sign in to comment.