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

Fixes #388 SizerBase Orientation Property #419

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 8 additions & 18 deletions components/CanvasView/src/Dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,13 @@
For UWP / WinAppSDK / Uno packages, place the package references here.
-->
<Project>
<!-- WinUI 2 / UWP -->
<ItemGroup Condition="'$(IsUwp)' == 'true'">
<PackageReference Include="Microsoft.Toolkit.Uwp.UI" Version="7.1.2"/>
</ItemGroup>
<!-- WinUI 2 / UWP / Uno -->
<ItemGroup Condition="'$(IsUwp)' == 'true' OR ('$(IsUno)' == 'true' AND '$(WinUIMajorVersion)' == '2')">
<PackageReference Include="CommunityToolkit.Uwp.Extensions" Version="8.0.0-beta.1"/>
</ItemGroup>

<!-- WinUI 2 / Uno -->
<ItemGroup Condition="'$(IsUno)' == 'true' AND '$(WinUIMajorVersion)' == '2'">
<PackageReference Include="Uno.Microsoft.Toolkit.Uwp.UI" Version="7.1.11"/>
</ItemGroup>

<!-- WinUI 3 / WinAppSdk -->
<ItemGroup Condition="'$(IsWinAppSdk)' == 'true'">
<PackageReference Include="CommunityToolkit.WinUI.UI" Version="7.1.2"/>
</ItemGroup>

<!-- WinUI 3 / Uno -->
<ItemGroup Condition="'$(IsUno)' == 'true' AND '$(WinUIMajorVersion)' == '3'">
<PackageReference Include="Uno.CommunityToolkit.WinUI.UI" Version="7.1.100-dev.15.g12261e2626"/>
</ItemGroup>
<!-- WinUI 3 / WinAppSdk / Uno -->
<ItemGroup Condition="'$(IsWinAppSdk)' == 'true' OR ('$(IsUno)' == 'true' AND '$(WinUIMajorVersion)' == '3')">
<PackageReference Include="CommunityToolkit.WinUI.Extensions" Version="8.0.0-beta.1"/>
</ItemGroup>
</Project>
26 changes: 8 additions & 18 deletions components/SegmentedControl/src/Dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,13 @@
For UWP / WinAppSDK / Uno packages, place the package references here.
-->
<Project>
<!-- WinUI 2 / UWP -->
<ItemGroup Condition="'$(IsUwp)' == 'true'">
<PackageReference Include="Microsoft.Toolkit.Uwp.UI" Version="7.1.2"/>
</ItemGroup>
<!-- WinUI 2 / UWP / Uno -->
<ItemGroup Condition="'$(IsUwp)' == 'true' OR ('$(IsUno)' == 'true' AND '$(WinUIMajorVersion)' == '2')">
<PackageReference Include="CommunityToolkit.Uwp.Extensions" Version="8.0.0-beta.1"/>
</ItemGroup>

<!-- WinUI 2 / Uno -->
<ItemGroup Condition="'$(IsUno)' == 'true' AND '$(WinUIMajorVersion)' == '2'">
<PackageReference Include="Uno.Microsoft.Toolkit.Uwp.UI" Version="7.1.11"/>
</ItemGroup>

<!-- WinUI 3 / WinAppSdk -->
<ItemGroup Condition="'$(IsWinAppSdk)' == 'true'">
<PackageReference Include="CommunityToolkit.WinUI.UI" Version="7.1.2"/>
</ItemGroup>

<!-- WinUI 3 / Uno -->
<ItemGroup Condition="'$(IsUno)' == 'true' AND '$(WinUIMajorVersion)' == '3'">
<PackageReference Include="Uno.CommunityToolkit.WinUI.UI" Version="7.1.100-dev.15.g12261e2626"/>
</ItemGroup>
<!-- WinUI 3 / WinAppSdk / Uno -->
<ItemGroup Condition="'$(IsWinAppSdk)' == 'true' OR ('$(IsUno)' == 'true' AND '$(WinUIMajorVersion)' == '3')">
<PackageReference Include="CommunityToolkit.WinUI.Extensions" Version="8.0.0-beta.1"/>
</ItemGroup>
</Project>
24 changes: 7 additions & 17 deletions components/SettingsControls/src/Dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,13 @@
For UWP / WinAppSDK / Uno packages, place the package references here.
-->
<Project>
<!-- WinUI 2 / UWP -->
<ItemGroup Condition="'$(IsUwp)' == 'true'">
<PackageReference Include="Microsoft.Toolkit.Uwp.UI" Version="7.1.2"/>
</ItemGroup>

