-
Notifications
You must be signed in to change notification settings - Fork 23
Code Samples
Natan Vieira edited this page Jul 16, 2023
·
16 revisions

private final MutableIntState counterState = mutableState(0);
@Override
public void onInit(ViewConfigBuilder config) {
config.title("Counter")
.cancelOnClick()
.layout(" - # + ");
}
@Override
public void onFirstRender(RenderContext render) {
// Current count item
render.layoutSlot('#')
// The `watch` here updates the item when `counterState` updates
.watch(counterState)
.renderWith(() -> new ItemStack(
/* type = */ Material.GOLD_INGOT,
/* amount = */ counterState.get(render)
));
// Decrement button
render.layoutSlot('-', new ItemStack(Material.ARROW))
.onClick(counterState::decrement);
// Increment button
render.layoutSlot('+', new ItemStack(Material.ARROW))
.onClick(counterState::increment);
}
- Installation
- Basic Usage
- Configuration Guide
- Interaction Handling
- Navigating Between Views
- Shared Contexts
- State Management
- Refs API
- Built-In Features
- Extra Features