Skin layoutChildren: when to get bounds of child nodes?
Werner Lehmann
lehmann at media-interactive.de
Thu Jul 31 08:09:49 UTC 2014
Hi Martin,
On 30.07.2014 17:39, Martin Sladecek wrote:
> I assume you don't change "child1" Nodes, so it should work.
I may add/insert such nodes but in that case I take the easy route and
simply rebuild the complete hbox.
> Yeah, one problem with layouts is when you want to do some layout that
> is almost the same as some predefined layout, but you need to tweak it
> somehow. Maybe in the future we could add some abstraction and extract
> some (parts of) the algorithms we use in our layout containers so they
> can be reused in custom layouts.
Right. I noticed some package private methods used internally by vbox
etc. This prevents me from making a copy of vbox which I can tweak
(often times removing many properties and lots of code not applicable to
that usecase). I suppose they could also be useful for other layouts
occasionally.
I figured if I would use translateX for the tweak I should be fine. For
the width I might be able to use scaleX but that does not feel right.
> If you reuse some predefined layout, you'll probably end up with some
> hacky code since you'll usually mess up with the inputs for the layout.
> The rule of thumb is to use some more complex (GridPane) or free form
> (AnchorPane) layout instead of trying to slightly tweak some simple layout.
> In your case, wouldn't GridPane do the job? Basically, you have a row of
> text nodes and you need a second row where a single rectangle is in the
> same column as currently selected (?) text node. The size of the
> rectangle can be set to fillWidth the column, so GridPane will do all
> the work for you.
AnchorPane might be applicable for this particular thing. The challenge
here is then to figure out the heights of elements so that I can stack
them to get a result similar to the vbox. For example, if I anchor the
hbox to the top of the AnchorPane and I want to have my moving rectangle
right below it I have to set static AnchorPane properties on that
rectangle and have to know the height of the hbox. Again I need to
position one element based on the default layouting of another. And if I
am not mistaken it could be difficult to animate those static properties.
I try to avoid GridPane because inserting and removing stuff means to
manually shift all subsequent indexes which is a bit tedious. Also, if I
want to animate an element moving from one cell to another it seems to
get in the way - or at least it does not offer any benefit over the
current vbox/hbox approach.
Werner
More information about the openjfx-dev
mailing list