Repository navigation
Adding markers to the scrubber. - #318
Conversation
This is a rewrite of the Scrubber to support markers. It also is a much nicer implementation of the scrubber that reuses more of the XAML Slider functionality, and reduces the amount of copied XAML from the default Slider style (from generic.xaml). As I was adding this change, it became apparent that the way the XAML slider draws its track would not work well with markers at 0.0 or 1.0 because the track ends up extending before and after the 0.0 and 1.0 positions which would make the markers look like they were incorrectly placed. So now we do all of the drawing (track, decrease rectangle, and thumb) using Composition. We also now mimic the mouse-over behavior of Slider so that the control feels a little more engaging. This required hooking Composition into the VisualStateManager, which is achieved by replacing the default VisualStateManager with our own implementation.
| Foreground="{ThemeResource SliderHeaderForeground}" | ||
| Margin="{ThemeResource SliderTopHeaderMargin}" | ||
| TextWrapping="Wrap" | ||
| Visibility="Collapsed" |
There was a problem hiding this comment.
Visibility="Collapsed" [](start = 30, length = 24)
For the elements that are not visible (or with opacity 0), they need to remain in the template because the slider control will reference them? #Closed
There was a problem hiding this comment.
Yes. I've removed some that I was confident about. I removed some others and got bitten by crashes when they were referenced by the Slider. There are probably more that can be removed but I don't feel confident about them. We're already cheaper than a normal slider as a result of removing some of the things from the template.
In reply to: 463148127 [](ancestors = 463148127)
| Grid.Row="2" | ||
| Grid.ColumnSpan="3" /> | ||
|
|
||
| <!-- The Width of the Thumb has been modified to make it round. --> |
There was a problem hiding this comment.
modified to make it round. [](start = 69, length = 26)
Is it needed coz looks like the thumb is transparent? #Closed
There was a problem hiding this comment.
The thumb is receiving the input. It just isn't visible. So yes, it's needed.
Also, some components in the template need to be there even if they're not visible because the Slider will try to reference them.
In reply to: 463150427 [](ancestors = 463150427)
| // Update the size of the progress rectangle and the position of the thumb. | ||
| _properties.InsertScalar("Width", (float)sliderWidth); | ||
|
|
||
| // Update the positio of the markers. |
There was a problem hiding this comment.
positio [](start = 26, length = 7)
position #Closed
We need to be able to handle TrimmedAnimatables that are initialized with a default value.
| Opacity="0" | ||
| Style="{StaticResource SliderThumbStyle}" | ||
| DataContext="{TemplateBinding Value}" | ||
| Height="20" |
There was a problem hiding this comment.
Height="20" [](start = 40, length = 11)
Is there a default ThemeResource height you can use for this? Or, is this a modified height to keep the thumb round (along with the width)? #Closed
There was a problem hiding this comment.
It is supposed to be the same shape as the slider we draw, which is not theme aware.
In reply to: 463298421 [](ancestors = 463298421)
| markers: Colors.White, | ||
| thumbFill: GetResourceBrushColor("LottieBasicBrush"), | ||
| thumbStroke: GetResourceBrushColor("LottieBasicBrush"), | ||
| track: GetResourceBrushColor("SliderTrackFillPointerOver"), |
There was a problem hiding this comment.
"SliderTrackFillPointerOver" [](start = 53, length = 28)
"SliderTrackFillPressed" for case "Pressed"? #Closed
There was a problem hiding this comment.
I don't know how to press the slider, and I'm fine with it not changing colors. This makes it simpler than trying to handle the pressed state explicitly.
In reply to: 463305999 [](ancestors = 463305999)
| switch (e.Action) | ||
| { | ||
| case NotifyCollectionChangedAction.Add: | ||
| // Add rectangles to display each marker. There are 2 rectangle - one |
There was a problem hiding this comment.
rectangle [](start = 74, length = 9)
"rectangles" #Closed
| Maximum="1" | ||
| StepFrequency="0.0001" | ||
| SmallChange="0.001" | ||
| AutomationProperties.Name="Progress slider"> |
There was a problem hiding this comment.
nit: rename to ProgressSlider #ByDesign
There was a problem hiding this comment.
This is a copy of the automation name that was given by another contributor. I don't know the rules for these names - is it supposed to be a single word?
In reply to: 465417002 [](ancestors = 465417002)
There was a problem hiding this comment.
Discussed privately - WinUI team makes these a single Pascal-cased word, so we'll do the same.s
In reply to: 465910831 [](ancestors = 465910831,465417002)
There was a problem hiding this comment.
But that would go against MSDN official advice: https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.automation.automationproperties.nameproperty?view=winrt-19041
"The Name property should be the same as the label text on screen."
We wouldn't smoosh and Pascal-case label text.
We don't have a label for this slider, but the name should correspond with the label that we would use if there were a label.
In reply to: 465975160 [](ancestors = 465975160,465910831,465417002)
| _decreaseRectangleBrush = CreateBoundColorBrush(_properties, "DecreaseRectangleColor"); | ||
|
|
||
| // Create the track rectangle. This is the track that the thumb moves along. | ||
| _trackRectangle = c.CreateSpriteVisual(); |
There was a problem hiding this comment.
I'm curious why the trackRectangle and decreaseRectangle have to be initialized in code behind when it's already set in the template? #Resolved
There was a problem hiding this comment.
They're not the same object. The template contains the XAML Rectangles, but with opacity=0 so they don't show up. We use Composition to draw the UI, but XAML to receive the input. Composition SpriteVisuals can be animated via expressions that respond to changes on other Composition object. The problem this solves is making the slider move while the Lottie is playing. When the Lottie is playing, there's no code running in the LottieViewer process, so we can't animate the XAML Rectangles.
In reply to: 465905081 [](ancestors = 465905081)
|
|
||
| void SetColors(Color markers, Color thumbFill, Color thumbStroke, Color track, Color decreaseRectangle) | ||
| { | ||
| _markerBrush.Color = markers; |
There was a problem hiding this comment.
I'm curious as to why colours are set in code behind? The brushes are already set in the VisualStateManager in xaml, thus you can update colours through updating the VisualState. #Resolved
There was a problem hiding this comment.
Different brush - this is updating the Composition objects, not the XAML objects.
In reply to: 465914466 [](ancestors = 465914466)
This is a rewrite of the Scrubber to support markers. It also is a much nicer implementation of the
scrubber that reuses more of the XAML Slider functionality, and reduces the amount of copied XAML from
the default Slider style (from generic.xaml).
As I was adding this change, it became apparent that the way the XAML slider draws its track would
not work well with markers at 0.0 or 1.0 because the track ends up extending before and after the
0.0 and 1.0 positions which would make the markers look like they were incorrectly placed. So now
we do all of the drawing (track, decrease rectangle, and thumb) using Composition.
We also now mimic the mouse-over behavior of Slider so that the control feels a little more engaging.
This required hooking Composition into the VisualStateManager, which is achieved by replacing the
default VisualStateManager with our own implementation.