On Wed, 5 Aug 2026 02:40:49 GMT, John Hendrikx <[email protected]> wrote:

>> modules/javafx.graphics/src/main/java/javafx/scene/layout/StackPane.java 
>> line 141:
>> 
>>> 139:     private static final Callback<Layoutable, Pos> ALIGNMENT_LOOKUP = 
>>> child -> StackPane.getAlignment((Node) child);
>>> 140: 
>>> 141:     private final StackPaneLayout stackPaneLayout = new 
>>> StackPaneLayout(MARGIN_LOOKUP, ALIGNMENT_LOOKUP);
>> 
>> would it make more sense to make StackPaneLayout an abstract class instead 
>> of using callbacks?
>
> There are multiple ways to go about it; the reason the callbacks exist is 
> that we need to access/track child constraints. Options include:
> 
> - Just provide callbacks to get at the constraints (the callbacks already 
> existed in `StackPane`, and the solution doesn't look to bad)
> - Instead of delegating this functionality back to the owner, we could make 
> this accessible on the `Layoutable` interface (add constraint get/set 
> methods) -- such methods would however introduce new API on `Node` so I've 
> left them out of this proposal (their implementation could just store them in 
> the properties map, so trivial implementation, just more formalized then 
> using `getProperties`)
>   - Special constraint methods could also live in a subinterface (to keep 
> them separate as they're a bit specific), so you could have `Constrainable` 
> -> `Layoutable` -> `Measurable`.
> - Expose `getProperties` on the `Layoutable` interface; this would be API 
> compatible, but would put a generic method on `Layoutable` that seems out of 
> place
> 
> The reason I wouldn't make it abstract is that these callbacks will be 
> optional. They are primarily needed for the original heavy-weight containers 
> (ie. `StackPane`) to provide the full functionality they offered before.  
> However, for embedded use, you can drop these providers if you don't need 
> per-child constraints.  Ideally, you can then just write: 
> `StackPaneLayout.of(child1, child2, child3)` or:
> 
> 
>     StackPaneLayout.of(
>         child1,
>         HBoxLayout.of(
>             VBoxLayout.of(
>                 child2, child3
>             ),
>             VBoxLayout.of(
>                 child4, child5
>             )
>         )
>     );
> 
> 
> There is a gap still however, which we should address: constraints can only 
> be put on `Node`s in this proof of concept; if I wanted to put a 
> stackpane-related constraint on the `HBoxLayout` above, I can't as it isn't a 
> `Node`.

yep, one more reason for the constraints to be a part of the layout and not the 
node.

anyway, callbacks are fine (only one static pointer added), especially if they 
are optional.

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

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

Reply via email to