Skip to content

Commit

Permalink
feat: Update InfoBadge to winui3/release/1.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Nov 14, 2023
1 parent 1c4a60e commit 95292c5
Show file tree
Hide file tree
Showing 5 changed files with 296 additions and 299 deletions.
137 changes: 69 additions & 68 deletions src/Uno.UI/Microsoft/UI/Xaml/Controls/InfoBadge/InfoBadge.cs
Original file line number Diff line number Diff line change
@@ -1,108 +1,109 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
// MUX reference InfoBadge.cpp, commit 76bd573
// MUX reference InfoBadge.cpp, tag winui3/release/1.4.2

using System;
using Uno.UI.Helpers.WinUI;
using Windows.Foundation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace Microsoft.UI.Xaml.Controls
namespace Microsoft.UI.Xaml.Controls;

/// <summary>
/// Represents a control for indicating notifications, alerts, new content, or to attract focus to an area within an app.
/// </summary>
public partial class InfoBadge : Control
{
public partial class InfoBadge : Control
//private const string IconPresenterName = "IconPresenter";

/// <summary>
/// Initializes a new instance of the InfoBadge class.
/// </summary>
public InfoBadge()
{
//private const string IconPresenterName = "IconPresenter";
DefaultStyleKey = typeof(InfoBadge);

public InfoBadge()
{
DefaultStyleKey = typeof(InfoBadge);
SetValue(TemplateSettingsProperty, new InfoBadgeTemplateSettings());
SizeChanged += OnSizeChanged;
}

SetValue(TemplateSettingsProperty, new InfoBadgeTemplateSettings());
SizeChanged += OnSizeChanged;
}
protected override void OnApplyTemplate()
{
OnDisplayKindPropertiesChanged();
}

protected override void OnApplyTemplate()
protected override Size MeasureOverride(Size availableSize)
{
var defaultDesiredSize = base.MeasureOverride(availableSize);
if (defaultDesiredSize.Width < defaultDesiredSize.Height)
{
OnDisplayKindPropertiesChanged();
return new Size(defaultDesiredSize.Height, defaultDesiredSize.Height);
}
return defaultDesiredSize;
}

private void OnPropertyChanged(DependencyPropertyChangedEventArgs args)
{
var property = args.Property;
Control thisAsControl = this;

protected override Size MeasureOverride(Size availableSize)
if (property == ValueProperty)
{
var defaultDesiredSize = base.MeasureOverride(availableSize);
if (defaultDesiredSize.Width < defaultDesiredSize.Height)
if (Value < -1)
{
return new Size(defaultDesiredSize.Height, defaultDesiredSize.Height);
throw new ArgumentOutOfRangeException("Value must be equal to or greater than -1");
}
return defaultDesiredSize;
}

private void OnPropertyChanged(DependencyPropertyChangedEventArgs args)
if (property == ValueProperty || property == IconSourceProperty)
{
var property = args.Property;
Control thisAsControl = this;

if (property == ValueProperty)
{
if (Value < -1)
{
throw new ArgumentOutOfRangeException("Value must be equal to or greater than -1");
}
}

if (property == ValueProperty || property == IconSourceProperty)
{
OnDisplayKindPropertiesChanged();
}
OnDisplayKindPropertiesChanged();
}
}

void OnDisplayKindPropertiesChanged()
void OnDisplayKindPropertiesChanged()
{
Control thisAsControl = this;
if (Value >= 0)
{
Control thisAsControl = this;
if (Value >= 0)
{
VisualStateManager.GoToState(thisAsControl, "Value", true);
}
else if (IconSource is { } iconSource)
VisualStateManager.GoToState(thisAsControl, "Value", true);
}
else if (IconSource is { } iconSource)
{
TemplateSettings.IconElement = iconSource.CreateIconElement();
if (iconSource is FontIconSource)
{
TemplateSettings.IconElement = iconSource.CreateIconElement();
if (iconSource is FontIconSource)
{
VisualStateManager.GoToState(thisAsControl, "FontIcon", true);
}
else
{
VisualStateManager.GoToState(thisAsControl, "Icon", true);
}
VisualStateManager.GoToState(thisAsControl, "FontIcon", true);
}
else
{
VisualStateManager.GoToState(thisAsControl, "Dot", true);
VisualStateManager.GoToState(thisAsControl, "Icon", true);
}
}
else
{
VisualStateManager.GoToState(thisAsControl, "Dot", true);
}
}

private void OnSizeChanged(object sender, Windows.UI.Xaml.SizeChangedEventArgs args)
private void OnSizeChanged(object sender, Windows.UI.Xaml.SizeChangedEventArgs args)
{
CornerRadius GetCornerRadius()
{
CornerRadius GetCornerRadius()
var cornerRadiusValue = ActualHeight / 2;
if (ReadLocalValue(CornerRadiusProperty) == DependencyProperty.UnsetValue)
{
var cornerRadiusValue = ActualHeight / 2;
if (SharedHelpers.IsRS5OrHigher())
{
if (ReadLocalValue(CornerRadiusProperty) == DependencyProperty.UnsetValue)
{
return new CornerRadius(cornerRadiusValue, cornerRadiusValue, cornerRadiusValue, cornerRadiusValue);
}
else
{
return new CornerRadius();
}
}
return new CornerRadius(cornerRadiusValue, cornerRadiusValue, cornerRadiusValue, cornerRadiusValue);
}
else
{
return new CornerRadius();
}
//return new CornerRadius(cornerRadiusValue, cornerRadiusValue, cornerRadiusValue, cornerRadiusValue);
}

var value = GetCornerRadius();
var value = GetCornerRadius();

TemplateSettings.InfoBadgeCornerRadius = value;
}
TemplateSettings.InfoBadgeCornerRadius = value;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
// MUX reference InfoBadge.properties.cpp, commit 76bd573
// MUX reference InfoBadge.properties.cpp, tag winui3/release/1.4.2

using System;
using System.Collections.Generic;
Expand All @@ -9,43 +9,61 @@
using System.Threading.Tasks;
using Windows.UI.Xaml;

namespace Microsoft.UI.Xaml.Controls
namespace Microsoft.UI.Xaml.Controls;

public partial class InfoBadge
{
public partial class InfoBadge
/// <summary>
/// Gets or sets the integer to be displayed in a numeric InfoBadge.
/// </summary>
public int Value
{
get => (int)GetValue(ValueProperty);
set => SetValue(ValueProperty, value);
}

/// <summary>
/// Identifies the InfoBadge.Value dependency property.
/// </summary>
public static DependencyProperty ValueProperty { get; } =
DependencyProperty.Register(nameof(Value), typeof(int), typeof(InfoBadge), new FrameworkPropertyMetadata(-1, OnPropertyChanged));

/// <summary>
/// Provides calculated values that can be referenced as TemplatedParent sources when defining
/// templates for an InfoBadge. Not intended for general use.
/// </summary>
public InfoBadgeTemplateSettings TemplateSettings
{
get => (InfoBadgeTemplateSettings)GetValue(TemplateSettingsProperty);
private set => SetValue(TemplateSettingsProperty, value);
}

/// <summary>
/// Identifies the InfoBadgeTemplateSettings dependency property.
/// </summary>
public static DependencyProperty TemplateSettingsProperty { get; } =
DependencyProperty.Register(nameof(TemplateSettings), typeof(InfoBadgeTemplateSettings), typeof(InfoBadge), new FrameworkPropertyMetadata(null, OnPropertyChanged));

/// <summary>
/// Gets or sets the icon to be used in an InfoBadge.
/// </summary>
public IconSource IconSource
{
get => (IconSource)GetValue(IconSourceProperty);
set => SetValue(IconSourceProperty, value);
}

/// <summary>
/// Identifies the InfoBadge.IconSource dependency property.
/// </summary>
public static DependencyProperty IconSourceProperty { get; } =
DependencyProperty.Register(nameof(IconSource), typeof(IconSource), typeof(InfoBadge), new FrameworkPropertyMetadata(null, OnPropertyChanged));

private static void OnPropertyChanged(
DependencyObject sender,
DependencyPropertyChangedEventArgs args)
{
public int Value
{
get => (int)GetValue(ValueProperty);
set => SetValue(ValueProperty, value);
}

public static DependencyProperty ValueProperty { get; } =
DependencyProperty.Register(nameof(Value), typeof(int), typeof(InfoBadge), new FrameworkPropertyMetadata(-1, OnPropertyChanged));

public InfoBadgeTemplateSettings TemplateSettings
{
get => (InfoBadgeTemplateSettings)GetValue(TemplateSettingsProperty);
set => SetValue(TemplateSettingsProperty, value);
}

public static DependencyProperty TemplateSettingsProperty { get; } =
DependencyProperty.Register(nameof(TemplateSettings), typeof(InfoBadgeTemplateSettings), typeof(InfoBadge), new FrameworkPropertyMetadata(null, OnPropertyChanged));

public IconSource IconSource
{
get => (IconSource)GetValue(IconSourceProperty);
set => SetValue(IconSourceProperty, value);
}

public static DependencyProperty IconSourceProperty { get; } =
DependencyProperty.Register(nameof(IconSource), typeof(IconSource), typeof(InfoBadge), new FrameworkPropertyMetadata(null, OnPropertyChanged));

private static void OnPropertyChanged(
DependencyObject sender,
DependencyPropertyChangedEventArgs args)
{
var owner = (InfoBadge)sender;
owner.OnPropertyChanged(args);
}
var owner = (InfoBadge)sender;
owner.OnPropertyChanged(args);
}
}
10 changes: 3 additions & 7 deletions src/Uno.UI/Microsoft/UI/Xaml/Controls/InfoBadge/InfoBadge.xaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
<!-- Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License. See LICENSE in the project root for license information. -->
<!-- MUX reference InfoBadge.xaml, commit 76bd573 -->
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Microsoft.UI.Xaml.Controls">

<Style TargetType="local:InfoBadge" BasedOn="{StaticResource DefaultInfoBadgeStyle}"/>
<!-- MUX reference InfoBadge.xaml, tag winui3/release/1.4.2 -->
<ResourceDictionary xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="using:Microsoft.UI.Xaml.Controls" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<Style TargetType="controls:InfoBadge" BasedOn="{StaticResource DefaultInfoBadgeStyle}" />
</ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -1,34 +1,51 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.
// MUX reference InfoBadgeTemplateSettings.properties.cpp, commit 76bd573
// MUX reference InfoBadgeTemplateSettings.properties.cpp, tag winui3/release/1.4.2

using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace Microsoft.UI.Xaml.Controls
namespace Microsoft.UI.Xaml.Controls;

/// <summary>
/// Provides calculated values that can be referenced as TemplatedParent sources when defining templates for an InfoBadge.
/// </summary>
public partial class InfoBadgeTemplateSettings : DependencyObject
{
public partial class InfoBadgeTemplateSettings : DependencyObject
/// <summary>
/// Initializes a new instance of the InfoBadgeTemplateSettings class.
/// </summary>
public InfoBadgeTemplateSettings()
{
public InfoBadgeTemplateSettings()
{
}

public IconElement IconElement
{
get => (IconElement)GetValue(IconElementProperty);
set => SetValue(IconElementProperty, value);
}
}

public static DependencyProperty IconElementProperty { get; } =
DependencyProperty.Register(nameof(IconElement), typeof(IconElement), typeof(InfoBadgeTemplateSettings), new FrameworkPropertyMetadata(null));
/// <summary>
/// Gets or sets the icon element for an InfoBadge.
/// </summary>
public IconElement IconElement
{
get => (IconElement)GetValue(IconElementProperty);
set => SetValue(IconElementProperty, value);
}

public CornerRadius InfoBadgeCornerRadius
{
get => (CornerRadius)GetValue(InfoBadgeCornerRadiusProperty);
set => SetValue(InfoBadgeCornerRadiusProperty, value);
}
/// <summary>
/// Identifies the InfoBadgeTemplateSettings.IconElement dependency property.
/// </summary>
public static DependencyProperty IconElementProperty { get; } =
DependencyProperty.Register(nameof(IconElement), typeof(IconElement), typeof(InfoBadgeTemplateSettings), new FrameworkPropertyMetadata(null));

public static DependencyProperty InfoBadgeCornerRadiusProperty { get; } =
DependencyProperty.Register(nameof(InfoBadgeCornerRadius), typeof(CornerRadius), typeof(InfoBadgeTemplateSettings), new FrameworkPropertyMetadata(default(CornerRadius)));
/// <summary>
/// Gets or sets the corner radius for an InfoBadge.
/// </summary>
public CornerRadius InfoBadgeCornerRadius
{
get => (CornerRadius)GetValue(InfoBadgeCornerRadiusProperty);
set => SetValue(InfoBadgeCornerRadiusProperty, value);
}

/// <summary>
/// Identifies the InfoBadgeTemplateSettings.InfoBadgeCornerRadius dependency property.
/// </summary>
public static DependencyProperty InfoBadgeCornerRadiusProperty { get; } =
DependencyProperty.Register(nameof(InfoBadgeCornerRadius), typeof(CornerRadius), typeof(InfoBadgeTemplateSettings), new FrameworkPropertyMetadata(default(CornerRadius)));
}
Loading

0 comments on commit 95292c5

Please sign in to comment.