Edmund
September 17, 2019, 6:29am
1
Hello again, I’m new to JME and I have the the problem that i can’t change the font of a button in a nifty gui. It works with a text, e.g.:
text(new TextBuilder() {{
text("1234");
font("Fonts/SomeFont.fnt");
}});
But it’s not working with this:
control(new ButtonBuilder("CloseButton", "Close") {{
font("Fonts/SomeFont.fnt");
}});
What am I doing wrong?
And by the way, where can I find a documentation that helps me finding errors like this (the nifty-gui manual didn’t help me with this problem)?
PS: I thank you all for spending your time to help guys like me!!
Nifty 1.3.2 manual (which I assume you are referring to) is just fine. Nifty just needs some practice, and having quick links to the source doesn’t hurt. Mainly to figure out hierarchies on control definitions etc.
You could try to circumvent this by using styles?
Edmund
September 17, 2019, 6:48am
3
I tried it with a style like this:
new StyleBuilder() {{
id("myStyle");
font("Fonts/SomeFont.fnt");
}}.build(nifty);
but again, to set the attribute with
style("myStyle");
works with a text, but not with a button.
Look here:
The builder does nothing with the Font parameter you give. You need to explicitly call setFont on the control.
Also, you often need to check the hierarchy (for using styles):
rami
September 17, 2019, 9:49am
5
Write the style like this
new StyleBuilder() {{
id("myStyle#text");
font("Fonts/SomeFont.fnt");
}}.build(nifty);
And set the button style to myStyle (without #text ).
1 Like
Edmund
September 17, 2019, 11:03am
6
I don’t understand why, but it works !!
Thank you very much!!
Edmund
September 17, 2019, 12:03pm
7
When i try the same with a TextFieldBuilder it’s not working. This works:
control(new TextFieldBuilder("txtLaenge","1035"){{
}});
But this does not
control(new TextFieldBuilder("txtLaenge","1035"){{
style("myStyle");
}});
I get the error that says “missing childLayout Attribute”. When i change it to
control(new TextFieldBuilder("txtLaenge","1035"){{
style("myStyle");
childLayoutCenter();
}});
i still get the same error !?!?
I’m new to Java and JME (self-taught) and must admit that i don’t really understand the documentation mentioned above.
It works because of the hierarchy:
1 Like
This might not work since you are wiping out some important bits from the original style (the childLayouts).
See the original style:
<?xml version="1.0" encoding="UTF-8"?>
<nifty-styles xmlns="http://nifty-gui.lessvoid.com/nifty-gui">
<registerMouseCursor id="textFieldCursor" filename="textfield/mouse-cursor-textfield.png" hotspotX="3"
hotspotY="12"/>
<!-- the background of the textfield -->
<style id="nifty-textfield#panel">
<attributes childLayout="overlay" height="23px"/>
<effect>
<onHover name="changeMouseCursor" id="textFieldCursor"/>
<onHover name="border" color="#822f" post="true"/>
</effect>
</style>
<!-- the actual input field -->
<style id="nifty-textfield#field">
<attributes childLayout="center" childClip="true" backgroundColor="#666f" padding="0px,2px"/>
<effect>
<onActive name="border" color="#222f" post="true" inset="1px"/>
<onFocus name="colorBar" color="#800f" post="true" inset="1px"/>
This file has been truncated. show original
But are you really using different font in every control you are creating? Set up a base font so that you don’t need to change this for every control.
1 Like
rami
September 17, 2019, 4:09pm
10
If you want to write a complete new style I advise you to copy the nifty black style XMLs and edit them. They have the right ids and you can just customize their appearance. If you don’t you can just take a look at the control definition xml to pickup the control children ids and use them in the selector.
Edmund
September 18, 2019, 5:34am
11
All i want to do ist to use a different font for all Elements.
I found a “fonts.xml” in "C:\Program Files\jmonkeyplatform\jmonkeyplatform\libs\nifty-style-black-1.4.3.jar with this content
<?xml version="1.0" encoding="UTF-8"?>
<nifty-styles xmlns="http://nifty-gui.lessvoid.com/nifty-gui">
<style id="button-font">
<attributes font="aurulent-sans-16.fnt"/>
</style>
<style id="tab-font">
<attributes font="aurulent-sans-16.fnt"/>
</style>
<style id="base-font">
<attributes font="aurulent-sans-16.fnt"/>
</style>
</nifty-styles>
Would it work to change the fonts here ?
If yes, how can i do this? I don’t know the workflow to change content in a jar-file .
1 Like
Edmund
September 18, 2019, 6:57am
12
All i want to do ist to use a different font for all Elements.
Can you tell me how to set up a base font?
rami
September 18, 2019, 7:54am
13
Yes, try to write a style file and load it from nifty loadStyleFile method.
<?xml version="1.0" encoding="UTF-8"?>
<nifty-styles xmlns="http://nifty-gui.lessvoid.com/nifty-gui">
<style id="base-font">
<attributes font="font.fnt"/>
</style>
</nifty-styles>
or write it in your screen XML file.
<nifty xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://nifty-gui.lessvoid.com/nifty-gui" xsi:schemaLocation="https://raw.githubusercontent.com/void256/nifty-gui/1.4/nifty-core/src/main/resources/nifty.xsd https://raw.githubusercontent.com/void256/nifty-gui/1.4/nifty-core/src/main/resources/nifty.xsd">
<style id="base-font">
<attributes font="font.fnt"/>
</style>
<screen>
<!--code code code....-->
</screen>
</nifty>
You should write the code that overrides the base-font style after loading the nifty black style.
3 Likes
Edmund
September 18, 2019, 8:56am
14
That’s it !!! Thank you very much !!!
2 Likes