Skip to content

Commit

Permalink
Fix Teaching Tip's Rounded Corners (#1305)
Browse files Browse the repository at this point in the history
* Attempt to fix a rare crash in calculator app.

* Do proper event token clean up.

* Use the routedEventHelpers instead of doing these events by hand

* Clean up

* Fix a silly mistake

* rename handler to revoker

* PTR: Fix high contrast list item display, remove background and add border to display PTR correctly in test page

* Fix teaching tips adorners to be compatible with rounded corners.

* Rename the converter peices

* UseNonstandardConditionalXaml

* move converter definitions out of the teaching tip style.
  • Loading branch information
StephenLPeters authored and jevansaks committed Sep 17, 2019
1 parent 96b64c0 commit a29c1b4
Show file tree
Hide file tree
Showing 12 changed files with 303 additions and 14 deletions.
4 changes: 4 additions & 0 deletions dev/Common/Common.vcxitems
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@
<ClCompile Include="$(MSBuildThisFileDirectory)CornerRadiusFilterConverter.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)LifetimeHandler.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\Generated\CornerRadiusFilterConverter.properties.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)CornerRadiusToThicknessConverter.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\Generated\CornerRadiusToThicknessConverter.properties.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="$(MSBuildThisFileDirectory)AutoHandle.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)ColorConversion.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)CornerRadiusFilterConverter.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)LifetimeHandler.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)CornerRadiusToThicknessConverter.h" />
</ItemGroup>
<ItemGroup>
<Page Include="$(MSBuildThisFileDirectory)Common_themeresources.xaml">
Expand All @@ -33,6 +36,7 @@
</Page>
</ItemGroup>
<ItemGroup>
<Midl Include="$(MSBuildThisFileDirectory)CornerRadiusToThicknessConverter.idl" />
<Midl Include="$(MSBuildThisFileDirectory)CornerRadiusFilterConverters.idl" />
</ItemGroup>
</Project>
61 changes: 61 additions & 0 deletions dev/Common/CornerRadiusToThicknessConverter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#include <pch.h>
#include <common.h>
#include "CornerRadiusToThicknessConverter.h"

winrt::Thickness CornerRadiusToThicknessConverter::Convert(winrt::CornerRadius const& radius, winrt::CornerRadiusToThicknessConverterKind const& filterKind)
{
auto result = winrt::Thickness{};

switch (filterKind)
{
case winrt::CornerRadiusToThicknessConverterKind::FilterLeftAndRightFromTop:
result.Left = radius.TopLeft;
result.Right = radius.TopRight;
result.Top = 0;
result.Bottom = 0;
break;
case winrt::CornerRadiusToThicknessConverterKind::FilterLeftAndRightFromBottom:
result.Left = radius.BottomLeft;
result.Right = radius.BottomRight;
result.Top = 0;
result.Bottom = 0;
break;
case winrt::CornerRadiusToThicknessConverterKind::FilterTopAndBottomFromLeft:
result.Left = 0;
result.Right = 0;
result.Top = radius.TopLeft;
result.Bottom = radius.BottomLeft;
break;
case winrt::CornerRadiusToThicknessConverterKind::FilterTopAndBottomFromRight:
result.Left = 0;
result.Right = 0;
result.Top = radius.TopRight;
result.Bottom = radius.BottomRight;
break;
}

return result;
}

winrt::IInspectable CornerRadiusToThicknessConverter::Convert(
winrt::IInspectable const& value,
winrt::TypeName const& targetType,
winrt::IInspectable const& parameter,
winrt::hstring const& language)
{
auto radius = unbox_value<winrt::CornerRadius>(value);

return box_value(Convert(radius, ConversionKind()));
}

winrt::IInspectable CornerRadiusToThicknessConverter::ConvertBack(
winrt::IInspectable const& value,
winrt::TypeName const& targetType,
winrt::IInspectable const& parameter,
winrt::hstring const& language)
{
winrt::throw_hresult(E_NOTIMPL);
}
28 changes: 28 additions & 0 deletions dev/Common/CornerRadiusToThicknessConverter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

#pragma once
#include "CornerRadiusToThicknessConverter.g.h"
#include "CornerRadiusToThicknessConverter.properties.h"

