Event when CSS is applied

Tomas Mikula tomas.mikula at gmail.com
Tue Feb 17 18:55:51 UTC 2015


On Tue, Feb 17, 2015 at 1:30 PM, Tom Eugelink <tbee at tbee.org> wrote:
> The control is a codewise polish up one of Gerrit's gauges (with
> permission!) and pulled into JFXtras (with tests and all). For an idea on
> what we are talking about:
> https://www.youtube.com/watch?v=RH5X1uBu1d8
>
> The process of centering the Text in that circle is a bit more complex.
> 1. The value may vary between a min and max value.
> 2. I want the Text to automatically utilize the maximum available space, but
> not change size when a longer or shorter text is shown.
>
> To do this I have two additional Text nodes that have the same styling as
> the Text node (so these are on the scene, but not visible, otherwise CSS is
> not applied). These two text nodes get the maximum and minimum possible
> value set. Then on these two some pythagoras is applied and in that way one
> can determine the scale factor so that the value will never be rendered
> outside of the circle. Then the actual to-be-rendered value can be placed
> into the Text node and positioned in the centre of the circle.
>
> The problem is that a lot of these calculations depend on the CSS styling.
> What font is set? Bold or not? So I can only do these calculcation after the
> CSS has been applied. This unfortunately is not yet the case when the skin
> is instantiated. This means that if I do not used the layoutChildren, the
> initial presentation is totally off, untill the first min/max/value is set.

Maybe I was misunderstood. I didn't suggest not doing it in
layoutChildren. My conclusion was to keep doing it in layoutChildren
and not worry about repositioning the text too often.

Tomas

>
> So I would like to know when the CSS is applied to do the initial
> calculations. After that only when CSS, min or max changes is a
> recalculation required.
>
> Tom
>
>
>
>
> On 17-2-2015 19:05, Tomas Mikula wrote:
>>
>> Hi Tom,
>>
>> suppose you have such an event and can tell whether CSS of your Text
>> has changed. But is changed CSS the only time you want to re-position
>> the Text? I guess you also need to re-position it when the size of the
>> parent changes. I imagine the logic for determining whether you need
>> to re-position the Text or not can get quite complicated.
>>
>> Why is it a problem that you reposition the Text too often?
>>
>> I imagine, and someone please correct me if I'm wrong, that when you
>> ask for text.prefWidth(-1), you get a cached prefWidth from the last
>> call, if no properties of Text have changed since the last call to
>> prefWidth. I also suppose, and again correct me if I'm wrong, that if
>> you resizeRelocate the Text to the exact same position and size as it
>> already has, it does not incur any additional operations down the road
>> compared to not calling resizeRelocate at all. So my conclusion is
>> that repositioning the Text to the same place is not more expensive
>> than checking whether the Text needs to be repositioned.
>>
>> Regards,
>> Tomas
>>
>> On Tue, Feb 17, 2015 at 10:14 AM, Tom Eugelink <tbee at tbee.org> wrote:
>>>
>>> Registering to fontProperty works, but potentially requires a lot of
>>> listeners on every property that may affect the size, like effect, scale,
>>> etc. So I'm leaving it in layoutChildren for now; better once to many
>>> than
>>> not often enough.
>>>
>>> Would adding such an event be a big change?
>>>
>>>
>>>
>>>
>>> On 17-2-2015 14:50, David Grieve wrote:
>>>>
>>>>
>>>> On 2/17/15 8:02 AM, Tom Eugelink wrote:
>>>>>
>>>>> I have a skin (of a control) that centers a Text node. This Text node
>>>>> can
>>>>> be styled via CSS, so this styling is a factor when centering. because
>>>>> larger font means wider text.
>>>>>
>>>>> The centering works perfectly, the only problem is figuring out when to
>>>>> center the node. At the moment I'm centering the node on every
>>>>> layoutChildren call of the skin, but this is way to often, because
>>>>> after
>>>>> applying the CSS chances are very low that the node will need to be
>>>>> repositioned.
>>>>>
>>>>> Basically I would like to be informed when the styling of a node has
>>>>> been
>>>>> applied or changed. Is there some place that can provide this
>>>>> information?
>>>>>
>>>> Not in general, no. But you can add a listener to a property that is
>>>> styled by CSS and react to the change. You might add a listener to the
>>>> Text
>>>> node's fontProperty, for example. Clearly this isn't an all-purpose
>>>> solution. Another approach is to hold onto the bounds (or maybe just the
>>>> pref width and height) of the child node. If the old bounds doesn't
>>>> equal
>>>> the new bounds, then recenter.
>>>
>>>
>


More information about the openjfx-dev mailing list