MalisisCore

48M Downloads

Alignment issues - explained.

Dockter opened this issue ยท 1 comments

commented

This is an attempt to explain the alignment issue in further detail and what I did to resolve it.

Here's a Label object I constructed:

// Player Display Name
title = new UILabel(this, ChatColor.AQUA + "Residence Info");
title.setPosition(0, 0, Anchor.CENTER | Anchor.TOP);
title.setColor(0xffffffff);
title.setSize(7, 7);
title.setFontScale(0.8F);

This is the container I drew it in:

// Construct Hud with all elements
resPane = new UIBackgroundContainer(this, 110, 55);
resPane.setPosition(-10, 0);
resPane.setAnchor(Anchor.RIGHT | Anchor.BOTTOM);
resPane.setColor(Integer.MIN_VALUE);
resPane.setBackgroundAlpha(125);

If this is constructed and displayed onto the screen, the label begins its draw at the center of the container and continues right, see picture:

http://www.almuramc.com/images/Issues/Center-Right-Draw.png

I correct this issue by setting the text of the label again after the object is constructed in either an "update" method or before the drawScreen():

http://pastie.org/9944820

As you can see, the text is now centered properly, only corrected by re-setting the text on the label after the object is constructed and displayed on the screen:

http://www.almuramc.com/images/Issues/Center-Center-Draw.png

So, bug: Anchor data isn't respected until after label object is constructed and displayed at least once on the screen.

commented

Problem was that the GUIs where constructed too soon : before the assets were loaded, so string size could not be calculated.