Skip to content

Commit

Permalink
infobar right aligned buttons (#4637)
Browse files Browse the repository at this point in the history
  • Loading branch information
ranjeshj authored Mar 25, 2021
1 parent 083796a commit d67e625
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
18 changes: 16 additions & 2 deletions dev/InfoBar/InfoBarPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,12 @@ winrt::Size InfoBarPanel::ArrangeOverride(winrt::Size const& finalSize)
const auto horizontalOrientationPadding = HorizontalOrientationPadding();
float horizontalOffset = (float)horizontalOrientationPadding.Left;
bool hasPreviousElement = false;
for (winrt::UIElement const& child : Children())

const auto children = Children();
const auto childCount = children.Size();
for (unsigned int i=0; i< childCount; i++)
{
const auto child = children.GetAt(i);
if (auto childAsFe = child.try_as<winrt::FrameworkElement>())
{
auto const desiredSize = child.DesiredSize();
Expand All @@ -131,7 +135,17 @@ winrt::Size InfoBarPanel::ArrangeOverride(winrt::Size const& finalSize)
auto horizontalMargin = winrt::InfoBarPanel::GetHorizontalOrientationMargin(child);

horizontalOffset += hasPreviousElement ? (float)horizontalMargin.Left : 0;
child.Arrange(winrt::Rect{ horizontalOffset, (float)horizontalOrientationPadding.Top + (float)horizontalMargin.Top, desiredSize.Width, desiredSize.Height });
if (i < childCount - 1)
{
child.Arrange(winrt::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(winrt::Rect{ horizontalOffset, (float)horizontalOrientationPadding.Top + (float)horizontalMargin.Top,
std::max(desiredSize.Width, finalSize.Width - horizontalOffset), desiredSize.Height });
}

horizontalOffset += desiredSize.Width + (float)horizontalMargin.Right;

hasPreviousElement = true;
Expand Down
2 changes: 2 additions & 0 deletions dev/InfoBar/TestUI/InfoBarPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
<ComboBoxItem Content="None" />
<ComboBoxItem Content="Button" />
<ComboBoxItem Content="Hyperlink" />
<ComboBoxItem Content="RightAlignedButton" />
<ComboBoxItem Content="RightAlignedHyperlink" />
</ComboBox>

<Button Content="Set Foreground" Click="SetForegroundClick"/>
Expand Down
15 changes: 15 additions & 0 deletions dev/InfoBar/TestUI/InfoBarPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ private void ActionButtonComboBox_SelectionChanged(object sender, SelectionChang
link.Content = "Informational link";
TestInfoBar.ActionButton = link;
}
else if (ActionButtonComboBox.SelectedIndex == 3)
{
var button = new Button();
button.Content = "Action";
button.HorizontalAlignment = HorizontalAlignment.Right;
TestInfoBar.ActionButton = button;
}
else if (ActionButtonComboBox.SelectedIndex == 4)
{
var link = new HyperlinkButton();
link.NavigateUri = new Uri("http://www.microsoft.com/");
link.Content = "Informational link";
link.HorizontalAlignment = HorizontalAlignment.Right;
TestInfoBar.ActionButton = link;
}
}

private void IconComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
Expand Down

0 comments on commit d67e625

Please sign in to comment.