Q: Rotated labels, layout and reflow

John-Val Rose johnvalrose at gmail.com
Sat Dec 15 11:17:27 UTC 2018


Yes, you are absolutely right John and again I’m sorry that I did not initially see the relevance of your question for this list.

I do now and I like your ideas :-)

> On 15 Dec 2018, at 22:06, John Hendrikx <hjohn at xs4all.nl> wrote:
> 
> 
> I asked here because, although not a bug, it may be a good feature to support -- and I was looking for confirmation that this really isn't currently possible.  It's not a bug because a rotation transform is expected to not change the layout bounds.  Making use of Group fixes the layout bounds but makes it impossible to do proper dynamic layouts with labels that have been rotated 90 degrees.
> 
> Questions similar like this one, without good resolutions, show up on forums and stackoverflow, and, looking at the bug database, I think even some of the graph components part of JavaFX that support rotated labels have similar layout problems when texts needs to be cut-off or reflowed in such labels.
> 
> I even looked at MigLayout already, and noticed a similar issue reported there where rotated labels are not handled properly, probably because the layout bounds don't take the rotation into account, which no doubt MigLayout relies on to do its thing.
> 
> Now, I would love to contribute a fix for this (I contributed some small things before), however I think this might be a tough issue to resolve. The way I see it, this cannot be solved without Label taking the rotation into account itself and providing proper layout bounds -- this is needed because Label decides if text reflow needs to occur depending on where it is placed, and this information is lost when it is put in a Group.
> 
> So I think Label(ed) would need a new Rotate property, which only supports 0, 90, 180 and 270 degrees, or perhaps an extension to the text direction property (left-right, right-left, top-down, down-top), but I think that it serves a different purpose that is independent from rotation.
> 
> With this extra information, Label can then do the proper layout calculations with potential reflow of text and provide correct layout bounds.  The actual text rendering would also need to be rotated somehow, and I'm not quite sure how that would be accomplished yet for Labels.
> 
> All in all, it sounds like quite some effort that would need a good design, especially since Label already has a short-cut property to add a Rotate transform that cannot be re-used for this, so a new property would have to make the difference very clear.
> 
> --John
> 
>> On 15/12/2018 09:18, Tom Eugelink wrote:
>> It's a bit grey. If this goes towards a bug in the layout, it could be
>> considered OpenJFX development. It could also go towards a patch,
>> because instead of using Canvas I would suggest (John) to look at the
>> HBox and see if you can figure out why it is not doing what you want.
>> And if that is too complex; write a layout that does this, and
>> contribute it to OpenJFX, ControlsFX or JFXtras. (I believe OpenJFX also
>> is the sum of all the extending libraries, not making the suck-it-all-in
>> mistake Java made.) The layout logic should be similar to when doing it
>> in Canvas, only reusable.
>> 
>> Also I have found that when rotating is involved, a lot of layouts do
>> not what you expect them to do. Have you given MigLayout a try? It
>> sometimes has surprising results (both positive and negative) ;-)
>> 
>> 
>> 
>> 
>>> On 15-12-2018 03:14, John-Val Rose wrote:
>>> My feedback would to ask this kind of question on a more appropriate
>>> list or forum.
>>> 
>>> I believe this list is exclusively to discuss issues related to the
>>> development of OpenJFX itself.
>>> 
>>> Graciously,
>>> 
>>> John-Val
>>> 
>>>> On 15 Dec 2018, at 12:50, John Hendrikx <hjohn at xs4all.nl> wrote:
>>>> 
>>>> 
>>>> (Sent this twice, first message got sent prematurely)
>>>> 
>>>> Hi list,
>>>> 
>>>> I get the impression that rotation of Labels needs to be something
>>>> that is directly supported by Label instead of handling this with a
>>>> Rotate transform (setRotate).
>>>> 
>>>> I want to achieve something quite trivial if no rotation was
>>>> involved, a layout like this, an HBox with 3 labels in it:
>>>> 
>>>>  +-HBox------------------------------------------------------------+
>>>>  |            | Long text that can reflow to multiple |            |
>>>>  | Short Text | lines if needed...                    | Short Text |
>>>>  |            |                                       |            |
>>>>  +-----------------------------------------------------------------+
>>>> 
>>>> The center label would be given grow Priority.ALWAYS.
>>>> 
>>>> Now... the rotated version just goes wrong in so many ways.
>>>> 
>>>> First, I need to use Groups in order to get the layout bounds
>>>> reasonable... however, these are unaware of how much space is
>>>> available and will kill the reflow in the center Label.
>>>> 
>>>> If I put a Group around the whole HBox, the same issue occurs as the
>>>> Group blocks any awareness of how big the area is where the three
>>>> labels are going to appear, effectively rendering the center label as
>>>> one long line.
>>>> 
>>>> What I'm actually trying to achieve is a layout that looks like this:
>>>> 
>>>>   +----+-------------------+
>>>>   |  T |                   |
>>>>   |  e |                   |
>>>>   |  x |                   |
>>>>   |  t |                   |
>>>>   +----+                   |
>>>>   |    |                   |
>>>>   |  T |                   |
>>>>   |  e |       Image       |
>>>>   |  x |                   |
>>>>   |  t |                   |
>>>>   |    |                   |
>>>>   +----+                   |
>>>>   |  T |                   |
>>>>   |  e |                   |
>>>>   |  x |                   |
>>>>   |  t |                   |
>>>>   +----+-------------------+
>>>> 
>>>> Except of course the left area should be the rotated HBox.
>>>> 
>>>> Is this really not possible at the moment, without using a Canvas or
>>>> something and a lot of layout calculations (to get reflow working)?
>>>> 
>>>> Any feedback appreciated :)
>>>> 
>>>> --John
>> 
>> 


More information about the openjfx-dev mailing list