<!-- WinUI 2 / Uno -->
<ItemGroup Condition="'$(IsUno)' == 'true' AND '$(WinUIMajorVersion)' == '2'">
<PackageReference Include="Uno.Microsoft.Toolkit.Uwp.UI" Version="7.1.11"/>
</ItemGroup>
<!-- WinUI 2 / UWP / Uno -->
<ItemGroup Condition="'$(IsUwp)' == 'true' OR ('$(IsUno)' == 'true' AND '$(WinUIMajorVersion)' == '2')">
<PackageReference Include="CommunityToolkit.Uwp.Extensions" Version="8.0.0-beta.1"/>
</ItemGroup>

<!-- WinUI 3 / WinAppSdk -->
<ItemGroup Condition="'$(IsWinAppSdk)' == 'true'">
<PackageReference Include="CommunityToolkit.WinUI.UI" Version="7.1.2"/>
</ItemGroup>

<!-- WinUI 3 / Uno -->
<ItemGroup Condition="'$(IsUno)' == 'true' AND '$(WinUIMajorVersion)' == '3'">
<PackageReference Include="Uno.CommunityToolkit.WinUI.UI" Version="7.1.100-dev.15.g12261e2626"/>
<!-- WinUI 3 / WinAppSdk / Uno -->
<ItemGroup Condition="'$(IsWinAppSdk)' == 'true' OR ('$(IsUno)' == 'true' AND '$(WinUIMajorVersion)' == '3')">
<PackageReference Include="CommunityToolkit.WinUI.Extensions" Version="8.0.0-beta.1"/>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<ToolkitComponentName>SizerBase</ToolkitComponentName>
<Description>This package contains SizerBase.</Description>
<Version>0.0.4</Version>
<Version>0.0.5</Version>

<!-- Rns suffix is required for namespaces shared across projects. See https://github.com/CommunityToolkit/Labs-Windows/issues/152 -->
<RootNamespace>CommunityToolkit.Labs.WinUI.SizerBaseRns</RootNamespace>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using CommunityToolkit.Labs.WinUI.SizerBaseLocal;
using CommunityToolkit.WinUI;

namespace CommunityToolkit.Labs.WinUI;

Expand Down
26 changes: 8 additions & 18 deletions components/SizerBase/src/Dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,13 @@
For UWP / WinAppSDK / Uno packages, place the package references here.
-->
<Project>
<!-- WinUI 2 / UWP -->
<ItemGroup Condition="'$(IsUwp)' == 'true'">
<!-- <PackageReference Include="Microsoft.Toolkit.Uwp.UI.Controls.Primitives" Version="7.1.2"/> -->
</ItemGroup>
<!-- WinUI 2 / UWP / Uno -->
<ItemGroup Condition="'$(IsUwp)' == 'true' OR ('$(IsUno)' == 'true' AND '$(WinUIMajorVersion)' == '2')">
<PackageReference Include="CommunityToolkit.Uwp.Extensions" Version="8.0.0-beta.1"/>
</ItemGroup>

<!-- WinUI 2 / Uno -->
<ItemGroup Condition="'$(IsUno)' == 'true' AND '$(WinUIMajorVersion)' == '2'">
<!-- <PackageReference Include="Uno.Microsoft.Toolkit.Uwp.UI.Controls.Primitives" Version="7.1.11"/> -->
</ItemGroup>

<!-- WinUI 3 / WinAppSdk -->
<ItemGroup Condition="'$(IsWinAppSdk)' == 'true'">
<!-- <PackageReference Include="CommunityToolkit.WinUI.UI.Controls.Primitives" Version="7.1.2"/> -->
</ItemGroup>

