How to scale control properly?

Martin Sladecek martin.sladecek at oracle.com
Tue Jun 10 06:23:17 UTC 2014


That should work for non-resizable Nodes, but resizables would be tricky 
if not impossible.

During the layout pass, we need to know min/pref/max size. In this case, 
it would have to be adjusted with the transformation (which can be a 
rotation,  shear or doesn't have to be affine). The transformation can 
make width&height depend on each other (like 45deg rotation makes the 
min/max width depend on height and vice-versa). Then there's a problem 
with Region's width/height properties which are being set by the layout 
pane. They should be without transformations (as internal layout uses 
them), so either the layout algorithms would have to undo the transforms 
and compute the right size or the logic would need to be in resize() 
call, which turns setWidth/setHeight to kind-of a pitfall.

I think the best solution would be to add some "scale" styleable-only 
property to Control, as that's probably the most reasonable transform we 
want to include in layout bounds. As controls have another layer of 
layoutChildren() call which passes the width/height and do not (should 
not?) use getWidth()/getHeight() for their layout, it might be possible 
to hide the internal logic in some common Skin code. That would also 
mean adding a mandatory Pane to each control that would be the root of 
the skin, but a child of the control, to hide the internal transformations.

-Martin

On 10.6.2014 05:09, Richard Bair wrote:
> One thing we’ve always considered was adding some kind of convenience API to Node to toggle how the layout bounds are computed (whether they take into account transforms or not). Martin, how difficult would that be, do you think?
>
> Richard
>
> On Jun 5, 2014, at 11:41 AM, Rafal Leibzig <rafaljfx at gmail.com> wrote:
>
>> Thanks for advice.
>> I know this trick with wrapping in a Group, but as i wrote on
>> stackoverflow, there is dropshadow effect after moving mouse over the
>> control.
>> This effect extends group's layoutBounds for a while.
>> And when mouse leaves out the control, then group's layoutBounds shrink.
>>
>> I found the sources/css for this control:
>> https://bitbucket.org/controlsfx/controlsfx/src/96f40eb0b579277139192e2398fbbaf7fd01f91e/controlsfx/src/main/resources/org/controlsfx/control/rating.css?at=default
>>
>> -- 
>> Rafal
>>
>>
>> 2014-06-05 16:12 GMT+02:00 Martin Sladecek <martin.sladecek at oracle.com>:
>>
>>> Hi Rafal,
>>> you can wrap the control in a Group. That way, it's (actually Group's)
>>> layoutBounds will be the same as it's transformed bounds (boundsInParent).
>>> Alternatively you can use css styling, but I don't know much about how to
>>> do it properly, maybe Jonathan can help you there.
>>>
>>> -Martin
>>>
>>>
>>> On 06/05/2014 01:13 AM, Rafal Leibzig wrote:
>>>
>>>> Hi,
>>>>
>>>> Sorry for disturbing you, but I have a question and no one answered me on
>>>> other forums.
>>>>
>>>> My question is rather simple:
>>>>
>>>> http://stackoverflow.com/questions/23997115/how-to-
>>>> scale-control-and-layout-it-properly-in-javafx
>>>>
>>>>
>>>> Thanks in advance.
>>>> You are the experts. :)
>>>>
>>>>
>>>>



More information about the openjfx-dev mailing list