Files
Terminal.Gui/Tests/UnitTestsParallelizable/ViewBase/Adornment/BorderArrangementTests.cs
BDisp 1a54ff0872 Fixes #4502. Shadows in overlapping views are not rendered consistently (#4465)
* Fixes Wide Glyphs

* Fix some unit tests failure

* Fix more unit tests

* Fixes #4468 - `MouseGrab` regressions (#4469)

* Fixed mouse grab issue

* Fixed mouse grab regrssions.

* Update Terminal.Gui/ViewBase/View.Mouse.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update Terminal.Gui/ViewBase/View.Mouse.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update Terminal.Gui/ViewBase/View.Mouse.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update Terminal.Gui/ViewBase/View.Mouse.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update Terminal.Gui/ViewBase/View.Mouse.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update Terminal.Gui/ViewBase/View.Mouse.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* code cleanup

* Update Terminal.Gui/ViewBase/View.Mouse.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Addressing pr feedback

* updated mouse.md

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Fixes #4050. Rename Command.Select and Selecting to Activate/Activating (#4470)

* Initial plan

* Rename Command.Select to Command.Activate and Selecting to Activating

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Add Activating event propagation to SuperView

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Update all comments and docs referencing Select to Activate

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Fix event log messages in examples to use Activating/Activate

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Revert automatic Activating event propagation that broke tests

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* Update docfx documentation to use Activate/Activating terminology

Co-authored-by: tig <585482+tig@users.noreply.github.com>

* renames

* Revert "Add Activating event propagation to SuperView"

This reverts commit 6d82bee9ad.

* added command diagrams

* mermaid

* updated level 3

* again

* Select->Activate in MouseTests.cs

* Update Terminal.Gui/Views/Selectors/FlagSelector.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Refactor: Rename Selecting to Activating in View APIs

Renamed the `Selecting` event and `OnSelecting` method to
`Activating` and `OnActivating` to better reflect their purpose.
Updated all related comments, test method names, variables,
and assertions in `View` and `ViewCommandTests` to align with
the new terminology.

Improved code clarity by using `_` for unused parameters in
lambda expressions. Renamed properties like `HandleSelecting`
to `HandleActivating` and adjusted naming conventions for
consistency (e.g., `OnactivatingCount` to `OnActivatingCount`).

These changes enhance readability, maintainability, and
terminology consistency across the codebase.

* Update Terminal.Gui/Views/Selectors/OptionSelector.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Typos

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tig <585482+tig@users.noreply.github.com>
Co-authored-by: Tig <tig@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Add support for wide glyphs into the ShadowStyle.Transparent

* The "IsDirty" content of the wide glyphs should be completely false after being displayed on the screen.

* FillRect must always call AddStr method to properly handle wide characters to invalidate overlapped wide glyphs, etc.

* We must set clip to the driver screen in the case where the view isn't Adornment and SuperView is null, allowing dialogs, popovers, etc to be drawn

* These assertions are important to ensure that the drawing state is consistent

* Subviews must be drawn after the superview content being drawn

* The attribute of next column of a wide glyph should be the same if it's in the clipped area

* Applied #4486

* Updated root view clipping logic to use App's screen or a large default rectangle, ensuring proper drawing area. Added comments clarifying subview drawing order and explaining issues with certain Debug.Assert checks in complex hierarchies, suggesting unit tests instead.

* Remove ClearFrame and always draw Margin if Thickness set

Removed the unused ClearFrame method from the View class. Updated DrawAdornments to always draw the Margin when its Thickness is not empty, regardless of ShadowStyle. This simplifies the drawing logic and removes unnecessary checks.

* Fix margin thickness adjustment

* Fix shadow draw on overlapped views

* Only draw shadows at the end of each runnable

* Only call ClearNeedsDraw in the static Draw method

* Replace unit test as requested

* Also use reverse in margins although not making difference

* Fix the ShadowStyle, ShadowWidth and ShadowHeight logic

* Making sure nothing broke.

* ShadowWidth and ShadowHeight always default to 1 at invalid values

* Removes unused parameter

* Using Rune.ReplacementChar to not confusing with space char inserted by the clearing region

* Using Rune.ReplacementChar

* Using Rune.ReplacementChar

* Fix merge error

* Fixing unit tests

* Reverting changes

* Fixing unit tests

* Fix unit test

* Fix shadow on overlapped views

* Cleanup code

---------

Co-authored-by: Tig <tig@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
Co-authored-by: tig <585482+tig@users.noreply.github.com>
2025-12-17 11:56:31 -07:00

272 lines
12 KiB
C#
Raw Blame History

