[SOLVED] Nifty: ”AbsoluteInside” ChildLayout is not ”inside”

Hello, we build a simple GUI that consists of a non-moveable Window (Panel).

This Panel contains another Panel (the green/brown one).



The positioning within the green/brown Panel is okay (horizontal and vertical panels)



Our problem is, that its parent is the Window to the right.

No matter what x Value we give the Panel, it will not move. It always stays on the left.

In this case, x is set to “900”. Its still on the left. If x is set to “0”, it stays the same. “0px” or “900px” wont change anything.

A “get” on the X-Property returns the Value we gave the Element (here 900)



j Monkey Engine 3 0 008



This is our Code for the “Window” (panel) on the right:

[java]package gui.tabmenu.inventory;



import de.lessvoid.nifty.builder.PanelBuilder;



/**

*

  • @author JabaXaro

    */

    public class InventoryPanelBuilder extends PanelBuilder {



    public InventoryPanelBuilder(int resX, int resY) {

    super("InventoryPanel");

    int x = resX - 140;

    int y = (resY - 237) / 2;

    x(String.valueOf(x));

    y(String.valueOf(y));

    backgroundImage("Interface/inventory.png");

    width("140px");

    height("237px");

    visible(false);

    childLayoutAbsoluteInside();

    }

    }

    [/java]

    Here is the code for the left small Panel:

    [java]package gui.tabmenu.inventory.grid;



    import de.lessvoid.nifty.builder.PanelBuilder;



    /**

    *
  • @author Carolin

    */

    public class GridPanelBuilder extends PanelBuilder {

    //TODO Ein custom NiftyGUI Control "InventoryPanel"



    public GridPanelBuilder(int slotXCount, int slotYCount, int slotXSize, int slotYSize) {

    super("Inventory");

    childLayoutVertical();

    x("900");

    backgroundColor("#0f05");

    y("137");

    System.out.println(get("x"));

    width(slotXSize * slotXCount + "px");

    height(slotYSize * slotYCount + "px");

    for (int yIndex = 0; yIndex < slotYCount; yIndex++) {

    panel(new GridRowPanelBuilder(slotXCount, slotXSize, slotYSize, yIndex));

    panel(new SpacePanelBuilder(0, 2));

    }



    }

    }

    [/java]

I had the same problem today…

900 seems pretty high, remember the co-ordinates are within the panel containing it.



It would also be better to do x(“900px”) (if that’s your intention) to make the units explicit. I’ve no idea what nifty defaults too.

The 900 is not the Problem.

If i set x and y to 0 the problem remains.



In fact, the Panel stays at exactly the same point.



P.S. Nifty defaults to pixel, so 900 = “900px”.

I’m doing what you are trying to do with absoluteLayout.

If you place it within another panel, it will act as the way you would suppose absoluteInside would work.



panel(100,100)

  • asboluteLayout
  • control(0,0)



    should place the control at 100,100



    [java]

    panel(new PanelBuilder("equipmentPanel") {

    {

    childLayoutAbsolute();

    width("" + ABILITIES_DIM.width);

    height("" + EQUIPMENT_DIM.height);

    alignCenter();

    visibleToMouse(true);

    backgroundColor(SUB_PANEL_BG);

    for (int slot = 0; slot < EQUIPMENT_SLOTS; slot++) {

    final int slotID = INVENTORY_SLOTS + slot;

    final int equipmentSlotID = slot;

    panel(new EquipmentSlotBuilder(slotID, equipmentSlotID));

    }

    }

    });

    [/java]



    [java]

    public EquipmentSlotBuilder(final int slotID, final int equipmentSlotID) {

    super("slot_" + slotID);

    {

    childLayoutAbsolute();

    x("" + pos[equipmentSlotID][0]);

    y("" + pos[equipmentSlotID][1]);

    width("" + SLOT_SIZE_P);

    height("" + SLOT_SIZE_P);

    control(new DroppableBuilder("droppable_" + slotID) {

    {

    childLayoutAbsolute();

    width("" + SLOT_SIZE);

    height("" + SLOT_SIZE);

    x("" + ITEM_PADDING);

    y("" + ITEM_PADDING);

    backgroundColor(SUB_PANEL_BG);

    control(new LabelBuilder() {

    {

    x("3");

    y("3");

    color("#ffffff33");

    text("" + slotID);

    }

    });

    control(new DraggableBuilder("draggable_" + slotID) {

    {

    childLayoutAbsolute();

    width("" + SLOT_SIZE);

    height("" + SLOT_SIZE);

    x("0");

    y("0");

    }

    });

    }

    });

    }

    }

    [/java]
1 Like

@perfecticus thanks a lot, works.



@void256 Is this “working as intended” though?

Looking at the names, it seems as if AbsoluteInside should act as Absolute does now.

The Nifty Manual explains this in detail on page 59 and 60, quote:


This childLayout works exactly the same as the „absolute“ layout we‘ve just discussed with one
exception: It‘s not possible to set a x or y position that would make the child element render outside
of its parent area. In case it would be drawn outside Nifty will automatically adjust the position (x
and y) so that the child element will stay inside the parent element.


It looks like that there might be something wrong with your element hierachy which will confuse Nifty. I can't tell for sure since you haven't provided a whole example. Maybe you add the elements dynamically and you forgot to call screen.layoutLayers() or something?