Skip to content

Layouts

Natan Vieira edited this page Nov 13, 2025 · 95 revisions
image

Layouts is a InventoryFramework feature that let you organize items in a view by “drawing” where each item should go.


Basic Usage

Each slot in your layout corresponds to a character.
You can map items to those characters using layoutSlot.

In the example below, both “A” and “#” represent items that will be defined later in the onFirstRender trigger.

image
@Override
public void onInit(@NotNull ViewConfigBuilder config) {
    config.layout("### A ###");
}

@Override
public void onFirstRender(@NotNull RenderContext render) {
    render.layoutSlot('A', new ItemStack(Material.DIAMOND));
    render.layoutSlot('#')
        .withItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE));
}

Tip

Other Inventory Framework features integrate with layouts out of the box. For instance, when using Pagination, the paginated items automatically adjust to the layout without any additional configuration.

Iterating over Layout Slots

You may have noticed that even if there are multiple “#” symbols in the layout, a single layoutSlot('#', ...) call is enough to fill all of them. Each matching character automatically gets assigned the same item or behavior.

If you want to change which item is displayed based on the slot iteration index, you can extend the layoutSlot call by providing a lambda that receives the slot’s iteration index and item builder.

image
@Override
public void onInit(@NotNull ViewConfigBuilder config) {
    config.layout("### A ###");
}

@Override
public void onFirstRender(@NotNull RenderContext render) {
    render.layoutSlot('A', new ItemStack(Material.DIAMOND));
    render.layoutSlot('#', (index, item) -> item.withItem(
        new ItemStack(Material.BLACK_STAINED_GLASS_PANE, index + 1))
    );
}

Configuration Rules

In your view configuration, you can define which layout will be applied to the view. Before doing so, keep in mind the following:

  • A layout is represented as a String[], where each string corresponds to a row.
  • The number of rows in the array must match the number of rows in the inventory.
  • Each string in the array must have the same length as the number of inventory columns.
  • If you define a layout but don’t specify a fixed inventory size, the inventory will automatically use the dimensions of the layout.

Example Usage

Example: In the example below, we use layout to create a black glass pane pattern around the inventory.

image
@Override
public void onInit(@NotNull ViewConfigBuilder config) {
    config.layout(
        "#########",
        "#       #",
        "#       #",
        "#       #",
        "#       #",
        "#########"
    );
}

@Override
public void onFirstRender(@NotNull RenderContext render) {
    render.layoutSlot('#')
        .withItem(new ItemStack(Material.BLACK_STAINED_GLASS_PANE));
}

Welcome to the Inventory Framework documentation.

▶️ Introduction

🧩 Core Topics

💡 Built-In Features

🧰 Extra Features

🤓 Advanced Usage

⚙️ Internal Mechanisms

You can find practical examples in the examples directory.

Clone this wiki locally