Merge pull request #2104 from BDisp/view-clear-background

Fixes 2094. View does not clear it's background.
This commit is contained in:
Tig
2022-10-20 07:37:24 -07:00
committed by GitHub
3 changed files with 46 additions and 15 deletions

View File

@@ -14,6 +14,7 @@ using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using NStack;
namespace Terminal.Gui {
@@ -1495,16 +1496,19 @@ namespace Terminal.Gui {
var clipRect = new Rect (Point.Empty, frame.Size);
//if (ColorScheme != null && !(this is Toplevel)) {
if (ColorScheme != null) {
Driver.SetAttribute (HasFocus ? ColorScheme.Focus : ColorScheme.Normal);
}
if (Border != null) {
Border.DrawContent (this);
} else if ((GetType ().IsPublic || GetType ().IsNestedPublic) && !IsOverridden (this, "Redraw") &&
(!NeedDisplay.IsEmpty || ChildNeedsDisplay || LayoutNeeded)) {
Clear (ViewToScreen (bounds));
}
if (!ustring.IsNullOrEmpty (TextFormatter.Text) || (this is Label && !AutoSize)) {
if (!ustring.IsNullOrEmpty (TextFormatter.Text)) {
Clear ();
// Draw any Text
if (TextFormatter != null) {
@@ -3050,5 +3054,19 @@ namespace Terminal.Gui {
return top;
}
/// <summary>
/// Check if the <paramref name="method"/> is overridden in the <paramref name="view"/>.
/// </summary>
/// <param name="view">The view.</param>
/// <param name="method">The method name.</param>
/// <returns><see langword="true"/> if it's overridden, <see langword="false"/>otherwise.</returns>
public bool IsOverridden (View view, string method)
{
Type t = view.GetType ();
MethodInfo m = t.GetMethod (method);
return (m.DeclaringType == t || m.ReflectedType == t) && m.GetBaseDefinition ().DeclaringType == typeof (Responder);
}
}
}

View File

@@ -13,7 +13,6 @@
using System;
using System.Linq;
using System.Reflection;
namespace Terminal.Gui {
/// <summary>
@@ -217,7 +216,7 @@ namespace Terminal.Gui {
/// <param name="view">The view to add to the scrollview.</param>
public override void Add (View view)
{
if (!IsOverridden (view)) {
if (!IsOverridden (view, "MouseEvent")) {
view.MouseEnter += View_MouseEnter;
view.MouseLeave += View_MouseLeave;
}
@@ -237,14 +236,6 @@ namespace Terminal.Gui {
Application.GrabMouse (this);
}
bool IsOverridden (View view)
{
Type t = view.GetType ();
MethodInfo m = t.GetMethod ("MouseEvent");
return (m.DeclaringType == t || m.ReflectedType == t) && m.GetBaseDefinition ().DeclaringType == typeof (Responder);
}
/// <summary>
/// Gets or sets the visibility for the horizontal scroll indicator.
/// </summary>
@@ -515,7 +506,7 @@ namespace Terminal.Gui {
vertical.MouseEvent (me);
} else if (me.Y == horizontal.Frame.Y && ShowHorizontalScrollIndicator) {
horizontal.MouseEvent (me);
} else if (IsOverridden (me.View)) {
} else if (IsOverridden (me.View, "MouseEvent")) {
Application.UngrabMouse ();
}
return true;

View File

@@ -2123,6 +2123,28 @@ Y
Assert.Equal (new Rect (0, 0, 8, 4), pos);
}
[Fact, AutoInitShutdown]
public void DrawFrame_With_Minimum_Size ()
{
var view = new View (new Rect (0, 0, 2, 2));
view.DrawContent += (_) => view.DrawFrame (view.Bounds, 0, true);
Assert.Equal (Point.Empty, new Point (view.Frame.X, view.Frame.Y));
Assert.Equal (new Size (2, 2), new Size (view.Frame.Width, view.Frame.Height));
Application.Top.Add (view);
Application.Begin (Application.Top);
var expected = @"
┌┐
└┘
";
var pos = GraphViewTests.AssertDriverContentsWithFrameAre (expected, output);
Assert.Equal (new Rect (0, 0, 2, 2), pos);
}
[Fact, AutoInitShutdown]
public void DrawFrame_With_Negative_Positions ()
{
@@ -2452,7 +2474,7 @@ Y
Width = Dim.Fill (),
Height = Dim.Fill ()
};
view.LayoutComplete += e => {
view.DrawContent += e => {
view.DrawFrame (view.Bounds);
var savedClip = Application.Driver.Clip;
Application.Driver.Clip = new Rect (1, 1, view.Bounds.Width - 2, view.Bounds.Height - 2);
@@ -2500,7 +2522,7 @@ Y
Width = Dim.Fill (),
Height = Dim.Fill ()
};
view.LayoutComplete += e => {
view.DrawContent += e => {
view.DrawFrame (view.Bounds);
var savedClip = Application.Driver.Clip;
Application.Driver.Clip = new Rect (1, 1, view.Bounds.Width - 2, view.Bounds.Height - 2);