Skip to content

Commit

Permalink
Merge pull request #6379 from MarchingCube/scrollbar-delay-control
Browse files Browse the repository at this point in the history
Allow for controling delay of scrollbar hide/show.
  • Loading branch information
maxkatz6 authored and Dan Walmsley committed Aug 16, 2021
1 parent b0f9994 commit 461e6cb
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions src/Avalonia.Controls/Primitives/ScrollBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ public class ScrollBar : RangeBase
public static readonly StyledProperty<bool> AllowAutoHideProperty =
AvaloniaProperty.Register<ScrollBar, bool>(nameof(AllowAutoHide), true);

/// <summary>
/// Defines the <see cref="HideDelay"/> property.
/// </summary>
public static readonly StyledProperty<TimeSpan> HideDelayProperty =
AvaloniaProperty.Register<ScrollBar, TimeSpan>(nameof(HideDelay), TimeSpan.FromSeconds(2));

/// <summary>
/// Defines the <see cref="ShowDelay"/> property.
/// </summary>
public static readonly StyledProperty<TimeSpan> ShowDelayProperty =
AvaloniaProperty.Register<ScrollBar, TimeSpan>(nameof(ShowDelay), TimeSpan.FromSeconds(0.5));

private Button _lineUpButton;
private Button _lineDownButton;
private Button _pageUpButton;
Expand Down Expand Up @@ -126,6 +138,24 @@ public bool AllowAutoHide
get => GetValue(AllowAutoHideProperty);
set => SetValue(AllowAutoHideProperty, value);
}

/// <summary>
/// Gets a value that determines how long will be the hide delay after user stops interacting with the scrollbar.
/// </summary>
public TimeSpan HideDelay
{
get => GetValue(HideDelayProperty);
set => SetValue(HideDelayProperty, value);
}

/// <summary>
/// Gets a value that determines how long will be the show delay when user starts interacting with the scrollbar.
/// </summary>
public TimeSpan ShowDelay
{
get => GetValue(ShowDelayProperty);
set => SetValue(ShowDelayProperty, value);
}

public event EventHandler<ScrollEventArgs> Scroll;

Expand Down Expand Up @@ -296,12 +326,12 @@ private void UpdateIsExpandedState()

private void CollapseAfterDelay()
{
InvokeAfterDelay(Collapse, TimeSpan.FromSeconds(2));
InvokeAfterDelay(Collapse, HideDelay);
}

private void ExpandAfterDelay()
{
InvokeAfterDelay(Expand, TimeSpan.FromMilliseconds(400));
InvokeAfterDelay(Expand, ShowDelay);
}

private void Collapse()
Expand Down

0 comments on commit 461e6cb

Please sign in to comment.