Skip to content

Partially Fixes #2483 - Removes old Border and leverages LineCanvas for Frames, etc...#2527

Merged
tig merged 24 commits into
gui-cs:v2_developfrom
tig:v2_autojoin_borders_fixes_2483
Apr 13, 2023
Merged

Partially Fixes #2483 - Removes old Border and leverages LineCanvas for Frames, etc...#2527
tig merged 24 commits into
gui-cs:v2_developfrom
tig:v2_autojoin_borders_fixes_2483

Conversation

@tig
Copy link
Copy Markdown
Member

@tig tig commented Apr 11, 2023

This PR is fairly massive, but also super cool (I think).

VwUOoRy 1

It includes:

  • Partial Fix of Remove need for TileView - Use LineCanvas to draw borders and auto-join borders #2483
    • Adds LineCanvas property to View. If the new UseSuperViewLineCanvas property is true (default is false) then the Border (a Frame) will use the view's SuperView's LineCanvas. This enables auto-join. But there are a bunch of edge cases for this to work smoothly that I'll tackle in a future PR that will complete Remove need for TileView - Use LineCanvas to draw borders and auto-join borders #2483.
    • The LineCanvas Experiments sets UseSuperViewLineCanvas to true so you can play around with this.
  • Fixes 'LineCanvas has two minds about what Length == 0` means #2530
  • Adds new APIs to LineCanvas and does some refactoring to ease testing (Clear, Bounds, ToString, ...)
  • Massively expands LineCanvas unit tests
  • Updates Rect with a better Union method that supports Rects with negative coords; changes ToString to match .NET style; Adds unit tests
  • Adds a new Line class that will eventually replace LineView. For now it's only used in a "LineCanvas Experiments" for testing.
  • Removes ConsoleDriver.DrawWindowFrame and ConsoleDriver.DrawWindowTitle
  • Moves View.DrawFrame to Frame.DrawFrame (still obsolete and not long for this world once the few Views that use it get refactored).
  • Adds DrawTitle to Frame (temporary API)
  • Renames BorderFrame to Border
  • Adds three new TestHelpers
    • SetupFakeDriverAttribute that simply sets Application.Driver = new FakeDriver() so code like LineCanvas that needs a driver can work without the overhead of AutoInitShutdown (which makes unit tests slower)
    • These guys make it easy to NOT use output and the CRAZY AssserDriverContentsAre... functions which cause hair loss.
	/// <summary>
	/// Verifies two strings are equivalent. If the assert fails, output will be generated to standard 
	/// output showing the expected and actual look.
	/// </summary>
	/// <param name="output"></param>
	/// <param name="expectedLook">A string containing the expected look. Newlines should be specified as "\r\n" as
	/// they will be converted to <see cref="Environment.NewLine"/> to make tests platform independent.</param>
	/// <param name="actualLook"></param>
	public static void AssertEqual (ITestOutputHelper output, string expectedLook, string actualLook)
	{
		// Convert newlines to platform-specific newlines
		expectedLook = expectedLook.Replace ("\r\n", Environment.NewLine);
		
		// If test is about to fail show user what things looked like
		if (!string.Equals (expectedLook, actualLook)) {
			output?.WriteLine ("Expected:" + Environment.NewLine + expectedLook);
			output?.WriteLine ("But Was:" + Environment.NewLine + actualLook);
		}

		Assert.Equal (expectedLook, actualLook);
	}

	/// <summary>
	/// Verifies two strings are equivalent. If the assert fails, output will be generated to standard 
	/// output showing the expected and actual look. 
	/// </summary>
	/// <param name="output">Uses <see cref="ustring.ToString()"/> on <paramref name="actualLook"/>.</param>
	/// <param name="expectedLook">A string containing the expected look. Newlines should be specified as "\r\n" as
	/// they will be converted to <see cref="Environment.NewLine"/> to make tests platform independent.</param>
	/// <param name="actualLook"></param>
	public static void AssertEqual (ITestOutputHelper output, string expectedLook, ustring actualLook)
	{
		// Convert newlines to platform-specific newlines
		expectedLook = expectedLook.Replace ("\r\n", Environment.NewLine);

		// If test is about to fail show user what things looked like
		if (!string.Equals (expectedLook, actualLook)) {
			output?.WriteLine ("Expected:" + Environment.NewLine + expectedLook);
			output?.WriteLine ("But Was:" + Environment.NewLine + actualLook.ToString ());
		}

		Assert.Equal (expectedLook, actualLook);
	}

