Skip to content

Commit

Permalink
[Shared] Reflect changes between width and pixel width (#3317)
Browse files Browse the repository at this point in the history
Fixes #3228
  • Loading branch information
paulcam206 authored and almedina-ms committed Sep 24, 2019
1 parent 01c3371 commit b62acac
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 11 deletions.
29 changes: 28 additions & 1 deletion source/android/adaptivecards/src/main/cpp/objectmodel_wrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13774,7 +13774,7 @@ SWIGEXPORT jstring JNICALL Java_io_adaptivecards_objectmodel_AdaptiveCardObjectM
}


SWIGEXPORT void JNICALL Java_io_adaptivecards_objectmodel_AdaptiveCardObjectModelJNI_Column_1SetWidth(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jstring jarg2) {
SWIGEXPORT void JNICALL Java_io_adaptivecards_objectmodel_AdaptiveCardObjectModelJNI_Column_1SetWidth_1_1SWIG_10(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jstring jarg2) {
AdaptiveCards::Column *arg1 = (AdaptiveCards::Column *) 0 ;
std::string *arg2 = 0 ;
std::shared_ptr< AdaptiveCards::Column > *smartarg1 = 0 ;
Expand All @@ -13798,6 +13798,33 @@ SWIGEXPORT void JNICALL Java_io_adaptivecards_objectmodel_AdaptiveCardObjectMode
}


SWIGEXPORT void JNICALL Java_io_adaptivecards_objectmodel_AdaptiveCardObjectModelJNI_Column_1SetWidth_1_1SWIG_11(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_, jstring jarg2, jlong jarg3, jobject jarg3_) {
AdaptiveCards::Column *arg1 = (AdaptiveCards::Column *) 0 ;
std::string *arg2 = 0 ;
std::vector< std::shared_ptr< AdaptiveCards::AdaptiveCardParseWarning > > *arg3 = (std::vector< std::shared_ptr< AdaptiveCards::AdaptiveCardParseWarning > > *) 0 ;
std::shared_ptr< AdaptiveCards::Column > *smartarg1 = 0 ;

(void)jenv;
(void)jcls;
(void)jarg1_;
(void)jarg3_;

smartarg1 = *(std::shared_ptr< AdaptiveCards::Column > **)&jarg1;
arg1 = (AdaptiveCards::Column *)(smartarg1 ? smartarg1->get() : 0);
if(!jarg2) {
SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null string");
return ;
}
const char *arg2_pstr = (const char *)jenv->GetStringUTFChars(jarg2, 0);
if (!arg2_pstr) return ;
std::string arg2_str(arg2_pstr);
arg2 = &arg2_str;
jenv->ReleaseStringUTFChars(jarg2, arg2_pstr);
arg3 = *(std::vector< std::shared_ptr< AdaptiveCards::AdaptiveCardParseWarning > > **)&jarg3;
(arg1)->SetWidth((std::string const &)*arg2,arg3);
}


SWIGEXPORT jint JNICALL Java_io_adaptivecards_objectmodel_AdaptiveCardObjectModelJNI_Column_1GetPixelWidth(JNIEnv *jenv, jclass jcls, jlong jarg1, jobject jarg1_) {
jint jresult = 0 ;
AdaptiveCards::Column *arg1 = (AdaptiveCards::Column *) 0 ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,8 @@ public class AdaptiveCardObjectModelJNI {
public final static native long Column_SerializeToJsonValue(long jarg1, Column jarg1_);
public final static native void Column_DeserializeChildren(long jarg1, Column jarg1_, long jarg2, ParseContext jarg2_, long jarg3, JsonValue jarg3_);
public final static native String Column_GetWidth(long jarg1, Column jarg1_);
public final static native void Column_SetWidth(long jarg1, Column jarg1_, String jarg2);
public final static native void Column_SetWidth__SWIG_0(long jarg1, Column jarg1_, String jarg2);
public final static native void Column_SetWidth__SWIG_1(long jarg1, Column jarg1_, String jarg2, long jarg3, AdaptiveCardParseWarningVector jarg3_);
public final static native int Column_GetPixelWidth(long jarg1, Column jarg1_);
public final static native void Column_SetPixelWidth(long jarg1, Column jarg1_, int jarg2);
public final static native long Column_GetItems__SWIG_0(long jarg1, Column jarg1_);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ public String GetWidth() {
}

public void SetWidth(String value) {
AdaptiveCardObjectModelJNI.Column_SetWidth(swigCPtr, this, value);
AdaptiveCardObjectModelJNI.Column_SetWidth__SWIG_0(swigCPtr, this, value);
}

public void SetWidth(String value, AdaptiveCardParseWarningVector warnings) {
AdaptiveCardObjectModelJNI.Column_SetWidth__SWIG_1(swigCPtr, this, value, AdaptiveCardParseWarningVector.getCPtr(warnings), warnings);
}

public int GetPixelWidth() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
<ClCompile Include="AdditionalPropertiesTest.cpp" />
<ClCompile Include="Base64Test.cpp" />
<ClCompile Include="ContainerStyleTest.cpp" />
<ClCompile Include="ElementTest.cpp" />
<ClCompile Include="FallbackTests.cpp" />
<ClCompile Include="UnsupportedtypesParsingTest.cpp" />
<ClCompile Include="EnumTest.cpp" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,8 @@
<ClCompile Include="FallbackTests.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="ElementTest.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace AdaptiveCardsSharedModelUnitTest
auto columnTest = std::make_shared<AdaptiveCards::Column>();
Assert::AreEqual(0, columnTest->GetPixelWidth());
Assert::AreEqual("Auto"s, columnTest->GetWidth());
<<<<<<< HEAD
Assert::AreEqual("{\"items\":[],\"type\":\"Column\",\"width\":\"Auto\"}\n"s, columnTest->Serialize());

columnTest->SetWidth("20px"s);
Expand All @@ -34,6 +35,14 @@ namespace AdaptiveCardsSharedModelUnitTest
Assert::AreEqual(0, columnTest->GetPixelWidth());
Assert::AreEqual("stretch"s, columnTest->GetWidth());
Assert::AreEqual("{\"items\":[],\"type\":\"Column\",\"width\":\"stretch\"}\n"s, columnTest->Serialize());
=======
columnTest->SetWidth("20px"s);
Assert::AreEqual(20, columnTest->GetPixelWidth());
Assert::AreEqual("20px"s, columnTest->GetWidth());
columnTest->SetPixelWidth(40);
Assert::AreEqual(40, columnTest->GetPixelWidth());
Assert::AreEqual("40px"s, columnTest->GetWidth());
>>>>>>> fee0c0319... [Shared] Reflect changes between width and pixel width (#3317)
}
};
}
10 changes: 5 additions & 5 deletions source/shared/cpp/ObjectModel/Column.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ void Column::SetWidth(const std::string& value,
std::vector<std::shared_ptr<AdaptiveSharedNamespace::AdaptiveCardParseWarning>>* warnings)
{
m_width = ParseUtil::ToLowercase(value);
const int parsedDimension = ParseSizeForPixelSize(m_width, warnings);
SetPixelWidth(parsedDimension);
m_pixelWidth = ParseSizeForPixelSize(m_width, warnings);
}

// explicit width takes precedence over relative width
Expand All @@ -40,6 +39,9 @@ int Column::GetPixelWidth() const
void Column::SetPixelWidth(const int value)
{
m_pixelWidth = value;
std::ostringstream pixelString;
pixelString << value << "px";
m_width = pixelString.str();
}

const std::vector<std::shared_ptr<BaseCardElement>>& Column::GetItems() const
Expand Down Expand Up @@ -128,9 +130,7 @@ std::shared_ptr<BaseCardElement> ColumnParser::Deserialize(ParseContext& context
columnWidth = ParseUtil::GetValueAsString(value, AdaptiveCardSchemaKey::Size);
}

column->SetWidth(ParseUtil::ToLowercase(columnWidth));
const int parsedDimension = ParseSizeForPixelSize(column->GetWidth(), &context.warnings);
column->SetPixelWidth(parsedDimension);
column->SetWidth(ParseUtil::ToLowercase(columnWidth), &context.warnings);

return column;
}
Expand Down
5 changes: 2 additions & 3 deletions source/shared/cpp/ObjectModel/Column.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ namespace AdaptiveSharedNamespace

std::string GetWidth() const;
void SetWidth(const std::string& value);
void SetWidth(const std::string& value,
std::vector<std::shared_ptr<AdaptiveSharedNamespace::AdaptiveCardParseWarning>>* warnings);

// explicit width takes precedence over relative width
int GetPixelWidth() const;
Expand All @@ -36,9 +38,6 @@ namespace AdaptiveSharedNamespace

private:
void PopulateKnownPropertiesSet() override;
void SetWidth(const std::string& value,
std::vector<std::shared_ptr<AdaptiveSharedNamespace::AdaptiveCardParseWarning>>* warnings);

std::string m_width;
unsigned int m_pixelWidth;
std::vector<std::shared_ptr<AdaptiveSharedNamespace::BaseCardElement>> m_items;
Expand Down

0 comments on commit b62acac

Please sign in to comment.