Browse Source

Cleanup code and add doc comments.

pull/4119/head
Dariusz Komosinski 6 years ago
parent
commit
8691aea157
  1. 42
      src/Avalonia.Controls/Primitives/ScrollBar.cs
  2. 80
      src/Avalonia.Controls/ScrollViewer.cs

42
src/Avalonia.Controls/Primitives/ScrollBar.cs

@ -41,14 +41,20 @@ namespace Avalonia.Controls.Primitives
public static readonly StyledProperty<Orientation> OrientationProperty =
AvaloniaProperty.Register<ScrollBar, Orientation>(nameof(Orientation), Orientation.Vertical);
public static readonly StyledProperty<bool> AllowAutoHideProperty =
AvaloniaProperty.Register<ScrollBar, bool>(nameof(AllowAutoHide), true);
/// <summary>
/// Defines the <see cref="IsExpandedProperty"/> property.
/// </summary>
public static readonly DirectProperty<ScrollBar, bool> IsExpandedProperty =
AvaloniaProperty.RegisterDirect<ScrollBar, bool>(
nameof(IsExpanded),
o => o.IsExpanded);
/// <summary>
/// Defines the <see cref="AllowAutoHide"/> property.
/// </summary>
public static readonly StyledProperty<bool> AllowAutoHideProperty =
AvaloniaProperty.Register<ScrollBar, bool>(nameof(AllowAutoHide), true);
private Button _lineUpButton;
private Button _lineDownButton;
private Button _pageUpButton;
@ -73,18 +79,6 @@ namespace Avalonia.Controls.Primitives
UpdatePseudoClasses(Orientation);
}
public bool IsExpanded
{
get => _isExpanded;
private set => SetAndRaise(IsExpandedProperty, ref _isExpanded, value);
}
public bool AllowAutoHide
{
get { return GetValue(AllowAutoHideProperty); }
set { SetValue(AllowAutoHideProperty, value); }
}
/// <summary>
/// Gets or sets the amount of the scrollable content that is currently visible.
/// </summary>
@ -113,6 +107,24 @@ namespace Avalonia.Controls.Primitives
set { SetValue(OrientationProperty, value); }
}
/// <summary>
/// Gets a value that indicates whether the scrollbar is expanded.
/// </summary>
public bool IsExpanded
{
get => _isExpanded;
private set => SetAndRaise(IsExpandedProperty, ref _isExpanded, value);
}
/// <summary>
/// Gets a value that indicates whether the scrollbar can hide itself when user is not interacting with it.
/// </summary>
public bool AllowAutoHide
{
get => GetValue(AllowAutoHideProperty);
set => SetValue(AllowAutoHideProperty, value);
}
public event EventHandler<ScrollEventArgs> Scroll;
/// <summary>

80
src/Avalonia.Controls/ScrollViewer.cs

@ -160,9 +160,6 @@ namespace Avalonia.Controls
nameof(VerticalScrollBarViewportSize),
o => o.VerticalScrollBarViewportSize);
public static readonly DirectProperty<ScrollViewer, bool> IsExpandedProperty =
ScrollBar.IsExpandedProperty.AddOwner<ScrollViewer>(o => o.IsExpanded);
/// <summary>
/// Defines the <see cref="VerticalScrollBarVisibility"/> property.
/// </summary>
@ -171,6 +168,15 @@ namespace Avalonia.Controls
nameof(VerticalScrollBarVisibility),
ScrollBarVisibility.Auto);
/// <summary>
/// Defines the <see cref="IsExpandedProperty"/> property.
/// </summary>
public static readonly DirectProperty<ScrollViewer, bool> IsExpandedProperty =
ScrollBar.IsExpandedProperty.AddOwner<ScrollViewer>(o => o.IsExpanded);
/// <summary>
/// Defines the <see cref="AllowAutoHide"/> property.
/// </summary>
public static readonly StyledProperty<bool> AllowAutoHideProperty =
ScrollBar.AllowAutoHideProperty.AddOwner<ScrollViewer>();
@ -223,18 +229,6 @@ namespace Avalonia.Controls
remove => RemoveHandler(ScrollChangedEvent, value);
}
public bool IsExpanded
{
get => _isExpanded;
private set => SetAndRaise(ScrollBar.IsExpandedProperty, ref _isExpanded, value);
}
public bool AllowAutoHide
{
get { return GetValue(AllowAutoHideProperty); }
set { SetValue(AllowAutoHideProperty, value); }
}
/// <summary>
/// Gets the extent of the scrollable content.
/// </summary>
@ -405,6 +399,24 @@ namespace Avalonia.Controls
get { return _viewport.Height; }
}
/// <summary>
/// Gets a value that indicates whether any scrollbar is expanded.
/// </summary>
public bool IsExpanded
{
get => _isExpanded;
private set => SetAndRaise(ScrollBar.IsExpandedProperty, ref _isExpanded, value);
}
/// <summary>
/// Gets a value that indicates whether scrollbars can hide itself when user is not interacting with it.
/// </summary>
public bool AllowAutoHide
{
get => GetValue(AllowAutoHideProperty);
set => SetValue(AllowAutoHideProperty, value);
}
/// <summary>
/// Scrolls the content up one line.
/// </summary>
@ -642,45 +654,41 @@ namespace Avalonia.Controls
_scrollBarExpandSubscription?.Dispose();
var horizontalScrollBar = e.NameScope.Find<ScrollBar>("PART_HorizontalScrollBar");
var verticalScrollBar = e.NameScope.Find<ScrollBar>("PART_VerticalScrollBar");
IObservable<bool> horizontalExpanded = null, verticalExpanded = null;
_scrollBarExpandSubscription = SubscribeToScrollBars(e);
}
if (horizontalScrollBar != null)
private IDisposable SubscribeToScrollBars(TemplateAppliedEventArgs e)
{
static IObservable<bool> GetExpandedObservable(ScrollBar scrollBar)
{
horizontalExpanded = horizontalScrollBar
.GetObservable(ScrollBar.IsExpandedProperty);
return scrollBar?.GetObservable(ScrollBar.IsExpandedProperty);
}
if (verticalScrollBar != null)
{
verticalExpanded = verticalScrollBar
.GetObservable(ScrollBar.IsExpandedProperty);
}
var horizontalScrollBar = e.NameScope.Find<ScrollBar>("PART_HorizontalScrollBar");
var verticalScrollBar = e.NameScope.Find<ScrollBar>("PART_VerticalScrollBar");
var horizontalExpanded = GetExpandedObservable(horizontalScrollBar);
var verticalExpanded = GetExpandedObservable(verticalScrollBar);
IObservable<bool> finalExpanded = null;
IObservable<bool> actualExpanded = null;
if (horizontalExpanded != null && verticalExpanded != null)
{
finalExpanded = horizontalExpanded.CombineLatest(verticalExpanded, (h, v) => h || v);
actualExpanded = horizontalExpanded.CombineLatest(verticalExpanded, (h, v) => h || v);
}
else
{
if (horizontalExpanded != null)
{
finalExpanded = horizontalExpanded;
}
actualExpanded = horizontalExpanded;
}
else if (verticalExpanded != null)
{
finalExpanded = verticalExpanded;
actualExpanded = verticalExpanded;
}
}
if (finalExpanded != null)
{
_scrollBarExpandSubscription = finalExpanded.Subscribe(OnScrollBarExpandedChanged);
}
return actualExpanded?.Subscribe(OnScrollBarExpandedChanged);
}
private void OnScrollBarExpandedChanged(bool isExpanded)

Loading…
Cancel
Save