-
Notifications
You must be signed in to change notification settings - Fork 133
[RangeSelector] Add support for vertical orientation #756
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
Merged
Arlodotexe
merged 24 commits into
CommunityToolkit:main
from
Illustar0:feat/allow-vertical-rangeselector
Feb 10, 2026
Merged
Changes from 13 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
8713493
feat: add vertical orientation support for RangeSelector control
Illustar0 b7d3028
fix: add missing sample
Illustar0 c701fee
fix: correct vertical normalized position calculation logic
Illustar0 dbdd1ea
refactor: simplify orientation check using ternary expression
Illustar0 db727ca
fix: prevent multiple subscriptions to Loaded event
Illustar0 fbd0f46
feat: implement vertical tooltip placement for RangeSelector control
Illustar0 a853889
fix: use DesiredSize.Height for tooltip measurement
Illustar0 a8b61fc
fix: prevent tooltip from showing when vertical placement is not set
Illustar0 b540174
fix: correct keyboard navigation for RTL contexts
Illustar0 3c9e8fe
feat: add orientation toggle and fix vertical mode layout issues
Illustar0 05c3b66
refactor: remove separate vertical RangeSelector sample
Illustar0 282b30f
fix: set vertical RangeSelector sample Minimum to 0
Illustar0 9074b65
refactor: introduce UVPoint helper to eliminate orientation-dependent…
Illustar0 b403a0f
feat: add UVCoord helper struct for orientation-aware coordinates
Illustar0 3983082
refactor: migrate from UVPoint to UVCoord for coordinate handling
Illustar0 391838e
refactor: remove deprecated UVPoint helper
Illustar0 30d83e1
docs: add comments explaining vertical drag logic
Illustar0 8036bca
fix: replace null suppression with null checks in DragWidth
Illustar0 54ddd70
Ran xaml styler
Arlodotexe fbd8884
Merge branch 'main' into feat/allow-vertical-rangeselector
Arlodotexe 3b334d3
feat: implement IEquatable for UVCoord
Illustar0 6df2913
Fixed nullability error on Equals method
Arlodotexe 7248ea7
Added missing XMLDoc comments
Arlodotexe fbae157
Fixed "'HashCode' does not exist" error on uap
Arlodotexe 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
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
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
237 changes: 237 additions & 0 deletions
237
components/RangeSelector/src/RangeSelector.Helpers.UVPoint.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,237 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| namespace CommunityToolkit.WinUI.Controls; | ||
|
|
||
| /// <summary> | ||
| /// A helper struct that abstracts orientation-dependent coordinate handling. | ||
| /// U represents the primary axis (X for horizontal, Y for vertical). | ||
| /// V represents the secondary axis (Y for horizontal, X for vertical). | ||
| /// </summary> | ||
| internal readonly struct UVPoint | ||
| { | ||
| /// <summary> | ||
| /// Gets the orientation this point is configured for. | ||
| /// </summary> | ||
| public Orientation Orientation { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the primary axis coordinate (X for horizontal, Y for vertical). | ||
| /// </summary> | ||
| public double U { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the secondary axis coordinate (Y for horizontal, X for vertical). | ||
| /// </summary> | ||
| public double V { get; } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="UVPoint"/> struct. | ||
| /// </summary> | ||
| /// <param name="orientation">The orientation context.</param> | ||
| /// <param name="u">The primary axis value.</param> | ||
| /// <param name="v">The secondary axis value.</param> | ||
| public UVPoint(Orientation orientation, double u, double v = 0) | ||
| { | ||
| Orientation = orientation; | ||
| U = u; | ||
| V = v; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the X coordinate (U for horizontal, V for vertical). | ||
| /// </summary> | ||
| public double X => Orientation == Orientation.Horizontal ? U : V; | ||
|
|
||
| /// <summary> | ||
| /// Gets the Y coordinate (V for horizontal, U for vertical). | ||
| /// </summary> | ||
| public double Y => Orientation == Orientation.Horizontal ? V : U; | ||
|
|
||
| /// <summary> | ||
| /// Creates a UVPoint from a Point with the specified orientation. | ||
| /// </summary> | ||
| /// <param name="point">The point in X/Y coordinates.</param> | ||
| /// <param name="orientation">The orientation context.</param> | ||
| /// <returns>A new UVPoint with converted coordinates.</returns> | ||
| public static UVPoint FromPoint(Point point, Orientation orientation) | ||
| { | ||
| return orientation == Orientation.Horizontal | ||
| ? new UVPoint(orientation, point.X, point.Y) | ||
| : new UVPoint(orientation, point.Y, point.X); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Converts this UVPoint to a Point in X/Y coordinates. | ||
| /// </summary> | ||
| /// <returns>A Point with X/Y coordinates.</returns> | ||
| public Point ToPoint() => new Point(X, Y); | ||
|
|
||
| /// <summary> | ||
| /// Creates a new UVPoint with the specified U value, preserving V and orientation. | ||
| /// </summary> | ||
| /// <param name="u">The new U value.</param> | ||
| /// <returns>A new UVPoint with the updated U value.</returns> | ||
| public UVPoint WithU(double u) => new UVPoint(Orientation, u, V); | ||
|
|
||
| /// <summary> | ||
| /// Creates a new UVPoint with the specified V value, preserving U and orientation. | ||
| /// </summary> | ||
| /// <param name="v">The new V value.</param> | ||
| /// <returns>A new UVPoint with the updated V value.</returns> | ||
| public UVPoint WithV(double v) => new UVPoint(Orientation, U, v); | ||
Illustar0 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
Illustar0 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /// <summary> | ||
| /// Extension methods for UVPoint operations on UI elements. | ||
| /// </summary> | ||
| internal static class UVPointExtensions | ||
| { | ||
| /// <param name="element">The element to position.</param> | ||
| extension(UIElement? element) | ||
| { | ||
| /// <summary> | ||
| /// Sets the Canvas position of an element using UVPoint coordinates. | ||
| /// For horizontal: sets Canvas.Left from U. | ||
| /// For vertical: sets Canvas.Top from U. | ||
| /// </summary> | ||
| /// <param name="point">The UVPoint containing position data.</param> | ||
| public void SetCanvasU(UVPoint point) | ||
| { | ||
| if (element == null) return; | ||
|
|
||
| if (point.Orientation == Orientation.Horizontal) | ||
| { | ||
| Canvas.SetLeft(element, point.U); | ||
| } | ||
| else | ||
| { | ||
| Canvas.SetTop(element, point.U); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the Canvas position of an element as a U coordinate. | ||
| /// For horizontal: returns Canvas.Left. | ||
| /// For vertical: returns Canvas.Top. | ||
| /// </summary> | ||
| /// <param name="orientation">The orientation context.</param> | ||
| /// <returns>The position along the primary axis.</returns> | ||
| public double GetCanvasU(Orientation orientation) | ||
| { | ||
| if (element == null) return 0; | ||
|
|
||
| return orientation == Orientation.Horizontal | ||
| ? Canvas.GetLeft(element) | ||
| : Canvas.GetTop(element); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Clears the Canvas position property for the primary axis. | ||
| /// For horizontal: clears Canvas.Left. | ||
| /// For vertical: clears Canvas.Top. | ||
| /// </summary> | ||
| /// <param name="orientation">The orientation context.</param> | ||
| public void ClearCanvasU(Orientation orientation) | ||
| { | ||
| if (element == null) return; | ||
|
|
||
| if (orientation == Orientation.Horizontal) | ||
| { | ||
| element.ClearValue(Canvas.LeftProperty); | ||
| } | ||
| else | ||
| { | ||
| element.ClearValue(Canvas.TopProperty); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Clears the Canvas position property for the secondary axis. | ||
| /// For horizontal: clears Canvas.Top. | ||
| /// For vertical: clears Canvas.Left. | ||
| /// </summary> | ||
| /// <param name="orientation">The orientation context.</param> | ||
| public void ClearCanvasV(Orientation orientation) | ||
| { | ||
| if (element == null) return; | ||
|
|
||
| if (orientation == Orientation.Horizontal) | ||
| { | ||
| element.ClearValue(Canvas.TopProperty); | ||
| } | ||
| else | ||
| { | ||
| element.ClearValue(Canvas.LeftProperty); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// <param name="element">The element to measure.</param> | ||
| extension(FrameworkElement? element) | ||
| { | ||
| /// <summary> | ||
| /// Gets the size along the primary axis (Width for horizontal, Height for vertical). | ||
| /// </summary> | ||
| /// <param name="orientation">The orientation context.</param> | ||
| /// <returns>The size along the primary axis.</returns> | ||
| public double GetSizeU(Orientation orientation) | ||
| { | ||
| if (element == null) return 0; | ||
|
|
||
| return orientation == Orientation.Horizontal | ||
| ? element.Width | ||
| : element.Height; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the actual size along the primary axis (ActualWidth for horizontal, ActualHeight for vertical). | ||
| /// </summary> | ||
| /// <param name="orientation">The orientation context.</param> | ||
| /// <returns>The actual size along the primary axis.</returns> | ||
| public double GetActualSizeU(Orientation orientation) | ||
| { | ||
| if (element == null) return 0; | ||
|
|
||
| return orientation == Orientation.Horizontal | ||
| ? element.ActualWidth | ||
| : element.ActualHeight; | ||
| } | ||
| } | ||
Illustar0 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /// <summary> | ||
| /// Gets the desired size along the primary axis from DesiredSize. | ||
| /// </summary> | ||
| /// <param name="element">The element to measure.</param> | ||
| /// <param name="orientation">The orientation context.</param> | ||
| /// <returns>The desired size along the primary axis.</returns> | ||
| public static double GetDesiredSizeU(this UIElement? element, Orientation orientation) | ||
| { | ||
| if (element == null) return 0; | ||
|
|
||
| return orientation == Orientation.Horizontal | ||
| ? element.DesiredSize.Width | ||
| : element.DesiredSize.Height; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Sets the size along the primary axis (Width for horizontal, Height for vertical). | ||
| /// </summary> | ||
| /// <param name="element">The element to resize.</param> | ||
| /// <param name="orientation">The orientation context.</param> | ||
| /// <param name="size">The size value to set.</param> | ||
| public static void SetSizeU(this FrameworkElement? element, Orientation orientation, double size) | ||
| { | ||
| if (element == null) return; | ||
|
|
||
| if (orientation == Orientation.Horizontal) | ||
| { | ||
| element.Width = size; | ||
| } | ||
| else | ||
| { | ||
| element.Height = size; | ||
| } | ||
| } | ||
Illustar0 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
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.