Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions Terminal.Gui/Core/View.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using NStack;

namespace Terminal.Gui {
Expand Down Expand Up @@ -1495,16 +1496,19 @@ public virtual void Redraw (Rect bounds)

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) {
Expand Down Expand Up @@ -3050,5 +3054,19 @@ public View GetTopSuperView ()

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);
}
}
}
13 changes: 2 additions & 11 deletions Terminal.Gui/Views/ScrollView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

using System;
using System.Linq;
using System.Reflection;

namespace Terminal.Gui {
/// <summary>
Expand Down Expand Up @@ -217,7 +216,7 @@ public bool KeepContentAlwaysInViewport {
/// <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;
}
Expand All @@ -237,14 +236,6 @@ void View_MouseEnter (MouseEventArgs e)
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>
Expand Down Expand Up @@ -515,7 +506,7 @@ public override bool MouseEvent (MouseEvent me)
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;
Expand Down
26 changes: 24 additions & 2 deletions UnitTests/ViewTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2123,6 +2123,28 @@ public void DrawFrame_With_Positive_Positions ()
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 ()
{
Expand Down Expand Up @@ -2452,7 +2474,7 @@ public void Clear_Can_Use_Driver_AddRune_Or_AddStr_Methods ()
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);
Expand Down Expand Up @@ -2500,7 +2522,7 @@ public void Clear_Bounds_Can_Use_Driver_AddRune_Or_AddStr_Methods ()
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);
Expand Down