Logical scene graph API
Michael Strauß
michaelstrau2 at gmail.com
Thu Jun 23 00:00:17 UTC 2022
A JavaFX scene graph can be traversed with the
`Node.getChildrenUnmodifiable()` and `Node.getParent()` methods.
However, this doesn't work as intuitively as one might expect: Control
skins can modify the scene graph by introducing additional nodes,
which makes it hard to reason about the structure of the scene graph.
Additionally, users might expect to find objects like `MenuItem` or
`Tab` in the scene graph, but since these are not nodes, they are
nowhere to be found.
Here are examples of the confusion that can arise from these issues:
http://www.kware.net/?p=8
https://stackoverflow.com/questions/24126226/javafx-walk-widget-tree
The core problem is that the scene graph is not a representation of
the logical structure of the JavaFX document, i.e. the structure of
controls and nodes that users will create in code or in an FXML file.
There are many legitimate reasons for wanting to traverse the logical
structure of a JavaFX document, and I think we can support this by
introducing the notion of a "logical graph" or "document graph".
The logical graph can be traversed by two new methods:
`Node.getLogicalChildren()` and `Node.getLogicalParent()`.
These methods would have to be implemented by controls to return their
logical children: for example, `Labeled` would return its `graphic`
node, since that is its only logical child.
Before delving into an API discussion, I'd like to collect some
feedback on the feature proposal as a whole. Do you think that a
"logical graph" concept should be added to JavaFX?
More information about the openjfx-dev
mailing list