Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #2983. View need a alternative DrawFrame for the v2. #2984

Closed
wants to merge 11 commits into from

Conversation

BDisp
Copy link
Collaborator

@BDisp BDisp commented Nov 12, 2023

Fixes #2983 - Use LineCanvas to draw the frame and supersede the obsolete method.

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

@BDisp BDisp requested a review from tig as a code owner November 12, 2023 01:08
@BDisp
Copy link
Collaborator Author

BDisp commented Nov 12, 2023

@tig the obsolete Frame.DrawFrame(Rect, bool) isn't using anymore and maybe can be removed?

@BDisp BDisp marked this pull request as draft November 16, 2023 12:35
Copy link
Collaborator

@tig tig left a comment

Choose a reason for hiding this comment

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

See my comments and questions.

Terminal.Gui/View/ViewDrawing.cs Outdated Show resolved Hide resolved
Terminal.Gui/View/ViewDrawing.cs Outdated Show resolved Hide resolved
Terminal.Gui/View/ViewDrawing.cs Outdated Show resolved Hide resolved
Terminal.Gui/View/ViewDrawing.cs Outdated Show resolved Hide resolved
@BDisp BDisp marked this pull request as ready for review November 18, 2023 23:31
@BDisp BDisp marked this pull request as draft November 19, 2023 11:15
@BDisp BDisp marked this pull request as ready for review November 19, 2023 19:13
@tznind
Copy link
Collaborator

tznind commented Nov 20, 2023

I'm looking at DrawIncompleteFrame and thinking there might be a simpler way to achieve this and create a lot more flexibility for other things. Here is my premise

Add a method which returns just the lines for the rect:

public IEnumerable<StraightLine> GetFrame (Rect rect, LineStyle lineStyle, Attribute? attribute = null)
{
	var vts = ViewToScreen (rect);			
	yield return new StraightLine(new Point (vts.X, vts.Y), vts.Width,
		Orientation.Horizontal, lineStyle, attribute);
	yield return new StraightLine (new Point (vts.Right - 1, vts.Y), vts.Height,
		Orientation.Vertical, lineStyle, attribute);
	yield return new StraightLine (new Point (vts.Right - 1, vts.Bottom - 1), -vts.Width,
		Orientation.Horizontal, lineStyle, attribute);
	yield return new StraightLine (new Point (vts.X, vts.Bottom - 1), -vts.Height,
		Orientation.Vertical, lineStyle, attribute);
}

Add an extension method that operates on a collection of lines that lets you create an exclusion area:

public static class StraightLineExtensions
{
/// <summary>
	/// Splits or removes all lines in the <paramref name="collection"/> such that none cover the given
	/// exclusion area.
	/// </summary>
	/// <param name="collection">Lines to adjust</param>
	/// <param name="start">First point to remove from collection</param>
	/// <param name="length">The number of sequential points to exclude</param>
	/// <param name="orientation">Orientation of the exclusion line</param>
	/// <returns></returns>
	public static IEnumerable<StraightLine> Exclude (this IEnumerable<StraightLine> collection, Point start, int length, Orientation orientation)
	{
		foreach(var l in collection) {

			// if line intersects the exclusion

			// if it is wholly inclusive of the line
				// remove it from returned collection
			// else if it is longer on both ends
				// split l into two lines
			// else
				// shorten right or left
		}

		return collection;
	}
}

What do you think? this would let you create rectangles with gaps in any sides needed and many other cool things besides?

I can probably work out the code for this method if its a go?

@BDisp
Copy link
Collaborator Author

BDisp commented Nov 20, 2023

What do you think? this would let you create rectangles with gaps in any sides needed and many other cool things besides?

I can probably work out the code for this method if its a go?

Any help is welcome. The DrawIncompleteFrame know where the side start and where the side end. It also allow to create rectangles with gaps in any sides needed by calling several times with different locations by using the same bounds. But any reduce of code is always better and more cleaning. So, the idea of exclusions is very good.
For now I have some TabView unit test failing.
Feel free to do what you think is better. Thanks.

@tznind
Copy link
Collaborator

tznind commented Nov 21, 2023

@BDisp I have created #3004 as an alternative approach to DrawIncompleteFrame which can hopefully simplify things. Let me know what you think.

@BDisp
Copy link
Collaborator Author

BDisp commented Nov 21, 2023

@BDisp I have created #3004 as an alternative approach to DrawIncompleteFrame which can hopefully simplify things. Let me know what you think.

I like it very much. More elegant and with less code. Thanks.

In this PR I'm using a non 0 location with a value of 3 to avoid be divisible by 2 and so avoiding bugs on the unit tests. I never more will be using the 0 location for unit tests with frame.

@BDisp
Copy link
Collaborator Author

BDisp commented Dec 4, 2023

Closing this because was supersede per the #3004.

@BDisp BDisp closed this Dec 4, 2023
@BDisp BDisp deleted the v2_drawframe-method_2983 branch December 4, 2023 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants