FXMisc / Flowless

Efficient VirtualFlow for JavaFX
BSD 2-Clause "Simplified" License
185 stars 38 forks source link

Make VirtualFlow's gravity styleable via CSS #34

Closed neilccbrown closed 7 years ago

neilccbrown commented 7 years ago

I propose that the Gravity of VirtualFlow should be made styleable via CSS (and thus mutable). If you're happy with the justification to add and the implementation strategy, I'm happy to write the code and submit a pull request.

Justification:

Use case 1: I have a RichTextFX control where I want the lines to be at the bottom (it's a history view of a terminal-like display, where the entry is underneath, and history should appear at the bottom and be bumped upwards as more is added). Because the Gravity of the VirtualFlow is a constructor parameter, I can't actually alter it unless I patch RichTextFX to allow it, and even then, it's a bit odd to have to pass a style attribute as an unchangeable constructor parameter. The VirtualFlow isn't public and we don't want to make it so, but if we could set the gravity parameter by CSS then it would solve the whole issue.

Use case 2: I am thinking of using VirtualFlow for a code-completion like popup window. It will appear below the line if there's room (with items at the top), or above the line otherwise (with items at the bottom). If Gravity is unchangeable then I can't dynamically move it from below to above without creating a new VirtualFlow.

Implementation:

I've had a look at the code and I don't think it will be a difficult change. VirtualFlow's constructor takes the gravity parameter, but only uses it to pass to Navigator's constructor. Navigator stores it as a field but only uses it in the utility methods at the bottom of the class. In turn these are only used by the method fillViewportFrom. Assuming IntelliJ's call hierarchy is complete, this all leads back to Navigator.layoutChildren():

image

I think this means that we can make a styleable property (with accessor and mutator) for gravity in VirtualFlow, which is passed as a reference to Navigator, and add a change listener to the property that calls VirtualFlow.requestLayout (or just Navigator.requestLayout?). Let me know if I've missed anything on the implementation side.

JordanMartinez commented 7 years ago

I believe this feature would also affect StyledTextAreaBehavior in RTFX, as pageUp-related things would need to be inverted.

neilccbrown commented 7 years ago

I've had a play with my hacked-up Gravity.REAR version of RichTextFX and it seems to handle page up and page down events correctly, when the area is full or only partially full. I think it may be that when the text doesn't fill the surrounding area, the code only moves the caret anyway (regardless of gravity), and when it does fill the area, it functions the same regardless of gravity. I may have overlooked something, though.

JordanMartinez commented 7 years ago

Closed by #35.