<!-- WinUI 3 / Uno -->
<ItemGroup Condition="'$(IsUno)' == 'true' AND '$(WinUIMajorVersion)' == '3'">
<!-- <PackageReference Include="Uno.CommunityToolkit.WinUI.UI.Controls.Primitives" Version="7.1.100-dev.15.g12261e2626"/> -->
</ItemGroup>
<!-- WinUI 3 / WinAppSdk / Uno -->
<ItemGroup Condition="'$(IsWinAppSdk)' == 'true' OR ('$(IsUno)' == 'true' AND '$(WinUIMajorVersion)' == '3')">
<PackageReference Include="CommunityToolkit.WinUI.Extensions" Version="8.0.0-beta.1"/>
</ItemGroup>
</Project>
18 changes: 9 additions & 9 deletions components/SizerBase/src/SizerBase.Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected override void OnManipulationStarting(ManipulationStartingRoutedEventAr
/// <inheritdoc />
protected override void OnManipulationDelta(ManipulationDeltaRoutedEventArgs e)
{
// We use Trancate here to provide 'snapping' points with the DragIncrement property
// We use Truncate here to provide 'snapping' points with the DragIncrement property
// It works for both our negative and positive values, as otherwise we'd need to use
// Ceiling when negative and Floor when positive to maintain the correct behavior.
var horizontalChange =
Expand Down Expand Up @@ -117,7 +117,7 @@ private void SizerBase_PointerReleased(object sender, PointerRoutedEventArgs e)

if (IsEnabled)
{
VisualStateManager.GoToState(this, _pointerEntered ? "PointerOver" : "Normal", true);
VisualStateManager.GoToState(this, _pointerEntered ? PointerOverState : NormalState, true);
}
}

Expand All @@ -127,7 +127,7 @@ private void SizerBase_PointerPressed(object sender, PointerRoutedEventArgs e)

if (IsEnabled)
{
VisualStateManager.GoToState(this, "Pressed", true);
VisualStateManager.GoToState(this, PointerOverState, true);
}
}

Expand All @@ -137,7 +137,7 @@ private void SizerBase_PointerExited(object sender, PointerRoutedEventArgs e)

if (!_pressed && !_dragging && IsEnabled)
{
VisualStateManager.GoToState(this, "Normal", true);
VisualStateManager.GoToState(this, NormalState, true);
}
}

Expand All @@ -147,32 +147,32 @@ private void SizerBase_PointerEntered(object sender, PointerRoutedEventArgs e)

if (!_pressed && !_dragging && IsEnabled)
{
VisualStateManager.GoToState(this, "PointerOver", true);
VisualStateManager.GoToState(this, PointerOverState, true);
}
}

private void SizerBase_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
{
_dragging = false;
_pressed = false;
VisualStateManager.GoToState(this, _pointerEntered ? "PointerOver" : "Normal", true);
VisualStateManager.GoToState(this, _pointerEntered ? PointerOverState : NormalState, true);
}

private void SizerBase_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e)
{
_dragging = true;
VisualStateManager.GoToState(this, "Pressed", true);
VisualStateManager.GoToState(this, PressedState, true);
}

private void SizerBase_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if (!IsEnabled)
{
VisualStateManager.GoToState(this, "Disabled", true);
VisualStateManager.GoToState(this, DisabledState, true);
}
else
{
VisualStateManager.GoToState(this, _pointerEntered ? "PointerOver" : "Normal", true);
VisualStateManager.GoToState(this, _pointerEntered ? PointerOverState : NormalState, true);
}
}
}
62 changes: 46 additions & 16 deletions components/SizerBase/src/SizerBase.Properties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using CommunityToolkit.WinUI;

