Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to CornerRadiusToThicknessConverter for more filters #90

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added active/CornerRadius/CornerRadius.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
108 changes: 108 additions & 0 deletions active/CornerRadius/CornerRadiusToThickness2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
> See comments in Markdown for how to use this spec template

MikeHillberg marked this conversation as resolved.
Show resolved Hide resolved

# Background

_This spec updates the existing [CornerRadiusToThicknessConverter](https://docs.microsoft.com/uwp/api/Microsoft.UI.Xaml.Controls.Primitives.CornerRadiusToThicknessConverter) class with new filters._
MikeHillberg marked this conversation as resolved.
Show resolved Hide resolved

WinUI has a [CornerRadius](https://docs.microsoft.com/uwp/api/Windows.UI.Xaml.CornerRadius) struct that's used to define the rounding the 4 corners of a box, and the [Thickness](https://docs.microsoft.com/uwp/api/Windows.UI.Xaml.Thickness) struct that's used for defining the padding or margin around the 4 sides of a box.

CornerRadius defines the radius length of the circle segment that's used to draw a rounded corner. For example the following uses 4 different radii for the 4 corners (the corners are listed in clockwise order starting from the top left corner):

```xml
<Border CornerRadius="0,20,40,60" BorderBrush="Red" BorderThickness="2" Height="100" Width="100" />
```

![Corner radius example](./CornerRadius.png)

Thickness defines 4 sides. For example the following uses 4 different values for the margins around a blue rectangle in a red box (the sides are listed in clockwise order starting from the left):

```xml
<Border BorderBrush="Red" BorderThickness="2" Height="100" Width="100" >
<Rectangle Fill="Blue" Margin="0,20,40,60" />
</Border>
```

![Thickness example](./Thickness.png)

For consistency it's useful to be able to build a Thickness out of components of a CornerRadius. For this reason the [CornerRadiusFilterConverter](https://docs.microsoft.com/uwp/api/Microsoft.UI.Xaml.Controls.Primitives.CornerRadiusFilterConverter) exists, which can be used in Xaml markup. That converter has a [CornerRadiusFilterKind](https://docs.microsoft.com/uwp/api/Microsoft.UI.Xaml.Controls.Primitives.CornerRadiusFilterKind) that lets you define which parts to pull out, what's being added in this spec is update to that enum to allow more parts to be pulled out.

**Existing values:**
* FilterTopAndBottomFromLeft,
* FilterTopAndBottomFromRight,
* FilterLeftAndRightFromTop,
* FilterLeftAndRightFromBottom

**New values:**
* FilterTopFromTopLeft,
* FilterTopFromTopRight,
* FilterRightFromTopRight,
* FilterRightFromBottomRight,
* FilterBottomFromBottomRight,
* FilterBottomFromBottomLeft,
* FilterLeftFromBottomLeft,
* FilterLeftFromTopLeft,
MikeHillberg marked this conversation as resolved.
Show resolved Hide resolved

The CornerRadiusFilterConverter is also updated with a new property -- Multiplier -- which is applied during the converstion. For example, setting this to -1 negates the value.
MikeHillberg marked this conversation as resolved.
Show resolved Hide resolved

# Examples

This example creates a converter that creates a Thickness from a CornerRadius, where the Thickness is set to zeros except for its left, which uses the the left component of the corner's bottom/left, and then negates it. For example, this converts

CornerRadius: `10, 20, 30, 40`

Thickness: `-40, 0, 0, 0`

```xml
<CornerRadiusToThicknessConverter ConversionKind="FilterLeftFromBottomLeft" Multiplier="-1" x:Name='CornerRadiusToThickness1'/>
```

This converter can then be used elsewhere in Xaml:

```xml
<Path
Margin="{Binding Source={ThemeResource OverlayCornerRadius},
Converter={StaticResource CornerRadiusToThickness1}}"
Height="100"
Margin="100"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TYPO: Margin being set twice.

Fill="Red"
Data="M4 0 L4 4 L0 4 A4,4 90 0 0 4 0 Z" />
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would like to see the results of this example. I tried pasting this into a test app and saw nothing because there is no stroke thickness or brush, and because I'm not sure what "M4 0 ..." produces. A labeled illustration would help.

Copy link
Contributor

@marcelwgn marcelwgn Jul 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, the example should show something when simply copy pasted. Fun fact, the path renders this kind of shape (the black part):

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommend: everything should be copy/paste-able.



# API Notes

| | |
| - | - |
| FilterTopFromTopLeft | Sets top from the top left corner |
| FilterTopFromTopRight | Sets the top from the top right corner |
| FilterRightFromTopRight | Sets the right from the top right corner |
| FilterRightFromBottomRight | Sets the right from the bottom right corner |
| FilterBottomFromBottomRight | Sets the bottom from the bottom right corner |
| FilterBottomFromBottomLeft | Sets the bottom from the bottom left corner |
| FilterLeftFromBottomLeft | Sets the left from the bottom left corner |
| FilterLeftFromTopLeft | Sets the left from the top left corner |

# API Details

```cs
[webhosthidden]
enum CornerRadiusToThicknessConverterKind
{
FilterTopAndBottomFromLeft,
FilterTopAndBottomFromRight,
FilterLeftAndRightFromTop,
FilterLeftAndRightFromBottom,

// New
FilterTopFromTopLeft,
FilterTopFromTopRight,
FilterRightFromTopRight,
FilterRightFromBottomRight,
FilterBottomFromBottomRight,
FilterBottomFromBottomLeft,
FilterLeftFromBottomLeft,
FilterLeftFromTopLeft,
};
```

Binary file added active/CornerRadius/Thickness.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.