Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit da22a4c

Browse files
committed
feat: Port ScrollView
1 parent 409e6dc commit da22a4c

62 files changed

Lines changed: 18738 additions & 1 deletion

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/Uno.UI/Helpers/FocusHelper.cs

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
using Microsoft.UI.Xaml;
5+
using Microsoft.UI.Xaml.Input;
6+
using Microsoft.UI.Xaml.Media;
7+
using Windows.System;
8+
9+
namespace Microsoft.UI.Xaml.Controls;
10+
11+
internal static class FocusHelper
12+
{
13+
public static bool IsGamepadNavigationDirection(VirtualKey key)
14+
{
15+
return key == VirtualKey.GamepadLeftThumbstickDown
16+
|| key == VirtualKey.GamepadDPadDown
17+
|| key == VirtualKey.GamepadLeftThumbstickUp
18+
|| key == VirtualKey.GamepadDPadUp
19+
|| key == VirtualKey.GamepadLeftThumbstickRight
20+
|| key == VirtualKey.GamepadDPadRight
21+
|| key == VirtualKey.GamepadLeftThumbstickLeft
22+
|| key == VirtualKey.GamepadDPadLeft;
23+
}
24+
25+
public static bool IsGamepadPageNavigationDirection(VirtualKey key)
26+
{
27+
return
28+
key == VirtualKey.GamepadLeftShoulder ||
29+
key == VirtualKey.GamepadRightShoulder ||
30+
key == VirtualKey.GamepadLeftTrigger ||
31+
key == VirtualKey.GamepadRightTrigger;
32+
}
33+
34+
public static FocusNavigationDirection GetNavigationDirection(VirtualKey key)
35+
{
36+
FocusNavigationDirection direction = FocusNavigationDirection.None;
37+
38+
switch (key)
39+
{
40+
case VirtualKey.GamepadDPadUp:
41+
case VirtualKey.GamepadLeftThumbstickUp:
42+
case VirtualKey.Up:
43+
direction = FocusNavigationDirection.Up;
44+
break;
45+
case VirtualKey.GamepadDPadDown:
46+
case VirtualKey.GamepadLeftThumbstickDown:
47+
case VirtualKey.Down:
48+
direction = FocusNavigationDirection.Down;
49+
break;
50+
case VirtualKey.GamepadDPadLeft:
51+
case VirtualKey.GamepadLeftThumbstickLeft:
52+
case VirtualKey.Left:
53+
direction = FocusNavigationDirection.Left;
54+
break;
55+
case VirtualKey.GamepadDPadRight:
56+
case VirtualKey.GamepadLeftThumbstickRight:
57+
case VirtualKey.Right:
58+
direction = FocusNavigationDirection.Right;
59+
break;
60+
}
61+
62+
return direction;
63+
}
64+
65+
public static FocusNavigationDirection GetPageNavigationDirection(VirtualKey key)
66+
{
67+
FocusNavigationDirection direction = FocusNavigationDirection.None;
68+
69+
switch (key)
70+
{
71+
case VirtualKey.GamepadLeftTrigger:
72+
direction = FocusNavigationDirection.Up;
73+
break;
74+
case VirtualKey.GamepadRightTrigger:
75+
direction = FocusNavigationDirection.Down;
76+
break;
77+
case VirtualKey.GamepadLeftShoulder:
78+
direction = FocusNavigationDirection.Left;
79+
break;
80+
case VirtualKey.GamepadRightShoulder:
81+
direction = FocusNavigationDirection.Right;
82+
break;
83+
}
84+
85+
return direction;
86+
}
87+
88+
public static FocusNavigationDirection GetOppositeDirection(FocusNavigationDirection direction)
89+
{
90+
FocusNavigationDirection oppositeDirection = FocusNavigationDirection.None;
91+
switch (direction)
92+
{
93+
case FocusNavigationDirection.Down:
94+
oppositeDirection = FocusNavigationDirection.Up;
95+
break;
96+
case FocusNavigationDirection.Up:
97+
oppositeDirection = FocusNavigationDirection.Down;
98+
break;
99+
case FocusNavigationDirection.Left:
100+
oppositeDirection = FocusNavigationDirection.Right;
101+
break;
102+
case FocusNavigationDirection.Right:
103+
oppositeDirection = FocusNavigationDirection.Left;
104+
break;
105+
case FocusNavigationDirection.Next:
106+
oppositeDirection = FocusNavigationDirection.Previous;
107+
break;
108+
case FocusNavigationDirection.Previous:
109+
oppositeDirection = FocusNavigationDirection.Next;
110+
break;
111+
}
112+
return oppositeDirection;
113+
}
114+
115+
public static UIElement GetUIElementForFocusCandidate(DependencyObject dobj)
116+
{
117+
var uielement = dobj as UIElement;
118+
var parent = dobj;
119+
while (uielement == null && parent != null)
120+
{
121+
parent = VisualTreeHelper.GetParent(dobj);
122+
if (parent is not null)
123+
{
124+
uielement = dobj as UIElement;
125+
}
126+
}
127+
128+
return uielement;
129+
}
130+
};

