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

ToggleSwitch Visual Update #3869

Merged
merged 11 commits into from
Jan 21, 2021
Merged

ToggleSwitch Visual Update #3869

merged 11 commits into from
Jan 21, 2021

Conversation

karkarl
Copy link
Contributor

@karkarl karkarl commented Dec 28, 2020

Description

ToggleSwitch visual updates + animation

How Has This Been Tested?

Visual Verification

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Dec 28, 2020
@YuliKl YuliKl added area-ToggleSwitch team-Controls Issue for the Controls team and removed needs-triage Issue needs to be triaged by the area owners labels Dec 28, 2020
@karkarl
Copy link
Contributor Author

karkarl commented Dec 28, 2020

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mdtauk
Copy link
Contributor

mdtauk commented Dec 28, 2020

Are you particularly keen on using the stretched Oval shape for Pressed states?

The curves being stretched create a visual mis-match with the outer containing shapes, which could be alleviated by using a rounded rectangle in a pill shape to match the outer shape.

image

@karkarl
Copy link
Contributor Author

karkarl commented Dec 29, 2020

Are you particularly keen on using the stretched Oval shape for Pressed states?

The curves being stretched create a visual mis-match with the outer containing shapes, which could be alleviated by using a rounded rectangle in a pill shape to match the outer shape.

image

I updated the xaml to use <Rectangle> with RadiusX and RadiusY much like the outer pill, and this was the closest I got to the pill shape. Would you happen to know how to better tweak this?

@marcelwgn
Copy link
Contributor

I updated the xaml to use with RadiusX and RadiusY much like the outer pill, and this was the closest I got to the pill shape. Would you happen to know how to better tweak this?

Maybe using an SVG for this would be better? SVG was also the way how I was able to get the inset corner radii for TabView.

@mdtauk
Copy link
Contributor

mdtauk commented Dec 29, 2020

I updated the xaml to use with RadiusX and RadiusY much like the outer pill, and this was the closest I got to the pill shape. Would you happen to know how to better tweak this?

Maybe using an SVG for this would be better? SVG was also the way how I was able to get the inset corner radii for TabView.

An SVG would not work, as what you need is to be able to increase the width of the shape, without changing the rounded corners.

In my example I have the rounded rectangle at 14px height, with 7px corner radius - and I increased the width to 19px with the same 7px corners.

image

The Rectangle should give you the right shape, but I am wondering it the keyframe animation is distorting the shape as the width changes.

Looking at the Xaml, the fact you are scaling is probably it, rather than animating the width value.

<DoubleAnimationUsingKeyFrames Storyboard.TargetName="SwitchKnobOff" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleX)">
    <!-- 1.42 is relative scale from 12px to 17px -->
    <SplineDoubleKeyFrame KeyTime="0:0:0.25" KeySpline="0.0,0.0 0.0,1.0" Value="1.42" />
</DoubleAnimationUsingKeyFrames>

You can do the same shape with a Border control, with Background and CornerRadius values. That may animate differently.

image
Rectangle in Green - Border in Blue

Also, the Pressed animation should probably anchor to the left or right, depending on whether the control is ON or OFF. So it expands from the edge, rather than scaling from the middle of the Thumb. That works fine when used in the PointerOver state, and works well as it is a Circle at that point.

@mdtauk
Copy link
Contributor

mdtauk commented Dec 29, 2020

A motion mockup

ToggleSwitch.Motion.mp4

@karkarl
Copy link
Contributor Author

karkarl commented Jan 4, 2021

Looking at the Xaml, the fact you are scaling is probably it, rather than animating the width value.

@mdtauk I opted to use ScaleX and Y transformations to not make it an independent animation out of concerns for performance. But you're right, it looks WAY better, so may be a worthwhile compromise.

@karkarl
Copy link
Contributor Author

karkarl commented Jan 4, 2021

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@ranjeshj
Copy link
Contributor

ranjeshj commented Jan 7, 2021

@karenbtlai can you merge with latest? That should fix the build failure.

@karkarl karkarl force-pushed the user/karenlai/ToggleSwitchUpdate branch from c3a98d4 to ce6b761 Compare January 7, 2021 19:13
@karkarl
Copy link
Contributor Author

karkarl commented Jan 7, 2021

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@karkarl
Copy link
Contributor Author

karkarl commented Jan 7, 2021

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@ranjeshj
Copy link
Contributor

ranjeshj commented Jan 8, 2021

Please move this into master branch.

</ObjectAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="SwitchKnobOn" Storyboard.TargetProperty="Width" EnableDependentAnimation="True" >
<SplineDoubleKeyFrame KeyTime="0:0:0.25" KeySpline="0.0,0.0 0.0,1.0" Value="12" />
Copy link
Contributor

Choose a reason for hiding this comment

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

Wondering if this number can be defined an x:double somewhere else? (Same with 14 and 17 below.) -- in case it's related to other sizes.

Copy link
Contributor

@mdtauk mdtauk Jan 11, 2021

Choose a reason for hiding this comment

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

Wondering if this number can be defined an x:double somewhere else? (Same with 14 and 17 below.) -- in case it's related to other sizes.

You could, but the ToggleSwitch is a pretty unique control design, and it does not support resizing like other controls, so it would not be changed commonly. So making them generalised resources, would not be super helpful.

Having said that, if the Thumb's size at rest is changeable with lightweight styling, the PointerOver, Pressed, and Disabled sizes could be added. But they would still be something like:
ToggleSwitchKnobDefaultSize
ToggleSwitchKnobPointerOverSize
ToggleSwitchKnobPressedSize
ToggleSwitchKnobDisabledSize

You would want to do the same with the SliderThumbSizes, and the RadioButtonCheckMarkSize etc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The 12px and 14px sizes are the same as RadioButtons and SliderThumbs. That also poses the question whether that should those be a shared resource?

Copy link
Contributor

Choose a reason for hiding this comment

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

The 12px and 14px sizes are the same as RadioButtons and SliderThumbs. That also poses the question whether that should those be a shared resource?

In that case, you could have a generalised value with the pixel sizes - but then use Lightweight styles for the controls, which reference those generalised values.

This would allow developers an easy way to modify the controls, if say they wanted to have the Slider Thumb parts be larger.

It is a little more complicated with some animations as you are putting in scale factors, rather than discreet values.

@karkarl karkarl force-pushed the user/karenlai/ToggleSwitchUpdate branch from f6a9c8d to 20f687e Compare January 12, 2021 01:37
@karkarl karkarl changed the base branch from feature/token-experiment to master January 12, 2021 01:38
@karkarl
Copy link
Contributor Author

karkarl commented Jan 12, 2021

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@karkarl karkarl merged commit 67149eb into master Jan 21, 2021
@karkarl karkarl deleted the user/karenlai/ToggleSwitchUpdate branch January 21, 2021 19:06
Kinnara added a commit to Kinnara/ModernWpf that referenced this pull request Nov 6, 2022
Kinnara added a commit to Kinnara/ModernWpf that referenced this pull request Nov 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-ToggleSwitch team-Controls Issue for the Controls team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants