Skip to content

Fixes #2358 - BREAKING CHANGE: Pos.Combine is incorrect for scenarios involving PosAbsolute#2379

Closed
tig wants to merge 16 commits intogui-cs:developfrom
tig:v1_setrelativelayout_improvement
Closed

Fixes #2358 - BREAKING CHANGE: Pos.Combine is incorrect for scenarios involving PosAbsolute#2379
tig wants to merge 16 commits intogui-cs:developfrom
tig:v1_setrelativelayout_improvement

Conversation

@tig
Copy link
Copy Markdown
Member

@tig tig commented Feb 24, 2023

This is a breaking change (it changes the previous behavior of SetRelativeLayout) and breaks any code that was using PosCombine but not realizing the results were invalid. For example, all of the Border related Scenarios.

We should take this breaking change because it fixes a real problem in how the API is supposed to work.

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 added the breaking-change For PRs that introduces a breaking change (behavior or API) label Feb 24, 2023
@tig tig requested a review from migueldeicaza as a code owner February 24, 2023 21:02
@tig
Copy link
Copy Markdown
Member Author

tig commented Feb 24, 2023

@BDisp - can you please do a CR of this?

@BDisp
Copy link
Copy Markdown
Collaborator

BDisp commented Feb 24, 2023

@tig I think you may merge the #2345 into this to leverage the frame border color not equal to the color scheme.

@BDisp
Copy link
Copy Markdown
Collaborator

BDisp commented Feb 25, 2023

@tig none of theses labels are redrawing on the Borders Comparisons, Borders on FrameView, Borders on Toplevel and Borders on Window scenarios.

var label = new Label ("I'm a Window") {
				X = Pos.Center (),
				Y = Pos.Center () - 3,
			};
var label2 = new Label ("I'm a Toplevel") {
				X = Pos.Center (),
				Y = Pos.Center () - 3,
			};
var label3 = new Label ("I'm a FrameView") {
				X = Pos.Center (),
				Y = Pos.Center () - 3,
			};

imagem

@BDisp
Copy link
Copy Markdown
Collaborator

BDisp commented Feb 25, 2023

On load theses to views are misaligned:
imagem

On the develop branch they are aligned:
imagem

I think this has to do with the Pos.Center and Pos.Absolute layout.

Comment thread UnitTests/Core/BorderTests.cs
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.

I wrote some considerations about this. I hope you don´t mind.

Comment on lines -280 to -281
[Fact, AutoInitShutdown]
public void Frame_And_Labels_Does_Not_Overspill_ScrollView ()
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.

These are also good unit to test with layout. I hope you reconsidered to not remove them.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

They were moved to LayoutTest.cs (or at least I meant to move them... Or I deleted them by accident). I'll re-look.

Comment thread Terminal.Gui/Core/View.cs
@@ -1109,8 +1110,15 @@ public void BringSubviewForward (View subview)
/// </remarks>
public void Clear ()
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 you have to merge with the PR #2354 because the Clear method is wrong on this PR. It causes layout malfunction.

Comment on lines -561 to -572
[Fact, AutoInitShutdown]
public void BorderStyle_And_DrawMarginFrame_Gets_Sets ()
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.

I hope you also maintain this unit test. I think you have some errors because of the View.Clear method.

@tig
Copy link
Copy Markdown
Member Author

tig commented Feb 26, 2023

On load theses to views are misaligned: imagem

On the develop branch they are aligned: imagem

I think this has to do with the Pos.Center and Pos.Absolute layout.

Yep, I struggled getting them to align using Pos.Bottom(label) but Panel's Frame is at the marginframe and label's is at the Margin so it wasn't working. I decided to leave it like this so that would be obvious (but I was also tired of fixing bugs in those Scenarios that were exposed by the bug fix).

@tig
Copy link
Copy Markdown
Member Author

tig commented Feb 26, 2023

@tig I think you may merge the #2345 into this to leverage the frame border color not equal to the color scheme.

Done. Thanks for noting that!

@tig
Copy link
Copy Markdown
Member Author

tig commented Feb 26, 2023

@tig none of theses labels are redrawing on the Borders Comparisons, Borders on FrameView, Borders on Toplevel and Borders on Window scenarios.

var label = new Label ("I'm a Window") {
				X = Pos.Center (),
				Y = Pos.Center () - 3,
			};
var label2 = new Label ("I'm a Toplevel") {
				X = Pos.Center (),
				Y = Pos.Center () - 3,
			};
var label3 = new Label ("I'm a FrameView") {
				X = Pos.Center (),
				Y = Pos.Center () - 3,
			};

imagem

