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

Move border creation outside of layout pass #1539

Merged
merged 1 commit into from Feb 2, 2024

Conversation

jperedadnr
Copy link
Collaborator

@jperedadnr jperedadnr commented Jan 31, 2024

Fixes #1538

This PR modifies the Borders#StrokeBorder class to avoid doing node creation on layout passes, by moving out the border creation to a method that is called only after the title label creation and when the width of the stackPane that wraps the user node changes.
The title label layout is overwritten only to relocate it properly.

This changes should increase notably the performance of any node wrapped with Borders.

Running the test attached to the issue shows now:

needs layout = false
needs layout = true
needs layout = false
needs layout = true

(that's it, no more infinite layout passes)

@abhinayagarwal
Copy link
Member

I can reproduce this with the provided sample in issue #1538. I can further confirm that this PR fixes the issue. Overall, it looks like a good enhancement. Is there a particular reason why titleLabel is currently only relocated and not resized in layoutChildren ?

@jperedadnr
Copy link
Collaborator Author

jperedadnr commented Feb 1, 2024

I overwrote computePrefWidth for that, and that should do it.

Adding titleLabel.resize to the layout pass brings back the infinite layout passes.

For the test case for instance, the label width (without padding) is 26.5, while pref width value (without padding) is: 26.4609375.

Without this change, there is a constant fight between pref and width:

  • StrokeBorders layoutChildren sets the label's width to its pref width, and Region::widthChanged calls requestParentLayout. During the layout, the width gets snapped (or set by computePrefWidth to a snapped value), and there is this log (adding a log to Region::widthChanged) repeated all over again (every pulse):
...
needs layout = false
value = 26.5 vs _width = 26.4609375
needs layout = true
value = 26.4609375 vs _width = 26.5
...

Of course, and option might be adding snap methods to the layout pass, but I guess computePrefWidth already takes care of that.

@abhinayagarwal abhinayagarwal merged commit 7a2e185 into controlsfx:master Feb 2, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PopOver has infinite layout passes when adding line border with title
2 participants