Layouts - DevNatan/inventory-framework GitHub Wiki

Layouts are used to organize the items in a view in an orderly way, draw the spaces where the items will be placed.

Usage

So let's get started, in onInit() change the configuration and set the layout property

@Override
public void onInit(ViewConfigBuilder config) {
    config.layout(...);
}

There is a reserved character 'O' which is the character that represents an item that will be filled by other view components such as: pagination and the function availableSlot(...) from onFirstRender.

final class LayeredView extends View {

    @Override
    public void onInit(ViewConfigBuilder config) {
        config.size(3).layout(
	     "         ",
	     " OOOOOOO ",
	     "         "
	);
    }

    @Override
    public void onFirstRender(RenderContext render) {
         render.availableSlot(new ItemStack(Material.GOLD_INGOT));
    }
}

But you are not limited to the 'O' character and the availableSlot(...) function, you can define any character you want in the layout. Use the layoutSlot(...) function to define items that represent a character in the layout.

final LayeredView extends View {

    @Override
    public void onInit(ViewConfigBuilder config) {
        config.size(3).layout(
	     "  FFFFF  ",
	     " OOOOOOO ",
	     "  FFFFF  "
	);
    }

    @Override
    public void onFirstRender(RenderContext render) {
         render.availableSlot(new ItemStack(Material.GOLD_INGOT));
         render.layoutSlot('F', new ItemStack(Material.DIAMOND));
    }
}

Rules

  • Layout is a String array, the size of this array must be the same number of rows as the inventory.
  • Each String in the array must have the same length as the inventory columns count.

Interactions by other components

Layouts take precedence over other components and are also used to determine the position of other components on the screen e.g. pagination. If there is a view with pagination & layout, pagination will use the layout to define the position of the current page items.

Normally, the O character will be the reserved character that will be used by other components.