-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScrollBarExtensions.cs
More file actions
93 lines (85 loc) · 4.35 KB
/
Copy pathScrollBarExtensions.cs
File metadata and controls
93 lines (85 loc) · 4.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using Terminal.Gui.App;
using Terminal.Gui.ViewBase;
using Terminal.Gui.Views;
namespace TerminalGui.Extensions.Extensions.ViewExtensions;
/// <summary>
/// Extension methods for <see cref="ScrollBar" />.
/// </summary>
public static class ScrollBarExtensions
{
extension(ScrollBar scrollBar)
{
/// <summary>
/// Subscribes to the <see cref="ScrollBar.OrientationChanged" /> event.
/// </summary>
/// <param name="callback">The callback to invoke with the <see cref="EventArgs{T}" /> containing the new <see cref="Orientation" />.</param>
/// <returns>The <see cref="ScrollBar" /> instance.</returns>
public ScrollBar OnOrientationChanged(Action<EventArgs<Orientation>> callback)
{
scrollBar.OrientationChanged += (_, e) => callback(e);
return scrollBar;
}
/// <summary>
/// Subscribes to the <see cref="ScrollBar.OrientationChanging" /> event.
/// Set <see cref="CancelEventArgs{T}.Cancel" /> to <see langword="true" /> to cancel the change.
/// </summary>
/// <param name="callback">The callback to invoke with the <see cref="CancelEventArgs{T}" /> containing the proposed <see cref="Orientation" />.</param>
/// <returns>The <see cref="ScrollBar" /> instance.</returns>
public ScrollBar OnOrientationChanging(Action<CancelEventArgs<Orientation>> callback)
{
scrollBar.OrientationChanging += (_, e) => callback(e);
return scrollBar;
}
/// <summary>
/// Subscribes to the <see cref="ScrollBar.ScrollableContentSizeChanged" /> event.
/// </summary>
/// <param name="callback">The callback to invoke with the <see cref="EventArgs{T}" /> containing the new size.</param>
/// <returns>The <see cref="ScrollBar" /> instance.</returns>
public ScrollBar OnScrollableContentSizeChanged(Action<EventArgs<int>> callback)
{
scrollBar.ScrollableContentSizeChanged += (_, e) => callback(e);
return scrollBar;
}
/// <summary>
/// Subscribes to the <see cref="ScrollBar.Scrolled" /> event.
/// </summary>
/// <param name="callback">The callback to invoke with the <see cref="EventArgs{T}" /> containing the scroll position.</param>
/// <returns>The <see cref="ScrollBar" /> instance.</returns>
public ScrollBar OnScrolled(Action<EventArgs<int>> callback)
{
scrollBar.Scrolled += (_, e) => callback(e);
return scrollBar;
}
/// <summary>
/// Subscribes to the <see cref="ScrollBar.SliderPositionChanged" /> event.
/// </summary>
/// <param name="callback">The callback to invoke with the <see cref="EventArgs{T}" /> containing the new slider position.</param>
/// <returns>The <see cref="ScrollBar" /> instance.</returns>
public ScrollBar OnSliderPositionChanged(Action<EventArgs<int>> callback)
{
scrollBar.SliderPositionChanged += (_, e) => callback(e);
return scrollBar;
}
/// <summary>
/// Subscribes to the <see cref="ScrollBar.ValueChanged" /> event.
/// </summary>
/// <param name="callback">The callback to invoke with the <see cref="ValueChangedEventArgs{T}" /> containing old and new values.</param>
/// <returns>The <see cref="ScrollBar" /> instance.</returns>
public ScrollBar OnValueChanged(Action<ValueChangedEventArgs<int>> callback)
{
scrollBar.ValueChanged += (_, e) => callback(e);
return scrollBar;
}
/// <summary>
/// Subscribes to the <see cref="ScrollBar.ValueChanging" /> event.
/// Set <see cref="ValueChangingEventArgs{T}.Handled" /> to <see langword="true" /> to cancel the change.
/// </summary>
/// <param name="callback">The callback to invoke with the <see cref="ValueChangingEventArgs{T}" /> containing current and proposed values.</param>
/// <returns>The <see cref="ScrollBar" /> instance.</returns>
public ScrollBar OnValueChanging(Action<ValueChangingEventArgs<int>> callback)
{
scrollBar.ValueChanging += (_, e) => callback(e);
return scrollBar;
}
}
}