Define View actions as events

This commit is contained in:
Artyom
2020-09-23 01:26:46 +03:00
committed by BDisp
parent 47a2020bf4
commit 666912c046
5 changed files with 23 additions and 18 deletions

View File

@@ -141,7 +141,7 @@ static class Demo {
#else
var filler = new Filler (new Rect (0, 0, 40, 40));
scrollView.Add (filler);
scrollView.DrawContent = (r) => {
scrollView.DrawContent += (r) => {
scrollView.ContentSize = filler.GetContentSize ();
};
#endif

View File

@@ -128,37 +128,37 @@ namespace Terminal.Gui {
/// <summary>
/// Event fired when a subview is being added to this view.
/// </summary>
public Action<View> Added;
public event Action<View> Added;
/// <summary>
/// Event fired when a subview is being removed from this view.
/// </summary>
public Action<View> Removed;
public event Action<View> Removed;
/// <summary>
/// Event fired when the view gets focus.
/// </summary>
public Action<FocusEventArgs> Enter;
public event Action<FocusEventArgs> Enter;
/// <summary>
/// Event fired when the view looses focus.
/// </summary>
public Action<FocusEventArgs> Leave;
public event Action<FocusEventArgs> Leave;
/// <summary>
/// Event fired when the view receives the mouse event for the first time.
/// </summary>
public Action<MouseEventArgs> MouseEnter;
public event Action<MouseEventArgs> MouseEnter;
/// <summary>
/// Event fired when the view receives a mouse event for the last time.
/// </summary>
public Action<MouseEventArgs> MouseLeave;
public event Action<MouseEventArgs> MouseLeave;
/// <summary>
/// Event fired when a mouse event is generated.
/// </summary>
public Action<MouseEventArgs> MouseClick;
public event Action<MouseEventArgs> MouseClick;
/// <summary>
/// Gets or sets the HotKey defined for this view. A user pressing HotKey on the keyboard while this view has focus will cause the Clicked event to fire.
@@ -1298,7 +1298,7 @@ namespace Terminal.Gui {
/// Rect provides the view-relative rectangle describing the currently visible viewport into the <see cref="View"/>.
/// </para>
/// </remarks>
public Action<Rect> DrawContent;
public event Action<Rect> DrawContent;
/// <summary>
/// Enables overrides to draw infinitely scrolled content and/or a background behind added controls.
@@ -1381,7 +1381,7 @@ namespace Terminal.Gui {
/// <summary>
/// Invoked when a character key is pressed and occurs after the key up event.
/// </summary>
public Action<KeyEventEventArgs> KeyPress;
public event Action<KeyEventEventArgs> KeyPress;
/// <inheritdoc/>
public override bool ProcessKey (KeyEvent keyEvent)
@@ -1429,7 +1429,7 @@ namespace Terminal.Gui {
/// <summary>
/// Invoked when a key is pressed
/// </summary>
public Action<KeyEventEventArgs> KeyDown;
public event Action<KeyEventEventArgs> KeyDown;
/// <param name="keyEvent">Contains the details about the key that produced the event.</param>
public override bool OnKeyDown (KeyEvent keyEvent)
@@ -1449,7 +1449,7 @@ namespace Terminal.Gui {
/// <summary>
/// Invoked when a key is released
/// </summary>
public Action<KeyEventEventArgs> KeyUp;
public event Action<KeyEventEventArgs> KeyUp;
/// <param name="keyEvent">Contains the details about the key that produced the event.</param>
public override bool OnKeyUp (KeyEvent keyEvent)
@@ -1730,7 +1730,7 @@ namespace Terminal.Gui {
/// <remarks>
/// Subscribe to this event to perform tasks when the <see cref="View"/> has been resized or the layout has otherwise changed.
/// </remarks>
public Action<LayoutEventArgs> LayoutStarted;
public event Action<LayoutEventArgs> LayoutStarted;
/// <summary>
/// Raises the <see cref="LayoutStarted"/> event. Called from <see cref="LayoutSubviews"/> before any subviews have been laid out.
@@ -1746,7 +1746,7 @@ namespace Terminal.Gui {
/// <remarks>
/// Subscribe to this event to perform tasks when the <see cref="View"/> has been resized or the layout has otherwise changed.
/// </remarks>
public Action<LayoutEventArgs> LayoutComplete;
public event Action<LayoutEventArgs> LayoutComplete;
/// <summary>
/// Event called only once when the <see cref="View"/> is being initialized for the first time.
@@ -1943,7 +1943,7 @@ namespace Terminal.Gui {
}
MouseEventArgs args = new MouseEventArgs (mouseEvent);
MouseClick?.Invoke (args);
OnMouseClick (args);
if (args.Handled)
return true;
if (MouseEvent (mouseEvent))
@@ -1961,6 +1961,11 @@ namespace Terminal.Gui {
return false;
}
/// <summary>
/// Invokes the MouseClick event.
/// </summary>
protected void OnMouseClick (MouseEventArgs args) => MouseClick?.Invoke (args);
/// <inheritdoc/>
protected override void Dispose (bool disposing)
{

View File

@@ -78,7 +78,7 @@ namespace Terminal.Gui {
public override bool OnMouseEvent (MouseEvent mouseEvent)
{
MouseEventArgs args = new MouseEventArgs (mouseEvent);
MouseClick?.Invoke (args);
OnMouseClick (args);
if (args.Handled)
return true;
if (MouseEvent (mouseEvent))

View File

@@ -477,7 +477,7 @@ namespace UICatalog {
EditMenuBarItem (null);
};
_lblMenuBar.Enter = (e) => {
_lblMenuBar.Enter += (e) => {
if (_menuBar?.Menus != null) {
_currentMenuBarItem = _menuBar.Menus [_currentSelectedMenuBar];
EditMenuBarItem (_menuBar.Menus [_currentSelectedMenuBar]);

View File

@@ -257,7 +257,7 @@ namespace UICatalog {
};
var filler = new Filler (new Rect (0, 0, 60, 40));
scrollView2.Add (filler);
scrollView2.DrawContent = (r) => {
scrollView2.DrawContent += (r) => {
scrollView2.ContentSize = filler.GetContentSize ();
};