class CornerRadiusToThicknessConverter :
public winrt::implementation::CornerRadiusToThicknessConverterT<CornerRadiusToThicknessConverter>,
public CornerRadiusToThicknessConverterProperties
{
public:
winrt::Thickness Convert(
winrt::CornerRadius const& radius,
winrt::CornerRadiusToThicknessConverterKind const& filterKind);

winrt::IInspectable Convert(
winrt::IInspectable const& value,
winrt::TypeName const& targetType,
winrt::IInspectable const& parameter,
winrt::hstring const& language);

winrt::IInspectable ConvertBack(
winrt::IInspectable const& value,
winrt::TypeName const& targetType,
winrt::IInspectable const& parameter,
winrt::hstring const& language);
};
27 changes: 27 additions & 0 deletions dev/Common/CornerRadiusToThicknessConverter.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace MU_XCP_NAMESPACE
{

[WUXC_VERSION_MUXONLY]
[webhosthidden]
[default_interface]
runtimeclass CornerRadiusToThicknessConverter : Windows.UI.Xaml.DependencyObject, Windows.UI.Xaml.Data.IValueConverter
{
CornerRadiusToThicknessConverter();

[MUX_DEFAULT_VALUE("winrt::CornerRadiusToThicknessConverterKind::FilterLeftAndRightFromTop")]
CornerRadiusToThicknessConverterKind ConversionKind{ get; set; };

static Windows.UI.Xaml.DependencyProperty ConversionKindProperty{ get; };
};

[WUXC_VERSION_MUXONLY]
[webhosthidden]
enum CornerRadiusToThicknessConverterKind
{
FilterTopAndBottomFromLeft,
FilterTopAndBottomFromRight,
FilterLeftAndRightFromTop,
FilterLeftAndRightFromBottom,
};

}
8 changes: 7 additions & 1 deletion dev/CommonStyles/CornerRadius_themeresources.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,11 @@
<primitives:CornerRadiusFilterConverter x:Key="LeftCornerRadiusFilterConverter" Filter="Left"/>
<primitives:CornerRadiusFilterConverter x:Key="TopLeftCornerRadiusDoubleValueConverter" Filter="TopLeftValue"/>
<primitives:CornerRadiusFilterConverter x:Key="BottomRightCornerRadiusDoubleValueConverter" Filter="BottomRightValue"/>



<primitives:CornerRadiusToThicknessConverter x:Key="TopThicknessFilterConverter" ConversionKind="FilterLeftAndRightFromTop"/>
<primitives:CornerRadiusToThicknessConverter x:Key="BottomThicknessFilterConverter" ConversionKind="FilterLeftAndRightFromBottom"/>
<primitives:CornerRadiusToThicknessConverter x:Key="LeftThicknessFilterConverter" ConversionKind="FilterTopAndBottomFromLeft"/>
<primitives:CornerRadiusToThicknessConverter x:Key="RightThicknessFilterConverter" ConversionKind="FilterTopAndBottomFromRight"/>

</ResourceDictionary>
46 changes: 46 additions & 0 deletions dev/Generated/CornerRadiusToThicknessConverter.properties.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

// DO NOT EDIT! This file was generated by CustomTasks.DependencyPropertyCodeGen
#include "pch.h"
#include "common.h"
#include "CornerRadiusToThicknessConverter.h"

CppWinRTActivatableClassWithDPFactory(CornerRadiusToThicknessConverter)

GlobalDependencyProperty CornerRadiusToThicknessConverterProperties::s_ConversionKindProperty{ nullptr };

CornerRadiusToThicknessConverterProperties::CornerRadiusToThicknessConverterProperties()
{
EnsureProperties();
}

void CornerRadiusToThicknessConverterProperties::EnsureProperties()
{
if (!s_ConversionKindProperty)
{
s_ConversionKindProperty =
InitializeDependencyProperty(
L"ConversionKind",
winrt::name_of<winrt::CornerRadiusToThicknessConverterKind>(),
winrt::name_of<winrt::CornerRadiusToThicknessConverter>(),
false /* isAttached */,
ValueHelper<winrt::CornerRadiusToThicknessConverterKind>::BoxValueIfNecessary(winrt::CornerRadiusToThicknessConverterKind::FilterLeftAndRightFromTop),
nullptr);
}
}

