Skip to content

Commit

Permalink
feat: Update InfoBar to latest from MUX
Browse files Browse the repository at this point in the history
feat: Update additional InfoBar files
  • Loading branch information
lukeblevins committed Jul 6, 2021
1 parent 826da94 commit 0f4fe67
Show file tree
Hide file tree
Showing 67 changed files with 2,468 additions and 392 deletions.
51 changes: 47 additions & 4 deletions src/Uno.UI/Microsoft/UI/Xaml/Controls/InfoBar/InfoBar.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MUX reference InfoBar.cpp, commit 3125489
// MUX reference InfoBar.cpp, commit 1f7779d

using Microsoft.UI.Xaml.Automation.Peers;
using Uno.UI.Helpers.WinUI;
Expand All @@ -14,13 +14,15 @@ namespace Microsoft.UI.Xaml.Controls
public partial class InfoBar : Control
{
private const string c_closeButtonName = "CloseButton";
private const string c_iconTextBlockName = "StandardIcon";
private const string c_contentRootName = "ContentRoot";

private readonly long _foregroundChangedCallbackRegistration;

private bool m_applyTemplateCalled = false;
private bool m_notifyOpen = false;
private bool m_isVisible = false;
private FrameworkElement m_standardIconTextBlock = null;
private InfoBarCloseReason m_lastCloseReason = InfoBarCloseReason.Programmatic;

public InfoBar()
Expand Down Expand Up @@ -62,6 +64,13 @@ protected override void OnApplyTemplate()
ToolTipService.SetToolTip(closeButton, tooltip);
}

var iconTextblock = GetTemplateChild<FrameworkElement>(c_iconTextBlockName);
if (iconTextblock != null)
{
m_standardIconTextBlock = iconTextblock;
AutomationProperties.SetName(iconTextblock, ResourceAccessor.GetLocalizedStringResource(GetIconSeverityLevelResourceName(Severity)));
}

var contentRootGrid = GetTemplateChild<Button>(c_contentRootName);
if (contentRootGrid != null)
{
Expand Down Expand Up @@ -166,6 +175,7 @@ private void UpdateVisibility(bool notify = true, bool force = true)
{
var notificationString = StringUtil.FormatString(
ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_InfoBarOpenedNotification),
ResourceAccessor.GetLocalizedStringResource(GetIconSeverityLevelResourceName(Severity)),
Title,
Message);

Expand Down Expand Up @@ -199,11 +209,22 @@ void UpdateSeverity()

switch (Severity)
{
case InfoBarSeverity.Success: severityState = "Success"; break;
case InfoBarSeverity.Warning: severityState = "Warning"; break;
case InfoBarSeverity.Error: severityState = "Error"; break;
case InfoBarSeverity.Success:
severityState = "Success";
break;
case InfoBarSeverity.Warning:
severityState = "Warning";
break;
case InfoBarSeverity.Error:
severityState = "Error";
break;
};

if (m_standardIconTextBlock is FrameworkElement iconTextblock)
{
AutomationProperties.SetName(iconTextblock, ResourceAccessor.GetLocalizedStringResource(GetIconSeverityLevelResourceName(Severity)));
}

VisualStateManager.GoToState(this, severityState, false);
}

Expand Down Expand Up @@ -242,5 +263,27 @@ void UpdateForeground()
// If Foreground is set, then change Title and Message Foreground to match.
VisualStateManager.GoToState(this, ReadLocalValue(Control.ForegroundProperty) == DependencyProperty.UnsetValue ? "ForegroundNotSet" : "ForegroundSet", false);
}

string GetSeverityLevelResourceName(InfoBarSeverity severity)
{
switch (severity)
{
case InfoBarSeverity.Success: return "InfoBarSeveritySuccessName";
case InfoBarSeverity.Warning: return "InfoBarSeverityWarningName";
case InfoBarSeverity.Error: return "InfoBarSeverityErrorName";
};
return "InfoBarSeverityInformationalName";
}

string GetIconSeverityLevelResourceName(InfoBarSeverity severity)
{
switch (severity)
{
case InfoBarSeverity.Success: return "InfoBarIconSeveritySuccessName";
case InfoBarSeverity.Warning: return "InfoBarIconSeverityWarningName";
case InfoBarSeverity.Error: return "InfoBarIconSeverityErrorName";
};
return "InfoBarIconSeverityInformationalName";
}
}
}
289 changes: 146 additions & 143 deletions src/Uno.UI/Microsoft/UI/Xaml/Controls/InfoBar/InfoBar.xaml

Large diffs are not rendered by default.

20 changes: 17 additions & 3 deletions src/Uno.UI/Microsoft/UI/Xaml/Controls/InfoBar/InfoBarPanel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// MUX reference InfoBarPanel.cpp, commit 533c6b1
// MUX reference InfoBarPanel.cpp, commit d67e625

using System;
using Windows.Foundation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
Expand Down Expand Up @@ -129,8 +130,12 @@ protected override Size ArrangeOverride(Size finalSize)
double horizontalOffset = horizontalOrientationPadding.Left;

bool hasPreviousElement = false;
foreach (UIElement child in Children)

var children = Children;
var childCount = (int)children.Count;
for (int i = 0; i < childCount; i++)
{
var child = children[i];
var childAsFe = child as FrameworkElement;
if (childAsFe != null)
{
Expand All @@ -140,7 +145,16 @@ protected override Size ArrangeOverride(Size finalSize)
var horizontalMargin = GetHorizontalOrientationMargin(child);

horizontalOffset += hasPreviousElement ? (float)horizontalMargin.Left : 0;
child.Arrange(new Rect(horizontalOffset, (float)horizontalOrientationPadding.Top + (float)horizontalMargin.Top, desiredSize.Width, desiredSize.Height));

if (i < childCount - 1)
{
child.Arrange(new Rect(horizontalOffset, (float)horizontalOrientationPadding.Top + (float)horizontalMargin.Top, desiredSize.Width, desiredSize.Height));
}
else
{
// Give the rest of the horizontal space to the last child.
child.Arrange(new Rect(horizontalOffset, (float)horizontalOrientationPadding.Top + (float)horizontalMargin.Top, Math.Max(desiredSize.Width, finalSize.Width - horizontalOffset), desiredSize.Height));
}
horizontalOffset += desiredSize.Width + (float)horizontalMargin.Right;

hasPreviousElement = true;
Expand Down
Loading

0 comments on commit 0f4fe67

Please sign in to comment.