Skip to content

Commit

Permalink
Jwoo/uwp wrap (#2264)
Browse files Browse the repository at this point in the history
* uwp wrap property for choice set and toggle input

* replaced expanded tab to tab in json payload

* rebased to master

* CR review feedback
  • Loading branch information
jwoo-msft authored Jan 5, 2019
1 parent a38be9b commit a9e1f72
Show file tree
Hide file tree
Showing 25 changed files with 120 additions and 29 deletions.
64 changes: 43 additions & 21 deletions samples/Tests/SearchResults.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
{
"type": "TextBlock",
"text": "3 results for 3d printer filament",
"bold": true,
"wrap": true,
"size": "large",
"horizontalAlignment": "center"
"bold": true,
"wrap": true,
"size": "large",
"horizontalAlignment": "center"
},
{
"type": "Input.ChoiceSet",
"id": "filament",
"style": "expanded",
"isMultiSelect": false,
"value": "1",
"wrap": true,
"wrap": true,
"choices": [
{
"title": "HATCHBOX 1.75mm White PLA 3D Printer Filament - 1kg Spool (2.2 lbs) - Dimensional Accuracy +/- 0.03mm",
Expand All @@ -33,26 +33,48 @@
}
]
},
{
"type": "TextBlock",
"text": "Specify Filament Type to ABS",
"size": "medium",
"bold": true
},
{
"type": "Input.Toggle",
"id": "filamenttype",
"title": "Acrylonitrile Butadiene Styrene: Making durable parts that need to withstand higher temperatures, Easy to print with, strong plastic (2952)",
"wrap": true,
"value": "true",
"valueOn": "true",
"valueOff": "false"
}
{
"type": "Input.ChoiceSet",
"id": "filamentCompact",
"style": "compact",
"isMultiSelect": false,
"value": "1",
"wrap": true,
"choices": [
{
"title": "HATCHBOX 1.75mm White PLA 3D Printer Filament - 1kg Spool (2.2 lbs) - Dimensional Accuracy +/- 0.03mm",
"value": "1"
},
{
"title": "HATCHBOX PLA 3D Printer Filament, Dimensional Accuracy +/- 0.03 mm, 1 kg Spool, 1.75 mm, Blue",
"value": "2"
},
{
"title": "3D Solutech Silver Metal 3D Printer PLA Filament 1.75MM Filament, Dimensional Accuracy +/- 0.03 mm, 2.2 LBS (1.0KG) - PLA175TCMS",
"value": "3"
}
]
},
{
"type": "TextBlock",
"text": "Specify Filament Type to ABS",
"size": "medium",
"bold": true
},
{
"type": "Input.Toggle",
"id": "filamenttype",
"title": "Get PLA(Poly Lactic Acid) filament by tommorrow if order in next 2 hours",
"wrap": true,
"value": "true",
"valueOn": "true",
"valueOff": "false"
}
],
"actions": [
{
"type": "Action.Submit",
"title": "OK"
"title": "Order"
}
]
}
3 changes: 2 additions & 1 deletion source/shared/cpp/ObjectModel/ChoiceSetInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
using namespace AdaptiveSharedNamespace;

ChoiceSetInput::ChoiceSetInput() :
BaseInputElement(CardElementType::ChoiceSetInput), m_isMultiSelect(false), m_choiceSetStyle(ChoiceSetStyle::Compact)
BaseInputElement(CardElementType::ChoiceSetInput), m_isMultiSelect(false),
m_choiceSetStyle(ChoiceSetStyle::Compact), m_wrap(false)
{
PopulateKnownPropertiesSet();
}
Expand Down
3 changes: 2 additions & 1 deletion source/shared/cpp/ObjectModel/ToggleInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

using namespace AdaptiveSharedNamespace;