void CornerRadiusToThicknessConverterProperties::ClearProperties()
{
s_ConversionKindProperty = nullptr;
}

void CornerRadiusToThicknessConverterProperties::ConversionKind(winrt::CornerRadiusToThicknessConverterKind const& value)
{
static_cast<CornerRadiusToThicknessConverter*>(this)->SetValue(s_ConversionKindProperty, ValueHelper<winrt::CornerRadiusToThicknessConverterKind>::BoxValueIfNecessary(value));
}

winrt::CornerRadiusToThicknessConverterKind CornerRadiusToThicknessConverterProperties::ConversionKind()
{
return ValueHelper<winrt::CornerRadiusToThicknessConverterKind>::CastOrUnbox(static_cast<CornerRadiusToThicknessConverter*>(this)->GetValue(s_ConversionKindProperty));
}
21 changes: 21 additions & 0 deletions dev/Generated/CornerRadiusToThicknessConverter.properties.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

// DO NOT EDIT! This file was generated by CustomTasks.DependencyPropertyCodeGen
#pragma once

class CornerRadiusToThicknessConverterProperties
{
public:
CornerRadiusToThicknessConverterProperties();

void ConversionKind(winrt::CornerRadiusToThicknessConverterKind const& value);
winrt::CornerRadiusToThicknessConverterKind ConversionKind();

static winrt::DependencyProperty ConversionKindProperty() { return s_ConversionKindProperty; }

static GlobalDependencyProperty s_ConversionKindProperty;

static void EnsureProperties();
static void ClearProperties();
};
46 changes: 46 additions & 0 deletions dev/Generated/ThicknessFilterConverter.properties.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

// DO NOT EDIT! This file was generated by CustomTasks.DependencyPropertyCodeGen
#include "pch.h"
#include "common.h"
#include "ThicknessFilterConverter.h"

CppWinRTActivatableClassWithDPFactory(ThicknessFilterConverter)

GlobalDependencyProperty ThicknessFilterConverterProperties::s_FilterProperty{ nullptr };

ThicknessFilterConverterProperties::ThicknessFilterConverterProperties()
{
EnsureProperties();
}

void ThicknessFilterConverterProperties::EnsureProperties()
{
if (!s_FilterProperty)
{
s_FilterProperty =
InitializeDependencyProperty(
L"Filter",
winrt::name_of<winrt::ThicknessFilterConverterKind>(),
winrt::name_of<winrt::ThicknessFilterConverter>(),
false /* isAttached */,
ValueHelper<winrt::ThicknessFilterConverterKind>::BoxValueIfNecessary(winrt::ThicknessFilterConverterKind::Top),
nullptr);
}
}

void ThicknessFilterConverterProperties::ClearProperties()
{
s_FilterProperty = nullptr;
}

void ThicknessFilterConverterProperties::Filter(winrt::ThicknessFilterConverterKind const& value)
{
static_cast<ThicknessFilterConverter*>(this)->SetValue(s_FilterProperty, ValueHelper<winrt::ThicknessFilterConverterKind>::BoxValueIfNecessary(value));
}

winrt::ThicknessFilterConverterKind ThicknessFilterConverterProperties::Filter()
{
return ValueHelper<winrt::ThicknessFilterConverterKind>::CastOrUnbox(static_cast<ThicknessFilterConverter*>(this)->GetValue(s_FilterProperty));
}
21 changes: 21 additions & 0 deletions dev/Generated/ThicknessFilterConverter.properties.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

// DO NOT EDIT! This file was generated by CustomTasks.DependencyPropertyCodeGen
#pragma once

class ThicknessFilterConverterProperties
{
public:
ThicknessFilterConverterProperties();

void Filter(winrt::ThicknessFilterConverterKind const& value);
winrt::ThicknessFilterConverterKind Filter();

static winrt::DependencyProperty FilterProperty() { return s_FilterProperty; }

static GlobalDependencyProperty s_FilterProperty;

static void EnsureProperties();
static void ClearProperties();
};
18 changes: 9 additions & 9 deletions dev/TeachingTip/TeachingTip.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,18 +238,18 @@ class TeachingTip :
}

