Problems with fonts/font sizes in niftygui controls

I cannot seem to change the fonts in niftygui controls. I have a test with several text controls and a button control and I am experimenting with using fonts. I use the font creator in the sdk to create different fonts of different sizes but I don’t seem to be able to get the controls to change fonts. Attached is the xml file with one of the tests.

[xml]<?xml version=“1.0” encoding=“UTF-8”?>


<useControls filename=“nifty-default-controls.xml” />

<useStyles filename=“nifty-default-styles.xml” />

<screen id=“start” controller=“rds.test2.RDSMain”>

<layer id=“layer” backgroundColor="#0000" childLayout=“center”>

<panel id=“panel” height=“30%” width=“30%” align=“right” valign=“bottom” backgroundColor="#f60f" childLayout=“center” visibleToMouse=“true”>

<text id=“myText” font=“Interface/Fonts/Baskerville.fnt” size=“40” color="#000f" text=“Menu” align=“center” valign=“center” />

<interact onClick=“sayHello(hi)”/>




<screen id=“connect” controller=“rds.test2.ConnectScreen”>

<layer id=“layer” backgroundColor="#0000" childLayout=“center”>

<panel id=“panel” height=“40%” width=“30%” align=“center” valign=“bottom” backgroundColor="#f60f" childLayout=“vertical” visibleToMouse=“true”>

<control name=“textfield” id=“myConnectHost” font=“Interface/Fonts/Arial.fnt” size=“40” color="#000f" text=“” align=“center” valign=“center” />

<interact onClick=“sayHello(connected)”/>

<control name=“textfield” id=“myConnectPort” font=“Interface/Fonts/Baskerville.fnt” color="#000f" text=“8080” align=“center” valign=“center” />

<control name=“textfield” id=“myText3” font=“Interface/Fonts/Baskerville.fnt” color="#000f" text=“disconnected” align=“center” valign=“center” />

<control name=“button” label=“Connect” id=“ConnectButton” font=“Interface/Fonts/Arial.fnt” align=“center” valign=“center”/>







Changing fonts should always work with the element, like:

[xml]<text id=“text” font=“aurulent-sans-16.fnt” color="#000f" text=“Hello World!” align=“center” valign=“center” />[/xml]

works here. Are you sure Nifty can find that font file?

For the “textfield” control things are a bit different. Currently it is not possible that you can change the font directly by setting the font attribute of the control (although that would be a nice thing to have available). Internally the “textfield” control actually consists of multiple Nifty elements. One of them is a element that represents the text of the textfield. Setting attributes for the control won’t change attributes for the “correct” internal text element.

To change the font of the textfield you’ll need to use your own style. Find the “nifty-textfield.xml” in the “nifty-style-black” jar for the standard style then either modify this file directly or create your own style file from it.

1 Like