Skip to content

Commit

Permalink
UWP - Add new property to the renderer (#8806)
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-dingler authored Feb 1, 2024
1 parent 608e213 commit 913e034
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 20 deletions.
2 changes: 2 additions & 0 deletions source/uwp/Renderer/idl/AdaptiveCards.Rendering.Uwp.idl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ namespace AdaptiveCards
String OverflowButtonText;
String OverflowButtonAccessibilityText;

Boolean AddSelectActionMargin;

void SetFixedDimensions(UInt32 desiredWidth, UInt32 desiredHeight);
void ResetFixedDimensions();

Expand Down
44 changes: 25 additions & 19 deletions source/uwp/SharedRenderer/lib/ActionHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,31 +509,37 @@ namespace AdaptiveCards::Rendering::Xaml_Rendering::ActionHelpers
auto button = CreateButton(action);
button.Content(elementToWrap);

uint32_t cardPadding = 0;
if (fullWidth)
{
cardPadding = hostConfig.Spacing().Padding();
}
auto hostConfigImpl = peek_innards<winrt::implementation::AdaptiveHostConfig>(hostConfig);
auto addSelectActionMargin = hostConfigImpl->AddSelectActionMargin();

// We want the hit target to equally split the vertical space above and below the current item.
// However, all we know is the spacing of the current item, which only applies to the spacing above.
// We don't know what the spacing of the NEXT element will be, so we can't calculate the correct spacing
// below. For now, we'll simply assume the bottom spacing is the same as the top. NOTE: Only apply spacings
// (padding, margin) for adaptive card elements to avoid adding spacings to card-level selectAction.
if (adaptiveCardElement)
if (addSelectActionMargin)
{
auto elementSpacing = adaptiveCardElement.Spacing();
uint32_t spacingSize = GetSpacingSizeFromSpacing(hostConfig, elementSpacing);
uint32_t cardPadding = 0;
if (fullWidth)
{
cardPadding = hostConfig.Spacing().Padding();
}

// We want the hit target to equally split the vertical space above and below the current item.
// However, all we know is the spacing of the current item, which only applies to the spacing above.
// We don't know what the spacing of the NEXT element will be, so we can't calculate the correct spacing
// below. For now, we'll simply assume the bottom spacing is the same as the top. NOTE: Only apply spacings
// (padding, margin) for adaptive card elements to avoid adding spacings to card-level selectAction.
if (adaptiveCardElement)
{
auto elementSpacing = adaptiveCardElement.Spacing();
uint32_t spacingSize = GetSpacingSizeFromSpacing(hostConfig, elementSpacing);

double topBottomPadding = spacingSize / 2.0;
double topBottomPadding = spacingSize / 2.0;

// For button padding, we apply the cardPadding and topBottomPadding (and then we negate these in the margin)
button.Padding({(double)cardPadding, topBottomPadding, (double)cardPadding, topBottomPadding});
// For button padding, we apply the cardPadding and topBottomPadding (and then we negate these in the margin)
button.Padding({(double)cardPadding, topBottomPadding, (double)cardPadding, topBottomPadding});

double negativeCardMargin = cardPadding * -1.0;
double negativeTopBottomMargin = topBottomPadding * -1.0;
double negativeCardMargin = cardPadding * -1.0;
double negativeTopBottomMargin = topBottomPadding * -1.0;

button.Margin({negativeCardMargin, negativeTopBottomMargin, negativeCardMargin, negativeTopBottomMargin});
button.Margin({negativeCardMargin, negativeTopBottomMargin, negativeCardMargin, negativeTopBottomMargin});
}
}

// Style the hit target button
Expand Down
10 changes: 10 additions & 0 deletions source/uwp/SharedRenderer/lib/AdaptiveCardRendererComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ namespace winrt::AdaptiveCards::Rendering::Xaml_Rendering::implementation
GetHostConfig()->OverflowMaxActions = overflowMaxActions;
}

bool AdaptiveCardRenderer::AddSelectActionMargin()
{
return GetHostConfig()->AddSelectActionMargin;
}

void AdaptiveCardRenderer::AddSelectActionMargin(bool addSelectActionMargin)
{
GetHostConfig()->AddSelectActionMargin = addSelectActionMargin;
}

winrt::RenderedAdaptiveCard AdaptiveCardRenderer::RenderAdaptiveCard(winrt::AdaptiveCard const& adaptiveCard)
{
auto renderedCard = winrt::make_self<implementation::RenderedAdaptiveCard>();
Expand Down
3 changes: 3 additions & 0 deletions source/uwp/SharedRenderer/lib/AdaptiveCardRendererComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ namespace winrt::AdaptiveCards::Rendering::Xaml_Rendering::implementation
return GetHostConfig()->OverflowButtonAccessibilityText = text;
}

void AddSelectActionMargin(bool addSelectActionMargin);
bool AddSelectActionMargin();

winrt::RenderedAdaptiveCard RenderAdaptiveCard(winrt::AdaptiveCard const& adaptiveCard);
winrt::RenderedAdaptiveCard RenderAdaptiveCardFromJsonString(hstring const& adaptiveJson);
winrt::RenderedAdaptiveCard RenderAdaptiveCardFromJson(winrt::JsonObject const& adaptiveJson);
Expand Down
2 changes: 1 addition & 1 deletion source/uwp/SharedRenderer/lib/AdaptiveHostConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace winrt::AdaptiveCards::Rendering::Xaml_Rendering::implementation
TextBlock{winrt::make<implementation::AdaptiveTextBlockConfig>(sharedHostConfig.GetTextBlock())},
TextStyles{winrt::make<implementation::AdaptiveTextStylesConfig>(sharedHostConfig.GetTextStyles())},
Table{winrt::make<implementation::AdaptiveTableConfig>(sharedHostConfig.GetTable())}, OverflowMaxActions{false},
OverflowButtonText{L"..."}, OverflowButtonAccessibilityText{L"More Actions"}
OverflowButtonText{L"..."}, OverflowButtonAccessibilityText{L"More Actions"}, AddSelectActionMargin{true}
{
}
}
1 change: 1 addition & 0 deletions source/uwp/SharedRenderer/lib/AdaptiveHostConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace winrt::AdaptiveCards::Rendering::Xaml_Rendering::implementation
property<bool> OverflowMaxActions;
property<hstring> OverflowButtonText;
property<hstring> OverflowButtonAccessibilityText;
property<bool> AddSelectActionMargin;

// ITypePeek method
void* PeekAt(REFIID riid) override { return PeekHelper(riid, this); }
Expand Down
3 changes: 3 additions & 0 deletions source/uwp/SharedVisualizer/ViewModel/DocumentViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ public static void InitializeRenderer(AdaptiveHostConfig hostConfig)

_renderer.OverflowMaxActions = true;

// Uncomment the line below to remove margins from selectAction. Default is `true`
//_renderer.AddSelectActionMargin = false;

// Add a feature representing this version of the visualizer. used for test cards.
_renderer.FeatureRegistration.Set("acTest", "1.0");

Expand Down
1 change: 1 addition & 0 deletions source/uwp/winui3/Renderer/AdaptiveCardRenderer.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
<ItemDefinitionGroup Condition="'$(Configuration)'=='Debug'">
<ClCompile>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<DebugInformationFormat Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">ProgramDatabase</DebugInformationFormat>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ namespace AdaptiveCards
String OverflowButtonText;
String OverflowButtonAccessibilityText;

Boolean AddSelectActionMargin;

void SetFixedDimensions(UInt32 desiredWidth, UInt32 desiredHeight);
void ResetFixedDimensions();

Expand Down

0 comments on commit 913e034

Please sign in to comment.