Improve performance of SupplementaryResult + Modify the height of RowDltrUnits when UnitConverter is in Landscape (#249)

* Modify the height of RowDltrUnits when UnitConverter  is in LandscapeLayout mode

* clean

* Use the same layout than the existing one while fixing the issue

* Refactor SupplementaryItemsControl to improve performance, not rely on parents and not force the parent element to be HorizonAlignment="stretch"

* take feedback into account

* add HorizontalNoOverflowStackPanel to vcproj.filters

* format conditionals

* replace max by std::max
This commit is contained in:
Rudy Huyn
2019-03-26 11:24:36 -07:00
committed by Pepe Rivera
parent e9aea9237d
commit ef3f5e9cbb
11 changed files with 151 additions and 82 deletions

View File

@@ -0,0 +1,70 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
//
// HorizontalNoOverflowStackPanel.xaml.cpp
// Implementation of the HorizontalNoOverflowStackPanel class
//
#include "pch.h"
#include "HorizontalNoOverflowStackPanel.h"
using namespace std;
using namespace CalculatorApp::Controls;
using namespace Windows::Foundation;
Size HorizontalNoOverflowStackPanel::MeasureOverride(Size availableSize)
{
float maxHeight = 0;
float width = 0;
for (auto child : Children)
{
child->Measure(Size(numeric_limits<float>::infinity(), numeric_limits<float>::infinity()));
maxHeight = max(maxHeight, child->DesiredSize.Height);
width += child->DesiredSize.Width;
}
return Size(min(width, availableSize.Width), min(availableSize.Height, maxHeight));
}
bool HorizontalNoOverflowStackPanel::ShouldPrioritizeLastItem()
{
return false;
}
Size HorizontalNoOverflowStackPanel::ArrangeOverride(Size finalSize)
{
if (Children->Size == 0)
{
return finalSize;
}
float posX = 0;
auto lastChild = Children->GetAt(Children->Size - 1);
float lastChildWidth = 0;
if (Children->Size > 2 && ShouldPrioritizeLastItem())
{
lastChildWidth = lastChild->DesiredSize.Width;
}
for (auto item : Children)
{
auto widthAvailable = finalSize.Width - posX;
if (item != lastChild)
{
widthAvailable -= lastChildWidth;
}
float itemWidth = item->DesiredSize.Width;
if (widthAvailable > 0 && itemWidth <= widthAvailable)
{
//stack the items horizontally (left to right)
item->Arrange(Rect(posX, 0, itemWidth, finalSize.Height));
posX += item->RenderSize.Width;
}
else
{
//Not display the item
item->Arrange(Rect(0, 0, 0, 0));
}
}
return finalSize;
}

View File

@@ -0,0 +1,28 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
//
// HorizontalNoOverflowStackPanel.h
// Declaration of the HorizontalNoOverflowStackPanel class
//
#pragma once
#include "CalcViewModel/Common/Utils.h"
namespace CalculatorApp
{
namespace Controls
{
public ref class HorizontalNoOverflowStackPanel : public Windows::UI::Xaml::Controls::Panel
{
DEPENDENCY_PROPERTY_OWNER(HorizontalNoOverflowStackPanel);
//Prioritize the last item over all other items (except the first one)
internal:
HorizontalNoOverflowStackPanel() {}
protected:
virtual Windows::Foundation::Size MeasureOverride(Windows::Foundation::Size availableSize) override;
virtual Windows::Foundation::Size ArrangeOverride(Windows::Foundation::Size finalSize) override;
virtual bool ShouldPrioritizeLastItem();
};
}
}

View File

@@ -38,5 +38,3 @@ void SupplementaryItemsControl::PrepareContainerForItemOverride(DependencyObject
{
return ref new SupplementaryContentPresenterAP(this);
}