Skip to content

Commit

Permalink
[NUI] Add wheelEvent and WheelScrollDistance property on ScrollableBase
Browse files Browse the repository at this point in the history
  • Loading branch information
everLEEst committed Nov 4, 2022
1 parent 75ee312 commit c2c74d9
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/Tizen.NUI.Components/Controls/ScrollableBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,25 @@ public float StepScrollDistance
}
private float stepScrollDistance = 0f;

/// <summary>
/// Wheel scroll move distance.
/// This value decide how long distance will it moves in wheel event.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public float WheelScrollDistance
{
get
{
return (float)GetValue(WheelScrollDistanceProperty);
}
set
{
SetValue(WheelScrollDistanceProperty, value);
NotifyPropertyChanged();
}
}
private float wheelScrollDistance = 50f;


// Let's consider more whether this needs to be set as protected.
private float finalTargetPosition;
Expand Down Expand Up @@ -942,6 +961,8 @@ private void Initialize()
PivotPoint = NUI.PivotPoint.CenterRight,
};

WheelEvent += OnWheelEvent;

AccessibilityManager.Instance.SetAccessibilityAttribute(this, AccessibilityManager.AccessibilityAttribute.Trait, "ScrollableBase");

SetKeyboardNavigationSupport(true);
Expand Down Expand Up @@ -1363,6 +1384,8 @@ protected override void Dispose(DisposeTypes type)
propertyNotification = null;
}

WheelEvent -= OnWheelEvent;

if (type == DisposeTypes.Explicit)
{

Expand Down Expand Up @@ -2148,6 +2171,22 @@ protected override bool AccessibilityScrollToChild(View child)

return true;
}


private bool OnWheelEvent(object o, WheelEventArgs e)
{
Wheel wheel = e?.Wheel;
if (wheel == null)
{
return false;
}

float currentScrollPosition = -(ScrollingDirection == Direction.Horizontal ? ContentContainer.CurrentPosition.X : ContentContainer.CurrentPosition.Y);
ScrollTo(currentScrollPosition + (wheelScrollDistance * wheel.Z), false);

return true;
}

}

} // namespace
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,24 @@ public partial class ScrollableBase
return instance.stepScrollDistance;
});

/// <summary>
/// WheelScrollDistanceProperty
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static readonly BindableProperty WheelScrollDistanceProperty = BindableProperty.Create(nameof(WheelScrollDistance), typeof(float), typeof(ScrollableBase), default(float), propertyChanged: (bindable, oldValue, newValue) =>
{
var instance = (ScrollableBase)bindable;
if (newValue != null)
{
instance.wheelScrollDistance = (float)newValue;
}
},
defaultValueCreator: (bindable) =>
{
var instance = (ScrollableBase)bindable;
return instance.stepScrollDistance;
});

/// <summary>
/// FadeScrollbarProperty
/// </summary>
Expand Down

0 comments on commit c2c74d9

Please sign in to comment.