-
Notifications
You must be signed in to change notification settings - Fork 473
Feature/rangeslider #2983
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
Open
stephenquan
wants to merge
23
commits into
CommunityToolkit:main
Choose a base branch
from
stephenquan:feature/rangeslider
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feature/rangeslider #2983
Changes from 16 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
d133c31
Initial RangeSlider implementation
stephenquan 8ce2ba7
Merge branch 'CommunityToolkit:main' into feature/rangeslider
stephenquan dd9ed67
Implemented various Copilot review suggestions
stephenquan bc29d3a
Merge branch 'main' into feature/rangeslider
stephenquan 0c8df7e
Use BindableProperty source-gen. Use IsOneOf extension method. Update…
stephenquan 99f7074
Update XML doc for RangeSlider focus mode as per Copilot's suggestion
stephenquan 61cbc63
Corrected XML doc for FocusMode property as per Copilot's feedback
stephenquan 00cb4c5
Various XML doc improvements. Refactor UpdateFocusedSliderLayout for …
stephenquan 424f804
Update XML doc for PlatformThumbSize
stephenquan 3b4fe7a
Implement maxValue calculation as suggested by Copilot
stephenquan 73e1b60
Add RangeSliderTests.cs
stephenquan 1962148
Implement consistent getter for static defaults
stephenquan f20faae
Add division by zero guard. Corrected label binding in sample.
stephenquan 17f9568
Use consistent naming in event handlers
stephenquan 1533249
Move BindableProperties to top of the file. Also moved SetFocusMode. …
stephenquan 9d2e7a0
Use Loaded instead of Dispatcher.Dispatch to finalize initialization
stephenquan e211320
Revert Loaded back to Dispatcher.Dispatch
stephenquan 6a85e2f
Provider alternate constructor workaround for unit tests
stephenquan ec6346a
Improve PlatformThumbSize XML doc. Corrected spelling in test method …
stephenquan dddf6a1
Merge branch 'main' into feature/rangeslider
stephenquan f0c2269
Use new BindableProperty initializer
stephenquan d4db602
Refactor CalculateValueFromSliderValue and CalculateValueFromSliderVa…
stephenquan 760c451
Merge branch 'main' into feature/rangeslider
ne0rrmatrix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
samples/CommunityToolkit.Maui.Sample/Pages/Views/RangeSlider/RangeSliderPage.xaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| <?xml version="1.0" encoding="utf-8" ?> | ||
| <pages:BasePage | ||
| x:Class="CommunityToolkit.Maui.Sample.Pages.Views.RangeSliderPage" | ||
| xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
| xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
| xmlns:mct="http://schemas.microsoft.com/dotnet/2022/maui/toolkit" | ||
| xmlns:pages="clr-namespace:CommunityToolkit.Maui.Sample.Pages" | ||
| xmlns:sample="clr-namespace:CommunityToolkit.Maui.Sample" | ||
| xmlns:viewModels="clr-namespace:CommunityToolkit.Maui.Sample.ViewModels.Views" | ||
| Title="RangeSlider" | ||
| Padding="12,12,12,0" | ||
| x:DataType="viewModels:RangeSliderViewModel" | ||
| x:TypeArguments="viewModels:RangeSliderViewModel"> | ||
|
|
||
| <ScrollView> | ||
| <VerticalStackLayout Spacing="10"> | ||
| <VerticalStackLayout.Resources> | ||
| <ResourceDictionary> | ||
| <Style x:Key="Heading" TargetType="Label"> | ||
| <Setter Property="VerticalTextAlignment" Value="Center" /> | ||
| <Setter Property="HorizontalTextAlignment" Value="Center" /> | ||
| <Setter Property="FontSize" Value="12" /> | ||
| <Setter Property="HorizontalOptions" Value="Center" /> | ||
| <Setter Property="LineBreakMode" Value="WordWrap" /> | ||
| <Setter Property="Margin" Value="10" /> | ||
| </Style> | ||
| <Style x:Key="HR" TargetType="Line"> | ||
| <Setter Property="Stroke" Value="{AppThemeBinding Light=Black, Dark=White}" /> | ||
| <Setter Property="X2" Value="300" /> | ||
| <Setter Property="HorizontalOptions" Value="Center" /> | ||
| </Style> | ||
| </ResourceDictionary> | ||
| </VerticalStackLayout.Resources> | ||
|
|
||
| <Label Style="{StaticResource Heading}" Text="Simple RangeSlider" /> | ||
|
|
||
| <Grid ColumnDefinitions="50,*,50" ColumnSpacing="10"> | ||
| <Label Text="{Binding SimpleLowerValue, StringFormat='{}{0:F1}'}" VerticalOptions="Center" /> | ||
| <mct:RangeSlider | ||
| Grid.Column="1" | ||
| HorizontalOptions="Fill" | ||
| LowerValue="{Binding SimpleLowerValue, Mode=TwoWay}" | ||
| MaximumValue="200" | ||
| MinimumValue="100" | ||
| UpperValue="{Binding SimpleUpperValue, Mode=TwoWay}" | ||
| WidthRequest="-1" /> | ||
| <Label | ||
| Grid.Column="2" | ||
| Text="{Binding SimpleUpperValue, StringFormat='{}{0:F1}'}" | ||
| VerticalOptions="Center" /> | ||
| </Grid> | ||
|
|
||
| <Line Style="{StaticResource HR}" /> | ||
|
|
||
| <Label Style="{StaticResource Heading}" Text="RangeSlider with StepSize" /> | ||
|
|
||
| <Grid ColumnDefinitions="50,*,50" ColumnSpacing="10"> | ||
| <Label Text="{Binding LowerValueWithStep, StringFormat='{}{0:F1}'}" VerticalOptions="Center" /> | ||
| <Border Grid.Column="1" HorizontalOptions="Fill"> | ||
| <mct:RangeSlider | ||
| HorizontalOptions="Fill" | ||
| LowerValue="{Binding LowerValueWithStep, Mode=TwoWay}" | ||
| MaximumValue="200" | ||
| MinimumValue="100" | ||
| StepSize="5" | ||
| UpperValue="{Binding UpperValueWithStep, Mode=TwoWay}" | ||
| WidthRequest="-1" /> | ||
| </Border> | ||
| <Label | ||
| Grid.Column="2" | ||
| Text="{Binding UpperValueWithStep, StringFormat='{}{0:F1}'}" | ||
| VerticalOptions="Center" /> | ||
| </Grid> | ||
|
|
||
| <Line Style="{StaticResource HR}" /> | ||
|
|
||
| <Label Style="{StaticResource Heading}" Text="RangeSlider with Minimum/Maximum swapped for descending behavior" /> | ||
|
|
||
| <Grid ColumnDefinitions="50,*,50" ColumnSpacing="10"> | ||
| <Label Text="{Binding LowerValueDescending, StringFormat='{}{0:F1}'}" VerticalOptions="Center" /> | ||
| <Border Grid.Column="1" HorizontalOptions="Fill"> | ||
| <mct:RangeSlider | ||
| HorizontalOptions="Fill" | ||
| LowerValue="{Binding LowerValueDescending, Mode=TwoWay}" | ||
| MaximumValue="100" | ||
| MinimumValue="200" | ||
| UpperValue="{Binding UpperValueDescending, Mode=TwoWay}" | ||
| WidthRequest="-1" /> | ||
| </Border> | ||
| <Label | ||
| Grid.Column="2" | ||
| Text="{Binding UpperValueDescending, StringFormat='{}{0:F1}'}" | ||
| VerticalOptions="Center" /> | ||
| </Grid> | ||
|
|
||
| <Line Style="{StaticResource HR}" /> | ||
|
|
||
| <Label Style="{StaticResource Heading}" Text="RangeSlider with Minimum/Maximum swapped for descending with step behavior" /> | ||
|
|
||
| <Grid ColumnDefinitions="50,*,50" ColumnSpacing="10"> | ||
| <Label Text="{Binding LowerValueDescendingWithStep, StringFormat='{}{0:F1}'}" VerticalOptions="Center" /> | ||
| <Border Grid.Column="1" HorizontalOptions="Fill"> | ||
| <mct:RangeSlider | ||
| HorizontalOptions="Fill" | ||
| LowerValue="{Binding LowerValueDescendingWithStep, Mode=TwoWay}" | ||
| MaximumValue="100" | ||
| MinimumValue="200" | ||
| StepSize="5" | ||
| UpperValue="{Binding UpperValueDescendingWithStep, Mode=TwoWay}" | ||
| WidthRequest="-1" /> | ||
| </Border> | ||
| <Label | ||
| Grid.Column="2" | ||
| Text="{Binding UpperValueDescendingWithStep, StringFormat='{}{0:F1}'}" | ||
| VerticalOptions="Center" /> | ||
| </Grid> | ||
|
|
||
| <Line Style="{StaticResource HR}" /> | ||
|
|
||
| <Label Style="{StaticResource Heading}" Text="RangeSlider with custom thumb and track colors" /> | ||
|
|
||
| <Grid ColumnDefinitions="50,*,50" ColumnSpacing="10"> | ||
| <Label Text="{Binding LowerValueWithCustomStyle, StringFormat='{}{0:F1}'}" VerticalOptions="Center" /> | ||
| <Border Grid.Column="1" HorizontalOptions="Fill"> | ||
| <mct:RangeSlider | ||
| HorizontalOptions="Fill" | ||
| InnerTrackColor="Orange" | ||
| InnerTrackCornerRadius="5" | ||
| InnerTrackSize="10" | ||
| LowerThumbColor="Red" | ||
| LowerValue="{Binding LowerValueWithCustomStyle, Mode=TwoWay}" | ||
| MaximumValue="200" | ||
| MinimumValue="100" | ||
| OuterTrackColor="DarkGray" | ||
| OuterTrackCornerRadius="7" | ||
| OuterTrackSize="14" | ||
| UpperThumbColor="Green" | ||
| UpperValue="{Binding UpperValueWithCustomStyle, Mode=TwoWay}" | ||
| WidthRequest="-1" /> | ||
| </Border> | ||
| <Label | ||
| Grid.Column="2" | ||
| Text="{Binding UpperValueWithCustomStyle, StringFormat='{}{0:F1}'}" | ||
| VerticalOptions="Center" /> | ||
| </Grid> | ||
|
|
||
| </VerticalStackLayout> | ||
| </ScrollView> | ||
| </pages:BasePage> |
11 changes: 11 additions & 0 deletions
11
samples/CommunityToolkit.Maui.Sample/Pages/Views/RangeSlider/RangeSliderPage.xaml.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| using CommunityToolkit.Maui.Sample.ViewModels.Views; | ||
|
|
||
| namespace CommunityToolkit.Maui.Sample.Pages.Views; | ||
|
|
||
| public partial class RangeSliderPage : BasePage<RangeSliderViewModel> | ||
| { | ||
| public RangeSliderPage(RangeSliderViewModel viewModel) : base(viewModel) | ||
| { | ||
| InitializeComponent(); | ||
| } | ||
| } |
36 changes: 36 additions & 0 deletions
36
samples/CommunityToolkit.Maui.Sample/ViewModels/Views/RangeSliderViewModel.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| using CommunityToolkit.Mvvm.ComponentModel; | ||
|
|
||
| namespace CommunityToolkit.Maui.Sample.ViewModels.Views; | ||
|
|
||
| public partial class RangeSliderViewModel : BaseViewModel | ||
| { | ||
| [ObservableProperty] | ||
| public partial double SimpleLowerValue { get; set; } = 125; | ||
|
|
||
| [ObservableProperty] | ||
| public partial double SimpleUpperValue { get; set; } = 175; | ||
stephenquan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| [ObservableProperty] | ||
| public partial double LowerValueWithCustomStyle { get; set; } = 125; | ||
|
|
||
| [ObservableProperty] | ||
| public partial double UpperValueWithCustomStyle { get; set; } = 175; | ||
|
|
||
| [ObservableProperty] | ||
| public partial double LowerValueWithStep { get; set; } = 125; | ||
|
|
||
| [ObservableProperty] | ||
| public partial double UpperValueWithStep { get; set; } = 175; | ||
|
|
||
| [ObservableProperty] | ||
| public partial double LowerValueDescending { get; set; } = 175; | ||
|
|
||
| [ObservableProperty] | ||
| public partial double UpperValueDescending { get; set; } = 125; | ||
|
|
||
| [ObservableProperty] | ||
| public partial double LowerValueDescendingWithStep { get; set; } = 175; | ||
|
|
||
| [ObservableProperty] | ||
| public partial double UpperValueDescendingWithStep { get; set; } = 125; | ||
pictos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
src/CommunityToolkit.Maui.Core/Primitives/Defaults/RangeSliderDefaults.shared.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| namespace CommunityToolkit.Maui.Core; | ||
|
|
||
| /// <summary> | ||
| /// Default Values for RangeSlider | ||
| /// </summary> | ||
| public static class RangeSliderDefaults | ||
| { | ||
| /// <summary> | ||
| /// Default width request | ||
| /// </summary> | ||
| public const double WidthRequest = 200; | ||
|
|
||
| /// <summary> | ||
| /// Default for Minimum Value | ||
| /// </summary> | ||
| public const double MinimumValue = 0; | ||
|
|
||
| /// <summary> | ||
| /// Default for Maximum Value | ||
| /// </summary> | ||
| public const double MaximumValue = 1; | ||
|
|
||
| /// <summary> | ||
| /// Default for Lower Value | ||
| /// </summary> | ||
| public const double LowerValue = 0; | ||
|
|
||
| /// <summary> | ||
| /// Default for Upper Value | ||
| /// </summary> | ||
| public const double UpperValue = 1; | ||
|
|
||
| /// <summary> | ||
| /// Default for Step Size | ||
| /// </summary> | ||
| public const double StepSize = 0; | ||
|
|
||
| /// <summary> | ||
| /// Default value for Lower Thumb Color | ||
| /// </summary> | ||
| public static Color LowerThumbColor { get; } = Colors.Gray; | ||
|
|
||
| /// <summary> | ||
| /// Default value for Upper Thumb Color | ||
| /// </summary> | ||
| public static Color UpperThumbColor { get; } = Colors.Gray; | ||
|
|
||
| /// <summary> | ||
| /// Default value for Track Color | ||
| /// </summary> | ||
| public static Color InnerTrackColor { get; } = Colors.Pink; | ||
|
|
||
| /// <summary> | ||
| /// Default value for Track Size | ||
| /// </summary> | ||
| public const double InnerTrackSize = 6; | ||
|
|
||
| /// <summary> | ||
| /// Default value for Inner Track Radius | ||
| /// </summary> | ||
| public static CornerRadius InnerTrackCornerRadius { get; } = new(3); | ||
|
|
||
| /// <summary> | ||
| /// Default value for Outer Track Color | ||
| /// </summary> | ||
| public static Color OuterTrackColor { get; } = Colors.LightGray; | ||
|
|
||
| /// <summary> | ||
| /// Default value for Outer Track Size | ||
| /// </summary> | ||
| public const double OuterTrackSize = 6; | ||
|
|
||
| /// <summary> | ||
| /// Default value for Outer Track Radius | ||
| /// </summary> | ||
| public static CornerRadius OuterTrackCornerRadius { get; } = new(3); | ||
|
|
||
| /// <summary> | ||
| /// Default value for Focus Mode | ||
| /// </summary> | ||
| public const RangeSliderFocusMode FocusMode = RangeSliderFocusMode.Default; | ||
| } |
20 changes: 20 additions & 0 deletions
20
src/CommunityToolkit.Maui.Core/Primitives/RangeSliderFocusMode.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| namespace CommunityToolkit.Maui.Core; | ||
|
|
||
| /// <summary> | ||
| /// Enum for RangeSlider focus mode | ||
| /// </summary> | ||
| public enum RangeSliderFocusMode | ||
| { | ||
stephenquan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /// <summary> | ||
| /// Balance the focus between the lower and upper thumbs | ||
| /// </summary> | ||
| Default, | ||
stephenquan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /// <summary> | ||
| /// The lower thumb has focus | ||
| /// </summary> | ||
| Lower, | ||
stephenquan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /// <summary> | ||
| /// The upper thumb has focus | ||
| /// </summary> | ||
| Upper, | ||
pictos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
stephenquan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Binary file added
BIN
+6.2 KB
src/CommunityToolkit.Maui.UnitTests/Views/RangeSlider/RangeSliderTests.cs
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.