Search code examples
libgdx

What, other the .row() can cause a libgdx table to start a new row?


Bit of a mystery to me this, but I have a table in libgdx where everything is being positioned in new cells vertically;

image of cells appearing vertically with debug on

I am not using .row() anywhere. Probably doing something stupid here but I cant see it. Clues as to what can cause this?

(I'll post the code if needed, but its not that neat, and seeing as I think knowing anything that can cause a newline will help me, it shouldn't necessarily be needed)

edit Tried to cut the code down to all the bits that happen when an item gets added

Code;

//function that triggers on adding

//SSSNode is a semantic reference for the items details,it just justs made into a label like object

public void addItem(SSSNode itemsnode){

    Item newitem = new Item(itemsnode); //Item extends label    
    allItems.add(newitem);

    super.add(newitem).size(60, 30).top().left().fillY().expandY();

    //pack();
    //super.invalidate();       
    //super.validate();  (tried doing pack, validate, and none...neither helped)

    //update the GUI bar in case the inventory tab isnt there yet
    MainExplorationView.usersGUI.setDataVisible(true);


}

The following code is in "usersGUI", which creates and handles the popup called inventory which is whats in the picture and is the table I cant get to behave.

//ensures the interface for the inventory popup is setup and visible
//also refreshes the links 
public void setDataVisible(boolean visible){

    if (myContents.isVisible!=true){
        myContents.isVisible=visible;

        refreshlinks();
        setupInventory(); 
    }
}

private void refreshlinks() {
    super.clearChildren();
    super.addActor(backgroundobject);
    super.addActor(ME.playersInventory); //re adds the inventory panel table?

    int y = 440; 
    ME.playersInventory.validate(); //revalidated the table (I dumped this almost everywhere in frustration)
    //below is not relevant, it updates other items in a onscreen gui
    for (InterfaceButton link : allLinks) {     

        if (link.isVisible==true){

            link.setPosition(5,y);  
            super.addActor(link);
            y=y-30;
        }

    }

    backgroundobject.setSize(85, 200);
    backgroundobject.setPosition(0,y+20);           



}
//ensures inventory is setup once.
public void setupInventory() {

    if (setup){         
        return;     
    } 
    Log.info("setupInventory");


    ME.playersInventory.setPrefWidth(super.getWidth());

    Log.info("width is "+super.getWidth());

    ME.playersInventory.setHeight(200);


    ME.playersInventory.pack();

    float X = myContents.getX();
    float Y = myContents.getY()-ME.playersInventory.getHeight();

    Log.info("popping up inventory at:"+X+","+Y);
    ME.playersInventory.setPosition(X, Y);


    super.validate();
    setup=true;
}

The full code is also on GitHub; https://github.com/ThomasWrobel/MeshExplorerGDX The whole project is a game being made to demo/test and open source distributed semantic database system. The relevant bit is the inventory and the maybe the gui that creates it.

Anyone with good knowledge of LibGDXs workings should I think not need to look any of the code though if theres other things that can tell a table to start a new row. (ie, any layout restrictions that can cause it to happen automatically? )


Solution

  • layout ending the current row was a side effect to make the layout logic simpler. It is now fixed.

    Note HorizontalGroup is still a better fit for your use case and has the benefit that you can add/remove actors at any index.