This is caused by bugs in those scenarios that I didn't notice:

			var label = new Label ("I'm a Window") {
				X = Pos.Center (),
				Y = Pos.Center () - 3,
			};

Y.PosCenter() - 3 for a 5 row tall superview puts the label outside of the Bounds.

This works better:

			var label = new Label ("I'm a Window") {
				X = Pos.Center (),
				Y = Pos.Top (button) - 1
			};

image

This regex search finds all instances of potential bugs that do this Pos.Center \(\) -.

@tig
Copy link
Copy Markdown
Member Author

tig commented Feb 26, 2023

I just pushed several fixes to this PR that fix the issues you noted. However, one fix that SHOULD have worked has caused another problem in the 3 "Borders on XXX" scenarios:

The button isn't painting right.

"Borders on Window"
image

"Borders on FrameView"
image

"Borders on Toplevel"
image

Since this doesn't happen in "Borders Comparsion" I'm wondering if this is another bug in the Scenario. Debugging now...

@BDisp
Copy link
Copy Markdown
Collaborator

BDisp commented Feb 26, 2023

Since this doesn't happen in "Borders Comparsion" I'm wondering if this is another bug in the Scenario. Debugging now...

I already noted that. Try to comment in the View on the GetMaxNeedDisplay method these two lines:

+			//rect.Width += Math.Max (oldFrame.X - newFrame.X, 0);
+			//rect.Height += Math.Max (oldFrame.Y - newFrame.Y, 0);

@tig I prefer to use the Y = Pos.Center () - 2, to really test that center is working properly. Change to -2, because you fixed some existent bug on the layout.

@tig
Copy link
Copy Markdown
Member Author

tig commented Feb 26, 2023

Since this doesn't happen in "Borders Comparsion" I'm wondering if this is another bug in the Scenario. Debugging now...

I already noted that. Try to comment in the View on the GetMaxNeedDisplay method these two lines:

+			//rect.Width += Math.Max (oldFrame.X - newFrame.X, 0);
+			//rect.Height += Math.Max (oldFrame.Y - newFrame.Y, 0);

@tig I prefer to use the Y = Pos.Center () - 2, to really test that center is working properly. Change to -2, because you fixed some existent bug on the layout.

The bug is here, I think:

image

GetNeedDisplay is {{X=0,Y=0,Width=65,Height=17}} for the label, which has AutoSize on and thus a Height of `. Thus this call to Clear is clearing more than it should:

image

I'm out of time for tonight. I you get a chance can you file a new issue for that?

@tig
Copy link
Copy Markdown
Member Author

tig commented Feb 26, 2023

@tig I prefer to use the Y = Pos.Center () - 2, to really test that center is working properly. Change to -2, because you fixed some existent bug on the layout.

Well, that didn't work, did it? Center WASN'T working right ;-).

I'm out of time tonight so I'm going to leave it as-is for now.

@tig
Copy link
Copy Markdown
Member Author

tig commented Feb 26, 2023

Now that I think about it more: Why isn't Clear honoring Driver.Clip???

@BDisp
Copy link
Copy Markdown
Collaborator

BDisp commented Feb 26, 2023

Now that I think about it more: Why isn't Clear honoring Driver.Clip???

If the Driver.Clip is equal to the current view bounds it's ok, otherwise is better maintain as is.

I'll work on this tomorrow.

BDisp added a commit to BDisp/Terminal.Gui that referenced this pull request Feb 27, 2023
BDisp added a commit to BDisp/Terminal.Gui that referenced this pull request Feb 27, 2023
@BDisp
Copy link
Copy Markdown
Collaborator

BDisp commented Feb 27, 2023

@tig I already finished and submitted the PR tig#10.

@tig
Copy link
Copy Markdown
Member Author

tig commented Feb 28, 2023

I now no longer want to fix this in v1.

This bug has persisted for years and I'm the first to notice it.

I am getting worn out trying to merge v1 changes into v2. I spent 3 hours yesterday and ended up giving up because I had made such a mess.

@BDisp
Copy link
Copy Markdown
Collaborator

BDisp commented Mar 1, 2023

@tig I added the PR #2385 on the v2 that fixes the #2358. The behavior with the button redraw doesn't reproduce anymore. I hope you don't mind.

@tig
Copy link
Copy Markdown
Member Author

tig commented Mar 2, 2023

Closing as a dupe of #2385

@tig tig closed this Mar 2, 2023
@tig tig deleted the v1_setrelativelayout_improvement branch April 3, 2024 01:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking-change For PRs that introduces a breaking change (behavior or API)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pos.Combine is incorrect for scenarios involving PosAbsolute

2 participants