-
Notifications
You must be signed in to change notification settings - Fork 0
KPage
KPages are an implementation of the InventoryContentContainer and can currently only be used inside the KPageInventory.
KPages serve the use to hold items in the current page, and easily be swapped out by another page, without losing their content.
The main builder for pages looks like the following:
val page = kPage {
// your config
}
When building pages inside a KPageInventory you can also use the inbuilt functions.
Because a page is also a InventoryContentContainer, you can configure them almost in the same way as a traditional inventory. To get a better understanding, take a look at the provided functions.
Items, and rows will always be placed relative to the page starting and end index, which will be influenced by the page header and footer. To write into the header you can use a negative slot for now. In a future release this will be changed!
Pages such as inventories also support openingAnimations or any kind of saved animation for it, to learn more look at here.
Be careful when using animation and swapping pages, this can cause unwanted behaviour. To stop this from happening, use the setItemsClickableWhileAnimating() method in the parent inventory.
To add functionality to the pages, to actually allow for dynamic pagination, you can use the kPageController class. This can currently either be set as the page footer, or page header.
To build a controller you can use the kPageController function:
val controller = kPageController {
nextBtn = kItem(Material.OAK_SIGN) {
setDisplayName(Component.text("Next"))
}
previousBtn = kItem(Material.OAK_SIGN) {
setDisplayName(Component.text("Previous"))
}
builder = { nextBtn, previousBtn, _ -> kRow {
setItem(3, nextBtn!!)
setItem(6, previousBtn!!)
}}
}
To build a controller you need to provide the builder method. Into this function the nextBtn, previousBtn and placeholderItem attribute of the controller will be passed. You need to return a kRow which will then be placed at either the footer or header of the page.
KIA will automatically add the required functionality to the buttons to handle paginations, when using the default builders.
Using the controller from the example above, you can set a controller inside a page by setting the footer and header of a page:
val page = kPage {
header = controller
}