#nullable enable
using System.Text;
using UnitTests;
using Xunit.Abstractions;
namespace ViewBaseTests.Adornments;
[Collection ("Global Test Setup")]
public class BorderArrangementTests (ITestOutputHelper output)
{
[Fact]
public void Arrangement_Handles_Wide_Glyphs_Correctly ()
{
IApplication app = Application.Create ();
app.Init ("fake");
app.Driver?.SetScreenSize (6, 5);
// Using a replacement char to make sure wide glyphs are handled correctly
// in the shadow area, to not confusing with a space char.
app.Driver?.GetOutputBuffer ().SetWideGlyphReplacement (Rune.ReplacementChar);
Runnable superview = new () { Width = Dim.Fill (), Height = Dim.Fill () };
superview.Text = """
🍎🍎🍎
🍎🍎🍎
🍎🍎🍎
🍎🍎🍎
🍎🍎🍎
""";
View view = new ()
{
X = 2, Width = 4, Height = 4, BorderStyle = LineStyle.Single,
Arrangement = ViewArrangement.Movable | ViewArrangement.Resizable, CanFocus = true
};
superview.Add (view);
app.Begin (superview);
Assert.Equal ("Absolute(2)", view.X.ToString ());
DriverAssert.AssertDriverContentsAre (
"""
🍎
🍎
🍎
🍎
🍎🍎🍎
""",
output,
app.Driver);
Assert.True (app.Keyboard.RaiseKeyDownEvent (Key.F5.WithCtrl));
app.LayoutAndDraw ();
DriverAssert.AssertDriverContentsAre (
"""
🍎
🍎
🍎
🍎
🍎🍎🍎
""",
output,
app.Driver);
Assert.True (app.Keyboard.RaiseKeyDownEvent (Key.CursorLeft));
Assert.Equal ("Absolute(1)", view.X.ToString ());
app.LayoutAndDraw ();
DriverAssert.AssertDriverContentsAre (
"""
<EFBFBD>
<EFBFBD>
<EFBFBD>
<EFBFBD>
🍎🍎🍎
""",
output,
app.Driver);
Assert.True (app.Keyboard.RaiseKeyDownEvent (Key.CursorLeft));
Assert.Equal ("Absolute(0)", view.X.ToString ());
app.LayoutAndDraw ();
DriverAssert.AssertDriverContentsAre (
"""
🍎
🍎
🍎
🍎
🍎🍎🍎
""",
output,
app.Driver);
}
[Fact]
public void Arrangement_With_SubView_In_Border_Handles_Wide_Glyphs_Correctly ()
{
IApplication app = Application.Create ();
app.Init ("fake");
app.Driver?.SetScreenSize (8, 7);
// Using a replacement char to make sure wide glyphs are handled correctly
// in the shadow area, to not confusing with a space char.
app.Driver?.GetOutputBuffer ().SetWideGlyphReplacement (Rune.ReplacementChar);
// Don't remove this array even if it seems unused, it is used to map the attributes indexes in the DriverAssert
// Otherwise the test won't detect issues with attributes not visibly by the naked eye
Attribute [] attributes =
[
new (ColorName16.Blue, ColorName16.BrightBlue, TextStyle.None),
new (ColorName16.BrightBlue, ColorName16.Blue, TextStyle.None),
new (ColorName16.Green, ColorName16.BrightGreen, TextStyle.None),
new (ColorName16.Magenta, ColorName16.BrightMagenta, TextStyle.None),
new (ColorName16.BrightMagenta, ColorName16.Magenta, TextStyle.None)
];
Runnable superview = new () { Width = Dim.Fill (), Height = Dim.Fill () };
superview.SetScheme (new () { Normal = attributes [0], Focus = attributes [1] });
superview.Text = """
🍎🍎🍎🍎
🍎🍎🍎🍎
🍎🍎🍎🍎
🍎🍎🍎🍎
🍎🍎🍎🍎
🍎🍎🍎🍎
🍎🍎🍎🍎
""";
View view = new () { X = 6, Width = 2, Height = 1, Text = "🦮" };
view.SetScheme (new () { Normal = attributes [2] });
View view2 = new ()
{
X = 2, Width = 6, Height = 6, Arrangement = ViewArrangement.Movable | ViewArrangement.Resizable, CanFocus = true
};
view2.Border!.Thickness = new (1);
view2.Border.Add (new View { Height = Dim.Auto (), Width = Dim.Auto (), Text = "Hi" });
view2.SetScheme (new () { Normal = attributes [3], HotNormal = attributes [4] });
superview.Add (view, view2);
app.Begin (superview);
Assert.Equal ("Absolute(2)", view2.X.ToString ());
DriverAssert.AssertDriverContentsAre (
"""
🍎Hi
🍎
🍎
🍎
🍎
🍎
🍎🍎🍎🍎
""",
output,
app.Driver);
DriverAssert.AssertDriverAttributesAre (
"""
11333333
11333333
11333333
11333333
11333333
11333333
11111111
""",
output,
app.Driver,
attributes);
Assert.True (app.Keyboard.RaiseKeyDownEvent (Key.F5.WithCtrl));
app.LayoutAndDraw ();
DriverAssert.AssertDriverContentsAre (
"""
🍎i
🍎
🍎
🍎
🍎
🍎
🍎🍎🍎🍎
""",
output,
app.Driver);
DriverAssert.AssertDriverAttributesAre (
"""
11433333
11333333
11333333
11333333
11333333
11333333
11111111
""",
output,
app.Driver,
attributes);
Assert.True (app.Keyboard.RaiseKeyDownEvent (Key.CursorLeft));
Assert.Equal ("Absolute(1)", view2.X.ToString ());
app.LayoutAndDraw ();
DriverAssert.AssertDriverContentsAre (
"""
<EFBFBD>i
<EFBFBD>
<EFBFBD>
<EFBFBD>
<EFBFBD>
<EFBFBD>
🍎🍎🍎🍎
""",
output,
app.Driver);
DriverAssert.AssertDriverAttributesAre (
"""
14333332
13333330
13333330
13333330
13333330
13333330
11111111
""",
output,
app.Driver,
attributes);
Assert.True (app.Keyboard.RaiseKeyDownEvent (Key.CursorLeft));
Assert.Equal ("Absolute(0)", view2.X.ToString ());
app.LayoutAndDraw ();
DriverAssert.AssertDriverContentsAre (
"""
i 🦮
🍎
🍎
🍎
🍎
🍎
🍎🍎🍎🍎
""",
output,
app.Driver);
DriverAssert.AssertDriverAttributesAre (
"""
43333322
33333311
33333311
33333311
33333311
33333311
11111111
""",
output,
app.Driver,
attributes);
}
}