1+ // Copyright (c) Microsoft Corporation. All rights reserved.
2+ // Licensed under the MIT License.
13#include " pch.h"
24#include " Carousel.h"
35
46using namespace AdaptiveCards ;
57
68namespace 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+
133152void 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
0 commit comments