On Sun, 9 Aug 2026 01:59:22 GMT, Nir Lisker <[email protected]> wrote:

>> This PR shows how virtual layouts could be implemented, as discussed on the 
>> mailinglist: 
>> https://mail.openjdk.org/archives/list/[email protected]/thread/PLNSQ3ZI63AVKEFKNT5GT6WHAD2GYMPC/
>> 
>> It would work by making new non-Node containers called Layouts which can 
>> contain a mix of either Nodes or other Layouts. Allowing Layouts to nest 
>> makes it possible to create a substructure similar to how nesting 
>> StackPane/HBox/VBox etc works today. An example is a simple control that has 
>> a graphic with a title and subtitle stacked vertically next to it:
>> 
>> 
>> +-------------+-----------------------------------------+
>> |             |                                         |
>> |             |                 Title                   |
>> |             |                                         |
>> |   Graphic   +-----------------------------------------+
>> |             |                                         |
>> |             |                Subtitle                 |
>> |             |                                         |
>> +-------------+-----------------------------------------+
>> 
>> For a control to model this, it would need a VBox containing the Title and 
>> Subtitle, and an HBox containing the Graphic and the VBox.  The two 
>> containers are heavy-weight Nodes and this incurs sufficiently large memory 
>> and performance penalties that most standard JavaFX controls will opt to 
>> instead roll their own layout code to avoid paying the cost for these.
>> 
>> With virtual layouts, the control could make use of non-Node containers. The 
>> control would add its three children (Graphic, Title and Subtitle) as direct 
>> children for display in the scene graph, but would offload their positioning 
>> to a virtual layout.  This roughly looks like this:
>> 
>> 
>>   public class TitledGraphic extends Region {
>>       private final HBoxLayout root;
>> 
>>       public TitledGraphic(Node graphic, String titleText, String 
>> subtitleText) {
>>           // Flat scene graph:
>>           getChildren().addAll(graphic, title, subtitle);
>> 
>>           // Create virtual layout:
>>           root = HBoxLayout.of(graphic, VBoxLayout.of(title, subtitle));
>>       }
>> 
>>       @Override
>>       protected void layoutChildren() {
>>           root.resizeRelocate(0, 0, getWidth(), getHeight());
>>       }
>> 
>>       @Override protected double computeMinWidth(double height)   { return 
>> root.minWidth(height); }
>>       @Override protected double computeMinHeight(double width)   { return 
>> root.minHeight(width); }...
>
> modules/javafx.graphics/src/main/java/javafx/scene/layout/Measurable.java 
> line 82:
> 
>> 80:      * <p>
>> 81:      * If {@link #maxWidth(double)} is lower than this number, {@code 
>> minWidth} takes
>> 82:      * precedence.
> 
> Is this guaranteed or a requirement?

As it depends on the cooperation of whoever is reading these values and is 
later basing a `resize` call on them, we can't guarantee anything here. Is it 
more that a correctly implemented layout should respect these values in that 
specific order, and that it should never call `resize` with values that are out 
of range -- it is however not so strict that a control could throw an exception 
if values are out of range -- there will just be some clipping or dead space.

So I think "specification" or "requirement"?  What would you call it? :)

The above is basically a copy of the original documentation, but as long as we 
are not adding new requirements or specifications that didn't exist before, we 
can adjust the wording.

-------------

PR Review Comment: https://git.openjdk.org/jfx/pull/2241#discussion_r3743347715

Reply via email to