get size after CSS
Tom Eugelink
tbee at tbee.org
Sun Dec 30 10:28:48 PST 2012
This seems to work. It is indeed is a little but late; the font is applied in the first pulse and then I apply the clip based that height, so on the second pulse all should be okay. I can live with that. Thanks!
@Phil; the question was: I need to know the font size (effective height) that is being set through CSS. It makes sense that the font property is set from the CSS, could have though of that myself, but didn't. Still learning JFX.
I needed that size in order to clip a multi line text to just a single (the first) line. My Agenda control should support the concept of what I call "tasks", which have an task date, but no duration. So there is no area where the text is part of (like appointments have, naturally clipping this text), but a task is a single moment. Maybe task is not the best word, but I haven't found a better one.
Tom
On 2012-12-26 18:27, Phil Race wrote:
> If I understand correctly, that is too late for Tom.
> Otherwise I'm not sure there'd be a question.
>
> -phil.
>
> On 12/26/12 6:52 AM, David Grieve wrote:
>> Listen for changes in the fontProperty of Text. If the font is set by CSS, it will happen just before the call to layout.
>>
>> On Dec 24, 2012, at 3:25 PM, Tom Eugelink <tbee at tbee.org> wrote:
>>
>>> My question basically is simple: I need to know the font size (effective height) that is being set through CSS.
>>>
>>> Tom
>>>
>>>
>>> On 2012-12-24 21:14, Phil Race wrote:
>>>> Ah. I understood you to mean some code was calling setStyle(String cssStyleStr).
>>>> I've never seen a problem before in the CSS applied from a file being too late for
>>>> layout but I suppose you need this before layout ..
>>>>
>>>> -phil
>>>>
>>>> On 12/24/2012 11:52 AM, Tom Eugelink wrote:
>>>>> The style node is not changed when the font is set in a CSS file (just tested it). It does not matter if the node actually is part of the scene or not.
>>>>>
>>>>> Tom
>>>>>
>>>>>
>>>>>
>>>>> On 2012-12-24 20:46, Phil Race wrote:
>>>>>> That doesn't sound like what I suggested which is to
>>>>>> 1) listen to the "style" property on the node you care about
>>>>>> 2) by hand parse that string and extract the pending font change
>>>>>> 3) Construct a Font with that size and face
>>>>>> 4) by hand call "setFont(..) using this font you constructed.
>>>>>>
>>>>>> -phil.
>>>>>>
>>>>>> On 12/24/2012 11:40 AM, Tom Eugelink wrote:
>>>>>>> The trick with listening to the boundInParent works, but only if I actually add the dummy node to the scene, otherwise the CSS is never applied (which makes sense of course). The problem is to know when to remove it again.
>>>>>>>
>>>>>>> Tom
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On 2012-12-24 19:58, Phil Race wrote:
>>>>>>>> I'm not the authority on CSS, far from it, but so far as I know that's
>>>>>>>> just how the CSS works. So the node has no idea of the pending change.
>>>>>>>> I recall Richard saying a couple of months ago that SceneBuilder
>>>>>>>> has the same issue/need. I don't know if a solution was applied there.
>>>>>>>>
>>>>>>>> Perhaps you could listen in on the style string property on the node
>>>>>>>> and when you detect its changed parse it yourself, looking for font and
>>>>>>>> size and directly apply the new font/size to a dummy Text object and
>>>>>>>> extract the needed info from that ?
>>>>>>>>
>>>>>>>> -phil.
>>>>>>>>
>>>>>>>>
>>>>>>>> On 12/22/2012 11:15 AM, Tom Eugelink wrote:
>>>>>>>>> I've got a javafx.scene.txt.Text node with a content that can be a longer multi line (because of the wrapping width) text. But the node serves as the title of a special type of appointment in the agenda control, and I want it to only show the text that fits on the first single line. For this I'm trying to use Text's clipping feature with a rectangle of height "M". My problem is that the font being used is set in CSS.
>>>>>>>>>
>>>>>>>>> How can I find out the Text's font height?
>>>>>>>>>
>>>>>>>>> I tried using a 'new Text("M")' and then use boundsInParent, but the CSS is applied after the next pulse, so the value of "getBoundsInParent().getHeight()" initially is that of the default font. I also tried listening to boundsInParentProperty and update the height when it gets invalidated, but that does not seem to be triggered.
>>>>>>>>>
>>>>>>>>> Tom
>
More information about the openjfx-dev
mailing list