T0neg0d-gui: Two little Bugs (Text in Buttons)

Hey there,
(especially @t0neg0d :slight_smile: )

I’ve been playing around with t0neg0d’s Gui and I really like the simplicity of it.
However, I found two little bugs I tought I should report:

1. When you set the color of the text in a button, it returns back to white after you hovered over it.
I took a look at Button.java and it seems like the originalFontColor is set at the beginning and not updated when you call setFontColor(…). In the method runLoseFocusEffect(…) this not updated originalFontColor is used, not the set color.
It’s not a big deal, but should be easy to fix.

2. I don’t know if I overlooked something, but I can’t get text inside a button to be centered. Images explain it best:

The font itself does not have very much space above the letters - I checked that.
Here is the code:
[java]
quitButton = new ButtonAdapter(screen, new Vector2f(35, 180), new Vector2f(120, 45)) {
@Override
public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {

    }
};
quitButton.setText("Quit");
quitButton.setFont("Interface/Fonts/MorrisRoman_Standard.fnt");
quitButton.setFontSize(45);
quitButton.setFontColor(ColorRGBA.Green);
panel.addChild(quitButton);

[/java]

Any suggestions?

Thanks in advance!

1 Like
@m41q said: Hey there, (especially @t0neg0d :) )

I’ve been playing around with t0neg0d’s Gui and I really like the simplicity of it.
However, I found two little bugs I tought I should report:

1. When you set the color of the text in a button, it returns back to white after you hovered over it.
I took a look at Button.java and it seems like the originalFontColor is set at the beginning and not updated when you call setFontColor(…). In the method runLoseFocusEffect(…) this not updated originalFontColor is used, not the set color.
It’s not a big deal, but should be easy to fix.

2. I don’t know if I overlooked something, but I can’t get text inside a button to be centered. Images explain it best:

The font itself does not have very much space above the letters - I checked that.
Here is the code:
[java]
quitButton = new ButtonAdapter(screen, new Vector2f(35, 180), new Vector2f(120, 45)) {
@Override
public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {

    }
};
quitButton.setText("Quit");
quitButton.setFont("Interface/Fonts/MorrisRoman_Standard.fnt");
quitButton.setFontSize(45);
quitButton.setFontColor(ColorRGBA.Green);
panel.addChild(quitButton);

[/java]

Any suggestions?

Thanks in advance!

Thanks for the catch on the first. I’ll get this fixed.

The second has been a nagging issue for large font sizes. TextElement actually fixes this problem, however, I haven’t updated the library to use this in place of BitmapText yet.

Let me see if I can figure out a way of getting this to act properly.

I’ll post an example of how to replace the text with TextElement this evening so if you want to give that a shot, it’ll be available for ya.

1 Like
@t0neg0d said: Thanks for the catch on the first. I'll get this fixed.

The second has been a nagging issue for large font sizes. TextElement actually fixes this problem, however, I haven’t updated the library to use this in place of BitmapText yet.

Let me see if I can figure out a way of getting this to act properly.

I’ll post an example of how to replace the text with TextElement this evening so if you want to give that a shot, it’ll be available for ya.

Thanks.
A quick simple workaround until the next update would be nice indeed.
I don’t know where you’re at, but for me it’s evening. :stuck_out_tongue_winking_eye:

EDIT:
I investigated a bit myself and took a look at Button.java and saw how you used the TextElement.
However, ‘my’ TextElement is an interface, not a class.

I guess I’ll have to wait until the next update, won’t I?

@m41q said: Thanks. A quick simple workaround until the next update would be nice indeed. I don't know where you're at, but for me it's evening. ;P

EDIT:
I investigated a bit myself and took a look at Button.java and saw how you used the TextElement.
However, ‘my’ TextElement is an interface, not a class.

I guess I’ll have to wait until the next update, won’t I?

Sorry for the delay… it’s been a really busy week.

Try this:

[java]
private ButtonAdapter getLabeledButton(Vector2f pos, String label) {
ButtonAdapter ba = new ButtonAdapter(
screen,
pos,
new Vector2f(94,20)
) {
@Override
public void onButtonFocus(MouseMotionEvent evt) { }
@Override
public void onButtonLostFocus(MouseMotionEvent evt) { }
};
bLabel = getButtonLabel(UIDUtil.getUID(), label, ba.getDimensions());
ba.addChild(bLabel);

	return ba;
}

private TextElement getButtonLabel(String UID, String text, Vector2f dim) {
	TextElement el = new TextElement(screen, UID, Vector2f.ZERO, new Vector2f(dim), null) {
		@Override
		public void onUpdate(float tpf) {  }
		@Override
		public void onEffectStart() {  }
		@Override
		public void onEffectStop() {  }
	};
	el.setIsResizable(false);
	el.setIsMovable(false);
	el.setTextWrap(LineWrapMode.NoWrap);
	el.setTextVAlign(VAlign.Center);
	el.setTextAlign(Align.Center);
	el.setFontSize(18);
	el.setText(text);
	return el;
}

[/java]

Then just call getLabeledButton

It uses TextElement in place of the default BitmapText label.

1 Like

Also note: TextElement is still being worked on. It has it’s quirks using wrap modes atm… some I have fixed and will be in the next update, others I am still working on. But, for this sort of thing it works just fine.

1 Like

@t0neg0d

Thanks you for the workaround.
I think you’ve won me over to your gui now :smiley:

1 Like

Just letting you know that I committed the fix for the default font color. If your pulling the sources from the repo, it’s available.