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

How to force a relayout? #854

Closed
garybentley opened this issue Oct 13, 2019 · 6 comments · Fixed by #859
Closed

How to force a relayout? #854

garybentley opened this issue Oct 13, 2019 · 6 comments · Fixed by #859

Comments

@garybentley
Copy link

I've asked a similar question to this before: #839 but I now have a different use case that I can't get around by setting a style.

In this case I am modifying what is drawn in a paragraph graphic when the user makes a change in the text. Specifically I am drawing a line in the paragraph graphic to match where the user selected a position in the text. See the image below:

edit-marker

The grey area is the paragraph graphic, the blue line is the "marker" to indicate how far into the text the user has edited.

My issue is that when the user changes the "edit position" I need to also update the marker but the marker is only changed on the next layout pass. I tried calling "requestLayout" on the area and the paragraph graphic but neither caused another layout.

So any suggestions on how to force a layout?

(Note: I do have a workaround but it involves a nasty removing/adding of a component to the graphic which is FAR from ideal, I'd ideally like to have a proper way of handling this situation, especially since I have a number of use cases that have the same issue.)

@Jugen
Copy link
Collaborator

Jugen commented Oct 18, 2019

Currently the paragraph graphic is refreshed by RichTextFX if either the paragraph index or paragraph factory changes. The graphic is also refreshed when JavaFX detects a change to the scene graph, which is basically what you are triggering.

So I'm thinking of adding a method that will recreate a specific paragraph graphic, something like:
recreateParagraphGraphic( parIdx ) or refreshParagraphGraphic( parIdx )

What do you think ? Which method name is preferable ?
Or do you have a different method name suggestion ?

@Jugen
Copy link
Collaborator

Jugen commented Oct 18, 2019

Alternatively you could use area.setParagraphStyle( parNdx, paragraphStyle ) which also triggers a paragraph graphic refresh.

@garybentley
Copy link
Author

Sorry for the delay, it's been a busy week. I think "recreate" would probably be better since it more closely represents the intent/purpose of the method.

Also, would you be able to add a "getParagraphGraphic(int)" method that will return the current paragraph graphic for a paragraph. I currently have a convoluted mess of caching and scene watching in place to try and get the current paragraph graphic for a paragraph. My use case is that the user clicks on something outside of the editor and that will open a popup at the location of a node in the paragraph graphic. See below.

item-popup

In this case the user clicked on "Item 1" in the tree in the left hand pane and the editor jumps to the correct location for the item and then displays a popup next to the appropriate icon.

@Jugen
Copy link
Collaborator

Jugen commented Oct 28, 2019

Could you maybe try this out and see if it works for you ?

@Jugen Jugen reopened this Oct 28, 2019
@garybentley
Copy link
Author

Yep they both work well, thanks for adding them.

@Jugen
Copy link
Collaborator

Jugen commented Nov 4, 2019

Great, I've fixed the typos in a new PR.

@Jugen Jugen closed this as completed Dec 24, 2019
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 a pull request may close this issue.

2 participants