mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
Added wheeling feature to the ScrollView.
This commit is contained in:
@@ -2267,8 +2267,12 @@ namespace Terminal.Gui {
|
||||
OfY = me.Y - newxy.Y,
|
||||
View = view
|
||||
};
|
||||
mouseGrabView.MouseEvent (nme);
|
||||
return;
|
||||
if (OutsideFrame (new Point (nme.X, nme.Y), mouseGrabView.Frame))
|
||||
lastMouseOwnerView.OnMouseLeave (me);
|
||||
if (mouseGrabView != null) {
|
||||
mouseGrabView.MouseEvent (nme);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (view != null) {
|
||||
@@ -2303,6 +2307,11 @@ namespace Terminal.Gui {
|
||||
}
|
||||
}
|
||||
|
||||
static bool OutsideFrame (Point p, Rect r)
|
||||
{
|
||||
return p.X < 0 || p.X > r.Width - 1 || p.Y < 0 || p.Y > r.Height - 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Action that is invoked once at beginning.
|
||||
/// </summary>
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
// - Perhaps allow an option to not display the scrollbar arrow indicators?
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Terminal.Gui {
|
||||
/// <summary>
|
||||
/// ScrollBarViews are views that display a 1-character scrollbar, either horizontal or vertical
|
||||
@@ -73,7 +75,7 @@ namespace Terminal.Gui {
|
||||
/// <param name="rect">Frame for the scrollbar.</param>
|
||||
/// <param name="size">The size that this scrollbar represents.</param>
|
||||
/// <param name="position">The position within this scrollbar.</param>
|
||||
/// <param name="isVertical">If set to <c>true</c> this is a vertical scrollbar, otherwize, the scrollbar is horizontal.</param>
|
||||
/// <param name="isVertical">If set to <c>true</c> this is a vertical scrollbar, otherwise, the scrollbar is horizontal.</param>
|
||||
public ScrollBarView (Rect rect, int size, int position, bool isVertical) : base (rect)
|
||||
{
|
||||
vertical = isVertical;
|
||||
@@ -314,9 +316,35 @@ namespace Terminal.Gui {
|
||||
/// <param name="view">The view to add to the scrollview.</param>
|
||||
public override void Add (View view)
|
||||
{
|
||||
if (!IsOverridden (view)) {
|
||||
view.MouseEnter += View_MouseEnter;
|
||||
view.MouseLeave += View_MouseLeave;
|
||||
vertical.MouseEnter += View_MouseEnter;
|
||||
vertical.MouseLeave += View_MouseLeave;
|
||||
horizontal.MouseEnter += View_MouseEnter;
|
||||
horizontal.MouseLeave += View_MouseLeave;
|
||||
}
|
||||
contentView.Add (view);
|
||||
}
|
||||
|
||||
void View_MouseLeave (object sender, MouseEvent e)
|
||||
{
|
||||
Application.UngrabMouse ();
|
||||
}
|
||||
|
||||
void View_MouseEnter (object sender, MouseEvent e)
|
||||
{
|
||||
Application.GrabMouse (this);
|
||||
}
|
||||
|
||||
bool IsOverridden (View view)
|
||||
{
|
||||
Type t = view.GetType ();
|
||||
MethodInfo m = t.GetMethod ("MouseEvent");
|
||||
|
||||
return m.DeclaringType == t && m.GetBaseDefinition ().DeclaringType == typeof (Responder);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the visibility for the horizontal scroll indicator.
|
||||
/// </summary>
|
||||
@@ -463,7 +491,7 @@ namespace Terminal.Gui {
|
||||
switch (kb.Key) {
|
||||
case Key.CursorUp:
|
||||
return ScrollUp (1);
|
||||
case (Key) 'v' | Key.AltMask:
|
||||
case (Key)'v' | Key.AltMask:
|
||||
case Key.PageUp:
|
||||
return ScrollUp (Bounds.Height);
|
||||
|
||||
@@ -489,5 +517,18 @@ namespace Terminal.Gui {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool MouseEvent (MouseEvent me)
|
||||
{
|
||||
if (me.Flags != MouseFlags.WheeledDown && me.Flags != MouseFlags.WheeledUp)
|
||||
return false;
|
||||
|
||||
if (me.Flags == MouseFlags.WheeledDown)
|
||||
ScrollDown (1);
|
||||
else if (me.Flags == MouseFlags.WheeledUp)
|
||||
ScrollUp (1);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user