Repository navigation
[Slider] Custom track, ticker, and overlay shape painters - #25008
Conversation
fee0205 to
8aaf7b9
Compare
johnsonmh
left a comment
There was a problem hiding this comment.
Looks good, I just had a bunch of nits but it's really just the same 2/3 things.
|
Updated, PTAL |
|
You will need to add tests before you commit, but it looks OK to me. Also, it would be nice to add to the "custom slider" demo in the Flutter gallery app to show a simple customization of the track, etc. |
|
I added tests, and am going to update the gallery with examples next (sep PR) |
HansMuller
left a comment
There was a problem hiding this comment.
Still working on this. Progress report :-)
There was a problem hiding this comment.
I think it's sufficient to say that it's the default [Slider] track shape.
Is it the default value of SliderThemeData.trackShape?
There was a problem hiding this comment.
Technically it is the default shape of the SliderThemeData.fromPrimaryColors ctor which is the default for the Theme. I copied the description directly from the 2 existing default shapes (RoundThumb and PaddleValueIndicator). Can cover this in #25672 as well
HansMuller
left a comment
There was a problem hiding this comment.
More feedback that's mostly about the docs. Adding this much new API requires adding a commensurate amount of helpful documentation.
There was a problem hiding this comment.
This isn't really helpful (if it is helpful then the reader is out of their depth).
It might be worth pointing out how he trackShape's preferred size contribute's to the slider's overall preferred size.
It would be worth pointing out that the default value of trackShape is RectangularSliderTrackShape.
There was a problem hiding this comment.
I was following the pattern of the other existing components here. If I remove "This can be customized by implementing a subclass of Foo" from the 3 new components, should I also take it away from the existing 2?
There was a problem hiding this comment.
It might be worth pointing out how he trackShape's preferred size contribute's to the slider's overall preferred size.
It doesn't actually do that in this change.
The default track size paints relative to the size of the parent box, but it subtracts out the size largest overlapping piece: the overlay. The intrinsic sizes are dependent on the overlay, thumb, and value indicators. The track shape's preferredRect is used inside the Slider class for:
- Tap gesture points to thumb position range, where 0.0 is track.left and 1.0 is track.right.
- The thumb center and discrete tick centers for their shape painters.
I added these as doc comments, but will go in more detail once I get to the actual SliderTrackShape doc comments.
It would be worth pointing out that the default value of trackShape is RectangularSliderTrackShape.
Done
There was a problem hiding this comment.
Doesn't define behavior.
The size and shape of the each [Slider] tick.
There was a problem hiding this comment.
Will resolve from above question:
I was following the pattern of the other existing components here. If I remove "This can be customized by implementing a subclass of Foo" from the 3 new components, should I also take it away from the existing 2?
There was a problem hiding this comment.
No need to fix them up in this PR. Filing an issue, so that the work happens eventually, would be helpful.
There was a problem hiding this comment.
Done, I ended up keeping some comments consistent by updating the, and some constsent by leaving tham as is, but I have filed #25672 to further improve the docs, and create a diagram
|
Ready for next review, PTAL |
There was a problem hiding this comment.
This is still hard to understand. This "overlay" is the temporary highlight that appears around the slider's thumb when the thumb is pressed and dragged?
There was a problem hiding this comment.
Yeah overlay was an existing term used within this class. The spec does not call it anything specifically, but it is visible when the thumb is pressed, focused, or hovered.
I added a little more description.
There was a problem hiding this comment.
Why does this method have an isEnabled parameter?
There was a problem hiding this comment.
In case a developer wants the track size for enabled/disabled to be different
There was a problem hiding this comment.
The conventional boilerplate for see also references like this is:
[RectangularSliderTrackShape], which default track shape.
There was a problem hiding this comment.
Fixed through out
There was a problem hiding this comment.
If this is just the value of Slider.isInteractive, why isn't the parameter called isInteractive?
There was a problem hiding this comment.
The correct terminology is "enabled" and "disabled", but isInteractive already exists within slider.dart. It is already correctly referred to as isEnabled in other places slider_theme.dart, so I am continuing with that. Ideally, it would be refactored to isEnabled, enabled, disabled, etc in slider.dart as well.
https://material.io/design/components/sliders.html#continuous-slider
see "States" ^
|
One other thing: the SliderTheme "see also" doc should mention the new shape values. |
8f575f9 to
5d08a96
Compare
There was a problem hiding this comment.
Looks like there are still comments from the last review that need to be addressed. Before submitting for another review, please read everything carefully:
- Watch out for obvious typos and indentos.
- Don't document methods or properties by reiterating the name.
- Make sure all feedback has been addressed.
There was a problem hiding this comment.
This appears to assume that the centers of the 3 shapes will be aligned. That doesn't seem correct?
There was a problem hiding this comment.
This makes more sense then the original; not clear why _overlayRadius was used. On the other hand the code was known to work ... any idea why we used to subtract _overlayRadius?
There was a problem hiding this comment.
Because the track was always padded from the slider edges by the overlay radius, but now that is encapsulated in the _trackRect
There was a problem hiding this comment.
Is the original comment obsolete now?
It looks like the underlying assumption here is that the thumb/overlay/tick could extend horizontally past both ends of the track by 50%. If that's correct, it would be helpful to say as much.
There was a problem hiding this comment.
computeMaxIntrinsicWidth isn't supposed to be called directly (see https://docs.flutter.io/flutter/rendering/RenderBox/computeMaxIntrinsicWidth.html), call getMaxIntrinsicWith().
There was a problem hiding this comment.
[isEnabled] has the same value as [Slider.isInteractive]. If true the slider will respond to input.
There was a problem hiding this comment.
Please don't just reiterate the name of a property as its definition.
There was a problem hiding this comment.
This param no longer exists, removed
There was a problem hiding this comment.
Moved a lot of these things to macros too
There was a problem hiding this comment.
The [center] offset is relative to the origin of the canvas.
There was a problem hiding this comment.
I think this comment may have to be adjusted with the macros that are now being used
3a8caa7 to
57c3b79
Compare
It mentions the abstract shapes. Should it also mention the defaults? |
HansMuller
left a comment
There was a problem hiding this comment.
This is really close. Just some simple cleanups.
| // need to padding to the track relative to the slider box itself. It is | ||
| // assumed that these shapes are vertically centered on the track. | ||
| double get _maxHorizontalTrackPadding => _sizesThatCanPadTrack.map((Size size) => size.width).reduce(math.max); | ||
| double get _maxVerticalTrackPadding => _sizesThatCanPadTrack.map((Size size) => size.width).reduce(math.max); |
There was a problem hiding this comment.
These are width and height values not really padding values. It would be clearer if they were called: maxSliderPartHeight and maxSliderPartWidth; the list below would be sliderPartSizes.
|
|
||
| @override | ||
| double computeMinIntrinsicHeight(double width) => _verticalPaddingFromShapes; | ||
| double computeMinIntrinsicHeight(double width) => _maxVerticalTrackPadding; |
There was a problem hiding this comment.
Shouldn't this be math.max(minPreferredTrackHeight, maxSliderPartHeight)
Same change in performResize
There was a problem hiding this comment.
Yes that is right. I changed it. Now the slider will size correctly if the track height is larger than the max height of the other parts.
| }); | ||
|
|
||
| testWidgets('SliderThemeData assigns the correct default shapes', (WidgetTester tester) async { | ||
| final SliderThemeData sliderTheme = _createDefaultSliderTheme(); |
There was a problem hiding this comment.
This value should be ThemeData().sliderTheme.
| ); | ||
| final SliderThemeData sliderTheme = theme.sliderTheme.copyWith(thumbColor: Colors.red.shade500); | ||
| double value = 0.25; | ||
| Widget buildApp({ |
There was a problem hiding this comment.
One line:
Widget buildApp({ bool enabled = true }) {
| bool enabled = true, | ||
| }) { | ||
| final ValueChanged<double> onChanged = enabled ? (double d) => value = d : null; | ||
| return Directionality( |
There was a problem hiding this comment.
It's OK to must build a MaterialApp/Scaffold for tests like this
There was a problem hiding this comment.
I made to be consistent with other tests (using the "Directionality -> MediaQuery -> Material -> Center -> SLiderTheme -> Slider" tree structure.) Is this one different?
There was a problem hiding this comment.
No, just a suggestion since pasting things together by hand is tedious and doesn't actually test the common case (MaterialApp/Scaffold is the common case).
…ider (flutter#25008) Create a slider shape for custom track, tick mark, and overlay painting, for the material slider.
Create a slider shape for custom track, tick mark, and overlay painting. Originally, this work was part of the larger range slider effort, but can and should work independently of having more than 1 thumb.
Without this change
With this change
CHANGES:
NEXT UP:
closes #22325