Pull Request checklist:

  • I've named my PR in the form of "Fixes #issue. Terse description."
  • My code follows the style guidelines of Terminal.Gui - if you use Visual Studio, hit CTRL-K-D to automatically reformat your files before committing.
  • My code follows the Terminal.Gui library design guidelines
  • I ran dotnet test before commit
  • I have made corresponding changes to the API documentation (using /// style comments)
  • My changes generate no new warnings
  • I have checked my code and corrected any poor grammar or misspellings
  • I conducted basic QA to assure all features are working

@tig tig mentioned this pull request Apr 12, 2023
8 tasks
@tig tig changed the title Fxes #2483 - Modifying Fxes #2483 - Removes old Border and leverages LineCanvas Apr 12, 2023
@tig tig changed the title Fxes #2483 - Removes old Border and leverages LineCanvas Fxes #2483 - Auto-join Borders - Removes old Border and leverages LineCanvas Apr 12, 2023
@tig tig marked this pull request as ready for review April 13, 2023 07:38
@tig tig requested a review from migueldeicaza as a code owner April 13, 2023 07:38
@tig tig changed the title Fxes #2483 - Auto-join Borders - Removes old Border and leverages LineCanvas Fxes #2483 - Removes old Border and leverages LineCanvas for Frames, etc... Apr 13, 2023
@tig tig changed the title Fxes #2483 - Removes old Border and leverages LineCanvas for Frames, etc... Partially Fixes #2483 - Removes old Border and leverages LineCanvas for Frames, etc... Apr 13, 2023
@tig
Copy link
Copy Markdown
Member Author

tig commented Apr 13, 2023

In addition to the updates in the first comment of this PR...

  • @BDisp I broke a few unit tests having to do with popups over dialogs. I couldn't figure it out. Maybe you can see what I did? Search for BUGBUG: Broke this test with #2483

@BDisp
Copy link
Copy Markdown
Collaborator

BDisp commented Apr 13, 2023

Looking into gif above, the current window being drag should be bring to front to overlap the others. Another issue is the borders being visible inside two windows. Only the border of the window being dragged should be visible inside others windows.

@tig
Copy link
Copy Markdown
Member Author

tig commented Apr 13, 2023

Looking into gif above, the current window being drag should be bring to front to overlap the others. Another issue is the borders being visible inside two windows. Only the border of the window being dragged should be visible inside others windows.

Right. These are all things that will need to be fixed before al this is done.

Related: #2537

Looking into gif above, the current window being drag should be bring to front to overlap the others.

This would bein Overalp mode only. In Tile mode the right behavior would be for it not be possible to have overlaps. This is what I meant in the spec:

image

Only the border of the window being dragged should be visible inside others windows.

Yes. My original plan, which is now partially implemented in this PR, was to have subviews just render to their SuperView's LineCanvas. But this causes the addition of the Lines to be done in the order opposite of how the subviews were added (their z-order). I've now realized this wont work for this reason and a few others.

Instead, we'll have the subviews render to their ownLineCanvas. The SuperView will then iterate through each subview, rendering that subview's LineCanvas in the correct order.

@BDisp
Copy link
Copy Markdown
Collaborator

BDisp commented Apr 13, 2023

Expected:
┌──────────────────┐
│                  │
│ ┌─────────────┐  │
│ │ Test        │  │
┌───────────────────
│ Select All   Ctrl+
│ Delete All   Ctrl+
│ Copy         Ctrl+
│ Cut          Ctrl+
│ Paste        Ctrl+
│ Undo         Ctrl+
│ Redo         Ctrl+
└───────────────────
│                  │
└──────────────────┘
But Was:
┌──────────────────┐
│                  │
│ ┌─────────────┐  │
│ │ Test        │  │
┌─│─────────────│───
│ └─────────────┘rl+
│ Delete All   Ctrl+
│ Copy         Ctrl+
│ Cut          Ctrl+
│ Paste        Ctrl+
│ Undo         Ctrl+
│ Redo         Ctrl+
└───────────────────
│                  │
└──────────────────┘

For sure I don´t like the current result. The question is what aspect should it has to have, since the LineCanvas is so powered? The Expected or the following?

┌──────────────────┐
│                  │
│ ┌─────────────┐  │
│ │ Test        │  │
├─┴─────────────┴──┴
│ Select All   Ctrl+
│ Delete All   Ctrl+
│ Copy         Ctrl+
│ Cut          Ctrl+
│ Paste        Ctrl+
│ Undo         Ctrl+
│ Redo         Ctrl+
├──────────────────┬
│                  │
└──────────────────┘

Copy link
Copy Markdown
Collaborator

@BDisp BDisp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tig I'll submit a PR to this PR.

Comment thread UnitTests/TestHelpers.cs Outdated
public static void AssertEqual (ITestOutputHelper output, string expectedLook, string actualLook)
{
// Convert newlines to platform-specific newlines
expectedLook = expectedLook.Replace ("\r\n", Environment.NewLine);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tig it seems that you are only testing on Linux because this will throw an exception if testing on Windows. You have to add the follow line:

		if (Environment.NewLine.Length == 2 && !expectedLook.Contains ("\r\n")) {
			expectedLook = expectedLook.Replace ("\n", Environment.NewLine);
		} else if (Environment.NewLine.Length == 1) {
			expectedLook = expectedLook.Replace ("\r\n", Environment.NewLine);
		}

Comment thread UnitTests/TestHelpers.cs Outdated
public static void AssertEqual (ITestOutputHelper output, string expectedLook, ustring actualLook)
{
// Convert newlines to platform-specific newlines
expectedLook = expectedLook.Replace ("\r\n", Environment.NewLine);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tig it seems that you are only testing on Linux because this will throw an exception if testing on Windows. You have to add the follow line:

		if (Environment.NewLine.Length == 2 && !expectedLook.Contains ("\r\n")) {
			expectedLook = expectedLook.Replace ("\n", Environment.NewLine);
		} else {
			expectedLook = expectedLook.Replace ("\r\n", Environment.NewLine);
		}

Comment thread UnitTests/TestHelpers.cs Outdated
expectedLook = expectedLook.Replace ("\r\n", Environment.NewLine);

// If test is about to fail show user what things looked like
if (!string.Equals (expectedLook, actualLook)) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To verify the equality you have to add ToString() for the ustring,

if (!string.Equals (expectedLook, actualLook.ToString ())) {

@tig
Copy link
Copy Markdown
Member Author

tig commented Apr 13, 2023

Expected:
┌──────────────────┐
│                  │
│ ┌─────────────┐  │
│ │ Test        │  │
┌───────────────────
│ Select All   Ctrl+
│ Delete All   Ctrl+
│ Copy         Ctrl+
│ Cut          Ctrl+
│ Paste        Ctrl+
│ Undo         Ctrl+
│ Redo         Ctrl+
└───────────────────
│                  │
└──────────────────┘
But Was:
┌──────────────────┐
│                  │
│ ┌─────────────┐  │
│ │ Test        │  │
┌─│─────────────│───
│ └─────────────┘rl+
│ Delete All   Ctrl+
│ Copy         Ctrl+
│ Cut          Ctrl+
│ Paste        Ctrl+
│ Undo         Ctrl+
│ Redo         Ctrl+
└───────────────────
│                  │
└──────────────────┘

For sure I don´t like the current result. The question is what aspect should it has to have, since the LineCanvas is so powered? The Expected or the following?

┌──────────────────┐
│                  │
│ ┌─────────────┐  │
│ │ Test        │  │
├─┴─────────────┴──┴
│ Select All   Ctrl+
│ Delete All   Ctrl+
│ Copy         Ctrl+
│ Cut          Ctrl+
│ Paste        Ctrl+
│ Undo         Ctrl+
│ Redo         Ctrl+
├──────────────────┬
│                  │
└──────────────────┘
Expected:
┌──────────────────┐
│                  │
│ ┌─────────────┐  │
│ │ Test        │  │
┌───────────────────
│ Select All   Ctrl+
│ Delete All   Ctrl+
│ Copy         Ctrl+
│ Cut          Ctrl+
│ Paste        Ctrl+
│ Undo         Ctrl+
│ Redo         Ctrl+
└───────────────────
│                  │
└──────────────────┘
But Was:
┌──────────────────┐
│                  │
│ ┌─────────────┐  │
│ │ Test        │  │
┌─│─────────────│───
│ └─────────────┘rl+
│ Delete All   Ctrl+
│ Copy         Ctrl+
│ Cut          Ctrl+
│ Paste        Ctrl+
│ Undo         Ctrl+
│ Redo         Ctrl+
└───────────────────
│                  │
└──────────────────┘

For sure I don´t like the current result. The question is what aspect should it has to have, since the LineCanvas is so powered? The Expected or the following?

┌──────────────────┐
│                  │
│ ┌─────────────┐  │
│ │ Test        │  │
├─┴─────────────┴──┴
│ Select All   Ctrl+
│ Delete All   Ctrl+
│ Copy         Ctrl+
│ Cut          Ctrl+
│ Paste        Ctrl+
│ Undo         Ctrl+
│ Redo         Ctrl+
├──────────────────┬
│                  │
└──────────────────┘

Expected.

@tig
Copy link
Copy Markdown
Member Author

tig commented Apr 13, 2023

For giggles, I just wasted a bunch of time making this happen:

yFcVEtM 1

@BDisp
Copy link
Copy Markdown
Collaborator

BDisp commented Apr 13, 2023

In addition to the updates in the first comment of this PR...

* @BDisp I broke a few unit tests having to do with popups over dialogs. I couldn't figure it out. Maybe you can see what I did? Search for `BUGBUG: Broke this test with #2483`

@tig I already had fixed this but when I merged from your repo to submit a PR, I get a bunch of errors again.

Comment thread Terminal.Gui/View/View.cs Outdated
// Invoke DrawContentCompleteEvent
OnDrawContentComplete (bounds);

OnDrawFrames ();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OnDrawFrames must be the first call on a Draw, otherwise the frames will always overlap the other views frames.

@tig tig merged commit 8c59e82 into gui-cs:v2_develop Apr 13, 2023
@tig tig deleted the v2_autojoin_borders_fixes_2483 branch April 3, 2024 01:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

2 participants