// These values are shifted by one because this is the 1px highlight that sits adjacent to the tip border.
inline winrt::Thickness BottomPlacementTopRightHighlightMargin(double width, double height) { return { (width / 2) + (TailShortSideLength() - 1.0f), 0, 1, 0 }; }
inline winrt::Thickness BottomRightPlacementTopRightHighlightMargin(double width, double height) { return { MinimumTipEdgeToTailEdgeMargin() + TailLongSideLength() - 1.0f, 0, 1, 0 }; }
inline winrt::Thickness BottomLeftPlacementTopRightHighlightMargin(double width, double height) { return { width - (MinimumTipEdgeToTailEdgeMargin() + 1.0f), 0, 1, 0 }; }
inline winrt::Thickness BottomPlacementTopRightHighlightMargin(double width, double height) { return { (width / 2) + (TailShortSideLength() - 1.0f), 0, 3, 0 }; }
inline winrt::Thickness BottomRightPlacementTopRightHighlightMargin(double width, double height) { return { MinimumTipEdgeToTailEdgeMargin() + TailLongSideLength() - 1.0f, 0, 3, 0 }; }
inline winrt::Thickness BottomLeftPlacementTopRightHighlightMargin(double width, double height) { return { width - (MinimumTipEdgeToTailEdgeMargin() + 1.0f), 0, 3, 0 }; }
static inline winrt::Thickness OtherPlacementTopRightHighlightMargin(double width, double height) { return { 0, 0, 0, 0 }; }

inline winrt::Thickness BottomPlacementTopLeftHighlightMargin(double width, double height) { return { 1, 0, (width / 2) + (TailShortSideLength() - 1.0f), 0 }; }
inline winrt::Thickness BottomRightPlacementTopLeftHighlightMargin(double width, double height) { return { 1, 0, width - (MinimumTipEdgeToTailEdgeMargin() + 1.0f), 0 }; }
inline winrt::Thickness BottomLeftPlacementTopLeftHighlightMargin(double width, double height) { return { 1, 0, MinimumTipEdgeToTailEdgeMargin() + TailLongSideLength() - 1.0f, 0 }; }
static inline winrt::Thickness TopEdgePlacementTopLeftHighlightMargin(double width, double height) { return { 1, 1, 1, 0 }; }
inline winrt::Thickness BottomPlacementTopLeftHighlightMargin(double width, double height) { return { 3, 0, (width / 2) + (TailShortSideLength() - 1.0f), 0 }; }
inline winrt::Thickness BottomRightPlacementTopLeftHighlightMargin(double width, double height) { return { 3, 0, width - (MinimumTipEdgeToTailEdgeMargin() + 1.0f), 0 }; }
inline winrt::Thickness BottomLeftPlacementTopLeftHighlightMargin(double width, double height) { return { 3, 0, MinimumTipEdgeToTailEdgeMargin() + TailLongSideLength() - 1.0f, 0 }; }
static inline winrt::Thickness TopEdgePlacementTopLeftHighlightMargin(double width, double height) { return { 3, 1, 3, 0 }; }
// Shifted by one since the tail edge's border is not accounted for automatically.
static inline winrt::Thickness LeftEdgePlacementTopLeftHighlightMargin(double width, double height) { return { 1, 1, 0, 0 }; }
static inline winrt::Thickness RightEdgePlacementTopLeftHighlightMargin(double width, double height) { return { 0, 1, 1, 0 }; }
static inline winrt::Thickness LeftEdgePlacementTopLeftHighlightMargin(double width, double height) { return { 3, 1, 2, 0 }; }
static inline winrt::Thickness RightEdgePlacementTopLeftHighlightMargin(double width, double height) { return { 2, 1, 3, 0 }; }

static inline double UntargetedTipFarPlacementOffset(float farWindowCoordinateInCoreWindowSpace, double tipSize, double offset) { return farWindowCoordinateInCoreWindowSpace - (tipSize + s_untargetedTipWindowEdgeMargin + offset); }
static inline double UntargetedTipCenterPlacementOffset(float nearWindowCoordinateInCoreWindowSpace, float farWindowCoordinateInCoreWindowSpace, double tipSize, double nearOffset, double farOffset) { return ((nearWindowCoordinateInCoreWindowSpace + farWindowCoordinateInCoreWindowSpace) / 2) - (tipSize / 2) + nearOffset - farOffset; }
Expand Down
Loading

0 comments on commit a29c1b4

Please sign in to comment.