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 = public static readonly StyledProperty<Orientation> OrientationProperty =
AvaloniaProperty.Register<ScrollBar, Orientation>(nameof(Orientation), Orientation.Vertical); AvaloniaProperty.Register<ScrollBar, Orientation>(nameof(Orientation), Orientation.Vertical);
public static readonly StyledProperty<bool> AllowAutoHideProperty = /// <summary>
AvaloniaProperty.Register<ScrollBar, bool>(nameof(AllowAutoHide), true); /// Defines the <see cref="IsExpandedProperty"/> property.
/// </summary>
public static readonly DirectProperty<ScrollBar, bool> IsExpandedProperty = public static readonly DirectProperty<ScrollBar, bool> IsExpandedProperty =
AvaloniaProperty.RegisterDirect<ScrollBar, bool>( AvaloniaProperty.RegisterDirect<ScrollBar, bool>(
nameof(IsExpanded), nameof(IsExpanded),
o => o.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 _lineUpButton;
private Button _lineDownButton; private Button _lineDownButton;
private Button _pageUpButton; private Button _pageUpButton;
@ -73,18 +79,6 @@ namespace Avalonia.Controls.Primitives
UpdatePseudoClasses(Orientation); 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> /// <summary>
/// Gets or sets the amount of the scrollable content that is currently visible. /// Gets or sets the amount of the scrollable content that is currently visible.
/// </summary> /// </summary>
@ -113,6 +107,24 @@ namespace Avalonia.Controls.Primitives
set { SetValue(OrientationProperty, value); } 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; public event EventHandler<ScrollEventArgs> Scroll;
/// <summary> /// <summary>

80
src/Avalonia.Controls/ScrollViewer.cs

@ -160,9 +160,6 @@ namespace Avalonia.Controls
nameof(VerticalScrollBarViewportSize), nameof(VerticalScrollBarViewportSize),
o => o.VerticalScrollBarViewportSize); o => o.VerticalScrollBarViewportSize);
public static readonly DirectProperty<ScrollViewer, bool> IsExpandedProperty =
ScrollBar.IsExpandedProperty.AddOwner<ScrollViewer>(o => o.IsExpanded);
/// <summary> /// <summary>
/// Defines the <see cref="VerticalScrollBarVisibility"/> property. /// Defines the <see cref="VerticalScrollBarVisibility"/> property.
/// </summary> /// </summary>
@ -171,6 +168,15 @@ namespace Avalonia.Controls
nameof(VerticalScrollBarVisibility), nameof(VerticalScrollBarVisibility),
ScrollBarVisibility.Auto); 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 = public static readonly StyledProperty<bool> AllowAutoHideProperty =
ScrollBar.AllowAutoHideProperty.AddOwner<ScrollViewer>(); ScrollBar.AllowAutoHideProperty.AddOwner<ScrollViewer>();
@ -223,18 +229,6 @@ namespace Avalonia.Controls
remove => RemoveHandler(ScrollChangedEvent, value); 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> /// <summary>
/// Gets the extent of the scrollable content. /// Gets the extent of the scrollable content.
/// </summary> /// </summary>
@ -405,6 +399,24 @@ namespace Avalonia.Controls
get { return _viewport.Height; } 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> /// <summary>
/// Scrolls the content up one line. /// Scrolls the content up one line.
/// </summary> /// </summary>
@ -642,45 +654,41 @@ namespace Avalonia.Controls
_scrollBarExpandSubscription?.Dispose(); _scrollBarExpandSubscription?.Dispose();
var horizontalScrollBar = e.NameScope.Find<ScrollBar>("PART_HorizontalScrollBar"); _scrollBarExpandSubscription = SubscribeToScrollBars(e);
var verticalScrollBar = e.NameScope.Find<ScrollBar>("PART_VerticalScrollBar"); }
IObservable<bool> horizontalExpanded = null, verticalExpanded = null;
if (horizontalScrollBar != null) private IDisposable SubscribeToScrollBars(TemplateAppliedEventArgs e)
{
static IObservable<bool> GetExpandedObservable(ScrollBar scrollBar)
{ {
horizontalExpanded = horizontalScrollBar return scrollBar?.GetObservable(ScrollBar.IsExpandedProperty);
.GetObservable(ScrollBar.IsExpandedProperty);
} }
if (verticalScrollBar != null) var horizontalScrollBar = e.NameScope.Find<ScrollBar>("PART_HorizontalScrollBar");
{ var verticalScrollBar = e.NameScope.Find<ScrollBar>("PART_VerticalScrollBar");
verticalExpanded = verticalScrollBar
.GetObservable(ScrollBar.IsExpandedProperty); var horizontalExpanded = GetExpandedObservable(horizontalScrollBar);
} var verticalExpanded = GetExpandedObservable(verticalScrollBar);
IObservable<bool> finalExpanded = null; IObservable<bool> actualExpanded = null;
if (horizontalExpanded != null && verticalExpanded != null) if (horizontalExpanded != null && verticalExpanded != null)
{ {
finalExpanded = horizontalExpanded.CombineLatest(verticalExpanded, (h, v) => h || v); actualExpanded = horizontalExpanded.CombineLatest(verticalExpanded, (h, v) => h || v);
} }
else else
{ {
if (horizontalExpanded != null) if (horizontalExpanded != null)
{ {
finalExpanded = horizontalExpanded; actualExpanded = horizontalExpanded;
} }
else if (verticalExpanded != null) else if (verticalExpanded != null)
{ {
finalExpanded = verticalExpanded; actualExpanded = verticalExpanded;
} }
} }
if (finalExpanded != null) return actualExpanded?.Subscribe(OnScrollBarExpandedChanged);
{
_scrollBarExpandSubscription = finalExpanded.Subscribe(OnScrollBarExpandedChanged);
}
} }
private void OnScrollBarExpandedChanged(bool isExpanded) private void OnScrollBarExpandedChanged(bool isExpanded)

Loading…
Cancel
Save