-
Notifications
You must be signed in to change notification settings - Fork 236
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 best to construct a ParagraphGraphicFactory that allows for dynamic positioning of Nodes #606
Comments
So, your goal is something like this?
And every time you scroll the viewport or insert/delete/replace text, the indicator's position is updated to still point to the same line of text, correct?
The If I understand your goal, then your basic approach is correct but needs to be improved by relocating the label each time the viewport is changed or the area's content is changed (even if that content doesn't affect the line in question). EventStream<?> viewport = area.getViewportChanges();
EventStream<?> content = area.richTextChanges();
// set up an Event Stream that emits an event any time one of these streams emits one
EventStream<?> renderTrigger = EventStreams.merge(viewport, content);
// subscribe to the trigger stream and store its subscription for later
Subscription sub = renderTrigger.subscribe(ignore -> updateLabelLocation());
EventStreams.changesOf(label.getSceneProperty())
// set up the following reaction when the
// label is added to the scene graph
.filter(s -> s != null)
.subscribeForOne(ignore ->
// now that it's added
// set up the following reaction
EventStreams.ChangesOf(label.getSceneProperty())
// when the label has been removed from the scene graph
// due to no longer being needed
.filter(s -> s == null)
// unsubscribe sub to prevent memory leaks
.subscribeForOne(sub.unsubscribe()); |
Perhaps, the easiest way to fix this would be to have 2 possible |
Yes, that's exactly the goal, to have an indicator move position in the left hand column to "follow" a specific piece of text, or position within the text. I think your suggestion of a forced relayout of the ParagraphGraphic node would probably be the best way to go. Then I just override layoutChildren and position the Nodes as appropriate. I'll modify my local version of RichTextFX to try this method out and let you know how I get on. Thanks for the code for stream watching, I will need to watch for text changes to also force a re-positioning, if needed. |
I've done some tests, it seems that if you just override So:
However there is one issue, the ParagraphGraphic will often get recreated and of course the paragraph index can change. Thus I have to recreate the Pane (in this case) numerous times but also have to keep references to the created Panes against the paragraph index, then remove the reference when the Pane is removed from the Scene. The trouble here is the overhead of having to manage those Panes and keeping references. Is there a better way to handle the ParagraphGraphics? Just a couple of other minor things:
i.e. area.getCharacterBoundsOnScreen (0, 0) This trapped me for a while. It would be good to have an exception thrown if the same value is passed in or a -1 returned to indicate the error.
|
Actually I retract my statement about Adding:
At line 231 of |
You could create your own
I'm not sure I understand what you mean by "parent paragraph." Could you clarify that?
We don't really have a policy. If you feel that it's useful, write and publish a page on what you have in mind and then open an issue about it so we can further discuss it. It might make more sense to discuss it in an issue first in case you have misunderstandings about some of the inner workings of things, but I think writing long documents in the Wiki page editor is easier than doing so in a regular issue. |
Does this mean we should use the idea I mentioned before of a lazy and strict ParagraphGraphic? We could get around the cast by changing the type from |
I tried your suggestion of a separate Region and that worked beautifully. You don't need to implement A call such as the one below handles things:
I found that the I'll add a full example as a new issue so that people can have look and use the method for tracking and highlighting text positions in a "margin" (or elsewhere). I think the change to Thank you for all your suggestions and help on this issue. Now that I can track positions in the text and display the markers the |
Glad you found a solution!
Mind submitting a PR to the demo package? |
Will do, I have been working on an example for the past couple of days. However the demo will require GenericStyledArea.getRangeBoundsOnScreen to be public to work. I have generalized getCharacterBoundsOnScreen to handle new line positions (which are valid positions for users to want to add things to even if a character is not visible, i.e. you might click at the end of a paragraph to indicate something). getRangeBoundsOnScreen depends on access to the virtualFlow which is private in GenericStyledArea and no public accessor method available for it so I can't just add that as well. If I do a pull request how do we handle that? Should I not worry about it and just do the request? |
This is a continuation and broadening of the question in: #587
What is the best way to create a ParagraphGraphicFactory that allows for Nodes to be dynamically positioned depending upon the vertical position/offset of a piece of text at a particular index/offset into a paragraph.
For example in the following block of text:
If I wish to add a Node (some kind of visual indicator) against the text "It was not that he felt" in the paragraph graphic to the left I could do:
This works relatively well for determining the y offset for positioning, the 150 is a nominal value used as an example, however there are a few issues:
It's only when I move paragraph 0 to paragraph 1 by adding a new line above do I get
which is what I would expect.
The call to ParagraphGraphicFactory.apply is only performed once and the Node resized as appropriate in ParagraphBox.layoutChildren. So what is the best way for me to handle the resizing since changing the width of the ParagraphBox may change the y offset of a piece of text? Is there a property or events I can observe to then trigger an update?
The resizing doesn't seem to clip. Here I have expanded the window so that the text is all on a single line, see below (image truncated because of large width). Note the => is still visible below the paragraph bounds.
The question really is "am I going about this the right way?" Should I use be using ParagraphGraphicFactory at all or is another technique more appropriate?
The text was updated successfully, but these errors were encountered: