Merge branch 'develop' into fixes_2296_attribute_make

This commit is contained in:
Tig
2023-02-06 07:08:44 +09:00
committed by GitHub
9 changed files with 1597 additions and 128 deletions

View File

@@ -1,4 +1,5 @@
using System;
using NStack;
using System;
using Xunit;
using Xunit.Abstractions;
//using GraphViewTests = Terminal.Gui.Views.GraphViewTests;
@@ -3991,6 +3992,7 @@ This is a tes
public bool IsKeyDown { get; set; }
public bool IsKeyPress { get; set; }
public bool IsKeyUp { get; set; }
public override ustring Text { get; set; }
public override bool OnKeyDown (KeyEvent keyEvent)
{
@@ -4009,6 +4011,41 @@ This is a tes
IsKeyUp = true;
return true;
}
public void CorrectRedraw (Rect bounds)
{
// Clear the old and new frame area
Clear (NeedDisplay);
DrawText ();
}
public void IncorrectRedraw (Rect bounds)
{
// Clear only the new frame area
Clear ();
DrawText ();
}
private void DrawText ()
{
var idx = 0;
for (int r = 0; r < Frame.Height; r++) {
for (int c = 0; c < Frame.Width; c++) {
if (idx < Text.Length) {
var rune = Text [idx];
if (rune != '\n') {
AddRune (c, r, Text [idx]);
}
idx++;
if (rune == '\n') {
break;
}
}
}
}
ClearLayoutNeeded ();
ClearNeedsDisplay ();
}
}
[Theory, AutoInitShutdown]
@@ -4176,5 +4213,281 @@ cccccccccccccccccccc", output);
111111111111111111110", attributes);
}
}
[Fact, AutoInitShutdown]
public void Correct_Redraw_Bounds_NeedDisplay_On_Shrink_And_Move_Up_Left_Using_Frame ()
{
var label = new Label ("At 0,0");
var view = new DerivedView () {
X = 2,
Y = 2,
Width = 30,
Height = 2,
Text = "A text with some long width\n and also with two lines."
};
var top = Application.Top;
top.Add (label, view);
Application.Begin (top);
view.CorrectRedraw (view.Bounds);
TestHelpers.AssertDriverContentsWithFrameAre (@"
At 0,0
A text with some long width
and also with two lines. ", output);
view.Frame = new Rect (1, 1, 10, 1);
Assert.Equal (new Rect (0, 0, 10, 1), view.Bounds);
Assert.Equal (new Rect (1, 1, 31, 3), view.NeedDisplay);
view.CorrectRedraw (view.Bounds);
TestHelpers.AssertDriverContentsWithFrameAre (@"
At 0,0
A text wit", output);
}
[Fact, AutoInitShutdown]
public void Correct_Redraw_Bounds_NeedDisplay_On_Shrink_And_Move_Up_Left_Using_Pos_Dim ()
{
var label = new Label ("At 0,0");
var view = new DerivedView () {
X = 2,
Y = 2,
Width = 30,
Height = 2,
Text = "A text with some long width\n and also with two lines."
};
var top = Application.Top;
top.Add (label, view);
Application.Begin (top);
view.CorrectRedraw (view.Bounds);
TestHelpers.AssertDriverContentsWithFrameAre (@"
At 0,0
A text with some long width
and also with two lines. ", output);
view.X = 1;
view.Y = 1;
view.Width = 10;
view.Height = 1;
Assert.Equal (new Rect (1, 1, 10, 1), view.Frame);
Assert.Equal (new Rect (0, 0, 10, 1), view.Bounds);
Assert.Equal (new Rect (1, 1, 31, 3), view.NeedDisplay);
view.CorrectRedraw (view.Bounds);
TestHelpers.AssertDriverContentsWithFrameAre (@"
At 0,0
A text wit", output);
}
[Fact, AutoInitShutdown]
public void Incorrect_Redraw_Bounds_NeedDisplay_On_Shrink_And_Move_Up_Left_Using_Frame ()
{
var label = new Label ("At 0,0");
var view = new DerivedView () {
X = 2,
Y = 2,
Width = 30,
Height = 2,
Text = "A text with some long width\n and also with two lines."
};
var top = Application.Top;
top.Add (label, view);
Application.Begin (top);
view.IncorrectRedraw (view.Bounds);
TestHelpers.AssertDriverContentsWithFrameAre (@"
At 0,0
A text with some long width
and also with two lines. ", output);
view.Frame = new Rect (1, 1, 10, 1);
Assert.Equal (new Rect (0, 0, 10, 1), view.Bounds);
Assert.Equal (new Rect (1, 1, 31, 3), view.NeedDisplay);
view.IncorrectRedraw (view.Bounds);
TestHelpers.AssertDriverContentsWithFrameAre (@"
At 0,0
A text wit
A text with some long width
and also with two lines. ", output);
}
[Fact, AutoInitShutdown]
public void Incorrect_Redraw_Bounds_NeedDisplay_On_Shrink_And_Move_Up_Left_Using_Pos_Dim ()
{
var label = new Label ("At 0,0");
var view = new DerivedView () {
X = 2,
Y = 2,
Width = 30,
Height = 2,
Text = "A text with some long width\n and also with two lines."
};
var top = Application.Top;
top.Add (label, view);
Application.Begin (top);
view.IncorrectRedraw (view.Bounds);
TestHelpers.AssertDriverContentsWithFrameAre (@"
At 0,0
A text with some long width
and also with two lines. ", output);
view.X = 1;
view.Y = 1;
view.Width = 10;
view.Height = 1;
Assert.Equal (new Rect (1, 1, 10, 1), view.Frame);
Assert.Equal (new Rect (0, 0, 10, 1), view.Bounds);
Assert.Equal (new Rect (1, 1, 31, 3), view.NeedDisplay);
view.IncorrectRedraw (view.Bounds);
TestHelpers.AssertDriverContentsWithFrameAre (@"
At 0,0
A text wit
A text with some long width
and also with two lines. ", output);
}
[Fact, AutoInitShutdown]
public void Correct_Redraw_Bounds_NeedDisplay_On_Shrink_And_Move_Down_Right_Using_Frame ()
{
var label = new Label ("At 0,0");
var view = new DerivedView () {
X = 2,
Y = 2,
Width = 30,
Height = 2,
Text = "A text with some long width\n and also with two lines."
};
var top = Application.Top;
top.Add (label, view);
Application.Begin (top);
view.CorrectRedraw (view.Bounds);
TestHelpers.AssertDriverContentsWithFrameAre (@"
At 0,0
A text with some long width
and also with two lines. ", output);
view.Frame = new Rect (3, 3, 10, 1);
Assert.Equal (new Rect (0, 0, 10, 1), view.Bounds);
Assert.Equal (new Rect (2, 2, 30, 2), view.NeedDisplay);
view.CorrectRedraw (view.Bounds);
TestHelpers.AssertDriverContentsWithFrameAre (@"
At 0,0
A text wit", output);
}
[Fact, AutoInitShutdown]
public void Correct_Redraw_Bounds_NeedDisplay_On_Shrink_And_Move_Down_Right_Using_Pos_Dim ()
{
var label = new Label ("At 0,0");
var view = new DerivedView () {
X = 2,
Y = 2,
Width = 30,
Height = 2,
Text = "A text with some long width\n and also with two lines."
};
var top = Application.Top;
top.Add (label, view);
Application.Begin (top);
view.CorrectRedraw (view.Bounds);
TestHelpers.AssertDriverContentsWithFrameAre (@"
At 0,0
A text with some long width
and also with two lines. ", output);
view.X = 3;
view.Y = 3;
view.Width = 10;
view.Height = 1;
Assert.Equal (new Rect (3, 3, 10, 1), view.Frame);
Assert.Equal (new Rect (0, 0, 10, 1), view.Bounds);
Assert.Equal (new Rect (2, 2, 30, 2), view.NeedDisplay);
view.CorrectRedraw (view.Bounds);
TestHelpers.AssertDriverContentsWithFrameAre (@"
At 0,0
A text wit", output);
}
[Fact, AutoInitShutdown]
public void Incorrect_Redraw_Bounds_NeedDisplay_On_Shrink_And_Move_Down_Right_Using_Frame ()
{
var label = new Label ("At 0,0");
var view = new DerivedView () {
X = 2,
Y = 2,
Width = 30,
Height = 2,
Text = "A text with some long width\n and also with two lines."
};
var top = Application.Top;
top.Add (label, view);
Application.Begin (top);
view.IncorrectRedraw (view.Bounds);
TestHelpers.AssertDriverContentsWithFrameAre (@"
At 0,0
A text with some long width
and also with two lines. ", output);
view.Frame = new Rect (3, 3, 10, 1);
Assert.Equal (new Rect (0, 0, 10, 1), view.Bounds);
Assert.Equal (new Rect (2, 2, 30, 2), view.NeedDisplay);
view.IncorrectRedraw (view.Bounds);
TestHelpers.AssertDriverContentsWithFrameAre (@"
At 0,0
A text with some long width
A text witith two lines. ", output);
}
[Fact, AutoInitShutdown]
public void Incorrect_Redraw_Bounds_NeedDisplay_On_Shrink_And_Move_Down_Right_Using_Pos_Dim ()
{
var label = new Label ("At 0,0");
var view = new DerivedView () {
X = 2,
Y = 2,
Width = 30,
Height = 2,
Text = "A text with some long width\n and also with two lines."
};
var top = Application.Top;
top.Add (label, view);
Application.Begin (top);
view.IncorrectRedraw (view.Bounds);
TestHelpers.AssertDriverContentsWithFrameAre (@"
At 0,0
A text with some long width
and also with two lines. ", output);
view.X = 3;
view.Y = 3;
view.Width = 10;
view.Height = 1;
Assert.Equal (new Rect (3, 3, 10, 1), view.Frame);
Assert.Equal (new Rect (0, 0, 10, 1), view.Bounds);
Assert.Equal (new Rect (2, 2, 30, 2), view.NeedDisplay);
view.IncorrectRedraw (view.Bounds);
TestHelpers.AssertDriverContentsWithFrameAre (@"
At 0,0
A text with some long width
A text witith two lines. ", output);
}
}
}