mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-28 16:58:01 +01:00
Got Hover working for all Views (Button) and Border. Still a bit of a prototype.
This commit is contained in:
@@ -212,7 +212,7 @@ public class Adornment : View
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
protected internal override bool OnMouseEnter (MouseEvent mouseEvent)
|
||||
protected internal override bool? OnMouseEnter (MouseEvent mouseEvent)
|
||||
{
|
||||
// Invert Normal
|
||||
if (Diagnostics.HasFlag (ViewDiagnosticFlags.MouseEnter) && ColorScheme != null)
|
||||
|
||||
@@ -57,7 +57,7 @@ public class Border : Adornment
|
||||
Application.GrabbingMouse += Application_GrabbingMouse;
|
||||
Application.UnGrabbingMouse += Application_UnGrabbingMouse;
|
||||
|
||||
HighlightStyle = HighlightStyle.Pressed;
|
||||
HighlightStyle |= HighlightStyle.Pressed;
|
||||
Highlight += Border_Highlight;
|
||||
}
|
||||
|
||||
@@ -73,6 +73,12 @@ public class Border : Adornment
|
||||
/// <inheritdoc/>
|
||||
public override void BeginInit ()
|
||||
{
|
||||
// TOOD: Hack - make Arragnement overidable
|
||||
if ((Parent?.Arrangement & ViewArrangement.Movable) != 0)
|
||||
{
|
||||
HighlightStyle |= HighlightStyle.Hover;
|
||||
}
|
||||
|
||||
base.BeginInit ();
|
||||
|
||||
#if SUBVIEW_BASED_BORDER
|
||||
@@ -100,7 +106,7 @@ public class Border : Adornment
|
||||
LayoutStarted += OnLayoutStarted;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#if SUBVIEW_BASED_BORDER
|
||||
private void OnLayoutStarted (object sender, LayoutEventArgs e)
|
||||
@@ -190,18 +196,30 @@ public class Border : Adornment
|
||||
|
||||
#region Mouse Support
|
||||
|
||||
private LineStyle _savedHighlightLineStyle;
|
||||
private LineStyle? _savedHighlightLineStyle;
|
||||
|
||||
private void Border_Highlight (object sender, HighlightEventArgs e)
|
||||
{
|
||||
if (e.HighlightStyle == HighlightStyle)
|
||||
if (e.HighlightStyle.HasFlag (HighlightStyle.Pressed))
|
||||
{
|
||||
_savedHighlightLineStyle = Parent?.BorderStyle ?? LineStyle;
|
||||
if (!_savedHighlightLineStyle.HasValue)
|
||||
{
|
||||
_savedHighlightLineStyle = Parent?.BorderStyle ?? LineStyle;
|
||||
}
|
||||
LineStyle = LineStyle.Heavy;
|
||||
}
|
||||
else
|
||||
else if (e.HighlightStyle.HasFlag (HighlightStyle.Hover))
|
||||
{
|
||||
LineStyle = _savedHighlightLineStyle;
|
||||
if (!_savedHighlightLineStyle.HasValue)
|
||||
{
|
||||
_savedHighlightLineStyle = Parent?.BorderStyle ?? LineStyle;
|
||||
}
|
||||
LineStyle = LineStyle.Double;
|
||||
}
|
||||
|
||||
if (e.HighlightStyle == HighlightStyle.None && _savedHighlightLineStyle.HasValue)
|
||||
{
|
||||
LineStyle = _savedHighlightLineStyle.Value;
|
||||
}
|
||||
Parent?.SetNeedsDisplay ();
|
||||
e.Cancel = true;
|
||||
@@ -321,7 +339,7 @@ public class Border : Adornment
|
||||
}
|
||||
}
|
||||
|
||||
#endregion Mouse Support
|
||||
#endregion Mouse Support
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void OnDrawContent (Rectangle contentArea)
|
||||
|
||||
@@ -90,7 +90,17 @@ public partial class View
|
||||
return false;
|
||||
}
|
||||
|
||||
return OnMouseEnter (mouseEvent);
|
||||
if (OnMouseEnter (mouseEvent) == true)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (HighlightStyle.HasFlag(HighlightStyle.Hover))
|
||||
{
|
||||
SetHighlight (HighlightStyle.Hover);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -108,7 +118,7 @@ public partial class View
|
||||
/// </remarks>
|
||||
/// <param name="mouseEvent"></param>
|
||||
/// <returns><see langword="true"/>, if the event was handled, <see langword="false"/> otherwise.</returns>
|
||||
protected internal virtual bool OnMouseEnter (MouseEvent mouseEvent)
|
||||
protected internal virtual bool? OnMouseEnter (MouseEvent mouseEvent)
|
||||
{
|
||||
|
||||
var args = new MouseEventEventArgs (mouseEvent);
|
||||
@@ -150,7 +160,17 @@ public partial class View
|
||||
return false;
|
||||
}
|
||||
|
||||
return OnMouseLeave (mouseEvent);
|
||||
if (OnMouseEnter (mouseEvent) == true)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (HighlightStyle.HasFlag (HighlightStyle.Hover))
|
||||
{
|
||||
SetHighlight (HighlightStyle.None);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
/// <summary>
|
||||
/// Called by <see cref="NewMouseEvent"/> when a mouse leaves <see cref="Bounds"/>. The view will
|
||||
@@ -400,12 +420,28 @@ public partial class View
|
||||
/// </remarks>
|
||||
internal void SetHighlight (HighlightStyle style)
|
||||
{
|
||||
// TODO: Make the highlight colors configurable
|
||||
|
||||
// Enable override via virtual method and/or event
|
||||
if (OnHighlight (style) == true)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (style.HasFlag (HighlightStyle.Hover))
|
||||
{
|
||||
if (_savedHighlightColorScheme is null && ColorScheme is { })
|
||||
{
|
||||
_savedHighlightColorScheme ??= ColorScheme;
|
||||
|
||||
var cs = new ColorScheme (ColorScheme)
|
||||
{
|
||||
Normal = new (ColorName.BrightRed, ColorName.Black),
|
||||
};
|
||||
ColorScheme = cs;
|
||||
}
|
||||
}
|
||||
|
||||
if (style.HasFlag (HighlightStyle.Pressed) || style.HasFlag (HighlightStyle.PressedOutside))
|
||||
{
|
||||
|
||||
@@ -415,14 +451,9 @@ public partial class View
|
||||
|
||||
if (CanFocus)
|
||||
{
|
||||
// TODO: Make the inverted color configurable
|
||||
var cs = new ColorScheme (ColorScheme)
|
||||
{
|
||||
// For Buttons etc...
|
||||
Focus = new (ColorScheme.Normal.Foreground, ColorScheme.Focus.Background),
|
||||
|
||||
// For Adornments
|
||||
Normal = new (ColorScheme.Focus.Foreground, ColorScheme.Normal.Background)
|
||||
};
|
||||
ColorScheme = cs;
|
||||
}
|
||||
@@ -437,7 +468,8 @@ public partial class View
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
if (style == HighlightStyle.None)
|
||||
{
|
||||
// Unhighlight
|
||||
if (_savedHighlightColorScheme is { })
|
||||
|
||||
@@ -54,6 +54,7 @@ public class Button : View
|
||||
CanFocus = true;
|
||||
AutoSize = true;
|
||||
HighlightStyle |= HighlightStyle.Pressed;
|
||||
HighlightStyle |= HighlightStyle.Hover;
|
||||
|
||||
// Override default behavior of View
|
||||
AddCommand (Command.HotKey, () =>
|
||||
|
||||
Reference in New Issue
Block a user