Problem changing nifty button textColor after disabling it

Hi,

I stumbled upon an issue with changing the text color of button.

I created a simple example to illustrate this:

nifty.xml:

<screen id="start" controller="pl.rembol.MyController">
    <layer id="foreground" childLayout="center">
        <panel childLayout="horizontal">
            <panel width="30%" childLayout="center">
                <control name="button" label="toggle">
                    <interact onClick="toggleMyButton()"/>
                </control>
            </panel>
            <panel width="30%" childLayout="center">
                <control name="button" label="color">
                    <interact onClick="colorMyButton()"/>
                </control>
            </panel>
            <panel width="40%" childLayout="center">
                <control name="button" id="myButton" label="myButton">
                </control>
            </panel>
        </panel>
    </layer>
</screen>

And then in controller:

public void toggleMyButton() {
    Button button = screen.findNiftyControl("myButton", Button.class);
    button.setEnabled(!button.isEnabled());
}

public void colorMyButton() {
    Button button = screen.findNiftyControl("myButton", Button.class);
    button.setText("text # "+ FastMath.nextRandomInt(100, 999));
    button.setTextColor(new Color(FastMath.nextRandomFloat(), FastMath.nextRandomFloat(), 
FastMath.nextRandomFloat(), 1));
}

Function of second button is to randomly change the text and color of third button, while the first button enables and disables third button.

Changing color works great until the first enable/disable - after that text changes but color does not.

I’ve dug a little into nifty code and it seems that the problem is in default onEnabled and onDisabled effect that uses “textColorAnimated” effect.

Apparently on activating an effect, EffectProcessorImpl adds it ti activeEffects list but it does not remove it after animation finishes.

A workaround I’ve found was calling:

 screen.findNiftyControl("myButton", Button.class).getElement().resetSingleEffect(EffectEventId.onEnabled);

after animation finishes, or disabling onEnabled/onDisabled effects on button whatsoever.

I understand that it might be done with purpose - if I’m controlling textColor manually, then I should not use “textColorAnimated” effects - but on the other hand, it works fine before first button disable, so it seems like it “breaks” after disabling.

I was wondering if anyone had similar issues?

No harm asking here, but I suggest you also open an issue at the Nifty tracker on GitHub:

The nifty project hasn’t updated in over a year… I’m not sure you’ll get any response.

It’s been long time between official releases, but issues filed do get responses.