Trigary / Iodine

A Minecraft mod - server plugin pair that adds custom GUIs and overlays. No more inventory and chat menus!
GNU General Public License v3.0
24 stars 0 forks source link

Weird displacement effect when trying to put elements above one another #29

Closed eDexiam closed 3 years ago

eDexiam commented 3 years ago
IodineOverlay plyOverlay = IodineApi.get().createOverlay(IodineOverlay.Anchor.TOP_RIGHT, 0, 0);

plyOverlay.addElement("EnergiumMainUIElement", GuiElements.TEXTURE, 0, 0, textureGuiElement -> {
textureGuiElement.setTexture("minecraft:textures/energium/energium_main_ui_element.png");
textureGuiElement.setPadding(new int[]{0,0,0,0});
textureGuiElement.setWidth((int) (100.0/1.5));
textureGuiElement.setHeight((int) (40.0/1.5));
});

//IodineOverlay plyOverlayText = IodineApi.get().createOverlay(IodineOverlay.Anchor.TOP_RIGHT, 0, 0);

plyOverlay.addElement("EnergiumAmountText", GuiElements.TEXT, 0, 0, textGuiElement -> { ;
textGuiElement.setPadding(new int[]{0, 0, 0, 0});
textGuiElement.setText("60");
});

plyOverlay.openFor(IodineApi.get().getPlayer(event.getPlayer().getUniqueId()));
//plyOverlayText.openFor(IodineApi.get().getPlayer(event.getPlayer().getUniqueId()));

The above codes produces this effect on the client image

I'm unsure why it is moving elements around, even when trying to adjust the padding on one of the elements I just can't make the elements overlap.

Also I've found out that this problem doesn't occur when using the CENTER anchor.

Trigary commented 3 years ago

Set the width of your text, it is 200 by default at the moment. The overlay's size equals the size of its biggest element, which was the text in this scenario. The overlay became 200 wide, got placed 200 units to the left counted from the right side of the screen. So even though the overlay's anchor is set to the top right corner, elements inside the overlay are left-aligned. It's a bit confusing, but it is what it is :/