src/Uno.UI/Helpers/WinUI/SharedHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ public static bool DoRectsIntersect(
606606
public static bool IsAncestor(
607607
DependencyObject child,
608608
DependencyObject parent,
609-
bool checkVisibility)
609+
bool checkVisibility = false)
610610
{
611611
if (child == null || parent == null || child == parent)
612612
{
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
using Microsoft.UI.Xaml;
5+
using Windows.Foundation;
6+
7+
namespace Microsoft.UI.Xaml.Controls;
8+
9+
internal sealed partial class BringIntoViewOffsetsChange : OffsetsChange
10+
{
11+
// UNO TODO: Revise element vs owner parameters...
12+
public BringIntoViewOffsetsChange(
13+
/*ITrackerHandleManager*/ UIElement owner,
14+
double zoomedHorizontalOffset,
15+
double zoomedVerticalOffset,
16+
ScrollPresenterViewKind offsetsKind,
17+
object options,
18+
UIElement element,
19+
Rect elementRect,
20+
double horizontalAlignmentRatio,
21+
double verticalAlignmentRatio,
22+
double horizontalOffset,
23+
double verticalOffset) : base(zoomedHorizontalOffset, zoomedVerticalOffset, offsetsKind, options)
24+
{
25+
Element = owner;
26+
ElementRect = elementRect;
27+
HorizontalAlignmentRatio = horizontalAlignmentRatio;
28+
VerticalAlignmentRatio = verticalAlignmentRatio;
29+
HorizontalOffset = horizontalOffset;
30+
VerticalOffset = verticalOffset;
31+
// SCROLLPRESENTER_TRACE_VERBOSE(nullptr, TRACE_MSG_METH, METH_NAME, this);
32+
}
33+
34+
// ~BringIntoViewOffsetsChange()
35+
// {
36+
// SCROLLPRESENTER_TRACE_VERBOSE(nullptr, TRACE_MSG_METH, METH_NAME, this);
37+
// }
38+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
using Microsoft.UI.Xaml;
5+
using Windows.Foundation;
6+
7+
namespace Microsoft.UI.Xaml.Controls;
8+
9+
internal sealed partial class BringIntoViewOffsetsChange : OffsetsChange
10+
{
11+
public UIElement Element { get; }
12+
13+
public Rect ElementRect { get; }
14+
15+
public double HorizontalAlignmentRatio { get; }
16+
17+
public double VerticalAlignmentRatio { get; }
18+
19+
public double HorizontalOffset { get; }
20+
21+
public double VerticalOffset { get; }
22+
};
23+
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
using System.Collections.Generic;
5+
using System.Numerics;
6+
using Microsoft.UI.Composition;
7+
using Microsoft.UI.Xaml;
8+
using Microsoft.UI.Xaml.Media;
9+
using Microsoft.UI.Xaml.Primitives;
10+
using Windows.Foundation;
11+
12+
namespace Microsoft.UI.Xaml.Controls.Primitives;
13+
14+
internal interface IScrollPresenter
15+
{
16+
Brush Background { get; set; }
17+
18+
ScrollingScrollMode ComputedHorizontalScrollMode { get; }
19+
20+
ScrollingScrollMode ComputedVerticalScrollMode { get; }
21+
22+
UIElement Content { get; set; }
23+
24+
ScrollingContentOrientation ContentOrientation { get; set; }
25+
26+
CompositionPropertySet ExpressionAnimationSources { get; }
27+
28+
double ExtentHeight { get; }
29+
30+
double ExtentWidth { get; }
31+
32+
double HorizontalAnchorRatio { get; set; }
33+
34+
double HorizontalOffset { get; }
35+
36+
ScrollingChainMode HorizontalScrollChainMode { get; set; }
37+
38+
IScrollController HorizontalScrollController { get; set; }
39+
40+
ScrollingScrollMode HorizontalScrollMode { get; set; }
41+
42+
ScrollingRailMode HorizontalScrollRailMode { get; set; }
43+
44+
IList<ScrollSnapPointBase> HorizontalSnapPoints { get; }
45+
46+
ScrollingInputKinds IgnoredInputKinds { get; set; }
47+
48+
double MaxZoomFactor { get; set; }
49+
50+
double MinZoomFactor { get; set; }
51+
52+
double ScrollableHeight { get; }
53+
54+
double ScrollableWidth { get; }
55+
56+
ScrollingInteractionState State { get; }
57+
58+
double VerticalAnchorRatio { get; set; }
59+
60+
double VerticalOffset { get; }
61+
62+
ScrollingChainMode VerticalScrollChainMode { get; set; }
63+
64+
IScrollController VerticalScrollController { get; set; }
65+
66+
ScrollingScrollMode VerticalScrollMode { get; set; }
67+
68+
ScrollingRailMode VerticalScrollRailMode { get; set; }
69+
70+
IList<ScrollSnapPointBase> VerticalSnapPoints { get; }
71+
72+
double ViewportHeight { get; }
73+
74+
double ViewportWidth { get; }
75+
76+
ScrollingChainMode ZoomChainMode { get; set; }
77+
78+
float ZoomFactor { get; }
79+
80+
ScrollingZoomMode ZoomMode { get; set; }
81+
82+
IList<ZoomSnapPointBase> ZoomSnapPoints { get; }
83+
84+
event TypedEventHandler<ScrollPresenter, ScrollingAnchorRequestedEventArgs> AnchorRequested;
85+
86+
event TypedEventHandler<ScrollPresenter, ScrollingBringingIntoViewEventArgs> BringingIntoView;
87+
88+
event TypedEventHandler<ScrollPresenter, object> ExtentChanged;
89+
90+
event TypedEventHandler<ScrollPresenter, ScrollingScrollAnimationStartingEventArgs> ScrollAnimationStarting;
91+
92+
event TypedEventHandler<ScrollPresenter, ScrollingScrollCompletedEventArgs> ScrollCompleted;
93+
94+
event TypedEventHandler<ScrollPresenter, object> StateChanged;
95+
96+
event TypedEventHandler<ScrollPresenter, object> ViewChanged;
97+
98+
event TypedEventHandler<ScrollPresenter, ScrollingZoomAnimationStartingEventArgs> ZoomAnimationStarting;
99+
100+
event TypedEventHandler<ScrollPresenter, ScrollingZoomCompletedEventArgs> ZoomCompleted;
101+
102+
int ScrollTo(double horizontalOffset, double verticalOffset);
103+
104+
int ScrollTo(double horizontalOffset, double verticalOffset, ScrollingScrollOptions options);
105+
106+
int ScrollBy(double horizontalOffsetDelta, double verticalOffsetDelta);
107+
108+
int ScrollBy(double horizontalOffsetDelta, double verticalOffsetDelta, ScrollingScrollOptions options);
109+
110+
int AddScrollVelocity(Vector2 offsetsVelocity, Vector2? inertiaDecayRate);
111+
112+
int ZoomTo(float zoomFactor, Vector2? centerPoint);
113+
114+
int ZoomTo(float zoomFactor, Vector2? centerPoint, ScrollingZoomOptions options);
115+
116+
int ZoomBy(float zoomFactorDelta, Vector2? centerPoint);
117+
118+
int ZoomBy(float zoomFactorDelta, Vector2? centerPoint, ScrollingZoomOptions options);
119+
120+
int AddZoomVelocity(float zoomFactorVelocity, Vector2? centerPoint, float? inertiaDecayRate);
121+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+
namespace Microsoft.UI.Xaml.Controls;
5+
6+
internal sealed partial class InteractionTrackerAsyncOperation
7+
{
8+
public InteractionTrackerAsyncOperation(
9+
InteractionTrackerAsyncOperationType operationType,
10+
InteractionTrackerAsyncOperationTrigger operationTrigger,
11+
bool isDelayed,
12+
ViewChangeBase viewChangeBase)
13+
{
14+
m_operationType = operationType;
15+
m_operationTrigger = operationTrigger;
16+
m_isDelayed = isDelayed;
17+
m_viewChangeBase = viewChangeBase;
18+
// SCROLLPRESENTER_TRACE_VERBOSE(nullptr, L"%s[0x%p](operationType: %s, operationTrigger: %s, isDelayed: %d, viewChange: 0x%p)\n",
19+
// METH_NAME, this, TypeLogging::InteractionTrackerAsyncOperationTypeToString(operationType).c_str(),
20+
// TypeLogging::InteractionTrackerAsyncOperationTriggerToString(operationTrigger).c_str(), isDelayed, viewChangeBase);
21+
22+
if (!IsAnimated())
23+
{
24+
m_postProcessingTicksCountdown = c_maxNonAnimatedOperationTicks;
25+
}
26+
}
27+
28+
// ~InteractionTrackerAsyncOperation()
29+
// {
30+
// SCROLLPRESENTER_TRACE_VERBOSE(nullptr, TRACE_MSG_METH, METH_NAME, this);
31+
// }
32+
}

0 commit comments

Comments
 (0)