Skip to content

Commit e7bfca5

Browse files
authored
Added Carousel To WinUI3/UWP (#8812)
* added shared model changes for Carousel * fixed formatting with clang-format * added missing files for linking * added carousel * core functionality done * adding rtl * implemented the rest of the features * chagned solid to transparency * added uwp support * clean up * fixed space
1 parent 54fa541 commit e7bfca5

33 files changed

+797
-67
lines changed

source/shared/cpp/AdaptiveCardsSharedModel/AdaptiveCardsSharedModelUnitTest/CarouselTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ namespace AdaptiveCardsSharedModelUnitTest
190190
Assert::AreEqual<std::string>(carousel->GetElementTypeString(), CardElementTypeToString(CardElementType::Carousel));
191191
Assert::AreEqual<bool>(carousel->GetAutoLoop().value(), false);
192192
Assert::AreEqual<int>(carousel->GetInitialPage().value(), static_cast<size_t>(1));
193-
Assert::AreEqual<std::string>(carousel->GetHeightInPixels(), "100px");
193+
Assert::AreEqual<int>(carousel->GetHeightInPixels(), 100);
194194
Assert::AreEqual<int>(carousel->GetTimer().value(), 5000);
195195

196196
auto carouselPage = std::dynamic_pointer_cast<CarouselPage>(carousel->GetPages()[0]);
@@ -300,7 +300,7 @@ namespace AdaptiveCardsSharedModelUnitTest
300300
Assert::AreEqual<std::string>(carousel->GetElementTypeString(), CardElementTypeToString(CardElementType::Carousel));
301301
Assert::AreEqual<bool>(carousel->GetAutoLoop().value(), false);
302302
Assert::AreEqual<int>(carousel->GetInitialPage().value(), static_cast<size_t>(1));
303-
Assert::AreEqual<std::string>(carousel->GetHeightInPixels(), "100px");
303+
Assert::AreEqual<int>(carousel->GetHeightInPixels(), 100);
304304
Assert::AreEqual<int>(carousel->GetTimer().value(), 5000);
305305

306306
auto carouselPage = std::dynamic_pointer_cast<CarouselPage>(carousel->GetPages()[0]);

source/shared/cpp/ObjectModel/Carousel.cpp

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
13
#include "pch.h"
24
#include "Carousel.h"
35

46
using namespace AdaptiveCards;
57

68
namespace AdaptiveCards
79
{
8-
Carousel::Carousel() : CollectionCoreElement(CardElementType::Carousel)
10+
Carousel::Carousel() : StyledCollectionElement(CardElementType::Carousel)
911
{
1012
PopulateKnownPropertiesSet();
1113
}
@@ -26,10 +28,12 @@ Json::Value Carousel::SerializeToJsonValue() const
2628
{
2729
Json::Value root = CollectionCoreElement::SerializeToJsonValue();
2830

29-
if (!m_heightInPixels.empty())
30-
{
31-
root[AdaptiveCardSchemaKeyToString(AdaptiveCardSchemaKey::HeightInPixels)] = m_heightInPixels;
32-
}
31+
if (m_heightInPixels)
32+
{
33+
std::ostringstream stringStream;
34+
stringStream << m_heightInPixels;
35+
root[AdaptiveCardSchemaKeyToString(AdaptiveCardSchemaKey::HeightInPixels)] = stringStream.str() + "px";
36+
}
3337

3438
if (m_initialPage.has_value())
3539
{
@@ -62,6 +66,11 @@ Json::Value Carousel::SerializeToJsonValue() const
6266
root[AdaptiveCardSchemaKeyToString(AdaptiveCardSchemaKey::Timer)] = m_timer.value_or(0);
6367
}
6468

69+
if (m_rtl.has_value())
70+
{
71+
root[AdaptiveCardSchemaKeyToString(AdaptiveCardSchemaKey::Rtl)] = m_rtl.value_or("");
72+
}
73+
6574
return root;
6675
}
6776

@@ -80,12 +89,12 @@ void Carousel::SetPages(const std::vector<std::shared_ptr<AdaptiveCards::Carouse
8089
m_pages = value;
8190
}
8291

83-
std::string Carousel::GetHeightInPixels() const
92+
unsigned int Carousel::GetHeightInPixels() const
8493
{
8594
return m_heightInPixels;
8695
}
8796

88-
void Carousel::SetHeightInPixels(const std::string& value)
97+
void Carousel::SetHeightInPixels(const unsigned int value)
8998
{
9099
m_heightInPixels = value;
91100
}
@@ -130,6 +139,16 @@ void Carousel::setAutoLoop(const std::optional<bool>& value)
130139
m_autoLoop = value;
131140
}
132141

142+
std::optional<bool> Carousel::GetRtl() const
143+
{
144+
return m_rtl;
145+
}
146+
147+
void Carousel::SetRtl(const std::optional<bool>& value)
148+
{
149+
m_rtl = value;
150+
}
151+
133152
void Carousel::DeserializeChildren(ParseContext& context, const Json::Value& value)
134153
{
135154
if (auto deserializedPages =
@@ -146,9 +165,15 @@ std::shared_ptr<BaseCardElement> CarouselParser::Deserialize(ParseContext& conte
146165

147166
context.AddProhibitedElementType(m_prohibitedTypesList);
148167

149-
std::shared_ptr<Carousel> carousel = CollectionCoreElement::Deserialize<Carousel>(context, value);
168+
std::shared_ptr<Carousel> carousel = StyledCollectionElement::Deserialize<Carousel>(context, value);
169+
170+
const auto& optionalPixelHeight =
171+
ParseSizeForPixelSize(ParseUtil::GetString(value, AdaptiveCardSchemaKey::HeightInPixels), &context.warnings);
150172

151-
carousel->SetHeightInPixels(ParseUtil::GetString(value, AdaptiveCardSchemaKey::HeightInPixels));
173+
if (optionalPixelHeight.has_value())
174+
{
175+
carousel->SetHeightInPixels(optionalPixelHeight.value_or(0));
176+
}
152177

153178
carousel->SetInitialPage(ParseUtil::GetOptionalUnsignedInt(value, AdaptiveCardSchemaKey::InitialPage));
154179

@@ -159,6 +184,10 @@ std::shared_ptr<BaseCardElement> CarouselParser::Deserialize(ParseContext& conte
159184
carousel->SetOrientation(ParseUtil::GetOptionalEnumValue<CarouselOrientation>(
160185
value, AdaptiveCardSchemaKey::Orientation, CarouselOrientationFromString));
161186

187+
carousel->SetRtl(ParseUtil::GetOptionalBool(value, AdaptiveCardSchemaKey::Rtl));
188+
189+
context.RemoveProhibitedElementType(m_prohibitedTypesList);
190+
162191
return carousel;
163192
}
164193

source/shared/cpp/ObjectModel/Carousel.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
13
#pragma once
24

35
#include "pch.h"
4-
#include "CollectionCoreElement.h"
6+
#include "StyledCollectionElement.h"
57
#include "CarouselPage.h"
68

79
namespace AdaptiveCards
810
{
9-
class Carousel : public CollectionCoreElement
11+
class Carousel : public StyledCollectionElement
1012
{
1113
public:
1214
Carousel();
@@ -23,8 +25,8 @@ class Carousel : public CollectionCoreElement
2325
const std::vector<std::shared_ptr<AdaptiveCards::CarouselPage>>& GetPages() const;
2426
void SetPages(const std::vector<std::shared_ptr<AdaptiveCards::CarouselPage>>& value);
2527

26-
std::string GetHeightInPixels() const;
27-
void SetHeightInPixels(const std::string& value);
28+
unsigned int GetHeightInPixels() const;
29+
void SetHeightInPixels(const unsigned int value);
2830

2931
std::optional<unsigned long> GetTimer() const;
3032
void SetTimer(const std::optional<unsigned long>& value);
@@ -38,15 +40,19 @@ class Carousel : public CollectionCoreElement
3840
std::optional<bool> GetAutoLoop() const;
3941
void setAutoLoop(const std::optional<bool>& value);
4042

43+
std::optional<bool> GetRtl() const;
44+
void SetRtl(const std::optional<bool>& value);
45+
4146
private:
4247
void PopulateKnownPropertiesSet();
4348

4449
std::vector<std::shared_ptr<AdaptiveCards::CarouselPage>> m_pages;
45-
std::string m_heightInPixels;
50+
unsigned int m_heightInPixels{0};
4651
std::optional<unsigned int> m_timer;
4752
std::optional<unsigned int> m_initialPage;
4853
std::optional<CarouselOrientation> m_orientation;
4954
std::optional<bool> m_autoLoop;
55+
std::optional<bool> m_rtl;
5056
};
5157

5258
class CarouselParser : public BaseCardElementParser

source/shared/cpp/ObjectModel/CarouselPage.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
13
#include "pch.h"
24
#include "CarouselPage.h"
35

source/shared/cpp/ObjectModel/CarouselPage.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
13
#pragma once
24

35
#include "Container.h"

source/shared/cpp/ObjectModel/ParseContext.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,17 @@ void ParseContext::AddProhibitedElementType(const std::vector<std::string>& list
330330
m_prohibitedElementTypes.insert(list.begin(), list.end());
331331
}
332332

333+
void ParseContext::RemoveProhibitedElementType(const std::vector<std::string>& list)
334+
{
335+
for (const auto& type : list)
336+
{
337+
if (const auto itr = m_prohibitedElementTypes.find(type); itr != m_prohibitedElementTypes.end())
338+
{
339+
m_prohibitedElementTypes.erase(itr);
340+
}
341+
}
342+
}
343+
333344
void ParseContext::ShouldParse(const std::string& typeString)
334345
{
335346
if (m_prohibitedElementTypes.find(typeString) != m_prohibitedElementTypes.end())

source/shared/cpp/ObjectModel/ParseContext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class ParseContext
4949
void PopBleedDirection();
5050

5151
void AddProhibitedElementType(const std::vector<std::string>& list);
52+
void RemoveProhibitedElementType(const std::vector<std::string>& list);
5253
void ShouldParse(const std::string& type);
5354

5455
private:

source/shared/cpp/ObjectModel/pch.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@
4444

4545
namespace AdaptiveCards
4646
{
47-
constexpr const char* const c_sharedModelVersion = "1.5";
47+
constexpr const char* const c_sharedModelVersion = "1.6";
4848
}

source/uwp/AdaptiveCardsObjectModel/idl/AdaptiveCards.ObjectModel.Uwp.idl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ namespace AdaptiveCards.ObjectModel.Uwp
6363
AdaptiveCard,
6464
TextBlock,
6565
Image,
66+
Carousel,
67+
CarouselPage,
6668
Container,
6769
Column,
6870
ColumnSet,
@@ -258,6 +260,12 @@ namespace AdaptiveCards.ObjectModel.Uwp
258260
MenuItem
259261
};
260262

263+
enum CarouselOrientation
264+
{
265+
Horizontal = 0,
266+
Vertical,
267+
};
268+
261269
declare { interface Windows.Foundation.Collections.IVector<AdaptiveRemoteResourceInformation>; }
262270

263271
interface IAdaptiveCardElement
@@ -593,6 +601,25 @@ namespace AdaptiveCards.ObjectModel.Uwp
593601
Windows.Foundation.Collections.IVector<AdaptiveColumn> Columns { get; };
594602
};
595603

604+
[default_interface] runtimeclass AdaptiveCarouselPage : IAdaptiveContainer, IAdaptiveContainerBase, IAdaptiveCardElement
605+
{
606+
AdaptiveCarouselPage();
607+
};
608+
609+
runtimeclass AdaptiveCarousel : IAdaptiveContainerBase, IAdaptiveCardElement
610+
{
611+
AdaptiveCarousel();
612+
Windows.Foundation.Collections.IVector<AdaptiveCarouselPage> Pages { get; };
613+
CarouselOrientation Orientation;
614+
Windows.Foundation.IReference<UInt64> Timer;
615+
Windows.Foundation.IReference<UInt32> InitialPage;
616+
Windows.Foundation.IReference<Boolean> AutoLoop;
617+
Windows.Foundation.IReference<VerticalContentAlignment> VerticalContentAlignment;
618+
Windows.Foundation.IReference<Boolean> Rtl;
619+
AdaptiveBackgroundImage BackgroundImage;
620+
UInt32 HeightInPixels;
621+
};
622+
596623
runtimeclass AdaptiveFact
597624
{
598625
AdaptiveFact();

source/uwp/Renderer/idl/AdaptiveCards.Rendering.Uwp.idl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,16 @@ namespace AdaptiveCards
556556
AdaptiveImageSetRenderer();
557557
}
558558

559+
[default_interface] runtimeclass AdaptiveCarouselRenderer : IAdaptiveElementRenderer
560+
{
561+
AdaptiveCarouselRenderer();
562+
}
563+
564+
[default_interface] runtimeclass AdaptiveCarouselPageRenderer : IAdaptiveElementRenderer
565+
{
566+
AdaptiveCarouselPageRenderer();
567+
}
568+
559569
[default_interface] runtimeclass AdaptiveContainerRenderer : IAdaptiveElementRenderer
560570
{
561571
AdaptiveContainerRenderer();

0 commit comments

Comments
 (0)