#if !WINAPPSDK
using CursorEnum = Windows.UI.Core.CoreCursorType;
#else
Expand All @@ -17,7 +19,7 @@ namespace CommunityToolkit.Labs.WinUI;
public partial class SizerBase : Control
{
/// <summary>
/// Gets or sets the cursor to use when hovering over the gripper bar. If left as <c>null</c>, the control will manage the cursor automatically based on the <see cref="Orientation"/> property value.
/// Gets or sets the cursor to use when hovering over the gripper bar. If left as <c>null</c>, the control will manage the cursor automatically based on the <see cref="Orientation"/> property value (default).
/// </summary>
public CursorEnum Cursor
{
Expand All @@ -32,13 +34,13 @@ public CursorEnum Cursor
DependencyProperty.Register(nameof(Cursor), typeof(CursorEnum), typeof(SizerBase), new PropertyMetadata(null, OnOrientationPropertyChanged));

/// <summary>
/// Gets or sets the incremental amount of change for draging with the mouse or touch of a sizer control. Effectively a snapping increment for changes. The default is 1.
/// Gets or sets the incremental amount of change for dragging with the mouse or touch of a sizer control. Effectively a snapping increment for changes. The default is 1.
/// </summary>
/// <example>
/// For instance, if the DragIncrement is set to 16. Then when a component is resized with the sizer, it will only increase or decrease in size in that increment. I.e. -16, 0, 16, 32, 48, etc...
/// </example>
/// <remarks>
/// This value is indepedent of the <see cref="KeyboardIncrement"/> property. If you need to provide consistent snapping when moving regardless of input device, set these properties to the same value.
/// This value is independent of the <see cref="KeyboardIncrement"/> property. If you need to provide consistent snapping when moving regardless of input device, set these properties to the same value.
/// </remarks>
public double DragIncrement
{
Expand Down Expand Up @@ -88,41 +90,69 @@ public Orientation Orientation
public static readonly DependencyProperty OrientationProperty =
DependencyProperty.Register(nameof(Orientation), typeof(Orientation), typeof(SizerBase), new PropertyMetadata(Orientation.Vertical, OnOrientationPropertyChanged));

/// <summary>
/// Gets or sets if the Thumb is visible. If not visible, only the background and cursor will be shown on MouseOver or Pressed states.
/// </summary>
public bool IsThumbVisible
{
get { return (bool)GetValue(IsThumbVisibleProperty); }
set { SetValue(IsThumbVisibleProperty, value); }
}

/// <summary>
/// Identifies the <see cref="IsThumbVisible"/> dependency property.
/// </summary>
public static readonly DependencyProperty IsThumbVisibleProperty =
DependencyProperty.Register(nameof(IsThumbVisible), typeof(bool), typeof(SizerBase), new PropertyMetadata(true, OnIsThumbVisiblePropertyChanged));


private static void OnOrientationPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is SizerBase gripper)
{
CursorEnum cursorToUse = gripper.Orientation == Orientation.Vertical ? CursorEnum.SizeWestEast : CursorEnum.SizeNorthSouth;
VisualStateManager.GoToState(gripper, gripper.Orientation == Orientation.Vertical ? VerticalState : HorizontalState, true);

CursorEnum cursorByOrientation = gripper.Orientation == Orientation.Vertical ? CursorEnum.SizeWestEast : CursorEnum.SizeNorthSouth;

// See if there's been a cursor override, otherwise we'll pick
var cursor = gripper.ReadLocalValue(CursorProperty);
if (cursor == DependencyProperty.UnsetValue || cursor == null)
{
cursor = cursorToUse;

// On UWP, we use the extension in XAML to control this behavior,
// so we'll update it here (and maintain binding).
// We'll keep it in-sync to maintain behavior for WinUI 3 as well.
gripper.SetValue(CursorProperty, cursor);
cursor = cursorByOrientation;
}

// We return here, as the Cursor will trigger this function again anyway to set for WinUI 3
return;
#if !WINAPPSDK
// On UWP, we use our XAML extension to control this behavior,
// so we'll update it here (and maintain any cursor override).
if (cursor is CursorEnum cursorValue)
{
FrameworkElementExtensions.SetCursor(gripper, cursorValue);
}

return;
#endif

// TODO: [UNO] Only supported on certain platforms
// See ProtectedCursor here: https://github.com/unoplatform/uno/blob/3fe3862b270b99dbec4d830b547942af61b1a1d9/src/Uno.UI/UI/Xaml/UIElement.cs#L1015-L1023
#if WINAPPSDK && !HAS_UNO
// Need to wait until we're at least applying template step of loading before setting Cursor
// See https://github.com/microsoft/microsoft-ui-xaml/issues/7062
if (gripper._applyingTemplate &&
cursor is CursorEnum cursorToSet &&
if (gripper._appliedTemplate &&
cursor is CursorEnum cursorValue &&
(gripper.ProtectedCursor == null ||
(gripper.ProtectedCursor is InputSystemCursor current &&
current.CursorShape != cursorToSet)))
current.CursorShape != cursorValue)))
{
gripper.ProtectedCursor = InputSystemCursor.Create(cursorToSet);
gripper.ProtectedCursor = InputSystemCursor.Create(cursorValue);
}
#endif
}
}
private static void OnIsThumbVisiblePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (d is SizerBase gripper)
{
VisualStateManager.GoToState(gripper, gripper.IsThumbVisible ? VisibleState : CollapsedState, true);
}
}
}
Loading