ToggleInput::ToggleInput() : BaseInputElement(CardElementType::ToggleInput), m_valueOff("false"), m_valueOn("true")
ToggleInput::ToggleInput() :
BaseInputElement(CardElementType::ToggleInput), m_valueOff("false"), m_valueOn("true"), m_wrap(false)
{
PopulateKnownPropertiesSet();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"actions":[{"data":"null","id":"","title":"Order","type":"Action.Submit"}],"body":[{"bold":true,"horizontalAlignment":"Center","size":"Large","text":"3 results for 3d printer filament","type":"TextBlock","wrap":true},{"choices":[{"title":"HATCHBOX 1.75mm White PLA 3D Printer Filament - 1kg Spool (2.2 lbs) - Dimensional Accuracy +/- 0.03mm","value":"1"},{"title":"HATCHBOX PLA 3D Printer Filament, Dimensional Accuracy +/- 0.03 mm, 1 kg Spool, 1.75 mm, Blue","value":"2"},{"title":"3D Solutech Silver Metal 3D Printer PLA Filament 1.75MM Filament, Dimensional Accuracy +/- 0.03 mm, 2.2 LBS (1.0KG) - PLA175TCMS","value":"3"}],"id":"filament","isRequired":false,"style":"Expanded","type":"Input.ChoiceSet","value":"1","wrap":true},{"choices":[{"title":"HATCHBOX 1.75mm White PLA 3D Printer Filament - 1kg Spool (2.2 lbs) - Dimensional Accuracy +/- 0.03mm","value":"1"},{"title":"HATCHBOX PLA 3D Printer Filament, Dimensional Accuracy +/- 0.03 mm, 1 kg Spool, 1.75 mm, Blue","value":"2"},{"title":"3D Solutech Silver Metal 3D Printer PLA Filament 1.75MM Filament, Dimensional Accuracy +/- 0.03 mm, 2.2 LBS (1.0KG) - PLA175TCMS","value":"3"}],"id":"filamentCompact","isRequired":false,"style":"Compact","type":"Input.ChoiceSet","value":"1","wrap":true},{"bold":true,"size":"Medium","text":"Specify Filament Type to ABS","type":"TextBlock"},{"id":"filamenttype","isRequired":false,"title":"Get PLA(Poly Lactic Acid) filament by tommorrow if order in next 2 hours","type":"Input.Toggle","value":"true","valueOff":"false","valueOn":"true","wrap":true}],"type":"AdaptiveCard","version":"1.0"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"HostConfigHash":"5da68b8","CardHash":"dfefdb8","Error":null}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"HostConfigHash":"9f2d152","CardHash":"dfefdb8","Error":null}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"HostConfigHash":"6e7bf22","CardHash":"dfefdb8","Error":null}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"HostConfigHash":"9aebe2c","CardHash":"dfefdb8","Error":null}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"HostConfigHash":"f813d32","CardHash":"dfefdb8","Error":null}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"HostConfigHash":"68476db","CardHash":"dfefdb8","Error":null}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"HostConfigHash":"1bb97f8","CardHash":"dfefdb8","Error":null}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions source/uwp/Renderer/idl/AdaptiveCards.Rendering.Uwp.idl
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,8 @@ AdaptiveNamespaceStart
[propput] HRESULT Value([in] HSTRING value);
[propget] HRESULT IsMultiSelect([out, retval] boolean* value);
[propput] HRESULT IsMultiSelect([in] boolean value);
[propget] HRESULT Wrap([out, retval] boolean* value);
[propput] HRESULT Wrap([in] boolean value);

[propget] HRESULT ChoiceSetStyle([out, retval] ChoiceSetStyle* value);
[propput] HRESULT ChoiceSetStyle([in] ChoiceSetStyle value);
Expand Down Expand Up @@ -1252,6 +1254,9 @@ AdaptiveNamespaceStart
[propget] HRESULT Title([out, retval] HSTRING* value);
[propput] HRESULT Title([in] HSTRING value);

[propget] HRESULT Wrap([out, retval] boolean* value);
[propput] HRESULT Wrap([in] boolean value);

[propget] HRESULT Value([out, retval] HSTRING* value);
[propput] HRESULT Value([in] HSTRING value);

Expand Down
14 changes: 14 additions & 0 deletions source/uwp/Renderer/lib/AdaptiveChoiceSetInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace AdaptiveNamespace
GenerateInputChoicesProjection(sharedChoiceSetInput->GetChoices(), m_choices.Get());

m_isMultiSelect = sharedChoiceSetInput->GetIsMultiSelect();
m_wrap = sharedChoiceSetInput->GetWrap();
m_choiceSetStyle = static_cast<ABI::AdaptiveNamespace::ChoiceSetStyle>(sharedChoiceSetInput->GetChoiceSetStyle());
RETURN_IF_FAILED(UTF8ToHString(sharedChoiceSetInput->GetValue(), m_value.GetAddressOf()));

Expand All @@ -57,6 +58,18 @@ namespace AdaptiveNamespace
return S_OK;
}

HRESULT AdaptiveChoiceSetInput::get_Wrap(_Out_ boolean* wrap)
{
*wrap = m_wrap;
return S_OK;
}

HRESULT AdaptiveChoiceSetInput::put_Wrap(boolean wrap)
{
m_wrap = wrap;
return S_OK;
}

