Skip to content

Commit

Permalink
[UWP] Fix AdaptiveColumn width (#3340)
Browse files Browse the repository at this point in the history
With change fee0c03, pixel width and string width in the shared model are now
last-writer-wins. Update `AdaptiveColumn::GetSharedModel()` to account for that.

Fixes #3339.
  • Loading branch information
paulcam206 authored and shalinijoshi19 committed Sep 24, 2019
1 parent a05742b commit fa72e34
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#include "stdafx.h"
#include "Column.h"

using namespace std::string_literals;

using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace AdaptiveCards;

namespace AdaptiveCardsSharedModelUnitTest
{
TEST_CLASS(ElementTest)
{
public:
TEST_METHOD(ColumnPixelWidthTest)
{
auto columnTest = std::make_shared<AdaptiveCards::Column>();
Assert::AreEqual(0, columnTest->GetPixelWidth());
Assert::AreEqual("Auto"s, columnTest->GetWidth());
Assert::AreEqual("{\"items\":[],\"type\":\"Column\",\"width\":\"Auto\"}\n"s, columnTest->Serialize());

columnTest->SetWidth("20px"s);
Assert::AreEqual(20, columnTest->GetPixelWidth());
Assert::AreEqual("20px"s, columnTest->GetWidth());
Assert::AreEqual("{\"items\":[],\"type\":\"Column\",\"width\":\"20px\"}\n"s, columnTest->Serialize());

columnTest->SetPixelWidth(40);
Assert::AreEqual(40, columnTest->GetPixelWidth());
Assert::AreEqual("40px"s, columnTest->GetWidth());
Assert::AreEqual("{\"items\":[],\"type\":\"Column\",\"width\":\"40px\"}\n"s, columnTest->Serialize());

columnTest->SetWidth("Stretch");
Assert::AreEqual(0, columnTest->GetPixelWidth());
Assert::AreEqual("stretch"s, columnTest->GetWidth());
Assert::AreEqual("{\"items\":[],\"type\":\"Column\",\"width\":\"stretch\"}\n"s, columnTest->Serialize());
}
};
}
12 changes: 10 additions & 2 deletions source/uwp/Renderer/lib/AdaptiveColumn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,16 @@ namespace AdaptiveNamespace

column->SetStyle(static_cast<AdaptiveSharedNamespace::ContainerStyle>(m_style));
column->SetVerticalContentAlignment(static_cast<AdaptiveSharedNamespace::VerticalContentAlignment>(m_verticalAlignment));
column->SetWidth(HStringToUTF8(m_width.Get()));
column->SetPixelWidth(m_pixelWidth);

if (m_pixelWidth)
{
column->SetPixelWidth(m_pixelWidth);
}
else
{
column->SetWidth(HStringToUTF8(m_width.Get()));
}

column->SetMinHeight(m_minHeight);
column->SetBleed(m_bleed);

Expand Down

0 comments on commit fa72e34

Please sign in to comment.