3 Nifty Questions

  1. I want to add an effect to a panel via java. When I create a new panel I can use the following code:

    [java]ControlEffectOnHoverAttributes cea = new ControlEffectOnHoverAttributes();

    cea.setName("myhint");

    cea.setAttribute("hintText", "This is a test…");[/java]

    but I didnt find a way to connect this with an existing element.


  2. I have a panel which contains a textfield and when I change the text the size of the panel should adapt the size of the textfield. Does a method exist which updates the size? At the moment I create a new panel via PanelBuilder every time I change the text → not really a neat solution.


  3. Are there color codes for textfields? I have a sentence and now I want to highlight a special word by changing the color. Is this possible?
  1. You can just use the effect builders if you’re building elements in Java code:

    [java]someBuilder.onHoverEffect(new HoverEffectBuilder(“hint”) {{

    effectParameter(“hintText”, “This is a test…”);

    }});[/java]


  2. Not that I know of, but you can use wrapping or just set the width of the text field to as large as you can from the start.

    You don’t have to create a new panel or builder each time you change the size though, just use:

    [java]panelElement.setConstraintWidth(new SizeValue(“400px”));

    panelElement.getParent().layoutElements();[/java]


  3. I don’t think you can highlight several non-connected words, but you can set the selection colour:

    [java]textElement.getRenderer(TextRenderer.class).setTextSelectionColor(new Color("#00ff00ff"));[/java]

    and then set the selection:

    [java]textElement.getRenderer(TextRenderer.class).setSelection(start, end);[/java]
1 Like
  1. But I dont want to build a new element, I want to add the effect to an existing one.


  2. layoutElements() works perfect, thx!


  3. What a pity. Then I will suggest Void that he add this feature in the future.^^
  1. I see. Well, for a hint, I do this in our project:

    [java]Properties properties = new Properties();

    properties.put("hintText", "Text here");

    EffectProperties prop = new EffectProperties(properties);

    hint.activate(nifty, element, prop);

    hint.execute(element, 1, new Falloff(), nifty.getRenderEngine());[/java]

    Perhaps that could help?
  1. You can do that, there are colour codes that cause nifty to change text colour.



    Details are in the nifty manual.

1.

hm, currently it looks like this but it is not working:

[java] HintEffect hintEffect = new HintEffect();

Properties properties = new Properties();

properties.put( "hintText" , "This is a test!" );

Effect effect = new Effect( nifty, false, false, false, "", "", "", true, EffectEventId.onHover);

effect.init( element, hintEffect, new EffectProperties(properties), new TimeProvider(), new LinkedList<Object>() );



element.registerEffect( EffectEventId.onHover, effect );

effect.enableInfinite();[/java]



3. I tried the color codes explained in the manual/the examples but they dont work:

[xml] <panel id="hintPanel" valign="bottom" childLayout="vertical" width="100%" style="nifty-panel-bright">

<text id="hintText" font="aurulent-sans-16.fnt" color="#000f" text="a word in #F00#red" wrap="true" width="100%" align="center" valign="center" />

</panel> [/xml]

  1. Sorry, I don’t know how it works if you do it that way, I’ve only done it the way I described above.


  2. Oh, you meant in labels / text elements, I thought you meant in editable text fields.

    For colours in non-editable text elements, read this nifty-gui blog post: http://nifty-gui.lessvoid.com/archives/144

You need a backslash before the first hash…

The forum has stolen my backslash -.-

My color code looks exactly like in the example Tumaini postet. ( i copy pasted it…)

Try another F on the end of the colour code maybe? All I can say is I did do a quick test with inserting colour codes into a string a while ago and it worked although in the end I didn’t like the effect and took it back out.



Remember you will need two backslashes in a java string to get one in the output.