HRESULT AdaptiveChoiceSetInput::get_ChoiceSetStyle(_Out_ ABI::AdaptiveNamespace::ChoiceSetStyle* choiceSetStyle)
{
*choiceSetStyle = m_choiceSetStyle;
Expand Down Expand Up @@ -102,6 +115,7 @@ namespace AdaptiveNamespace
choiceSet->SetChoiceSetStyle(static_cast<AdaptiveSharedNamespace::ChoiceSetStyle>(m_choiceSetStyle));
choiceSet->SetIsMultiSelect(m_isMultiSelect);
choiceSet->SetValue(HStringToUTF8(m_value.Get()));
choiceSet->SetWrap(m_wrap);

RETURN_IF_FAILED(GenerateSharedChoices(m_choices.Get(), choiceSet->GetChoices()));

Expand Down
4 changes: 4 additions & 0 deletions source/uwp/Renderer/lib/AdaptiveChoiceSetInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ namespace AdaptiveNamespace
IFACEMETHODIMP get_IsMultiSelect(_Out_ boolean* isMultiSelect);
IFACEMETHODIMP put_IsMultiSelect(boolean isMultiSelect);

IFACEMETHODIMP get_Wrap(_Out_ boolean* wrap);
IFACEMETHODIMP put_Wrap(boolean wrap);

IFACEMETHODIMP get_ChoiceSetStyle(_Out_ ABI::AdaptiveNamespace::ChoiceSetStyle* choiceSetStyle);
IFACEMETHODIMP put_ChoiceSetStyle(ABI::AdaptiveNamespace::ChoiceSetStyle choiceSetStyle);

Expand Down Expand Up @@ -110,6 +113,7 @@ namespace AdaptiveNamespace

private:
Microsoft::WRL::ComPtr<ABI::Windows::Foundation::Collections::IVector<ABI::AdaptiveNamespace::IAdaptiveChoiceInput*>> m_choices;
boolean m_wrap;
boolean m_isMultiSelect;
ABI::AdaptiveNamespace::ChoiceSetStyle m_choiceSetStyle;
Microsoft::WRL::Wrappers::HString m_value;
Expand Down
14 changes: 14 additions & 0 deletions source/uwp/Renderer/lib/AdaptiveToggleInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace AdaptiveNamespace
RETURN_IF_FAILED(UTF8ToHString(sharedToggleInput->GetValue(), m_value.GetAddressOf()));
RETURN_IF_FAILED(UTF8ToHString(sharedToggleInput->GetValueOn(), m_valueOn.GetAddressOf()));
RETURN_IF_FAILED(UTF8ToHString(sharedToggleInput->GetValueOff(), m_valueOff.GetAddressOf()));
m_wrap = sharedToggleInput->GetWrap();

InitializeBaseElement(std::static_pointer_cast<BaseInputElement>(sharedToggleInput));
return S_OK;
Expand All @@ -54,6 +55,18 @@ namespace AdaptiveNamespace

HRESULT AdaptiveToggleInput::put_ValueOn(_In_ HSTRING valueOn) { return m_valueOn.Set(valueOn); }

HRESULT AdaptiveToggleInput::get_Wrap(_Out_ boolean* wrap)
{
*wrap = m_wrap;
return S_OK;
}

HRESULT AdaptiveToggleInput::put_Wrap(boolean wrap)
{
m_wrap = wrap;
return S_OK;
}

HRESULT AdaptiveToggleInput::get_ElementType(_Out_ ElementType* elementType)
{
*elementType = ElementType::ToggleInput;
Expand All @@ -71,6 +84,7 @@ namespace AdaptiveNamespace
toggleInput->SetValue(HStringToUTF8(m_value.Get()));
toggleInput->SetValueOn(HStringToUTF8(m_valueOn.Get()));
toggleInput->SetValueOff(HStringToUTF8(m_valueOff.Get()));
toggleInput->SetWrap(m_wrap);

sharedModel = toggleInput;

Expand Down
4 changes: 4 additions & 0 deletions source/uwp/Renderer/lib/AdaptiveToggleInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ namespace AdaptiveNamespace
IFACEMETHODIMP get_Title(_Outptr_ HSTRING* title);
IFACEMETHODIMP put_Title(_In_ HSTRING title);

IFACEMETHODIMP get_Wrap(_Out_ boolean* wrap);
IFACEMETHODIMP put_Wrap(boolean wrap);

IFACEMETHODIMP get_Value(_Outptr_ HSTRING* value);
IFACEMETHODIMP put_Value(_In_ HSTRING value);

Expand Down Expand Up @@ -109,6 +112,7 @@ namespace AdaptiveNamespace
Microsoft::WRL::Wrappers::HString m_value;
Microsoft::WRL::Wrappers::HString m_valueOn;
Microsoft::WRL::Wrappers::HString m_valueOff;
boolean m_wrap;
};

ActivatableClass(AdaptiveToggleInput);
Expand Down
18 changes: 13 additions & 5 deletions source/uwp/Renderer/lib/XamlBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2745,18 +2745,20 @@ namespace AdaptiveNamespace
THROW_IF_FAILED(adaptiveChoiceSetInput->get_Choices(&choices));

std::vector<std::string> values = GetChoiceSetValueVector(adaptiveChoiceSetInput);
boolean wrap;
adaptiveChoiceSetInput->get_Wrap(&wrap);

int currentIndex = 0;
int selectedIndex = -1;
XamlHelpers::IterateOverVector<IAdaptiveChoiceInput>(
choices.Get(), [&currentIndex, &selectedIndex, itemsVector, values](IAdaptiveChoiceInput* adaptiveChoiceInput) {
choices.Get(), [&currentIndex, &selectedIndex, itemsVector, values, wrap](IAdaptiveChoiceInput* adaptiveChoiceInput) {
HString title;
THROW_IF_FAILED(adaptiveChoiceInput->get_Title(title.GetAddressOf()));

ComPtr<IComboBoxItem> comboBoxItem = XamlHelpers::CreateXamlClass<IComboBoxItem>(
HStringReference(RuntimeClass_Windows_UI_Xaml_Controls_ComboBoxItem));

XamlHelpers::SetContent(comboBoxItem.Get(), title.Get());
XamlHelpers::SetContent(comboBoxItem.Get(), title.Get(), wrap);

// If multiple values are specified, no option is selected
if (values.size() == 1 && IsChoiceSelected(values, adaptiveChoiceInput))
Expand Down Expand Up @@ -2801,7 +2803,10 @@ namespace AdaptiveNamespace

std::vector<std::string> values = GetChoiceSetValueVector(adaptiveChoiceSetInput);

XamlHelpers::IterateOverVector<IAdaptiveChoiceInput>(choices.Get(), [panel, isMultiSelect, renderContext, values](IAdaptiveChoiceInput* adaptiveChoiceInput) {
boolean wrap;
adaptiveChoiceSetInput->get_Wrap(&wrap);

XamlHelpers::IterateOverVector<IAdaptiveChoiceInput>(choices.Get(), [panel, isMultiSelect, renderContext, values, wrap](IAdaptiveChoiceInput* adaptiveChoiceInput) {
ComPtr<IUIElement> choiceItem;
if (isMultiSelect)
{
Expand Down Expand Up @@ -2835,7 +2840,7 @@ namespace AdaptiveNamespace

HString title;
THROW_IF_FAILED(adaptiveChoiceInput->get_Title(title.GetAddressOf()));
XamlHelpers::SetContent(choiceItem.Get(), title.Get());
XamlHelpers::SetContent(choiceItem.Get(), title.Get(), wrap);

THROW_IF_FAILED(AddHandledTappedEvent(choiceItem.Get()));

Expand Down Expand Up @@ -3404,7 +3409,10 @@ namespace AdaptiveNamespace
HString title;
THROW_IF_FAILED(adaptiveToggleInput->get_Title(title.GetAddressOf()));

XamlHelpers::SetContent(checkBox.Get(), title.Get());
boolean wrap;
adaptiveToggleInput->get_Wrap(&wrap);

XamlHelpers::SetContent(checkBox.Get(), title.Get(), wrap);

HString value;
THROW_IF_FAILED(adaptiveToggleInput->get_Value(value.GetAddressOf()));
Expand Down
12 changes: 11 additions & 1 deletion source/uwp/Renderer/lib/XamlHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ namespace AdaptiveNamespace
}
}

template<typename T> static void SetContent(_In_ T* item, _In_ HSTRING contentString)
template<typename T> static void SetContent(_In_ T* item, _In_ HSTRING contentString, boolean wrap)
{
ComPtr<T> localItem(item);
ComPtr<IContentControl> contentControl;
Expand All @@ -126,9 +126,19 @@ namespace AdaptiveNamespace
ComPtr<ITextBlock> content =
XamlHelpers::CreateXamlClass<ITextBlock>(HStringReference(RuntimeClass_Windows_UI_Xaml_Controls_TextBlock));
THROW_IF_FAILED(content->put_Text(contentString));

if (wrap)
{
THROW_IF_FAILED(content->put_TextWrapping(TextWrapping::TextWrapping_WrapWholeWords));
}
THROW_IF_FAILED(contentControl->put_Content(content.Get()));
}

template<typename T> static void SetContent(T* item, HSTRING contentString)
{
SetContent(item, contentString, false);
}

template<typename T>
static void AddRow(_In_ T* item, _In_ ABI::Windows::UI::Xaml::Controls::IGrid* grid, ABI::Windows::UI::Xaml::GridLength rowHeight)
{
Expand Down

0 comments on commit a9e1f72

Please sign in to comment.